mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
move CloudsTex into EnvRenderer.cs
This commit is contained in:
parent
bd7fe7ff44
commit
4151381ac2
6 changed files with 44 additions and 25 deletions
|
@ -197,7 +197,6 @@ namespace ClassicalSharp {
|
|||
public Vector3 CurrentCameraPos;
|
||||
|
||||
public Animations Animations;
|
||||
internal int CloudsTex;
|
||||
internal bool screenshotRequested;
|
||||
|
||||
internal EntryList AcceptedUrls = new EntryList("texturecache", "acceptedurls.txt");
|
||||
|
|
|
@ -317,7 +317,6 @@ namespace ClassicalSharp {
|
|||
|
||||
Graphics.DeleteIb(ref defaultIb);
|
||||
Drawer2D.DisposeInstance();
|
||||
Graphics.DeleteTexture(ref CloudsTex);
|
||||
Graphics.Dispose();
|
||||
|
||||
if (Options.OptionsChanged.Count == 0) return;
|
||||
|
@ -418,15 +417,12 @@ namespace ClassicalSharp {
|
|||
}
|
||||
|
||||
void TextureChangedCore(object sender, TextureEventArgs e) {
|
||||
byte[] data = e.Data;
|
||||
if (e.Name == "terrain.png") {
|
||||
Bitmap atlas = Platform.ReadBmp32Bpp(Drawer2D, data);
|
||||
Bitmap atlas = Platform.ReadBmp32Bpp(Drawer2D, e.Data);
|
||||
if (ChangeTerrainAtlas(atlas)) return;
|
||||
atlas.Dispose();
|
||||
} else if (e.Name == "cloud.png" || e.Name == "clouds.png") {
|
||||
UpdateTexture(ref CloudsTex, e.Name, data, false);
|
||||
} else if (e.Name == "default.png") {
|
||||
Bitmap bmp = Platform.ReadBmp32Bpp(Drawer2D, data);
|
||||
Bitmap bmp = Platform.ReadBmp32Bpp(Drawer2D, e.Data);
|
||||
Drawer2D.SetFontBitmap(bmp);
|
||||
Events.RaiseChatFontChanged();
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace ClassicalSharp.Renderers {
|
|||
|
||||
public unsafe sealed class EnvRenderer : IGameComponent {
|
||||
|
||||
int cloudsVb = -1, cloudVertices, skyVb = -1, skyVertices;
|
||||
int cloudsVb = -1, cloudVertices, skyVb = -1, skyVertices, cloudsTex;
|
||||
World map;
|
||||
Game game;
|
||||
internal bool legacy, minimal;
|
||||
|
@ -90,6 +90,7 @@ namespace ClassicalSharp.Renderers {
|
|||
map = game.World;
|
||||
ResetAllEnv(null, null);
|
||||
|
||||
game.Events.TextureChanged += TextureChanged;
|
||||
game.WorldEvents.EnvVariableChanged += EnvVariableChanged;
|
||||
game.Events.ViewDistanceChanged += ResetAllEnv;
|
||||
game.Graphics.ContextLost += ContextLost;
|
||||
|
@ -109,14 +110,22 @@ namespace ClassicalSharp.Renderers {
|
|||
ResetAllEnv(null, null);
|
||||
}
|
||||
|
||||
void TextureChanged(object sender, TextureEventArgs e) {
|
||||
if (e.Name == "cloud.png" || e.Name == "clouds.png") {
|
||||
game.UpdateTexture(ref cloudsTex, e.Name, e.Data, false);
|
||||
}
|
||||
}
|
||||
|
||||
void ResetAllEnv(object sender, EventArgs e) {
|
||||
UpdateFog();
|
||||
ContextRecreated();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
game.Graphics.DeleteTexture(ref cloudsTex);
|
||||
ContextLost();
|
||||
|
||||
game.Events.TextureChanged -= TextureChanged;
|
||||
game.WorldEvents.EnvVariableChanged -= EnvVariableChanged;
|
||||
game.Events.ViewDistanceChanged -= ResetAllEnv;
|
||||
game.Graphics.ContextLost -= ContextLost;
|
||||
|
@ -194,7 +203,7 @@ namespace ClassicalSharp.Renderers {
|
|||
|
||||
gfx.AlphaTest = true;
|
||||
gfx.Texturing = true;
|
||||
gfx.BindTexture(game.CloudsTex);
|
||||
gfx.BindTexture(cloudsTex);
|
||||
gfx.SetBatchFormat(VertexFormat.P3fT2fC4b);
|
||||
gfx.BindVb(cloudsVb);
|
||||
gfx.DrawVb_IndexedTris(cloudVertices);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "VertexStructs.h"
|
||||
#include "Game.h"
|
||||
#include "ErrorHandler.h"
|
||||
#include "Stream.h"
|
||||
|
||||
GfxResourceID env_cloudsVb, env_skyVb, env_cloudsTex;
|
||||
Int32 env_cloudVertices, env_skyVertices;
|
||||
|
@ -273,6 +274,15 @@ void EnvRenderer_ResetAllEnv(void* obj) {
|
|||
EnvRenderer_ContextRecreated(NULL);
|
||||
}
|
||||
|
||||
void EnvRenderer_FileChanged(void* obj, Stream* src) {
|
||||
String cloud = String_FromConst("cloud.png");
|
||||
String clouds = String_FromConst("clouds.png");
|
||||
|
||||
if (String_CaselessEquals(&src->Name, &cloud) || String_CaselessEquals(&src->Name, &clouds)) {
|
||||
Game_UpdateTexture(&env_cloudsTex, src, false);
|
||||
}
|
||||
}
|
||||
|
||||
void EnvRenderer_EnvVariableChanged(void* obj, Int32 envVar) {
|
||||
if (EnvRenderer_Minimal) return;
|
||||
|
||||
|
@ -301,6 +311,8 @@ void EnvRenderer_UseMinimalMode(bool minimal) {
|
|||
|
||||
void EnvRenderer_Init(void) {
|
||||
EnvRenderer_ResetAllEnv(NULL);
|
||||
|
||||
Event_RegisterStream(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, NULL, EnvRenderer_ResetAllEnv);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, EnvRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, EnvRenderer_ContextRecreated);
|
||||
|
@ -319,7 +331,10 @@ void EnvRenderer_OnNewMapLoaded(void) {
|
|||
}
|
||||
|
||||
void EnvRenderer_Free(void) {
|
||||
Gfx_DeleteTexture(&env_cloudsTex);
|
||||
EnvRenderer_ContextLost(NULL);
|
||||
|
||||
Event_UnregisterStream(&TextureEvents_FileChanged, NULL, EnvRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, NULL, EnvRenderer_ResetAllEnv);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, EnvRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, EnvRenderer_ContextRecreated);
|
||||
|
|
|
@ -124,11 +124,11 @@ void SkyboxRenderer_EnvVariableChanged(void* obj, Int32 envVar) {
|
|||
}
|
||||
|
||||
void SkyboxRenderer_Init(void) {
|
||||
Event_RegisterStream(&TextureEvents_FileChanged, NULL, &SkyboxRenderer_FileChanged);
|
||||
Event_RegisterVoid(&TextureEvents_PackChanged, NULL, &SkyboxRenderer_TexturePackChanged);
|
||||
Event_RegisterInt32(&WorldEvents_EnvVarChanged, NULL, &SkyboxRenderer_EnvVariableChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, &SkyboxRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, &SkyboxRenderer_ContextRecreated);
|
||||
Event_RegisterStream(&TextureEvents_FileChanged, NULL, SkyboxRenderer_FileChanged);
|
||||
Event_RegisterVoid(&TextureEvents_PackChanged, NULL, SkyboxRenderer_TexturePackChanged);
|
||||
Event_RegisterInt32(&WorldEvents_EnvVarChanged, NULL, SkyboxRenderer_EnvVariableChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, SkyboxRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, SkyboxRenderer_ContextRecreated);
|
||||
}
|
||||
|
||||
void SkyboxRenderer_Reset(void) { Gfx_DeleteTexture(&skybox_tex); }
|
||||
|
@ -137,11 +137,11 @@ void SkyboxRenderer_Free(void) {
|
|||
Gfx_DeleteTexture(&skybox_tex);
|
||||
SkyboxRenderer_ContextLost(NULL);
|
||||
|
||||
Event_UnregisterStream(&TextureEvents_FileChanged, NULL, &SkyboxRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&TextureEvents_PackChanged, NULL, &SkyboxRenderer_TexturePackChanged);
|
||||
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, NULL, &SkyboxRenderer_EnvVariableChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, &SkyboxRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, &SkyboxRenderer_ContextRecreated);
|
||||
Event_UnregisterStream(&TextureEvents_FileChanged, NULL, SkyboxRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&TextureEvents_PackChanged, NULL, SkyboxRenderer_TexturePackChanged);
|
||||
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, NULL, SkyboxRenderer_EnvVariableChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, SkyboxRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, SkyboxRenderer_ContextRecreated);
|
||||
}
|
||||
|
||||
IGameComponent SkyboxRenderer_MakeGameComponent(void) {
|
||||
|
|
|
@ -196,9 +196,9 @@ void WeatherRenderer_Init(void) {
|
|||
weather_lastPos = Vector3I_Create1(Int32_MaxValue);
|
||||
WeatherRenderer_ContextRecreated(NULL);
|
||||
|
||||
Event_RegisterStream(&TextureEvents_FileChanged, NULL, &WeatherRenderer_FileChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, &WeatherRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, &WeatherRenderer_ContextRecreated);
|
||||
Event_RegisterStream(&TextureEvents_FileChanged, NULL, WeatherRenderer_FileChanged);
|
||||
Event_RegisterVoid(&GfxEvents_ContextLost, NULL, WeatherRenderer_ContextLost);
|
||||
Event_RegisterVoid(&GfxEvents_ContextRecreated, NULL, WeatherRenderer_ContextRecreated);
|
||||
}
|
||||
|
||||
void WeatherRenderer_Reset(void) {
|
||||
|
@ -213,9 +213,9 @@ void WeatherRenderer_Free(void) {
|
|||
WeatherRenderer_ContextLost(NULL);
|
||||
WeatherRenderer_Reset();
|
||||
|
||||
Event_UnregisterStream(&TextureEvents_FileChanged, NULL, &WeatherRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, &WeatherRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, &WeatherRenderer_ContextRecreated);
|
||||
Event_UnregisterStream(&TextureEvents_FileChanged, NULL, WeatherRenderer_FileChanged);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextLost, NULL, WeatherRenderer_ContextLost);
|
||||
Event_UnregisterVoid(&GfxEvents_ContextRecreated, NULL, WeatherRenderer_ContextRecreated);
|
||||
}
|
||||
|
||||
IGameComponent WeatherRenderer_MakeGameComponent(void) {
|
||||
|
|
Loading…
Add table
Reference in a new issue