- Cache size is now an option
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-04-19 06:02:29 +00:00
parent 337301e039
commit 33e79e234e
15 changed files with 76 additions and 52 deletions

View File

@@ -66,25 +66,20 @@ bool JMP3::fillBuffers() {
}
bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize) {
printf("load\n");
m_inBufferSize = inBufferSize;
printf("1\n");
//m_inBuffer = new char[m_inBufferSize];
//if (!m_inBuffer)
// return false;
m_outBufferSize = outBufferSize;
printf("2\n");
//m_outBuffer = new short[outBufferSize];
//if (!m_outBuffer)
// return false;
printf("3:%s\n",filename.c_str());
m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777);
if (m_fileHandle < 0)
return false;
printf("4\n");
int ret = sceMp3InitResource();
if (ret < 0)
return false;
@@ -108,53 +103,40 @@ bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize
initArgs.pcmBufSize = m_outBufferSize;
initArgs.pcmBuf = (SceVoid*) m_outBuffer;
printf("5\n");
m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs);
if (m_mp3Handle < 0)
return false;
// Alright we are all set up, let's fill the first buffer.
printf("5.5\n");
bool _filled= fillBuffers();
if (! _filled) return false;
printf("end = %i, bufsize = %i, outSize = %i\n", fileSize, m_inBufferSize, m_outBufferSize);
// Start this bitch up!
printf("6\n");
int start = sceMp3Init(m_mp3Handle);
if (start < 0)
return false;
printf("7\n");
m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle);
printf("8\n");
m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle);
return true;
}
bool JMP3::unload() {
printf("unload 1\n");
if (m_channel >= 0)
sceAudioSRCChRelease();
printf("unload 2\n");
sceMp3ReleaseMp3Handle(m_mp3Handle);
printf("unload 3\n");
sceMp3TermResource();
printf("unload 4\n");
sceIoClose(m_fileHandle);
printf("unload 5\n");
//delete[] m_inBuffer;
printf("unload 6\n");
//delete[] m_outBuffer;
printf("unload 7\n");
return true;
}

View File

@@ -84,6 +84,7 @@ class GameApp: public JApp
static JResourceManager * CommonRes;
static hgeParticleSystem * Particles[6];
static int HasMusic;
static string systemError;
static JMusic* music;
};

View File

@@ -11,6 +11,7 @@ using std::string;
#define OPTIONS_DIFFICULTY_MODE_UNLOCKED "prx_handler" //huhu
#define OPTIONS_MOMIR_MODE_UNLOCKED "prx_rimom" //haha
#define OPTIONS_DIFFICULTY "difficulty"
#define OPTIONS_CACHESIZE "cacheSize"
// WALDORF - added
#define OPTIONS_INTERRUPT_SECONDS "interruptSeconds"

View File

