- fix compilation issue on psp

- attempt at reducing loading times on the PSP: I merged a few graphics files together, removed some unused calls from the initialization functions, and moved some other ones to have a more lazy approach. The PSP version remains fairly slow in some parts (especially loading, but also entering the shop, or starting a new game), so I will try to reduce file access as much as possible in the days to come. Not a release blocker IMO though, but I4d sure love if it were faster.
- uppercased "Track1.mp3" to be in line with the actual filename. Most likely this had been broken forever on case-sensitive OSes
- I removed costly calls from the textscroller. I believe it wasn't very useful in its previous state. Now it's only "advertising" for unlockable stuff, which I think is ok (and allows to refresh it every time the menu is loaded)
- As a counterpart, added a "% complete" progress bar in the menu, something I wanted to add a while ago.
This commit is contained in:
wagic.the.homebrew
2011-12-11 13:48:24 +00:00
parent f8f5c24304
commit c9fd53808f
17 changed files with 135 additions and 107 deletions

View File

@@ -19,6 +19,7 @@
class JLogger{
public:
static void Log(const char * text);
static void Log(std::string text);
JLogger(const char* text);
~JLogger();
@@ -26,6 +27,7 @@ class JLogger{
const char* mText;
static std::string lastLog;
static int lastTime;
};
#endif

View File

@@ -88,11 +88,6 @@ public:
//////////////////////////////////////////////////////////////////////////
static JRenderer* GetInstance();
/*
//START PurpleScreen Debug
static int debugged;
//END PurpleScreen Debug
*/
static void Destroy();
static void Set3DFlag(bool flag);

View File

@@ -7,7 +7,13 @@
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
//
//-------------------------------------------------------------------------------------
// Should we add PrecompiledHeader.h to more platforms here? PSP Doesn't support it in JGE (erwan 2011/12/11)
#if defined (IOS)
#include "PrecompiledHeader.h"
#endif
#include <iostream>
#include <map>
#include <set>
@@ -357,7 +363,7 @@ void JGE::Init()
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
JRenderer::GetInstance();
//JRenderer::GetInstance(); Lazy loading
//JFileSystem::GetInstance(); Lazy loading
//JSoundSystem::GetInstance(); let's do lazy loading
@@ -451,7 +457,7 @@ void JGE::Init()
mDone = false;
mPaused = false;
mCriticalAssert = false;
JRenderer::GetInstance();
//JRenderer::GetInstance(); Lazy loading
//JFileSystem::GetInstance(); Lazy loading
JSoundSystem::GetInstance();
LeftClickedProcessed();

View File

@@ -1,24 +1,34 @@
#include "../include/JLogger.h"
#include "../include/JGE.h"
#include "../include/DebugRoutines.h"
#include <fstream>
string JLogger::lastLog = "";
int JLogger::lastTime = 0;
void JLogger::Log(const char * text){
#ifdef DOLOG
std::ofstream file(LOG_FILE, std::ios_base::app);
std::stringstream out;
int newTime = JGEGetTime();
out << newTime << "(+" << newTime - lastTime << ") :" << text;
if (file){
file << text;
file << out.str();
file << "\n";
file.close();
lastTime = newTime;
}
DebugTrace(text);
DebugTrace(out.str());
#endif
lastLog = text;
}
void JLogger::Log(std::string text){
Log(text.c_str());
}
JLogger::JLogger(const char* text) : mText(text)
{
#ifdef DOLOG

View File

@@ -49,7 +49,7 @@ bool done = false;
JApp *game = NULL;
JGE *g_engine = NULL;
u32 gTickFrequency;
u32 gTickFrequency = 1;
//------------------------------------------------------------------------------------------------
// Exit callback
@@ -293,6 +293,14 @@ u8 JGEGetAnalogY() { return gCtrlPad.Ly; }
// The main loop
int main(int argc, char *argv[])
{
pspDebugScreenInit();
pspDebugScreenSetBackColor(0x00000000);
pspDebugScreenSetTextColor(0xFFFFFFFF);
pspDebugScreenClear();
pspDebugScreenPrintf("Wagic:Loading core...");
JLOG("SetupCallbacks()");
SetupCallbacks();
#ifdef DEVHOOK

View File

@@ -289,9 +289,10 @@ void filesystem::InsertZip(const char * Filename, const size_t PackID)
string ZipPath = m_BasePath + Filename;
// Open zip
ifstream File(ZipPath.c_str(), ios::binary);
LOG(("opening zip:" + ZipPath).c_str());
ifstream File(ZipPath.c_str(), ios::binary);
if (! File)
return;
@@ -331,6 +332,8 @@ void filesystem::InsertZip(const char * Filename, const size_t PackID)
// Add zip file to Zips data base (only if not empty)
if (ZipInfo.m_NbEntries != 0)
m_Zips[PackID] = ZipInfo;
LOG("--zip file loading DONE");
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 938 B

View File

@@ -69,6 +69,7 @@ class AIPlayer: public Player{
private:
static int totalAIDecks; //a cache that counts the number of AI deck files in the AI folder. see getTotalAIDecks() below.
static int countTotalDecks(int lower, int higher, int current);
protected:
bool mFastTimerMode;

View File

@@ -12,6 +12,7 @@ class GameStateMenu: public GameState, public JGuiListener
private:
TextScroller * scroller;
int scrollerSet;
int mPercentComplete;
JGuiController* mGuiController;
SimpleMenu* subMenuController;
SimpleMenu* gameTypeMenu;
@@ -50,6 +51,7 @@ private:
string loadRandomWallpaper(); //loads a list of string of textures that can be randolmy shown on the loading screen
void RenderTopMenu();
int gamePercentComplete();
public:
GameStateMenu(GameApp* parent);

View File

@@ -336,26 +336,34 @@ AIPlayer * AIPlayerFactory::createAIPlayerTest(GameObserver *observer, MTGAllCar
int AIPlayer::getTotalAIDecks()
{
if (totalAIDecks != -1)
return totalAIDecks;
totalAIDecks = 0;
bool found = true;
while (found)
{
found = false;
char buffer[512];
sprintf(buffer, "ai/baka/deck%i.txt", totalAIDecks + 1);
if (JFileSystem::GetInstance()->FileExists(buffer))
{
found = true;
totalAIDecks++;
}
}
if (totalAIDecks == -1)
totalAIDecks = countTotalDecks(0,0,1);
return totalAIDecks;
}
int AIPlayer::countTotalDecks(int lower, int higher, int current) {
char buffer[512];
sprintf(buffer, "ai/baka/deck%i.txt", current);
if (JFileSystem::GetInstance()->FileExists(buffer))
{
if (higher == current + 1)
return current;
int newlower = current;
int newcurrent = higher ? (higher + newlower)/2 : current * 2;
return countTotalDecks(newlower, higher, newcurrent);
} else {
if (!lower)
return 0;
if (lower == current - 1)
return lower;
int newhigher = current;
int newcurrent = (lower + newhigher) / 2;
return countTotalDecks(lower, newhigher, newcurrent);
}
}
void AIPlayer::invalidateTotalAIDecks()
{
totalAIDecks = -1;

View File

@@ -258,9 +258,12 @@ void CardGui::Render()
JQuadPtr mor;
if(card->isMorphed && !alternate)
{
mor = card->getObserver()->getResourceManager()->GetQuad("morph");
mor->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(mor.get(), actX, actY, actT,scale, scale);
mor = card->getObserver()->getResourceManager()->RetrieveTempQuad("morph.jpg");
if (mor && mor->mTex) {
mor->SetHotSpot(static_cast<float> (mor->mTex->mWidth / 2), static_cast<float> (mor->mTex->mHeight / 2));
mor->SetColor(ARGB(255,255,255,255));
renderer->RenderQuad(mor.get(), actX, actY, actT,scale, scale);
}
}
//draws the numbers power/toughness

View File

@@ -92,6 +92,7 @@ void GameApp::Create()
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#elif defined (PSP)
pspFpuSetEnable(0); //disable FPU Exceptions until we find where the FPU errors come from
pspDebugScreenPrintf("Wagic:Loading resources...");
#endif
#endif //QT_CONFIG
//_CrtSetBreakAlloc(368);
@@ -122,7 +123,7 @@ void GameApp::Create()
}
mfile.close();
}
LOG("init Res Folder at " + foldersRoot);
JFileSystem::init(foldersRoot + "User/", foldersRoot + systemFolder);
// Create User Folders (for write access) if they don't exist
@@ -135,9 +136,11 @@ void GameApp::Create()
}
}
LOG("Loading Modrules");
//Load Mod Rules before everything else
gModRules.load("rules/modrules.xml");
LOG("Loading Unlockables");
//Load awards (needs to be loaded before any option are accessed)
Unlockable::load();
@@ -210,39 +213,28 @@ void GameApp::Create()
// The translator is ready now.
LOG("--Loading various textures");
// Load in this function only textures that are used frequently throughout the game. These textures will constantly stay in Ram, so be frugal
WResourceManager::Instance()->RetrieveTexture("phasebar.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("wood.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("gold.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("goldglow.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("backdrop.jpg", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("handback.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("BattleIcon.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("DefenderIcon.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("shadow.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("white.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("extracostshadow.png", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("morph.jpg", RETRIEVE_MANAGE);
WResourceManager::Instance()->RetrieveTexture("shadows.png", RETRIEVE_MANAGE);
jq = WResourceManager::Instance()->RetrieveQuad("BattleIcon.png", 0, 0, 25, 25, "BattleIcon", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(12, 12);
jq = WResourceManager::Instance()->RetrieveQuad("DefenderIcon.png", 0, 0, 24, 23, "DefenderIcon", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(12, 12);
jq = WResourceManager::Instance()->RetrieveQuad("shadow.png", 0, 0, 16, 16, "shadow", RETRIEVE_MANAGE);
jq = WResourceManager::Instance()->RetrieveQuad("shadows.png", 2, 2, 16, 16, "white", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(8, 8);
jq = WResourceManager::Instance()->RetrieveQuad("white.png", 0, 0, 16, 16, "white", RETRIEVE_MANAGE);
jq = WResourceManager::Instance()->RetrieveQuad("shadows.png", 20, 2, 16, 16, "shadow", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(8, 8);
jq = WResourceManager::Instance()->RetrieveQuad("extracostshadow.png", 0, 0, 16, 16, "extracostshadow", RETRIEVE_MANAGE);
jq = WResourceManager::Instance()->RetrieveQuad("shadows.png", 38, 2, 16, 16, "extracostshadow", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(8, 8);
jq = WResourceManager::Instance()->RetrieveQuad("morph.jpg", 0, 0, MTG_MINIIMAGE_WIDTH, MTG_MINIIMAGE_HEIGHT, "morph", RETRIEVE_MANAGE);
if (jq)
jq->SetHotSpot(static_cast<float> (jq->mTex->mWidth / 2), static_cast<float> (jq->mTex->mHeight / 2));
jq = WResourceManager::Instance()->RetrieveQuad("phasebar.png", 0, 0, 0, 0, "phasebar", RETRIEVE_MANAGE);
LOG("Init Collection");
MTGAllCards::loadInstance();

View File

@@ -246,7 +246,7 @@ void GameStateDeckViewer::Start()
//init welcome menu
updateDecks();
GameApp::playMusic("track1.mp3");
GameApp::playMusic("Track1.mp3");
loadIndexes();
mEngine->ResetInput();

View File

@@ -21,6 +21,7 @@
#include "Rules.h"
#include "ModRules.h"
#include "Credits.h"
#include "AIPlayer.h"
#ifdef NETWORK_SUPPORT
#include <JNetwork.h>
@@ -108,7 +109,6 @@ void GameStateMenu::Create()
}
scroller = NEW TextScroller(Fonts::MAIN_FONT, SCREEN_WIDTH / 2 - 90, SCREEN_HEIGHT - 17, 180);
scrollerSet = 0;
splashTex = NULL;
JFileSystem::GetInstance()->scanfolder("sets/", setFolders);
@@ -150,6 +150,8 @@ void GameStateMenu::Start()
currentState = currentState | MENU_STATE_MINOR_FADEIN;
wallpaper = "";
scrollerSet = 0; // This will force-update the scroller text
mPercentComplete = 0;
}
void GameStateMenu::genNbCardsStr()
@@ -182,37 +184,8 @@ void GameStateMenu::genNbCardsStr()
void GameStateMenu::fillScroller()
{
scroller->Reset();
char buffer[4096];
char buff2[512];
DeckStats * stats = DeckStats::GetInstance();
vector<DeckMetaData *> playerDecks = BuildDeckList(options.profileFile(), "", NULL, 6);
int totalGames = 0;
for (size_t j = 0; j < playerDecks.size(); j++)
{
DeckMetaData* meta = playerDecks[j];
if (meta)
meta->LoadStats();
sprintf(buffer, "stats/player_deck%i.txt", meta->getDeckId());
string deckstats = options.profileFile(buffer);
if (fileExists(deckstats.c_str()))
{
stats->load(deckstats.c_str());
int percentVictories = stats->percentVictories();
sprintf(buff2, _("You have a %i%% victory ratio with \"%s\"").c_str(), percentVictories, meta->getName().c_str());
scroller->Add(buff2);
sprintf(buff2, _("You have played %i games with \"%s\"").c_str(), meta->getGamesPlayed(), meta->getName().c_str());
scroller->Add(buff2);
totalGames += meta->getGamesPlayed();
}
}
if (totalGames)
{
sprintf(buff2, _("You have played a total of %i games").c_str(), totalGames);
scroller->Add(buff2);
}
if (!options[Options::DIFFICULTY_MODE_UNLOCKED].number)
scroller->Add(_("Unlock the difficult mode for more challenging duels!"));
@@ -240,37 +213,56 @@ void GameStateMenu::fillScroller()
sprintf(buff2, _("You have unlocked %i expansions out of %i").c_str(), nbunlocked, setlist.size());
scroller->Add(buff2);
PlayerData * playerdata = NEW PlayerData(MTGCollection());
if (gModRules.general.hasDeckEditor() && gModRules.general.hasShop())
{
int totalCards = playerdata->collection->totalCards();
if (totalCards)
{
sprintf(buff2, _("You have a total of %i cards in your collection").c_str(), totalCards);
scroller->Add(buff2);
int estimatedValue = playerdata->collection->totalPrice();
sprintf(buff2, _("The shopkeeper would buy your entire collection for around %i credits").c_str(), estimatedValue / 2);
scroller->Add(buff2);
sprintf(buff2, _("The cards in your collection have an average value of %i credits").c_str(), estimatedValue / totalCards);
scroller->Add(buff2);
}
}
sprintf(buff2, _("You currently have %i credits").c_str(), playerdata->credits);
SAFE_DELETE(playerdata);
scroller->Add(buff2);
scroller->Add(_("More cards and mods at http://wololo.net/wagic"));
scroller->Add(_("These stats will be updated next time you run Wagic"));
scrollerSet = 1;
scroller->setRandom();
}
int GameStateMenu::gamePercentComplete() {
if (mPercentComplete)
return mPercentComplete;
int done = 0;
int total = 0;
total++;
if (options[Options::DIFFICULTY_MODE_UNLOCKED].number)
done++;
for (map<string, Unlockable *>::iterator it = Unlockable::unlockables.begin(); it != Unlockable::unlockables.end(); ++it) {
total++;
if (it->second->isUnlocked())
total++;
}
total++;
if (options[Options::RANDOMDECK_MODE_UNLOCKED].number)
done++;
total++;
if (options[Options::EVILTWIN_MODE_UNLOCKED].number)
done++;
//Unlocked sets
total+= setlist.size();
for (int i = 0; i < setlist.size(); i++)
{
if (1 == options[Options::optionSet(i)].number)
done++;
}
//unlocked AI decks
int currentlyUnlocked = options[Options::AIDECKS_UNLOCKED].number;
int totalAIDecks = AIPlayer::getTotalAIDecks();
int reallyUnlocked = MIN(currentlyUnlocked, totalAIDecks);
total+= totalAIDecks / 10;
done+= reallyUnlocked / 10;
mPercentComplete = 100 * done / total;
return mPercentComplete;
}
int GameStateMenu::nextSetFolder(const string & root, const string & file)
{
bool found = false;
@@ -678,6 +670,7 @@ void GameStateMenu::RenderTopMenu()
{
float leftTextPos = 10;
float rightTextPos = SCREEN_WIDTH - 10;
JRenderer * renderer = JRenderer::GetInstance();
vector<ModRulesOtherMenuItem *>items = gModRules.menu.other;
for (size_t i = 0; i < items.size(); ++i)
@@ -701,6 +694,11 @@ void GameStateMenu::RenderTopMenu()
mFont->SetColor(ARGB(128,255,255,255));
mFont->DrawString(GAME_VERSION, rightTextPos, 5, JGETEXT_RIGHT);
mFont->DrawString(nbcardsStr, leftTextPos, 5);
renderer->FillRect(leftTextPos, 26, 104, 8, ARGB(255, 100, 90, 60));
renderer->FillRect(leftTextPos + 2, 28, (float)(gamePercentComplete()), 4, ARGB(255,220,200, 125));
char buf[512];
sprintf(buf, _("achieved: %i%%").c_str(), gamePercentComplete());
mFont->DrawString(buf, (leftTextPos + 104) / 2, 35, JGETEXT_CENTER);
mFont->SetScale(1.f);
mFont->SetColor(ARGB(255,255,255,255));
}