Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
royfalk committed Oct 3, 2024
2 parents 08daa5b + 50f1678 commit 4354d63
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 514 deletions.
9 changes: 9 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ SET(LIBRESOURCE
src/resource/product.cpp
src/resource/cargo.cpp
src/resource/manifest.cpp
src/resource/python_utils.cpp
src/resource/random_utils.cpp
src/cmd/json.cpp
)
Expand Down Expand Up @@ -1720,6 +1721,7 @@ IF (USE_GTEST)
src/resource/tests/resource_test.cpp
src/resource/tests/manifest_tests.cpp
src/resource/tests/random_tests.cpp
src/resource/tests/python_tests.cpp
src/exit_unit_tests.cpp
src/components/tests/energy_container_tests.cpp
src/components/tests/balancing_tests.cpp
Expand All @@ -1744,6 +1746,8 @@ IF (USE_GTEST)

TARGET_LINK_LIBRARIES(
${TEST_NAME}
${Boost_LIBRARIES}
${Python3_LIBRARIES}
gtest_main
vegastrike-testing
Boost::log
Expand All @@ -1767,6 +1771,11 @@ IF (USE_GTEST)
DESTINATION ${CMAKE_BINARY_DIR}/test_assets
)

FILE(
COPY "src/components/tests/python_tests.py"
DESTINATION ${CMAKE_BINARY_DIR}
)

INCLUDE(GoogleTest)
gtest_discover_tests(${TEST_NAME})
ENDIF (USE_GTEST)
100 changes: 50 additions & 50 deletions engine/src/cmd/base_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,60 +82,60 @@ static boost::python::tuple GetRandomBarMessage() {
}
}

PYTHON_BEGIN_MODULE(Base)
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Room, "Room");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetCurRoom, "SetCurRoom");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::GetCurRoom, "GetCurRoom");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::GetNumRoom, "GetNumRoom");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::GetNumRoom, "HasObject");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Comp, "Comp");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::CompPython, "CompPython");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Launch, "Launch");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::LaunchPython, "LaunchPython");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Link, "Link");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::LinkPython, "LinkPython");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Python, "Python");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::EraseLink, "EraseLink");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Ship, "Ship");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Texture, "Texture");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Video, "Video");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::VideoStream, "VideoStream");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::PlayVideo, "PlayVideo");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::StopVideo, "StopVideo");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetVideoCallback, "SetVideoCallback");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetDJEnabled, "SetDJEnabled");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetTexture, "SetTexture");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetTextureSize, "SetTextureSize");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetTexturePos, "SetTexturePos");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::EnqueueMessageToRoom, "EnqueueMessageToRoom");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::MessageToRoom, "MessageToRoom");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::EnqueueMessage, "EnqueueMessage");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::Message, "Message");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::EraseObj, "EraseObj");
PYTHON_DEFINE_GLOBAL(Base, &::GetRandomBarMessage, "GetRandomBarMessage");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::RunScript, "RunScript");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::TextBox, "TextBox");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetTextBoxText, "SetTextBoxText");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::GlobalKeyPython, "GlobalKeyPython");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetLinkArea, "SetLinkArea");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetLinkText, "SetLinkText");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetLinkPython, "SetLinkPython");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetLinkRoom, "SetLinkRoom");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetLinkEventMask, "SetLinkEventMask");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::BuyShip, "BuyShip");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SellShip, "SellShip");
BOOST_PYTHON_MODULE(Base) {
boost::python::def("Room", &BaseUtil::Room);
boost::python::def("SetCurRoom", &BaseUtil::SetCurRoom);
boost::python::def("GetCurRoom", &BaseUtil::GetCurRoom);
boost::python::def("GetNumRoom", &BaseUtil::GetNumRoom);
boost::python::def("HasObject", &BaseUtil::GetNumRoom);
boost::python::def("Comp", &BaseUtil::Comp);
boost::python::def("CompPython", &BaseUtil::CompPython);
boost::python::def("Launch", &BaseUtil::Launch);
boost::python::def("LaunchPython", &BaseUtil::LaunchPython);
boost::python::def("Link", &BaseUtil::Link);
boost::python::def("LinkPython", &BaseUtil::LinkPython);
boost::python::def("Python", &BaseUtil::Python);
boost::python::def("EraseLink", &BaseUtil::EraseLink);
boost::python::def("Ship", &BaseUtil::Ship);
boost::python::def("Texture", &BaseUtil::Texture);
boost::python::def("Video", &BaseUtil::Video);
boost::python::def("VideoStream", &BaseUtil::VideoStream);
boost::python::def("PlayVideo", &BaseUtil::PlayVideo);
boost::python::def("StopVideo", &BaseUtil::StopVideo);
boost::python::def("SetVideoCallback", &BaseUtil::SetVideoCallback);
boost::python::def("SetDJEnabled", &BaseUtil::SetDJEnabled);
boost::python::def("SetTexture", &BaseUtil::SetTexture);
boost::python::def("SetTextureSize", &BaseUtil::SetTextureSize);
boost::python::def("SetTexturePos", &BaseUtil::SetTexturePos);
boost::python::def("EnqueueMessageToRoom", &BaseUtil::EnqueueMessageToRoom);
boost::python::def("MessageToRoom", &BaseUtil::MessageToRoom);
boost::python::def("EnqueueMessage", &BaseUtil::EnqueueMessage);
boost::python::def("Message", &BaseUtil::Message);
boost::python::def("EraseObj", &BaseUtil::EraseObj);
boost::python::def("GetRandomBarMessage", &::GetRandomBarMessage);
boost::python::def("RunScript", &BaseUtil::RunScript);
boost::python::def("TextBox", &BaseUtil::TextBox);
boost::python::def("SetTextBoxText", &BaseUtil::SetTextBoxText);
boost::python::def("GlobalKeyPython", &BaseUtil::GlobalKeyPython);
boost::python::def("SetLinkArea", &BaseUtil::SetLinkArea);
boost::python::def("SetLinkText", &BaseUtil::SetLinkText);
boost::python::def("SetLinkPython", &BaseUtil::SetLinkPython);
boost::python::def("SetLinkRoom", &BaseUtil::SetLinkRoom);
boost::python::def("SetLinkEventMask", &BaseUtil::SetLinkEventMask);
boost::python::def("BuyShip", &BaseUtil::BuyShip);
boost::python::def("SellShip", &BaseUtil::SellShip);

PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetEventData, "SetEventData");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::SetMouseEventData, "SetMouseEventData");
PYTHON_DEFINE_GLOBAL(Base, &::GetEventDataPython, "GetEventData");
boost::python::def("SetEventData", &BaseUtil::SetEventData);
boost::python::def("SetMouseEventData", &BaseUtil::SetMouseEventData);
boost::python::def("GetEventData", &::GetEventDataPython);

PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::GetTextWidth, "GetTextWidth");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::GetTextHeight, "GetTextHeight");
boost::python::def("GetTextWidth", &BaseUtil::GetTextWidth);
boost::python::def("GetTextHeight", &BaseUtil::GetTextHeight);

PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::LoadBaseInterface, "LoadBaseInterface");
PYTHON_DEFINE_GLOBAL(Base, &BaseUtil::ExitGame, "ExitGame");
boost::python::def("LoadBaseInterface", &BaseUtil::LoadBaseInterface);
boost::python::def("ExitGame", &BaseUtil::ExitGame);

PYTHON_END_MODULE(Base)
}

void InitBase() {
PyImport_AppendInittab("Base", PYTHON_MODULE_INIT_FUNCTION(Base));
Expand Down
34 changes: 17 additions & 17 deletions engine/src/cmd/script/director_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static bool isUtf8SaveGamePy(string savegame) {
return isUtf8SaveGame(savegame);
}

PYTHON_BEGIN_MODULE(Director)
BOOST_PYTHON_MODULE(Director) {
PYTHON_BEGIN_INHERIT_CLASS(Director, pythonMission, PythonMissionBaseClass, "Mission")
PYTHON_DEFINE_METHOD_DEFAULT(Class, &PythonMissionBaseClass::Pickle, "Pickle", pythonMission::default_Pickle);
PYTHON_DEFINE_METHOD_DEFAULT(Class,
Expand All @@ -341,22 +341,22 @@ PYTHON_BEGIN_MODULE(Director)
"Execute",
pythonMission::default_Execute);
PYTHON_END_CLASS(Director, pythonMission)
PYTHON_DEFINE_GLOBAL(Director, &putSaveDataPy, "putSaveData");
PYTHON_DEFINE_GLOBAL(Director, &pushSaveDataPy, "pushSaveData");
PYTHON_DEFINE_GLOBAL(Director, &eraseSaveDataPy, "eraseSaveData");
PYTHON_DEFINE_GLOBAL(Director, &clearSaveDataPy, "clearSaveData");
PYTHON_DEFINE_GLOBAL(Director, &getSaveDataPy, "getSaveData");
PYTHON_DEFINE_GLOBAL(Director, &getSaveDataLengthPy, "getSaveDataLength");
PYTHON_DEFINE_GLOBAL(Director, &putSaveStringPy, "putSaveString");
PYTHON_DEFINE_GLOBAL(Director, &pushSaveStringPy, "pushSaveString");
PYTHON_DEFINE_GLOBAL(Director, &getSaveStringPy, "getSaveString");
PYTHON_DEFINE_GLOBAL(Director, &getSaveStringLengthPy, "getSaveStringLength");
PYTHON_DEFINE_GLOBAL(Director, &eraseSaveStringPy, "eraseSaveString");
PYTHON_DEFINE_GLOBAL(Director, &clearSaveStringPy, "clearSaveString");
PYTHON_DEFINE_GLOBAL(Director, &loadStringListPy, "loadStringList");
PYTHON_DEFINE_GLOBAL(Director, &saveStringListPy, "saveStringList");
PYTHON_DEFINE_GLOBAL(Director, &isUtf8SaveGamePy, "isUtf8SaveGame");
PYTHON_END_MODULE(Director)
boost::python::def("putSaveData", &putSaveDataPy);
boost::python::def("pushSaveData", &pushSaveDataPy);
boost::python::def("eraseSaveData", &eraseSaveDataPy);
boost::python::def("clearSaveData", &clearSaveDataPy);
boost::python::def("getSaveData", &getSaveDataPy);
boost::python::def("getSaveDataLength", &getSaveDataLengthPy);
boost::python::def("putSaveString", &putSaveStringPy);
boost::python::def("pushSaveString", &pushSaveStringPy);
boost::python::def("getSaveString", &getSaveStringPy);
boost::python::def("getSaveStringLength", &getSaveStringLengthPy);
boost::python::def("eraseSaveString", &eraseSaveStringPy);
boost::python::def("clearSaveString", &clearSaveStringPy);
boost::python::def("loadStringList", &loadStringListPy);
boost::python::def("saveStringList", &saveStringListPy);
boost::python::def("isUtf8SaveGame", &isUtf8SaveGamePy);
}

void InitDirector() {
PyImport_AppendInittab("Director", PYTHON_MODULE_INIT_FUNCTION(Director));
Expand Down
8 changes: 4 additions & 4 deletions engine/src/cmd/script/director_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
#include "cmd/unit_generic.h"
#include "mission.h"

PYTHON_BEGIN_MODULE(Base)
BOOST_PYTHON_MODULE(Base) {
//Nothing here, but keeps those files that do a "import Base" happy.
PYTHON_END_MODULE(Base)
}

PYTHON_BEGIN_MODULE(Briefing)
BOOST_PYTHON_MODULE(Briefing) {
//Nothing here, but keeps those files that do a "import Briefing" happy.
PYTHON_END_MODULE(Briefing)
}

void InitBase() {
PyImport_AppendInittab("Base", PYTHON_MODULE_INIT_FUNCTION(Base));
Expand Down
4 changes: 4 additions & 0 deletions engine/src/components/tests/python_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


def append(first, second):
return first+second
2 changes: 2 additions & 0 deletions engine/src/configuration/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Configuration::Configuration() {
* behavior/range bounding is complicated/necessary-for-stability abd additional validation code is required for checking/adjusting user inputs
*/
void Configuration::OverrideDefaultsWithUserConfiguration() {
general_config.screen = GetGameConfig().GetInt16("general.screen", general_config.screen);

general_config.pitch = GetGameConfig().GetFloat("general.pitch", general_config.pitch);
general_config.yaw = GetGameConfig().GetFloat("general.yaw", general_config.yaw);
general_config.roll = GetGameConfig().GetFloat("general.roll", general_config.roll);
Expand Down
3 changes: 3 additions & 0 deletions engine/src/configuration/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace vega_config {
struct GeneralConfig {
GeneralConfig() = default;

int screen{0}; // TODO: move to a dedicated section along with other such paramters.
// e.g. screen width and height, resolution, color, etc.

float pitch{0.0F};
float yaw{0.0F};
float roll{0.0F};
Expand Down
2 changes: 2 additions & 0 deletions engine/src/gfx/halo_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define VEGA_STRIKE_ENGINE_GFX_HALOSYSTEM_H

#include <vector>
#include <string>

#include "matrix.h"
class Mesh;
struct GFXColor;
Expand Down
14 changes: 12 additions & 2 deletions engine/src/gldrv/winsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "vs_logging.h"
#include "options.h"
#include "vs_exit.h"
#include "configuration/configuration.h"

#include "SDL2/SDL_video.h"

Expand Down Expand Up @@ -253,8 +254,17 @@ static bool setup_sdl_video_mode(int *argc, char **argv) {
width = g_game.x_resolution;
height = g_game.y_resolution;


SDL_Window *window = SDL_CreateWindow("Vegastrike", 0, 0, width, height, video_flags);
const int screen_number = configuration()->general_config.screen;
SDL_Window *window = nullptr;
if(screen_number == 0) {
window = SDL_CreateWindow("Vegastrike", 0, 0, width, height, video_flags);
} else {
window = SDL_CreateWindow("Vegastrike",
SDL_WINDOWPOS_UNDEFINED_DISPLAY(screen_number),
SDL_WINDOWPOS_UNDEFINED_DISPLAY(screen_number),
0, 0, video_flags);
}


if(!window) {
std::cerr << "No window\n" << std::flush;
Expand Down
Loading

0 comments on commit 4354d63

Please sign in to comment.