From 4a15edcc83d696bf24bbcdccf95cff2961f4c569 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Sun, 28 Apr 2024 14:42:22 -0700 Subject: [PATCH] More work on OpenGL stuff; got vegastrike-engine to build again finally on macOS! Yay! Also, replaced the functionality of the winsys_enable_key_repeat function, which used SDL constructs that are deprecated in SDL2. Finally, moved the definition of remove_all_references_to into the header file (vega_collection_utils.h), rendering vega_collection_utils.cpp obsolete. --- engine/CMakeLists.txt | 2 -- engine/src/gfx/mesh_gfx.cpp | 2 +- engine/src/gfx/mesh_server.cpp | 2 +- engine/src/gldrv/gl_init.cpp | 5 +-- engine/src/gldrv/winsys.cpp | 49 ++++++---------------------- engine/src/gldrv/winsys.h | 1 - engine/src/vega_collection_utils.cpp | 10 ++++-- engine/src/vega_collection_utils.h | 17 +++++++++- 8 files changed, 39 insertions(+), 49 deletions(-) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index f4a496f8c..8c6bd880a 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -1090,7 +1090,6 @@ ADD_LIBRARY(vegastrike-engine_com ${LIBROOTGENERIC_SOURCES} ${LIBSCRIPT_SOURCES} ${LIBGFXGENERIC_SOURCES} - src/vega_collection_utils.cpp ) #TARGET_COMPILE_FEATURES(vegastrike-engine_com PUBLIC cxx_std_11) @@ -1704,7 +1703,6 @@ IF (USE_GTEST) ${LIBRESOURCE} ${LIBCMD_SOURCES} ${LIBVS_LOGGING} - src/vega_collection_utils.cpp ) target_compile_definitions(vegastrike-testing PUBLIC "BOOST_ALL_DYN_LINK" "$<$:BOOST_DEBUG_PYTHON>") set_property(TARGET vegastrike-testing PROPERTY POSITION_INDEPENDENT_CODE TRUE) diff --git a/engine/src/gfx/mesh_gfx.cpp b/engine/src/gfx/mesh_gfx.cpp index 6b2bedcbd..88fa0cfc9 100644 --- a/engine/src/gfx/mesh_gfx.cpp +++ b/engine/src/gfx/mesh_gfx.cpp @@ -440,7 +440,7 @@ Mesh::~Mesh() { } vector *hashers = bfxmHashTable.Get(hash_name); bool hashers_was_deleted = false; - remove_all_references_to(this, hashers, hashers_was_deleted); + remove_all_references_to(this, hashers, true, hashers_was_deleted); if (hashers_was_deleted) { VS_LOG_AND_FLUSH(debug, "hashers was deleted"); } diff --git a/engine/src/gfx/mesh_server.cpp b/engine/src/gfx/mesh_server.cpp index 2419076a6..bf33fdca5 100644 --- a/engine/src/gfx/mesh_server.cpp +++ b/engine/src/gfx/mesh_server.cpp @@ -119,7 +119,7 @@ Mesh::~Mesh() { } vector *hashers = bfxmHashTable.Get(hash_name); bool hashers_was_deleted = false; - remove_all_references_to(this, hashers, hashers_was_deleted); + remove_all_references_to(this, hashers, true, hashers_was_deleted); if (hashers_was_deleted) { VS_LOG_AND_FLUSH(debug, "hashers was deleted"); } diff --git a/engine/src/gldrv/gl_init.cpp b/engine/src/gldrv/gl_init.cpp index b65e4cfec..3cbafe984 100644 --- a/engine/src/gldrv/gl_init.cpp +++ b/engine/src/gldrv/gl_init.cpp @@ -586,8 +586,9 @@ void GFXInit(int argc, char **argv) { char vsicon[9] = "vega.ico"; winsys_init(&argc, argv, &vsname[0], &vsicon[0]); - /* Ignore key-repeat messages */ - winsys_enable_key_repeat(false); + /* Note: We have a different way to ignore key-repeat messages in SDL2. Now we just ignore any SDL_KEYDOWN event + * with the "repeat" field set to true, I guess, or something like that. -- stephengtuggy 2024-04-28 */ +// winsys_enable_key_repeat(false); glViewport(0, 0, g_game.x_resolution, g_game.y_resolution); static GFXColor clearcol = vs_config->getColor("space_background");; diff --git a/engine/src/gldrv/winsys.cpp b/engine/src/gldrv/winsys.cpp index 9f2d24c13..d07f01d95 100644 --- a/engine/src/gldrv/winsys.cpp +++ b/engine/src/gldrv/winsys.cpp @@ -25,7 +25,6 @@ #include #include -#include #include "gl_globals.h" #include "winsys.h" @@ -352,23 +351,6 @@ void winsys_shutdown() { keepRunning = false; } -/*---------------------------------------------------------------------------*/ -/*! - * Enables/disables key repeat messages from being generated - * \return - * \author jfpatry - * \date Created: 2000-10-19 - * \date Modified: 2000-10-19 - */ -void winsys_enable_key_repeat(bool enabled) { - if (enabled) { - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, - SDL_DEFAULT_REPEAT_INTERVAL); - } else { - SDL_EnableKeyRepeat(0, 0); - } -} - /*---------------------------------------------------------------------------*/ /*! * Shows/hides mouse cursor @@ -418,17 +400,19 @@ void winsys_process_events() { switch (event.type) { case SDL_KEYUP: state = true; - //does same thing as KEYDOWN, but with different state. + if (keyboard_func) { + SDL_GetMouseState(&x, &y); + + //Send the event + (*keyboard_func)(event.key.keysym.sym, event.key.keysym.mod, + state, + x, y); + } + break; case SDL_KEYDOWN: - if (keyboard_func) { + if (keyboard_func && (event.key.repeat == 0)) { SDL_GetMouseState(&x, &y); -// VS_LOG(debug, (boost::format("Kbd: %1$s mod:%2$x sym:%3$x scan:%4$x") -// % ((event.type == SDL_KEYUP) ? "KEYUP" : "KEYDOWN") -// % event.key.keysym.mod -// % event.key.keysym.sym -// % event.key.keysym.scancode -// )); //Send the event (*keyboard_func)(event.key.keysym.sym, event.key.keysym.mod, @@ -787,19 +771,6 @@ void winsys_shutdown() } } -/*---------------------------------------------------------------------------*/ -/*! - * Enables/disables key repeat messages from being generated - * \return - * \author jfpatry - * \date Created: 2000-10-19 - * \date Modified: 2000-10-19 - */ -void winsys_enable_key_repeat( bool enabled ) -{ - glutIgnoreKeyRepeat( !enabled ); -} - /*---------------------------------------------------------------------------*/ /*! * Shows/hides mouse cursor diff --git a/engine/src/gldrv/winsys.h b/engine/src/gldrv/winsys.h index 642c1bd0b..ac030ee00 100644 --- a/engine/src/gldrv/winsys.h +++ b/engine/src/gldrv/winsys.h @@ -318,7 +318,6 @@ void winsys_set_motion_func(winsys_motion_func_t func); void winsys_set_passive_motion_func(winsys_motion_func_t func); void winsys_swap_buffers(); -void winsys_enable_key_repeat(bool enabled); void winsys_warp_pointer(int x, int y); void winsys_show_cursor(bool visible); diff --git a/engine/src/vega_collection_utils.cpp b/engine/src/vega_collection_utils.cpp index f8f5dd966..82fa1fd4f 100644 --- a/engine/src/vega_collection_utils.cpp +++ b/engine/src/vega_collection_utils.cpp @@ -25,17 +25,23 @@ #include "vega_collection_utils.h" #include -template void remove_all_references_to(const T *thus, owner *> &vec, bool& collection_was_deleted) { +template +void remove_all_references_to(const T *thus, std::vector *&vec, bool delete_collection_if_empty, + bool &collection_was_deleted) { if (vec) { if (!vec->empty()) { auto first_to_remove = std::stable_partition(vec->begin(), vec->end(), [thus](const T *pi) { return pi != thus; }); vec->erase(first_to_remove, vec->end()); } - if (vec->empty()) { + if (vec->empty() && delete_collection_if_empty) { delete vec; vec = nullptr; collection_was_deleted = true; } } } + +class Mesh; + +template<> void remove_all_references_to(const Mesh *thus, owner *> &vec, bool delete_collection_if_empty, bool& collection_was_deleted); diff --git a/engine/src/vega_collection_utils.h b/engine/src/vega_collection_utils.h index bdde2c4fd..19a93787b 100644 --- a/engine/src/vega_collection_utils.h +++ b/engine/src/vega_collection_utils.h @@ -29,6 +29,21 @@ #include #include "owner.h" -template void remove_all_references_to(const T *thus, owner *> &vec, bool& collection_was_deleted); +template +void remove_all_references_to(const T *thus, std::vector *&vec, bool delete_collection_if_empty, + bool &collection_was_deleted) { + if (vec) { + if (!vec->empty()) { + auto first_to_remove = std::stable_partition(vec->begin(), vec->end(), + [thus](const T *pi) { return pi != thus; }); + vec->erase(first_to_remove, vec->end()); + } + if (vec->empty() && delete_collection_if_empty) { + delete vec; + vec = nullptr; + collection_was_deleted = true; + } + } +} #endif //VEGA_STRIKE_VEGA_COLLECTION_UTILS_H