diff --git a/projects/mtg/Makefile b/projects/mtg/Makefile index bb9a15013..9e950c02d 100644 --- a/projects/mtg/Makefile +++ b/projects/mtg/Makefile @@ -1,4 +1,4 @@ -OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o +OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/ObjectAnalytics.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS)) RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache) diff --git a/projects/mtg/include/CardPrimitive.h b/projects/mtg/include/CardPrimitive.h index 0d044e899..faac2c049 100644 --- a/projects/mtg/include/CardPrimitive.h +++ b/projects/mtg/include/CardPrimitive.h @@ -7,10 +7,14 @@ #include #include "ManaCost.h" +#include "ObjectAnalytics.h" using namespace std; class CardPrimitive +#ifdef TRACK_OBJECT_USAGE + : public InstanceCounter +#endif { protected: string lcname; @@ -37,6 +41,7 @@ public: vectortypes; CardPrimitive(); CardPrimitive(CardPrimitive * source); + virtual ~CardPrimitive(); void setColor(int _color, int removeAllOthers = 0); void setColor(string _color, int removeAllOthers = 0); diff --git a/projects/mtg/include/MTGCard.h b/projects/mtg/include/MTGCard.h index f7a59feaa..f61800f79 100644 --- a/projects/mtg/include/MTGCard.h +++ b/projects/mtg/include/MTGCard.h @@ -13,11 +13,16 @@ #include #include +#include "ObjectAnalytics.h" + class CardPrimitive; using namespace std; class MTGCard +#ifdef TRACK_OBJECT_USAGE + : public InstanceCounter +#endif { protected: friend class MTGSetInfo; diff --git a/projects/mtg/include/MTGCardInstance.h b/projects/mtg/include/MTGCardInstance.h index ace35bec4..5d0bcc81d 100644 --- a/projects/mtg/include/MTGCardInstance.h +++ b/projects/mtg/include/MTGCardInstance.h @@ -25,6 +25,10 @@ struct Pos; using namespace std; class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable +#ifdef TRACK_OBJECT_USAGE + , public InstanceCounter +#endif + { protected: int untapping; diff --git a/projects/mtg/include/ObjectAnalytics.h b/projects/mtg/include/ObjectAnalytics.h new file mode 100644 index 000000000..7915b6cbb --- /dev/null +++ b/projects/mtg/include/ObjectAnalytics.h @@ -0,0 +1,87 @@ +#ifndef OBJECTANALYTICS_H +#define OBJECTANALYTICS_H + +#ifdef DEBUG +#define TRACK_OBJECT_USAGE +#endif + +#ifdef TRACK_OBJECT_USAGE + +namespace ObjectAnalytics +{ + /* + ** See ObjectAnalytics.cpp for how to add additional objects to this function's dump + */ + void DumpStatistics(); +} + +#define SUPPORT_OBJECT_ANALYTICS(classname) \ +template <> unsigned int InstanceCounter::sHighWaterMark = 0; \ +template <> unsigned int InstanceCounter::sInstanceCount = 0; \ + + +/** +** Helper class for tracking object instances. +** Usage: +** class Foo +** #ifdef TRACK_OBJECT_USAGE +** : public InstanceCounter +** #endif +** +** Additionally, since the implementation uses static counters, +** somewhere in your class body, you need to put in the following macro: +** SUPPORT_OBJECT_ANALYTICS(Foo); +*/ +template +class InstanceCounter +{ +public: + InstanceCounter() + { + if (sHighWaterMark < ++sInstanceCount) + sHighWaterMark = sInstanceCount; + } + + InstanceCounter(const InstanceCounter&) + { + if (sHighWaterMark < ++sInstanceCount) + sHighWaterMark = sInstanceCount; + } + InstanceCounter& operator =(const InstanceCounter&) + { + } + + ~InstanceCounter() + { + --sInstanceCount; + } + + static unsigned int GetCurrentObjectCount() + { + return sInstanceCount; + } + + static unsigned int GetMaximumObjectCount() + { + return sHighWaterMark; + } + + static unsigned int GetCurrentByteCount() + { + return sizeof(T) * sInstanceCount; + } + + static unsigned int GetMaximumByteCount() + { + return sizeof(T) * sHighWaterMark; + } + + static unsigned int sInstanceCount; + static unsigned int sHighWaterMark; +}; + +#else +#define SUPPORT_OBJECT_ANALYTICS(classname) +#endif //TRACK_OBJECT_USAGE + +#endif //OBJECTANALYTICS_H diff --git a/projects/mtg/src/CardPrimitive.cpp b/projects/mtg/src/CardPrimitive.cpp index 5e8aee0ef..74f1fd96d 100644 --- a/projects/mtg/src/CardPrimitive.cpp +++ b/projects/mtg/src/CardPrimitive.cpp @@ -8,6 +8,8 @@ using std::string; +SUPPORT_OBJECT_ANALYTICS(CardPrimitive) + CardPrimitive::CardPrimitive() { init(); @@ -44,6 +46,10 @@ CardPrimitive::CardPrimitive(CardPrimitive * source) alias = source->alias; } +CardPrimitive::~CardPrimitive() +{ +} + int CardPrimitive::init() { basicAbilities.clear(); diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index fd8a87539..12675c7c0 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -268,6 +268,11 @@ void GameApp::LoadGameStates() void GameApp::Destroy() { LOG("==Destroying GameApp=="); + +#ifdef TRACK_OBJECT_USAGE + ObjectAnalytics::DumpStatistics(); +#endif + for (int i = GAME_STATE_MENU; i <= GAME_STATE_MAX - 1; i++) { if (mGameStates[i]) diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 0b7d68790..8e98b44c3 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -245,6 +245,10 @@ void GameStateDuel::End() { DebugTrace("Ending GameStateDuel"); +#ifdef TRACK_OBJECT_USAGE + ObjectAnalytics::DumpStatistics(); +#endif + JRenderer::GetInstance()->EnableVSync(false); if (!premadeDeck && mPlayers[0] && mPlayers[1]) { // save the stats for the game diff --git a/projects/mtg/src/MTGCard.cpp b/projects/mtg/src/MTGCard.cpp index 6262cade2..2b971092b 100644 --- a/projects/mtg/src/MTGCard.cpp +++ b/projects/mtg/src/MTGCard.cpp @@ -13,6 +13,8 @@ using std::string; +SUPPORT_OBJECT_ANALYTICS(MTGCard) + MTGCard::MTGCard() { init(); diff --git a/projects/mtg/src/MTGCardInstance.cpp b/projects/mtg/src/MTGCardInstance.cpp index d26d96e83..7d63333c5 100644 --- a/projects/mtg/src/MTGCardInstance.cpp +++ b/projects/mtg/src/MTGCardInstance.cpp @@ -14,6 +14,8 @@ using namespace std; +SUPPORT_OBJECT_ANALYTICS(MTGCardInstance) + MTGCardInstance MTGCardInstance::AnyCard = MTGCardInstance(); MTGCardInstance MTGCardInstance::NoCard = MTGCardInstance(); diff --git a/projects/mtg/src/ObjectAnalytics.cpp b/projects/mtg/src/ObjectAnalytics.cpp new file mode 100644 index 000000000..852f8e681 --- /dev/null +++ b/projects/mtg/src/ObjectAnalytics.cpp @@ -0,0 +1,38 @@ +#include "PrecompiledHeader.h" + +#include "ObjectAnalytics.h" + +#include "CardPrimitive.h" +#include "DebugRoutines.h" +#include "MTGCard.h" +#include "MTGCardInstance.h" + +namespace ObjectAnalytics +{ + void DumpStatistics() + { +#ifdef TRACK_OBJECT_USAGE + + DebugTrace("-----------------------------------------------------------"); + DebugTrace("Object Usage Stats" << std::endl); + DebugTrace("CardPrimitive current count: " << InstanceCounter::GetCurrentObjectCount()); + DebugTrace("CardPrimitive current byte usage: " << InstanceCounter::GetCurrentByteCount()); + DebugTrace("CardPrimitive max count: " << InstanceCounter::GetMaximumObjectCount()); + DebugTrace("CardPrimitive max byte usage: " << InstanceCounter::GetMaximumByteCount() << std::endl); + + DebugTrace("MTGCard current count: " << InstanceCounter::GetCurrentObjectCount()); + DebugTrace("MTGCard current byte usage: " << InstanceCounter::GetCurrentByteCount()); + DebugTrace("MTGCard max count: " << InstanceCounter::GetMaximumObjectCount()); + DebugTrace("MTGCard max byte usage: " << InstanceCounter::GetMaximumByteCount() << std::endl); + + DebugTrace("MTGCardInstance current count: " << InstanceCounter::GetCurrentObjectCount()); + DebugTrace("MTGCardInstance current byte usage: " << InstanceCounter::GetCurrentByteCount()); + DebugTrace("MTGCardInstance max count: " << InstanceCounter::GetMaximumObjectCount()); + DebugTrace("MTGCardInstance max byte usage: " << InstanceCounter::GetMaximumByteCount() << std::endl); + + DebugTrace("-----------------------------------------------------------"); + +#endif + } +} + diff --git a/projects/mtg/template.vcxproj b/projects/mtg/template.vcxproj index e9783d8ca..21db2caab 100644 --- a/projects/mtg/template.vcxproj +++ b/projects/mtg/template.vcxproj @@ -379,6 +379,7 @@ + @@ -492,6 +493,7 @@ + diff --git a/projects/mtg/template.vcxproj.filters b/projects/mtg/template.vcxproj.filters index 7a50d7447..7f6da0455 100644 --- a/projects/mtg/template.vcxproj.filters +++ b/projects/mtg/template.vcxproj.filters @@ -301,6 +301,9 @@ src + + src + @@ -624,6 +627,9 @@ inc + + inc +