Skip to content

Commit

Permalink
More on STATIC_VARS_DESTROYED; also, "only" refresh 120 times per second
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengtuggy committed Apr 30, 2024
1 parent a2e06c7 commit aeac04e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions engine/objconv/basemaker/base_maker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ void VSSprite::GetRotation( float &rot )
}
*/

void VSExit(int code) {
STATIC_VARS_DESTROYED = true;
exit(code);
}

Expand Down
3 changes: 3 additions & 0 deletions engine/src/accountserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ using std::string;
#include "networking/acctserver.h"
#include "lin_time.h"

bool STATIC_VARS_DESTROYED = false;

void VSExit(int code) {
STATIC_VARS_DESTROYED = true;
exit(code);
}

Expand Down
1 change: 1 addition & 0 deletions engine/src/audio/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ void closeRenderer() {

void VSExit(int code) {
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
STATIC_VARS_DESTROYED = true;
exit(code);
}

Expand Down
3 changes: 3 additions & 0 deletions engine/src/exit_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
#include "vs_exit.h"
#include "vs_logging.h"

bool STATIC_VARS_DESTROYED = false;

void VSExit(int code) {
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
STATIC_VARS_DESTROYED = true;
exit(code);
}
9 changes: 7 additions & 2 deletions engine/src/gldrv/winsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <assert.h>
#include <sstream>
#include <lin_time.h>

#include "gl_globals.h"
#include "winsys.h"
Expand Down Expand Up @@ -69,6 +70,8 @@ static winsys_atexit_func_t atexit_func = nullptr;
static bool redisplay = false;
static bool keepRunning = true;

const double REFRESH_RATE = 1.0 / 120.0;

/*---------------------------------------------------------------------------*/
/*!
* Requests that the screen be redrawn
Expand Down Expand Up @@ -427,6 +430,7 @@ void winsys_process_events() {
keysym_to_unicode_init = true;
memset(keysym_to_unicode, 0, sizeof(keysym_to_unicode));
}
double timeLastChecked = realTime();
while (keepRunning) {
SDL_LockAudio();
SDL_UnlockAudio();
Expand Down Expand Up @@ -510,8 +514,9 @@ void winsys_process_events() {
/* Delay for a bit. This allows the other threads to do some
* work (otherwise the audio thread gets starved). */
}
winsys_swap_buffers();
SDL_Delay(2);
while (realTime() < timeLastChecked + REFRESH_RATE) {
SDL_Delay(1);
}
}
winsys_cleanup();
}
Expand Down
3 changes: 2 additions & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ int readCommandLineOptions(int argc, char **argv);
void VSExit(int code) {
Music::CleanupMuzak();
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
STATIC_VARS_DESTROYED = true;
winsys_exit(code);
}

void cleanup(void) {
STATIC_VARS_DESTROYED = true;
// stephengtuggy 2020-10-30: Output message both to the console and to the logs
printf("Thank you for playing!\n");
VS_LOG(info, "Thank you for playing!");
VegaStrikeLogging::VegaStrikeLogger::instance().FlushLogsProgramExiting();
STATIC_VARS_DESTROYED = true;
if (_Universe != NULL) {
_Universe->WriteSaveGame(true);
}
Expand Down
1 change: 1 addition & 0 deletions engine/src/vegaserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ float AUDIO_ATOM = 0.0f;

void VSExit(int code) {
VSServer->closeAllSockets();
STATIC_VARS_DESTROYED = true;
exit(1);
}

Expand Down

0 comments on commit aeac04e

Please sign in to comment.