From 593aec681d138f7106b034530f5b5eb89643bce1 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 5 Sep 2011 16:46:00 -0400 Subject: PEGASUS: Restructure remaining MMShell code into the base code MMTimeValue has been removed, as Common::Timestamp will just be used instead --- .../pegasus/MMShell/Base_Classes/MMFunctionPtr.cpp | 48 ---------- .../pegasus/MMShell/Base_Classes/MMFunctionPtr.h | 51 ----------- engines/pegasus/MMShell/Utilities/MMIDObject.h | 68 -------------- engines/pegasus/MMShell/Utilities/MMTimeValue.cpp | 60 ------------- engines/pegasus/MMShell/Utilities/MMTimeValue.h | 52 ----------- engines/pegasus/MMShell/Utilities/MMUtilities.cpp | 63 ------------- engines/pegasus/MMShell/Utilities/MMUtilities.h | 43 --------- engines/pegasus/hotspot.cpp | 2 +- engines/pegasus/hotspot.h | 4 +- engines/pegasus/items/item.cpp | 2 +- engines/pegasus/items/item.h | 4 +- engines/pegasus/module.mk | 4 +- engines/pegasus/neighborhood/neighborhood.cpp | 2 +- engines/pegasus/neighborhood/neighborhood.h | 4 +- engines/pegasus/notification.cpp | 2 +- engines/pegasus/notification.h | 4 +- engines/pegasus/util.cpp | 100 +++++++++++++++++++++ engines/pegasus/util.h | 72 +++++++++++++++ 18 files changed, 185 insertions(+), 400 deletions(-) delete mode 100755 engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.cpp delete mode 100755 engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.h delete mode 100755 engines/pegasus/MMShell/Utilities/MMIDObject.h delete mode 100755 engines/pegasus/MMShell/Utilities/MMTimeValue.cpp delete mode 100755 engines/pegasus/MMShell/Utilities/MMTimeValue.h delete mode 100755 engines/pegasus/MMShell/Utilities/MMUtilities.cpp delete mode 100755 engines/pegasus/MMShell/Utilities/MMUtilities.h create mode 100755 engines/pegasus/util.cpp create mode 100755 engines/pegasus/util.h (limited to 'engines/pegasus') diff --git a/engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.cpp b/engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.cpp deleted file mode 100755 index 9a2543db7b..0000000000 --- a/engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.cpp +++ /dev/null @@ -1,48 +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. - * - * 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/MMShell/Base_Classes/MMFunctionPtr.h" - -namespace Pegasus { - -MMFunctionPtr::MMFunctionPtr() { - fTheFunction = 0; - fFunctionArg = 0; -} - -MMFunctionPtr::~MMFunctionPtr() { -} - -void MMFunctionPtr::SetFunctionPtr(tFunctionPtr theFunction, void *functionArg) { - fTheFunction = theFunction; - fFunctionArg = functionArg; -} - -void MMFunctionPtr::CallFunction() { - if (fTheFunction != 0) - (*fTheFunction)(this, fFunctionArg); -} - -} // End of namespace Pegasus diff --git a/engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.h b/engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.h deleted file mode 100755 index 4aa18cac81..0000000000 --- a/engines/pegasus/MMShell/Base_Classes/MMFunctionPtr.h +++ /dev/null @@ -1,51 +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. - * - * 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_MMSHELL_BASECLASSES_MMFUNCTIONPTR_H -#define PEGASUS_MMSHELL_BASECLASSES_MMFUNCTIONPTR_H - -namespace Pegasus { - -class MMFunctionPtr; - -typedef void (*tFunctionPtr)(MMFunctionPtr *theFunction, void *functionArg); - -class MMFunctionPtr { -public: - MMFunctionPtr(); - virtual ~MMFunctionPtr(); - - void SetFunctionPtr(tFunctionPtr theFunction, void *functionArg); - -protected: - void CallFunction(); - - tFunctionPtr fTheFunction; - void *fFunctionArg; -}; - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/MMShell/Utilities/MMIDObject.h b/engines/pegasus/MMShell/Utilities/MMIDObject.h deleted file mode 100755 index 112d3b8275..0000000000 --- a/engines/pegasus/MMShell/Utilities/MMIDObject.h +++ /dev/null @@ -1,68 +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. - * - * 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_MMSHELL_MMIDOBJECT_H -#define PEGASUS_MMSHELL_MMIDOBJECT_H - -#include "pegasus/types.h" - -namespace Pegasus { - -class MMIDObject { -friend inline int operator==(const MMIDObject &arg1, const MMIDObject &arg1); -friend inline int operator!=(const MMIDObject &arg2, const MMIDObject &arg2); - -public: - MMIDObject(const tMM32BitID id); - ~MMIDObject(); - - tMM32BitID getObjectID() const; - -private: - tMM32BitID _objectID; -}; - -inline MMIDObject::MMIDObject(const tMM32BitID id) { - _objectID = id; -} - -inline MMIDObject::~MMIDObject() { -} - -inline tMM32BitID MMIDObject::getObjectID() const { - return _objectID; -} - -inline int operator==(const MMIDObject &arg1, const MMIDObject &arg2) { - return arg1._objectID == arg2._objectID; -} - -inline int operator!=(const MMIDObject &arg1, const MMIDObject &arg2) { - return arg1._objectID != arg2._objectID; -} - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/MMShell/Utilities/MMTimeValue.cpp b/engines/pegasus/MMShell/Utilities/MMTimeValue.cpp deleted file mode 100755 index 92971a6636..0000000000 --- a/engines/pegasus/MMShell/Utilities/MMTimeValue.cpp +++ /dev/null @@ -1,60 +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. - * - * 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/constants.h" -#include "pegasus/MMShell/Utilities/MMTimeValue.h" - -namespace Pegasus { - -MMTimeValue::MMTimeValue() { - fTheTime = 0; - fTheScale = kDefaultTimeScale; -} - -TimeValue MMTimeValue::GetTime() const { - return fTheTime; -} - -void MMTimeValue::GetTime(TimeValue &time, const TimeScale scale) const { - time = fTheTime * fTheScale / scale; -} - -void MMTimeValue::SetTime(const TimeValue time) { - fTheTime = time; -} - -void MMTimeValue::SetTime(const TimeValue time, const TimeScale scale) { - fTheTime = time * scale / fTheScale; -} - -TimeScale MMTimeValue::GetScale() const { - return fTheScale; -} - -void MMTimeValue::SetScale(const TimeScale scale) { - fTheScale = scale; -} - -} // End of namespace Pegasus diff --git a/engines/pegasus/MMShell/Utilities/MMTimeValue.h b/engines/pegasus/MMShell/Utilities/MMTimeValue.h deleted file mode 100755 index a112f9c233..0000000000 --- a/engines/pegasus/MMShell/Utilities/MMTimeValue.h +++ /dev/null @@ -1,52 +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. - * - * 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_MMSHELL_MMTIMEVALUE_H -#define PEGASUS_MMSHELL_MMTIMEVALUE_H - -#include "pegasus/types.h" - -namespace Pegasus { - -class MMTimeValue { -public: - MMTimeValue(); - - TimeValue GetTime() const; - void GetTime(TimeValue &time, const TimeScale scale) const; - void SetTime(const TimeValue time); - void SetTime(const TimeValue time, const TimeScale scale); - - TimeScale GetScale() const; - void SetScale(const TimeScale scale); - -protected: - TimeValue fTheTime; - TimeScale fTheScale; -}; - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/MMShell/Utilities/MMUtilities.cpp b/engines/pegasus/MMShell/Utilities/MMUtilities.cpp deleted file mode 100755 index e6bd146a08..0000000000 --- a/engines/pegasus/MMShell/Utilities/MMUtilities.cpp +++ /dev/null @@ -1,63 +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. - * - * 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 "common/random.h" -#include "common/util.h" - -#include "pegasus/MMShell/Utilities/MMUtilities.h" - -namespace Pegasus { - -inline int32 Round(const int32 a, const int32 b) { - if (b < 0) - if (a < 0) - return -((a - (-b >> 1)) / -b); - else - return -((a + (-b >> 1)) / -b); - else - if (a < 0) - return (a - (b >> 1)) / b; - else - return (a + (b >> 1)) / b; -} - -int32 LinearInterp(const int32 start1, const int32 stop1, const int32 current1, const int32 start2, const int32 stop2) { - if (start2 == stop2) - return start2; - else - return start2 + Round((current1 - start1) * (stop2 - start2), (stop1 - start1)); -} - -void ShuffleArray(int32 *arr, int32 count, Common::RandomSource &random) { - if (count > 1) { - for (int32 i = 1; i < count; ++i) { - int32 j = random.getRandomNumber(i); - if (j != i) - SWAP(arr[i], arr[j]); - } - } -} - -} // End of namespace Pegasus diff --git a/engines/pegasus/MMShell/Utilities/MMUtilities.h b/engines/pegasus/MMShell/Utilities/MMUtilities.h deleted file mode 100755 index d5f7e541de..0000000000 --- a/engines/pegasus/MMShell/Utilities/MMUtilities.h +++ /dev/null @@ -1,43 +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. - * - * 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_MMSHELL_UTILITIES_MMUTILITIES_H -#define PEGASUS_MMSHELL_UTILITIES_MMUTILITIES_H - -#include "common/scummsys.h" - -namespace Common { - class RandomSource; -} - -namespace Pegasus { - -int32 LinearInterp(const int32 start1, const int32 stop1, const int32 current1, const int32 start2, const int32 stop2); - -void ShuffleArray(int32 *arr, int32 count, Common::RandomSource &random); - -} // End of namespace Pegasus - -#endif diff --git a/engines/pegasus/hotspot.cpp b/engines/pegasus/hotspot.cpp index f97ad1d290..58ca353831 100755 --- a/engines/pegasus/hotspot.cpp +++ b/engines/pegasus/hotspot.cpp @@ -29,7 +29,7 @@ namespace Pegasus { HotspotList g_allHotspots; -Hotspot::Hotspot(const tHotSpotID id) : MMIDObject(id) { +Hotspot::Hotspot(const tHotSpotID id) : IDObject(id) { _spotFlags = kNoHotSpotFlags; _spotActive = false; } diff --git a/engines/pegasus/hotspot.h b/engines/pegasus/hotspot.h index 97bbf37832..d5a2fb0f6f 100755 --- a/engines/pegasus/hotspot.h +++ b/engines/pegasus/hotspot.h @@ -31,7 +31,7 @@ #include "pegasus/constants.h" #include "pegasus/types.h" -#include "pegasus/MMShell/Utilities/MMIDObject.h" +#include "pegasus/util.h" /* @@ -46,7 +46,7 @@ namespace Pegasus { -class Hotspot : public MMIDObject { +class Hotspot : public IDObject { public: Hotspot(const tHotSpotID); virtual ~Hotspot(); diff --git a/engines/pegasus/items/item.cpp b/engines/pegasus/items/item.cpp index 2043317f5f..cdd81293cc 100755 --- a/engines/pegasus/items/item.cpp +++ b/engines/pegasus/items/item.cpp @@ -33,7 +33,7 @@ namespace Pegasus { -Item::Item(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) : MMIDObject(id) { +Item::Item(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction) : IDObject(id) { _itemNeighborhood = neighborhood; _itemRoom = room; _itemDirection = direction; diff --git a/engines/pegasus/items/item.h b/engines/pegasus/items/item.h index 517ffc0c6e..f623df5a4b 100755 --- a/engines/pegasus/items/item.h +++ b/engines/pegasus/items/item.h @@ -28,8 +28,8 @@ #include "common/endian.h" -#include "pegasus/MMShell/Utilities/MMIDObject.h" #include "pegasus/types.h" +#include "pegasus/util.h" namespace Common { class Error; @@ -285,7 +285,7 @@ enum tItemType { */ -class Item : public MMIDObject { +class Item : public IDObject { public: Item(const tItemID id, const tNeighborhoodID neighborhood, const tRoomID room, const tDirectionConstant direction); virtual ~Item(); diff --git a/engines/pegasus/module.mk b/engines/pegasus/module.mk index d3bcbcb500..5b8898ff85 100644 --- a/engines/pegasus/module.mk +++ b/engines/pegasus/module.mk @@ -12,15 +12,13 @@ MODULE_OBJS = \ overview.o \ pegasus.o \ sound.o \ + util.o \ video.o \ items/inventory.o \ items/item.o \ items/itemlist.o \ items/biochips/biochipitem.o \ items/inventory/inventoryitem.o \ - MMShell/Base_Classes/MMFunctionPtr.o \ - MMShell/Utilities/MMTimeValue.o \ - MMShell/Utilities/MMUtilities.o \ neighborhood/door.o \ neighborhood/exit.o \ neighborhood/extra.o \ diff --git a/engines/pegasus/neighborhood/neighborhood.cpp b/engines/pegasus/neighborhood/neighborhood.cpp index 8048fa4240..39efda35e5 100644 --- a/engines/pegasus/neighborhood/neighborhood.cpp +++ b/engines/pegasus/neighborhood/neighborhood.cpp @@ -32,7 +32,7 @@ namespace Pegasus { -Neighborhood::Neighborhood(PegasusEngine *vm, const Common::String &resName, tNeighborhoodID id) : MMIDObject(id), _vm(vm), _resName(resName) { +Neighborhood::Neighborhood(PegasusEngine *vm, const Common::String &resName, tNeighborhoodID id) : IDObject(id), _vm(vm), _resName(resName) { GameState.setOpenDoorLocation(kNoRoomID, kNoDirection); _currentAlternate = 0; _interruptionFilter = kFilterAllInput; diff --git a/engines/pegasus/neighborhood/neighborhood.h b/engines/pegasus/neighborhood/neighborhood.h index d567a5b3d3..baeed7d124 100644 --- a/engines/pegasus/neighborhood/neighborhood.h +++ b/engines/pegasus/neighborhood/neighborhood.h @@ -32,7 +32,7 @@ #include "pegasus/hotspot.h" #include "pegasus/notification.h" #include "pegasus/sound.h" -#include "pegasus/MMShell/Utilities/MMIDObject.h" +#include "pegasus/util.h" #include "pegasus/neighborhood/door.h" #include "pegasus/neighborhood/exit.h" #include "pegasus/neighborhood/extra.h" @@ -84,7 +84,7 @@ bool operator!=(const tQueueRequest &arg1, const tQueueRequest &arg2); typedef Common::Queue NeighborhoodActionQueue; -class Neighborhood : public MMIDObject, public NotificationReceiver { +class Neighborhood : public IDObject, public NotificationReceiver { public: Neighborhood(PegasusEngine *vm, const Common::String &resName, tNeighborhoodID id); virtual ~Neighborhood(); diff --git a/engines/pegasus/notification.cpp b/engines/pegasus/notification.cpp index f03e4705b7..9725cfbe1e 100755 --- a/engines/pegasus/notification.cpp +++ b/engines/pegasus/notification.cpp @@ -30,7 +30,7 @@ namespace Pegasus { typedef tReceiverList::iterator tReceiverIterator; -Notification::Notification(const tNotificationID id, NotificationManager *owner) : MMIDObject(id) { +Notification::Notification(const tNotificationID id, NotificationManager *owner) : IDObject(id) { _owner = owner; _currentFlags = kNoNotificationFlags; if (_owner) diff --git a/engines/pegasus/notification.h b/engines/pegasus/notification.h index d276f456ad..ded66478fc 100755 --- a/engines/pegasus/notification.h +++ b/engines/pegasus/notification.h @@ -29,7 +29,7 @@ #include "common/list.h" #include "pegasus/types.h" -#include "pegasus/MMShell/Utilities/MMIDObject.h" +#include "pegasus/util.h" namespace Pegasus { @@ -50,7 +50,7 @@ typedef Common::List tReceiverList; A notification can have 32 flags associated with it, which can be user-defined. */ -class Notification : public MMIDObject { +class Notification : public IDObject { friend class NotificationManager; public: diff --git a/engines/pegasus/util.cpp b/engines/pegasus/util.cpp new file mode 100755 index 0000000000..a4c9a351c2 --- /dev/null +++ b/engines/pegasus/util.cpp @@ -0,0 +1,100 @@ +/* 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 "common/random.h" +#include "common/util.h" + +#include "pegasus/util.h" + +namespace Pegasus { + +IDObject::IDObject(const tMM32BitID id) { + _objectID = id; +} + +IDObject::~IDObject() { +} + +tMM32BitID IDObject::getObjectID() const { + return _objectID; +} + +int operator==(const IDObject &arg1, const IDObject &arg2) { + return arg1.getObjectID() == arg2.getObjectID(); +} + +int operator!=(const IDObject &arg1, const IDObject &arg2) { + return arg1.getObjectID() != arg2.getObjectID(); +} + +FunctionPtr::FunctionPtr() { + _function = 0; + _functionArg = 0; +} + +FunctionPtr::~FunctionPtr() { +} + +void FunctionPtr::setFunctionPtr(tFunctionPtr function, void *functionArg) { + _function = function; + _functionArg = functionArg; +} + +void FunctionPtr::callFunction() { + if (_function != 0) + (*_function)(this, _functionArg); +} + +inline int32 pegasusRound(const int32 a, const int32 b) { + if (b < 0) + if (a < 0) + return -((a - (-b >> 1)) / -b); + else + return -((a + (-b >> 1)) / -b); + else + if (a < 0) + return (a - (b >> 1)) / b; + else + return (a + (b >> 1)) / b; +} + +int32 linearInterp(const int32 start1, const int32 stop1, const int32 current1, const int32 start2, const int32 stop2) { + if (start2 == stop2) + return start2; + else + return start2 + pegasusRound((current1 - start1) * (stop2 - start2), (stop1 - start1)); +} + +void shuffleArray(int32 *arr, int32 count, Common::RandomSource &random) { + if (count > 1) { + for (int32 i = 1; i < count; ++i) { + int32 j = random.getRandomNumber(i); + if (j != i) + SWAP(arr[i], arr[j]); + } + } +} + +} // End of namespace Pegasus diff --git a/engines/pegasus/util.h b/engines/pegasus/util.h new file mode 100755 index 0000000000..83c0c33324 --- /dev/null +++ b/engines/pegasus/util.h @@ -0,0 +1,72 @@ +/* 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_MMSHELL_MMIDOBJECT_H +#define PEGASUS_MMSHELL_MMIDOBJECT_H + +#include "pegasus/types.h" + +namespace Common { + class RandomSource; +} + +namespace Pegasus { + +class IDObject { +public: + IDObject(const tMM32BitID id); + ~IDObject(); + + tMM32BitID getObjectID() const; + +private: + tMM32BitID _objectID; +}; + +class FunctionPtr; + +typedef void (*tFunctionPtr)(FunctionPtr *theFunction, void *functionArg); + +class FunctionPtr { +public: + FunctionPtr(); + virtual ~FunctionPtr(); + + void setFunctionPtr(tFunctionPtr function, void *functionArg); + +protected: + void callFunction(); + + tFunctionPtr _function; + void *_functionArg; +}; + +int32 linearInterp(const int32 start1, const int32 stop1, const int32 current1, const int32 start2, const int32 stop2); + +void shuffleArray(int32 *arr, int32 count, Common::RandomSource &random); + +} // End of namespace Pegasus + +#endif -- cgit v1.2.3