More theoretical fixes to the scroller. I didn't repro this on win, but I had a couple of cases on my psp - I suspect that the missing reset on the currentID counter was causing problems should the task list shrink after a duel. Also added a modulus calculation to make sure that we never go outside the bounds of the string vector.

This commit is contained in:
wrenczes
2010-11-08 09:26:21 +00:00
parent 52a2823f7b
commit eec0c5b717
+4 -2
View File
@@ -39,6 +39,7 @@ void TextScroller::Add(string text){
void TextScroller::Reset(){ void TextScroller::Reset(){
strings.clear(); strings.clear();
currentId = 0;
} }
void TextScroller::Update(float dt){ void TextScroller::Update(float dt){
@@ -54,7 +55,7 @@ void TextScroller::Update(float dt){
currentId = (rand() % strings.size()); currentId = (rand() % strings.size());
}else{ }else{
currentId++; currentId++;
if (currentId > strings.size()-1)currentId = 0; if (currentId >= strings.size())currentId = 0;
} }
mText = strings[currentId]; mText = strings[currentId];
} }
@@ -68,7 +69,8 @@ void TextScroller::Update(float dt){
size_t nbItemsToDisplay = ( minimumItems < strings.size() ? minimumItems : strings.size()); size_t nbItemsToDisplay = ( minimumItems < strings.size() ? minimumItems : strings.size());
for ( size_t idx = 0; idx < nbItemsToDisplay; ++idx) for ( size_t idx = 0; idx < nbItemsToDisplay; ++idx)
{ {
scrollerText << strings[currentId + idx]; size_t index = (currentId + idx) % strings.size();
scrollerText << strings[index];
} }
currentId++; currentId++;
if ( currentId >= strings.size()) if ( currentId >= strings.size())