Skip to content

Commit

Permalink
winsys.cpp, lin_time.cpp: More on how the main loop(s) work(s). Also …
Browse files Browse the repository at this point in the history
…vs_logging.cpp: Don't log after STATIC_VARS_DESTROYED.
  • Loading branch information
stephengtuggy committed Apr 30, 2024
1 parent c40a519 commit a2e06c7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
17 changes: 10 additions & 7 deletions engine/src/gldrv/winsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ static bool setup_sdl_video_mode() {
VS_LOG_FLUSH_EXIT(fatal, "No GL context", 1);
}

// This makes our buffer swap synchronized with the monitor's vertical refresh
SDL_GL_SetSwapInterval(1);

VS_LOG_AND_FLUSH(important_info, (boost::format("GL Vendor: %1%") % glGetString(GL_VENDOR)));
VS_LOG_AND_FLUSH(important_info, (boost::format("GL Renderer: %1%") % glGetString(GL_RENDERER)));
VS_LOG_AND_FLUSH(important_info, (boost::format("GL Version: %1%") % glGetString(GL_VERSION)));
Expand Down Expand Up @@ -326,7 +329,7 @@ static bool setup_sdl_video_mode() {
void winsys_init(int *argc, char **argv, char const *window_title, char const *icon_title) {
keepRunning = true;

Uint32 sdl_flags = SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS | SDL_INIT_TIMER;
Uint32 sdl_flags = SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
g_game.x_resolution = game_options()->x_resolution;
g_game.y_resolution = game_options()->y_resolution;
gl_options.fullscreen = game_options()->fullscreen;
Expand All @@ -340,18 +343,18 @@ void winsys_init(int *argc, char **argv, char const *window_title, char const *i
exit(1); // stephengtuggy 2020-07-27 - I would use VSExit here, but that calls winsys_exit, which I'm not sure will work if winsys_init hasn't finished yet.
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

//signal( SIGSEGV, SIG_DFL );
SDL_Surface *icon = nullptr;
if (icon_title) {
icon = SDL_LoadBMP(icon_title);
}
if (icon) {
// SDL_BlitSurface(i)
SDL_SetColorKey(icon, SDL_TRUE, ((Uint32 *) (icon->pixels))[0]);
}
/*
* Init video
*/
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

#if defined (USE_STENCIL_BUFFER)
/* Not sure if this is sufficient to activate stencil buffer */
Expand Down Expand Up @@ -507,8 +510,8 @@ void winsys_process_events() {
/* Delay for a bit. This allows the other threads to do some
* work (otherwise the audio thread gets starved). */
}
// SDL_GL_SwapWindow(window);
SDL_Delay(1);
winsys_swap_buffers();
SDL_Delay(2);
}
winsys_cleanup();
}
Expand Down
6 changes: 6 additions & 0 deletions engine/src/lin_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ void micro_sleep( unsigned int n )
(void) usleep( (useconds_t) n );
}

#elif defined (__APPLE__) && defined (__MACH__)

void micro_sleep(unsigned int n) {
usleep(static_cast<useconds_t>(n));
}

#else

void micro_sleep(unsigned int n) {
Expand Down
19 changes: 17 additions & 2 deletions engine/src/vs_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "vs_logging.h"
#include "vs_exit.h"
#include "vs_globals.h"

#include <string>
#include <cstdint>
Expand Down Expand Up @@ -86,7 +87,9 @@ void VegaStrikeLogger::InitLoggingPart2(const uint8_t debug_level,
}

void VegaStrikeLogger::FlushLogs() {
logging_core_->flush();
if (!STATIC_VARS_DESTROYED) {
logging_core_->flush();
}
std::cout << std::flush;
std::cerr << std::flush;
std::clog << std::flush;
Expand All @@ -95,12 +98,15 @@ void VegaStrikeLogger::FlushLogs() {
}

void VegaStrikeLogger::FlushLogsProgramExiting() {
logging_core_->flush();
if (!STATIC_VARS_DESTROYED) {
logging_core_->flush();
}
std::cout << std::flush;
std::cerr << std::flush;
std::clog << std::flush;
fflush(stdout);
fflush(stderr);
STATIC_VARS_DESTROYED = true;
}

BOOST_LOG_GLOBAL_LOGGER_INIT(my_logger, severity_logger_mt<vega_log_level>) {
Expand Down Expand Up @@ -128,6 +134,9 @@ VegaStrikeLogger::~VegaStrikeLogger() {
}

void VegaStrikeLogger::Log(const vega_log_level level, const std::string &message) {
if (STATIC_VARS_DESTROYED) {
return;
}
boost::log::record rec = slg_.open_record(boost::log::keywords::severity = level);
if (rec)
{
Expand All @@ -150,6 +159,9 @@ void VegaStrikeLogger::LogFlushExit(const vega_log_level level, const std::strin
}

void VegaStrikeLogger::Log(const vega_log_level level, const char *message) {
if (STATIC_VARS_DESTROYED) {
return;
}
boost::log::record rec = slg_.open_record(boost::log::keywords::severity = level);
if (rec)
{
Expand All @@ -172,6 +184,9 @@ void VegaStrikeLogger::LogFlushExit(const vega_log_level level, const char* mess
}

void VegaStrikeLogger::Log(const vega_log_level level, const boost::basic_format<char> &message) {
if (STATIC_VARS_DESTROYED) {
return;
}
boost::log::record rec = slg_.open_record(boost::log::keywords::severity = level);
if (rec)
{
Expand Down

0 comments on commit a2e06c7

Please sign in to comment.