blobwarsAttrition/src/main.c

204 lines
3.2 KiB
C
Raw Normal View History

2018-01-21 10:31:38 +01:00
/*
2019-06-02 17:13:34 +02:00
Copyright (C) 2018-2019 Parallel Realities
2018-01-21 10:31:38 +01: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"
2018-07-07 08:00:55 +02:00
static void capFrameRate(long *then, float *remainder);
2018-02-03 14:07:56 +01:00
static void handleCommandLine(int argc, char *argv[]);
2018-01-21 10:31:38 +01:00
2018-02-03 14:07:56 +01:00
int main(int argc, char *argv[])
2018-01-21 10:31:38 +01:00
{
2018-02-02 09:26:58 +01:00
long then, nextSecond, frames;
2018-07-07 08:00:55 +02:00
float remainder;
2018-02-06 23:26:05 +01:00
memset(&app, 0, sizeof(App));
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
atexit(cleanup);
srand(time(NULL));
2019-06-02 17:13:34 +02:00
initLookups();
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
initSDL();
2019-06-02 17:13:34 +02:00
init18N(argc, argv);
2018-01-21 10:31:38 +01:00
initGameSystem();
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
handleCommandLine(argc, argv);
2019-06-02 17:13:34 +02:00
2018-02-02 09:26:58 +01:00
frames = 0;
2019-06-02 17:13:34 +02:00
2018-12-22 23:46:38 +01:00
remainder = 0;
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
nextSecond = SDL_GetTicks() + 1000;
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
while (1)
{
then = SDL_GetTicks();
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
handleInput();
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
app.delegate.logic();
2019-06-02 17:13:34 +02:00
2018-02-14 23:31:42 +01:00
doTrophyAlerts();
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
prepareScene();
app.delegate.draw();
2019-06-02 17:13:34 +02:00
2018-02-14 23:31:42 +01:00
drawTrophyAlert();
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
presentScene();
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
capFrameRate(&then, &remainder);
2019-06-02 17:13:34 +02:00
2018-02-02 09:26:58 +01:00
frames++;
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
if (SDL_GetTicks() >= nextSecond)
{
2018-02-02 09:26:58 +01:00
dev.fps = frames;
2019-06-02 17:13:34 +02:00
2018-02-02 09:26:58 +01:00
frames = 0;
2019-06-02 17:13:34 +02:00
2018-02-13 22:36:42 +01:00
game.stats[STAT_TIME_PLAYED]++;
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
nextSecond = SDL_GetTicks() + 1000;
2018-02-14 20:12:29 +01:00
awardTrophies();
2019-06-02 17:13:34 +02:00
2018-02-26 08:53:12 +01:00
if (dev.takeScreenshots)
{
saveScreenshot(NULL);
}
2018-01-21 10:31:38 +01:00
}
}
return 0;
}
2018-07-07 08:00:55 +02:00
static void capFrameRate(long *then, float *remainder)
2018-01-21 10:31:38 +01:00
{
long wait;
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
wait = 16 + *remainder;
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
*remainder -= (int)*remainder;
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
wait -= (SDL_GetTicks() - *then);
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
if (wait < 0)
2018-01-21 10:31:38 +01:00
{
2018-07-07 08:00:55 +02:00
wait = 1;
2018-01-21 10:31:38 +01:00
}
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
SDL_Delay(wait);
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
*remainder += 0.667;
2019-06-02 17:13:34 +02:00
2018-07-07 08:00:55 +02:00
*then = SDL_GetTicks();
2018-01-21 10:31:38 +01:00
}
2018-02-03 14:07:56 +01:00
static void handleCommandLine(int argc, char *argv[])
2018-01-21 10:31:38 +01:00
{
2018-05-13 09:59:30 +02:00
int i;
2018-03-09 19:26:04 +01:00
char *worldId;
worldId = NULL;
2019-06-02 17:13:34 +02:00
2018-01-21 10:31:38 +01:00
for (i = 1 ; i < argc ; i++)
{
2018-03-09 19:26:04 +01:00
if (strcmp(argv[i], "-debug") == 0)
{
dev.debug = 1;
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
2018-04-15 11:45:18 +02:00
createScreenshotFolder();
2018-03-09 19:26:04 +01:00
}
if (strcmp(argv[i], "-info") == 0)
{
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
}
if (strcmp(argv[i], "-blind") == 0)
{
dev.cheatBlind = 1;
}
if (strcmp(argv[i], "-noenemies") == 0)
{
dev.cheatNoEnemies = 1;
}
if (strcmp(argv[i], "-keys") == 0)
{
dev.cheatKeys = 1;
}
if (strcmp(argv[i], "-power") == 0)
{
dev.cheatPower = 1;
}
if (strcmp(argv[i], "-health") == 0)
{
dev.cheatHealth = 1;
}
if (strcmp(argv[i], "-levels") == 0)
{
dev.cheatLevels = 1;
}
if (strcmp(argv[i], "-screenshots") == 0)
{
dev.takeScreenshots = 1;
2018-04-15 11:45:18 +02:00
createScreenshotFolder();
2018-03-09 19:26:04 +01:00
}
if (strcmp(argv[i], "-world") == 0)
{
worldId = argv[++i];
}
2019-06-02 17:13:34 +02:00
2018-03-15 09:00:00 +01:00
if (strcmp(argv[i], "-ending") == 0)
{
initEnding();
return;
}
2019-06-02 17:13:34 +02:00
2018-03-16 09:28:25 +01:00
if (strcmp(argv[i], "-credits") == 0)
{
initCredits();
return;
}
2018-01-21 10:31:38 +01:00
}
2019-06-02 17:13:34 +02:00
2018-03-19 09:08:29 +01:00
if (worldId != NULL)
{
2018-05-13 09:59:30 +02:00
initWorldTest(worldId);
2018-03-19 09:08:29 +01:00
}
else
{
initTitle();
}
2018-01-21 10:31:38 +01:00
}