Skip to content

Commit

Permalink
Merge pull request #614 from edge-classic/ec_lua_coal
Browse files Browse the repository at this point in the history
Support COAL and Lua with detection
  • Loading branch information
pbdot authored Nov 22, 2023
2 parents 95bbc86 + 340d3a5 commit 6399132
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 153 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)

option(EDGE_GL_ES2 "Enable GLES2 Rendering Backend" OFF)
option(EDGE_SANITIZE "Enable code sanitizing" OFF)
option(EDGE_COAL "Enable COAL scripting" ON)

include("cmake/EDGEClassic.cmake")

Expand Down
4 changes: 1 addition & 3 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ add_subdirectory(libprimesynth)
add_subdirectory(libRAD)
add_subdirectory(m4p)
add_subdirectory(miniz)
if (NOT EDGE_COAL)
add_subdirectory(lua)
endif()
add_subdirectory(lua)
4 changes: 1 addition & 3 deletions source_files/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

add_subdirectory(ajbsp)
if (EDGE_COAL)
add_subdirectory(coal)
endif()
add_subdirectory(coal)
add_subdirectory(ddf)
add_subdirectory(dehacked)
add_subdirectory(ec_voxelib)
Expand Down
24 changes: 6 additions & 18 deletions source_files/edge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,16 @@ set (EDGE_SOURCE_FILES
w_sprite.cc
w_texture.cc
w_wad.cc
)

if (EDGE_COAL)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} vm_coal.cc vm_hud.cc vm_player.cc)
else()
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES}
vm_coal.cc
vm_hud.cc
vm_player.cc
script/lua_debugger.cc
script/compat/lua_vm.cc
script/compat/lua_compat.cc
script/compat/lua_core.cc
script/compat/lua_game.cc
script/compat/lua_player.cc
script/compat/lua_hud.cc)
endif()

if (EMSCRIPTEN)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} i_web.cc)
Expand All @@ -141,15 +137,11 @@ set (EDGE_LINK_LIBRARIES
libprimesynth
libRAD
m4p
miniz
miniz
edge_coal
lua
)

if (EDGE_COAL)
set (EDGE_LINK_LIBRARIES ${EDGE_LINK_LIBRARIES} edge_coal)
else()
set (EDGE_LINK_LIBRARIES ${EDGE_LINK_LIBRARIES} lua)
endif()

if (WIN32)
set (EDGE_SOURCE_FILES ${EDGE_SOURCE_FILES} w32_res.rc)
set (EDGE_LINK_LIBRARIES ${EDGE_LINK_LIBRARIES} wsock32)
Expand All @@ -166,10 +158,6 @@ else()
target_compile_definitions(edge-classic PRIVATE UNIX)
endif()

if(EDGE_COAL)
target_compile_definitions(edge-classic PRIVATE EDGE_COAL)
endif()

target_include_directories(edge-classic PRIVATE ./)

if (NOT EDGE_GL_ES2)
Expand Down
45 changes: 22 additions & 23 deletions source_files/edge/e_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@
#include "w_wad.h"
#include "version.h"

#ifdef EDGE_COAL
#include "vm_coal.h"
#else
#include "script/compat/lua_compat.h"
#endif

extern cvar_c r_doubleframes;

Expand Down Expand Up @@ -197,7 +194,7 @@ DEF_CVAR(ddf_lax, "0", CVAR_ARCHIVE)
DEF_CVAR(ddf_quiet, "0", CVAR_ARCHIVE)

static const image_c *loading_image = nullptr;
const image_c *menu_backdrop = nullptr;
const image_c *menu_backdrop = nullptr;

static void E_TitleDrawer(void);

Expand Down Expand Up @@ -600,11 +597,10 @@ void E_Display(void)
case GS_LEVEL:
R_PaletteStuff();

#ifdef EDGE_COAL
VM_RunHud();
#else
LUA_RunHud();
#endif
if (VM_UseCoal())
VM_RunHud();
else
LUA_RunHud();

if (need_save_screenshot)
{
Expand Down Expand Up @@ -837,8 +833,8 @@ void E_PickMenuScreen(void)
}

