Migrate to OFApplicationDelegate
FossilOrigin-Name: 9432e52ca0f52d0661ae65c0cebbf1fa9259a4d3459b4f6df4927fa4ac18c609
This commit is contained in:
parent
86576fa026
commit
1e8d1cfbef
3 changed files with 42 additions and 28 deletions
|
@ -2,8 +2,20 @@
|
||||||
|
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
void
|
OF_APPLICATION_DELEGATE(Cube)
|
||||||
cleanup(char *msg) // single program exit point;
|
|
||||||
|
@implementation Cube
|
||||||
|
- (void)showMessage: (OFString *)msg
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
MessageBoxW(NULL, msg.UTF16String, L"cube fatal error",
|
||||||
|
MB_OK | MB_SYSTEMMODAL);
|
||||||
|
#else
|
||||||
|
[OFStdOut writeString: msg];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillTerminate: (OFNotification *)notification
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
disconnect(true);
|
disconnect(true);
|
||||||
|
@ -12,31 +24,24 @@ cleanup(char *msg) // single program exit point;
|
||||||
cleansound();
|
cleansound();
|
||||||
cleanupserver();
|
cleanupserver();
|
||||||
SDL_ShowCursor(1);
|
SDL_ShowCursor(1);
|
||||||
if (msg) {
|
|
||||||
#ifdef _WIN32
|
|
||||||
MessageBox(
|
|
||||||
NULL, msg, "cube fatal error", MB_OK | MB_SYSTEMMODAL);
|
|
||||||
#else
|
|
||||||
printf(msg);
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
exit(1);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
quit() // normal exit
|
quit() // normal exit
|
||||||
{
|
{
|
||||||
writeservercfg();
|
writeservercfg();
|
||||||
cleanup(NULL);
|
[OFApplication.sharedApplication terminateWithStatus: 0];
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fatal(char *s, char *o) // failure exit
|
fatal(char *s, char *o) // failure exit
|
||||||
{
|
{
|
||||||
sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());
|
sprintf_sd(msg)("%s%s (%s)\n", s, o, SDL_GetError());
|
||||||
cleanup(msg);
|
OFApplication *app = OFApplication.sharedApplication;
|
||||||
};
|
[(Cube *)app.delegate showMessage: @(msg)];
|
||||||
|
[app terminateWithStatus: 1];
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
alloc(int s) // for some big chunks... most other allocs use the memory pool
|
alloc(int s) // for some big chunks... most other allocs use the memory pool
|
||||||
|
@ -45,7 +50,7 @@ alloc(int s) // for some big chunks... most other allocs use the memory pool
|
||||||
if (!b)
|
if (!b)
|
||||||
fatal("out of memory!");
|
fatal("out of memory!");
|
||||||
return b;
|
return b;
|
||||||
};
|
}
|
||||||
|
|
||||||
int scr_w = 640;
|
int scr_w = 640;
|
||||||
int scr_h = 480;
|
int scr_h = 480;
|
||||||
|
@ -78,7 +83,7 @@ screenshot()
|
||||||
};
|
};
|
||||||
SDL_FreeSurface(image);
|
SDL_FreeSurface(image);
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
COMMAND(screenshot, ARG_NONE);
|
COMMAND(screenshot, ARG_NONE);
|
||||||
COMMAND(quit, ARG_NONE);
|
COMMAND(quit, ARG_NONE);
|
||||||
|
@ -88,7 +93,7 @@ keyrepeat(bool on)
|
||||||
{
|
{
|
||||||
SDL_EnableKeyRepeat(
|
SDL_EnableKeyRepeat(
|
||||||
on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL);
|
on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||||
};
|
}
|
||||||
|
|
||||||
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
|
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
|
||||||
VARP(minmillis, 0, 5, 1000);
|
VARP(minmillis, 0, 5, 1000);
|
||||||
|
@ -96,13 +101,19 @@ VARP(minmillis, 0, 5, 1000);
|
||||||
int islittleendian = 1;
|
int islittleendian = 1;
|
||||||
int framesinmap = 0;
|
int framesinmap = 0;
|
||||||
|
|
||||||
int
|
- (void)applicationDidFinishLaunching: (OFNotification *)notification
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
bool dedicated = false;
|
bool dedicated = false;
|
||||||
int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = 4;
|
int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = 4;
|
||||||
char *sdesc = "", *ip = "", *master = NULL, *passwd = "";
|
char *sdesc = "", *ip = "", *master = NULL, *passwd = "";
|
||||||
islittleendian = *((char *)&islittleendian);
|
islittleendian = *((char *)&islittleendian);
|
||||||
|
int argc, *argcPtr;
|
||||||
|
char **argv, ***argvPtr;
|
||||||
|
|
||||||
|
[OFApplication.sharedApplication getArgumentCount: &argcPtr
|
||||||
|
andArgumentValues: &argvPtr];
|
||||||
|
argc = *argcPtr;
|
||||||
|
argv = *argvPtr;
|
||||||
|
|
||||||
processInitQueue();
|
processInitQueue();
|
||||||
|
|
||||||
|
@ -249,7 +260,7 @@ main(int argc, char **argv)
|
||||||
player1->yaw += 5;
|
player1->yaw += 5;
|
||||||
gl_drawframe(scr_w, scr_h, fps);
|
gl_drawframe(scr_w, scr_h, fps);
|
||||||
player1->yaw -= 5;
|
player1->yaw -= 5;
|
||||||
};
|
}
|
||||||
gl_drawframe(scr_w, scr_h, fps);
|
gl_drawframe(scr_w, scr_h, fps);
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int lasttype = 0, lastbut = 0;
|
int lasttype = 0, lastbut = 0;
|
||||||
|
@ -285,9 +296,9 @@ main(int argc, char **argv)
|
||||||
lasttype = event.type;
|
lasttype = event.type;
|
||||||
lastbut = event.button.button;
|
lastbut = event.button.button;
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
quit();
|
quit();
|
||||||
return 1;
|
}
|
||||||
};
|
@end
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
|
@interface Cube: OFObject <OFApplicationDelegate>
|
||||||
|
@end
|
||||||
|
|
||||||
enum // block types, order matters!
|
enum // block types, order matters!
|
||||||
{
|
{
|
||||||
SOLID = 0, // entirely solid cube [only specifies wtex]
|
SOLID = 0, // entirely solid cube [only specifies wtex]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
executable('client',
|
executable('client',
|
||||||
[
|
[
|
||||||
|
'Cube.mm',
|
||||||
'client.mm',
|
'client.mm',
|
||||||
'clientextras.mm',
|
'clientextras.mm',
|
||||||
'clientgame.mm',
|
'clientgame.mm',
|
||||||
|
@ -9,7 +10,6 @@ executable('client',
|
||||||
'editing.mm',
|
'editing.mm',
|
||||||
'entities.mm',
|
'entities.mm',
|
||||||
'init.mm',
|
'init.mm',
|
||||||
'main.mm',
|
|
||||||
'menus.mm',
|
'menus.mm',
|
||||||
'monster.mm',
|
'monster.mm',
|
||||||
'physics.mm',
|
'physics.mm',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue