| 1138 | } |
| 1139 | |
| 1140 | void game_main_loop(GameApi* game, void* data) |
| 1141 | { |
| 1142 | bool need_exit = false; |
| 1143 | |
| 1144 | Core::Timer timer; |
| 1145 | timer.Start(); |
| 1146 | |
| 1147 | if (!game->init(game, timer, data)) |
| 1148 | { |
| 1149 | need_exit = true; |
| 1150 | } |
| 1151 | |
| 1152 | for (;;) |
| 1153 | { |
| 1154 | if (need_exit) |
| 1155 | { |
| 1156 | break; |
| 1157 | } |
| 1158 | |
| 1159 | if (game->poll_event(game) != 0) |
| 1160 | { |
| 1161 | if (game->process_event != nullptr) |
| 1162 | { |
| 1163 | game->process_event(game, timer.GetTimeS()); |
| 1164 | } |
| 1165 | continue; |
| 1166 | } |
| 1167 | |
| 1168 | if (game->is_paused(game)) |
| 1169 | { |
| 1170 | if (!timer.IsPaused()) |
| 1171 | { |
| 1172 | timer.Pause(); |
| 1173 | } |
| 1174 | |
| 1175 | game->wait_event(game); |
| 1176 | |
| 1177 | if (game->process_event != nullptr) |
| 1178 | { |
| 1179 | game->process_event(game, timer.GetTimeS()); |
| 1180 | } |
| 1181 | need_exit = game->need_exit(game); |
| 1182 | continue; |
| 1183 | } |
| 1184 | |
| 1185 | need_exit = game->need_exit(game); |
| 1186 | |
| 1187 | if (game->is_paused(game)) |
| 1188 | { |
| 1189 | if (!timer.IsPaused()) |
| 1190 | { |
| 1191 | timer.Pause(); |
| 1192 | } |
| 1193 | } else |
| 1194 | { |
| 1195 | if (timer.IsPaused()) |
| 1196 | { |
| 1197 | timer.Resume(); |