Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade SDL to version 2 #792

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions engine/CMakeLists.txt

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions engine/src/cmd/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "json.h"
#include <string.h>

#include "vs_logging.h"

/*! \brief Checks for an empty string
*
* @param str The string to check
Expand Down Expand Up @@ -388,6 +390,12 @@ std::vector<std::string> json::parsing::parse_array(const char *input)
// Initalize the result
std::vector<std::string> result;

if (input != nullptr) {
VS_LOG_AND_FLUSH(debug, boost::format("JSON Data: %s") % input);
} else {
VS_LOG_AND_FLUSH(debug, "Invalid JSON Input - NULL Pointer");
}

const char *index = json::parsing::tlws(input);
if (*index != '[') throw json::parsing_error("Input was not an array");
index++;
Expand Down
9 changes: 9 additions & 0 deletions engine/src/cmd/upgradeable_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "unit_generic.h"
#include "weapon_info.h"
#include "vega_cast_utils.h"
#include "vs_logging.h"

std::vector<std::string> ParseUnitUpgrades(const std::string &upgrades) {
if(upgrades.size() == 0) {
Expand Down Expand Up @@ -141,6 +142,14 @@ bool UpgradeableUnit::UpgradeMounts(const Unit *up,
return true;
}

// there needs to be some mounts to be able to mount to
if (num_mounts == 0) {
// would be nice to make this more meaningful but that's a little harder given
// the casting of `unit` from `this`.
VS_LOG(debug, "No mounts to attach to.");
return false;
}

int j = mountoffset;
int i = 0;
bool cancompletefully = true;
Expand Down
5 changes: 1 addition & 4 deletions engine/src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <vector>

#ifdef HAVE_SDL
# include <SDL/SDL.h>
# include <SDL2/SDL.h>
#endif

#include <string>
Expand Down Expand Up @@ -1605,9 +1605,6 @@ void BringConsole(const KBData &, KBSTATE newState) {
if (CommandInterpretor) {
winsys_set_keyboard_func((winsys_keyboard_func_t) &commandI::keypress);
CommandInterpretor->console = true;
#ifdef HAVE_SDL
SDL_EnableUNICODE(true);
#endif
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions engine/src/config_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "python/python_compile.h"
#include "gfx/screenshot.h"
#include "vs_logging.h"
#include "sdl_key_converter.h"

/* *********************************************************** */

Expand Down Expand Up @@ -355,8 +356,8 @@ void GameVegaConfig::checkBind(configNode *node) {
VS_LOG(warning, "not a bind node ");
return;
}
std::string tmp = node->attr_value("modifier");
int modifier = getModifier(tmp.c_str());
std::string modifier_string = node->attr_value("modifier");
int modifier = getModifier(modifier_string);

