From 6c1efd5a297e4517c3ded93571e0064890ac6336 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 5 Nov 2018 04:16:08 +0100 Subject: [PATCH 1/4] GCC/Clang: Don't use -ffast-math, Debug Build with -O0 I don't trust -ffast-math, not even with -fno-unsafe-math-optimizations --- neo/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index c582660c..24e63733 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -154,12 +154,12 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options(-march=pentium3) endif() - set(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG -O1") + set(CMAKE_C_FLAGS_DEBUG "-g -ggdb -D_DEBUG -O0") set(CMAKE_C_FLAGS_DEBUGALL "-g -ggdb -D_DEBUG") set(CMAKE_C_FLAGS_PROFILE "-g -ggdb -D_DEBUG -O1 -fno-omit-frame-pointer") - set(CMAKE_C_FLAGS_RELEASE "-O2 -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer") - set(CMAKE_C_FLAGS_MINSIZEREL "-Os -ffast-math -fno-unsafe-math-optimizations -fomit-frame-pointer") + set(CMAKE_C_FLAGS_RELEASE "-O2 -fno-unsafe-math-optimizations -fno-math-errno -fno-trapping-math -fomit-frame-pointer") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -fno-unsafe-math-optimizations -fno-math-errno -fno-trapping-math -fno-omit-frame-pointer") + set(CMAKE_C_FLAGS_MINSIZEREL "-Os -fno-unsafe-math-optimizations -fno-math-errno -fno-trapping-math -fomit-frame-pointer") set(CMAKE_CXX_FLAGS_DEBUGALL ${CMAKE_C_FLAGS_DEBUGALL}) set(CMAKE_CXX_FLAGS_PROFILE ${CMAKE_C_FLAGS_PROFILE}) From cd0a11f974f8c3295b7b9b5c7e06b4414ba2c705 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 5 Nov 2018 04:32:04 +0100 Subject: [PATCH 2/4] Allow scaling non-menu WIN_DESKTOP GUIs to 4:3 WIN_DESKTOP means that this can currently only be set for the top-level window in a .gui (all its subwindows/widgets will be scaled implicitly) There are two ways to make a GUI use this: 1. in the .gui add a window variable "scaleto43 1", like windowDef Desktop { rect 0 ,0 ,640 ,480 nocursor 1 float talk 0 scaleto43 1 // .. etc rest of windowDef 2. When creating the GUI from C++ code, you can afterwards make the UserInterface scale to 4:3 like this: idUserInterface* ui = Whatever(); // create it ui->SetStateBool("scaleto43", true); ui->StateChanged(gameLocal.time); Both lines are important! As you can see in my changes to Player.cpp, my primary usecase for this is the cursor/crosshair GUI. --- neo/d3xp/Player.cpp | 7 +++++++ neo/game/Player.cpp | 7 +++++++ neo/ui/UserInterface.cpp | 13 +++++++++++++ neo/ui/Window.cpp | 22 ++++++++++++++++++---- neo/ui/Window.h | 2 ++ 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/neo/d3xp/Player.cpp b/neo/d3xp/Player.cpp index dc779dfe..34956f38 100644 --- a/neo/d3xp/Player.cpp +++ b/neo/d3xp/Player.cpp @@ -1779,6 +1779,13 @@ void idPlayer::Spawn( void ) { cursor = uiManager->FindGui( temp, true, gameLocal.isMultiplayer, gameLocal.isMultiplayer ); } if ( cursor ) { + // DG: make it scale to 4:3 so crosshair looks properly round + // yes, like so many scaling-related things this is a bit hacky + // and note that this is special cased in StateChanged and you + // can *not* generally set windowDef properties like this. + cursor->SetStateBool("scaleto43", true); + cursor->StateChanged(gameLocal.time); // DG end + cursor->Activate( true, gameLocal.time ); } diff --git a/neo/game/Player.cpp b/neo/game/Player.cpp index e3878fa7..b8018182 100644 --- a/neo/game/Player.cpp +++ b/neo/game/Player.cpp @@ -1464,6 +1464,13 @@ void idPlayer::Spawn( void ) { cursor = uiManager->FindGui( temp, true, gameLocal.isMultiplayer, gameLocal.isMultiplayer ); } if ( cursor ) { + // DG: make it scale to 4:3 so crosshair looks properly round + // yes, like so many scaling-related things this is a bit hacky + // and note that this is special cased in StateChanged and you + // can *not* generally set windowDef properties like this. + cursor->SetStateBool("scaleto43", true); + cursor->StateChanged(gameLocal.time); // DG end + cursor->Activate( true, gameLocal.time ); } diff --git a/neo/ui/UserInterface.cpp b/neo/ui/UserInterface.cpp index 5a60a22b..9e595e36 100644 --- a/neo/ui/UserInterface.cpp +++ b/neo/ui/UserInterface.cpp @@ -462,6 +462,19 @@ float idUserInterfaceLocal::GetStateFloat( const char *varName, const char* defa void idUserInterfaceLocal::StateChanged( int _time, bool redraw ) { time = _time; if (desktop) { + // DG: little hack: allow game DLLs to do + // ui->SetStateBool("scaleto43", true); + // ui->StateChanged(gameLocal.time); + // so we can force cursors.gui (crosshair) to be scaled, for example + bool scaleTo43 = false; + if(state.GetBool("scaleto43", "0", scaleTo43)) { + if(scaleTo43) + desktop->SetFlag(WIN_SCALETO43); + else + desktop->ClearFlag(WIN_SCALETO43); + } + // DG end + desktop->StateChanged( redraw ); } if ( state.GetBool( "noninteractive" ) ) { diff --git a/neo/ui/Window.cpp b/neo/ui/Window.cpp index 3de88f0b..5658d0c9 100644 --- a/neo/ui/Window.cpp +++ b/neo/ui/Window.cpp @@ -1210,10 +1210,15 @@ void idWindow::Redraw(float x, float y) { // DG: allow scaling menus to 4:3 bool fixupFor43 = false; - if ( (flags & (WIN_MENUGUI | WIN_DESKTOP)) == (WIN_MENUGUI | WIN_DESKTOP) - && r_scaleMenusTo43.GetBool() ) { - fixupFor43 = true; - dc->SetMenuScaleFix(true); + if ( flags & WIN_DESKTOP ) { + // only scale desktop windows (will automatically scale its sub-windows) + // that EITHER have the scaleto43 flag set OR are fullscreen menus and r_scaleMenusTo43 is 1 + if( (flags & WIN_SCALETO43) || + ((flags & WIN_MENUGUI) && r_scaleMenusTo43.GetBool()) ) + { + fixupFor43 = true; + dc->SetMenuScaleFix(true); + } } if ( flags & WIN_SHOWTIME ) { @@ -1941,6 +1946,15 @@ bool idWindow::ParseInternalVar(const char *_name, idParser *src) { } return true; } + // DG: added this window flag for Windows that should be scaled to 4:3 + // (with "empty" bars left/right or above/below) + if (idStr::Icmp(_name, "scaleto43") == 0) { + if ( src->ParseBool() ) { + flags |= WIN_SCALETO43; + } + return true; + } + // DG end if (idStr::Icmp(_name, "forceaspectwidth") == 0) { forceAspectWidth = src->ParseFloat(); return true; diff --git a/neo/ui/Window.h b/neo/ui/Window.h index 2d2af631..96f6534e 100644 --- a/neo/ui/Window.h +++ b/neo/ui/Window.h @@ -65,6 +65,8 @@ const int WIN_WANTENTER = 0x01000000; const int WIN_DESKTOP = 0x10000000; +const int WIN_SCALETO43 = 0x20000000; // DG: for the "scaleto43" window flag (=> scale window to 4:3 with "empty" bars left/right or above/below) + const char CAPTION_HEIGHT[] = "16.0"; const char SCROLLER_SIZE[] = "16.0"; const int SCROLLBAR_SIZE = 16; From f407b2b8e98c2f00ed6e53556382a4b582d89e57 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 5 Nov 2018 04:33:46 +0100 Subject: [PATCH 3/4] Increase Script MAX_GLOBALS in vanilla game DLL It's the same value d3xp uses. This is for mods that have their own (more complex) scripts, but use the standard base.dll/.so --- neo/game/script/Script_Program.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/game/script/Script_Program.h b/neo/game/script/Script_Program.h index 59756770..ae602841 100644 --- a/neo/game/script/Script_Program.h +++ b/neo/game/script/Script_Program.h @@ -44,7 +44,7 @@ class idSaveGame; class idRestoreGame; #define MAX_STRING_LEN 128 -#define MAX_GLOBALS 196608 // in bytes +#define MAX_GLOBALS 296608 // in bytes - DG: increased this for better support of mods that use the vanilla game dll #define MAX_STRINGS 1024 #define MAX_FUNCS 3072 #define MAX_STATEMENTS 81920 // statement_t - 18 bytes last I checked From f5dfdead439a442f968e51ee3e74963025fdfcaa Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 5 Nov 2018 04:54:53 +0100 Subject: [PATCH 4/4] Do the cursor/crosshair scaling to 4:3 also when loading savegame --- neo/d3xp/Player.cpp | 6 ++++++ neo/game/Player.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/neo/d3xp/Player.cpp b/neo/d3xp/Player.cpp index 34956f38..966c49ec 100644 --- a/neo/d3xp/Player.cpp +++ b/neo/d3xp/Player.cpp @@ -2473,6 +2473,12 @@ void idPlayer::Restore( idRestoreGame *savefile ) { savefile->ReadInt( focusTime ); savefile->ReadObject( reinterpret_cast( focusVehicle ) ); savefile->ReadUserInterface( cursor ); + // DG: make it scale to 4:3 so crosshair looks properly round + // yes, like so many scaling-related things this is a bit hacky + // and note that this is special cased in StateChanged and you + // can *not* generally set windowDef properties like this. + cursor->SetStateBool("scaleto43", true); + cursor->StateChanged(gameLocal.time); // DG end savefile->ReadInt( oldMouseX ); savefile->ReadInt( oldMouseY ); diff --git a/neo/game/Player.cpp b/neo/game/Player.cpp index b8018182..8caaab4b 100644 --- a/neo/game/Player.cpp +++ b/neo/game/Player.cpp @@ -2033,6 +2033,13 @@ void idPlayer::Restore( idRestoreGame *savefile ) { savefile->ReadObject( reinterpret_cast( focusVehicle ) ); savefile->ReadUserInterface( cursor ); + // DG: make it scale to 4:3 so crosshair looks properly round + // yes, like so many scaling-related things this is a bit hacky + // and note that this is special cased in StateChanged and you + // can *not* generally set windowDef properties like this. + cursor->SetStateBool("scaleto43", true); + cursor->StateChanged(gameLocal.time); // DG end + savefile->ReadInt( oldMouseX ); savefile->ReadInt( oldMouseY );