mirror of
https://github.com/cxong/cdogs-sdl.git
synced 2025-07-23 07:23:01 +02:00
Add --demo option for auto quitting #253
This commit is contained in:
@@ -55,9 +55,6 @@ script:
|
||||
# Match install prefix with data dir so that package contains everything required
|
||||
- cmake -DCMAKE_INSTALL_PREFIX=. -DDATA_INSTALL_DIR=. -Wno-dev .
|
||||
- make -j2
|
||||
|
||||
# Tests are broken on osx. Hope this will be fixed some day
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make test ; fi
|
||||
- ctest -VV -S
|
||||
|
||||
after_success:
|
||||
|
@@ -55,9 +55,6 @@ script:
|
||||
# Match install prefix with data dir so that package contains everything required
|
||||
- cmake -DCMAKE_INSTALL_PREFIX=. -DDATA_INSTALL_DIR=. -Wno-dev .
|
||||
- make -j2
|
||||
|
||||
# Tests are broken on osx. Hope this will be fixed some day
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make test ; fi
|
||||
- ctest -VV -S
|
||||
|
||||
after_success:
|
||||
|
@@ -22,7 +22,7 @@
|
||||
This file incorporates work covered by the following copyright and
|
||||
permission notice:
|
||||
|
||||
Copyright (c) 2013-2017, 2019-2020 Cong Xu
|
||||
Copyright (c) 2013-2017, 2019-2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -152,7 +152,8 @@ int main(int argc, char *argv[])
|
||||
char buf[CDOGS_PATH_MAX];
|
||||
ProcessCommandLine(buf, argc, argv);
|
||||
LOG(LM_MAIN, LL_INFO, "Command line (%d args):%s", argc, buf);
|
||||
if (!ParseArgs(argc, argv, &connectAddr, &loadCampaign))
|
||||
int demoQuitTimer = 0;
|
||||
if (!ParseArgs(argc, argv, &connectAddr, &loadCampaign, &demoQuitTimer))
|
||||
{
|
||||
goto bail;
|
||||
}
|
||||
@@ -189,6 +190,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
EventInit(&gEventHandlers);
|
||||
gEventHandlers.DemoQuitTimer = demoQuitTimer;
|
||||
NetServerInit(&gNetServer);
|
||||
PicManagerInit(&gPicManager);
|
||||
TileClassesInit(&gTileClasses);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
Copyright (c) 2013-2016, 2018-2020 Cong Xu
|
||||
Copyright (c) 2013-2016, 2018-2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -248,6 +248,17 @@ void EventPoll(
|
||||
GraphicsConfigSetFromConfig(&gGraphicsDevice.cachedConfig, &gConfig);
|
||||
GraphicsInitialize(&gGraphicsDevice);
|
||||
}
|
||||
|
||||
// Auto quit on timer
|
||||
if (handlers->DemoQuitTimer > 0)
|
||||
{
|
||||
handlers->DemoQuitTimer -= ticks;
|
||||
if (handlers->DemoQuitTimer <= 0)
|
||||
{
|
||||
LOG(LM_MAIN, LL_INFO, "Auto-quitting");
|
||||
handlers->HasQuit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int GetKeyboardCmd(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
Copyright (c) 2013-2017, 2020 Cong Xu
|
||||
Copyright (c) 2013-2017, 2020-2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,6 +45,7 @@ typedef struct
|
||||
bool HasResolutionChanged;
|
||||
bool HasQuit;
|
||||
bool HasLostFocus;
|
||||
int DemoQuitTimer;
|
||||
} EventHandlers;
|
||||
|
||||
extern EventHandlers gEventHandlers;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
|
||||
Copyright (c) 2013-2015, 2018 Cong Xu, davidrgmcb
|
||||
Copyright (c) 2013-2015, 2018, 2021 Cong Xu, davidrgmcb
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -59,7 +59,6 @@ void KeyInit(keyboard_t *keyboard)
|
||||
{
|
||||
memset(keyboard, 0, sizeof *keyboard);
|
||||
keyboard->modState = KMOD_NONE;
|
||||
keyboard->ticks = 0;
|
||||
keyboard->repeatedTicks = 0;
|
||||
keyboard->isFirstRepeat = 1;
|
||||
for (int i = 0; i < MAX_KEYBOARD_CONFIGS; i++)
|
||||
@@ -189,7 +188,7 @@ void DiagonalHold(keyboard_t *keyboard, int currentPlayer)
|
||||
//Propogates all changes to the keyboard state, when these are removed the function ceases to do anything.
|
||||
}
|
||||
|
||||
void KeyPostPoll(keyboard_t *keyboard, Uint32 ticks)
|
||||
void KeyPostPoll(keyboard_t *keyboard, const Uint32 ticks)
|
||||
{
|
||||
int isRepeating = 0;
|
||||
int areSameKeysPressed = 1;
|
||||
@@ -205,8 +204,7 @@ void KeyPostPoll(keyboard_t *keyboard, Uint32 ticks)
|
||||
// If same keys have been pressed, remember how long they have been pressed
|
||||
if (areSameKeysPressed)
|
||||
{
|
||||
Uint32 ticksElapsed = ticks - keyboard->ticks;
|
||||
keyboard->repeatedTicks += ticksElapsed;
|
||||
keyboard->repeatedTicks += ticks;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -248,7 +246,6 @@ void KeyPostPoll(keyboard_t *keyboard, Uint32 ticks)
|
||||
!keyboard->previousKeys[i].isPressed;
|
||||
}
|
||||
}
|
||||
keyboard->ticks = ticks;
|
||||
|
||||
for (int currentPlayer = 0; currentPlayer < MAX_KEYBOARD_CONFIGS; ++currentPlayer)
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
|
||||
Copyright (c) 2013-2015, 2018 Cong Xu
|
||||
Copyright (c) 2013-2015, 2018, 2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -89,7 +89,6 @@ typedef struct
|
||||
KeyPress pressedKeys[SDL_NUM_SCANCODES];
|
||||
SDL_Keymod modState;
|
||||
char Typed[32];
|
||||
Uint32 ticks;
|
||||
Uint32 repeatedTicks;
|
||||
bool isFirstRepeat;
|
||||
InputKeys PlayerKeys[MAX_KEYBOARD_CONFIGS];
|
||||
@@ -101,7 +100,7 @@ InputKeys KeyLoadPlayerKeys(Config *c);
|
||||
void KeyPrePoll(keyboard_t *keyboard);
|
||||
void KeyOnKeyDown(keyboard_t *keyboard, const SDL_Keysym s);
|
||||
void KeyOnKeyUp(keyboard_t *keyboard, const SDL_Keysym s);
|
||||
void KeyPostPoll(keyboard_t *keyboard, Uint32 ticks);
|
||||
void KeyPostPoll(keyboard_t *keyboard, const Uint32 ticks);
|
||||
bool KeyIsDown(const keyboard_t *k, const int key);
|
||||
bool KeyIsPressed(const keyboard_t *k, const int key);
|
||||
bool KeyIsReleased(const keyboard_t *k, const int key);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
|
||||
Copyright (c) 2013-2015, 2019-2020 Cong Xu
|
||||
Copyright (c) 2013-2015, 2019-2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -108,7 +108,7 @@ void MouseOnWheel(Mouse *m, const Sint32 x, const Sint32 y)
|
||||
m->wheel = svec2i(x, y);
|
||||
}
|
||||
|
||||
void MousePostPoll(Mouse *mouse, Uint32 ticks)
|
||||
void MousePostPoll(Mouse *mouse, const Uint32 ticks)
|
||||
{
|
||||
int areSameButtonsPressed = 1;
|
||||
int i;
|
||||
@@ -124,8 +124,7 @@ void MousePostPoll(Mouse *mouse, Uint32 ticks)
|
||||
// pressed
|
||||
if (areSameButtonsPressed)
|
||||
{
|
||||
Uint32 ticksElapsed = ticks - mouse->ticks;
|
||||
mouse->repeatedTicks += ticksElapsed;
|
||||
mouse->repeatedTicks += ticks;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -151,7 +150,6 @@ void MousePostPoll(Mouse *mouse, Uint32 ticks)
|
||||
mouse->currentButtons[i] && !mouse->previousButtons[i];
|
||||
}
|
||||
}
|
||||
mouse->ticks = ticks;
|
||||
}
|
||||
|
||||
bool MouseHasMoved(const Mouse *m)
|
||||
|
@@ -2,7 +2,7 @@
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
|
||||
Copyright (c) 2013-2015, 2019-2020 Cong Xu
|
||||
Copyright (c) 2013-2015, 2019-2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -44,7 +44,6 @@ typedef struct
|
||||
struct vec2i wheel;
|
||||
SDL_Cursor *cursor;
|
||||
const Pic *trail;
|
||||
Uint32 ticks;
|
||||
Uint32 repeatedTicks;
|
||||
|
||||
struct vec2i mouseMovePos;
|
||||
@@ -59,7 +58,7 @@ void MousePrePoll(Mouse *mouse);
|
||||
void MouseOnButtonDown(Mouse *mouse, Uint8 button);
|
||||
void MouseOnButtonUp(Mouse *mouse, Uint8 button);
|
||||
void MouseOnWheel(Mouse *m, const Sint32 x, const Sint32 y);
|
||||
void MousePostPoll(Mouse *mouse, Uint32 ticks);
|
||||
void MousePostPoll(Mouse *mouse, const Uint32 ticks);
|
||||
bool MouseHasMoved(const Mouse *m);
|
||||
int MouseGetPressed(const Mouse *m);
|
||||
bool MouseIsDown(const Mouse *m, const int button);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
Copyright (c) 2013-2016, 2019-2020 Cong Xu
|
||||
Copyright (c) 2013-2016, 2019-2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -89,15 +89,16 @@ void PrintHelp(void)
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
printf(" --log=M,L Enable logging for module M at level L.\n\n");
|
||||
printf(
|
||||
" --log=L Enable logging for all modules at level L.\n\n");
|
||||
printf(" --logfile=F Log to file by filename\n\n");
|
||||
" --log=M,L Enable logging for module M at level L.\n\n"
|
||||
" --log=L Enable logging for all modules at level L.\n\n"
|
||||
" --logfile=F Log to file by filename\n\n");
|
||||
|
||||
printf(
|
||||
"%s\n",
|
||||
"Other:\n"
|
||||
" --connect=host (Experimental) connect to a game server\n");
|
||||
" --connect=host (Experimental) connect to a game server\n"
|
||||
" --demo (Experimental) run game for 30 seconds\n");
|
||||
}
|
||||
|
||||
void ProcessCommandLine(char *buf, const int argc, char *argv[])
|
||||
@@ -121,7 +122,7 @@ void ProcessCommandLine(char *buf, const int argc, char *argv[])
|
||||
static void PrintConfig(const Config *c, const int indent);
|
||||
bool ParseArgs(
|
||||
const int argc, char *argv[], ENetAddress *connectAddr,
|
||||
const char **loadCampaign)
|
||||
const char **loadCampaign, int *demoQuitTimer)
|
||||
{
|
||||
struct option longopts[] = {
|
||||
{"fullscreen", no_argument, NULL, 'f'},
|
||||
@@ -131,6 +132,7 @@ bool ParseArgs(
|
||||
{"config", optional_argument, NULL, 'C'},
|
||||
{"log", required_argument, NULL, 1000},
|
||||
{"logfile", required_argument, NULL, 1001},
|
||||
{"demo", no_argument, NULL, 1002},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{0, 0, NULL, 0}};
|
||||
int opt = 0;
|
||||
@@ -192,6 +194,10 @@ bool ParseArgs(
|
||||
case 1001:
|
||||
LogOpenFile(optarg);
|
||||
break;
|
||||
case 1002:
|
||||
*demoQuitTimer = 30 * 1000;
|
||||
printf("Entering demo mode; will auto-quit in 30 seconds\n");
|
||||
break;
|
||||
case 'x':
|
||||
if (enet_address_set_host(connectAddr, optarg) != 0)
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
Copyright (c) 2013-2016, Cong Xu
|
||||
Copyright (c) 2013-2016, 2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,4 +41,4 @@ void ProcessCommandLine(char *buf, const int argc, char *argv[]);
|
||||
// Parse command-line arguments and set config. Returns whether to run the game
|
||||
bool ParseArgs(
|
||||
const int argc, char *argv[],
|
||||
ENetAddress *connectAddr, const char **loadCampaign);
|
||||
ENetAddress *connectAddr, const char **loadCampaign, int *demoQuitTimer);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
C-Dogs SDL
|
||||
A port of the legendary (and fun) action/arcade cdogs.
|
||||
|
||||
Copyright (c) 2014, 2016-2018 Cong Xu
|
||||
Copyright (c) 2014, 2016-2018, 2021 Cong Xu
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@@ -210,7 +210,7 @@ bool LoopRunnerRunInner(LoopRunInnerData *ctx)
|
||||
// Input
|
||||
if ((ctx->data->Frames & 1) || !ctx->data->InputEverySecondFrame)
|
||||
{
|
||||
EventPoll(&gEventHandlers, ctx->p.TicksNow, NULL);
|
||||
EventPoll(&gEventHandlers, ctx->p.TicksElapsed, NULL);
|
||||
if (ctx->data->InputFunc)
|
||||
{
|
||||
ctx->data->InputFunc(ctx->data);
|
||||
|
Reference in New Issue
Block a user