From ecd81a9a6d84e74fa89b0905620bcc342ef68da5 Mon Sep 17 00:00:00 2001
From: Matthew Hoops
Date: Wed, 7 Sep 2011 13:13:34 -0400
Subject: PEGASUS: Add Idler framework

---
 engines/pegasus/module.mk   |  1 +
 engines/pegasus/pegasus.cpp | 14 ++++++++++++
 engines/pegasus/pegasus.h   |  9 ++++++++
 engines/pegasus/timers.cpp  | 53 +++++++++++++++++++++++++++++++++++++++++++++
 engines/pegasus/timers.h    | 50 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 127 insertions(+)
 create mode 100755 engines/pegasus/timers.cpp
 create mode 100755 engines/pegasus/timers.h

(limited to 'engines')

diff --git a/engines/pegasus/module.mk b/engines/pegasus/module.mk
index 8d3ee52304..50e9b54dd3 100644
--- a/engines/pegasus/module.mk
+++ b/engines/pegasus/module.mk
@@ -13,6 +13,7 @@ MODULE_OBJS = \
 	overview.o \
 	pegasus.o \
 	sound.o \
+	timers.o \
 	util.o \
 	video.o \
 	items/inventory.o \
diff --git a/engines/pegasus/pegasus.cpp b/engines/pegasus/pegasus.cpp
index 3093e9be2c..466945e211 100644
--- a/engines/pegasus/pegasus.cpp
+++ b/engines/pegasus/pegasus.cpp
@@ -34,6 +34,7 @@
 #include "pegasus/console.h"
 #include "pegasus/gamestate.h"
 #include "pegasus/pegasus.h"
+#include "pegasus/timers.h"
 
 //#define RUN_SUB_MOVIE // :D :D :D :D :D :D
 //#define RUN_INTERFACE_TEST
@@ -281,4 +282,17 @@ GUI::Debugger *PegasusEngine::getDebugger() {
 	return _console;
 }
 
+void PegasusEngine::addIdler(Idler *idler) {
+	_idlers.push_back(idler);
+}
+
+void PegasusEngine::removeIdler(Idler *idler) {
+	_idlers.remove(idler);
+}
+
+void PegasusEngine::giveIdleTime() {
+	for (Common::List<Idler *>::iterator it = _idlers.begin(); it != _idlers.end(); it++)
+		(*it)->useIdleTime();
+}
+
 } // End of namespace Pegasus
diff --git a/engines/pegasus/pegasus.h b/engines/pegasus/pegasus.h
index 5c85251d76..53593c1c1b 100644
--- a/engines/pegasus/pegasus.h
+++ b/engines/pegasus/pegasus.h
@@ -23,6 +23,7 @@
 #ifndef PEGASUS_H
 #define PEGASUS_H
 
+#include "common/list.h"
 #include "common/macresman.h"
 #include "common/scummsys.h"
 #include "common/system.h"
@@ -46,6 +47,7 @@ struct PegasusGameDescription;
 class SoundManager;
 class VideoManager;
 class GraphicsManager;
+class Idler;
 
 enum ItemLocation {
 	kItemLocationCaldoria = 0,
@@ -96,6 +98,9 @@ public:
 
 	bool isDemo() const;
 
+	void addIdler(Idler *idler);
+	void removeIdler(Idler *idler);
+
 private:
 	// Intro
 	void runIntro();
@@ -141,6 +146,10 @@ private:
 	// Intro Directory Code
 	bool detectOpeningClosingDirectory();
 	Common::String _introDirectory;
+
+	// Idlers
+	Common::List<Idler *> _idlers;
+	void giveIdleTime();
 };
 
 } // End of namespace Pegasus
diff --git a/engines/pegasus/timers.cpp b/engines/pegasus/timers.cpp
new file mode 100755
index 0000000000..5908854d13
--- /dev/null
+++ b/engines/pegasus/timers.cpp
@@ -0,0 +1,53 @@
+/* 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.
+ *
+ * Additional copyright for this file:
+ * Copyright (C) 1995-1997 Presto Studios, Inc.
+ *
+ * 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 "pegasus/pegasus.h"
+#include "pegasus/timers.h"
+
+namespace Pegasus {
+
+Idler::Idler() {
+	_isIdling = false;
+}
+
+Idler::~Idler() {
+	stopIdling();
+}
+
+void Idler::startIdling() {
+	if (!isIdling()) {
+		((PegasusEngine *)g_engine)->addIdler(this);
+		_isIdling = true;
+	}
+}
+
+void Idler::stopIdling() {
+	if (isIdling()) {
+		((PegasusEngine *)g_engine)->removeIdler(this);
+		_isIdling = false;
+	}
+}
+
+} // End of namespace Pegasus
diff --git a/engines/pegasus/timers.h b/engines/pegasus/timers.h
new file mode 100755
index 0000000000..e4bb41086f
--- /dev/null
+++ b/engines/pegasus/timers.h
@@ -0,0 +1,50 @@
+/* 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.
+ *
+ * Additional copyright for this file:
+ * Copyright (C) 1995-1997 Presto Studios, Inc.
+ *
+ * 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 PEGASUS_TIMERS_H
+#define PEGASUS_TIMERS_H
+
+namespace Pegasus {
+
+class Idler {
+friend class PegasusEngine;
+
+public:
+	Idler();
+	virtual ~Idler();
+	
+	virtual void startIdling();
+	virtual void stopIdling();
+	bool isIdling() const { return _isIdling; }
+	
+protected:
+	virtual void useIdleTime() {}
+
+	bool _isIdling;
+};
+
+} // End of namespace Pegasus
+
+#endif
-- 
cgit v1.2.3