aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-06 22:17:26 -0400
committerPaul Gilbert2016-04-06 22:17:26 -0400
commit51df4d98d3a066e092f34cf7968c436a3e430df2 (patch)
tree9e35582d31b834dff272da7fd27de03633990017 /engines/titanic
parente728e901d02aca51858f91ac29b1a177e5e80a07 (diff)
downloadscummvm-rg350-51df4d98d3a066e092f34cf7968c436a3e430df2.tar.gz
scummvm-rg350-51df4d98d3a066e092f34cf7968c436a3e430df2.tar.bz2
scummvm-rg350-51df4d98d3a066e092f34cf7968c436a3e430df2.zip
TITANIC: In-progress converting message handling to be more like original
I currently was using multiple inheritance to define the message classes that a class supports, but this caused problems when, for example, a class tested to see if an object supported CMouseMsg. The class in question supported several mouse messages, but a standard dynamic_cast returned nullptr for the class, since it didn't directly support it
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/core/background.cpp16
-rw-r--r--engines/titanic/core/background.h13
-rw-r--r--engines/titanic/core/game_object.cpp3
-rw-r--r--engines/titanic/core/game_object.h1
-rw-r--r--engines/titanic/core/message_target.cpp15
-rw-r--r--engines/titanic/core/message_target.h43
-rw-r--r--engines/titanic/core/named_item.cpp3
-rw-r--r--engines/titanic/core/named_item.h1
-rw-r--r--engines/titanic/core/tree_item.cpp3
-rw-r--r--engines/titanic/core/tree_item.h1
-rw-r--r--engines/titanic/core/view_item.cpp15
-rw-r--r--engines/titanic/core/view_item.h15
-rw-r--r--engines/titanic/game/gondolier/gondolier_mixer.h3
-rw-r--r--engines/titanic/game/television.h14
14 files changed, 104 insertions, 42 deletions
diff --git a/engines/titanic/core/background.cpp b/engines/titanic/core/background.cpp
index cb8e26450f..5859719026 100644
--- a/engines/titanic/core/background.cpp
+++ b/engines/titanic/core/background.cpp
@@ -24,6 +24,12 @@
namespace Titanic {
+BEGIN_MESSAGE_MAP(CBackground, CGameObject)
+ ON_MESSAGE(StatusChangeMsg)
+ ON_MESSAGE(SetFrameMsg)
+ ON_MESSAGE(VisibleMsg)
+END_MESSAGE_MAP()
+
CBackground::CBackground() : CGameObject(), _fieldBC(0), _fieldC0(0), _fieldDC(0) {
}
@@ -49,7 +55,7 @@ void CBackground::load(SimpleFile *file) {
CGameObject::load(file);
}
-bool CBackground::handleMessage(CStatusChangeMsg &msg) {
+bool CBackground::StatusChangeMsg(CStatusChangeMsg *msg) {
setVisible(true);
if (_fieldDC) {
fn1(_fieldBC, _fieldC0, 16);
@@ -59,13 +65,13 @@ bool CBackground::handleMessage(CStatusChangeMsg &msg) {
return true;
}
-bool CBackground::handleMessage(CSetFrameMsg &msg) {
- loadFrame(msg._frameNumber);
+bool CBackground::SetFrameMsg(CSetFrameMsg *msg) {
+ loadFrame(msg->_frameNumber);
return true;
}
-bool CBackground::handleMessage(CVisibleMsg &msg) {
- setVisible(msg._visible);
+bool CBackground::VisibleMsg(CVisibleMsg *msg) {
+ setVisible(msg->_visible);
return true;
}
diff --git a/engines/titanic/core/background.h b/engines/titanic/core/background.h
index bd8f94987e..91c34073cd 100644
--- a/engines/titanic/core/background.h
+++ b/engines/titanic/core/background.h
@@ -28,10 +28,7 @@
namespace Titanic {
-class CBackground : public CGameObject,
- public CStatusChangeMsgTarget,
- public CSetFrameMsgTarget,
- public CVisibleMsgTarget {
+class CBackground : public CGameObject {
protected:
int _fieldBC;
int _fieldC0;
@@ -39,9 +36,11 @@ protected:
CString _string2;
int _fieldDC;
protected:
- virtual bool handleMessage(CStatusChangeMsg &msg);
- virtual bool handleMessage(CSetFrameMsg &msg);
- virtual bool handleMessage(CVisibleMsg &msg);
+ DECLARE_MESSAGE_MAP
+
+ virtual bool StatusChangeMsg(CStatusChangeMsg *msg);
+ virtual bool SetFrameMsg(CSetFrameMsg *msg);
+ virtual bool VisibleMsg(CVisibleMsg *msg);
public:
CLASSDEF
CBackground();
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index d2b1c29ed7..2bac988b31 100644
--- a/engines/titanic/core/game_object.cpp
+++ b/engines/titanic/core/game_object.cpp
@@ -31,6 +31,9 @@
namespace Titanic {
+BEGIN_MESSAGE_MAP(CGameObject, CNamedItem)
+END_MESSAGE_MAP()
+
void *CGameObject::_v1 = nullptr;
CGameObject::CGameObject(): CNamedItem() {
diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h
index 495fc8a2c9..7391a6b079 100644
--- a/engines/titanic/core/game_object.h
+++ b/engines/titanic/core/game_object.h
@@ -36,6 +36,7 @@ class CVideoSurface;
class CMouseDragStartMsg;
class CGameObject : public CNamedItem {
+ DECLARE_MESSAGE_MAP
public:
static void *_v1;
private:
diff --git a/engines/titanic/core/message_target.cpp b/engines/titanic/core/message_target.cpp
index a7dd3a02a2..b99fa5c606 100644
--- a/engines/titanic/core/message_target.cpp
+++ b/engines/titanic/core/message_target.cpp
@@ -23,7 +23,20 @@
#include "titanic/core/message_target.h"
namespace Titanic {
-
+
+const MSGMAP *CMessageTarget::getMessageMap() const {
+ return getThisMessageMap();
+}
+
+const MSGMAP *CMessageTarget::getThisMessageMap() {
+ static const MSGMAP_ENTRY _messageEntries[] = {
+ { (PMSG)nullptr, nullptr }
+ };
+
+ static const MSGMAP messageMap = { nullptr, &_messageEntries[0] };
+ return &messageMap;
+}
+
void CMessageTarget::save(SimpleFile *file, int indent) const {
file->writeNumberLine(0, indent);
CSaveableObject::save(file, indent);
diff --git a/engines/titanic/core/message_target.h b/engines/titanic/core/message_target.h
index b099546852..0f43bcd2c5 100644
--- a/engines/titanic/core/message_target.h
+++ b/engines/titanic/core/message_target.h
@@ -27,7 +27,49 @@
namespace Titanic {
+class CMessageTarget;
+class CMessage;
+
+typedef bool (CMessageTarget::*PMSG)(CMessage *msg);
+
+struct MSGMAP_ENTRY {
+ PMSG _fn;
+ ClassDef *_class;
+};
+
+struct MSGMAP {
+ const MSGMAP *(* pFnGetBaseMap)();
+ const MSGMAP_ENTRY *lpEntries;
+};
+
+#define DECLARE_MESSAGE_MAP \
+protected: \
+ static const MSGMAP *getThisMessageMap(); \
+ virtual const MSGMAP *getMessageMap() const;
+
+#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
+ const MSGMAP *theClass::getMessageMap() const \
+ { return getThisMessageMap(); } \
+ const MSGMAP *theClass::getThisMessageMap() \
+ { \
+ typedef theClass ThisClass; \
+ typedef baseClass TheBaseClass; \
+ typedef bool (theClass::*FNPTR)(CMessage *msg); \
+ static const MSGMAP_ENTRY _messageEntries[] = {
+
+#define ON_MESSAGE(msgClass) \
+ { static_cast<PMSG>((FNPTR)&ThisClass::msgClass), C##msgClass::_type },
+
+#define END_MESSAGE_MAP() \
+ { (PMSG)nullptr, nullptr } \
+ }; \
+ static const MSGMAP messageMap = \
+ { &TheBaseClass::getThisMessageMap, &_messageEntries[0] }; \
+ return &messageMap; \
+ }
+
class CMessageTarget: public CSaveableObject {
+ DECLARE_MESSAGE_MAP
public:
CLASSDEF
@@ -40,7 +82,6 @@ public:
* Load the data for the class from file
*/
virtual void load(SimpleFile *file);
-
};
} // End of namespace Titanic
diff --git a/engines/titanic/core/named_item.cpp b/engines/titanic/core/named_item.cpp
index 02e75044aa..72d3fd9f42 100644
--- a/engines/titanic/core/named_item.cpp
+++ b/engines/titanic/core/named_item.cpp
@@ -27,6 +27,9 @@
namespace Titanic {
+BEGIN_MESSAGE_MAP(CNamedItem, CTreeItem)
+END_MESSAGE_MAP()
+
CString CNamedItem::dumpItem(int indent) const {
CString result = CTreeItem::dumpItem(indent);
result += " " + _name;
diff --git a/engines/titanic/core/named_item.h b/engines/titanic/core/named_item.h
index 6ee11e960e..9763e1b332 100644
--- a/engines/titanic/core/named_item.h
+++ b/engines/titanic/core/named_item.h
@@ -32,6 +32,7 @@ class CNodeItem;
class CRoomItem;
class CNamedItem: public CTreeItem {
+ DECLARE_MESSAGE_MAP
public:
CString _name;
public:
diff --git a/engines/titanic/core/tree_item.cpp b/engines/titanic/core/tree_item.cpp
index e7b61dc853..80eac81e99 100644
--- a/engines/titanic/core/tree_item.cpp
+++ b/engines/titanic/core/tree_item.cpp
@@ -36,6 +36,9 @@
namespace Titanic {
+BEGIN_MESSAGE_MAP(CTreeItem, CMessageTarget)
+END_MESSAGE_MAP()
+
CTreeItem::CTreeItem() : _parent(nullptr), _firstChild(nullptr),
_nextSibling(nullptr), _priorSibling(nullptr), _field14(0) {
}
diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h
index 9710a255d0..f5b1407fcd 100644
--- a/engines/titanic/core/tree_item.h
+++ b/engines/titanic/core/tree_item.h
@@ -36,6 +36,7 @@ class CScreenManager;
class CRoomItem;
class CTreeItem: public CMessageTarget {
+ DECLARE_MESSAGE_MAP
private:
CTreeItem *_parent;
CTreeItem *_nextSibling;
diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp
index 098adc0c61..26e0d86d27 100644
--- a/engines/titanic/core/view_item.cpp
+++ b/engines/titanic/core/view_item.cpp
@@ -30,6 +30,13 @@
namespace Titanic {
+BEGIN_MESSAGE_MAP(CViewItem, CNamedItem)
+ ON_MESSAGE(MouseButtonDownMsg)
+ ON_MESSAGE(MouseButtonUpMsg)
+ ON_MESSAGE(MouseDoubleClickMsg)
+ ON_MESSAGE(MouseMoveMsg)
+END_MESSAGE_MAP()
+
CViewItem::CViewItem() : CNamedItem() {
Common::fill(&_buttonUpTargets[0], &_buttonUpTargets[4], nullptr);
_field24 = 0;
@@ -161,7 +168,7 @@ void CViewItem::enterView(CViewItem *newView) {
}
}
-bool CViewItem::handleMessage(CMouseButtonDownMsg &msg) {
+bool CViewItem::MouseButtonDownMsg(CMouseButtonDownMsg &msg) {
if (msg._buttons & MB_LEFT) {
if (!handleMouseMsg(&msg, true)) {
CGameManager *gm = getGameManager();
@@ -186,21 +193,21 @@ bool CViewItem::handleMessage(CMouseButtonDownMsg &msg) {
return true;
}
-bool CViewItem::handleMessage(CMouseButtonUpMsg &msg) {
+bool CViewItem::MouseButtonUpMsg(CMouseButtonUpMsg &msg) {
if (msg._buttons & MB_LEFT)
handleMouseMsg(&msg, false);
return true;
}
-bool CViewItem::handleMessage(CMouseDoubleClickMsg &msg) {
+bool CViewItem::MouseDoubleClickMsg(CMouseDoubleClickMsg &msg) {
if (msg._buttons & MB_LEFT)
handleMouseMsg(&msg, false);
return true;
}
-bool CViewItem::handleMessage(CMouseMoveMsg &msg) {
+bool CViewItem::MouseMoveMsg(CMouseMoveMsg &msg) {
CScreenManager *screenManager = CScreenManager::_screenManagerPtr;
if (handleMouseMsg(&msg, true)) {
diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h
index fc4089f924..f439929f5e 100644
--- a/engines/titanic/core/view_item.h
+++ b/engines/titanic/core/view_item.h
@@ -29,11 +29,8 @@
namespace Titanic {
-class CViewItem : public CNamedItem,
- public CMouseButtonDownMsgTarget,
- public CMouseButtonUpMsgTarget,
- public CMouseMoveMsgTarget,
- public CMouseDoubleClickMsgTarget {
+class CViewItem : public CNamedItem {
+ DECLARE_MESSAGE_MAP
private:
CTreeItem *_buttonUpTargets[4];
private:
@@ -55,10 +52,10 @@ protected:
int _field50;
int _field54;
protected:
- virtual bool handleMessage(CMouseButtonDownMsg &msg);
- virtual bool handleMessage(CMouseButtonUpMsg &msg);
- virtual bool handleMessage(CMouseMoveMsg &msg);
- virtual bool handleMessage(CMouseDoubleClickMsg &msg);
+ virtual bool MouseButtonDownMsg(CMouseButtonDownMsg &msg);
+ virtual bool MouseButtonUpMsg(CMouseButtonUpMsg &msg);
+ virtual bool MouseMoveMsg(CMouseMoveMsg &msg);
+ virtual bool MouseDoubleClickMsg(CMouseDoubleClickMsg &msg);
public:
int _viewNumber;
public:
diff --git a/engines/titanic/game/gondolier/gondolier_mixer.h b/engines/titanic/game/gondolier/gondolier_mixer.h
index c6ea840ea6..1186393d04 100644
--- a/engines/titanic/game/gondolier/gondolier_mixer.h
+++ b/engines/titanic/game/gondolier/gondolier_mixer.h
@@ -28,8 +28,7 @@
namespace Titanic {
-class CGondolierMixer : public CGondolierBase,
- public CEnterRoomMsgTarget {
+class CGondolierMixer : public CGondolierBase {
private:
int _fieldBC;
int _fieldC0;
diff --git a/engines/titanic/game/television.h b/engines/titanic/game/television.h
index c6c920b74c..9fb33943c0 100644
--- a/engines/titanic/game/television.h
+++ b/engines/titanic/game/television.h
@@ -29,19 +29,7 @@
namespace Titanic {
-class CTelevision : public CBackground,
- public CLeaveViewMsgTarget,
- public CChangeSeasonMsgTarget,
- public CEnterViewMsgTarget,
- public CPETUpMsgTarget,
- public CPETDownMsgTarget,
- public CActMsgTarget,
- public CPETActivateMsgTarget,
- public CMovieEndMsgTarget,
- public CShipSettingMsgTarget,
- public CTurnOffTarget,
- public CTurnOnTarget,
- public CLightsMsgTarget {
+class CTelevision : public CBackground {
private:
static int _v1;
static bool _turnOn;