aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-09 19:36:12 -0400
committerPaul Gilbert2016-04-09 19:36:12 -0400
commitf7748622faa71729d12f3d0ec063417bdca60eb6 (patch)
treea25d1f9bc108bdf53d2fe78a7b121c3c5c595987
parent6405ba6ecbbec9a8e45e6093bcacf2cab7f3b94b (diff)
downloadscummvm-rg350-f7748622faa71729d12f3d0ec063417bdca60eb6.tar.gz
scummvm-rg350-f7748622faa71729d12f3d0ec063417bdca60eb6.tar.bz2
scummvm-rg350-f7748622faa71729d12f3d0ec063417bdca60eb6.zip
TITANIC: Further implementation of timers
-rw-r--r--engines/titanic/core/saveable_object.cpp3
-rw-r--r--engines/titanic/game_manager.cpp3
-rw-r--r--engines/titanic/game_manager.h16
-rw-r--r--engines/titanic/messages/messages.h10
-rw-r--r--engines/titanic/module.mk2
-rw-r--r--engines/titanic/support/time_event_info.cpp206
-rw-r--r--engines/titanic/support/time_event_info.h (renamed from engines/titanic/support/timer.h)52
-rw-r--r--engines/titanic/support/timer.cpp109
8 files changed, 278 insertions, 123 deletions
diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp
index 9f0ac320e2..4ef6a4a766 100644
--- a/engines/titanic/core/saveable_object.cpp
+++ b/engines/titanic/core/saveable_object.cpp
@@ -406,6 +406,7 @@
#include "titanic/sound/water_lapping_sounds.h"
#include "titanic/star_control/star_control.h"
+#include "titanic/support/time_event_info.h"
namespace Titanic {
@@ -1004,6 +1005,7 @@ DEFFN(CViewAutoSoundPlayer)
DEFFN(CViewTogglesOtherMusic)
DEFFN(CWaterLappingSounds)
DEFFN(CStarControl)
+DEFFN(CTimeEventInfo)
void CSaveableObject::initClassList() {
_classDefs = new Common::List<ClassDef *>();
@@ -1592,6 +1594,7 @@ void CSaveableObject::initClassList() {
ADDFN(CViewTogglesOtherMusic, CEnterViewTogglesOtherMusic);
ADDFN(CWaterLappingSounds, CRoomAutoSoundPlayer);
ADDFN(CStarControl, CGameObject);
+ ADDFN(CTimeEventInfo, ListItem);
}
void CSaveableObject::freeClassList() {
diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp
index 56355dc58b..31bb4278e1 100644
--- a/engines/titanic/game_manager.cpp
+++ b/engines/titanic/game_manager.cpp
@@ -37,6 +37,7 @@ CGameManager::CGameManager(CProjectItem *project, CGameView *gameView):
_field30(0), _soundMaker(nullptr), _field4C(0),
_dragItem(nullptr), _field54(0), _lastDiskTicksCount(0), _tickCount2(0) {
+ CTimeEventInfo::_nextId = 0;
_videoSurface1 = nullptr;
_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340);
_project->setGameManager(this);
@@ -91,7 +92,7 @@ void CGameManager::preSave(CProjectItem *project) {
msg.execute(project, nullptr, MSGFLAG_SCAN);
// Notify sub-objects of the save
- _timers.preSave();
+ _timers.preSave(_lastDiskTicksCount);
_trueTalkManager.preSave();
_sound.preSave();
}
diff --git a/engines/titanic/game_manager.h b/engines/titanic/game_manager.h
index 8b4c0be34e..6e5782fb1d 100644
--- a/engines/titanic/game_manager.h
+++ b/engines/titanic/game_manager.h
@@ -28,7 +28,7 @@
#include "titanic/input_handler.h"
#include "titanic/input_translator.h"
#include "titanic/support/simple_file.h"
-#include "titanic/support/timer.h"
+#include "titanic/support/time_event_info.h"
#include "titanic/support/video_surface.h"
#include "titanic/true_talk/true_talk_manager.h"
#include "titanic/sound/background_sound_maker.h"
@@ -43,7 +43,7 @@ class CGameView;
class CGameManager {
private:
CTrueTalkManager _trueTalkManager;
- CTimerList _timers;
+ CTimeEventInfoList _timers;
int _field30;
CBackgroundSoundMaker *_soundMaker;
CVideoSurface *_videoSurface1;
@@ -169,6 +169,18 @@ public:
* Set and return the current screen manager
*/
CScreenManager *setScreenManager() const;
+
+ /**
+ * Adds a timer
+ */
+ void addTimer(CTimeEventInfo *timer) { _timers.push_back(timer); }
+
+ /**
+ * Stops a timer
+ */
+ void stopTimer(uint id) { _timers.stop(id); }
+
+ void setTimer44(uint id, uint val) { _timers.set44(id, val); }
};
} // End of namespace Titanic
diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h
index e566b5d661..82601e525f 100644
--- a/engines/titanic/messages/messages.h
+++ b/engines/titanic/messages/messages.h
@@ -222,16 +222,18 @@ public:
}
};
-MESSAGE1(CTimeMsg, int, value, 0);
+MESSAGE1(CTimeMsg, uint, _ticks, 0);
class CTimerMsg : public CTimeMsg {
public:
- int _field8;
+ uint _timerCtr;
int _fieldC;
- CString _string1;
+ CString _action;
public:
CLASSDEF
- CTimerMsg() : CTimeMsg(), _field8(0), _fieldC(0) {}
+ CTimerMsg() : CTimeMsg(), _timerCtr(0), _fieldC(0) {}
+ CTimerMsg(uint ticks, uint timerCtr, int val2, const CString &action) :
+ CTimeMsg(ticks), _timerCtr(timerCtr), _fieldC(val2), _action(action) {}
static bool isSupportedBy(const CTreeItem *item) {
return supports(item, _type);
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index 74dfbfbb7c..7a142eabb0 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -437,7 +437,7 @@ MODULE_OBJS := \
support/simple_file.o \
support/string.o \
support/text_cursor.o \
- support/timer.o \
+ support/time_event_info.o \
support/video_surface.o \
true_talk/barbot_script.o \
true_talk/bellbot_script.o \
diff --git a/engines/titanic/support/time_event_info.cpp b/engines/titanic/support/time_event_info.cpp
new file mode 100644
index 0000000000..c3312de7d7
--- /dev/null
+++ b/engines/titanic/support/time_event_info.cpp
@@ -0,0 +1,206 @@
+/* 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 "titanic/support/time_event_info.h"
+#include "titanic/core/game_object.h"
+#include "titanic/core/project_item.h"
+#include "titanic/messages/messages.h"
+
+namespace Titanic {
+
+void CTimeEventInfoList::postLoad(uint ticks, CProjectItem *project) {
+ for (iterator i = begin(); i != end(); ++i)
+ (*i)->postLoad(ticks, project);
+}
+
+void CTimeEventInfoList::preSave(uint ticks) {
+ for (iterator i = begin(); i != end(); ++i)
+ (*i)->preSave(ticks);
+}
+
+void CTimeEventInfoList::postSave() {
+ for (iterator i = begin(); i != end(); ++i)
+ (*i)->postSave();
+}
+
+void CTimeEventInfoList::update(uint ticks) {
+ // Remove any items that are done
+ for (iterator i = begin(); i != end(); ) {
+ CTimeEventInfo *item = *i;
+ if (item->_done) {
+ i = erase(i);
+ delete item;
+ } else {
+ ++i;
+ }
+ }
+
+ // Handle updating the items
+ for (iterator i = begin(); i != end(); ) {
+ CTimeEventInfo *item = *i;
+ if (!item->update(ticks)) {
+ ++i;
+ } else {
+ i = erase(i);
+ delete item;
+ }
+ }
+}
+
+void CTimeEventInfoList::stop(uint id) {
+ for (iterator i = begin(); i != end(); ++i) {
+ CTimeEventInfo *item = *i;
+ if (item->_id == id) {
+ item->_done = true;
+ return;
+ }
+ }
+}
+
+void CTimeEventInfoList::set44(uint id, uint val) {
+ for (iterator i = begin(); i != end(); ++i) {
+ CTimeEventInfo *item = *i;
+ if (item->_id == id) {
+ item->set44(val);
+ return;
+ }
+ }
+}
+
+/*------------------------------------------------------------------------*/
+
+uint CTimeEventInfo::_nextId;
+
+CTimeEventInfo::CTimeEventInfo() : ListItem(), _lockCounter(0),
+ _field14(0), _firstDuration(0), _duration(0), _target(nullptr),
+ _actionVal(0), _field2C(0), _field30(0), _timerCtr(0),
+ _lastTimerTicks(0), _field3C(0), _done(false), _field44(0) {
+ _id = _nextId++;
+}
+
+CTimeEventInfo::CTimeEventInfo(uint ticks, uint f14, uint firstDuration,
+ uint duration, CTreeItem *target, int timerVal3, const CString &action) :
+ ListItem(), _lockCounter(0), _field14(f14), _firstDuration(firstDuration),
+ _duration(duration), _target(target), _field2C(0), _field30(0),
+ _timerCtr(0), _lastTimerTicks(ticks), _field3C(0), _done(false),
+ _field44(true) {
+ _id = _nextId++;
+}
+
+void CTimeEventInfo::save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+
+ CString targetName;
+ if (_target)
+ targetName = _target->getName();
+ file->writeQuotedLine(targetName, indent);
+ file->writeNumberLine(_id, indent);
+ file->writeNumberLine(_field14, indent);
+ file->writeNumberLine(_firstDuration, indent);
+ file->writeNumberLine(_duration, indent);
+ file->writeNumberLine(_actionVal, indent);
+ file->writeQuotedLine(_action, indent);
+ file->writeNumberLine(_timerCtr, indent);
+ file->writeNumberLine(_field3C, indent);
+ file->writeNumberLine(_done, indent);
+ file->writeNumberLine(_field44, indent);
+}
+
+void CTimeEventInfo::load(SimpleFile *file) {
+ lock();
+ int val = file->readNumber();
+
+ if (!val) {
+ _targetName = file->readString();
+ _id = file->readNumber();
+ _field14 = file->readNumber();
+ _firstDuration = file->readNumber();
+ _duration = file->readNumber();
+ _actionVal = file->readNumber();
+ _action = file->readString();
+ _timerCtr = file->readNumber();
+ _field3C = file->readNumber();
+ _done = file->readNumber() != 0;
+ _field44 = file->readNumber();
+ _target = nullptr;
+ }
+}
+
+void CTimeEventInfo::postLoad(uint ticks, CProjectItem *project) {
+ if (!_field44 || _targetName.empty())
+ _done = true;
+
+ // Get the timer's target
+ if (project)
+ _target = project->findByName(_targetName);
+ if (!_target)
+ _done = true;
+
+ _lastTimerTicks = ticks + _field3C;
+ if (_id >= _nextId)
+ _nextId = _id + 1;
+
+ unlock();
+}
+
+void CTimeEventInfo::preSave(uint ticks) {
+ _field3C = _lastTimerTicks - ticks;
+ lock();
+}
+
+void CTimeEventInfo::postSave() {
+ unlock();
+}
+
+bool CTimeEventInfo::update(uint ticks) {
+ if (_lockCounter)
+ return false;
+
+ if (_timerCtr) {
+ if (ticks > (_lastTimerTicks + _duration)) {
+ ++_timerCtr;
+ _lastTimerTicks = ticks;
+
+ if (_target) {
+ CTimerMsg timerMsg(ticks, _timerCtr, _actionVal, _action);
+ timerMsg.execute(_target);
+ }
+ }
+ } else {
+ if (ticks > (_lastTimerTicks + _firstDuration)) {
+ _timerCtr = 1;
+ _lastTimerTicks = ticks;
+
+ if (_target) {
+ CTimerMsg timerMsg(ticks, _timerCtr, _actionVal, _action);
+ timerMsg.execute(_target);
+ }
+
+ if (!_field14)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/support/timer.h b/engines/titanic/support/time_event_info.h
index 4d74bae34c..ee923f5fcb 100644
--- a/engines/titanic/support/timer.h
+++ b/engines/titanic/support/time_event_info.h
@@ -23,21 +23,61 @@
#ifndef TITANIC_TIMER_H
#define TITANIC_TIMER_H
+#include "common/algorithm.h"
#include "titanic/core/list.h"
namespace Titanic {
+class CTreeItem;
class CProjectItem;
-class CTimer : public ListItem {
+class CTimeEventInfo : public ListItem {
private:
- static int _v1;
+ /**
+ * Increments the counter
+ */
+ void lock() { ++_lockCounter; }
+
+ /**
+ * Called at the end of both post load and post save actions
+ */
+ void unlock() {
+ _lockCounter = MAX(_lockCounter - 1, 0);
+ }
+public:
+ static uint _nextId;
public:
+ int _lockCounter;
uint _id;
+ uint _field14;
+ uint _firstDuration;
+ uint _duration;
+ CTreeItem *_target;
+ uint _actionVal;
+ CString _action;
+ uint _field2C;
+ uint _field30;
+ uint _timerCtr;
+ uint _lastTimerTicks;
+ uint _field3C;
bool _done;
uint _field44;
+ CString _targetName;
public:
- CTimer();
+ CLASSDEF
+ CTimeEventInfo();
+ CTimeEventInfo(uint ticks, uint f14, uint firstDuration, uint duration,
+ CTreeItem *target, int timerVal3, const CString &action);
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
/**
* Called after loading a game has finished
@@ -47,7 +87,7 @@ public:
/**
* Called when a game is about to be saved
*/
- void preSave();
+ void preSave(uint ticks);
/**
* Called when a game has finished being saved
@@ -59,7 +99,7 @@ public:
void set44(uint val) { _field44 = val; }
};
-class CTimerList : public List<CTimer> {
+class CTimeEventInfoList : public List<CTimeEventInfo> {
public:
/**
* Called after loading a game has finished
@@ -69,7 +109,7 @@ public:
/**
* Called when a game is about to be saved
*/
- void preSave();
+ void preSave(uint ticks);
/**
* Called when a game has finished being saved
diff --git a/engines/titanic/support/timer.cpp b/engines/titanic/support/timer.cpp
deleted file mode 100644
index 6f99a67fd8..0000000000
--- a/engines/titanic/support/timer.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/* 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 "titanic/support/timer.h"
-#include "titanic/core/project_item.h"
-
-namespace Titanic {
-
-void CTimerList::postLoad(uint ticks, CProjectItem *project) {
- for (iterator i = begin(); i != end(); ++i)
- (*i)->postLoad(ticks, project);
-}
-
-void CTimerList::preSave() {
- for (iterator i = begin(); i != end(); ++i)
- (*i)->preSave();
-}
-
-void CTimerList::postSave() {
- for (iterator i = begin(); i != end(); ++i)
- (*i)->postSave();
-}
-
-void CTimerList::update(uint ticks) {
- // Remove any items that are done
- for (iterator i = begin(); i != end(); ) {
- CTimer *item = *i;
- if (item->_done) {
- i = erase(i);
- delete item;
- } else {
- ++i;
- }
- }
-
- // Handle updating the items
- for (iterator i = begin(); i != end(); ) {
- CTimer *item = *i;
- if (!item->update(ticks)) {
- ++i;
- } else {
- i = erase(i);
- delete item;
- }
- }
-}
-
-void CTimerList::stop(uint id) {
- for (iterator i = begin(); i != end(); ++i) {
- CTimer *item = *i;
- if (item->_id == id) {
- item->_done = true;
- return;
- }
- }
-}
-
-void CTimerList::set44(uint id, uint val) {
- for (iterator i = begin(); i != end(); ++i) {
- CTimer *item = *i;
- if (item->_id == id) {
- item->set44(val);
- return;
- }
- }
-}
-
-/*------------------------------------------------------------------------*/
-
-CTimer::CTimer() : _id(0), _done(false),
- _field44(0) {
-}
-
-void CTimer::postLoad(uint ticks, CProjectItem *project) {
- warning("TODO");
-}
-
-void CTimer::preSave() {
- warning("TODO: CTimer::preSave");
-}
-
-void CTimer::postSave() {
- warning("TODO: CTimer::postSave");
-}
-
-bool CTimer::update(uint ticks) {
- return false;
-}
-
-} // End of namespace Titanic