Skip to content

Commit

Permalink
Make COAL and Dehacked compile-time options
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Dec 20, 2024
1 parent f0df710 commit 35fdc36
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 48 deletions.
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
option(EDGE_GL_ES2 "Enable GLES2 Rendering Backend" OFF)
option(EDGE_SANITIZE "Enable code sanitizing" OFF)
option(EDGE_PROFILING "Enable Profiling" OFF)
option(EDGE_COAL_SUPPORT "Enable support for COAL scripting" ON)
option(EDGE_DEHACKED_SUPPORT "Enable support for Dehacked patch conversion" ON)

include("${CMAKE_SOURCE_DIR}/cmake/EDGEClassic.cmake")

Expand Down Expand Up @@ -103,12 +105,20 @@ else()

endif()

# set some directory values for various situations

if(${CMAKE_SYSTEM} MATCHES "BSD")
include_directories("/usr/local/include")
endif()

if (MSVC)
set(SDL2_DIR "${CMAKE_SOURCE_DIR}/libraries/sdl2")
endif()

find_package(SDL2 REQUIRED)

# set certain definitions (if appropriate)

if (APPLE)
include_directories(${SDL2_INCLUDE_DIR})
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" AND APPLE)
Expand All @@ -118,15 +128,19 @@ if (APPLE)
endif()
endif()

if(${CMAKE_SYSTEM} MATCHES "BSD")
include_directories("/usr/local/include")
endif()

if (NOT EDGE_GL_ES2)
find_package(OpenGL REQUIRED)
else()
add_definitions(-DEDGE_GL_ES2)
endif()

if (EDGE_COAL_SUPPORT)
add_definitions(-DEDGE_COAL_SUPPORT)
endif()

if (EDGE_DEHACKED_SUPPORT)
add_definitions(-DEDGE_DEHACKED_SUPPORT)
endif()

add_subdirectory(libraries)
add_subdirectory(source_files)
8 changes: 6 additions & 2 deletions source_files/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

add_subdirectory(ajbsp)
add_subdirectory(coal)
if (EDGE_COAL_SUPPORT)
add_subdirectory(coal)
endif ()
add_subdirectory(ddf)
add_subdirectory(dehacked)
if (EDGE_DEHACKED_SUPPORT)
add_subdirectory(dehacked)
endif()
add_subdirectory(epi)
add_subdirectory(edge)
22 changes: 16 additions & 6 deletions source_files/edge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set (EDGE_SOURCE_FILES
im_filter.cc
im_data.cc
im_funcs.cc
l_deh.cc
m_argv.cc
m_bbox.cc
m_cheat.cc
Expand Down Expand Up @@ -113,9 +112,6 @@ set (EDGE_SOURCE_FILES
w_sprite.cc
w_texture.cc
w_wad.cc
vm_coal.cc
vm_hud.cc
vm_player.cc
script/lua_debugger.cc
script/compat/lua_vm.cc
script/compat/lua_compat.cc
Expand All @@ -124,6 +120,14 @@ set (EDGE_SOURCE_FILES
script/compat/lua_player.cc
script/compat/lua_hud.cc)

if (EDGE_COAL_SUPPORT)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} vm_coal.cc vm_hud.cc vm_player.cc)
endif()

if (EDGE_DEHACKED_SUPPORT)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} l_deh.cc)
endif()

if (EMSCRIPTEN)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} i_web.cc)
else()
Expand All @@ -132,9 +136,7 @@ endif()

