diff --git a/JGE/include/JLogger.h b/JGE/include/JLogger.h index e4d88495e..a7a5ea481 100644 --- a/JGE/include/JLogger.h +++ b/JGE/include/JLogger.h @@ -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 diff --git a/JGE/include/JRenderer.h b/JGE/include/JRenderer.h index 4a4bb6232..ebbc66a3a 100644 --- a/JGE/include/JRenderer.h +++ b/JGE/include/JRenderer.h @@ -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); diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index e96941539..d6c233604 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -7,7 +7,13 @@ // Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) // //------------------------------------------------------------------------------------- + + +// 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 #include #include @@ -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(); diff --git a/JGE/src/JLogger.cpp b/JGE/src/JLogger.cpp index 46c6a904c..6f78b81cb 100644 --- a/JGE/src/JLogger.cpp +++ b/JGE/src/JLogger.cpp @@ -1,24 +1,34 @@ #include "../include/JLogger.h" +#include "../include/JGE.h" #include "../include/DebugRoutines.h" #include 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 diff --git a/JGE/src/main.cpp b/JGE/src/main.cpp index 093eee39b..4afe4bba6 100644 --- a/JGE/src/main.cpp +++ b/JGE/src/main.cpp @@ -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 diff --git a/JGE/src/zipFS/zfsystem.cpp b/JGE/src/zipFS/zfsystem.cpp index 522d5ce02..9610d564d 100644 --- a/JGE/src/zipFS/zfsystem.cpp +++ b/JGE/src/zipFS/zfsystem.cpp @@ -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"); } diff --git a/projects/mtg/bin/Res/graphics/extracostshadow.png b/projects/mtg/bin/Res/graphics/extracostshadow.png deleted file mode 100644 index d2329028c..000000000 Binary files a/projects/mtg/bin/Res/graphics/extracostshadow.png and /dev/null differ diff --git a/projects/mtg/bin/Res/graphics/shadow.png b/projects/mtg/bin/Res/graphics/shadow.png deleted file mode 100644 index 4ffde0a8f..000000000 Binary files a/projects/mtg/bin/Res/graphics/shadow.png and /dev/null differ diff --git a/projects/mtg/bin/Res/graphics/shadows.png b/projects/mtg/bin/Res/graphics/shadows.png new file mode 100644 index 000000000..3fbe7e72c Binary files /dev/null and b/projects/mtg/bin/Res/graphics/shadows.png differ diff --git a/projects/mtg/bin/Res/graphics/white.png b/projects/mtg/bin/Res/graphics/white.png deleted file mode 100644 index ecc2538e4..000000000 Binary files a/projects/mtg/bin/Res/graphics/white.png and /dev/null differ diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index 089edc446..01a029fae 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -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; diff --git a/projects/mtg/include/GameStateMenu.h b/projects/mtg/include/GameStateMenu.h index 4a2d6b713..d8fb9106a 100644 --- a/projects/mtg/include/GameStateMenu.h +++ b/projects/mtg/include/GameStateMenu.h @@ -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); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index f3695b39a..fa6577200 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -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; diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index 22e8c1058..06d1ab83d 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -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 (mor->mTex->mWidth / 2), static_cast (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 diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 454803c77..dd2cd8c9d 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -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 (jq->mTex->mWidth / 2), static_cast (jq->mTex->mHeight / 2)); + jq = WResourceManager::Instance()->RetrieveQuad("phasebar.png", 0, 0, 0, 0, "phasebar", RETRIEVE_MANAGE); + LOG("Init Collection"); MTGAllCards::loadInstance(); diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index e61a174bc..36123073a 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -246,7 +246,7 @@ void GameStateDeckViewer::Start() //init welcome menu updateDecks(); - GameApp::playMusic("track1.mp3"); + GameApp::playMusic("Track1.mp3"); loadIndexes(); mEngine->ResetInput(); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index e266f9d00..0573e1515 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -21,6 +21,7 @@ #include "Rules.h" #include "ModRules.h" #include "Credits.h" +#include "AIPlayer.h" #ifdef NETWORK_SUPPORT #include @@ -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 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::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(); vectoritems = 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)); }