[Scummvm-git-logs] scummvm master -> 8ec26fe0dbe57f5853b09cd6e80c5ffc91f9138a

aquadran noreply at scummvm.org
Sun Nov 17 13:07:38 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8ec26fe0db WINTERMUTE: Restore plugin events functionality


Commit: 8ec26fe0dbe57f5853b09cd6e80c5ffc91f9138a
    https://github.com/scummvm/scummvm/commit/8ec26fe0dbe57f5853b09cd6e80c5ffc91f9138a
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2024-11-17T14:07:34+01:00

Commit Message:
WINTERMUTE: Restore plugin events functionality

Changed paths:
  A engines/wintermute/ext/plugin_event.h
    engines/wintermute/ad/ad_game.cpp
    engines/wintermute/base/base_game.cpp
    engines/wintermute/base/base_game.h
    engines/wintermute/base/saveload.cpp


diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp
index 3d6a4cd5f72..84756a2d032 100644
--- a/engines/wintermute/ad/ad_game.cpp
+++ b/engines/wintermute/ad/ad_game.cpp
@@ -271,6 +271,7 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) {
 		_scene = new AdScene(_gameRef);
 		registerObject(_scene);
 	} else {
+		_gameRef->_pluginEvents.applyEvent(WME_EVENT_SCENE_SHUTDOWN, _scene);
 		_scene->applyEvent("SceneShutdown", true);
 
 		setPrevSceneName(_scene->getName());
@@ -310,6 +311,7 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) {
 			}
 
 			_scene->loadState();
+			_gameRef->_pluginEvents.applyEvent(WME_EVENT_SCENE_INIT, _scene);
 		}
 		if (fadeIn) {
 			_gameRef->_transMgr->start(TRANSITION_FADE_IN);
@@ -2092,12 +2094,18 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) {
 			_scEngine->tick();
 		}
 
+		// process plugin events
+		if (doUpdate)
+			_gameRef->_pluginEvents.applyEvent(WME_EVENT_UPDATE, nullptr);
+
 		Point32 p;
 		getMousePos(&p);
 
 		_scene->update();
-		_scene->display();
 
+		_gameRef->_pluginEvents.applyEvent(WME_EVENT_SCENE_DRAW_BEGIN, _scene);
+		_scene->display();
+		_gameRef->_pluginEvents.applyEvent(WME_EVENT_SCENE_DRAW_END, _scene);
 
 		// display in-game windows
 		displayWindows(true);
diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp
index ff77e4ad93b..252045472b1 100644
--- a/engines/wintermute/base/base_game.cpp
+++ b/engines/wintermute/base/base_game.cpp
@@ -503,6 +503,8 @@ bool BaseGame::initialize1() {
 		}
 		registerObject(_fader);
 
+		_pluginEvents.clearEvents();
+
 		loaded = true;
 	}
 	if (loaded == true) {
diff --git a/engines/wintermute/base/base_game.h b/engines/wintermute/base/base_game.h
index 7c28fb4045e..c4e3fda0472 100644
--- a/engines/wintermute/base/base_game.h
+++ b/engines/wintermute/base/base_game.h
@@ -31,6 +31,7 @@
 #include "engines/wintermute/base/base_object.h"
 #include "engines/wintermute/base/base_game_custom_actions.h"
 #include "engines/wintermute/base/timer.h"
+#include "engines/wintermute/ext/plugin_event.h"
 #include "engines/wintermute/persistent.h"
 #include "engines/wintermute/coll_templ.h"
 #include "engines/wintermute/math/rect32.h"
@@ -415,6 +416,7 @@ private:
 	uint8 getFilePartChecksumHc(const char *filename, uint32 begin, uint32 end);
 #endif
 
+	PluginEvent _pluginEvents;
 };
 
 } // End of namespace Wintermute