string cmdstr = node->attr_value("command");
string player_bound = node->attr_value("player");
Expand All @@ -371,7 +372,7 @@ void GameVegaConfig::checkBind(configNode *node) {
string player_str = node->attr_value("player");
string joy_str = node->attr_value("joystick");
string mouse_str = node->attr_value("mouse");
string keystr = node->attr_value("key");
const std::string keystr = node->attr_value("key");
string additional_data = node->attr_value("data");
string buttonstr = node->attr_value("button");
string hat_str = node->attr_value("hatswitch");
Expand All @@ -391,6 +392,7 @@ void GameVegaConfig::checkBind(configNode *node) {
//normal keyboard key
//now map the command to a callback function and bind it
if (keystr.length() == 1) {
const int sdl_key_value = SDLKeyConverter::Convert(keystr);
BindKey(keystr[0], modifier, XMLSupport::parse_int(player_bound), handler, KBData(additional_data));
} else {
int glut_key = key_map[keystr];
Expand Down
6 changes: 3 additions & 3 deletions engine/src/gfx/coord_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>.
*/


#include "cmd/unit_generic.h"
#include "star_system.h"
#include "loc_select.h"
Expand All @@ -38,10 +37,11 @@ int CoordinateSelectChange = 0;
int CoordinateSelectmousex;
int CoordinateSelectmousey;
extern Vector MouseCoordinate(int mouseX, int mouseY);
extern KBSTATE keyState[LAST_MODIFIER][KEYMAP_SIZE];

extern KBSTATE mouseButtonState;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um... what? Is it keyboard state or mouse button state?

At best, this is very confusing; at worst, it may not be correct at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks for a modifier key is also pressed ie:Ctrl,Alt etc

Copy link
Member

@BenjamenMeyer BenjamenMeyer Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh...it's our own definition - https://github.com/vegastrike/Vega-Strike-Engine-Source/blob/master/engine/src/in.h#L25

Perhaps it should be renamed to BUTTON_STATE or something - equally applies to Mouse, Keyboard, and even Joysticks and other inputs that way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the BUTTON_STATE idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mixed on whether that should be in this PR or a separate one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want this in this PR. It's a mostly cosmetic thing and will impact 520 instances in around 30 files. It's better to do it in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@royfalk OK, fair enough. That can be done in a separate PR.


void CoordinateSelect::MouseMoveHandle(KBSTATE, int x, int y, int, int, int) {
if (keyState[0]['z'] == DOWN) {
if (mouseButtonState == DOWN) {
CoordinateSelectChange = 2;
} else {
CoordinateSelectChange = 1;
Expand Down
5 changes: 3 additions & 2 deletions engine/src/gfx/loc_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "vs_globals.h"
#include <stdio.h>

extern KBSTATE mouseButtonState;

LocationSelect::LocationSelect(Vector start, Vector Plane1,
Vector Plane2 /*, System * par */ ) : LocSelAni("locationselect.ani",
true,
Expand Down Expand Up @@ -64,14 +66,13 @@ LocationSelect::LocationSelect(Vector start, Vector Plane1, Vector Plane2,
MoveLocation(start, Plane1, Plane2, Plane3);
}

extern KBSTATE keyState[LAST_MODIFIER][KEYMAP_SIZE];
Vector DeltaPosition(0, 0, 0);
bool changed = false;
bool vert = false;
#define DELTA_MOVEMENT

void LocationSelect::MouseMoveHandle(KBSTATE kk, int x, int y, int delx, int dely, int mod) {
if (keyState[0]['z'] == DOWN) {
if (mouseButtonState == DOWN) {
#ifdef DELTA_MOVEMENT
if (kk == PRESS) {
DeltaPosition.k = dely;
Expand Down
32 changes: 29 additions & 3 deletions engine/src/gfx/mesh_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,41 @@ Mesh::~Mesh() {
vector<Mesh *> *hashers = bfxmHashTable.Get(hash_name);
vector<Mesh *>::iterator finder;
if (hashers) {
for (size_t i = hashers->size() - 1; i >= 0; --i) {
if (hashers->at(i) == this) {
hashers->erase(hashers->begin() + i);
// the foollowing loop has several tricks to it:
// 1. `std::vector::erase()` can take an interator and remove it from the vector; but invalidates
// the iterator in the process
// 2. To overcome the invalid iterator issue, the next previous iterator is cached
// 3. In the case that the previous iterator would be invalid (e.g it's at the start) then it needs
// to restart the loop without the loop conditions, therefore a simple GOTO is used instead to
// avoid the incrementing the iterator so that values are not skipped
// A reverse iterator could kind of help this; however, `std::vector::erase` unfortunately
// does not work on reverse iterators.
for (auto hashItem = hashers->begin(); hashItem != hashers->end(); ++hashItem) {
retryEraseItem:
if (*hashItem == this) {
bool resetIter = false;
auto cachedHashItem = hashers->begin();
if (hashItem != hashers->begin()) {
cachedHashItem = hashItem - 1;
} else {
resetIter = true;
cachedHashItem = hashItem + 1;
}
hashers->erase(hashItem);
if (hashers->empty()) {
bfxmHashTable.Delete(hash_name);
delete hashers;
hashers = nullptr;
break;
}

if (resetIter) {
hashItem = hashers->begin();
// a necessary use of Goto as we do not want to use ++hashItem
goto retryEraseItem;
} else {
hashItem = cachedHashItem;
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions engine/src/gldrv/gl_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ void GFXInit(int argc, char **argv) {
char vsname[12] = "Vega Strike";
char vsicon[9] = "vega.ico";
winsys_init(&argc, argv, &vsname[0], &vsicon[0]);
/* Ingore key-repeat messages */
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
Loading
Loading