set (EDGE_LINK_LIBRARIES
edge_ajbsp
edge_coal
edge_ddf
edge_deh
edge_epi
edge_tracy
${SDL2_LIBRARIES}
Expand All @@ -156,6 +158,14 @@ set (EDGE_LINK_LIBRARIES
xxhash
)

if (EDGE_COAL_SUPPORT)
set (EDGE_LINK_LIBRARIES ${EDGE_LINK_LIBRARIES} edge_coal)
endif()

if (EDGE_DEHACKED_SUPPORT)
set (EDGE_LINK_LIBRARIES ${EDGE_LINK_LIBRARIES} edge_deh)
endif()

if (WIN32)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} w32_res.rc)
endif()
Expand Down
13 changes: 11 additions & 2 deletions source_files/edge/e_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
#include "sv_chunk.h"
#include "sv_main.h"
#include "version.h"
#if EDGE_COAL_SUPPORT
#include "vm_coal.h"
#endif
#include "w_files.h"
#include "w_model.h"
#include "w_sprite.h"
Expand Down Expand Up @@ -646,12 +648,14 @@ void EdgeDisplay(void)
{
case kGameStateLevel:
PaletteTicker();

#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaRunHUD();
else
COALRunHUD();

#else
LuaRunHUD();
#endif
if (need_save_screenshot)
{
CreateSaveScreenshot();
Expand Down Expand Up @@ -2333,6 +2337,7 @@ static void EdgeStartup(void)
InitializeSound();
NetworkInitialize();
CheatInitialize();
#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
{
LuaInit();
Expand All @@ -2343,6 +2348,10 @@ static void EdgeStartup(void)
InitializeCOAL();
COALLoadScripts();
}
#else
LuaInit();
LuaLoadScripts();
#endif
}

static void InitialState(void)
Expand Down
13 changes: 11 additions & 2 deletions source_files/edge/e_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
#include "m_random.h"
#include "p_local.h"
#include "script/compat/lua_compat.h"
#include "vm_coal.h" // For COALEndLevel()
#if EDGE_COAL_SUPPORT
#include "vm_coal.h"
#endif

//
// PLAYER ARRAY
Expand All @@ -64,6 +66,10 @@ int total_bots;
int console_player = -1; // player taking events
int display_player = -1; // view being displayed

// For COAL/Lua VMs
Player *ui_hud_who = nullptr;
Player *ui_player_who = nullptr;

static constexpr uint8_t kMaximumBodies = 50;

static MapObject *body_queue[kMaximumBodies];
Expand Down Expand Up @@ -143,11 +149,14 @@ void PlayerFinishLevel(Player *p, bool keep_cards)
// Lobo 2023: uncomment if still getting
// "INTERNAL ERROR: player has a removed attacker"
p->attacker_ = nullptr;

#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaEndLevel();
else
COALEndLevel();
#else
LuaEndLevel();
#endif
}

//
Expand Down
20 changes: 18 additions & 2 deletions source_files/edge/g_game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
#include "sv_chunk.h"
#include "sv_main.h"
#include "version.h"
#if EDGE_COAL_SUPPORT
#include "vm_coal.h"
#endif
#include "w_wad.h"

GameState game_state = kGameStateNothing;
Expand Down Expand Up @@ -308,10 +310,14 @@ void DoLoadLevel(void)
LoadLevel_Bits();

SpawnInitialPlayers();
#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaBeginLevel();
else
COALBeginLevel();
#else
LuaBeginLevel();
#endif
}

//
Expand Down Expand Up @@ -852,11 +858,14 @@ static void GameDoLoadGame(void)
HUDStart();

SetPalette(kPaletteNormal, 0);

#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaLoadGame();
else
COALLoadGame();
#else
LuaLoadGame();
#endif
}

//
Expand Down Expand Up @@ -950,10 +959,14 @@ static bool GameSaveGameToFile(std::string filename, const char *description)

