Erwan
- Fixed a bug in SampleCache - simplified card files initial parsing
This commit is contained in:
@@ -141,6 +141,7 @@ class GameStateMenu: public GameState, public JGuiListener
|
||||
|
||||
SAFE_DELETE(subMenuController);
|
||||
|
||||
|
||||
SAFE_DELETE(mIconsTexture);
|
||||
|
||||
for (int i = 0; i < 10 ; i++){
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
#include "../include/GameApp.h"
|
||||
#include "../include/TexturesCache.h"
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
class GameApp;
|
||||
class MTGCard;
|
||||
|
||||
@@ -40,9 +42,6 @@ class MtgSets{
|
||||
class MTGAllCards {
|
||||
protected:
|
||||
int conf_read_mode;
|
||||
int conf_fd;
|
||||
char * conf_buffer;
|
||||
int read_cursor;
|
||||
int colorsCount[MTG_NB_COLORS];
|
||||
int total_cards;
|
||||
GameApp * parent;
|
||||
@@ -64,11 +63,11 @@ class MTGAllCards {
|
||||
int countByType(const char * _type);
|
||||
int countByColor(int color);
|
||||
int countBySet(int setId);
|
||||
int readConfLine(int set_id);
|
||||
int readConfLine(ifstream &file, int set_id);
|
||||
int totalCards();
|
||||
int randomCardId();
|
||||
private:
|
||||
int processConfLine(char* file, MTGCard* card);
|
||||
int processConfLine(string s, MTGCard* card);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,23 +26,13 @@
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define BUFSIZE 600
|
||||
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
template <typename T, size_t N>
|
||||
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
|
||||
#define countof( array ) (sizeof( _ArraySizeHelper( array ) ))
|
||||
|
||||
|
||||
|
||||
int lowercase(string source);
|
||||
|
||||
int filesize(const char * filename);
|
||||
int read_file (const char * filename, char * buffer, int filesize);
|
||||
int readline (char * in_buffer, char * out_buffer, int cursor);
|
||||
int readfile_to_ints(const char * filename, int * out_buffer);
|
||||
int fileExists(const char * filename);
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@ JApp* JGameLauncher::GetGameApp()
|
||||
//-------------------------------------------------------------------------------------
|
||||
char *JGameLauncher::GetName()
|
||||
{
|
||||
return strdup("Wagic");
|
||||
return "Wagic";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ int MtgSets::Add(const char * name){
|
||||
}
|
||||
|
||||
|
||||
int MTGAllCards::processConfLine(char *buffer, MTGCard *card){
|
||||
string s = buffer;
|
||||
int MTGAllCards::processConfLine(string s, MTGCard *card){
|
||||
unsigned int i = s.find_first_of("=");
|
||||
if (i == string::npos) return 0;
|
||||
string key = s.substr(0,i);
|
||||
@@ -132,15 +131,14 @@ void MTGAllCards::init(){
|
||||
|
||||
int MTGAllCards::load(const char * config_file, const char * set_name,int autoload){
|
||||
conf_read_mode = 0;
|
||||
int file_size = filesize(config_file);
|
||||
conf_buffer = (char *) malloc(file_size);
|
||||
read_cursor = 0;
|
||||
// conf_fd = sceIoOpen(config_file, PSP_O_RDONLY, 0777);
|
||||
read_file(config_file, conf_buffer, file_size );
|
||||
int set_id = MtgSets::SetsList->Add(set_name);
|
||||
if (autoload){
|
||||
while(readConfLine(set_id)){};
|
||||
|
||||
std::ifstream setFile(config_file);
|
||||
|
||||
if (setFile){
|
||||
while(readConfLine(setFile, set_id)){};
|
||||
}
|
||||
|
||||
return total_cards;
|
||||
}
|
||||
|
||||
@@ -153,6 +151,11 @@ MTGAllCards::~MTGAllCards(){
|
||||
|
||||
void MTGAllCards::destroyAllCards(){
|
||||
for (int i= 0; i < total_cards; i++){
|
||||
#ifdef WIN32
|
||||
char buf[4096];
|
||||
sprintf(buf,"deleting %s\n", collection[i]->getName());
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
delete collection[i];
|
||||
};
|
||||
|
||||
@@ -227,33 +230,33 @@ int MTGAllCards::totalCards(){
|
||||
return (total_cards);
|
||||
}
|
||||
|
||||
int MTGAllCards::readConfLine(int set_id){
|
||||
char buffer[BUFSIZE];
|
||||
read_cursor = readline(conf_buffer, buffer, read_cursor);
|
||||
if (read_cursor){
|
||||
int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
|
||||
|
||||
string s;
|
||||
int result = 0;
|
||||
if(std::getline(file,s)) result = 1;
|
||||
switch(conf_read_mode) {
|
||||
case 0:
|
||||
conf_read_mode = 1;
|
||||
collection[total_cards] = NEW MTGCard(mCache,set_id);
|
||||
if (s.find("[card]") != string::npos){
|
||||
collection[total_cards] = NEW MTGCard(mCache,set_id);
|
||||
conf_read_mode = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (buffer[0] == '[' && buffer[1] == '/'){
|
||||
conf_read_mode = 0;
|
||||
total_cards++;
|
||||
if (s.find("[/card]") != string::npos){
|
||||
conf_read_mode = 0;
|
||||
total_cards++;
|
||||
}else{
|
||||
processConfLine(buffer, collection[total_cards]);
|
||||
processConfLine(s, collection[total_cards]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}else{
|
||||
free (conf_buffer);
|
||||
}
|
||||
|
||||
return read_cursor;
|
||||
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,9 @@ void SimpleMenu::Render(){
|
||||
renderer->FillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(70,0,0,0));
|
||||
renderer->FillRoundRect(mX,mY,mWidth,mHeight,10,ARGB(255,17,17,17));
|
||||
renderer->FillRoundRect(mX+2,mY+2,mWidth - 4,mHeight-4,10,ARGB(255,62,62,62));
|
||||
if (displaytitle)
|
||||
if (displaytitle){
|
||||
mFont->DrawString(title.c_str(), mX+10, mY+10);
|
||||
}
|
||||
for (int i = startId; i < startId + maxItems ; i++){
|
||||
if (i > mCount-1) break;
|
||||
((SimpleMenuItem * )mObjects[i])->RenderWithOffset(-20*startId);
|
||||
@@ -48,3 +49,5 @@ void SimpleMenu::Add(int id, const char * text){
|
||||
JGuiController::Add(NEW SimpleMenuItem(id, mFont, text, mWidth/2 + mX + 10, mY + 10 + y, (mCount == 0)));
|
||||
if (mCount <= maxItems) mHeight += 20;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ SampleCache * SampleCache::GetInstance(){
|
||||
}
|
||||
|
||||
JSample * SampleCache::getSample(string filename){
|
||||
lastTime++;
|
||||
map<string,SampleCached *>::iterator it = cache.find(filename);
|
||||
if (it == cache.end()){
|
||||
if (cache.size() >10) cleanOldest(); //Poor man's limit
|
||||
@@ -134,10 +135,11 @@ JSample * SampleCache::getSample(string filename){
|
||||
cleanCache();
|
||||
sample = JSoundSystem::GetInstance()->LoadSample(filename.c_str());
|
||||
}
|
||||
lastTime++;
|
||||
|
||||
cache[filename] = NEW SampleCached(lastTime, sample);
|
||||
return sample;
|
||||
}else{
|
||||
it->second->lastTime = lastTime;
|
||||
return (it->second->sample);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,72 +34,6 @@ int filesize(const char * filename){
|
||||
return file_size;
|
||||
}
|
||||
|
||||
int read_file (const char * filename, char * buffer, int file_size){
|
||||
int a = 0;
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
FILE * file = fopen(filename, "rb");
|
||||
a = fread(buffer, 1, file_size, file);
|
||||
fclose(file);
|
||||
#else
|
||||
int file = sceIoOpen(filename,PSP_O_RDONLY, 0777);
|
||||
|
||||
a = sceIoRead(file, buffer, file_size);
|
||||
sceIoClose(file);
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "%s is %d characters long.\n", filename, strlen(&buffer[0]) );
|
||||
return a;
|
||||
|
||||
}
|
||||
|
||||
int readline (char * in_buffer, char * out_buffer, int cursor){
|
||||
char a;
|
||||
int found = 0;
|
||||
int i = 0;
|
||||
|
||||
//int read_ok = 0;
|
||||
while (found == 0){
|
||||
a = in_buffer[cursor];
|
||||
cursor++;
|
||||
if (a == '\r'){
|
||||
a = in_buffer[cursor];
|
||||
cursor ++;
|
||||
}
|
||||
if (a == 0){
|
||||
found = 1;
|
||||
cursor = 0;
|
||||
}else{
|
||||
if(a == '\n' || i==(BUFSIZE - 1)){
|
||||
found = 1;
|
||||
out_buffer[i] = 0;
|
||||
|
||||
if (a != '\n'){
|
||||
int endofline = 0;
|
||||
while (!endofline){
|
||||
//int read;
|
||||
a = in_buffer[cursor];
|
||||
|
||||
cursor++;
|
||||
if (a == 0 || a=='\n'){
|
||||
endofline = 1;
|
||||
fprintf(stderr, "buffer overflow in readline %s\n", out_buffer);
|
||||
}
|
||||
if (a == 0 ){
|
||||
cursor = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
out_buffer[i] = a;
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
out_buffer[i] = 0;
|
||||
return(cursor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int readfile_to_ints(const char * filename, int * out_buffer){
|
||||
|
||||
Reference in New Issue
Block a user