Now changing sun/shadow color updates modern lighting colors

This commit is contained in:
Goodlyay 2024-05-07 18:03:13 -07:00
parent ff3752a26d
commit c601405db0
3 changed files with 18 additions and 2 deletions

View File

@ -425,7 +425,10 @@ void Lighting_SwitchActive(void) {
Lighting.AllocState();
}
static void OnInit(void) { Lighting_ApplyActive(); }
static void OnInit(void) {
Event_Register_(&WorldEvents.EnvVarChanged, NULL, ModernLighting_OnEnvVariableChanged);
Lighting_ApplyActive();
}
static void OnReset(void) { Lighting.FreeState(); }
static void OnNewMapLoaded(void) { Lighting.AllocState(); }

View File

@ -63,6 +63,7 @@ CC_VAR extern struct _Lighting {
void Lighting_SwitchActive(void);
void Lighting_ApplyActive(void);
void ModernLighting_SetActive(void);
void ModernLighting_OnEnvVariableChanged(void* obj, int envVar);
void ClassicLighting_FreeState(void);
void ClassicLighting_AllocState(void);

View File

@ -504,7 +504,11 @@ static void CalculateChunkLightingAll(int chunkIndex, int cx, int cy, int cz) {
chunkLightingDataFlags[chunkIndex] = CHUNK_ALL_CALCULATED;
}
static void ModernLighting_OnBlockChanged(int x, int y, int z, BlockID oldBlock, BlockID newBlock) { }
static void ModernLighting_OnBlockChanged(int x, int y, int z, BlockID oldBlock, BlockID newBlock) {
}
/* Invalidates/Resets lighting state for all of the blocks in the world */
/* (e.g. because a block changed whether it is full bright or not) */
static void ModernLighting_Refresh(void) {
ModernLighting_InitPalettes();
/* Set all the chunk lighting data flags to CHUNK_UNCALCULATED? */
@ -583,4 +587,12 @@ void ModernLighting_SetActive(void) {
Lighting.FreeState = ModernLighting_FreeState;
Lighting.AllocState = ModernLighting_AllocState;
Lighting.LightHint = ModernLighting_LightHint;
}
void ModernLighting_OnEnvVariableChanged(void* obj, int envVar) {
/* This is always called, but should only do anything if modern lighting is on */
if (!Lighting_Modern) { return; }
if (envVar == ENV_VAR_SUN_COLOR || envVar == ENV_VAR_SHADOW_COLOR) {
ModernLighting_InitPalettes();
}
}