// found one !!
title_game = gamedefs.GetSize() - 1;
title_pic = 29999;
title_game = gamedefs.GetSize() - 1;
title_pic = 29999;
image_c *new_backdrop = new image_c;
new_backdrop->name = menu_image->name;
new_backdrop->actual_h = menu_image->actual_h;
Expand All @@ -861,13 +857,13 @@ void E_PickMenuScreen(void)
new_backdrop->total_w = menu_image->total_w;
new_backdrop->anim.cur = new_backdrop;
new_backdrop->grayscale = true;
menu_backdrop = new_backdrop;
menu_backdrop = new_backdrop;
return;
}

// if we get here just use the loading image if it exists
title_game = gamedefs.GetSize() - 1;
title_pic = 29999;
title_game = gamedefs.GetSize() - 1;
title_pic = 29999;
if (loading_image)
{
image_c *new_backdrop = new image_c;
Expand All @@ -892,7 +888,7 @@ void E_PickMenuScreen(void)
new_backdrop->total_w = loading_image->total_w;
new_backdrop->anim.cur = new_backdrop;
new_backdrop->grayscale = true;
menu_backdrop = new_backdrop;
menu_backdrop = new_backdrop;
}
else
menu_backdrop = nullptr;
Expand Down Expand Up @@ -935,7 +931,7 @@ void E_AdvanceTitle(void)
title_pic = 0;
continue;
}

// ignore non-existing images
title_image = W_ImageLookup(g->titlepics[title_pic].c_str(), INS_Graphic, ILF_Null);

Expand Down Expand Up @@ -1860,13 +1856,16 @@ static void E_Startup(void)
S_Init();
N_InitNetwork();
M_CheatInit();
#ifdef EDGE_COAL
VM_InitCoal();
VM_LoadScripts();
#else
LUA_Init();
LUA_LoadScripts();
#endif
if (VM_UseCoal())
{
VM_InitCoal();
VM_LoadScripts();
}
else
{
LUA_Init();
LUA_LoadScripts();
}
}

static void E_Shutdown(void)
Expand Down
12 changes: 4 additions & 8 deletions source_files/edge/e_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@

#include "str_util.h"

#ifdef EDGE_COAL
#include "vm_coal.h" // For VM_EndLevel()
#else
#include "script/compat/lua_compat.h"
#endif

//
// PLAYER ARRAY
Expand Down Expand Up @@ -148,11 +145,10 @@ void G_PlayerFinishLevel(player_t *p, bool keep_cards)
// "INTERNAL ERROR: player has a removed attacker"
p->attacker = NULL;

#ifdef EDGE_COAL
VM_EndLevel();
#else
LUA_EndLevel();
#endif
if (VM_UseCoal())
VM_EndLevel();
else
LUA_EndLevel();
}

//
Expand Down
39 changes: 16 additions & 23 deletions source_files/edge/g_game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@
#include "version.h"
#include "w_wad.h"
#include "f_interm.h"
#ifdef EDGE_COAL
#include "vm_coal.h"
#else
#include "script/compat/lua_compat.h"
#endif

extern cvar_c r_doubleframes;

Expand Down Expand Up @@ -311,11 +308,10 @@ void G_DoLoadLevel(void)
LoadLevel_Bits();

SpawnInitialPlayers();
#ifdef EDGE_COAL
VM_BeginLevel();
#else
LUA_BeginLevel();
#endif
if (VM_UseCoal())
VM_BeginLevel();
else
LUA_BeginLevel();
}

//
Expand Down Expand Up @@ -884,11 +880,10 @@ static void G_DoLoadGame(void)

V_SetPalette(PALETTE_NORMAL, 0);

#ifdef EDGE_COAL
VM_LoadGame(); // Stub for now
#else
LUA_LoadGame();
#endif
if (VM_UseCoal())
VM_LoadGame(); // Stub for now
else
LUA_LoadGame();
}

