-
Notifications
You must be signed in to change notification settings - Fork 5
/
racestate.cpp
executable file
·212 lines (178 loc) · 5.52 KB
/
racestate.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/***************************************************************************
file : racestate.cpp
created : Sat Nov 16 12:00:42 CET 2002
copyright : (C) 2002-2014 by Eric Espie, Bernhard Wymann
email : [email protected]
version : $Id: racestate.cpp,v 1.5.2.5 2014/02/04 14:03:03 berniw Exp $
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/** @file
@author <a href=mailto:[email protected]>Eric Espie</a>
@version $Id: racestate.cpp,v 1.5.2.5 2014/02/04 14:03:03 berniw Exp $
*/
/* The Race Engine State Automaton */
#include <stdlib.h>
#include <stdio.h>
#include <tgfclient.h>
#include <raceman.h>
#include <racescreens.h>
#include "racemain.h"
#include "raceinit.h"
#include "raceengine.h"
#include "racegl.h"
#include "raceresults.h"
#include "racemanmenu.h"
#include "racestate.h"
static void *mainMenu;
/* State Automaton Init */
void
ReStateInit(void *prevMenu)
{
mainMenu = prevMenu;
}
#include <execinfo.h>
void print_stacktrace()
{
printf("\n\n\n\n\nstackstrace begin:\n");
int size = 16;
void * array[16];
int stack_num = backtrace(array, size);
char ** stacktrace = backtrace_symbols(array, stack_num);
for (int i = 0; i < stack_num; ++i)
{
printf("%s\n", stacktrace[i]);
}
free(stacktrace);
printf("stackstrace begin:\n\n\n\n\n");
}
/* State Automaton Management */
/* Called when a race menu is entered */
void
ReStateManage(void)
{
// print_stacktrace();
int mode = RM_SYNC | RM_NEXT_STEP;
do {
switch (ReInfo->_reState) {
case RE_STATE_CONFIG:
GfOut("RaceEngine: state = RE_STATE_CONFIG\n");
/* Display the race specific menu */
mode = ReRacemanMenu();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_EVENT_INIT;
}
break;
case RE_STATE_EVENT_INIT:
GfOut("RaceEngine: state = RE_STATE_EVENT_INIT\n");
/* Load the event description (track and drivers list) */
mode = ReRaceEventInit();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_PRE_RACE;
}
break;
case RE_STATE_PRE_RACE:
GfOut("RaceEngine: state = RE_STATE_PRE_RACE\n");
mode = RePreRace();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_RACE_START;
}
break;
case RE_STATE_RACE_START:
GfOut("RaceEngine: state = RE_STATE_RACE_START\n");
mode = ReRaceStart();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_RACE;
}
break;
case RE_STATE_RACE:
mode = ReUpdate();
if (ReInfo->s->_raceState == RM_RACE_ENDED) {
/* race finished */
ReInfo->_reState = RE_STATE_RACE_END;
} else if (mode & RM_END_RACE) {
/* interrupt by player */
ReInfo->_reState = RE_STATE_RACE_STOP;
}
/////////////////////////// by Yurong
else if (mode == RE_STATE_PRE_RACE) {
ReInfo->_reState = RE_STATE_PRE_RACE;
}
/////////////////////////// end by Yurong
break;
case RE_STATE_RACE_STOP:
GfOut("RaceEngine: state = RE_STATE_RACE_STOP\n");
/* Interrupted by player */
mode = ReRaceStop();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_RACE_END;
}
break;
case RE_STATE_RACE_END:
GfOut("RaceEngine: state = RE_STATE_RACE_END\n");
mode = ReRaceEnd();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_POST_RACE;
} else if (mode & RM_NEXT_RACE) {
ReInfo->_reState = RE_STATE_RACE_START;
}
break;
case RE_STATE_POST_RACE:
GfOut("RaceEngine: state = RE_STATE_POST_RACE\n");
mode = RePostRace();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_EVENT_SHUTDOWN;
} else if (mode & RM_NEXT_RACE) {
ReInfo->_reState = RE_STATE_PRE_RACE;
}
break;
case RE_STATE_EVENT_SHUTDOWN:
GfOut("RaceEngine: state = RE_STATE_EVENT_SHUTDOWN\n");
mode = ReEventShutdown();
if (mode & RM_NEXT_STEP) {
ReInfo->_reState = RE_STATE_SHUTDOWN;
} else if (mode & RM_NEXT_RACE) {
ReInfo->_reState = RE_STATE_EVENT_INIT;
}
break;
case RE_STATE_SHUTDOWN:
if (ReInfo->_displayMode == RM_DISP_MODE_CONSOLE) {
return;
}
case RE_STATE_ERROR:
GfOut("RaceEngine: state = RE_STATE_SHUTDOWN\n");
/* Back to race menu */
ReInfo->_reState = RE_STATE_CONFIG;
mode = RM_SYNC;
break;
case RE_STATE_EXIT:
printf("RaceEngine: state = RE_STATE_EXIT");
GfScrShutdown();
exit (0); /* brutal isn't it ? */
break;
}
// printf("========================= while condition is %d ================================\n", (mode & (RM_SYNC | RM_QUIT)) == RM_SYNC);
// fflush(stdout);
} while ((mode & (RM_SYNC | RM_QUIT)) == RM_SYNC);
if (mode & RM_QUIT) {
GfScrShutdown();
exit (0); /* brutal isn't it ? */
}
if (mode & RM_ACTIVGAMESCR) {
GfuiScreenActivate(ReInfo->_reGameScreen);
}
}
/* Change and Execute a New State */
void
ReStateApply(void *vstate)
{
long state = (long)vstate;
ReInfo->_reState = (int)state;
ReStateManage();
}