Jeck - Card ID collisions, cache fixes, cache deleted pooling.
* mtgid now defaults to 0. * TextScroller will not update when empty. * Cache now moves WCachedResources we're finished with to a garbage pool for later use (to reduce memory fragmentation). * Demo still crashes... but I'm thinking that has to do with fragmentation, not a leak?
This commit is contained in:
@@ -1,66 +1,68 @@
|
||||
#include "../include/TextScroller.h"
|
||||
|
||||
#include <JLBFont.h>
|
||||
|
||||
TextScroller::TextScroller(JLBFont * font, float x, float y, float width, float speed):JGuiObject(0){
|
||||
mFont = font;
|
||||
mWidth = width;
|
||||
mSpeed = speed;
|
||||
mX = x;
|
||||
mY = y;
|
||||
start = -width;
|
||||
timer = 0;
|
||||
currentId = 0;
|
||||
mRandom = 0;
|
||||
}
|
||||
|
||||
void TextScroller::setRandom(int mode){
|
||||
mRandom = mode;
|
||||
if (mRandom && strings.size()){
|
||||
currentId = (rand() % strings.size());
|
||||
mText = strings[currentId];
|
||||
}
|
||||
}
|
||||
|
||||
void TextScroller::Add(string text){
|
||||
if (!strings.size()) mText = text;
|
||||
strings.push_back(text);
|
||||
}
|
||||
|
||||
void TextScroller::Reset(){
|
||||
strings.clear();
|
||||
}
|
||||
|
||||
void TextScroller::Update(float dt){
|
||||
start+=mSpeed*dt;
|
||||
if (start > mFont->GetStringWidth(mText.c_str())){
|
||||
start = -mWidth;
|
||||
if (mRandom){
|
||||
currentId = (rand() % strings.size());
|
||||
}else{
|
||||
currentId++;
|
||||
if (currentId > strings.size()-1)currentId = 0;
|
||||
}
|
||||
mText = strings[currentId];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TextScroller::Render(){
|
||||
mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth);
|
||||
}
|
||||
|
||||
ostream& TextScroller::toString(ostream& out) const
|
||||
{
|
||||
return out << "TextScroller ::: mText : " << mText
|
||||
<< " ; tempText : " << tempText
|
||||
<< " ; mFont : " << mFont
|
||||
<< " ; mWidth : " << mWidth
|
||||
<< " ; mSpeed : " << mSpeed
|
||||
<< " ; mX,mY : " << mX << "," << mY
|
||||
<< " ; start : " << start
|
||||
<< " ; timer : " << timer
|
||||
<< " ; strings : ?" // << strings
|
||||
<< " ; currentId : " << currentId
|
||||
<< " ; mRandom : " << mRandom;
|
||||
}
|
||||
#include "../include/TextScroller.h"
|
||||
|
||||
#include <JLBFont.h>
|
||||
|
||||
TextScroller::TextScroller(JLBFont * font, float x, float y, float width, float speed):JGuiObject(0){
|
||||
mFont = font;
|
||||
mWidth = width;
|
||||
mSpeed = speed;
|
||||
mX = x;
|
||||
mY = y;
|
||||
start = -width;
|
||||
timer = 0;
|
||||
currentId = 0;
|
||||
mRandom = 0;
|
||||
}
|
||||
|
||||
void TextScroller::setRandom(int mode){
|
||||
mRandom = mode;
|
||||
if (mRandom && strings.size()){
|
||||
currentId = (rand() % strings.size());
|
||||
mText = strings[currentId];
|
||||
}
|
||||
}
|
||||
|
||||
void TextScroller::Add(string text){
|
||||
if (!strings.size()) mText = text;
|
||||
strings.push_back(text);
|
||||
}
|
||||
|
||||
void TextScroller::Reset(){
|
||||
strings.clear();
|
||||
}
|
||||
|
||||
void TextScroller::Update(float dt){
|
||||
if(!strings.size())
|
||||
return;
|
||||
start+=mSpeed*dt;
|
||||
if (start > mFont->GetStringWidth(mText.c_str())){
|
||||
start = -mWidth;
|
||||
if (mRandom){
|
||||
currentId = (rand() % strings.size());
|
||||
}else{
|
||||
currentId++;
|
||||
if (currentId > strings.size()-1)currentId = 0;
|
||||
}
|
||||
mText = strings[currentId];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TextScroller::Render(){
|
||||
mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth);
|
||||
}
|
||||
|
||||
ostream& TextScroller::toString(ostream& out) const
|
||||
{
|
||||
return out << "TextScroller ::: mText : " << mText
|
||||
<< " ; tempText : " << tempText
|
||||
<< " ; mFont : " << mFont
|
||||
<< " ; mWidth : " << mWidth
|
||||
<< " ; mSpeed : " << mSpeed
|
||||
<< " ; mX,mY : " << mX << "," << mY
|
||||
<< " ; start : " << start
|
||||
<< " ; timer : " << timer
|
||||
<< " ; strings : ?" // << strings
|
||||
<< " ; currentId : " << currentId
|
||||
<< " ; mRandom : " << mRandom;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user