//
Expand Down Expand Up @@ -985,11 +980,10 @@ static bool G_SaveGameToFile(std::filesystem::path filename, const char *descrip

static void G_DoSaveGame(void)
{
#ifdef EDGE_COAL
VM_SaveGame(); // Stub for now; eventually things like determining if saving is allowed, etc
#else
LUA_SaveGame();
#endif
if (VM_UseCoal())
VM_SaveGame(); // Stub for now; eventually things like determining if saving is allowed, etc
else
LUA_SaveGame();

std::filesystem::path fn(SV_FileName("current", "head"));

Expand Down Expand Up @@ -1123,11 +1117,10 @@ static void G_DoNewGame(void)
delete defer_params;
defer_params = NULL;

#ifdef EDGE_COAL
VM_NewGame();
#else
LUA_NewGame();
#endif
if (VM_UseCoal())
VM_NewGame();
else
LUA_NewGame();

// -AJA- 2003/10/09: support for pre-level briefing screen on first map.
// FIXME: kludgy. All this game logic desperately needs rethinking.
Expand Down
20 changes: 9 additions & 11 deletions source_files/edge/n_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@

#include "str_util.h"

#ifdef EDGE_COAL
#include "coal.h" // for coal::vm_c
extern coal::vm_c *ui_vm;
extern void VM_SetFloat(coal::vm_c *vm, const char *mod_name, const char *var_name, double value);
#else
#include "coal.h"
#include "vm_coal.h" // for coal::vm_c
#include "script/compat/lua_compat.h"
#endif

extern coal::vm_c *ui_vm;
extern void VM_SetFloat(coal::vm_c *vm, const char *mod_name, const char *var_name, double value);

// #define DEBUG_TICS 1

Expand Down Expand Up @@ -190,11 +189,10 @@ void N_GrabTiccmds(void)

memcpy(&p->cmd, p->in_cmds + buf, sizeof(ticcmd_t));
}
#ifdef EDGE_COAL
VM_SetFloat(ui_vm, "sys", "gametic", gametic / (r_doubleframes.d ? 2 : 1));
#else
LUA_SetFloat(LUA_GetGlobalVM(), "sys", "gametic", gametic / (r_doubleframes.d ? 2 : 1));
#endif
if (VM_UseCoal())
VM_SetFloat(ui_vm, "sys", "gametic", gametic / (r_doubleframes.d ? 2 : 1));
else
LUA_SetFloat(LUA_GetGlobalVM(), "sys", "gametic", gametic / (r_doubleframes.d ? 2 : 1));

gametic++;
}
Expand Down
26 changes: 12 additions & 14 deletions source_files/edge/p_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@

#include "AlmostEquals.h"

#ifdef EDGE_COAL
#include "coal.h" // for coal::vm_c
extern coal::vm_c *ui_vm;

extern void VM_SetVector(coal::vm_c *vm, const char *mod_name, const char *var_name, double val_1, double val_2,
double val_3);
#else
#include "vm_coal.h"
#include "script/compat/lua_compat.h"
#endif

extern coal::vm_c *ui_vm;
extern void VM_SetVector(coal::vm_c *vm, const char *mod_name, const char *var_name, double val_1, double val_2,
double val_3);

extern cvar_c r_doubleframes;

Expand Down Expand Up @@ -880,13 +878,13 @@ bool P_PlayerThink(player_t *player, bool extra_tic)
player->actiondown[0] = (cmd->extbuttons & EBT_ACTION1) ? true : false;
player->actiondown[1] = (cmd->extbuttons & EBT_ACTION2) ? true : false;

#ifdef EDGE_COAL
VM_SetVector(ui_vm, "player", "inventory_event_handler", cmd->extbuttons & EBT_INVPREV ? 1 : 0,
cmd->extbuttons & EBT_INVUSE ? 1 : 0, cmd->extbuttons & EBT_INVNEXT ? 1 : 0);
#else
LUA_SetVector3(LUA_GetGlobalVM(), "player", "inventory_event_handler", epi::vec3_c(cmd->extbuttons & EBT_INVPREV ? 1 : 0,
cmd->extbuttons & EBT_INVUSE ? 1 : 0, cmd->extbuttons & EBT_INVNEXT ? 1 : 0));
#endif
if (VM_UseCoal())
VM_SetVector(ui_vm, "player", "inventory_event_handler", cmd->extbuttons & EBT_INVPREV ? 1 : 0,
cmd->extbuttons & EBT_INVUSE ? 1 : 0, cmd->extbuttons & EBT_INVNEXT ? 1 : 0);
else
LUA_SetVector3(LUA_GetGlobalVM(), "player", "inventory_event_handler",
epi::vec3_c(cmd->extbuttons & EBT_INVPREV ? 1 : 0, cmd->extbuttons & EBT_INVUSE ? 1 : 0,
cmd->extbuttons & EBT_INVNEXT ? 1 : 0));

// FIXME separate code more cleanly
if (extra_tic && r_doubleframes.d)
Expand Down
Loading

0 comments on commit 6399132

Please sign in to comment.