AGS: Beginnings of new Globals class

This commit is contained in:
Paul Gilbert 2021-01-18 11:14:56 -08:00
parent 3d84af6aeb
commit cf9bbb2bb2
15 changed files with 113 additions and 29 deletions

View file

@ -37,6 +37,7 @@
#include "ags/lib/std/set.h" #include "ags/lib/std/set.h"
#include "ags/shared/ac/common.h" #include "ags/shared/ac/common.h"
#include "ags/engine/ac/game.h" #include "ags/engine/ac/game.h"
#include "ags/engine/globals.h"
#include "ags/engine/ac/gamesetup.h" #include "ags/engine/ac/gamesetup.h"
#include "ags/engine/ac/gamestate.h" #include "ags/engine/ac/gamestate.h"
#include "ags/shared/core/def_version.h" #include "ags/shared/core/def_version.h"
@ -328,13 +329,15 @@ AGSEngine *g_vm;
AGSEngine::AGSEngine(OSystem *syst, const AGSGameDescription *gameDesc) : Engine(syst), AGSEngine::AGSEngine(OSystem *syst, const AGSGameDescription *gameDesc) : Engine(syst),
_gameDescription(gameDesc), _randomSource("AGS"), _events(nullptr), _music(nullptr), _gameDescription(gameDesc), _randomSource("AGS"), _events(nullptr), _music(nullptr),
_rawScreen(nullptr), _screen(nullptr), _gfxDriver(nullptr) { _rawScreen(nullptr), _screen(nullptr), _gfxDriver(nullptr),
_globals(nullptr) {
g_vm = this; g_vm = this;
DebugMan.addDebugChannel(kDebugPath, "Path", "Pathfinding debug level"); DebugMan.addDebugChannel(kDebugPath, "Path", "Pathfinding debug level");
DebugMan.addDebugChannel(kDebugGraphics, "Graphics", "Graphics debug level"); DebugMan.addDebugChannel(kDebugGraphics, "Graphics", "Graphics debug level");
_events = new EventsManager(); _events = new EventsManager();
_music = new Music(_mixer); _music = new Music(_mixer);
_globals = new ::AGS3::Globals();
} }
AGSEngine::~AGSEngine() { AGSEngine::~AGSEngine() {
@ -342,6 +345,7 @@ AGSEngine::~AGSEngine() {
delete _rawScreen; delete _rawScreen;
delete _events; delete _events;
delete _music; delete _music;
delete _globals;
} }
uint32 AGSEngine::getFeatures() const { uint32 AGSEngine::getFeatures() const {

View file

@ -37,6 +37,10 @@
#include "ags/lib/allegro/system.h" #include "ags/lib/allegro/system.h"
#include "ags/engine/util/mutex_std.h" #include "ags/engine/util/mutex_std.h"
namespace AGS3 {
class Globals;
}
namespace AGS { namespace AGS {
#define SCREEN_WIDTH 320 #define SCREEN_WIDTH 320
@ -64,6 +68,7 @@ public:
::AGS3::AGS::Engine::Mutex _sMutex; ::AGS3::AGS::Engine::Mutex _sMutex;
::AGS3::AGS::Engine::Mutex _soundCacheMutex; ::AGS3::AGS::Engine::Mutex _soundCacheMutex;
::AGS3::AGS::Engine::Mutex _mp3Mutex; ::AGS3::AGS::Engine::Mutex _mp3Mutex;
::AGS3::Globals *_globals;
protected: protected:
// Engine APIs // Engine APIs
virtual Common::Error run(); virtual Common::Error run();

View file

@ -158,7 +158,6 @@ RoomStruct thisroom;
volatile int switching_away_from_game = 0; volatile int switching_away_from_game = 0;
volatile bool switched_away = false; volatile bool switched_away = false;
volatile char want_exit = 0, abort_engine = 0;
GameDataVersion loaded_game_file_version = kGameVersion_Undefined; GameDataVersion loaded_game_file_version = kGameVersion_Undefined;
int frames_per_second = 40; int frames_per_second = 40;
int displayed_room = -10, starting_room = -1; int displayed_room = -10, starting_room = -1;

View file

@ -44,6 +44,7 @@
#include "ags/shared/script/cc_error.h" #include "ags/shared/script/cc_error.h"
#include "ags/shared/util/string_utils.h" #include "ags/shared/util/string_utils.h"
#include "ags/shared/util/textstreamwriter.h" #include "ags/shared/util/textstreamwriter.h"
#include "ags/engine/globals.h"
#include "ags/events.h" #include "ags/events.h"
#if AGS_PLATFORM_OS_WINDOWS #if AGS_PLATFORM_OS_WINDOWS
@ -59,7 +60,6 @@ extern char check_dynamic_sprites_at_exit;
extern int displayed_room; extern int displayed_room;
extern RoomStruct thisroom; extern RoomStruct thisroom;
extern char pexbuf[STD_BUFFER_SIZE]; extern char pexbuf[STD_BUFFER_SIZE];
extern volatile char want_exit, abort_engine;
extern GameSetupStruct game; extern GameSetupStruct game;
@ -471,8 +471,8 @@ int check_for_messages_from_editor() {
game_paused_in_debugger = 0; game_paused_in_debugger = 0;
break_on_next_script_step = 1; break_on_next_script_step = 1;
} else if (strncmp(msgPtr, "EXIT", 4) == 0) { } else if (strncmp(msgPtr, "EXIT", 4) == 0) {
want_exit = 1; _G(want_exit) = 1;
abort_engine = 1; _G(abort_engine) = 1;
check_dynamic_sprites_at_exit = 0; check_dynamic_sprites_at_exit = 0;
} }
@ -488,7 +488,7 @@ int check_for_messages_from_editor() {
bool send_exception_to_editor(const char *qmsg) { bool send_exception_to_editor(const char *qmsg) {
#if AGS_PLATFORM_OS_WINDOWS #if AGS_PLATFORM_OS_WINDOWS
want_exit = 0; _G(want_exit) = 0;
// allow the editor to break with the error message // allow the editor to break with the error message
if (editor_window_handle != NULL) if (editor_window_handle != NULL)
SetForegroundWindow(editor_window_handle); SetForegroundWindow(editor_window_handle);
@ -496,7 +496,7 @@ bool send_exception_to_editor(const char *qmsg) {
if (!send_message_to_editor("ERROR", qmsg)) if (!send_message_to_editor("ERROR", qmsg))
return false; return false;
while ((check_for_messages_from_editor() == 0) && (want_exit == 0)) { while ((check_for_messages_from_editor() == 0) && (_G(want_exit) == 0)) {
update_polled_mp3(); update_polled_mp3();
platform->Delay(10); platform->Delay(10);
} }

View file

@ -0,0 +1,37 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ags/engine/globals.h"
namespace AGS3 {
Globals *g_globals;
Globals::Globals() : _want_exit(false), _abort_engine(false) {
g_globals = this;
}
Globals::~Globals() {
g_globals = nullptr;
}
} // namespace AGS3

View file

@ -0,0 +1,44 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef AGS_ENGINE_GLOBALS_H
#define AGS_ENGINE_GLOBALS_H
namespace AGS3 {
class Globals {
public:
bool _want_exit;
bool _abort_engine;
public:
Globals();
~Globals();
};
extern Globals *g_globals;
#define _G(FIELD) (::AGS3::g_globals->_##FIELD)
} // namespace AGS3
#endif

View file

@ -89,7 +89,6 @@ using namespace AGS::Engine;
extern char check_dynamic_sprites_at_exit; extern char check_dynamic_sprites_at_exit;
extern int our_eip; extern int our_eip;
extern volatile char want_exit, abort_engine;
extern bool justRunSetup; extern bool justRunSetup;
extern GameSetup usetup; extern GameSetup usetup;
extern GameSetupStruct game; extern GameSetupStruct game;

View file

@ -66,6 +66,7 @@
#include "ags/engine/ac/timer.h" #include "ags/engine/ac/timer.h"
#include "ags/engine/ac/keycode.h" #include "ags/engine/ac/keycode.h"
#include "ags/lib/allegro/keyboard.h" #include "ags/lib/allegro/keyboard.h"
#include "ags/engine/globals.h"
#include "ags/events.h" #include "ags/events.h"
namespace AGS3 { namespace AGS3 {
@ -77,7 +78,6 @@ extern int numAnimButs;
extern int mouse_on_iface; // mouse cursor is over this interface extern int mouse_on_iface; // mouse cursor is over this interface
extern int ifacepopped; extern int ifacepopped;
extern int is_text_overlay; extern int is_text_overlay;
extern volatile char want_exit, abort_engine;
extern int proper_exit, our_eip; extern int proper_exit, our_eip;
extern int displayed_room, starting_room, in_new_room, new_room_was; extern int displayed_room, starting_room, in_new_room, new_room_was;
extern GameSetupStruct game; extern GameSetupStruct game;
@ -124,7 +124,7 @@ unsigned int loopcounter = 0;
static unsigned int lastcounter = 0; static unsigned int lastcounter = 0;
static void ProperExit() { static void ProperExit() {
want_exit = 0; _G(want_exit) = 0;
proper_exit = 1; proper_exit = 1;
quit("||exit!"); quit("||exit!");
} }
@ -737,7 +737,7 @@ void UpdateGameOnce(bool checkControls, IDriverDependantBitmap *extraBitmap, int
numEventsAtStartOfFunction = numevents; numEventsAtStartOfFunction = numevents;
if (want_exit) { if (_G(want_exit)) {
ProperExit(); ProperExit();
} }
@ -944,7 +944,7 @@ static void GameLoopUntilEvent(int untilwhat, const void *daaa) {
auto cached_user_disabled_for = user_disabled_for; auto cached_user_disabled_for = user_disabled_for;
SetupLoopParameters(untilwhat, daaa); SetupLoopParameters(untilwhat, daaa);
while (GameTick() == 0 && !abort_engine) { while (GameTick() == 0 && !_G(abort_engine)) {
} }
our_eip = 78; our_eip = 78;
@ -992,7 +992,7 @@ void RunGameUntilAborted() {
// skip ticks to account for time spent starting game. // skip ticks to account for time spent starting game.
skipMissedTicks(); skipMissedTicks();
while (!abort_engine) { while (!_G(abort_engine)) {
GameTick(); GameTick();
if (load_new_game) { if (load_new_game) {
@ -1003,8 +1003,8 @@ void RunGameUntilAborted() {
} }
void update_polled_stuff_if_runtime() { void update_polled_stuff_if_runtime() {
if (want_exit) { if (_G(want_exit)) {
want_exit = 0; _G(want_exit) = 0;
quit("||exit!"); quit("||exit!");
} }

View file

@ -51,7 +51,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 volatile char want_exit, abort_engine;
extern GameSetupStruct game; extern GameSetupStruct game;
extern GameState play; extern GameState play;
extern const char *loadSaveGameOnStartup; extern const char *loadSaveGameOnStartup;

View file

@ -46,6 +46,7 @@
#include "ags/shared/core/assetmanager.h" #include "ags/shared/core/assetmanager.h"
#include "ags/engine/plugin/plugin_engine.h" #include "ags/engine/plugin/plugin_engine.h"
#include "ags/engine/media/audio/audio_system.h" #include "ags/engine/media/audio/audio_system.h"
#include "ags/engine/globals.h"
#include "ags/ags.h" #include "ags/ags.h"
namespace AGS3 { namespace AGS3 {
@ -67,7 +68,6 @@ extern IAGSEditorDebugger *editor_debugger;
extern int need_to_stop_cd; extern int need_to_stop_cd;
extern int use_cdplayer; extern int use_cdplayer;
extern IGraphicsDriver *gfxDriver; extern IGraphicsDriver *gfxDriver;
extern volatile char abort_engine;
bool handledErrorInEditor; bool handledErrorInEditor;
@ -233,7 +233,7 @@ char quit_message[256] = "\0";
// "!|" is a special code used to mean that the player has aborted (Alt+X) // "!|" is a special code used to mean that the player has aborted (Alt+X)
void quit(const char *quitmsg) { void quit(const char *quitmsg) {
strncpy(quit_message, quitmsg, 256); strncpy(quit_message, quitmsg, 256);
abort_engine = true; _G(abort_engine) = true;
} }
void quit_free() { void quit_free() {

View file

@ -844,8 +844,6 @@ void update_volume_drop_if_voiceover() {
apply_volume_drop_modifier(play.speech_has_voice); apply_volume_drop_modifier(play.speech_has_voice);
} }
extern volatile char want_exit;
void update_mp3_thread() { void update_mp3_thread() {
if (switching_away_from_game) { if (switching_away_from_game) {
return; return;

View file

@ -20,8 +20,6 @@
* *
*/ */
//include <cstdio>
//include <string.h>
#include "ags/shared/ac/common.h" #include "ags/shared/ac/common.h"
#include "ags/engine/ac/dynobj/cc_dynamicarray.h" #include "ags/engine/ac/dynobj/cc_dynamicarray.h"
#include "ags/engine/ac/dynobj/managedobjectpool.h" #include "ags/engine/ac/dynobj/managedobjectpool.h"
@ -45,6 +43,7 @@
#include "ags/engine/ac/dynobj/cc_dynamicobject_addr_and_manager.h" #include "ags/engine/ac/dynobj/cc_dynamicobject_addr_and_manager.h"
#include "ags/shared/util/memory.h" #include "ags/shared/util/memory.h"
#include "ags/shared/util/string_utils.h" // linux strnicmp definition #include "ags/shared/util/string_utils.h" // linux strnicmp definition
#include "ags/engine/globals.h"
namespace AGS3 { namespace AGS3 {
@ -58,7 +57,6 @@ extern int maxWhileLoops;
extern new_line_hook_type new_line_hook; extern new_line_hook_type new_line_hook;
extern ScriptString myScriptStringImpl; extern ScriptString myScriptStringImpl;
extern volatile char abort_engine;
enum ScriptOpArgIsReg { enum ScriptOpArgIsReg {
kScOpNoArgIsReg = 0, kScOpNoArgIsReg = 0,
@ -435,7 +433,7 @@ int ccInstance::Run(int32_t curpc) {
FunctionCallStack func_callstack; FunctionCallStack func_callstack;
while (1) { while (1) {
if (abort_engine) if (_G(abort_engine))
return -1; return -1;
/* /*

View file

@ -22,9 +22,9 @@
#include "ags/events.h" #include "ags/events.h"
#include "common/system.h" #include "common/system.h"
#include "ags/engine/globals.h"
namespace AGS3 { namespace AGS3 {
extern volatile char want_exit, abort_engine;
extern char check_dynamic_sprites_at_exit; extern char check_dynamic_sprites_at_exit;
} }
@ -46,8 +46,8 @@ void EventsManager::pollEvents() {
while (g_system->getEventManager()->pollEvent(e)) { while (g_system->getEventManager()->pollEvent(e)) {
if (e.type == Common::EVENT_QUIT) { if (e.type == Common::EVENT_QUIT) {
::AGS3::want_exit = 1; _G(want_exit) = true;
::AGS3::abort_engine = 1; _G(abort_engine) = true;
::AGS3::check_dynamic_sprites_at_exit = 0; ::AGS3::check_dynamic_sprites_at_exit = 0;
} else if (e.type == Common::EVENT_KEYDOWN) { } else if (e.type == Common::EVENT_KEYDOWN) {

View file

@ -102,6 +102,7 @@ MODULE_OBJS = \
shared/util/textstreamwriter.o \ shared/util/textstreamwriter.o \
shared/util/version.o \ shared/util/version.o \
shared/util/wgt2allg.o \ shared/util/wgt2allg.o \
engine/globals.o \
engine/ac/dynobj/cc_agsdynamicobject.o \ engine/ac/dynobj/cc_agsdynamicobject.o \
engine/ac/dynobj/cc_audiochannel.o \ engine/ac/dynobj/cc_audiochannel.o \
engine/ac/dynobj/cc_audioclip.o \ engine/ac/dynobj/cc_audioclip.o \

View file

@ -22,6 +22,7 @@
#include "ags/shared/ac/common.h" #include "ags/shared/ac/common.h"
#include "ags/shared/util/string.h" #include "ags/shared/util/string.h"
#include "ags/engine/globals.h"
#include "ags/ags.h" #include "ags/ags.h"
namespace AGS3 { namespace AGS3 {
@ -29,7 +30,6 @@ namespace AGS3 {
using namespace AGS::Shared; using namespace AGS::Shared;
const char *game_file_sig = "Adventure Creator Game File v2"; const char *game_file_sig = "Adventure Creator Game File v2";
extern volatile char abort_engine;
void quitprintf(const char *fmt, ...) { void quitprintf(const char *fmt, ...) {
va_list ap; va_list ap;
@ -37,7 +37,7 @@ void quitprintf(const char *fmt, ...) {
String text = String::FromFormatV(fmt, ap); String text = String::FromFormatV(fmt, ap);
va_end(ap); va_end(ap);
if (!abort_engine) if (!_G(abort_engine))
::AGS::g_vm->GUIError(text); ::AGS::g_vm->GUIError(text);
quit(text); quit(text);
} }