blob: f50097282259eaf83cadc6b140006ed0e59762f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include "scenes.h"
#include <raylib.h>
#include <stdlib.h>
#include <sys/types.h>
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 != 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);
}
|