tbftss/src/main.c

186 lines
3.1 KiB
C
Raw Normal View History

2015-10-20 13:51:49 +02:00
/*
2016-02-21 16:50:27 +01:00
Copyright (C) 2015-2016 Parallel Realities
2015-10-20 13:51:49 +02:00
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "main.h"
2015-12-20 13:25:20 +01:00
static void handleArguments(int argc, char *argv[]);
2015-10-20 13:51:49 +02:00
int main(int argc, char *argv[])
{
float td;
long then, lastFrameTime, frames;
2015-12-20 17:13:35 +01:00
long expireTextTimer;
2015-10-20 13:51:49 +02:00
SDL_Event event;
memset(&app, 0, sizeof(App));
2015-12-18 11:12:37 +01:00
memset(&dev, 0, sizeof(Dev));
2015-10-20 13:51:49 +02:00
atexit(cleanup);
srand(time(NULL));
init18N(argc, argv);
2016-03-03 19:03:07 +01:00
initLookups();
2015-10-20 13:51:49 +02:00
initSDL();
initGameSystem();
2015-12-20 13:25:20 +01:00
handleArguments(argc, argv);
2015-10-20 13:51:49 +02:00
2015-12-18 11:12:37 +01:00
dev.fps = frames = td = 0;
2015-10-20 13:51:49 +02:00
then = SDL_GetTicks();
lastFrameTime = SDL_GetTicks() + 1000;
2015-12-20 17:13:35 +01:00
expireTextTimer = SDL_GetTicks() + (1000 * 10);
2015-10-20 13:51:49 +02:00
while (1)
{
td += (SDL_GetTicks() - then);
then = SDL_GetTicks();
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_MOUSEMOTION:
doMouseMotion(&event.motion);
break;
case SDL_MOUSEWHEEL:
doMouseWheel(&event.wheel);
break;
2015-11-23 15:52:11 +01:00
case SDL_MOUSEBUTTONDOWN:
doMouseDown(&event.button);
break;
case SDL_MOUSEBUTTONUP:
doMouseUp(&event.button);
break;
2015-10-20 13:51:49 +02:00
case SDL_KEYDOWN:
doKeyDown(&event.key);
2015-10-20 13:51:49 +02:00
break;
case SDL_KEYUP:
doKeyUp(&event.key);
2015-10-20 13:51:49 +02:00
break;
case SDL_QUIT:
exit(0);
break;
}
}
2016-02-23 08:19:31 +01:00
if (app.modalDialog.type != MD_NONE)
{
doModalDialog();
}
2015-10-20 13:51:49 +02:00
while (td >= LOGIC_RATE)
{
app.delegate.logic();
td -= LOGIC_RATE;
game.stats[STAT_TIME]++;
2015-10-20 13:51:49 +02:00
}
prepareScene();
2015-10-20 13:51:49 +02:00
app.delegate.draw();
2016-02-23 08:19:31 +01:00
if (app.modalDialog.type != MD_NONE)
{
drawModalDialog();
}
presentScene();
2015-12-18 11:12:37 +01:00
doDevKeys();
2015-10-20 13:51:49 +02:00
frames++;
if (SDL_GetTicks() > lastFrameTime)
{
2015-12-18 11:12:37 +01:00
dev.fps = frames;
2015-10-20 13:51:49 +02:00
frames = 0;
lastFrameTime = SDL_GetTicks() + 1000;
2015-12-18 11:12:37 +01:00
if (dev.takeScreenshots)
{
saveScreenshot();
}
2015-10-20 13:51:49 +02:00
}
2015-12-20 17:13:35 +01:00
if (SDL_GetTicks() > expireTextTimer)
{
expireTexts(0);
expireTextTimer = SDL_GetTicks() + (1000 * 10);
}
/* always zero the mouse motion */
app.mouse.dx = app.mouse.dy = 0;
2015-10-20 13:51:49 +02:00
SDL_Delay(1);
}
return 0;
}
2015-12-20 13:25:20 +01:00
static void handleArguments(int argc, char *argv[])
{
int i;
int testingMission = 0;
for (i = 1 ; i < argc ; i++)
{
/* assume this is filename for testing */
if (argv[i][0] != '-')
{
loadTestMission(argv[i]);
testingMission = 1;
}
else
{
if (strcmp(argv[i], "-debug") == 0)
{
dev.debug = 1;
2016-03-06 10:48:09 +01:00
createScreenshotFolder();
2015-12-20 13:25:20 +01:00
}
}
}
if (!testingMission)
{
2016-02-27 17:16:21 +01:00
if (fileExists(getSaveFilePath("game.save")))
{
loadGame();
}
2015-12-20 13:25:20 +01:00
initTitle();
}
}