Skip to content

Commit

Permalink
PEGASUS: Remove g_allItems global construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Aug 28, 2012
1 parent 81e7c9a commit f61146f
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 48 deletions.
8 changes: 3 additions & 5 deletions engines/pegasus/items/itemlist.cpp
Expand Up @@ -26,14 +26,12 @@
#include "common/error.h"
#include "common/stream.h"

#include "engines/pegasus/items/item.h"
#include "engines/pegasus/items/itemlist.h"
#include "pegasus/pegasus.h"
#include "pegasus/items/item.h"
#include "pegasus/items/itemlist.h"

namespace Pegasus {

// TODO: Don't use global construction!
ItemList g_allItems;

ItemList::ItemList() {
}

Expand Down
3 changes: 1 addition & 2 deletions engines/pegasus/items/itemlist.h
Expand Up @@ -52,8 +52,7 @@ class ItemList : public Common::List<Item *> {

typedef ItemList::iterator ItemIterator;

// TODO: Don't use global construction!
extern ItemList g_allItems;
#define g_allItems (((PegasusEngine *)g_engine)->getAllItems())

} // End of namespace Pegasus

Expand Down
8 changes: 4 additions & 4 deletions engines/pegasus/neighborhood/caldoria/caldoria.cpp
Expand Up @@ -1175,7 +1175,7 @@ void Caldoria::receiveNotification(Notification *notification, const Notificatio
arriveAt(kCaldoria27, GameState.getCurrentDirection());
break;
case kCaGTCardSwipe:
item = (InventoryItem *)g_allItems.findItemByID(kKeyCard);
item = (InventoryItem *)_vm->getAllItems().findItemByID(kKeyCard);
_vm->addItemToInventory(item);
setCurrentActivation(kActivateReadyToTransport);
break;
Expand Down Expand Up @@ -1212,7 +1212,7 @@ void Caldoria::receiveNotification(Notification *notification, const Notificatio
}
break;
case kCa53EastShootSinclair:
_vm->addItemToInventory((InventoryItem *)g_allItems.findItemByID(kStunGun));
_vm->addItemToInventory((InventoryItem *)_vm->getAllItems().findItemByID(kStunGun));
startExtraSequence(kCa53EastZoomOutFromSinclair, kExtraCompletedFlag, false);
GameState.setScoringStunnedSinclair(true);
break;
Expand Down Expand Up @@ -1769,8 +1769,8 @@ void Caldoria::openElevatorMovie() {
void Caldoria::emptyOJGlass() {
GameState.setTakenItemID(kOrangeJuiceGlassFull, false);
GameState.setTakenItemID(kOrangeJuiceGlassEmpty, true);
_vm->removeItemFromInventory((InventoryItem *)g_allItems.findItemByID(kOrangeJuiceGlassFull));
_vm->addItemToInventory((InventoryItem *)g_allItems.findItemByID(kOrangeJuiceGlassEmpty));
_vm->removeItemFromInventory((InventoryItem *)_vm->getAllItems().findItemByID(kOrangeJuiceGlassFull));
_vm->addItemToInventory((InventoryItem *)_vm->getAllItems().findItemByID(kOrangeJuiceGlassEmpty));
}

void Caldoria::doorBombTimerExpired() {
Expand Down
8 changes: 4 additions & 4 deletions engines/pegasus/neighborhood/mars/mars.cpp
Expand Up @@ -1632,7 +1632,7 @@ void Mars::activateHotspots() {
case MakeRoomView(kMars56, kEast):
switch (getCurrentActivation()) {
case kActivateReactorReadyForNitrogen:
item = (InventoryItem *)g_allItems.findItemByID(kNitrogenCanister);
item = (InventoryItem *)_vm->getAllItems().findItemByID(kNitrogenCanister);
if (item->getItemState() != kNitrogenFull)
_vm->getAllHotspots().deactivateOneHotspot(kMars57DropNitrogenSpotID);
// Fall through...
Expand Down Expand Up @@ -2151,7 +2151,7 @@ void Mars::receiveNotification(Notification *notification, const NotificationFla
}
break;
case kMarsTurnOnPod:
item = (InventoryItem *)g_allItems.findItemByID(kMarsCard);
item = (InventoryItem *)_vm->getAllItems().findItemByID(kMarsCard);
_vm->addItemToInventory(item);
GameState.setScoringTurnedOnTransport();
loadLoopSound1("");
Expand Down Expand Up @@ -2259,7 +2259,7 @@ void Mars::receiveNotification(Notification *notification, const NotificationFla
GameState.setMarsLockFrozen(false);
break;
case kMars57FreezeLock:
item = (InventoryItem *)g_allItems.findItemByID(kNitrogenCanister);
item = (InventoryItem *)_vm->getAllItems().findItemByID(kNitrogenCanister);
item->setItemState(kNitrogenEmpty);
_vm->addItemToInventory(item);
setCurrentActivation(kActivateReactorReadyForCrowBar);
Expand All @@ -2271,7 +2271,7 @@ void Mars::receiveNotification(Notification *notification, const NotificationFla
_utilityFuse.lightFuse();
break;
case kMars57BreakLock:
item = (InventoryItem *)g_allItems.findItemByID(kCrowbar);
item = (InventoryItem *)_vm->getAllItems().findItemByID(kCrowbar);
_vm->addItemToInventory(item);
GameState.setScoringUsedCrowBar();
GameState.setMarsLockBroken(true);
Expand Down
4 changes: 2 additions & 2 deletions engines/pegasus/neighborhood/neighborhood.cpp
Expand Up @@ -676,7 +676,7 @@ void Neighborhood::clickInHotspot(const Input &input, const Hotspot *clickedSpot
}

if (itemID != kNoItemID) {
Item *draggingItem = g_allItems.findItemByID(itemID);
Item *draggingItem = _vm->getAllItems().findItemByID(itemID);

if (draggingItem) {
takeItemFromRoom(draggingItem);
Expand Down Expand Up @@ -1157,7 +1157,7 @@ void Neighborhood::activateOneHotspot(HotspotInfoTable::Entry &entry, Hotspot *h
break;
default:
if ((hotspot->getHotspotFlags() & kPickUpBiochipSpotFlag) != 0) {
Item *item = g_allItems.findItemByID(entry.hotspotItem);
Item *item = _vm->getAllItems().findItemByID(entry.hotspotItem);
if (item && item->getItemNeighborhood() == getObjectID())
hotspot->setActive();
} else {
Expand Down
8 changes: 4 additions & 4 deletions engines/pegasus/neighborhood/norad/alpha/noradalpha.cpp
Expand Up @@ -136,25 +136,25 @@ void NoradAlpha::start() {
RoomID itemRoom;
DirectionConstant itemDirection;

Item *item = (Item *)g_allItems.findItemByID(kGasCanister);
Item *item = (Item *)_vm->getAllItems().findItemByID(kGasCanister);
item->getItemRoom(itemNeighborhood, itemRoom, itemDirection);

if (itemNeighborhood == getObjectID()) {
_fillingStationItem = item;
} else {
item = (Item *)g_allItems.findItemByID(kAirMask);
item = (Item *)_vm->getAllItems().findItemByID(kAirMask);
item->getItemRoom(itemNeighborhood, itemRoom, itemDirection);

if (itemNeighborhood == getObjectID()) {
_fillingStationItem = item;
} else {
item = (Item *)g_allItems.findItemByID(kNitrogenCanister);
item = (Item *)_vm->getAllItems().findItemByID(kNitrogenCanister);
item->getItemRoom(itemNeighborhood, itemRoom, itemDirection);

if (itemNeighborhood == getObjectID()) {
_fillingStationItem = item;
} else {
item = (Item *)g_allItems.findItemByID(kArgonCanister);
item = (Item *)_vm->getAllItems().findItemByID(kArgonCanister);
item->getItemRoom(itemNeighborhood, itemRoom, itemDirection);
if (itemNeighborhood == getObjectID())
_fillingStationItem = item;
Expand Down
2 changes: 1 addition & 1 deletion engines/pegasus/neighborhood/norad/delta/noraddelta.cpp
Expand Up @@ -846,7 +846,7 @@ void NoradDelta::doSolve() {

if (GameState.getCurrentRoomAndView() == MakeRoomView(kNorad68, kWest)) {
if (!_vm->playerHasItemID(kRetinalScanBiochip))
_vm->addItemToBiochips((BiochipItem *)g_allItems.findItemByID(kRetinalScanBiochip));
_vm->addItemToBiochips((BiochipItem *)_vm->getAllItems().findItemByID(kRetinalScanBiochip));

BiochipItem *biochip = _vm->getCurrentBiochip();
if (biochip != 0 && biochip->getObjectID() != kRetinalScanBiochip && g_interface)
Expand Down
10 changes: 5 additions & 5 deletions engines/pegasus/neighborhood/prehistoric/prehistoric.cpp
Expand Up @@ -284,7 +284,7 @@ void Prehistoric::turnTo(const DirectionConstant newDirection) {
break;
case MakeRoomView(kPrehistoric16, kNorth):
case MakeRoomView(kPrehistoric21, kWest):
keyCard = g_allItems.findItemByID(kKeyCard);
keyCard = _vm->getAllItems().findItemByID(kKeyCard);
if (keyCard->getItemState() == kFlashlightOff) {
keyCard->setItemState(kFlashlightOn);
playSpotSoundSync(kPrehistoricFlashlightClickIn, kPrehistoricFlashlightClickOut);
Expand All @@ -294,7 +294,7 @@ void Prehistoric::turnTo(const DirectionConstant newDirection) {
case MakeRoomView(kPrehistoric16, kWest):
case MakeRoomView(kPrehistoric21, kNorth):
case MakeRoomView(kPrehistoric21, kSouth):
keyCard = g_allItems.findItemByID(kKeyCard);
keyCard = _vm->getAllItems().findItemByID(kKeyCard);
if (keyCard->getItemState() == kFlashlightOn) {
keyCard->setItemState(kFlashlightOff);
playSpotSoundSync(kPrehistoricFlashlightClickIn, kPrehistoricFlashlightClickOut);
Expand Down Expand Up @@ -356,7 +356,7 @@ void Prehistoric::arriveAt(const RoomID room, const DirectionConstant direction)
zoomToVault();
break;
case MakeRoomView(kPrehistoric16, kNorth):
keyCard = g_allItems.findItemByID(kKeyCard);
keyCard = _vm->getAllItems().findItemByID(kKeyCard);

if (keyCard->getItemState() == kFlashlightOff) {
keyCard->setItemState(kFlashlightOn);
Expand All @@ -383,7 +383,7 @@ void Prehistoric::arriveAt(const RoomID room, const DirectionConstant direction)
case MakeRoomView(kPrehistoric19, kNorth):
case MakeRoomView(kPrehistoric20, kNorth):
case MakeRoomView(kPrehistoric21, kEast):
keyCard = g_allItems.findItemByID(kKeyCard);
keyCard = _vm->getAllItems().findItemByID(kKeyCard);

if (keyCard->getItemState() == kFlashlightOn) {
keyCard->setItemState(kFlashlightOff);
Expand Down Expand Up @@ -554,7 +554,7 @@ void Prehistoric::receiveNotification(Notification *notification, const Notifica
break;
case kPre25EastUnlockingVaultNoLog:
case kPre25EastUnlockingVaultWithLog:
_vm->addItemToInventory((InventoryItem *)g_allItems.findItemByID(kJourneymanKey));
_vm->addItemToInventory((InventoryItem *)_vm->getAllItems().findItemByID(kJourneymanKey));
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions engines/pegasus/neighborhood/tsa/fulltsa.cpp
Expand Up @@ -1108,7 +1108,7 @@ void FullTSA::pickedUpItem(Item *item) {
GameState.setScoringGotJourneymanKey(true);
break;
case kPegasusBiochip:
biochip = (BiochipItem *)g_allItems.findItemByID(kMapBiochip);
biochip = (BiochipItem *)_vm->getAllItems().findItemByID(kMapBiochip);
_vm->addItemToBiochips(biochip);
GameState.setScoringGotPegasusBiochip(true);
break;
Expand Down Expand Up @@ -2373,7 +2373,7 @@ void FullTSA::receiveNotification(Notification *notification, const Notification

switch (lastExtra) {
case kTSAGTCardSwipe:
item = (InventoryItem *)g_allItems.findItemByID(kKeyCard);
item = (InventoryItem *)_vm->getAllItems().findItemByID(kKeyCard);
_vm->addItemToInventory(item);
setCurrentActivation(kActivateTSAReadyToTransport);
break;
Expand Down
16 changes: 8 additions & 8 deletions engines/pegasus/neighborhood/wsc/wsc.cpp
Expand Up @@ -1098,7 +1098,7 @@ void WSC::closeDoorOffScreen(const RoomID room, const DirectionConstant) {
case kWSC82:
case kWSC92:
case kWSC93:
keyCard = g_allItems.findItemByID(kKeyCard);
keyCard = _vm->getAllItems().findItemByID(kKeyCard);
if (keyCard->getItemState() == kFlashlightOn && (GameState.getCurrentRoom() == kWSC81 ||
GameState.getCurrentRoom() == kWSC93)) {
keyCard->setItemState(kFlashlightOff);
Expand Down Expand Up @@ -1166,11 +1166,11 @@ void WSC::doorOpened() {

switch (GameState.getCurrentRoomAndView()) {
case MakeRoomView(kWSC42, kEast):
_vm->addItemToInventory((InventoryItem *)g_allItems.findItemByID(kSinclairKey));
_vm->addItemToInventory((InventoryItem *)_vm->getAllItems().findItemByID(kSinclairKey));
break;
case MakeRoomView(kWSC58, kSouth):
GameState.setScoringUsedCrowBarInWSC();
_vm->addItemToInventory((InventoryItem *)g_allItems.findItemByID(kCrowbar));
_vm->addItemToInventory((InventoryItem *)_vm->getAllItems().findItemByID(kCrowbar));
break;
case MakeRoomView(kWSC06, kNorth):
case MakeRoomView(kWSC79, kWest):
Expand Down Expand Up @@ -1663,7 +1663,7 @@ void WSC::receiveNotification(Notification *notification, const NotificationFlag
makeContinuePoint();
break;
case kWSCDartScan2:
_vm->addItemToInventory((InventoryItem *)g_allItems.findItemByID(kPoisonDart));
_vm->addItemToInventory((InventoryItem *)_vm->getAllItems().findItemByID(kPoisonDart));
GameState.setScoringRemovedDart();
GameState.setWSCRemovedDart(true);
setUpPoison();
Expand Down Expand Up @@ -1915,7 +1915,7 @@ void WSC::receiveNotification(Notification *notification, const NotificationFlag
//g_AIArea->playAIMovie(kRightAreaSignature, "Images/AI/WSC/XN59WD", false, kWarningInterruption);
break;
case kW98RobotGassed:
item = (Item *)g_allItems.findItemByID(kArgonCanister);
item = (Item *)_vm->getAllItems().findItemByID(kArgonCanister);
_vm->addItemToInventory((InventoryItem *)item);
setCurrentActivation(kActivationRobotDead);
GameState.setWSCRobotDead(true);
Expand Down Expand Up @@ -2112,7 +2112,7 @@ void WSC::activateOneHotspot(HotspotInfoTable::Entry &entry, Hotspot *hotspot) {
hotspot->setActive();
break;
case kW98DropArgonSpotID:
argonCanister = g_allItems.findItemByID(kArgonCanister);
argonCanister = _vm->getAllItems().findItemByID(kArgonCanister);
if (argonCanister->getItemState() != kArgonFull)
hotspot->setInactive();
break;
Expand Down Expand Up @@ -2342,9 +2342,9 @@ void WSC::pickedUpItem(Item *item) {
break;
case kArgonPickup:
_vm->removeItemFromInventory((InventoryItem *)item);
item = (Item *)g_allItems.findItemByID(kArgonCanister);
item = (Item *)_vm->getAllItems().findItemByID(kArgonCanister);
_vm->addItemToInventory((InventoryItem *)item);
item = (Item *)g_allItems.findItemByID(kSinclairKey);
item = (Item *)_vm->getAllItems().findItemByID(kSinclairKey);
_vm->addItemToInventory((InventoryItem *)item);
_vm->getAllHotspots().setHotspotRect(kWSC02SouthMorphOutSpotID,
Common::Rect(kNavAreaLeft, kNavAreaTop, 512 + kNavAreaLeft, 256 + kNavAreaTop));
Expand Down
22 changes: 11 additions & 11 deletions engines/pegasus/pegasus.cpp
Expand Up @@ -470,14 +470,14 @@ bool PegasusEngine::loadFromStream(Common::ReadStream *stream) {
setEnergyDeathReason(stream->readByte());

// Items
g_allItems.readFromStream(stream);
_allItems.readFromStream(stream);

// Inventory
byte itemCount = stream->readByte();

if (itemCount > 0) {
for (byte i = 0; i < itemCount; i++) {
InventoryItem *inv = (InventoryItem *)g_allItems.findItemByID((ItemID)stream->readUint16BE());
InventoryItem *inv = (InventoryItem *)_allItems.findItemByID((ItemID)stream->readUint16BE());
addItemToInventory(inv);
}

Expand All @@ -489,7 +489,7 @@ bool PegasusEngine::loadFromStream(Common::ReadStream *stream) {

if (biochipCount > 0) {
for (byte i = 0; i < biochipCount; i++) {
BiochipItem *biochip = (BiochipItem *)g_allItems.findItemByID((ItemID)stream->readUint16BE());
BiochipItem *biochip = (BiochipItem *)_allItems.findItemByID((ItemID)stream->readUint16BE());
addItemToBiochips(biochip);
}

Expand Down Expand Up @@ -541,7 +541,7 @@ bool PegasusEngine::writeToStream(Common::WriteStream *stream, int saveType) {
stream->writeByte(getEnergyDeathReason());

// Items
g_allItems.writeToStream(stream);
_allItems.writeToStream(stream);

// Inventory
byte itemCount = _items.getNumItems();
Expand Down Expand Up @@ -1392,7 +1392,7 @@ bool PegasusEngine::itemInLocation(const ItemID itemID, const NeighborhoodID nei
RoomID itemRoom;
DirectionConstant itemDirection;

Item *item = g_allItems.findItemByID(itemID);
Item *item = _allItems.findItemByID(itemID);
item->getItemRoom(itemNeighborhood, itemRoom, itemDirection);

return itemNeighborhood == neighborhood && itemRoom == room && itemDirection == direction;
Expand Down Expand Up @@ -1503,17 +1503,17 @@ void PegasusEngine::startNewGame() {
removeAllItemsFromInventory();
removeAllItemsFromBiochips();

BiochipItem *biochip = (BiochipItem *)g_allItems.findItemByID(kAIBiochip);
BiochipItem *biochip = (BiochipItem *)_allItems.findItemByID(kAIBiochip);
addItemToBiochips(biochip);

if (isDemo()) {
biochip = (BiochipItem *)g_allItems.findItemByID(kPegasusBiochip);
biochip = (BiochipItem *)_allItems.findItemByID(kPegasusBiochip);
addItemToBiochips(biochip);
biochip = (BiochipItem *)g_allItems.findItemByID(kMapBiochip);
biochip = (BiochipItem *)_allItems.findItemByID(kMapBiochip);
addItemToBiochips(biochip);
InventoryItem *item = (InventoryItem *)g_allItems.findItemByID(kKeyCard);
InventoryItem *item = (InventoryItem *)_allItems.findItemByID(kKeyCard);
addItemToInventory(item);
item = (InventoryItem *)g_allItems.findItemByID(kJourneymanKey);
item = (InventoryItem *)_allItems.findItemByID(kJourneymanKey);
addItemToInventory(item);
_currentItemID = kJourneymanKey;
} else {
Expand Down Expand Up @@ -2154,7 +2154,7 @@ void PegasusEngine::drawScaledFrame(const Graphics::Surface *frame, uint16 x, ui
}

void PegasusEngine::destroyInventoryItem(const ItemID itemID) {
InventoryItem *item = (InventoryItem *)g_allItems.findItemByID(itemID);
InventoryItem *item = (InventoryItem *)_allItems.findItemByID(itemID);

ItemExtraEntry entry;

Expand Down
2 changes: 2 additions & 0 deletions engines/pegasus/pegasus.h
Expand Up @@ -132,6 +132,7 @@ friend class InputHandler;
void setAmbienceLevel(uint16);

// Items
ItemList &getAllItems() { return _allItems; }
bool playerHasItem(const Item *);
bool playerHasItemID(const ItemID);
void checkFlashlight();
Expand Down Expand Up @@ -228,6 +229,7 @@ friend class InputHandler;
void giveIdleTime();

// Items
ItemList _allItems;
void createItems();
void createItem(ItemID itemID, NeighborhoodID neighborhoodID, RoomID roomID, DirectionConstant direction);
Inventory _items;
Expand Down

0 comments on commit f61146f

Please sign in to comment.