#include "scenes.h" #include #include #include #include Scene **sceneStack = NULL; size_t sceneStackDepth = 0; Scene *getCurrentScene() { if (sceneStackDepth == 0) return NULL; return sceneStack[sceneStackDepth - 1]; } Scene *getPreviousScene() { if (sceneStackDepth <= 1) return NULL; return sceneStack[sceneStackDepth - 2]; } bool InitSceneStack() { sceneStack = malloc(sizeof(Scene) * SCENE_STACK_SIZE); return sceneStack != NULL; } bool AddScene(Scene *newScene) { if (newScene == NULL || sceneStackDepth == SCENE_STACK_SIZE) return false; sceneStack[sceneStackDepth] = newScene; sceneStackDepth += 1; return true; } void DeleteSceneFromStack() { Scene *currentScene = getCurrentScene(); if (currentScene == NULL) return; PopUpState currentSceneState = POPUP_ACTIVE; if (currentScene->GetCurrentState != NULL) currentSceneState = currentScene->GetCurrentState(currentScene); currentScene->Deint(currentScene); sceneStack[--sceneStackDepth] = NULL; Scene *prevoiusScene = getCurrentScene(); if (prevoiusScene == NULL || prevoiusScene->Reopen == NULL) return; prevoiusScene->Reopen(prevoiusScene, currentSceneState); } bool DrawScene() { Scene *currentScene = getCurrentScene(); if (currentScene == NULL) return false; if (currentScene->IsTransparent) { Scene *prevScene = getPreviousScene(); if (prevScene != NULL) prevScene->Draw(prevScene); } return currentScene->Draw(currentScene); } bool UpdateScene() { Scene *currentScene = getCurrentScene(); if (currentScene == NULL) return false; return currentScene->Update(currentScene); }