diff --git a/engines/wintermute/base/saveload.cpp b/engines/wintermute/base/saveload.cpp
index f1083bf7f22..15fcbef95e1 100644
--- a/engines/wintermute/base/saveload.cpp
+++ b/engines/wintermute/base/saveload.cpp
@@ -55,6 +55,7 @@ bool SaveLoad::loadGame(const Common::String &filename, BaseGame *gameRef) {
 	gameRef->_renderer->initSaveLoad(false);
 
 	gameRef->_loadInProgress = true;
+	gameRef->_pluginEvents.clearEvents();
 	BasePersistenceManager *pm = new BasePersistenceManager();
 	if (DID_SUCCEED(ret = pm->initLoad(filename))) {
 		//if (DID_SUCCEED(ret = cleanup())) {
@@ -66,6 +67,7 @@ bool SaveLoad::loadGame(const Common::String &filename, BaseGame *gameRef) {
 				// data initialization after load
 				SaveLoad::initAfterLoad();
 
+				gameRef->_pluginEvents.applyEvent(WME_EVENT_GAME_AFTER_LOAD, nullptr);
 				gameRef->applyEvent("AfterLoad", true);
 
 				gameRef->displayContent(true, false);
@@ -92,6 +94,7 @@ bool SaveLoad::saveGame(int slot, const char *desc, bool quickSave, BaseGame *ga
 
 	gameRef->LOG(0, "Saving game '%s'...", filename.c_str());
 
+	gameRef->_pluginEvents.applyEvent(WME_EVENT_GAME_BEFORE_SAVE, nullptr);
 	gameRef->applyEvent("BeforeSave", true);
 
 	bool ret;
diff --git a/engines/wintermute/ext/plugin_event.h b/engines/wintermute/ext/plugin_event.h
new file mode 100644
index 00000000000..6b6e8481d1d
--- /dev/null
+++ b/engines/wintermute/ext/plugin_event.h
@@ -0,0 +1,89 @@
+/* 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef WINTERMUTE_PLUGIN_EVENT_H
+#define WINTERMUTE_PLUGIN_EVENT_H
+
+namespace Wintermute {
+
+//////////////////////////////////////////////////////////////////////////
+// WME events
+typedef enum {
+	WME_EVENT_UPDATE = 0,
+	WME_EVENT_SCENE_DRAW_BEGIN,
+	WME_EVENT_SCENE_DRAW_END,
+	WME_EVENT_SCENE_INIT,
+	WME_EVENT_SCENE_SHUTDOWN,
+	WME_EVENT_GAME_BEFORE_SAVE,
+	WME_EVENT_GAME_AFTER_LOAD,
+	WME_EVENT_MAX
+} EWmeEvent;
+
+typedef void (*PluginApplyEvent)(void *, void *);
+
+typedef struct _PluginEventEntry {
+	EWmeEvent        _type;
+	PluginApplyEvent _callback;
+	void             *_plugin;
+} PluginEventEntry;
+
+class PluginEvent {
+public:
+	PluginEvent() {};
+	~PluginEvent() {};
+
+	void subscribeEvent(PluginEventEntry &event) {
+		for (auto it = _entries.begin(); it != _entries.end(); ++it) {
+			if (event._type == (*it)._type && event._callback == (*it)._callback) {
+				break;
+			}
+		}
+		_entries.push_back(event);
+	}
+
+	void unsubscribeEvent(PluginEventEntry &event) {
+		for (auto it = _entries.begin(); it != _entries.end(); ++it) {
+			if (event._type == (*it)._type && event._callback == (*it)._callback) {
+				_entries.erase(it);
+				break;
+			}
+		}
+	}
+
+	void applyEvent(EWmeEvent type, void *eventData) {
+		for (auto it = _entries.begin(); it != _entries.end(); ++it) {
+			if (type == (*it)._type && (*it)._callback != nullptr) {
+				(*it)._callback(eventData, (*it)._plugin);
+			}
+		}
+	}
+
+	void clearEvents() {
+		_entries.clear();
+	}
+
+private:
+	Common::List<PluginEventEntry> _entries;
+};
+
+} // End of namespace Wintermute
+
+#endif




More information about the Scummvm-git-logs mailing list