AGS: Move script.cpp globals into Globals

This commit is contained in:
Paul Gilbert 2021-02-28 15:07:54 -08:00
parent c3d96c399c
commit b6dd902163
29 changed files with 380 additions and 409 deletions

View file

@ -395,12 +395,12 @@ void AGSEngine::setGraphicsMode(size_t w, size_t h) {
bool AGSEngine::canLoadGameStateCurrently() { bool AGSEngine::canLoadGameStateCurrently() {
return !_GP(thisroom).Options.SaveLoadDisabled && return !_GP(thisroom).Options.SaveLoadDisabled &&
!::AGS3::inside_script && !_GP(play).fast_forward; !_G(inside_script) && !_GP(play).fast_forward;
} }
bool AGSEngine::canSaveGameStateCurrently() { bool AGSEngine::canSaveGameStateCurrently() {
return !_GP(thisroom).Options.SaveLoadDisabled && return !_GP(thisroom).Options.SaveLoadDisabled &&
!::AGS3::inside_script && !_GP(play).fast_forward; !_G(inside_script) && !_GP(play).fast_forward;
} }
Common::Error AGSEngine::loadGameState(int slot) { Common::Error AGSEngine::loadGameState(int slot) {

View file

@ -70,12 +70,8 @@ namespace AGS3 {
using namespace AGS::Shared; using namespace AGS::Shared;
extern ccInstance *dialogScriptsInst;
extern int in_new_room; extern int in_new_room;
extern CharacterInfo *playerchar; extern CharacterInfo *playerchar;
extern AGSPlatformDriver *platform; extern AGSPlatformDriver *platform;
extern int cur_mode, cur_cursor; extern int cur_mode, cur_cursor;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
@ -193,11 +189,11 @@ int run_dialog_script(DialogTopic *dtpp, int dialogID, int offse, int optionInde
said_speech_line = 0; said_speech_line = 0;
int result = RUN_DIALOG_STAY; int result = RUN_DIALOG_STAY;
if (dialogScriptsInst) { if (_G(dialogScriptsInst)) {
char funcName[100]; char funcName[100];
sprintf(funcName, "_run_dialog%d", dialogID); sprintf(funcName, "_run_dialog%d", dialogID);
RunTextScriptIParam(dialogScriptsInst, funcName, RuntimeScriptValue().SetInt32(optionIndex)); RunTextScriptIParam(_G(dialogScriptsInst), funcName, RuntimeScriptValue().SetInt32(optionIndex));
result = dialogScriptsInst->returnValue; result = _G(dialogScriptsInst)->returnValue;
} else { } else {
// old dialog format // old dialog format
if (offse == -1) if (offse == -1)
@ -402,8 +398,8 @@ bool get_custom_dialog_options_dimensions(int dlgnum) {
ccDialogOptionsRendering.Reset(); ccDialogOptionsRendering.Reset();
ccDialogOptionsRendering.dialogID = dlgnum; ccDialogOptionsRendering.dialogID = dlgnum;
getDialogOptionsDimensionsFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(getDialogOptionsDimensionsFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
run_function_on_non_blocking_thread(&getDialogOptionsDimensionsFunc); run_function_on_non_blocking_thread(&_GP(getDialogOptionsDimensionsFunc));
if ((ccDialogOptionsRendering.width > 0) && if ((ccDialogOptionsRendering.width > 0) &&
(ccDialogOptionsRendering.height > 0)) { (ccDialogOptionsRendering.height > 0)) {
@ -646,8 +642,8 @@ void DialogOptions::Redraw() {
dialogOptionsRenderingSurface->hasAlphaChannel = ccDialogOptionsRendering.hasAlphaChannel; dialogOptionsRenderingSurface->hasAlphaChannel = ccDialogOptionsRendering.hasAlphaChannel;
options_surface_has_alpha = dialogOptionsRenderingSurface->hasAlphaChannel != 0; options_surface_has_alpha = dialogOptionsRenderingSurface->hasAlphaChannel != 0;
renderDialogOptionsFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(renderDialogOptionsFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
run_function_on_non_blocking_thread(&renderDialogOptionsFunc); run_function_on_non_blocking_thread(&_GP(renderDialogOptionsFunc));
if (!ccDialogOptionsRendering.surfaceAccessed) if (!ccDialogOptionsRendering.surfaceAccessed)
debug_script_warn("dialog_options_get_dimensions was implemented, but no dialog_options_render function drew anything to the surface"); debug_script_warn("dialog_options_get_dimensions was implemented, but no dialog_options_render function drew anything to the surface");
@ -830,8 +826,8 @@ bool DialogOptions::Run() {
} }
if (new_custom_render) { if (new_custom_render) {
runDialogOptionRepExecFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(runDialogOptionRepExecFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
run_function_on_non_blocking_thread(&runDialogOptionRepExecFunc); run_function_on_non_blocking_thread(&_GP(runDialogOptionRepExecFunc));
} }
int gkey; int gkey;
@ -856,9 +852,9 @@ bool DialogOptions::Run() {
} }
} }
} else if (new_custom_render) { } else if (new_custom_render) {
runDialogOptionKeyPressHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(runDialogOptionKeyPressHandlerFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionKeyPressHandlerFunc.params[1].SetInt32(GetKeyForKeyPressCb(gkey)); _GP(runDialogOptionKeyPressHandlerFunc).params[1].SetInt32(GetKeyForKeyPressCb(gkey));
run_function_on_non_blocking_thread(&runDialogOptionKeyPressHandlerFunc); run_function_on_non_blocking_thread(&_GP(runDialogOptionKeyPressHandlerFunc));
} }
// Allow selection of options by keyboard shortcuts // Allow selection of options by keyboard shortcuts
else if (_GP(game).options[OPT_DIALOGNUMBERED] >= kDlgOptKeysOnly && else if (_GP(game).options[OPT_DIALOGNUMBERED] >= kDlgOptKeysOnly &&
@ -877,10 +873,10 @@ bool DialogOptions::Run() {
if ((_G(mousex) >= dirtyx) && (_G(mousey) >= dirtyy) && if ((_G(mousex) >= dirtyx) && (_G(mousey) >= dirtyy) &&
(_G(mousex) < dirtyx + tempScrn->GetWidth()) && (_G(mousex) < dirtyx + tempScrn->GetWidth()) &&
(_G(mousey) < dirtyy + tempScrn->GetHeight())) { (_G(mousey) < dirtyy + tempScrn->GetHeight())) {
getDialogOptionUnderCursorFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(getDialogOptionUnderCursorFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
run_function_on_non_blocking_thread(&getDialogOptionUnderCursorFunc); run_function_on_non_blocking_thread(&_GP(getDialogOptionUnderCursorFunc));
if (!getDialogOptionUnderCursorFunc.atLeastOneImplementationExists) if (!_GP(getDialogOptionUnderCursorFunc).atLeastOneImplementationExists)
quit("!The script function dialog_options_get_active is not implemented. It must be present to use a custom dialogue system."); quit("!The script function dialog_options_get_active is not implemented. It must be present to use a custom dialogue system.");
mouseison = ccDialogOptionsRendering.activeOptionID; mouseison = ccDialogOptionsRendering.activeOptionID;
@ -918,11 +914,11 @@ bool DialogOptions::Run() {
!_GP(play).IsIgnoringInput()) { !_GP(play).IsIgnoringInput()) {
if (mouseison < 0 && !new_custom_render) { if (mouseison < 0 && !new_custom_render) {
if (usingCustomRendering) { if (usingCustomRendering) {
runDialogOptionMouseClickHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(runDialogOptionMouseClickHandlerFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionMouseClickHandlerFunc.params[1].SetInt32(mouseButtonPressed + 1); _GP(runDialogOptionMouseClickHandlerFunc).params[1].SetInt32(mouseButtonPressed + 1);
run_function_on_non_blocking_thread(&runDialogOptionMouseClickHandlerFunc); run_function_on_non_blocking_thread(&_GP(runDialogOptionMouseClickHandlerFunc));
if (runDialogOptionMouseClickHandlerFunc.atLeastOneImplementationExists) { if (_GP(runDialogOptionMouseClickHandlerFunc).atLeastOneImplementationExists) {
Redraw(); Redraw();
return true; // continue running loop return true; // continue running loop
} }
@ -933,9 +929,9 @@ bool DialogOptions::Run() {
// they clicked the text box // they clicked the text box
parserActivated = 1; parserActivated = 1;
} else if (new_custom_render) { } else if (new_custom_render) {
runDialogOptionMouseClickHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(runDialogOptionMouseClickHandlerFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionMouseClickHandlerFunc.params[1].SetInt32(mouseButtonPressed + 1); _GP(runDialogOptionMouseClickHandlerFunc).params[1].SetInt32(mouseButtonPressed + 1);
run_function_on_non_blocking_thread(&runDialogOptionMouseClickHandlerFunc); run_function_on_non_blocking_thread(&_GP(runDialogOptionMouseClickHandlerFunc));
} else if (usingCustomRendering) { } else if (usingCustomRendering) {
chose = mouseison; chose = mouseison;
return false; // end dialog options running loop return false; // end dialog options running loop
@ -947,12 +943,12 @@ bool DialogOptions::Run() {
if (usingCustomRendering) { if (usingCustomRendering) {
if (mouseWheelTurn != 0) { if (mouseWheelTurn != 0) {
runDialogOptionMouseClickHandlerFunc.params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering); _GP(runDialogOptionMouseClickHandlerFunc).params[0].SetDynamicObject(&ccDialogOptionsRendering, &ccDialogOptionsRendering);
runDialogOptionMouseClickHandlerFunc.params[1].SetInt32((mouseWheelTurn < 0) ? 9 : 8); _GP(runDialogOptionMouseClickHandlerFunc).params[1].SetInt32((mouseWheelTurn < 0) ? 9 : 8);
run_function_on_non_blocking_thread(&runDialogOptionMouseClickHandlerFunc); run_function_on_non_blocking_thread(&_GP(runDialogOptionMouseClickHandlerFunc));
if (!new_custom_render) { if (!new_custom_render) {
if (runDialogOptionMouseClickHandlerFunc.atLeastOneImplementationExists) if (_GP(runDialogOptionMouseClickHandlerFunc).atLeastOneImplementationExists)
Redraw(); Redraw();
return true; // continue running loop return true; // continue running loop
} }

View file

@ -92,7 +92,7 @@ extern GameSetup usetup;
extern int convert_16bit_bgr; extern int convert_16bit_bgr;
extern ScriptSystem scsystem;
extern AGSPlatformDriver *platform; extern AGSPlatformDriver *platform;
extern char noWalkBehindsAtAll; extern char noWalkBehindsAtAll;
@ -697,7 +697,7 @@ void render_to_screen() {
construct_engine_overlay(); construct_engine_overlay();
// only vsync in full screen mode, it makes things worse in a window // only vsync in full screen mode, it makes things worse in a window
gfxDriver->EnableVsyncBeforeRender((scsystem.vsync > 0) && (!scsystem.windowed)); gfxDriver->EnableVsyncBeforeRender((_GP(scsystem).vsync > 0) && (!_GP(scsystem).windowed));
bool succeeded = false; bool succeeded = false;
while (!succeeded) { while (!succeeded) {

View file

@ -83,8 +83,8 @@ int run_claimable_event(const char *tsname, bool includeRoom, int numParams, con
eventClaimed = EVENT_INPROGRESS; eventClaimed = EVENT_INPROGRESS;
int toret; int toret;
if (includeRoom && roominst) { if (includeRoom && _G(roominst)) {
toret = RunScriptFunctionIfExists(roominst, tsname, numParams, params); toret = RunScriptFunctionIfExists(_G(roominst), tsname, numParams, params);
if (eventClaimed == EVENT_CLAIMED) { if (eventClaimed == EVENT_CLAIMED) {
eventClaimed = eventClaimedOldValue; eventClaimed = eventClaimedOldValue;
@ -93,8 +93,8 @@ int run_claimable_event(const char *tsname, bool includeRoom, int numParams, con
} }
// run script modules // run script modules
for (int kk = 0; kk < numScriptModules; kk++) { for (int kk = 0; kk < _G(numScriptModules); kk++) {
toret = RunScriptFunctionIfExists(moduleInst[kk], tsname, numParams, params); toret = RunScriptFunctionIfExists(_GP(moduleInst)[kk], tsname, numParams, params);
if (eventClaimed == EVENT_CLAIMED) { if (eventClaimed == EVENT_CLAIMED) {
eventClaimed = eventClaimedOldValue; eventClaimed = eventClaimedOldValue;

View file

@ -455,8 +455,8 @@ void restore_game_dialog() {
DisplayMessage(983); DisplayMessage(983);
return; return;
} }
if (inside_script) { if (_G(inside_script)) {
curscript->queue_action(ePSARestoreGameDialog, 0, "RestoreGameDialog"); _G(curscript)->queue_action(ePSARestoreGameDialog, 0, "RestoreGameDialog");
return; return;
} }
setup_for_dialog(); setup_for_dialog();
@ -472,8 +472,8 @@ void save_game_dialog() {
DisplayMessage(983); DisplayMessage(983);
return; return;
} }
if (inside_script) { if (_G(inside_script)) {
curscript->queue_action(ePSASaveGameDialog, 0, "SaveGameDialog"); _G(curscript)->queue_action(ePSASaveGameDialog, 0, "SaveGameDialog");
return; return;
} }
setup_for_dialog(); setup_for_dialog();
@ -495,7 +495,7 @@ void unload_game_file() {
_GP(play).FreeViewportsAndCameras(); _GP(play).FreeViewportsAndCameras();
characterScriptObjNames.clear(); _GP(characterScriptObjNames).clear();
free(charextra); free(charextra);
free(_G(mls)); free(_G(mls));
free(actsps); free(actsps);
@ -504,43 +504,43 @@ void unload_game_file() {
free(actspswbbmp); free(actspswbbmp);
free(actspswbcache); free(actspswbcache);
if ((gameinst != nullptr) && (gameinst->pc != 0)) { if ((_G(gameinst) != nullptr) && (_G(gameinst)->pc != 0)) {
quit("Error: unload_game called while script still running"); quit("Error: unload_game called while script still running");
} else { } else {
delete gameinstFork; delete _G(gameinstFork);
delete gameinst; delete _G(gameinst);
gameinstFork = nullptr; _G(gameinstFork) = nullptr;
gameinst = nullptr; _G(gameinst) = nullptr;
} }
gamescript.reset(); _GP(gamescript).reset();
if ((dialogScriptsInst != nullptr) && (dialogScriptsInst->pc != 0)) { if ((_G(dialogScriptsInst) != nullptr) && (_G(dialogScriptsInst)->pc != 0)) {
quit("Error: unload_game called while dialog script still running"); quit("Error: unload_game called while dialog script still running");
} else if (dialogScriptsInst != nullptr) { } else if (_G(dialogScriptsInst) != nullptr) {
delete dialogScriptsInst; delete _G(dialogScriptsInst);
dialogScriptsInst = nullptr; _G(dialogScriptsInst) = nullptr;
} }
dialogScriptsScript.reset(); _GP(dialogScriptsScript).reset();
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
delete moduleInstFork[i]; delete _GP(moduleInstFork)[i];
delete moduleInst[i]; delete _GP(moduleInst)[i];
scriptModules[i].reset(); _GP(scriptModules)[i].reset();
} }
moduleInstFork.resize(0); _GP(moduleInstFork).resize(0);
moduleInst.resize(0); _GP(moduleInst).resize(0);
scriptModules.resize(0); _GP(scriptModules).resize(0);
repExecAlways.moduleHasFunction.resize(0); _GP(repExecAlways).moduleHasFunction.resize(0);
lateRepExecAlways.moduleHasFunction.resize(0); _GP(lateRepExecAlways).moduleHasFunction.resize(0);
getDialogOptionsDimensionsFunc.moduleHasFunction.resize(0); _GP(getDialogOptionsDimensionsFunc).moduleHasFunction.resize(0);
renderDialogOptionsFunc.moduleHasFunction.resize(0); _GP(renderDialogOptionsFunc).moduleHasFunction.resize(0);
getDialogOptionUnderCursorFunc.moduleHasFunction.resize(0); _GP(getDialogOptionUnderCursorFunc).moduleHasFunction.resize(0);
runDialogOptionMouseClickHandlerFunc.moduleHasFunction.resize(0); _GP(runDialogOptionMouseClickHandlerFunc).moduleHasFunction.resize(0);
runDialogOptionKeyPressHandlerFunc.moduleHasFunction.resize(0); _GP(runDialogOptionKeyPressHandlerFunc).moduleHasFunction.resize(0);
runDialogOptionRepExecFunc.moduleHasFunction.resize(0); _GP(runDialogOptionRepExecFunc).moduleHasFunction.resize(0);
numScriptModules = 0; _G(numScriptModules) = 0;
free(_G(views)); free(_G(views));
_G(views) = nullptr; _G(views) = nullptr;
@ -574,7 +574,7 @@ void unload_game_file() {
guibg[i] = nullptr; guibg[i] = nullptr;
} }
guiScriptObjNames.clear(); _GP(guiScriptObjNames).clear();
free(guibg); free(guibg);
_GP(guis).clear(); _GP(guis).clear();
free(_G(scrGui)); free(_G(scrGui));
@ -1007,8 +1007,8 @@ void save_game(int slotn, const char *descript) {
// the state of blocked scripts // the state of blocked scripts
can_run_delayed_command(); can_run_delayed_command();
if (inside_script) { if (_G(inside_script)) {
strcpy(curscript->postScriptSaveSlotDescription[curscript->queue_action(ePSASaveGame, slotn, "SaveGameSlot")], descript); strcpy(_G(curscript)->postScriptSaveSlotDescription[_G(curscript)->queue_action(ePSASaveGame, slotn, "SaveGameSlot")], descript);
return; return;
} }
@ -1083,11 +1083,11 @@ HSaveError restore_game_scripts(Stream *in, const PreservedParams &pp, RestoredD
r_data.GlobalScript.Data.reset(new char[gdatasize]); r_data.GlobalScript.Data.reset(new char[gdatasize]);
in->Read(r_data.GlobalScript.Data.get(), gdatasize); in->Read(r_data.GlobalScript.Data.get(), gdatasize);
if (in->ReadInt32() != numScriptModules) { if (in->ReadInt32() != _G(numScriptModules)) {
return new SavegameError(kSvgErr_GameContentAssertion, "Mismatching number of script modules."); return new SavegameError(kSvgErr_GameContentAssertion, "Mismatching number of script modules.");
} }
r_data.ScriptModules.resize(numScriptModules); r_data.ScriptModules.resize(_G(numScriptModules));
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
size_t module_size = in->ReadInt32(); size_t module_size = in->ReadInt32();
if (pp.ScMdDataSize[i] != (int)module_size) { if (pp.ScMdDataSize[i] != (int)module_size) {
return new SavegameError(kSvgErr_GameContentAssertion, String::FromFormat("Mismatching size of script module data, module %d.", i)); return new SavegameError(kSvgErr_GameContentAssertion, String::FromFormat("Mismatching size of script module data, module %d.", i));
@ -1787,7 +1787,7 @@ void display_switch_in() {
platform->DisplaySwitchIn(); platform->DisplaySwitchIn();
ags_clear_input_buffer(); ags_clear_input_buffer();
// If auto lock option is set, lock mouse to the game window // If auto lock option is set, lock mouse to the game window
if (usetup.mouse_auto_lock && scsystem.windowed) if (usetup.mouse_auto_lock && _GP(scsystem).windowed)
Mouse::TryLockToWindow(); Mouse::TryLockToWindow();
} }
@ -2278,7 +2278,7 @@ void RegisterStaticObjects() {
ccAddExternalStaticObject("gs_globals", &_GP(play).globalvars[0], &GlobalStaticManager); ccAddExternalStaticObject("gs_globals", &_GP(play).globalvars[0], &GlobalStaticManager);
ccAddExternalStaticObject("mouse", &scmouse, &GlobalStaticManager); ccAddExternalStaticObject("mouse", &scmouse, &GlobalStaticManager);
ccAddExternalStaticObject("palette", &palette[0], &GlobalStaticManager); ccAddExternalStaticObject("palette", &palette[0], &GlobalStaticManager);
ccAddExternalStaticObject("system", &scsystem, &GlobalStaticManager); ccAddExternalStaticObject("system", &_GP(scsystem), &GlobalStaticManager);
ccAddExternalStaticObject("savegameindex", &_GP(play).filenumbers[0], &GlobalStaticManager); ccAddExternalStaticObject("savegameindex", &_GP(play).filenumbers[0], &GlobalStaticManager);
} }

View file

@ -47,7 +47,7 @@ using namespace AGS::Engine;
extern CharacterInfo *playerchar; extern CharacterInfo *playerchar;
extern ScriptSystem scsystem;
GameState::GameState() { GameState::GameState() {
Common::fill(&globalvars[0], &globalvars[MAXGLOBALVARS], 0); Common::fill(&globalvars[0], &globalvars[MAXGLOBALVARS], 0);
@ -84,8 +84,8 @@ void GameState::SetAutoRoomViewport(bool on) {
void GameState::SetMainViewport(const Rect &viewport) { void GameState::SetMainViewport(const Rect &viewport) {
_mainViewport.SetRect(viewport); _mainViewport.SetRect(viewport);
Mouse::SetGraphicArea(); Mouse::SetGraphicArea();
scsystem.viewport_width = game_to_data_coord(_mainViewport.GetRect().GetWidth()); _GP(scsystem).viewport_width = game_to_data_coord(_mainViewport.GetRect().GetWidth());
scsystem.viewport_height = game_to_data_coord(_mainViewport.GetRect().GetHeight()); _GP(scsystem).viewport_height = game_to_data_coord(_mainViewport.GetRect().GetHeight());
_mainViewportHasChanged = true; _mainViewportHasChanged = true;
} }

View file

@ -57,8 +57,8 @@ void RunDialog(int tum) {
get_script_position(last_in_dialog_request_script_pos); get_script_position(last_in_dialog_request_script_pos);
if (inside_script) if (_G(inside_script))
curscript->queue_action(ePSARunDialog, tum, "RunDialog"); _G(curscript)->queue_action(ePSARunDialog, tum, "RunDialog");
else else
do_conversation(tum); do_conversation(tum);
} }

View file

@ -77,20 +77,14 @@ using namespace AGS::Shared;
#define ALLEGRO_KEYBOARD_HANDLER #define ALLEGRO_KEYBOARD_HANDLER
extern ExecutingScript *curscript;
extern int displayed_room; extern int displayed_room;
extern int game_paused; extern int game_paused;
extern char gamefilenamebuf[200]; extern char gamefilenamebuf[200];
extern GameSetup usetup; extern GameSetup usetup;
extern unsigned int load_new_game; extern unsigned int load_new_game;
extern int load_new_game_restore; extern int load_new_game_restore;
extern RoomStatus *croom; extern RoomStatus *croom;
extern int gui_disabled_style; extern int gui_disabled_style;
extern int getloctype_index; extern int getloctype_index;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
extern color palette[256]; extern color palette[256];
@ -111,8 +105,8 @@ void GiveScore(int amnt) {
void restart_game() { void restart_game() {
can_run_delayed_command(); can_run_delayed_command();
if (inside_script) { if (_G(inside_script)) {
curscript->queue_action(ePSARestartGame, 0, "RestartGame"); _G(curscript)->queue_action(ePSARestartGame, 0, "RestartGame");
return; return;
} }
try_restore_save(RESTART_POINT_SAVE_GAME_NUMBER); try_restore_save(RESTART_POINT_SAVE_GAME_NUMBER);
@ -123,8 +117,8 @@ void RestoreGameSlot(int slnum) {
quit("!RestoreGameSlot: a game cannot be restored from within game_start"); quit("!RestoreGameSlot: a game cannot be restored from within game_start");
can_run_delayed_command(); can_run_delayed_command();
if (inside_script) { if (_G(inside_script)) {
curscript->queue_action(ePSARestoreGame, slnum, "RestoreGameSlot"); _G(curscript)->queue_action(ePSARestoreGame, slnum, "RestoreGameSlot");
return; return;
} }
try_restore_save(slnum); try_restore_save(slnum);
@ -258,8 +252,8 @@ int RunAGSGame(const char *newgame, unsigned int mode, int data) {
_GP(play).takeover_data = data; _GP(play).takeover_data = data;
load_new_game_restore = -1; load_new_game_restore = -1;
if (inside_script) { if (_G(inside_script)) {
curscript->queue_action(ePSARunAGSGame, mode | RAGMODE_LOADNOW, "RunAGSGame"); _G(curscript)->queue_action(ePSARunAGSGame, mode | RAGMODE_LOADNOW, "RunAGSGame");
ccInstance::GetCurrentInstance()->Abort(); ccInstance::GetCurrentInstance()->Abort();
} else } else
load_new_game = mode | RAGMODE_LOADNOW; load_new_game = mode | RAGMODE_LOADNOW;
@ -869,7 +863,7 @@ void SetMultitasking(int mode) {
} }
// Don't allow background running if full screen // Don't allow background running if full screen
if ((mode == 1) && (!scsystem.windowed)) if ((mode == 1) && (!_GP(scsystem).windowed))
mode = 0; mode = 0;
if (mode == 0) { if (mode == 0) {

View file

@ -30,11 +30,8 @@
namespace AGS3 { namespace AGS3 {
extern ExecutingScript *curscript;
void sc_invscreen() { void sc_invscreen() {
curscript->queue_action(ePSAInvScreen, 0, "InventoryScreen"); _G(curscript)->queue_action(ePSAInvScreen, 0, "InventoryScreen");
} }
void SetInvDimensions(int ww, int hh) { void SetInvDimensions(int ww, int hh) {

View file

@ -120,11 +120,11 @@ void NewRoom(int nrnum) {
} else if (in_inv_screen) { } else if (in_inv_screen) {
inv_screen_newroom = nrnum; inv_screen_newroom = nrnum;
return; return;
} else if ((inside_script == 0) & (in_graph_script == 0)) { } else if ((_G(inside_script) == 0) & (_G(in_graph_script) == 0)) {
new_room(nrnum, playerchar); new_room(nrnum, playerchar);
return; return;
} else if (inside_script) { } else if (_G(inside_script)) {
curscript->queue_action(ePSANewRoom, nrnum, "NewRoom"); _G(curscript)->queue_action(ePSANewRoom, nrnum, "NewRoom");
// we might be within a MoveCharacterBlocking -- the room // we might be within a MoveCharacterBlocking -- the room
// change should abort it // change should abort it
if ((playerchar->walking > 0) && (playerchar->walking < TURNING_AROUND)) { if ((playerchar->walking > 0) && (playerchar->walking < TURNING_AROUND)) {
@ -133,7 +133,7 @@ void NewRoom(int nrnum) {
_G(mls)[playerchar->walking].direct = 1; _G(mls)[playerchar->walking].direct = 1;
StopMoving(_GP(game).playercharacter); StopMoving(_GP(game).playercharacter);
} }
} else if (in_graph_script) } else if (_G(in_graph_script))
gs_to_newroom = nrnum; gs_to_newroom = nrnum;
} }
@ -179,12 +179,12 @@ int HasPlayerBeenInRoom(int roomnum) {
void CallRoomScript(int value) { void CallRoomScript(int value) {
can_run_delayed_command(); can_run_delayed_command();
if (!inside_script) if (!_G(inside_script))
quit("!CallRoomScript: not inside a script???"); quit("!CallRoomScript: not inside a script???");
_GP(play).roomscript_finished = 0; _GP(play).roomscript_finished = 0;
RuntimeScriptValue rval_null; RuntimeScriptValue rval_null;
curscript->run_another("on_call", kScInstRoom, 1, RuntimeScriptValue().SetInt32(value), rval_null); _G(curscript)->run_another("on_call", kScInstRoom, 1, RuntimeScriptValue().SetInt32(value), rval_null);
} }
int HasBeenToRoom(int roomnum) { int HasBeenToRoom(int roomnum) {

View file

@ -64,22 +64,12 @@ namespace AGS3 {
using namespace AGS::Shared; using namespace AGS::Shared;
using namespace AGS::Engine; using namespace AGS::Engine;
extern GameSetup usetup; extern GameSetup usetup;
extern int cur_mode, cur_cursor; extern int cur_mode, cur_cursor;
extern ccInstance *gameinst;
extern Bitmap **guibg; extern Bitmap **guibg;
extern IDriverDependantBitmap **guibgbmp; extern IDriverDependantBitmap **guibgbmp;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
int ifacepopped = -1; // currently displayed pop-up GUI (-1 if none) int ifacepopped = -1; // currently displayed pop-up GUI (-1 if none)
int mouse_on_iface = -1; // mouse cursor is over this interface int mouse_on_iface = -1; // mouse cursor is over this interface
int mouse_ifacebut_xoffs = -1, mouse_ifacebut_yoffs = -1; int mouse_ifacebut_xoffs = -1, mouse_ifacebut_yoffs = -1;
@ -363,7 +353,7 @@ void process_interface_click(int ifce, int btn, int mbut) {
// otherwise, run interface_click // otherwise, run interface_click
if ((theObj->GetEventCount() > 0) && if ((theObj->GetEventCount() > 0) &&
(!theObj->EventHandlers[0].IsEmpty()) && (!theObj->EventHandlers[0].IsEmpty()) &&
(!gameinst->GetSymbolAddress(theObj->EventHandlers[0]).IsNull())) { (!_G(gameinst)->GetSymbolAddress(theObj->EventHandlers[0]).IsNull())) {
// control-specific event handler // control-specific event handler
if (strchr(theObj->GetEventArgs(0), ',') != nullptr) if (strchr(theObj->GetEventArgs(0), ',') != nullptr)
QueueScriptFunction(kScInstGame, theObj->EventHandlers[0], 2, QueueScriptFunction(kScInstGame, theObj->EventHandlers[0], 2,

View file

@ -54,7 +54,7 @@ using namespace AGS::Engine;
extern ScriptSystem scsystem;
extern CharacterInfo *playerchar; extern CharacterInfo *playerchar;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
@ -328,7 +328,7 @@ int IsModeEnabled(int which) {
void Mouse_EnableControl(bool on) { void Mouse_EnableControl(bool on) {
usetup.mouse_ctrl_enabled = on; // remember setting in config usetup.mouse_ctrl_enabled = on; // remember setting in config
bool is_windowed = scsystem.windowed != 0; bool is_windowed = _GP(scsystem).windowed != 0;
// Whether mouse movement should be controlled by the engine - this is // Whether mouse movement should be controlled by the engine - this is
// determined based on related config option. // determined based on related config option.
bool should_control_mouse = usetup.mouse_ctrl_when == kMouseCtrl_Always || bool should_control_mouse = usetup.mouse_ctrl_when == kMouseCtrl_Always ||

View file

@ -74,7 +74,6 @@
#include "ags/engine/gfx/gfxfilter.h" #include "ags/engine/gfx/gfxfilter.h"
#include "ags/shared/util/math.h" #include "ags/shared/util/math.h"
#include "ags/engine/media/audio/audio_system.h" #include "ags/engine/media/audio/audio_system.h"
#include "ags/shared/debugging/out.h" #include "ags/shared/debugging/out.h"
#include "ags/engine/script/script_api.h" #include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h" #include "ags/engine/script/script_runtime.h"
@ -92,17 +91,13 @@ extern GameSetup usetup;
extern RoomStatus *croom; extern RoomStatus *croom;
extern int displayed_room; extern int displayed_room;
extern RoomObject *objs; extern RoomObject *objs;
extern ccInstance *roominst;
extern AGSPlatformDriver *platform; extern AGSPlatformDriver *platform;
extern int numevents; extern int numevents;
extern CharacterExtras *charextra; extern CharacterExtras *charextra;
extern int done_es_error; extern int done_es_error;
extern int our_eip; extern int our_eip;
extern Bitmap *walkareabackup, *walkable_areas_temp; extern Bitmap *walkareabackup, *walkable_areas_temp;
extern int in_new_room, new_room_was; // 1 in new room, 2 first time in new room, 3 loading saved game extern int in_new_room, new_room_was; // 1 in new room, 2 first time in new room, 3 loading saved game
extern int in_leaves_screen; extern int in_leaves_screen;
@ -243,10 +238,10 @@ void convert_room_background_to_game_res() {
void save_room_data_segment() { void save_room_data_segment() {
croom->FreeScriptData(); croom->FreeScriptData();
croom->tsdatasize = roominst->globaldatasize; croom->tsdatasize = _G(roominst)->globaldatasize;
if (croom->tsdatasize > 0) { if (croom->tsdatasize > 0) {
croom->tsdata = (char *)malloc(croom->tsdatasize + 10); croom->tsdata = (char *)malloc(croom->tsdatasize + 10);
memcpy(croom->tsdata, &roominst->globaldata[0], croom->tsdatasize); memcpy(croom->tsdata, &_G(roominst)->globaldata[0], croom->tsdatasize);
} }
} }
@ -281,12 +276,12 @@ void unload_old_room() {
} }
if (croom == nullptr) ; if (croom == nullptr) ;
else if (roominst != nullptr) { else if (_G(roominst) != nullptr) {
save_room_data_segment(); save_room_data_segment();
delete roominstFork; delete _G(roominstFork);
delete roominst; delete _G(roominst);
roominstFork = nullptr; _G(roominstFork) = nullptr;
roominst = nullptr; _G(roominst) = nullptr;
} else croom->tsdatasize = 0; } else croom->tsdatasize = 0;
memset(&_GP(play).walkable_areas_on[0], 1, MAX_WALK_AREAS + 1); memset(&_GP(play).walkable_areas_on[0], 1, MAX_WALK_AREAS + 1);
_GP(play).bg_frame = 0; _GP(play).bg_frame = 0;
@ -315,10 +310,10 @@ void unload_old_room() {
for (ff = 0; ff < croom->numobj; ff++) { for (ff = 0; ff < croom->numobj; ff++) {
// un-export the object's script object // un-export the object's script object
if (objectScriptObjNames[ff].IsEmpty()) if (_G(objectScriptObjNames)[ff].IsEmpty())
continue; continue;
ccRemoveExternalSymbol(objectScriptObjNames[ff]); ccRemoveExternalSymbol(_G(objectScriptObjNames)[ff]);
} }
for (ff = 0; ff < MAX_ROOM_HOTSPOTS; ff++) { for (ff = 0; ff < MAX_ROOM_HOTSPOTS; ff++) {
@ -643,15 +638,15 @@ void load_new_room(int newnum, CharacterInfo *forchar) {
for (cc = 0; cc < MAX_ROOM_OBJECTS; cc++) { for (cc = 0; cc < MAX_ROOM_OBJECTS; cc++) {
// 64 bit: Using the id instead // 64 bit: Using the id instead
// _G(scrObj)[cc].obj = &croom->obj[cc]; // _G(scrObj)[cc].obj = &croom->obj[cc];
objectScriptObjNames[cc].Free(); _G(objectScriptObjNames)[cc].Free();
} }
for (cc = 0; cc < croom->numobj; cc++) { for (cc = 0; cc < croom->numobj; cc++) {
// export the object's script object // export the object's script object
if (_GP(thisroom).Objects[cc].ScriptName.IsEmpty()) if (_GP(thisroom).Objects[cc].ScriptName.IsEmpty())
continue; continue;
objectScriptObjNames[cc] = _GP(thisroom).Objects[cc].ScriptName; _G(objectScriptObjNames)[cc] = _GP(thisroom).Objects[cc].ScriptName;
ccAddExternalDynamicObject(objectScriptObjNames[cc], &_G(scrObj)[cc], &_GP(ccDynamicObject)); ccAddExternalDynamicObject(_G(objectScriptObjNames)[cc], &_G(scrObj)[cc], &_GP(ccDynamicObject));
} }
for (cc = 0; cc < MAX_ROOM_HOTSPOTS; cc++) { for (cc = 0; cc < MAX_ROOM_HOTSPOTS; cc++) {
@ -720,14 +715,14 @@ void load_new_room(int newnum, CharacterInfo *forchar) {
update_polled_stuff_if_runtime(); update_polled_stuff_if_runtime();
roominst = nullptr; _G(roominst) = nullptr;
if (debug_flags & DBG_NOSCRIPT) ; if (debug_flags & DBG_NOSCRIPT) ;
else if (_GP(thisroom).CompiledScript != nullptr) { else if (_GP(thisroom).CompiledScript != nullptr) {
compile_room_script(); compile_room_script();
if (croom->tsdatasize > 0) { if (croom->tsdatasize > 0) {
if (croom->tsdatasize != roominst->globaldatasize) if (croom->tsdatasize != _G(roominst)->globaldatasize)
quit("room script data segment size has changed"); quit("room script data segment size has changed");
memcpy(&roominst->globaldata[0], croom->tsdata, croom->tsdatasize); memcpy(&_G(roominst)->globaldata[0], croom->tsdata, croom->tsdatasize);
} }
} }
our_eip = 207; our_eip = 207;
@ -1003,19 +998,19 @@ void check_new_room() {
void compile_room_script() { void compile_room_script() {
ccError = 0; ccError = 0;
roominst = ccInstance::CreateFromScript(_GP(thisroom).CompiledScript); _G(roominst) = ccInstance::CreateFromScript(_GP(thisroom).CompiledScript);
if ((ccError != 0) || (roominst == nullptr)) { if ((ccError != 0) || (_G(roominst) == nullptr)) {
quitprintf("Unable to create local script: %s", ccErrorString.GetCStr()); quitprintf("Unable to create local script: %s", ccErrorString.GetCStr());
} }
roominstFork = roominst->Fork(); _G(roominstFork) = _G(roominst)->Fork();
if (roominstFork == nullptr) if (_G(roominstFork) == nullptr)
quitprintf("Unable to create forked room instance: %s", ccErrorString.GetCStr()); quitprintf("Unable to create forked room instance: %s", ccErrorString.GetCStr());
repExecAlways.roomHasFunction = true; _GP(repExecAlways).roomHasFunction = true;
lateRepExecAlways.roomHasFunction = true; _GP(lateRepExecAlways).roomHasFunction = true;
getDialogOptionsDimensionsFunc.roomHasFunction = true; _GP(getDialogOptionsDimensionsFunc).roomHasFunction = true;
} }
int bg_just_changed = 0; int bg_just_changed = 0;

View file

@ -54,7 +54,7 @@ using namespace AGS::Engine;
extern GameSetup usetup; extern GameSetup usetup;
extern ScriptAudioChannel scrAudioChannel[MAX_SOUND_CHANNELS + 1]; extern ScriptAudioChannel scrAudioChannel[MAX_SOUND_CHANNELS + 1];
extern ScriptSystem scsystem;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
extern volatile bool switched_away; extern volatile bool switched_away;
@ -64,11 +64,11 @@ bool System_HasInputFocus() {
} }
int System_GetColorDepth() { int System_GetColorDepth() {
return scsystem.coldepth; return _GP(scsystem).coldepth;
} }
int System_GetOS() { int System_GetOS() {
return scsystem.os; return _GP(scsystem).os;
} }
// [IKM] 2014-09-21 // [IKM] 2014-09-21
@ -133,20 +133,20 @@ void System_SetNumLock(int newValue) {
} }
int System_GetVsync() { int System_GetVsync() {
return scsystem.vsync; return _GP(scsystem).vsync;
} }
void System_SetVsync(int newValue) { void System_SetVsync(int newValue) {
if (ags_stricmp(gfxDriver->GetDriverID(), "D3D9") != 0) if (ags_stricmp(gfxDriver->GetDriverID(), "D3D9") != 0)
scsystem.vsync = newValue; _GP(scsystem).vsync = newValue;
} }
int System_GetWindowed() { int System_GetWindowed() {
return scsystem.windowed; return _GP(scsystem).windowed;
} }
void System_SetWindowed(int windowed) { void System_SetWindowed(int windowed) {
if (windowed != scsystem.windowed) if (windowed != _GP(scsystem).windowed)
engine_try_switch_windowed_gfxmode(); engine_try_switch_windowed_gfxmode();
} }

View file

@ -291,11 +291,11 @@ void debug_script_print(const String &msg, MessageType mt) {
ccInstance *curinst = ccInstance::GetCurrentInstance(); ccInstance *curinst = ccInstance::GetCurrentInstance();
if (curinst != nullptr) { if (curinst != nullptr) {
String scriptname; String scriptname;
if (curinst->instanceof == gamescript) if (curinst->instanceof == _GP(gamescript))
scriptname = "G "; scriptname = "G ";
else if (curinst->instanceof == _GP(thisroom).CompiledScript) else if (curinst->instanceof == _GP(thisroom).CompiledScript)
scriptname = "R "; scriptname = "R ";
else if (curinst->instanceof == dialogScriptsScript) else if (curinst->instanceof == _GP(dialogScriptsScript))
scriptname = "D "; scriptname = "D ";
else else
scriptname = "? "; scriptname = "? ";

View file

@ -79,10 +79,6 @@ extern StaticArray StaticRegionArray;
extern StaticArray StaticInventoryArray; extern StaticArray StaticInventoryArray;
extern StaticArray StaticDialogArray; extern StaticArray StaticDialogArray;
extern std::vector<ccInstance *> moduleInst;
extern std::vector<ccInstance *> moduleInstFork;
extern std::vector<RuntimeScriptValue> moduleRepExecAddr;
// Old dialog support (defined in ac/dialog) // Old dialog support (defined in ac/dialog)
extern std::vector< std::shared_ptr<unsigned char> > old_dialog_scripts; extern std::vector< std::shared_ptr<unsigned char> > old_dialog_scripts;
extern std::vector<String> old_speech_lines; extern std::vector<String> old_speech_lines;
@ -138,7 +134,7 @@ void InitAndRegisterAudioObjects() {
// Initializes characters and registers them in the script system // Initializes characters and registers them in the script system
void InitAndRegisterCharacters() { void InitAndRegisterCharacters() {
characterScriptObjNames.resize(_GP(game).numcharacters); _GP(characterScriptObjNames).resize(_GP(game).numcharacters);
for (int i = 0; i < _GP(game).numcharacters; ++i) { for (int i = 0; i < _GP(game).numcharacters; ++i) {
_GP(game).chars[i].walking = 0; _GP(game).chars[i].walking = 0;
_GP(game).chars[i].animating = 0; _GP(game).chars[i].animating = 0;
@ -156,8 +152,8 @@ void InitAndRegisterCharacters() {
ccRegisterManagedObject(&_GP(game).chars[i], &_GP(ccDynamicCharacter)); ccRegisterManagedObject(&_GP(game).chars[i], &_GP(ccDynamicCharacter));
// export the character's script object // export the character's script object
characterScriptObjNames[i] = _GP(game).chars[i].scrname; _GP(characterScriptObjNames)[i] = _GP(game).chars[i].scrname;
ccAddExternalDynamicObject(characterScriptObjNames[i], &_GP(game).chars[i], &_GP(ccDynamicCharacter)); ccAddExternalDynamicObject(_GP(characterScriptObjNames)[i], &_GP(game).chars[i], &_GP(ccDynamicCharacter));
} }
} }
@ -191,7 +187,7 @@ HError InitAndRegisterGUI() {
_G(scrGui)[i].id = -1; _G(scrGui)[i].id = -1;
} }
guiScriptObjNames.resize(_GP(game).numgui); _GP(guiScriptObjNames).resize(_GP(game).numgui);
for (int i = 0; i < _GP(game).numgui; ++i) { for (int i = 0; i < _GP(game).numgui; ++i) {
// link controls to their parent guis // link controls to their parent guis
HError err = _GP(guis)[i].RebuildArray(); HError err = _GP(guis)[i].RebuildArray();
@ -201,9 +197,9 @@ HError InitAndRegisterGUI() {
export_gui_controls(i); export_gui_controls(i);
// copy the script name to its own memory location // copy the script name to its own memory location
// because ccAddExtSymbol only keeps a reference // because ccAddExtSymbol only keeps a reference
guiScriptObjNames[i] = _GP(guis)[i].Name; _GP(guiScriptObjNames)[i] = _GP(guis)[i].Name;
_G(scrGui)[i].id = i; _G(scrGui)[i].id = i;
ccAddExternalDynamicObject(guiScriptObjNames[i], &_G(scrGui)[i], &_GP(ccDynamicGUI)); ccAddExternalDynamicObject(_GP(guiScriptObjNames)[i], &_G(scrGui)[i], &_GP(ccDynamicGUI));
ccRegisterManagedObject(&_G(scrGui)[i], &_GP(ccDynamicGUI)); ccRegisterManagedObject(&_G(scrGui)[i], &_GP(ccDynamicGUI));
} }
return HError::None(); return HError::None();
@ -297,19 +293,19 @@ void LoadFonts(GameDataVersion data_ver) {
} }
void AllocScriptModules() { void AllocScriptModules() {
moduleInst.resize(numScriptModules, nullptr); _GP(moduleInst).resize(_G(numScriptModules), nullptr);
moduleInstFork.resize(numScriptModules, nullptr); _GP(moduleInstFork).resize(_G(numScriptModules), nullptr);
moduleRepExecAddr.resize(numScriptModules); _GP(moduleRepExecAddr).resize(_G(numScriptModules));
repExecAlways.moduleHasFunction.resize(numScriptModules, true); _GP(repExecAlways).moduleHasFunction.resize(_G(numScriptModules), true);
lateRepExecAlways.moduleHasFunction.resize(numScriptModules, true); _GP(lateRepExecAlways).moduleHasFunction.resize(_G(numScriptModules), true);
getDialogOptionsDimensionsFunc.moduleHasFunction.resize(numScriptModules, true); _GP(getDialogOptionsDimensionsFunc).moduleHasFunction.resize(_G(numScriptModules), true);
renderDialogOptionsFunc.moduleHasFunction.resize(numScriptModules, true); _GP(renderDialogOptionsFunc).moduleHasFunction.resize(_G(numScriptModules), true);
getDialogOptionUnderCursorFunc.moduleHasFunction.resize(numScriptModules, true); _GP(getDialogOptionUnderCursorFunc).moduleHasFunction.resize(_G(numScriptModules), true);
runDialogOptionMouseClickHandlerFunc.moduleHasFunction.resize(numScriptModules, true); _GP(runDialogOptionMouseClickHandlerFunc).moduleHasFunction.resize(_G(numScriptModules), true);
runDialogOptionKeyPressHandlerFunc.moduleHasFunction.resize(numScriptModules, true); _GP(runDialogOptionKeyPressHandlerFunc).moduleHasFunction.resize(_G(numScriptModules), true);
runDialogOptionRepExecFunc.moduleHasFunction.resize(numScriptModules, true); _GP(runDialogOptionRepExecFunc).moduleHasFunction.resize(_G(numScriptModules), true);
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
moduleRepExecAddr[i].Invalidate(); _GP(moduleRepExecAddr)[i].Invalidate();
} }
} }
@ -422,10 +418,10 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
// NOTE: we must do this after plugins, because some plugins may export // NOTE: we must do this after plugins, because some plugins may export
// script symbols too. // script symbols too.
// //
gamescript = ents.GlobalScript; _GP(gamescript) = ents.GlobalScript;
dialogScriptsScript = ents.DialogScript; _GP(dialogScriptsScript) = ents.DialogScript;
numScriptModules = ents.ScriptModules.size(); _G(numScriptModules) = ents.ScriptModules.size();
scriptModules = ents.ScriptModules; _GP(scriptModules) = ents.ScriptModules;
AllocScriptModules(); AllocScriptModules();
if (create_global_script()) if (create_global_script())
return new GameInitError(kGameInitErr_ScriptLinkFailed, ccErrorString); return new GameInitError(kGameInitErr_ScriptLinkFailed, ccErrorString);

View file

@ -356,29 +356,29 @@ void DoBeforeRestore(PreservedParams &pp) {
} }
// preserve script data sizes and cleanup scripts // preserve script data sizes and cleanup scripts
pp.GlScDataSize = gameinst->globaldatasize; pp.GlScDataSize = _G(gameinst)->globaldatasize;
delete gameinstFork; delete _G(gameinstFork);
delete gameinst; delete _G(gameinst);
gameinstFork = nullptr; _G(gameinstFork) = nullptr;
gameinst = nullptr; _G(gameinst) = nullptr;
pp.ScMdDataSize.resize(numScriptModules); pp.ScMdDataSize.resize(_G(numScriptModules));
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
pp.ScMdDataSize[i] = moduleInst[i]->globaldatasize; pp.ScMdDataSize[i] = _GP(moduleInst)[i]->globaldatasize;
delete moduleInstFork[i]; delete _GP(moduleInstFork)[i];
delete moduleInst[i]; delete _GP(moduleInst)[i];
moduleInst[i] = nullptr; _GP(moduleInst)[i] = nullptr;
} }
_GP(play).FreeProperties(); _GP(play).FreeProperties();
_GP(play).FreeViewportsAndCameras(); _GP(play).FreeViewportsAndCameras();
delete roominstFork; delete _G(roominstFork);
delete roominst; delete _G(roominst);
roominstFork = nullptr; _G(roominstFork) = nullptr;
roominst = nullptr; _G(roominst) = nullptr;
delete dialogScriptsInst; delete _G(dialogScriptsInst);
dialogScriptsInst = nullptr; _G(dialogScriptsInst) = nullptr;
resetRoomStatuses(); resetRoomStatuses();
_GP(troom).FreeScriptData(); _GP(troom).FreeScriptData();
@ -468,14 +468,14 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
// read the global data into the newly created script // read the global data into the newly created script
if (r_data.GlobalScript.Data.get()) if (r_data.GlobalScript.Data.get())
memcpy(gameinst->globaldata, r_data.GlobalScript.Data.get(), memcpy(_G(gameinst)->globaldata, r_data.GlobalScript.Data.get(),
Math::Min((size_t)gameinst->globaldatasize, r_data.GlobalScript.Len)); Math::Min((size_t)_G(gameinst)->globaldatasize, r_data.GlobalScript.Len));
// restore the script module data // restore the script module data
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
if (r_data.ScriptModules[i].Data.get()) if (r_data.ScriptModules[i].Data.get())
memcpy(moduleInst[i]->globaldata, r_data.ScriptModules[i].Data.get(), memcpy(_GP(moduleInst)[i]->globaldata, r_data.ScriptModules[i].Data.get(),
Math::Min((size_t)moduleInst[i]->globaldatasize, r_data.ScriptModules[i].Len)); Math::Min((size_t)_GP(moduleInst)[i]->globaldatasize, r_data.ScriptModules[i].Len));
} }
setup_player_character(_GP(game).playercharacter); setup_player_character(_GP(game).playercharacter);
@ -731,7 +731,7 @@ void DoBeforeSave() {
if (displayed_room >= 0) { if (displayed_room >= 0) {
// update the current room script's data segment copy // update the current room script's data segment copy
if (roominst) if (_G(roominst))
save_room_data_segment(); save_room_data_segment();
// Update the saved interaction variable values // Update the saved interaction variable values

View file

@ -808,17 +808,17 @@ HSaveError ReadDynamicSurfaces(PStream in, int32_t cmp_ver, const PreservedParam
HSaveError WriteScriptModules(PStream out) { HSaveError WriteScriptModules(PStream out) {
// write the data segment of the global script // write the data segment of the global script
int data_len = gameinst->globaldatasize; int data_len = _G(gameinst)->globaldatasize;
out->WriteInt32(data_len); out->WriteInt32(data_len);
if (data_len > 0) if (data_len > 0)
out->Write(gameinst->globaldata, data_len); out->Write(_G(gameinst)->globaldata, data_len);
// write the script modules data segments // write the script modules data segments
out->WriteInt32(numScriptModules); out->WriteInt32(_G(numScriptModules));
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
data_len = moduleInst[i]->globaldatasize; data_len = _GP(moduleInst)[i]->globaldatasize;
out->WriteInt32(data_len); out->WriteInt32(data_len);
if (data_len > 0) if (data_len > 0)
out->Write(moduleInst[i]->globaldata, data_len); out->Write(_GP(moduleInst)[i]->globaldata, data_len);
} }
return HSaveError::None(); return HSaveError::None();
} }
@ -833,10 +833,10 @@ HSaveError ReadScriptModules(PStream in, int32_t cmp_ver, const PreservedParams
r_data.GlobalScript.Data.reset(new char[data_len]); r_data.GlobalScript.Data.reset(new char[data_len]);
in->Read(r_data.GlobalScript.Data.get(), data_len); in->Read(r_data.GlobalScript.Data.get(), data_len);
if (!AssertGameContent(err, in->ReadInt32(), numScriptModules, "Script Modules")) if (!AssertGameContent(err, in->ReadInt32(), _G(numScriptModules), "Script Modules"))
return err; return err;
r_data.ScriptModules.resize(numScriptModules); r_data.ScriptModules.resize(_G(numScriptModules));
for (int i = 0; i < numScriptModules; ++i) { for (int i = 0; i < _G(numScriptModules); ++i) {
data_len = in->ReadInt32(); data_len = in->ReadInt32();
if (!AssertGameObjectContent(err, data_len, pp.ScMdDataSize[i], "script module data", "module", i)) if (!AssertGameObjectContent(err, data_len, pp.ScMdDataSize[i], "script module data", "module", i))
return err; return err;

View file

@ -96,7 +96,7 @@ extern int eip_guinum;
extern int eip_guiobj; extern int eip_guiobj;
extern SpeechLipSyncLine *splipsync; extern SpeechLipSyncLine *splipsync;
extern int numLipLines, curLipLine, curLipLinePhoneme; extern int numLipLines, curLipLine, curLipLinePhoneme;
extern ScriptSystem scsystem;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
extern Bitmap **actsps; extern Bitmap **actsps;
extern color palette[256]; extern color palette[256];
@ -901,11 +901,11 @@ void engine_init_game_settings() {
void engine_setup_scsystem_auxiliary() { void engine_setup_scsystem_auxiliary() {
// ScriptSystem::aci_version is only 10 chars long // ScriptSystem::aci_version is only 10 chars long
strncpy(scsystem.aci_version, _G(EngineVersion).LongString, 10); strncpy(_GP(scsystem).aci_version, _G(EngineVersion).LongString, 10);
if (usetup.override_script_os >= 0) { if (usetup.override_script_os >= 0) {
scsystem.os = usetup.override_script_os; _GP(scsystem).os = usetup.override_script_os;
} else { } else {
scsystem.os = platform->GetSystemOSID(); _GP(scsystem).os = platform->GetSystemOSID();
} }
} }

View file

@ -51,7 +51,7 @@ using namespace AGS::Shared;
using namespace AGS::Engine; using namespace AGS::Engine;
extern ScriptSystem scsystem;
extern int _places_r, _places_g, _places_b; extern int _places_r, _places_g, _places_b;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
@ -123,10 +123,10 @@ void convert_objects_to_data_resolution(GameDataVersion filever) {
} }
void engine_setup_system_gamesize() { void engine_setup_system_gamesize() {
scsystem.width = _GP(game).GetGameRes().Width; _GP(scsystem).width = _GP(game).GetGameRes().Width;
scsystem.height = _GP(game).GetGameRes().Height; _GP(scsystem).height = _GP(game).GetGameRes().Height;
scsystem.viewport_width = game_to_data_coord(_GP(play).GetMainViewport().GetWidth()); _GP(scsystem).viewport_width = game_to_data_coord(_GP(play).GetMainViewport().GetWidth());
scsystem.viewport_height = game_to_data_coord(_GP(play).GetMainViewport().GetHeight()); _GP(scsystem).viewport_height = game_to_data_coord(_GP(play).GetMainViewport().GetHeight());
} }
void engine_init_resolution_settings(const Size game_size) { void engine_init_resolution_settings(const Size game_size) {
@ -281,7 +281,7 @@ void engine_post_gfxmode_mouse_setup(const DisplayMode &dm, const Size &init_des
on_coordinates_scaling_changed(); on_coordinates_scaling_changed();
// If auto lock option is set, lock mouse to the game window // If auto lock option is set, lock mouse to the game window
if (usetup.mouse_auto_lock && scsystem.windowed != 0) if (usetup.mouse_auto_lock && _GP(scsystem).windowed != 0)
Mouse::TryLockToWindow(); Mouse::TryLockToWindow();
} }
@ -294,16 +294,16 @@ void engine_pre_gfxmode_mouse_cleanup() {
// Fill in scsystem struct with display mode parameters // Fill in scsystem struct with display mode parameters
void engine_setup_scsystem_screen(const DisplayMode &dm) { void engine_setup_scsystem_screen(const DisplayMode &dm) {
scsystem.coldepth = dm.ColorDepth; _GP(scsystem).coldepth = dm.ColorDepth;
scsystem.windowed = dm.Windowed; _GP(scsystem).windowed = dm.Windowed;
scsystem.vsync = dm.Vsync; _GP(scsystem).vsync = dm.Vsync;
} }
void engine_post_gfxmode_setup(const Size &init_desktop) { void engine_post_gfxmode_setup(const Size &init_desktop) {
DisplayMode dm = gfxDriver->GetDisplayMode(); DisplayMode dm = gfxDriver->GetDisplayMode();
// If color depth has changed (or graphics mode was inited for the // If color depth has changed (or graphics mode was inited for the
// very first time), we also need to recreate bitmaps // very first time), we also need to recreate bitmaps
bool has_driver_changed = scsystem.coldepth != dm.ColorDepth; bool has_driver_changed = _GP(scsystem).coldepth != dm.ColorDepth;
engine_setup_scsystem_screen(dm); engine_setup_scsystem_screen(dm);
engine_post_gfxmode_driver_setup(); engine_post_gfxmode_driver_setup();
@ -316,7 +316,7 @@ void engine_post_gfxmode_setup(const Size &init_desktop) {
// "windowed" flag to be specified. Find out whether this function // "windowed" flag to be specified. Find out whether this function
// has anything to do with graphics mode at all. It is quite possible // has anything to do with graphics mode at all. It is quite possible
// that we may split it into two functions, or remove parameter. // that we may split it into two functions, or remove parameter.
platform->PostAllegroInit(scsystem.windowed != 0); platform->PostAllegroInit(_GP(scsystem).windowed != 0);
video_on_gfxmode_changed(); video_on_gfxmode_changed();
invalidate_screen(); invalidate_screen();

View file

@ -60,14 +60,8 @@ using namespace AGS::Shared;
using namespace AGS::Engine; using namespace AGS::Engine;
extern int ifacepopped; extern int ifacepopped;
extern DialogTopic *dialog; extern DialogTopic *dialog;
extern AGSPlatformDriver *platform; extern AGSPlatformDriver *platform;
extern int numScriptModules;
// Test if engine supports extended capabilities required to run the game // Test if engine supports extended capabilities required to run the game
bool test_game_caps(const std::set<String> &caps, std::set<String> &failed_caps) { bool test_game_caps(const std::set<String> &caps, std::set<String> &failed_caps) {

View file

@ -86,8 +86,6 @@ extern int game_paused;
extern int getloctype_index; extern int getloctype_index;
extern int in_enters_screen, done_es_error; extern int in_enters_screen, done_es_error;
extern int in_leaves_screen; extern int in_leaves_screen;
extern int inside_script, in_graph_script;
extern int no_blocking_functions;
extern CharacterInfo *playerchar; extern CharacterInfo *playerchar;
extern int mouse_ifacebut_xoffs, mouse_ifacebut_yoffs; extern int mouse_ifacebut_xoffs, mouse_ifacebut_yoffs;
extern int cur_mode; extern int cur_mode;
@ -136,14 +134,14 @@ static void game_loop_check_problems_at_start() {
debug_script_warn("Wait() was used in Player Enters Screen - use Enters Screen After Fadein instead"); debug_script_warn("Wait() was used in Player Enters Screen - use Enters Screen After Fadein instead");
done_es_error = 1; done_es_error = 1;
} }
if (no_blocking_functions) if (_G(no_blocking_functions))
quit("!A blocking function was called from within a non-blocking event such as " REP_EXEC_ALWAYS_NAME); quit("!A blocking function was called from within a non-blocking event such as " REP_EXEC_ALWAYS_NAME);
} }
static void game_loop_check_new_room() { static void game_loop_check_new_room() {
if (in_new_room == 0) { if (in_new_room == 0) {
// Run the room and game script repeatedly_execute // Run the room and game script repeatedly_execute
run_function_on_non_blocking_thread(&repExecAlways); run_function_on_non_blocking_thread(&_GP(repExecAlways));
setevent(EV_TEXTSCRIPT, TS_REPEAT); setevent(EV_TEXTSCRIPT, TS_REPEAT);
setevent(EV_RUNEVBLOCK, EVB_ROOM, 0, 6); setevent(EV_RUNEVBLOCK, EVB_ROOM, 0, 6);
} }
@ -155,7 +153,7 @@ static void game_loop_check_new_room() {
static void game_loop_do_late_update() { static void game_loop_do_late_update() {
if (in_new_room == 0) { if (in_new_room == 0) {
// Run the room and game script late_repeatedly_execute // Run the room and game script late_repeatedly_execute
run_function_on_non_blocking_thread(&lateRepExecAlways); run_function_on_non_blocking_thread(&_GP(lateRepExecAlways));
} }
} }
@ -206,12 +204,12 @@ static int game_loop_check_ground_level_interactions() {
} }
static void lock_mouse_on_click() { static void lock_mouse_on_click() {
if (usetup.mouse_auto_lock && scsystem.windowed) if (usetup.mouse_auto_lock && _GP(scsystem).windowed)
Mouse::TryLockToWindow(); Mouse::TryLockToWindow();
} }
static void toggle_mouse_lock() { static void toggle_mouse_lock() {
if (scsystem.windowed) { if (_GP(scsystem).windowed) {
if (Mouse::IsLockedToWindow()) if (Mouse::IsLockedToWindow())
Mouse::UnlockFromWindow(); Mouse::UnlockFromWindow();
else else
@ -265,7 +263,7 @@ static void check_mouse_controls() {
wasongui = mongu; wasongui = mongu;
wasbutdown = mbut + 1; wasbutdown = mbut + 1;
} else setevent(EV_TEXTSCRIPT, TS_MCLICK, mbut + 1); } else setevent(EV_TEXTSCRIPT, TS_MCLICK, mbut + 1);
// else RunTextScriptIParam(gameinst,"on_mouse_click",aa+1); // else RunTextScriptIParam(_G(gameinst),"on_mouse_click",aa+1);
} }
if (mwheelz < 0) if (mwheelz < 0)
@ -483,7 +481,7 @@ static void check_keyboard_controls() {
return; return;
} }
if (inside_script) { if (_G(inside_script)) {
// Don't queue up another keypress if it can't be run instantly // Don't queue up another keypress if it can't be run instantly
debug_script_log("Keypress %d ignored (game blocked)", kgn); debug_script_log("Keypress %d ignored (game blocked)", kgn);
return; return;
@ -539,7 +537,7 @@ static void check_keyboard_controls() {
setevent(EV_TEXTSCRIPT, TS_KEYPRESS, kgn); setevent(EV_TEXTSCRIPT, TS_KEYPRESS, kgn);
} }
// RunTextScriptIParam(gameinst,"on_key_press",kgn); // RunTextScriptIParam(_G(gameinst),"on_key_press",kgn);
} }
// check_controls: checks mouse & keyboard interface // check_controls: checks mouse & keyboard interface

View file

@ -53,9 +53,6 @@ using namespace AGS::Shared;
using namespace AGS::Engine; using namespace AGS::Engine;
extern int our_eip, displayed_room; extern int our_eip, displayed_room;
extern std::vector<ccInstance *> moduleInst;
extern int numScriptModules;
extern CharacterInfo *playerchar; extern CharacterInfo *playerchar;
extern int convert_16bit_bgr; extern int convert_16bit_bgr;
@ -91,10 +88,10 @@ void start_game() {
// skip ticks to account for initialisation or a restored _GP(game). // skip ticks to account for initialisation or a restored _GP(game).
skipMissedTicks(); skipMissedTicks();
for (int kk = 0; kk < numScriptModules; kk++) for (int kk = 0; kk < _G(numScriptModules); kk++)
RunTextScript(moduleInst[kk], "game_start"); RunTextScript(_GP(moduleInst)[kk], "game_start");
RunTextScript(gameinst, "game_start"); RunTextScript(_G(gameinst), "game_start");
our_eip = -43; our_eip = -43;

View file

@ -52,7 +52,7 @@ using namespace AGS::Shared::Memory;
extern ccInstance *loadedInstances[MAX_LOADED_INSTANCES]; // in script/script_runtime extern ccInstance *loadedInstances[MAX_LOADED_INSTANCES]; // in script/script_runtime
extern int gameHasBeenRestored; // in ac/game extern int gameHasBeenRestored; // in ac/game
extern ExecutingScript *curscript; // in script/script // in script/script
extern int maxWhileLoops; extern int maxWhileLoops;
extern new_line_hook_type new_line_hook; extern new_line_hook_type new_line_hook;

View file

@ -60,46 +60,9 @@ extern RoomObject *objs;
extern int our_eip; extern int our_eip;
extern CharacterInfo *playerchar; extern CharacterInfo *playerchar;
ExecutingScript scripts[MAX_SCRIPT_AT_ONCE];
ExecutingScript *curscript = nullptr;
PScript gamescript;
PScript dialogScriptsScript;
ccInstance *gameinst = nullptr, *roominst = nullptr;
ccInstance *dialogScriptsInst = nullptr;
ccInstance *gameinstFork = nullptr, *roominstFork = nullptr;
int num_scripts = 0;
int post_script_cleanup_stack = 0;
int inside_script = 0, in_graph_script = 0;
int no_blocking_functions = 0; // set to 1 while in rep_Exec_always
NonBlockingScriptFunction repExecAlways(REP_EXEC_ALWAYS_NAME, 0);
NonBlockingScriptFunction lateRepExecAlways(LATE_REP_EXEC_ALWAYS_NAME, 0);
NonBlockingScriptFunction getDialogOptionsDimensionsFunc("dialog_options_get_dimensions", 1);
NonBlockingScriptFunction renderDialogOptionsFunc("dialog_options_render", 1);
NonBlockingScriptFunction getDialogOptionUnderCursorFunc("dialog_options_get_active", 1);
NonBlockingScriptFunction runDialogOptionMouseClickHandlerFunc("dialog_options_mouse_click", 2);
NonBlockingScriptFunction runDialogOptionKeyPressHandlerFunc("dialog_options_key_press", 2);
NonBlockingScriptFunction runDialogOptionRepExecFunc("dialog_options_repexec", 1);
ScriptSystem scsystem;
std::vector<PScript> scriptModules;
std::vector<ccInstance *> moduleInst;
std::vector<ccInstance *> moduleInstFork;
std::vector<RuntimeScriptValue> moduleRepExecAddr;
int numScriptModules = 0;
std::vector<String> characterScriptObjNames;
String objectScriptObjNames[MAX_ROOM_OBJECTS];
std::vector<String> guiScriptObjNames;
int run_dialog_request(int parmtr) { int run_dialog_request(int parmtr) {
_GP(play).stop_dialog_at_end = DIALOG_RUNNING; _GP(play).stop_dialog_at_end = DIALOG_RUNNING;
RunTextScriptIParam(gameinst, "dialog_request", RuntimeScriptValue().SetInt32(parmtr)); RunTextScriptIParam(_G(gameinst), "dialog_request", RuntimeScriptValue().SetInt32(parmtr));
if (_GP(play).stop_dialog_at_end == DIALOG_STOP) { if (_GP(play).stop_dialog_at_end == DIALOG_STOP) {
_GP(play).stop_dialog_at_end = DIALOG_NONE; _GP(play).stop_dialog_at_end = DIALOG_NONE;
@ -129,19 +92,19 @@ void run_function_on_non_blocking_thread(NonBlockingScriptFunction *funcToRun) {
// run modules // run modules
// modules need a forkedinst for this to work // modules need a forkedinst for this to work
for (int kk = 0; kk < numScriptModules; kk++) { for (int kk = 0; kk < _G(numScriptModules); kk++) {
funcToRun->moduleHasFunction[kk] = DoRunScriptFuncCantBlock(moduleInstFork[kk], funcToRun, funcToRun->moduleHasFunction[kk]); funcToRun->moduleHasFunction[kk] = DoRunScriptFuncCantBlock(_GP(moduleInstFork)[kk], funcToRun, funcToRun->moduleHasFunction[kk]);
if (room_changes_was != _GP(play).room_changes) if (room_changes_was != _GP(play).room_changes)
return; return;
} }
funcToRun->globalScriptHasFunction = DoRunScriptFuncCantBlock(gameinstFork, funcToRun, funcToRun->globalScriptHasFunction); funcToRun->globalScriptHasFunction = DoRunScriptFuncCantBlock(_G(gameinstFork), funcToRun, funcToRun->globalScriptHasFunction);
if (room_changes_was != _GP(play).room_changes) if (room_changes_was != _GP(play).room_changes)
return; return;
funcToRun->roomHasFunction = DoRunScriptFuncCantBlock(roominstFork, funcToRun, funcToRun->roomHasFunction); funcToRun->roomHasFunction = DoRunScriptFuncCantBlock(_G(roominstFork), funcToRun, funcToRun->roomHasFunction);
} }
//----------------------------------------------------------- //-----------------------------------------------------------
@ -237,28 +200,28 @@ int run_interaction_script(InteractionScripts *nint, int evnt, int chkAny, int i
int create_global_script() { int create_global_script() {
ccSetOption(SCOPT_AUTOIMPORT, 1); ccSetOption(SCOPT_AUTOIMPORT, 1);
for (int kk = 0; kk < numScriptModules; kk++) { for (int kk = 0; kk < _G(numScriptModules); kk++) {
moduleInst[kk] = ccInstance::CreateFromScript(scriptModules[kk]); _GP(moduleInst)[kk] = ccInstance::CreateFromScript(_GP(scriptModules)[kk]);
if (moduleInst[kk] == nullptr) if (_GP(moduleInst)[kk] == nullptr)
return -3; return -3;
// create a forked instance for rep_exec_always // create a forked instance for rep_exec_always
moduleInstFork[kk] = moduleInst[kk]->Fork(); _GP(moduleInstFork)[kk] = _GP(moduleInst)[kk]->Fork();
if (moduleInstFork[kk] == nullptr) if (_GP(moduleInstFork)[kk] == nullptr)
return -3; return -3;
moduleRepExecAddr[kk] = moduleInst[kk]->GetSymbolAddress(REP_EXEC_NAME); _GP(moduleRepExecAddr)[kk] = _GP(moduleInst)[kk]->GetSymbolAddress(REP_EXEC_NAME);
} }
gameinst = ccInstance::CreateFromScript(gamescript); _G(gameinst) = ccInstance::CreateFromScript(_GP(gamescript));
if (gameinst == nullptr) if (_G(gameinst) == nullptr)
return -3; return -3;
// create a forked instance for rep_exec_always // create a forked instance for rep_exec_always
gameinstFork = gameinst->Fork(); _G(gameinstFork) = _G(gameinst)->Fork();
if (gameinstFork == nullptr) if (_G(gameinstFork) == nullptr)
return -3; return -3;
if (dialogScriptsScript != nullptr) { if (_GP(dialogScriptsScript) != nullptr) {
dialogScriptsInst = ccInstance::CreateFromScript(dialogScriptsScript); _G(dialogScriptsInst) = ccInstance::CreateFromScript(_GP(dialogScriptsScript));
if (dialogScriptsInst == nullptr) if (_G(dialogScriptsInst) == nullptr)
return -3; return -3;
} }
@ -269,30 +232,30 @@ int create_global_script() {
void cancel_all_scripts() { void cancel_all_scripts() {
int aa; int aa;
for (aa = 0; aa < num_scripts; aa++) { for (aa = 0; aa < _G(num_scripts); aa++) {
if (scripts[aa].forked) if (_G(scripts)[aa].forked)
scripts[aa].inst->AbortAndDestroy(); _G(scripts)[aa].inst->AbortAndDestroy();
else else
scripts[aa].inst->Abort(); _G(scripts)[aa].inst->Abort();
scripts[aa].numanother = 0; _G(scripts)[aa].numanother = 0;
} }
num_scripts = 0; _G(num_scripts) = 0;
/* if (gameinst!=NULL) ->Abort(gameinst); /* if (_G(gameinst)!=NULL) ->Abort(_G(gameinst));
if (roominst!=NULL) ->Abort(roominst);*/ if (_G(roominst)!=NULL) ->Abort(_G(roominst));*/
} }
ccInstance *GetScriptInstanceByType(ScriptInstType sc_inst) { ccInstance *GetScriptInstanceByType(ScriptInstType sc_inst) {
if (sc_inst == kScInstGame) if (sc_inst == kScInstGame)
return gameinst; return _G(gameinst);
else if (sc_inst == kScInstRoom) else if (sc_inst == kScInstRoom)
return roominst; return _G(roominst);
return nullptr; return nullptr;
} }
void QueueScriptFunction(ScriptInstType sc_inst, const char *fn_name, size_t param_count, const RuntimeScriptValue &p1, const RuntimeScriptValue &p2) { void QueueScriptFunction(ScriptInstType sc_inst, const char *fn_name, size_t param_count, const RuntimeScriptValue &p1, const RuntimeScriptValue &p2) {
if (inside_script) if (_G(inside_script))
// queue the script for the run after current script is finished // queue the script for the run after current script is finished
curscript->run_another(fn_name, sc_inst, param_count, p1, p2); _G(curscript)->run_another(fn_name, sc_inst, param_count, p1, p2);
else else
// if no script is currently running, run the requested script right away // if no script is currently running, run the requested script right away
RunScriptFunction(sc_inst, fn_name, param_count, p1, p2); RunScriptFunction(sc_inst, fn_name, param_count, p1, p2);
@ -314,7 +277,7 @@ bool DoRunScriptFuncCantBlock(ccInstance *sci, NonBlockingScriptFunction *funcTo
if (!hasTheFunc) if (!hasTheFunc)
return (false); return (false);
no_blocking_functions++; _G(no_blocking_functions)++;
int result = 0; int result = 0;
if (funcToRun->numParameters < 3) { if (funcToRun->numParameters < 3) {
@ -333,7 +296,7 @@ bool DoRunScriptFuncCantBlock(ccInstance *sci, NonBlockingScriptFunction *funcTo
// this might be nested, so don't disrupt blocked scripts // this might be nested, so don't disrupt blocked scripts
ccErrorString = ""; ccErrorString = "";
ccError = 0; ccError = 0;
no_blocking_functions--; _G(no_blocking_functions)--;
return (hasTheFunc); return (hasTheFunc);
} }
@ -350,25 +313,25 @@ int PrepareTextScript(ccInstance *sci, const char **tsname) {
ccErrorString = "script is already in execution"; ccErrorString = "script is already in execution";
return -3; return -3;
} }
scripts[num_scripts].init(); _G(scripts)[_G(num_scripts)].init();
scripts[num_scripts].inst = sci; _G(scripts)[_G(num_scripts)].inst = sci;
// CHECKME: this conditional block will never run, because // CHECKME: this conditional block will never run, because
// function would have quit earlier (deprecated functionality?) // function would have quit earlier (deprecated functionality?)
if (sci->IsBeingRun()) { if (sci->IsBeingRun()) {
scripts[num_scripts].inst = sci->Fork(); _G(scripts)[_G(num_scripts)].inst = sci->Fork();
if (scripts[num_scripts].inst == nullptr) if (_G(scripts)[_G(num_scripts)].inst == nullptr)
quit("unable to fork instance for secondary script"); quit("unable to fork instance for secondary script");
scripts[num_scripts].forked = 1; _G(scripts)[_G(num_scripts)].forked = 1;
} }
curscript = &scripts[num_scripts]; _G(curscript) = &_G(scripts)[_G(num_scripts)];
num_scripts++; _G(num_scripts)++;
if (num_scripts >= MAX_SCRIPT_AT_ONCE) if (_G(num_scripts) >= MAX_SCRIPT_AT_ONCE)
quit("too many nested text script instances created"); quit("too many nested text script instances created");
// in case script_run_another is the function name, take a backup // in case script_run_another is the function name, take a backup
strncpy(scfunctionname, tsname[0], MAX_FUNCTION_NAME_LEN); strncpy(scfunctionname, tsname[0], MAX_FUNCTION_NAME_LEN);
tsname[0] = &scfunctionname[0]; tsname[0] = &scfunctionname[0];
update_script_mouse_coords(); update_script_mouse_coords();
inside_script++; _G(inside_script)++;
// aborted_ip=0; // aborted_ip=0;
// abort_executor=0; // abort_executor=0;
return 0; return 0;
@ -395,7 +358,7 @@ int RunScriptFunctionIfExists(ccInstance *sci, const char *tsname, int numParam,
ccErrorString = ""; ccErrorString = "";
if (numParam < 3) { if (numParam < 3) {
toret = curscript->inst->CallScriptFunction(tsname, numParam, params); toret = _G(curscript)->inst->CallScriptFunction(tsname, numParam, params);
} else } else
quit("Too many parameters to RunScriptFunctionIfExists"); quit("Too many parameters to RunScriptFunctionIfExists");
@ -404,14 +367,14 @@ int RunScriptFunctionIfExists(ccInstance *sci, const char *tsname, int numParam,
quit_with_script_error(tsname); quit_with_script_error(tsname);
} }
post_script_cleanup_stack++; _G(post_script_cleanup_stack)++;
if (post_script_cleanup_stack > 50) if (_G(post_script_cleanup_stack) > 50)
quitprintf("!post_script_cleanup call stack exceeded: possible recursive function call? running %s", tsname); quitprintf("!post_script_cleanup call stack exceeded: possible recursive function call? running %s", tsname);
post_script_cleanup(); post_script_cleanup();
post_script_cleanup_stack--; _G(post_script_cleanup_stack)--;
// restore cached error state // restore cached error state
ccError = cachedCcError; ccError = cachedCcError;
@ -426,14 +389,14 @@ int RunScriptFunctionIfExists(ccInstance *sci, const char *tsname, int numParam,
int RunTextScript(ccInstance *sci, const char *tsname) { int RunTextScript(ccInstance *sci, const char *tsname) {
if (strcmp(tsname, REP_EXEC_NAME) == 0) { if (strcmp(tsname, REP_EXEC_NAME) == 0) {
// run module rep_execs // run module rep_execs
// FIXME: in theory the function may be already called for moduleInst[i], // FIXME: in theory the function may be already called for _GP(moduleInst)[i],
// in which case this should not be executed; need to rearrange the code somehow // in which case this should not be executed; need to rearrange the code somehow
int room_changes_was = _GP(play).room_changes; int room_changes_was = _GP(play).room_changes;
int restore_game_count_was = gameHasBeenRestored; int restore_game_count_was = gameHasBeenRestored;
for (int kk = 0; kk < numScriptModules; kk++) { for (int kk = 0; kk < _G(numScriptModules); kk++) {
if (!moduleRepExecAddr[kk].IsNull()) if (!_GP(moduleRepExecAddr)[kk].IsNull())
RunScriptFunctionIfExists(moduleInst[kk], tsname, 0, nullptr); RunScriptFunctionIfExists(_GP(moduleInst)[kk], tsname, 0, nullptr);
if ((room_changes_was != _GP(play).room_changes) || if ((room_changes_was != _GP(play).room_changes) ||
(restore_game_count_was != gameHasBeenRestored)) (restore_game_count_was != gameHasBeenRestored))
@ -442,7 +405,7 @@ int RunTextScript(ccInstance *sci, const char *tsname) {
} }
int toret = RunScriptFunctionIfExists(sci, tsname, 0, nullptr); int toret = RunScriptFunctionIfExists(sci, tsname, 0, nullptr);
if ((toret == -18) && (sci == roominst)) { if ((toret == -18) && (sci == _G(roominst))) {
// functions in room script must exist // functions in room script must exist
quitprintf("prepare_script: error %d (%s) trying to run '%s' (Room %d)", toret, ccErrorString.GetCStr(), tsname, displayed_room); quitprintf("prepare_script: error %d (%s) trying to run '%s' (Room %d)", toret, ccErrorString.GetCStr(), tsname, displayed_room);
} }
@ -486,7 +449,7 @@ String GetScriptName(ccInstance *sci) {
// TODO: check script modules too? // TODO: check script modules too?
if (!sci) if (!sci)
return "Not in a script"; return "Not in a script";
else if (sci->instanceof == gamescript) else if (sci->instanceof == _GP(gamescript))
return "Global script"; return "Global script";
else if (sci->instanceof == _GP(thisroom).CompiledScript) else if (sci->instanceof == _GP(thisroom).CompiledScript)
return String::FromFormat("Room %d script", displayed_room); return String::FromFormat("Room %d script", displayed_room);
@ -510,16 +473,16 @@ char *make_ts_func_name(const char *base, int iii, int subd) {
void post_script_cleanup() { void post_script_cleanup() {
// should do any post-script stuff here, like go to new room // should do any post-script stuff here, like go to new room
if (ccError) quit(ccErrorString); if (ccError) quit(ccErrorString);
ExecutingScript copyof = scripts[num_scripts - 1]; ExecutingScript copyof = _G(scripts)[_G(num_scripts) - 1];
if (scripts[num_scripts - 1].forked) if (_G(scripts)[_G(num_scripts) - 1].forked)
delete scripts[num_scripts - 1].inst; delete _G(scripts)[_G(num_scripts) - 1].inst;
num_scripts--; _G(num_scripts)--;
inside_script--; _G(inside_script)--;
if (num_scripts > 0) if (_G(num_scripts) > 0)
curscript = &scripts[num_scripts - 1]; _G(curscript) = &_G(scripts)[_G(num_scripts) - 1];
else { else {
curscript = nullptr; _G(curscript) = nullptr;
} }
// if (abort_executor) user_disabled_data2=aborted_ip; // if (abort_executor) user_disabled_data2=aborted_ip;
@ -532,13 +495,13 @@ void post_script_cleanup() {
switch (copyof.postScriptActions[ii]) { switch (copyof.postScriptActions[ii]) {
case ePSANewRoom: case ePSANewRoom:
// only change rooms when all scripts are done // only change rooms when all scripts are done
if (num_scripts == 0) { if (_G(num_scripts) == 0) {
new_room(thisData, playerchar); new_room(thisData, playerchar);
// don't allow any pending room scripts from the old room // don't allow any pending room scripts from the old room
// in run_another to be executed // in run_another to be executed
return; return;
} else } else
curscript->queue_action(ePSANewRoom, thisData, "NewRoom"); _G(curscript)->queue_action(ePSANewRoom, thisData, "NewRoom");
break; break;
case ePSAInvScreen: case ePSAInvScreen:
invscreen(); invscreen();
@ -881,7 +844,7 @@ int run_interaction_commandlist(InteractionCommandList *nicl, int *timesrun, int
// check and abort game if the script is currently // check and abort game if the script is currently
// inside the rep_exec_always function // inside the rep_exec_always function
void can_run_delayed_command() { void can_run_delayed_command() {
if (no_blocking_functions) if (_G(no_blocking_functions))
quit("!This command cannot be used within non-blocking events such as " REP_EXEC_ALWAYS_NAME); quit("!This command cannot be used within non-blocking events such as " REP_EXEC_ALWAYS_NAME);
} }

View file

@ -84,45 +84,6 @@ InteractionVariable *FindGraphicalVariable(const char *varName);
void run_unhandled_event(int evnt); void run_unhandled_event(int evnt);
void can_run_delayed_command(); void can_run_delayed_command();
extern ExecutingScript scripts[MAX_SCRIPT_AT_ONCE];
extern ExecutingScript *curscript;
extern PScript gamescript;
extern PScript dialogScriptsScript;
extern ccInstance *gameinst, *roominst;
extern ccInstance *dialogScriptsInst;
extern ccInstance *gameinstFork, *roominstFork;
extern int num_scripts;
extern int post_script_cleanup_stack;
extern int inside_script, in_graph_script;
extern int no_blocking_functions; // set to 1 while in rep_Exec_always
extern NonBlockingScriptFunction repExecAlways;
extern NonBlockingScriptFunction lateRepExecAlways;
extern NonBlockingScriptFunction getDialogOptionsDimensionsFunc;
extern NonBlockingScriptFunction renderDialogOptionsFunc;
extern NonBlockingScriptFunction getDialogOptionUnderCursorFunc;
extern NonBlockingScriptFunction runDialogOptionMouseClickHandlerFunc;
extern NonBlockingScriptFunction runDialogOptionKeyPressHandlerFunc;
extern NonBlockingScriptFunction runDialogOptionRepExecFunc;
extern ScriptSystem scsystem;
extern std::vector<PScript> scriptModules;
extern std::vector<ccInstance *> moduleInst;
extern std::vector<ccInstance *> moduleInstFork;
extern std::vector<RuntimeScriptValue> moduleRepExecAddr;
extern int numScriptModules;
// TODO: find out if these extra arrays are really necessary. This may be remains from the
// time when the symbol import table was holding raw pointers to char array.
extern std::vector<AGS::Shared::String> characterScriptObjNames;
extern AGS::Shared::String objectScriptObjNames[MAX_ROOM_OBJECTS];
extern std::vector<AGS::Shared::String> guiScriptObjNames;
} // namespace AGS3 } // namespace AGS3
#endif #endif

View file

@ -37,12 +37,16 @@
#include "ags/engine/ac/dynobj/cc_object.h" #include "ags/engine/ac/dynobj/cc_object.h"
#include "ags/engine/ac/dynobj/cc_audiochannel.h" #include "ags/engine/ac/dynobj/cc_audiochannel.h"
#include "ags/engine/ac/dynobj/cc_audioclip.h" #include "ags/engine/ac/dynobj/cc_audioclip.h"
#include "ags/engine/ac/dynobj/scriptsystem.h"
#include "ags/engine/ac/objectcache.h" #include "ags/engine/ac/objectcache.h"
#include "ags/engine/ac/dynobj/scripthotspot.h" #include "ags/engine/ac/dynobj/scripthotspot.h"
#include "ags/engine/ac/dynobj/scriptinvitem.h" #include "ags/engine/ac/dynobj/scriptinvitem.h"
#include "ags/engine/ac/dynobj/scriptobject.h" #include "ags/engine/ac/dynobj/scriptobject.h"
#include "ags/engine/ac/dynobj/scriptregion.h" #include "ags/engine/ac/dynobj/scriptregion.h"
#include "ags/engine/ac/dynobj/scriptstring.h" #include "ags/engine/ac/dynobj/scriptstring.h"
#include "ags/engine/script/executingscript.h"
#include "ags/engine/script/nonblockingscriptfunction.h"
#include "ags/engine/script/script.h"
namespace AGS3 { namespace AGS3 {
@ -79,13 +83,36 @@ Globals::Globals() {
_scrRegion = new ScriptRegion[MAX_ROOM_REGIONS]; _scrRegion = new ScriptRegion[MAX_ROOM_REGIONS];
_scrInv = new ScriptInvItem[MAX_INV]; _scrInv = new ScriptInvItem[MAX_INV];
_objcache = new ObjectCache[MAX_ROOM_OBJECTS]; _objcache = new ObjectCache[MAX_ROOM_OBJECTS];
// script.cpp
_scripts = new ExecutingScript[MAX_SCRIPT_AT_ONCE];
_gamescript = new PScript();
_dialogScriptsScript = new PScript();
_repExecAlways = new NonBlockingScriptFunction(REP_EXEC_ALWAYS_NAME, 0);
_lateRepExecAlways = new NonBlockingScriptFunction(LATE_REP_EXEC_ALWAYS_NAME, 0);
_getDialogOptionsDimensionsFunc = new NonBlockingScriptFunction("dialog_options_get_dimensions", 1);
_renderDialogOptionsFunc = new NonBlockingScriptFunction("dialog_options_render", 1);
_getDialogOptionUnderCursorFunc = new NonBlockingScriptFunction("dialog_options_get_active", 1);
_runDialogOptionMouseClickHandlerFunc = new NonBlockingScriptFunction("dialog_options_mouse_click", 2);
_runDialogOptionKeyPressHandlerFunc = new NonBlockingScriptFunction("dialog_options_key_press", 2);
_runDialogOptionRepExecFunc = new NonBlockingScriptFunction("dialog_options_repexec", 1);
_scsystem = new ScriptSystem();
_scriptModules = new std::vector<PScript>();
_moduleInst = new std::vector<ccInstance *>();
_moduleInstFork = new std::vector<ccInstance *>();
_moduleRepExecAddr = new std::vector<RuntimeScriptValue>();
_characterScriptObjNames = new std::vector<String>();
_objectScriptObjNames = new String[MAX_ROOM_OBJECTS];
_guiScriptObjNames = new std::vector<String>();
} }
Globals::~Globals() { Globals::~Globals() {
g_globals = nullptr; g_globals = nullptr;
// debug.cpp
delete _DbgMgr; delete _DbgMgr;
// game.cpp
delete _ccDynamicGUIObject; delete _ccDynamicGUIObject;
delete _ccDynamicCharacter; delete _ccDynamicCharacter;
delete _ccDynamicHotspot; delete _ccDynamicHotspot;
@ -108,6 +135,27 @@ Globals::~Globals() {
delete[] _scrRegion; delete[] _scrRegion;
delete[] _scrInv; delete[] _scrInv;
delete[] _objcache; delete[] _objcache;
// script.cpp
delete[] _scripts;
delete _gamescript;
delete _dialogScriptsScript;
delete _repExecAlways;
delete _lateRepExecAlways;
delete _getDialogOptionsDimensionsFunc;
delete _renderDialogOptionsFunc;
delete _getDialogOptionUnderCursorFunc;
delete _runDialogOptionMouseClickHandlerFunc;
delete _runDialogOptionKeyPressHandlerFunc;
delete _runDialogOptionRepExecFunc;
delete _scsystem;
delete _scriptModules;
delete _moduleInst;
delete _moduleInstFork;
delete _moduleRepExecAddr;
delete _characterScriptObjNames;
delete[] _objectScriptObjNames;
delete _guiScriptObjNames;
} }
} // namespace AGS3 } // namespace AGS3

View file

@ -26,6 +26,7 @@
#include "ags/shared/util/string.h" #include "ags/shared/util/string.h"
#include "ags/shared/util/version.h" #include "ags/shared/util/version.h"
#include "ags/shared/gui/guimain.h" #include "ags/shared/gui/guimain.h"
#include "ags/shared/script/cc_script.h"
#include "ags/lib/std/set.h" #include "ags/lib/std/set.h"
namespace AGS3 { namespace AGS3 {
@ -50,20 +51,25 @@ struct CCDialog;
struct CCGUI; struct CCGUI;
struct CCGUIObject; struct CCGUIObject;
struct CCHotspot; struct CCHotspot;
struct ccInstance;
struct CCInventory; struct CCInventory;
struct CCObject; struct CCObject;
struct CCRegion; struct CCRegion;
struct IAGSEditorDebugger; struct ExecutingScript;
struct GameSetupStruct; struct GameSetupStruct;
struct GameState; struct GameState;
struct IAGSEditorDebugger;
struct NonBlockingScriptFunction;
struct RoomStatus; struct RoomStatus;
struct ScriptString; struct RuntimeScriptValue;
struct ScriptObject; struct ScriptDialog;
struct ScriptGUI; struct ScriptGUI;
struct ScriptHotspot; struct ScriptHotspot;
struct ScriptRegion;
struct ScriptInvItem; struct ScriptInvItem;
struct ScriptDialog; struct ScriptObject;
struct ScriptRegion;
struct ScriptString;
struct ScriptSystem;
struct ViewStruct; struct ViewStruct;
struct CharacterCache; struct CharacterCache;
struct ObjectCache; struct ObjectCache;
@ -106,7 +112,6 @@ public:
/**@}*/ /**@}*/
/** /**
* \defgroup debug globals * \defgroup debug globals
* @{ * @{
@ -236,6 +241,51 @@ public:
/**@}*/ /**@}*/
/**
* \defgroup script globals
* @{
*/
ExecutingScript *_scripts;
ExecutingScript *_curscript = nullptr;
PScript *_gamescript;
PScript *_dialogScriptsScript;
ccInstance *_gameinst = nullptr, *_roominst = nullptr;
ccInstance *_dialogScriptsInst = nullptr;
ccInstance *_gameinstFork = nullptr, *_roominstFork = nullptr;
int _num_scripts = 0;
int _post_script_cleanup_stack = 0;
int _inside_script = 0, _in_graph_script = 0;
int _no_blocking_functions = 0; // set to 1 while in rep_Exec_always
NonBlockingScriptFunction *_repExecAlways;
NonBlockingScriptFunction *_lateRepExecAlways;
NonBlockingScriptFunction *_getDialogOptionsDimensionsFunc;
NonBlockingScriptFunction *_renderDialogOptionsFunc;
NonBlockingScriptFunction *_getDialogOptionUnderCursorFunc;
NonBlockingScriptFunction *_runDialogOptionMouseClickHandlerFunc;
NonBlockingScriptFunction *_runDialogOptionKeyPressHandlerFunc;
NonBlockingScriptFunction *_runDialogOptionRepExecFunc;
ScriptSystem *_scsystem;
std::vector<PScript> *_scriptModules;
std::vector<ccInstance *> *_moduleInst;
std::vector<ccInstance *> *_moduleInstFork;
std::vector<RuntimeScriptValue> *_moduleRepExecAddr;
int _numScriptModules = 0;
// TODO: find out if these extra arrays are really necessary. This may be remains from the
// time when the symbol import table was holding raw pointers to char array.
std::vector<String> *_characterScriptObjNames;
String *_objectScriptObjNames;
std::vector<String> *_guiScriptObjNames;
/**@}*/
public: public:
Globals(); Globals();
~Globals(); ~Globals();

View file

@ -88,18 +88,10 @@ using namespace AGS::Engine;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
extern int displayed_room; extern int displayed_room;
extern RoomStatus *croom; extern RoomStatus *croom;
extern int game_paused; extern int game_paused;
extern GameSetup usetup; extern GameSetup usetup;
extern int inside_script;
extern ccInstance *gameinst, *roominst;
extern color palette[256]; extern color palette[256];
extern PluginObjectReader pluginReaders[MAX_PLUGIN_OBJECT_READERS]; extern PluginObjectReader pluginReaders[MAX_PLUGIN_OBJECT_READERS];
extern int numPluginReaders; extern int numPluginReaders;
@ -255,7 +247,7 @@ void IAGSEngine::GetScreenDimensions(int32 *width, int32 *height, int32 *coldept
if (height != nullptr) if (height != nullptr)
height[0] = _GP(play).GetMainViewport().GetHeight(); height[0] = _GP(play).GetMainViewport().GetHeight();
if (coldepth != nullptr) if (coldepth != nullptr)
coldepth[0] = scsystem.coldepth; coldepth[0] = _GP(scsystem).coldepth;
} }
unsigned char **IAGSEngine::GetRawBitmapSurface(BITMAP *bmp) { unsigned char **IAGSEngine::GetRawBitmapSurface(BITMAP *bmp) {
@ -671,12 +663,12 @@ void IAGSEngine::DisableSound() {
usetup.audio_backend = 0; usetup.audio_backend = 0;
} }
int IAGSEngine::CanRunScriptFunctionNow() { int IAGSEngine::CanRunScriptFunctionNow() {
if (inside_script) if (_G(inside_script))
return 0; return 0;
return 1; return 1;
} }
int IAGSEngine::CallGameScriptFunction(const char *name, int32 globalScript, int32 numArgs, long arg1, long arg2, long arg3) { int IAGSEngine::CallGameScriptFunction(const char *name, int32 globalScript, int32 numArgs, long arg1, long arg2, long arg3) {
if (inside_script) if (_G(inside_script))
return -300; return -300;
ccInstance *toRun = GetScriptInstanceByType(globalScript ? kScInstGame : kScInstRoom); ccInstance *toRun = GetScriptInstanceByType(globalScript ? kScInstGame : kScInstRoom);
@ -718,7 +710,7 @@ void IAGSEngine::SetSpriteAlphaBlended(int32 slot, int32 isAlphaBlended) {
} }
void IAGSEngine::QueueGameScriptFunction(const char *name, int32 globalScript, int32 numArgs, long arg1, long arg2) { void IAGSEngine::QueueGameScriptFunction(const char *name, int32 globalScript, int32 numArgs, long arg1, long arg2) {
if (!inside_script) { if (!_G(inside_script)) {
this->CallGameScriptFunction(name, globalScript, numArgs, arg1, arg2, 0); this->CallGameScriptFunction(name, globalScript, numArgs, arg1, arg2, 0);
return; return;
} }
@ -726,7 +718,7 @@ void IAGSEngine::QueueGameScriptFunction(const char *name, int32 globalScript, i
if (numArgs < 0 || numArgs > 2) if (numArgs < 0 || numArgs > 2)
quit("IAGSEngine::QueueGameScriptFunction: invalid number of arguments"); quit("IAGSEngine::QueueGameScriptFunction: invalid number of arguments");
curscript->run_another(name, globalScript ? kScInstGame : kScInstRoom, numArgs, _G(curscript)->run_another(name, globalScript ? kScInstGame : kScInstRoom, numArgs,
RuntimeScriptValue().SetPluginArgument(arg1), RuntimeScriptValue().SetPluginArgument(arg2)); RuntimeScriptValue().SetPluginArgument(arg1), RuntimeScriptValue().SetPluginArgument(arg2));
} }