Some minor tidyup

This commit is contained in:
UnknownShadow200 2024-05-20 22:21:50 +10:00
parent 21ee159b2c
commit 1290640a7c
5 changed files with 29 additions and 25 deletions

View File

@ -583,14 +583,14 @@ void FancyLighting_SetActive(void) {
Lighting.IsLit_Fast = IsLit_Fast; Lighting.IsLit_Fast = IsLit_Fast;
Lighting.Color_Sprite_Fast = Color; Lighting.Color_Sprite_Fast = Color;
Lighting.Color_YMax_Fast = Color; Lighting.Color_YMax_Fast = Color;
Lighting.Color_YMin_Fast = Color_YMinSide; Lighting.Color_YMin_Fast = Color_YMinSide;
Lighting.Color_XSide_Fast = Color_XSide; Lighting.Color_XSide_Fast = Color_XSide;
Lighting.Color_ZSide_Fast = Color_ZSide; Lighting.Color_ZSide_Fast = Color_ZSide;
Lighting.FreeState = FreeState; Lighting.FreeState = FreeState;
Lighting.AllocState = AllocState; Lighting.AllocState = AllocState;
Lighting.LightHint = LightHint; Lighting.LightHint = LightHint;
} }
static void OnEnvVariableChanged(void* obj, int envVar) { static void OnEnvVariableChanged(void* obj, int envVar) {

View File

@ -18,10 +18,18 @@ const char* const LightingMode_Names[LIGHTING_MODE_COUNT] = { "Classic", "Fancy"
cc_uint8 Lighting_Mode; cc_uint8 Lighting_Mode;
cc_bool Lighting_ModeLockedByServer; cc_bool Lighting_ModeLockedByServer;
cc_bool Lighting_ModeSetByServer; cc_bool Lighting_ModeSetByServer;
cc_uint8 Lighting_ModeCached; cc_uint8 Lighting_ModeUserCached;
struct _Lighting Lighting; struct _Lighting Lighting;
#define Lighting_Pack(x, z) ((x) + World.Width * (z)) #define Lighting_Pack(x, z) ((x) + World.Width * (z))
void Lighting_SetMode(cc_uint8 mode, cc_bool fromServer) {
cc_uint8 oldMode = Lighting_Mode;
Lighting_Mode = mode;
Event_RaiseLightingMode(&WorldEvents.LightingModeChanged, oldMode, fromServer);
}
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------Classic lighting-----------------------------------------------------* *----------------------------------------------------Classic lighting-----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
@ -435,6 +443,7 @@ static void Lighting_SwitchActive(void) {
static void Lighting_HandleModeChanged(void* obj, cc_uint8 oldMode, cc_bool fromServer) { static void Lighting_HandleModeChanged(void* obj, cc_uint8 oldMode, cc_bool fromServer) {
if (Lighting_Mode == oldMode) return; if (Lighting_Mode == oldMode) return;
Builder_ApplyActive(); Builder_ApplyActive();
if (World.Loaded) { if (World.Loaded) {
Lighting_SwitchActive(); Lighting_SwitchActive();
MapRenderer_Refresh(); MapRenderer_Refresh();
@ -444,11 +453,10 @@ static void Lighting_HandleModeChanged(void* obj, cc_uint8 oldMode, cc_bool from
} }
static void OnInit(void) { static void OnInit(void) {
Lighting_Mode = Options_GetEnum(OPT_LIGHTING_MODE, LIGHTING_MODE_CLASSIC, LightingMode_Names, LIGHTING_MODE_COUNT); Lighting_Mode = Options_GetEnum(OPT_LIGHTING_MODE, LIGHTING_MODE_CLASSIC, LightingMode_Names, LIGHTING_MODE_COUNT);
Lighting_ModeLockedByServer = false; Lighting_ModeLockedByServer = false;
Lighting_ModeSetByServer = false; Lighting_ModeSetByServer = false;
Lighting_ModeCached = Lighting_Mode; Lighting_ModeUserCached = Lighting_Mode;
FancyLighting_OnInit(); FancyLighting_OnInit();
Lighting_ApplyActive(); Lighting_ApplyActive();

View File

@ -21,7 +21,8 @@ extern cc_bool Lighting_ModeLockedByServer;
/* True if the current lighting mode has been set by the server instead of the client */ /* True if the current lighting mode has been set by the server instead of the client */
extern cc_bool Lighting_ModeSetByServer; extern cc_bool Lighting_ModeSetByServer;
/* The lighting mode that was set by the client before being set by the server */ /* The lighting mode that was set by the client before being set by the server */
extern cc_uint8 Lighting_ModeCached; extern cc_uint8 Lighting_ModeUserCached;
void Lighting_SetMode(cc_uint8 mode, cc_bool fromServer);
/* How much ambient occlusion to apply in fancy lighting where 1.0f = none and 0.0f = maximum*/ /* How much ambient occlusion to apply in fancy lighting where 1.0f = none and 0.0f = maximum*/

View File

@ -2899,12 +2899,11 @@ static void GraphicsOptionsScreen_SetSmooth(const cc_string* v) {
} }
static void GraphicsOptionsScreen_GetLighting(cc_string* v) { String_AppendConst(v, LightingMode_Names[Lighting_Mode]); } static void GraphicsOptionsScreen_GetLighting(cc_string* v) { String_AppendConst(v, LightingMode_Names[Lighting_Mode]); }
static void GraphicsOptionsScreen_SetLighting(const cc_string* v) { static void GraphicsOptionsScreen_SetLighting(const cc_string* v) {
cc_uint8 oldMode = Lighting_Mode; cc_uint8 mode = Utils_ParseEnum(v, 0, LightingMode_Names, LIGHTING_MODE_COUNT);
Lighting_Mode = Utils_ParseEnum(v, 0, LightingMode_Names, LIGHTING_MODE_COUNT);
Options_Set(OPT_LIGHTING_MODE, v); Options_Set(OPT_LIGHTING_MODE, v);
Lighting_ModeSetByServer = false;
Event_RaiseLightingMode(&WorldEvents.LightingModeChanged, oldMode, false); Lighting_ModeSetByServer = false;
Lighting_SetMode(mode, false);
} }
static void GraphicsOptionsScreen_GetCamera(cc_string* v) { Menu_GetBool(v, Camera.Smooth); } static void GraphicsOptionsScreen_GetCamera(cc_string* v) { Menu_GetBool(v, Camera.Smooth); }

View File

@ -1533,30 +1533,26 @@ static void CPE_ExtEntityTeleport(cc_uint8* data) {
static void CPE_LightingMode(cc_uint8* data) { static void CPE_LightingMode(cc_uint8* data) {
cc_uint8 mode = *data++; cc_uint8 mode = *data++;
cc_uint8 lockedByte = *data++; cc_bool locked = *data++ != 0;
cc_bool locked = lockedByte > 0 ? true : false;
cc_uint8 oldMode = Lighting_Mode;
if (mode == 0) { if (mode == 0) {
if (!Lighting_ModeSetByServer) return; if (!Lighting_ModeSetByServer) return;
/* locked is ignored with mode 0 and always set to false */ /* locked is ignored with mode 0 and always set to false */
Lighting_ModeLockedByServer = false; Lighting_ModeLockedByServer = false;
Lighting_ModeSetByServer = false; Lighting_ModeSetByServer = false;
Lighting_Mode = Lighting_ModeCached;
Event_RaiseLightingMode(&WorldEvents.LightingModeChanged, oldMode, true); Lighting_SetMode(Lighting_ModeUserCached, true);
return; return;
} }
/* Convert from Network mode (0 = no change, 1 = classic, 2 = fancy) to client mode (0 = classic, 1 = fancy) */ /* Convert from Network mode (0 = no change, 1 = classic, 2 = fancy) to client mode (0 = classic, 1 = fancy) */
mode--; mode--;
if (mode >= LIGHTING_MODE_COUNT) return; if (mode >= LIGHTING_MODE_COUNT) return;
if (!Lighting_ModeSetByServer) Lighting_ModeCached = Lighting_Mode; if (!Lighting_ModeSetByServer) Lighting_ModeUserCached = Lighting_Mode;
Lighting_ModeLockedByServer = locked; Lighting_ModeLockedByServer = locked;
Lighting_ModeSetByServer = true; Lighting_ModeSetByServer = true;
Lighting_Mode = mode;
Event_RaiseLightingMode(&WorldEvents.LightingModeChanged, oldMode, true); Lighting_SetMode(mode, true);
} }
static void CPE_Reset(void) { static void CPE_Reset(void) {