Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengtuggy committed Apr 30, 2024
1 parent 9c21d7d commit 363182c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 37 deletions.
2 changes: 1 addition & 1 deletion engine/src/cmd/ai/firekeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ bool ChooseTargets(Unit *me, bool (*typeofunit)(Unit *, Unit *), bool reverse) {
for (un_iter iter = drawlist.createIterator(); (target = *iter) != NULL; ++iter) {
vec.push_back(target);
}
if (vec.size() == 0) {
if (vec.empty()) {
return false;
}
if (reverse) {
Expand Down
51 changes: 33 additions & 18 deletions engine/src/gldrv/winsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ static bool setup_sdl_video_mode() {
int width, height;
if (gl_options.fullscreen) {
video_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
} else {
}
else
{
#ifndef _WIN32
video_flags |= SDL_WINDOW_RESIZABLE;
#endif
Expand All @@ -221,7 +223,7 @@ static bool setup_sdl_video_mode() {
game_options()->rgb_pixel_format = ((bpp == 16) ? "555" : "888");
}
if ((game_options()->rgb_pixel_format.length() == 3) && isdigit(game_options()->rgb_pixel_format[0])
&& isdigit(game_options()->rgb_pixel_format[1]) && isdigit(game_options()->rgb_pixel_format[2])) {
&& isdigit(game_options()->rgb_pixel_format[1]) && isdigit(game_options()->rgb_pixel_format[2])) {
rs = game_options()->rgb_pixel_format[0] - '0';
gs = game_options()->rgb_pixel_format[1] - '0';
bs = game_options()->rgb_pixel_format[2] - '0';
Expand All @@ -236,7 +238,9 @@ static bool setup_sdl_video_mode() {
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, bs);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, game_options()->z_pixel_format);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
} else {
}
else
{
otherattributes = 5;
otherbpp = 16;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rs);
Expand All @@ -261,7 +265,9 @@ static bool setup_sdl_video_mode() {

if (SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl")) {
VS_LOG_AND_FLUSH(important_info, "SDL_SetHint(SDL_HINT_RENDER_DRIVER, ...) succeeded");
} else {
}
else
{
VS_LOG_AND_FLUSH(error, (boost::format("SDL_SetHint(SDL_HINT_RENDER_DRIVER, ...) failed. Error: %1%") % SDL_GetError()));
SDL_ClearError();
}
Expand All @@ -281,36 +287,41 @@ static bool setup_sdl_video_mode() {
VS_LOG_FLUSH_EXIT(fatal, "Failed to make window context current", 1);
}

SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (renderer == nullptr) {
VS_LOG_AND_FLUSH(error, (boost::format(
"SDL_CreateRenderer(...) with VSync option failed; trying again without VSync option. Error was: %1%") %
SDL_GetError()));
"SDL_CreateRenderer(...) with VSync option failed; trying again without VSync option. Error was: %1%") %
SDL_GetError()));
SDL_ClearError();

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == nullptr) {
VS_LOG_AND_FLUSH(error, (boost::format(
"SDL_CreateRenderer(...) with SDL_RENDERER_ACCELERATED failed; trying again with software rendering option. Error was: %1%") %
SDL_GetError()));
"SDL_CreateRenderer(...) with SDL_RENDERER_ACCELERATED failed; trying again with software rendering option. Error was: %1%") %
SDL_GetError()));
SDL_ClearError();

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (renderer == nullptr) {
VS_LOG_FLUSH_EXIT(fatal, (boost::format(
"SDL_CreateRenderer(...) failed on the third try, with software rendering! Error: %1%") %
SDL_GetError()),
1);
"SDL_CreateRenderer(...) failed on the third try, with software rendering! Error: %1%") %
SDL_GetError()),
1);
}
}
}

if (SDL_RenderSetLogicalSize(renderer, width, height) < 0) {
VS_LOG_FLUSH_EXIT(fatal, (boost::format("SDL_RenderSetLogicalSize(...) failed! Error: %1%") % SDL_GetError()),
8);
8);
}

