From a74c3bbcd2f6caad993dfa44e45b7aac37c05a0a Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Tue, 15 Jun 2010 17:10:17 +0000 Subject: [PATCH] Fix console log not opening early enough on startup, and also minor cleanups to database loader code (removed File_Reader.h) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3213 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/DataBase_Loader.h | 76 +++++++++++++++++++++++------------------ pcsx2/File_Reader.h | 18 ---------- pcsx2/gui/App.h | 2 +- pcsx2/gui/AppInit.cpp | 9 ++--- 4 files changed, 49 insertions(+), 56 deletions(-) delete mode 100644 pcsx2/File_Reader.h diff --git a/pcsx2/DataBase_Loader.h b/pcsx2/DataBase_Loader.h index 2dba732cdb..ef073c2b89 100644 --- a/pcsx2/DataBase_Loader.h +++ b/pcsx2/DataBase_Loader.h @@ -16,10 +16,18 @@ #pragma once #include "Common.h" -#include "File_Reader.h" #include "AppConfig.h" #include +struct key_pair; +class Game_Data; + +// This was originally configured to use deque, but there appear to be no uses of deque's sole +// advantage: adding and removing items from the head of the list. So I changed it to vector +// since it is a slightly lighter weight class. --air +typedef std::vector GameDataArray; +typedef std::vector KeyPairArray; + struct key_pair { wxString key; wxString value; @@ -67,7 +75,9 @@ struct key_pair { class Game_Data { public: wxString id; // Serial Identification Code - deque kList; // List of all (key, value) pairs for game data + KeyPairArray kList; // List of all (key, value) pairs for game data + +public: Game_Data(const wxString& _id = wxEmptyString) : id(_id) {} @@ -81,6 +91,7 @@ public: } }; + // DataBase_Loader: // Give the starting Key and Value you're looking for, // and it will extract the necessary data from the database. @@ -103,13 +114,15 @@ protected: bool extractMultiLine(const wxString& line, key_pair& keyPair, wxInputStream& reader); void extract(const wxString& line, key_pair& keyPair, wxInputStream& reader); - const wxString m_emptyString; // empty string for returning stuff .. never modify! + // temp areas used as buffers for accelerated loading of database content. These strings are + // allocated and grown only once, and then reused for the duration of the database loading + // process; saving thousands of heapp allocation operations. wxString m_dest; std::string m_intermediate; public: - deque gList; // List of all game data - Game_Data* curGame; // Current game data + GameDataArray gList; // List of all game data + Game_Data* curGame; // Current game data (index into gList) wxString header; // Header of the database wxString baseKey; // Key to separate games by ("Serial") @@ -125,30 +138,27 @@ public: wxString s0; Game_Data game; - try { - while(!reader.Eof()) { - while(!reader.Eof()) { // Find first game - pxReadLine(reader, s0, m_intermediate); - extract(s0.Trim(true).Trim(false), keyPair, reader); - if (keyPair.CompareKey(key)) break; - header += s0 + L'\n'; + while(!reader.Eof()) { + while(!reader.Eof()) { // Find first game + pxReadLine(reader, s0, m_intermediate); + extract(s0.Trim(true).Trim(false), keyPair, reader); + if (keyPair.CompareKey(key)) break; + header += s0 + L'\n'; + } + game.NewSerial( keyPair.value ); + game.kList.push_back(keyPair); + + while(!reader.Eof()) { // Fill game data, find new game, repeat... + pxReadLine(reader, s0, m_intermediate); + extract(s0.Trim(true).Trim(false), keyPair, reader); + if (!keyPair.IsOk()) continue; + if (keyPair.CompareKey(key)) { + gList.push_back(game); + game.NewSerial(keyPair.value); } - game.NewSerial( keyPair.value ); game.kList.push_back(keyPair); - - while(!reader.Eof()) { // Fill game data, find new game, repeat... - pxReadLine(reader, s0, m_intermediate); - extract(s0.Trim(true).Trim(false), keyPair, reader); - if (!keyPair.IsOk()) continue; - if (keyPair.CompareKey(key)) { - gList.push_back(game); - game.NewSerial(keyPair.value); - } - game.kList.push_back(keyPair); - } } } - catch( Exception::EndOfStream& ) {} if (game.IsOk()) gList.push_back(game); @@ -165,7 +175,7 @@ public: // Sets the current game to the one matching the serial id given // Returns true if game found, false if not found... bool setGame(const wxString& id) { - deque::iterator it = gList.begin(); + GameDataArray::iterator it( gList.begin() ); for ( ; it != gList.end(); ++it) { if (it[0].id == id) { curGame = &it[0]; @@ -175,7 +185,7 @@ public: curGame = NULL; return false; } - + // Returns true if a game is currently loaded into the database // Returns false if otherwise (this means you need to call setGame() // or it could mean the game was not found in the database at all...) @@ -187,9 +197,9 @@ public: void saveToFile(const wxString& file = L"GameIndex.dbf") { wxFFileOutputStream writer( file ); pxWriteMultiline(writer, header); - deque::iterator it = gList.begin(); + GameDataArray::iterator it( gList.begin() ); for ( ; it != gList.end(); ++it) { - deque::iterator i = it[0].kList.begin(); + KeyPairArray::iterator i = it[0].kList.begin(); for ( ; i != it[0].kList.end(); ++i) { pxWriteMultiline(writer, i[0].toString() ); } @@ -211,7 +221,7 @@ public: // Searches the current game's data to see if the given key exists bool keyExists(const wxChar* key) { if (curGame) { - deque::iterator it = curGame->kList.begin(); + KeyPairArray::iterator it( curGame->kList.begin() ); for ( ; it != curGame->kList.end(); ++it) { if (it[0].CompareKey(key)) { return true; @@ -225,7 +235,7 @@ public: // Totally Deletes the specified key/pair value from the current game's data void deleteKey(const wxChar* key) { if (curGame) { - deque::iterator it = curGame->kList.begin(); + KeyPairArray::iterator it( curGame->kList.begin() ); for ( ; it != curGame->kList.end(); ++it) { if (it[0].CompareKey(key)) { curGame->kList.erase(it); @@ -239,7 +249,7 @@ public: // Gets a string representation of the 'value' for the given key wxString getString(const wxChar* key) { if (curGame) { - deque::iterator it = curGame->kList.begin(); + KeyPairArray::iterator it( curGame->kList.begin() ); for ( ; it != curGame->kList.end(); ++it) { if (it[0].CompareKey(key)) { return it[0].value; @@ -296,7 +306,7 @@ public: // Write a string value to the specified key void writeString(const wxString& key, const wxString& value) { if (curGame) { - deque::iterator it = curGame->kList.begin(); + KeyPairArray::iterator it( curGame->kList.begin() ); for ( ; it != curGame->kList.end(); ++it) { if (it[0].CompareKey(key)) { it[0].value = value; diff --git a/pcsx2/File_Reader.h b/pcsx2/File_Reader.h deleted file mode 100644 index b9d0fb7d57..0000000000 --- a/pcsx2/File_Reader.h +++ /dev/null @@ -1,18 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -using namespace std; diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index 3b6539e3c7..06930cae49 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -530,7 +530,7 @@ public: StartupOptions Startup; CommandlineOverrides Overrides; - wxTimer* m_timer_Termination; + ScopedPtr m_timer_Termination; protected: ScopedPtr m_StdoutRedirHandle; diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp index ad90d8ff94..1433fb289a 100644 --- a/pcsx2/gui/AppInit.cpp +++ b/pcsx2/gui/AppInit.cpp @@ -203,7 +203,7 @@ void Pcsx2App::OpenMainFrame() MainEmuFrame* mainFrame = new MainEmuFrame( NULL, L"PCSX2" ); m_id_MainFrame = mainFrame->GetId(); - PostAppMethod( &Pcsx2App::OpenProgramLog ); + PostIdleAppMethod( &Pcsx2App::OpenProgramLog ); SetTopWindow( mainFrame ); // not really needed... SetExitOnFrameDelete( false ); // but being explicit doesn't hurt... @@ -498,8 +498,6 @@ bool Pcsx2App::OnInit() SysExecutorThread.Start(); DetectCpuAndUserMode(); - if( Startup.ForceConsole ) g_Conf->ProgLogBox.Visible = true; - // Set Manual Exit Handling // ---------------------------- // PCSX2 has a lot of event handling logistics, so we *cannot* depend on wxWidgets automatic event @@ -512,6 +510,9 @@ bool Pcsx2App::OnInit() // Start GUI and/or Direct Emulation // ------------------------------------- + if( Startup.ForceConsole ) g_Conf->ProgLogBox.Visible = true; + PostAppMethod( &Pcsx2App::OpenProgramLog ); + if( m_UseGUI ) PostAppMethod( &Pcsx2App::OpenMainFrame ); @@ -763,6 +764,6 @@ struct CrtDebugBreak } }; -//CrtDebugBreak breakAt( 8564 ); +//CrtDebugBreak breakAt( 2014 ); #endif