Skip to content

Commit

Permalink
More work on OpenGL stuff; got vegastrike-engine to build again final…
Browse files Browse the repository at this point in the history
…ly 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.
  • Loading branch information
stephengtuggy committed Apr 28, 2024
1 parent a9a6f03 commit 4a15edc
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 49 deletions.
2 changes: 0 additions & 2 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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" "$<$<CONFIG:Debug>:BOOST_DEBUG_PYTHON>")
set_property(TARGET vegastrike-testing PROPERTY POSITION_INDEPENDENT_CODE TRUE)
Expand Down
2 changes: 1 addition & 1 deletion engine/src/gfx/mesh_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Mesh::~Mesh() {
}
vector<Mesh *> *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");
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/gfx/mesh_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Mesh::~Mesh() {
}
vector<Mesh *> *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");
}
Expand Down
5 changes: 3 additions & 2 deletions engine/src/gldrv/gl_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");;
Expand Down
49 changes: 10 additions & 39 deletions engine/src/gldrv/winsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <assert.h>
#include <sstream>
#include <SDL/SDL_keyboard.h>

#include "gl_globals.h"
#include "winsys.h"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion engine/src/gldrv/winsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions engine/src/vega_collection_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@
#include "vega_collection_utils.h"
#include <algorithm>

template<typename T> void remove_all_references_to(const T *thus, owner<std::vector<T *> *> &vec, bool& collection_was_deleted) {
template<typename T>
void remove_all_references_to(const T *thus, std::vector<T *> *&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<Mesh>(const Mesh *thus, owner<std::vector<Mesh *> *> &vec, bool delete_collection_if_empty, bool& collection_was_deleted);
17 changes: 16 additions & 1 deletion engine/src/vega_collection_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
#include <functional>
#include "owner.h"

template<typename T> void remove_all_references_to(const T *thus, owner<std::vector<T *> *> &vec, bool& collection_was_deleted);
template<typename T>
void remove_all_references_to(const T *thus, std::vector<T *> *&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

0 comments on commit 4a15edc

Please sign in to comment.