std::string version = (const char *) glGetString(GL_RENDERER);
#if defined (GL_RENDERER)
std::string version{};
const GLubyte * renderer_string = glGetString(GL_RENDERER);
if (renderer_string) {
version = (const char*)renderer_string;
}
if (version == "GDI Generic" || version == "software") {
if (game_options()->gl_accelerated_visual) {
VS_LOG_AND_FLUSH(error, "GDI Generic software driver reported, trying to reset.");
Expand All @@ -323,6 +334,7 @@ static bool setup_sdl_video_mode() {
VS_LOG_AND_FLUSH(error, "Please make sure a graphics card driver is installed and functioning properly.");
}
}
#endif

// This makes our buffer swap synchronized with the monitor's vertical refresh
if (SDL_GL_SetSwapInterval(1) < 0) {
Expand Down Expand Up @@ -454,6 +466,9 @@ void winsys_process_events() {
memset(keysym_to_unicode, 0, sizeof(keysym_to_unicode));
}
double timeLastChecked = realTime();
if (timeLastChecked == INFINITY) {
timeLastChecked = 0;
}
while (keepRunning) {
SDL_LockAudio();
SDL_UnlockAudio();
Expand Down Expand Up @@ -547,10 +562,10 @@ void winsys_process_events() {
} while (realTime() < timeLastChecked + REFRESH_RATE);
timeLastChecked = realTime();

// // Blue
// glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT);
// winsys_swap_buffers();
// Blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
winsys_swap_buffers();
}
winsys_cleanup();
}
Expand Down
54 changes: 37 additions & 17 deletions engine/src/lin_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ VSRandom vsrandom(time(NULL));
#define NOMINMAX
#endif //tells VCC not to generate min/max macros
#include <windows.h>
static LONGLONG ttime;
static LONGLONG newtime = 0;
static LONGLONG freq;
static alignas(16) LARGE_INTEGER ttime{};
static alignas(16) LARGE_INTEGER newtime{};
static alignas(16) LARGE_INTEGER freq{};
static double dblnewtime;
#else
#if defined (HAVE_SDL)
Expand Down Expand Up @@ -169,8 +169,8 @@ void micro_sleep(unsigned int n) {

void InitTime() {
#ifdef WIN32
QueryPerformanceFrequency( (LARGE_INTEGER*) &freq );
QueryPerformanceCounter( (LARGE_INTEGER*) &ttime );
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&ttime);

#elif defined (_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
Expand Down Expand Up @@ -201,9 +201,13 @@ double GetElapsedTime() {

double queryTime() {
#ifdef WIN32
LONGLONG tmpnewtime;
QueryPerformanceCounter( (LARGE_INTEGER*) &tmpnewtime );
return ( (double) tmpnewtime )/(double) freq-firsttime;
alignas(16) LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
double tmpnewtime = 0;
if (freq.QuadPart > 0) {
tmpnewtime = static_cast<double>(ticks.QuadPart / freq.QuadPart);
}
return tmpnewtime - firsttime;
#elif defined (_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
Expand All @@ -225,9 +229,15 @@ double queryTime() {

double realTime() {
#ifdef WIN32
LONGLONG tmpnewtime;
QueryPerformanceCounter( (LARGE_INTEGER*) &tmpnewtime );
return ( (double) tmpnewtime )/(double) freq;
alignas(16) LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
double tmpnewtime = 0;
if (freq.QuadPart > 0) {
tmpnewtime = static_cast<double>(ticks.QuadPart / freq.QuadPart);
}
if (tmpnewtime == INFINITY) {
tmpnewtime = 0;
}
#elif defined (_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
Expand All @@ -250,15 +260,25 @@ double realTime() {
void UpdateTime() {
static bool first = true;
#ifdef WIN32
QueryPerformanceCounter( (LARGE_INTEGER*) &newtime );
elapsedtime = ( (double) (newtime-ttime) )/freq;
alignas(16) LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);
double tmpnewtime = 0;
if (freq.QuadPart > 0) {
tmpnewtime = static_cast<double>(ticks.QuadPart / freq.QuadPart);
}
if (tmpnewtime == INFINITY) {
tmpnewtime = 0;
}
double tmpttime = 0;
if (freq.QuadPart > 0) {
tmpttime = static_cast<double>(ttime.QuadPart / freq.QuadPart);
}
elapsedtime = (tmpnewtime - tmpttime);
ttime = newtime;
if (freq == 0)
dblnewtime = 0.;
else
dblnewtime = ( (double) newtime )/( (double) freq );
if (first)
{
firsttime = dblnewtime;
}
#elif defined(_POSIX_MONOTONIC_CLOCK)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
Expand Down
4 changes: 3 additions & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ int main(int argc, char *argv[]) {
}
_Universe = new Universe(argc, argv, game_options()->galaxy.c_str());
TheTopLevelUnit = new Unit(0);
InitTime();
_Universe->Loop(bootstrap_first_loop);

//Unregister commands - and cleanup memory
Expand Down Expand Up @@ -536,6 +537,7 @@ void bootstrap_first_loop() {
bs_tp = new TextPlane();
}
bootstrap_draw("Vegastrike Loading...", SplashScreen);
//InitTime();
if (i++ > 4) {
if (_Universe) {
if (game_options()->main_menu) {
Expand All @@ -557,7 +559,7 @@ void SetStartupView(Cockpit *cp) {

void bootstrap_main_loop() {
static bool LoadMission = true;
InitTime();
//InitTime();
if (LoadMission) {
LoadMission = false;
active_missions.push_back(mission = new Mission(mission_name));
Expand Down

0 comments on commit 363182c

Please sign in to comment.