-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstagestack.cpp
More file actions
77 lines (59 loc) · 1.11 KB
/
stagestack.cpp
File metadata and controls
77 lines (59 loc) · 1.11 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "stagestack.h"
StageStack::StageStack()
{
StackIndex = -1;
}
int StageStack::Push(Stage* newStage)
{
if( StackIndex == MAX_STACK_SIZE - 1 )
return -1;
// Pause any current stage
if( StackIndex != -1 )
this->Current()->Pause();
StackIndex++;
Stack[StackIndex] = newStage;
Stack[StackIndex]->Begin();
return 0;
}
Stage* StageStack::Pop()
{
Stage* result;
// Remove stage from stack
result = this->Current();
result->Finish();
Stack[StackIndex] = 0;
StackIndex--;
// If there's still an item on the stack, resume it
if( StackIndex != -1 )
this->Current()->Resume();
return result;
}
Stage* StageStack::Current()
{
if( StackIndex == -1 )
return 0;
return Stack[StackIndex];
}
int StageStack::GetStackIndex()
{
return StackIndex;
}
Stage* StageStack::Item(int index)
{
return Stack[index];
}
Stage* StageStack::Previous( Stage* checkStage )
{
if( StackIndex < 0 )
return 0;
for( int i = 0; i <= StackIndex; i++ )
{
if( Stack[i] == checkStage && i != 0 )
return Stack[i-1];
}
return 0;
}
bool StageStack::IsEmpty()
{
return (StackIndex < 0);
}