@@ -6,6 +6,7 @@
#include "../include/GameState.h"
#include "../include/SimpleMenu.h"
class GameStateMenu: public GameState, public JGuiListener
{
private:

View File

@@ -26,7 +26,6 @@ class MTGGuiPlay: public PlayGuiObjectController {
float mGlitterX, mGlitterY;
JTexture * mPhaseBarTexture;
JQuad * mIcons[7];
JTexture * mIconsTexture;
JTexture * mBgTex;
JQuad * mBg;

View File

@@ -16,6 +16,7 @@ class ManaCost{
int cost[Constants::MTG_NB_COLORS+1];
ManaCostHybrid * hybrids[10];
unsigned int nbhybrids;
int extraCostsIsCopy;
public:
ExtraCosts * extraCosts;

View File

@@ -2,7 +2,7 @@
#define _TEXTURES_CACHE_H
#define MAX_CACHE_OBJECTS 100
#define CACHE_SIZE_PIXELS 6000000
#define CACHE_SIZE_PIXELS 2000000
#define CACHE_CARD 1
#define CACHE_THUMB 2
@@ -43,6 +43,7 @@ class TexturesCache{
int nb_textures;
int delete_previous;
int totalsize;
int maxSize;
CardTexture * cache[MAX_CACHE_OBJECTS];
public:
int isInCache(MTGCard * card, int type=CACHE_CARD);

View File

@@ -401,7 +401,7 @@ int AIPlayer::chooseAttackers(){
int AIPlayer::canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy){
if (ennemy->has(Constants::FIRSTSTRIKE) || ennemy->has(Constants::DOUBLESTRIKE)) return 0;
if (!(card->has(Constants::FIRSTSTRIKE) || card->has(Constants::DOUBLESTRIKE))) return 0;
if (!card->power >= ennemy->toughness) return 0;
if (!(card->power >= ennemy->toughness)) return 0;
return 1;
}
@@ -461,8 +461,8 @@ int AIPlayer::chooseBlockers(){
}else{
MTGCardInstance * attacker = card->defenser;
if (opponentsToughness[attacker] <= 0 ||
(card->toughness <= card->defenser->power && opponentForce*2 <life && !canFirstStrikeKill(card,card->defenser)) ||
card->defenser->nbOpponents()>1){
(card->toughness <= attacker->power && opponentForce*2 <life && !canFirstStrikeKill(card,attacker)) ||
attacker->nbOpponents()>1){
g->mLayers->actionLayer()->reactToClick(a,card);
}else{
set = 1;

View File

@@ -10,7 +10,10 @@ int DeckStat::percentVictories(){
}
DeckStats * DeckStats::GetInstance(){
if (!mInstance) mInstance = NEW DeckStats();
if (!mInstance){
mInstance = NEW DeckStats();
}
return mInstance;
}
@@ -19,6 +22,7 @@ void DeckStats::cleanStats(){
for (it = stats.begin(); it != stats.end(); it++){
SAFE_DELETE(it->second);
}
stats.clear();
}
@@ -53,7 +57,10 @@ void DeckStats::load(const char * filename){
int games = atoi(s.c_str());
std::getline(file,s);
int victories = atoi(s.c_str());
stats[deckfile] = NEW DeckStat(games,victories);
map<string,DeckStat *>::iterator it = stats.find(deckfile);
if (it == stats.end()){
stats[deckfile] = NEW DeckStat(games,victories);
}
}
file.close();
}

View File

@@ -21,6 +21,7 @@ JResourceManager* GameApp::CommonRes = NEW JResourceManager();
hgeParticleSystem* GameApp::Particles[] = {NULL,NULL,NULL,NULL,NULL,NULL};
int GameApp::HasMusic = 1;
JMusic * GameApp::music = NULL;
string GameApp::systemError = "";
GameState::GameState(GameApp* parent): mParent(parent)
{
@@ -105,6 +106,10 @@ void GameApp::Create()
CommonRes->LoadJLBFont("graphics/magic",16);
CommonRes->CreateTexture("graphics/phasebar.png");
CommonRes->CreateTexture("graphics/background.png");
CommonRes->CreateTexture("graphics/back.jpg");
//CommonRes->CreateTexture("graphics/interrupt.png");
//CommonRes->CreateQuad("interrupt", "graphics/interrupt.png", 0, 0, 256, 128);
@@ -171,7 +176,7 @@ void GameApp::Destroy()
}
SAFE_DELETE(cache);
SampleCache::DestroyInstance();
delete(DeckStats::GetInstance());
SAFE_DELETE(CommonRes);
@@ -182,7 +187,7 @@ void GameApp::Destroy()
SAFE_DELETE(music);
delete(DeckStats::GetInstance());
SimpleMenu::destroy();
@@ -196,6 +201,7 @@ void GameApp::Destroy()
void GameApp::Update()
{
if (systemError.size()) return;
JGE* mEngine = JGE::GetInstance();
if (mEngine->GetButtonState(PSP_CTRL_START) && mEngine->GetButtonClick(PSP_CTRL_TRIANGLE))
{
@@ -236,7 +242,12 @@ void GameApp::Update()
void GameApp::Render()
{
if (systemError.size()){
fprintf(stderr, systemError.c_str());
JLBFont * mFont= CommonRes->GetJLBFont("graphics/simon");
if (mFont) mFont->DrawString(systemError.c_str(),1,1);
return;
}
if (mCurrentState != NULL)
{
mCurrentState->Render();

View File

@@ -4,6 +4,7 @@
#include "../include/MenuItem.h"
#include "../include/GameOptions.h"
#include "../include/GameApp.h"
#include "../include/MTGCard.h"
static const char* GAME_VERSION = "WTH?! 0.6.0 - by WilLoW";
#define ALPHA_WARNING 0
@@ -72,6 +73,8 @@ GameStateMenu::~GameStateMenu() {}
void GameStateMenu::Create()
{
mDip = NULL;
mReadConf = 0;
mCurrentSetName[0] = 0;
@@ -241,8 +244,10 @@ void GameStateMenu::Update(float dt)
break;
case MENU_STATE_MAJOR_MAINMENU :
if (mGuiController!=NULL){
mGuiController->Update(dt);
mGuiController->Update(dt);
}
break;
case MENU_STATE_MAJOR_SUBMENU :
subMenuController->Update(dt);
@@ -407,6 +412,7 @@ void GameStateMenu::Render()
}
}
}

View File

@@ -31,6 +31,7 @@ void GameStateOptions::Start()
if (GameOptions::GetInstance()->values[OPTIONS_DIFFICULTY_MODE_UNLOCKED].getIntValue()) {
optionsList->Add(NEW OptionItem(OPTIONS_DIFFICULTY, "Difficulty", 3, 1));
}
optionsList->Add(NEW OptionItem(OPTIONS_CACHESIZE, "Cache Size", 60, 5));
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
optionsMenu = NEW SimpleMenu(102, this,mFont, 50,170);
optionsMenu->Add(1, "Save & Back to Main Menu");

View File

@@ -26,7 +26,7 @@ MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id,
offset = 0;
mPhaseBarTexture = JRenderer::GetInstance()->LoadTexture("graphics/phasebar.png", TEX_TYPE_USE_VRAM);
mPhaseBarTexture = GameApp::CommonRes->GetTexture("graphics/phasebar.png");
for (int i=0; i < 12; i++){
phaseIcons[2*i] = NEW JQuad(mPhaseBarTexture, i*28, 0, 28, 28);
phaseIcons[2*i + 1] = NEW JQuad(mPhaseBarTexture, i*28, 28, 28, 28);
@@ -36,26 +36,34 @@ MTGGuiPlay::MTGGuiPlay(int id, GameObserver * _game):PlayGuiObjectController(id,
mGlitterAlpha = -1;
mFont= GameApp::CommonRes->GetJLBFont("graphics/simon");
mIconsTexture = JRenderer::GetInstance()->LoadTexture("graphics/menuicons.png", TEX_TYPE_USE_VRAM);
//load all the icon images
mIcons[Constants::MTG_COLOR_ARTIFACT] = NEW JQuad(mIconsTexture, 2+6*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_LAND] = NEW JQuad(mIconsTexture, 2+5*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_WHITE] = NEW JQuad(mIconsTexture, 2+4*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_RED] = NEW JQuad(mIconsTexture, 2+3*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_BLACK] = NEW JQuad(mIconsTexture, 2+2*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_BLUE] = NEW JQuad(mIconsTexture, 2+1*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_GREEN] = NEW JQuad(mIconsTexture, 2+0*36, 38, 32, 32);
mIcons[Constants::MTG_COLOR_ARTIFACT] = GameApp::CommonRes->GetQuad("c_artifact");
mIcons[Constants::MTG_COLOR_LAND] = GameApp::CommonRes->GetQuad("c_land");
mIcons[Constants::MTG_COLOR_WHITE] = GameApp::CommonRes->GetQuad("c_white");
mIcons[Constants::MTG_COLOR_RED] = GameApp::CommonRes->GetQuad("c_red");
mIcons[Constants::MTG_COLOR_BLACK] = GameApp::CommonRes->GetQuad("c_black");
mIcons[Constants::MTG_COLOR_BLUE] = GameApp::CommonRes->GetQuad("c_blue");
mIcons[Constants::MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i=0; i < 7; i++){
mIcons[i]->SetHotSpot(16,16);
}
mBgTex = JRenderer::GetInstance()->LoadTexture("graphics/background.png", TEX_TYPE_USE_VRAM);
mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
mBgTex = GameApp::CommonRes->GetTexture("graphics/background.png");
if (mBgTex) mBg = NEW JQuad(mBgTex, 0, 0, 480, 272);
else {
mBg = NULL;
GameApp::systemError = "error Loading Texture mBgTex in MTGGuiPlay intialization";
}
mBgTex2 = JRenderer::GetInstance()->LoadTexture("graphics/back.jpg", TEX_TYPE_USE_VRAM);
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){
alphaBg[i] = 255;
mBgTex2 = GameApp::CommonRes->GetTexture("graphics/back.jpg");
if (mBgTex2){
mBg2 = NEW JQuad(mBgTex2, 0, 0, 480, 255);
for (int i= 0; i < 4; i++){
alphaBg[i] = 255;
}
}else{
mBg2 = NULL;
GameApp::systemError = "error Loading Texture mBgTex2 in MTGGuiPlay intialization";
}
alphaBg[0] = 0;
AddPlayersGuiInfo();
@@ -401,20 +409,17 @@ void MTGGuiPlay::Render(){
MTGGuiPlay::~MTGGuiPlay(){
LOG("==Destroying MTGGuiPlay==");
delete mBg;
delete mBgTex;
for (int i=0; i < 7; i++){
delete mIcons[i];
}
delete mIconsTexture;
//delete mBgTex;
delete mGlitter;
for (int i=0; i < 12; i++){
delete phaseIcons[2*i] ;
delete phaseIcons[2*i + 1];
}
delete mPhaseBarTexture;
//delete mPhaseBarTexture;
SAFE_DELETE(mBg2);
SAFE_DELETE(mBgTex2);
//SAFE_DELETE(mBgTex2);
LOG("==Destroying MTGGuiPlay Successful==");

View File

@@ -128,6 +128,9 @@ ManaCost::~ManaCost(){
for (unsigned int i = 0; i < nbhybrids ; i++){
SAFE_DELETE(hybrids[i]);
}
if (!extraCostsIsCopy) {
SAFE_DELETE(extraCosts);
}
}
void ManaCost::x(){
@@ -141,6 +144,7 @@ void ManaCost::init(){
}
nbhybrids = 0;
extraCosts = NULL;
extraCostsIsCopy = 1;
}
@@ -156,6 +160,7 @@ void ManaCost::copy(ManaCost * _manaCost){
if (_manaCost->extraCosts){
//TODO Deep copy ?
extraCosts = _manaCost->extraCosts;
extraCostsIsCopy = 1;
}
}

View File

@@ -1,5 +1,6 @@
#include "../include/config.h"
#include "../include/TexturesCache.h"
#include "../include/GameOptions.h"
TexturesCache::TexturesCache(){
nb_textures = 0;
@@ -9,6 +10,8 @@ TexturesCache::TexturesCache(){
for (int i=0; i<MAX_CACHE_OBJECTS;i++){
cache[i] = NULL;
}
maxSize = GameOptions::GetInstance()->values[OPTIONS_CACHESIZE].getIntValue() * 100000;
if (!maxSize) maxSize = CACHE_SIZE_PIXELS;
#ifdef WIN32
char buf [4096];
sprintf(buf, " Init TextureCache : %p\n", this);
@@ -61,7 +64,7 @@ void TexturesCache::removeQuad(int id){
}
int TexturesCache::cleanup(){
while (nb_textures >= MAX_CACHE_OBJECTS - 1 || totalsize > CACHE_SIZE_PIXELS){
while (nb_textures >= MAX_CACHE_OBJECTS - 1 || totalsize > maxSize){
int i = getOldestQuad();
if (i == -1) return 0;
removeQuad(i);