From 9ac42e4fadcbae0d666430f8685c4663c5a6eac8 Mon Sep 17 00:00:00 2001 From: westonCoder Date: Sun, 8 Oct 2023 13:12:39 -0500 Subject: [PATCH] made the savefile value an int, less computation overall --- src/menu/gameplay_options.c | 36 ++++++++++++++++++--------------- src/menu/gameplay_options.h | 1 + src/savefile/savefile.c | 2 +- src/savefile/savefile.h | 2 +- src/scene/dynamic_render_list.c | 2 +- src/scene/render_plan.c | 24 +++++++++++----------- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/menu/gameplay_options.c b/src/menu/gameplay_options.c index 9e88956..2d6315f 100644 --- a/src/menu/gameplay_options.c +++ b/src/menu/gameplay_options.c @@ -12,25 +12,11 @@ #define GAMEPLAY_WIDTH 252 #define GAMEPLAY_HEIGHT 124 -#define SCROLL_TICKS 9 +#define SCROLL_TICKS PORTAL_RENDER_DEPTH_MAX - 1 #define SCROLL_INTERVALS (SCROLL_TICKS - 1) #define GAMEPLAY_X ((SCREEN_WD - GAMEPLAY_WIDTH) / 2) -void gameplayOptionsInit(struct GameplayOptions* gameplayOptions) { - gameplayOptions->selectedItem = GameplayOptionMovingPortals; - - gameplayOptions->movingPortals = menuBuildCheckbox(&gDejaVuSansFont, "Movable Portals", GAMEPLAY_X + 8, GAMEPLAY_Y + 8); - gameplayOptions->wideScreen = menuBuildCheckbox(&gDejaVuSansFont, "Wide Screen", GAMEPLAY_X + 8, GAMEPLAY_Y + 28); - - gameplayOptions->portalRenderDepthText = menuBuildText(&gDejaVuSansFont, "Portal Render Depth", GAMEPLAY_X + 8, GAMEPLAY_Y + 48); - gameplayOptions->portalRenderDepth = menuBuildSlider(GAMEPLAY_X + 126, GAMEPLAY_Y + 48, 126, SCROLL_TICKS); - - gameplayOptions->movingPortals.checked = (gSaveData.controls.flags & ControlSaveMoveablePortals) != 0; - gameplayOptions->wideScreen.checked = (gSaveData.controls.flags & ControlSaveWideScreen) != 0; - gameplayOptions->portalRenderDepth.value = (float)gSaveData.controls.portalRenderDepth / 0xFFFF; -} - #define FULL_SCROLL_TIME 2.0f #define SCROLL_MULTIPLIER (int)(0xFFFF * FIXED_DELTA_TIME / (80 * FULL_SCROLL_TIME)) #define SCROLL_CHUNK_SIZE (0x10000 / SCROLL_INTERVALS) @@ -66,6 +52,22 @@ void gameplayOptionsHandleSlider(unsigned short* settingValue, float* sliderValu *sliderValue = (float)newValue / 0xFFFF; } +void gameplayOptionsInit(struct GameplayOptions* gameplayOptions) { + gameplayOptions->selectedItem = GameplayOptionMovingPortals; + + gameplayOptions->movingPortals = menuBuildCheckbox(&gDejaVuSansFont, "Movable Portals", GAMEPLAY_X + 8, GAMEPLAY_Y + 8); + gameplayOptions->wideScreen = menuBuildCheckbox(&gDejaVuSansFont, "Wide Screen", GAMEPLAY_X + 8, GAMEPLAY_Y + 28); + + gameplayOptions->portalRenderDepthText = menuBuildText(&gDejaVuSansFont, "Portal Render Depth", GAMEPLAY_X + 8, GAMEPLAY_Y + 48); + gameplayOptions->portalRenderDepth = menuBuildSlider(GAMEPLAY_X + 126, GAMEPLAY_Y + 48, 126, SCROLL_TICKS); + + gameplayOptions->movingPortals.checked = (gSaveData.controls.flags & ControlSaveMoveablePortals) != 0; + gameplayOptions->wideScreen.checked = (gSaveData.controls.flags & ControlSaveWideScreen) != 0; + gameplayOptions->portalRenderDepth.value = (float)(gSaveData.controls.portalRenderDepth / PORTAL_RENDER_DEPTH_MAX); + gameplayOptions->render_depth = (0xFFFF/PORTAL_RENDER_DEPTH_MAX)* gSaveData.controls.portalRenderDepth; + gameplayOptionsHandleSlider(&gameplayOptions->render_depth, &gameplayOptions->portalRenderDepth.value); +} + enum MenuDirection gameplayOptionsUpdate(struct GameplayOptions* gameplayOptions) { int controllerDir = controllerGetDirectionDown(0); @@ -115,7 +117,9 @@ enum MenuDirection gameplayOptionsUpdate(struct GameplayOptions* gameplayOptions } } case GameplayOptionPortalRenderDepth: - gameplayOptionsHandleSlider(&gSaveData.controls.portalRenderDepth, &gameplayOptions->portalRenderDepth.value); + + gameplayOptionsHandleSlider(&gameplayOptions->render_depth, &gameplayOptions->portalRenderDepth.value); + gSaveData.controls.portalRenderDepth = (int)((gameplayOptions->render_depth * (1.0f/0xFFFF) * PORTAL_RENDER_DEPTH_MAX)); break; break; } diff --git a/src/menu/gameplay_options.h b/src/menu/gameplay_options.h index 68b1d44..035529c 100644 --- a/src/menu/gameplay_options.h +++ b/src/menu/gameplay_options.h @@ -18,6 +18,7 @@ struct GameplayOptions { struct MenuSlider portalRenderDepth; Gfx* portalRenderDepthText; short selectedItem; + unsigned short render_depth; }; void gameplayOptionsInit(struct GameplayOptions* gameplayOptions); diff --git a/src/savefile/savefile.c b/src/savefile/savefile.c index c9fe2fc..7f9ca61 100755 --- a/src/savefile/savefile.c +++ b/src/savefile/savefile.c @@ -94,7 +94,7 @@ void savefileNew() { gSaveData.controls.sensitivity = 0x4000; gSaveData.controls.acceleration = 0x4000; gSaveData.controls.deadzone = 0x4000; - gSaveData.controls.portalRenderDepth = 0x4000; + gSaveData.controls.portalRenderDepth = 2; gSaveData.audio.soundVolume = 0xFF; gSaveData.audio.musicVolume = 0xFF; diff --git a/src/savefile/savefile.h b/src/savefile/savefile.h index 6146a4b..e81fe3b 100755 --- a/src/savefile/savefile.h +++ b/src/savefile/savefile.h @@ -47,7 +47,7 @@ struct ControlSaveState { unsigned short flags; unsigned short sensitivity; unsigned short acceleration; - unsigned short portalRenderDepth; + int portalRenderDepth; unsigned short deadzone; }; diff --git a/src/scene/dynamic_render_list.c b/src/scene/dynamic_render_list.c index 7f5a284..8f8beb7 100644 --- a/src/scene/dynamic_render_list.c +++ b/src/scene/dynamic_render_list.c @@ -184,7 +184,7 @@ void dynamicRenderListPopulate(struct DynamicRenderDataList* list, struct Render continue; } - if (stages[stageIndex].currentDepth == ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)) && (object->flags & DYNAMIC_SCENE_OBJECT_SKIP_ROOT)) { + if (stages[stageIndex].currentDepth == gSaveData.controls.portalRenderDepth && (object->flags & DYNAMIC_SCENE_OBJECT_SKIP_ROOT)) { continue; } diff --git a/src/scene/render_plan.c b/src/scene/render_plan.c index 310a5d2..9f8ddf7 100644 --- a/src/scene/render_plan.c +++ b/src/scene/render_plan.c @@ -32,7 +32,7 @@ void renderPropsInit(struct RenderProps* props, struct Camera* camera, float asp cameraSetupMatrices(camera, renderState, aspectRatio, &fullscreenViewport, 1, &props->cameraMatrixInfo); props->viewport = &fullscreenViewport; - props->currentDepth = ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)); + props->currentDepth = gSaveData.controls.portalRenderDepth; props->exitPortalIndex = NO_PORTAL; props->fromRoom = roomIndex; props->parentStageIndex = -1; @@ -70,12 +70,12 @@ void renderPropscheckViewportSize(int* min, int* max, int screenSize) { } int renderPropsZDistance(int currentDepth) { - if (currentDepth >= ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX))) { + if (currentDepth >= gSaveData.controls.portalRenderDepth) { return 0; } else if (currentDepth < 0) { return G_MAXZ; } else { - return G_MAXZ - (G_MAXZ >> (((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)) - currentDepth)); + return G_MAXZ - (G_MAXZ >> (gSaveData.controls.portalRenderDepth - currentDepth)); } } @@ -337,7 +337,7 @@ int renderShouldRenderOtherPortal(struct Scene* scene, int visiblePortal, struct return 0; } - if ((scene->player.body.flags & (RigidBodyIsTouchingPortalA << visiblePortal)) != 0 && properties->currentDepth == ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX))) { + if ((scene->player.body.flags & (RigidBodyIsTouchingPortalA << visiblePortal)) != 0 && properties->currentDepth == gSaveData.controls.portalRenderDepth) { return 1; } @@ -415,9 +415,9 @@ void renderPlanFinishView(struct RenderPlan* renderPlan, struct Scene* scene, st } void renderPlanAdjustViewportDepth(struct RenderPlan* renderPlan) { - float depthWeight[((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)) + 1]; + float depthWeight[gSaveData.controls.portalRenderDepth + 1]; - for (int i = 0; i <= ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)); ++i) { + for (int i = 0; i <= gSaveData.controls.portalRenderDepth; ++i) { depthWeight[i] = 0.0f; } @@ -431,21 +431,21 @@ void renderPlanAdjustViewportDepth(struct RenderPlan* renderPlan) { float totalWeight = 0.0f; - for (int i = 0; i <= ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)); ++i) { + for (int i = 0; i <= gSaveData.controls.portalRenderDepth; ++i) { totalWeight += depthWeight[i]; } // give the main view a larger slice of the depth buffer - totalWeight += depthWeight[((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX))]; - depthWeight[((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX))] *= 2.0f; + totalWeight += depthWeight[gSaveData.controls.portalRenderDepth]; + depthWeight[gSaveData.controls.portalRenderDepth] *= 2.0f; float scale = (float)G_MAXZ / totalWeight; - short zBufferBoundary[((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)) + 2]; + short zBufferBoundary[gSaveData.controls.portalRenderDepth + 2]; - zBufferBoundary[((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)) + 1] = 0; + zBufferBoundary[gSaveData.controls.portalRenderDepth + 1] = 0; - for (int i = ((int)(gSaveData.controls.portalRenderDepth * (1.0f / 0xFFFF) * PORTAL_RENDER_DEPTH_MAX)); i >= 0; --i) { + for (int i = gSaveData.controls.portalRenderDepth; i >= 0; --i) { zBufferBoundary[i] = (short)(scale * depthWeight[i]) + zBufferBoundary[i + 1]; zBufferBoundary[i] = MIN(zBufferBoundary[i], G_MAXZ);