mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-17 18:36:43 +02:00
#15 exit game from menu
This commit is contained in:
@@ -246,6 +246,7 @@ namespace Core {
|
|||||||
} settings;
|
} settings;
|
||||||
|
|
||||||
bool resetState;
|
bool resetState;
|
||||||
|
bool isQuit;
|
||||||
|
|
||||||
int getTime() {
|
int getTime() {
|
||||||
return osGetTime();
|
return osGetTime();
|
||||||
@@ -255,6 +256,10 @@ namespace Core {
|
|||||||
lastTime = getTime();
|
lastTime = getTime();
|
||||||
resetState = true;
|
resetState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void quit() {
|
||||||
|
isQuit = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
@@ -550,6 +555,8 @@ namespace Core {
|
|||||||
tinf_init();
|
tinf_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
isQuit = false;
|
||||||
|
|
||||||
Input::init();
|
Input::init();
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
void *libGL = dlopen("libGLESv2.so", RTLD_LAZY);
|
void *libGL = dlopen("libGLESv2.so", RTLD_LAZY);
|
||||||
|
@@ -514,7 +514,12 @@ struct Inventory {
|
|||||||
switch (item->value) {
|
switch (item->value) {
|
||||||
case 0 : nextLevel = passportSlots[slot]; break;
|
case 0 : nextLevel = passportSlots[slot]; break;
|
||||||
case 1 : nextLevel = level->isTitle() ? level->getStartId() : id; break;
|
case 1 : nextLevel = level->isTitle() ? level->getStartId() : id; break;
|
||||||
case 2 : nextLevel = level->isTitle() ? TR::LVL_MAX : level->getTitleId(); break;
|
case 2 :
|
||||||
|
if (!level->isTitle())
|
||||||
|
nextLevel = level->getTitleId();
|
||||||
|
else
|
||||||
|
Core::quit(); // exit game
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextLevel != TR::LVL_MAX) {
|
if (nextLevel != TR::LVL_MAX) {
|
||||||
|
@@ -214,12 +214,12 @@ int main(int argc, char **argv) {
|
|||||||
sndInit();
|
sndInit();
|
||||||
Game::init(argc > 1 ? argv[1] : NULL);
|
Game::init(argc > 1 ? argv[1] : NULL);
|
||||||
|
|
||||||
while (1) {
|
while (!Core::isQuit) {
|
||||||
if (XPending(dpy)) {
|
if (XPending(dpy)) {
|
||||||
XEvent event;
|
XEvent event;
|
||||||
XNextEvent(dpy, &event);
|
XNextEvent(dpy, &event);
|
||||||
if (event.type == ClientMessage && *event.xclient.data.l == WM_DELETE_WINDOW)
|
if (event.type == ClientMessage && *event.xclient.data.l == WM_DELETE_WINDOW)
|
||||||
break;
|
Core::quit();
|
||||||
WndProc(event,dpy,wnd);
|
WndProc(event,dpy,wnd);
|
||||||
} else {
|
} else {
|
||||||
pthread_mutex_lock(&sndMutex);
|
pthread_mutex_lock(&sndMutex);
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
bool isQuit = false;
|
|
||||||
WindowRef window;
|
WindowRef window;
|
||||||
AGLContext context;
|
AGLContext context;
|
||||||
|
|
||||||
@@ -71,7 +70,7 @@ OSStatus eventHandler(EventHandlerCallRef handler, EventRef event, void* userDat
|
|||||||
case kEventClassWindow :
|
case kEventClassWindow :
|
||||||
switch (eventKind) {
|
switch (eventKind) {
|
||||||
case kEventWindowClosed :
|
case kEventWindowClosed :
|
||||||
isQuit = true;
|
Core::quit();
|
||||||
break;
|
break;
|
||||||
case kEventWindowBoundsChanged : {
|
case kEventWindowBoundsChanged : {
|
||||||
aglUpdateContext(context);
|
aglUpdateContext(context);
|
||||||
@@ -202,7 +201,7 @@ int main() {
|
|||||||
ShowWindow(window);
|
ShowWindow(window);
|
||||||
|
|
||||||
EventRecord event;
|
EventRecord event;
|
||||||
while (!isQuit)
|
while (!Core::isQuit)
|
||||||
if (!GetNextEvent(0xffff, &event) && Game::update()) {
|
if (!GetNextEvent(0xffff, &event) && Game::update()) {
|
||||||
Game::render();
|
Game::render();
|
||||||
aglSwapBuffers(context);
|
aglSwapBuffers(context);
|
||||||
|
@@ -468,13 +468,12 @@ int main(int argc, char **argv) {
|
|||||||
sndInit();
|
sndInit();
|
||||||
|
|
||||||
char *lvlName = argc > 1 ? argv[1] : NULL;
|
char *lvlName = argc > 1 ? argv[1] : NULL;
|
||||||
char *sndName = argc > 2 ? argv[2] : NULL;
|
|
||||||
|
|
||||||
Game::init(lvlName, sndName);
|
Game::init(lvlName);
|
||||||
|
|
||||||
inputInit(); // initialize and grab input devices
|
inputInit(); // initialize and grab input devices
|
||||||
|
|
||||||
while (!Input::down[ikEscape]) {
|
while (!Core::isQuit) {
|
||||||
inputUpdate();
|
inputUpdate();
|
||||||
|
|
||||||
pthread_mutex_lock(&sndMutex);
|
pthread_mutex_lock(&sndMutex);
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
|
int osStartTime = 0;
|
||||||
|
|
||||||
int osGetTime() {
|
int osGetTime() {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
LARGE_INTEGER Freq, Count;
|
LARGE_INTEGER Freq, Count;
|
||||||
@@ -24,7 +26,7 @@ int osGetTime() {
|
|||||||
return int(Count.QuadPart * 1000L / Freq.QuadPart);
|
return int(Count.QuadPart * 1000L / Freq.QuadPart);
|
||||||
#else
|
#else
|
||||||
timeBeginPeriod(0);
|
timeBeginPeriod(0);
|
||||||
return int(timeGetTime());
|
return int(timeGetTime()) - osStartTime;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,6 +359,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
Sound::channelsCount = 0;
|
Sound::channelsCount = 0;
|
||||||
|
|
||||||
|
osStartTime = osGetTime();
|
||||||
|
|
||||||
touchInit(hWnd);
|
touchInit(hWnd);
|
||||||
joyInit();
|
joyInit();
|
||||||
sndInit(hWnd);
|
sndInit(hWnd);
|
||||||
@@ -371,10 +375,12 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
do {
|
while (!Core::isQuit) {
|
||||||
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
|
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
|
if (msg.message == WM_QUIT)
|
||||||
|
Core::quit();
|
||||||
} else {
|
} else {
|
||||||
joyUpdate();
|
joyUpdate();
|
||||||
if (Game::update()) {
|
if (Game::update()) {
|
||||||
@@ -385,7 +391,7 @@ int main(int argc, char** argv) {
|
|||||||
Sleep(20);
|
Sleep(20);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} while (msg.message != WM_QUIT);
|
};
|
||||||
|
|
||||||
sndFree();
|
sndFree();
|
||||||
Game::deinit();
|
Game::deinit();
|
||||||
|
Reference in New Issue
Block a user