* Performance improvement for the deck editor when scrolling cards
  (transform 2*N*log(N)<Cmp1> + N*<read> into log(N)<Cmp1> +
  N*<read>). I expect this improvement to be much more significant,
  performance-wise, than last night's one.
This commit is contained in:
jean.chalard
2009-06-05 01:58:41 +00:00
parent c822b245c1
commit 01bd44025d
5 changed files with 21 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DamageResolverLayer.o objs/DeckDataWrapper.o objs/DeckStats.o objs/DuelLayers.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GuiCardsController.o objs/GuiLayers.o objs/Logger.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/MTGGuiHand.o objs/MTGGuiPlay.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PriceList.o objs/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/TexturesCache.o objs/Token.o objs/Translate.o objs/utils.o objs/WEvent.o
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DamageResolverLayer.o objs/DeckDataWrapper.o objs/DeckStats.o objs/DuelLayers.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GuiCardsController.o objs/GuiLayers.o objs/Logger.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/MTGGuiHand.o objs/MTGGuiPlay.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PriceList.o objs/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/TexturesCache.o objs/Token.o objs/Translate.o objs/utils.o objs/WEvent.o
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)

View File

@@ -27,7 +27,6 @@ class DeckDataWrapper{
int colors[Constants::MTG_NB_COLORS+1];
int currentColor;
map<MTGCard *, int,Cmp1> cards;
int currentposition;
MTGDeck * parent;
DeckDataWrapper(MTGDeck * deck);
@@ -38,7 +37,6 @@ class DeckDataWrapper{
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);
void updateCounts(MTGCard * card = NULL, int removed = 0);
void updateCurrentPosition(MTGCard * currentCard,int color = -1);
int getCount(int color = -1);
int totalPrice();
void save();

View File

@@ -1,9 +1,11 @@
#ifndef _EFFECTS_H_
#define _EFFECTS_H_
class Effect
{
#include <JGui.h>
class Effect : public JGuiObject
{
Effect(int id) : JGuiObject(id) {};
};
#endif // _EFFECTS_H_

View File

@@ -103,7 +103,6 @@ class GameStateDeckViewer: public GameState, public JGuiListener
}
cardIndex[0] = currentCard;
}
displayed_deck->updateCurrentPosition(cardIndex[2],colorFilter);
}
void loadIndexes(MTGCard * current = NULL){
@@ -121,9 +120,7 @@ class GameStateDeckViewer: public GameState, public JGuiListener
OutputDebugString(buf);
#endif
_current = displayed_deck->getNext(_current,colorFilter);
}
displayed_deck->updateCurrentPosition(cardIndex[2],colorFilter);
}
void switchDisplay(){
@@ -443,13 +440,26 @@ class GameStateDeckViewer: public GameState, public JGuiListener
void renderSlideBar(){
int currentPos = displayed_deck->currentposition;
int total = displayed_deck->getCount(colorFilter);
int filler = 15;
int y = SCREEN_HEIGHT-25;
int bar_size = SCREEN_WIDTH - 2*filler;
int cursor_pos = bar_size * currentPos / total;
JRenderer * r = JRenderer::GetInstance();
typedef map<MTGCard *,int,Cmp1>::reverse_iterator rit;
int currentPos = 0;
{
rit end = rit(displayed_deck->cards.begin());
rit it = rit(displayed_deck->cards.find(cardIndex[2]));
if (-1 == colorFilter)
for (; it != end; ++it)
currentPos += it->second;
else
for (; it != end; ++it)
if (it->first->hasColor(colorFilter)) currentPos += it->second;
}
int cursor_pos = bar_size * currentPos / total;
r->FillRoundRect(filler + 5,y+5,bar_size,0,3,ARGB(hudAlpha/2,0,0,0));
r->DrawLine(filler+cursor_pos + 5 ,y+5,filler+cursor_pos + 5,y+10,ARGB(hudAlpha/2,0,0,0));

View File

@@ -13,7 +13,6 @@ DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
Add(card);
}
currentposition = 0;
currentColor = -1;
}
@@ -159,19 +158,6 @@ MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){
}
}
void DeckDataWrapper::updateCurrentPosition(MTGCard * currentCard, int color){
currentposition = 0;
MTGCard * next = getNext(NULL,color);
while (next){
currentposition+=cards[next];
if (next == currentCard){
next = NULL;
}else{
next = getNext(next,color);
}
}
}
int DeckDataWrapper::getCount(int color){
if (color == -1) return colors[Constants::MTG_NB_COLORS];
return colors[color];
@@ -188,4 +174,4 @@ int DeckDataWrapper::totalPrice(){
}
delete pricelist;
return total;
}
}