aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/MMShell
diff options
context:
space:
mode:
authorMatthew Hoops2011-06-16 14:12:18 -0400
committerMatthew Hoops2011-06-16 14:12:18 -0400
commite789ab0d3b21c1c0cf76700b40f2e3c440a825a0 (patch)
treede0c9855ac595cc9d529a08c0be0c2479858ff87 /engines/pegasus/MMShell
parentfd8eaba47a3a3bdbac56f2d21d100b3b953ed2f5 (diff)
downloadscummvm-rg350-e789ab0d3b21c1c0cf76700b40f2e3c440a825a0.tar.gz
scummvm-rg350-e789ab0d3b21c1c0cf76700b40f2e3c440a825a0.tar.bz2
scummvm-rg350-e789ab0d3b21c1c0cf76700b40f2e3c440a825a0.zip
PEGASUS: Import the MMNotification classes
Diffstat (limited to 'engines/pegasus/MMShell')
-rwxr-xr-xengines/pegasus/MMShell/Notification/MMNotification.cpp99
-rwxr-xr-xengines/pegasus/MMShell/Notification/MMNotification.h85
-rwxr-xr-xengines/pegasus/MMShell/Notification/MMNotificationManager.cpp61
-rwxr-xr-xengines/pegasus/MMShell/Notification/MMNotificationManager.h58
-rwxr-xr-xengines/pegasus/MMShell/Notification/MMNotificationReceiver.cpp46
-rwxr-xr-xengines/pegasus/MMShell/Notification/MMNotificationReceiver.h53
6 files changed, 402 insertions, 0 deletions
diff --git a/engines/pegasus/MMShell/Notification/MMNotification.cpp b/engines/pegasus/MMShell/Notification/MMNotification.cpp
new file mode 100755
index 0000000000..5bc082004d
--- /dev/null
+++ b/engines/pegasus/MMShell/Notification/MMNotification.cpp
@@ -0,0 +1,99 @@
+/* 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
+ *
+ * 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/MMShell/MMConstants.h"
+#include "pegasus/MMShell/Notification/MMNotification.h"
+#include "pegasus/MMShell/Notification/MMNotificationManager.h"
+#include "pegasus/MMShell/Notification/MMNotificationReceiver.h"
+
+namespace Pegasus {
+
+typedef tReceiverList::iterator tReceiverIterator;
+
+MMNotification::MMNotification(const tNotificationID id, MMNotificationManager *owner) : MMIDObject(id) {
+ fOwner = owner;
+ fCurrentFlags = kNoNotificationFlags;
+ if (fOwner)
+ fOwner->AddNotification(this);
+}
+
+MMNotification::~MMNotification() {
+ for (tReceiverIterator it = fReceivers.begin(); it != fReceivers.end(); it++)
+ it->fReceiver->NewNotification(NULL);
+
+ if (fOwner)
+ fOwner->RemoveNotification(this);
+}
+
+// Selectively set or clear notificiation bits.
+// Wherever mask is 0, leave existing bits untouched.
+// Wherever mask is 1, set bit equivalent to flags.
+void MMNotification::NotifyMe(MMNotificationReceiver* receiver, tNotificationFlags flags, tNotificationFlags mask) {
+ for (tReceiverIterator it = fReceivers.begin(); it != fReceivers.end(); it++) {
+ if (it->fReceiver == receiver) {
+ it->fMask = (it->fMask & ~mask) | (flags & mask);
+ receiver->NewNotification(this);
+ return;
+ }
+ }
+
+ tReceiverEntry newEntry;
+ newEntry.fReceiver = receiver;
+ newEntry.fMask = flags;
+ fReceivers.push_back(newEntry);
+
+ receiver->NewNotification(this);
+}
+
+void MMNotification::CancelNotification(MMNotificationReceiver *receiver) {
+ for (tReceiverIterator it = fReceivers.begin(); it != fReceivers.end(); it++)
+ if (it->fReceiver == receiver)
+ fReceivers.erase(it);
+}
+
+void MMNotification::SetNotificationFlags(tNotificationFlags flags, tNotificationFlags mask) {
+ fCurrentFlags = (fCurrentFlags & ~mask) | flags;
+}
+
+void MMNotification::CheckReceivers() {
+ tNotificationFlags currentFlags = fCurrentFlags;
+ fCurrentFlags = kNoNotificationFlags;
+
+ for (tReceiverIterator it = fReceivers.begin(); it != fReceivers.end(); it++)
+ if (it->fMask & currentFlags)
+ it->fReceiver->ReceiveNotification(this, currentFlags);
+}
+
+// Receiver entries are equal if their receivers are equal.
+
+int operator==(const tReceiverEntry &entry1, const tReceiverEntry &entry2) {
+ return entry1.fReceiver == entry2.fReceiver;
+}
+
+int operator!=(const tReceiverEntry &entry1, const tReceiverEntry &entry2) {
+ return entry1.fReceiver != entry2.fReceiver;
+}
+
+} // End of namespace Pegasus
diff --git a/engines/pegasus/MMShell/Notification/MMNotification.h b/engines/pegasus/MMShell/Notification/MMNotification.h
new file mode 100755
index 0000000000..a47563329d
--- /dev/null
+++ b/engines/pegasus/MMShell/Notification/MMNotification.h
@@ -0,0 +1,85 @@
+/* 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
+ *
+ * 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_MMSHELL_NOTIFICATION_MMNOTIFICATION_H
+#define PEGASUS_MMSHELL_NOTIFICATION_MMNOTIFICATION_H
+
+#include "common/list.h"
+
+#include "pegasus/MMShell/MMTypes.h"
+#include "pegasus/MMShell/Utilities/MMIDObject.h"
+
+namespace Pegasus {
+
+class MMNotificationManager;
+class MMNotificationReceiver;
+
+struct tReceiverEntry {
+ MMNotificationReceiver *fReceiver;
+ tNotificationFlags fMask;
+};
+
+int operator==(const tReceiverEntry &entry1, const tReceiverEntry &entry1);
+int operator!=(const tReceiverEntry &entry1, const tReceiverEntry &entry1);
+
+typedef Common::List<tReceiverEntry> tReceiverList;
+
+/*
+ A notification can have 32 flags associated with it, which can be user-defined.
+*/
+
+class MMNotification : public MMIDObject {
+friend class MMNotificationManager;
+
+public:
+ MMNotification(const tNotificationID id, MMNotificationManager *owner);
+ virtual ~MMNotification();
+
+ // NotifyMe will have this receiver notified when any of the specified notification
+ // flags are set.
+ // If there is already a notification set for this receiver, NotifyMe does a bitwise
+ // OR with the receiver's current notification flags.
+
+ // Can selectively set or clear notification bits by using the flags and mask argument.
+
+ void NotifyMe(MMNotificationReceiver*, tNotificationFlags flags, tNotificationFlags mask);
+ void CancelNotification(MMNotificationReceiver *receiver);
+
+ void SetNotificationFlags(tNotificationFlags flags, tNotificationFlags mask);
+ tNotificationFlags GetNotificationFlags() { return fCurrentFlags; }
+
+ void ClearNotificationFlags() { SetNotificationFlags(0, ~(tNotificationFlags)0); }
+
+protected:
+ void CheckReceivers();
+
+ MMNotificationManager *fOwner;
+ tReceiverList fReceivers;
+ tNotificationFlags fCurrentFlags;
+};
+
+} // End of namespace Pegasus
+
+#endif
diff --git a/engines/pegasus/MMShell/Notification/MMNotificationManager.cpp b/engines/pegasus/MMShell/Notification/MMNotificationManager.cpp
new file mode 100755
index 0000000000..806f5c4a88
--- /dev/null
+++ b/engines/pegasus/MMShell/Notification/MMNotificationManager.cpp
@@ -0,0 +1,61 @@
+/* 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
+ *
+ * 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/MMShell/MMConstants.h"
+#include "pegasus/MMShell/Notification/MMNotificationManager.h"
+
+namespace Pegasus {
+
+typedef tNotificationList::iterator tNotificationIterator;
+
+MMNotificationManager::MMNotificationManager() {
+}
+
+MMNotificationManager::~MMNotificationManager() {
+ DetachNotifications();
+}
+
+void MMNotificationManager::AddNotification(MMNotification *notification) {
+ fNotifications.push_back(notification);
+}
+
+void MMNotificationManager::RemoveNotification(MMNotification *notification) {
+ for (tNotificationIterator it = fNotifications.begin(); it != fNotifications.end(); it++)
+ if ((*it) == notification)
+ fNotifications.erase(it);
+}
+
+void MMNotificationManager::DetachNotifications() {
+ for (tNotificationIterator it = fNotifications.begin(); it != fNotifications.end(); it++)
+ (*it)->fOwner = 0;
+}
+
+void MMNotificationManager::CheckNotifications() {
+ for (tNotificationIterator it = fNotifications.begin(); it != fNotifications.end(); it++)
+ if ((*it)->fCurrentFlags != kNoNotificationFlags)
+ (*it)->CheckReceivers();
+}
+
+} // End of namespace Pegasus
diff --git a/engines/pegasus/MMShell/Notification/MMNotificationManager.h b/engines/pegasus/MMShell/Notification/MMNotificationManager.h
new file mode 100755
index 0000000000..50af8940ec
--- /dev/null
+++ b/engines/pegasus/MMShell/Notification/MMNotificationManager.h
@@ -0,0 +1,58 @@
+/* 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
+ *
+ * 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_MMSHELL_NOTIFICATION_MMNOTIFICATIONMANAGER_H
+#define PEGASUS_MMSHELL_NOTIFICATION_MMNOTIFICATIONMANAGER_H
+
+#include "common/list.h"
+
+#include "pegasus/MMShell/Notification/MMNotificationReceiver.h"
+
+namespace Pegasus {
+
+class MMNotification;
+
+typedef Common::List<MMNotification *> tNotificationList;
+
+class MMNotificationManager : public MMNotificationReceiver {
+friend class MMNotification;
+
+public:
+ MMNotificationManager();
+ virtual ~MMNotificationManager();
+
+ void CheckNotifications();
+
+protected:
+ void AddNotification(MMNotification *notification);
+ void RemoveNotification(MMNotification *notification);
+ void DetachNotifications();
+
+ tNotificationList fNotifications;
+};
+
+} // End of namespace Pegasus
+
+#endif
diff --git a/engines/pegasus/MMShell/Notification/MMNotificationReceiver.cpp b/engines/pegasus/MMShell/Notification/MMNotificationReceiver.cpp
new file mode 100755
index 0000000000..41191b1b8e
--- /dev/null
+++ b/engines/pegasus/MMShell/Notification/MMNotificationReceiver.cpp
@@ -0,0 +1,46 @@
+/* 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
+ *
+ * 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/MMShell/Notification/MMNotificationReceiver.h"
+
+namespace Pegasus {
+
+MMNotificationReceiver::MMNotificationReceiver() {
+ fNotification = NULL;
+}
+
+MMNotificationReceiver::~MMNotificationReceiver() {
+ if (fNotification)
+ fNotification->CancelNotification(this);
+}
+
+void MMNotificationReceiver::ReceiveNotification(MMNotification *, const tNotificationFlags) {
+}
+
+void MMNotificationReceiver::NewNotification(MMNotification *notification) {
+ fNotification = notification;
+}
+
+} // End of namespace Pegasus
diff --git a/engines/pegasus/MMShell/Notification/MMNotificationReceiver.h b/engines/pegasus/MMShell/Notification/MMNotificationReceiver.h
new file mode 100755
index 0000000000..649d0cb804
--- /dev/null
+++ b/engines/pegasus/MMShell/Notification/MMNotificationReceiver.h
@@ -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
+ *
+ * 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_MMSHELL_NOTIFICATION_MMNOTIFICATIONRECEIVER_H
+#define PEGASUS_MMSHELL_NOTIFICATION_MMNOTIFICATIONRECEIVER_H
+
+#include "pegasus/MMShell/Notification/MMNotification.h"
+
+namespace Pegasus {
+
+class MMNotificationReceiver {
+friend class MMNotification;
+
+public:
+ MMNotificationReceiver();
+ virtual ~MMNotificationReceiver();
+
+protected:
+ // ReceiveNotification is called automatically whenever a notification that this
+ // receiver depends on has its flags set
+
+ virtual void ReceiveNotification(MMNotification *, const tNotificationFlags);
+ virtual void NewNotification(MMNotification *notification);
+
+private:
+ MMNotification *fNotification;
+};
+
+} // End of namespace Pegasus
+
+#endif