static void GameDoSaveGame(void)
{
#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaSaveGame();
else
COALSaveGame();
#else
LuaSaveGame();
#endif

std::string fn(SaveFilename("current", "head"));

Expand Down Expand Up @@ -1082,11 +1095,14 @@ static void GameDoNewGame(void)

delete defer_params;
defer_params = nullptr;

#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaNewGame();
else
COALNewGame();
#else
LuaNewGame();
#endif

// -AJA- 2003/10/09: support for pre-level briefing screen on first map.
// FIXME: kludgy. All this game logic desperately needs rethinking.
Expand Down
10 changes: 9 additions & 1 deletion source_files/edge/n_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <stdlib.h>
#include <string.h>

#if EDGE_COAL_SUPPORT
#include "coal.h"
#endif
#include "ddf_types.h"
#include "dm_state.h"
#include "e_input.h"
Expand All @@ -37,10 +39,12 @@
#include "m_argv.h"
#include "m_random.h"
#include "script/compat/lua_compat.h"
#include "vm_coal.h" // for coal::vm_c
#if EDGE_COAL_SUPPORT
#include "vm_coal.h"

extern coal::VM *ui_vm;
extern void COALSetFloat(coal::VM *vm, const char *mod_name, const char *var_name, double value);
#endif

// only true if packets are exchanged with a server
bool network_game = false;
Expand Down Expand Up @@ -166,10 +170,14 @@ void GrabTicCommands(void)

memcpy(&p->command_, p->input_commands_ + buf, sizeof(EventTicCommand));
}
#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaSetFloat(LuaGetGlobalVM(), "sys", "gametic", game_tic);
else
COALSetFloat(ui_vm, "sys", "gametic", game_tic);
#else
LuaSetFloat(LuaGetGlobalVM(), "sys", "gametic", game_tic);
#endif

game_tic++;
}
Expand Down
2 changes: 2 additions & 0 deletions source_files/edge/p_umapinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "ddf_game.h"
#include "ddf_language.h"
#include "ddf_thing.h"
#if EDGE_DEHACKED_SUPPORT
#include "deh_text.h"
#endif
#include "epi_ename.h"
#include "epi_scanner.h"
#include "epi_str_compare.h"
Expand Down
15 changes: 12 additions & 3 deletions source_files/edge/p_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

#include "AlmostEquals.h"
#include "bot_think.h"
#include "coal.h" // for coal::vm_c
#if EDGE_COAL_SUPPORT
#include "coal.h"
#endif
#include "ddf_colormap.h"
#include "dm_state.h"
#include "e_input.h"
Expand All @@ -43,11 +45,13 @@
#include "s_sound.h"
#include "script/compat/lua_compat.h"
#include "stb_sprintf.h"
#if EDGE_COAL_SUPPORT
#include "vm_coal.h"

extern coal::VM *ui_vm;
extern void COALSetVector(coal::VM *vm, const char *mod_name, const char *var_name, double val_1, double val_2,
double val_3);
#endif

EDGE_DEFINE_CONSOLE_VARIABLE(erraticism, "0", kConsoleVariableFlagArchive)

Expand Down Expand Up @@ -853,7 +857,7 @@ bool PlayerThink(Player *player)

player->action_button_down_[0] = (cmd->extended_buttons & kExtendedButtonCodeAction1) ? true : false;
player->action_button_down_[1] = (cmd->extended_buttons & kExtendedButtonCodeAction2) ? true : false;

#if EDGE_COAL_SUPPORT
if (LuaUseLuaHUD())
LuaSetVector3(LuaGetGlobalVM(), "player", "inventory_event_handler",
HMM_Vec3{{cmd->extended_buttons & kExtendedButtonCodeInventoryPrevious ? 1.0f : 0.0f,
Expand All @@ -864,7 +868,12 @@ bool PlayerThink(Player *player)
cmd->extended_buttons & kExtendedButtonCodeInventoryPrevious ? 1 : 0,
cmd->extended_buttons & kExtendedButtonCodeInventoryUse ? 1 : 0,
cmd->extended_buttons & kExtendedButtonCodeInventoryNext ? 1 : 0);

#else
LuaSetVector3(LuaGetGlobalVM(), "player", "inventory_event_handler",
HMM_Vec3{{cmd->extended_buttons & kExtendedButtonCodeInventoryPrevious ? 1.0f : 0.0f,
cmd->extended_buttons & kExtendedButtonCodeInventoryUse ? 1.0f : 0.0f,
cmd->extended_buttons & kExtendedButtonCodeInventoryNext ? 1.0f : 0.0f}});
#endif
// decrement jump_wait_ counter
if (player->jump_wait_ > 0)
player->jump_wait_--;
Expand Down
Loading

0 comments on commit 35fdc36

Please sign in to comment.