Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 23, 2011, 12:45:53 AM (13 years ago)
Author:
landauf
Message:

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Game.cc

    r8729 r8858  
    4040
    4141#include "util/Clock.h"
    42 #include "util/Debug.h"
     42#include "util/Output.h"
    4343#include "util/Exception.h"
    4444#include "util/Sleep.h"
     
    6060    SetConsoleCommand("exit", &stop_game);
    6161    static void printFPS()
    62         { COUT(0) << Game::getInstance().getAvgFPS() << std::endl; }
     62        { orxout(message) << Game::getInstance().getAvgFPS() << endl; }
    6363    SetConsoleCommand("Stats", "printFPS", &printFPS);
    6464    static void printTickTime()
    65         { COUT(0) << Game::getInstance().getAvgTickTime() << std::endl; }
     65        { orxout(message) << Game::getInstance().getAvgTickTime() << endl; }
    6666    SetConsoleCommand("Stats", "printTickTime", &printTickTime);
    6767
     
    8484        , destructionHelper_(this)
    8585    {
     86        orxout(internal_status) << "initializing Game object..." << endl;
     87
    8688#ifdef ORXONOX_PLATFORM_WINDOWS
    8789        minimumSleepTime_ = 1000/*us*/;
     
    106108
    107109        // Create the Core
     110        orxout(internal_info) << "creating Core object:" << endl;
    108111        this->core_ = new Core(cmdLine);
    109112
     
    125128        this->loadedTopStateNode_ = this->rootStateNode_;
    126129        this->loadedStates_.push_back(this->getState(rootStateNode_->name_));
     130
     131        orxout(internal_status) << "finished initializing Game object" << endl;
    127132    }
    128133
    129134    void Game::destroy()
    130135    {
     136        orxout(internal_status) << "destroying Game object..." << endl;
     137
    131138        // Remove us from the object lists again to avoid problems when destroying them
    132139        this->unregisterObject();
     
    139146        safeObjectDelete(&core_);
    140147        safeObjectDelete(&gameClock_);
     148
     149        orxout(internal_status) << "finished destroying Game object..." << endl;
    141150    }
    142151
     
    163172    {
    164173        if (this->requestedStateNodes_.empty())
    165             COUT(0) << "Warning: Starting game without requesting GameState. This automatically terminates the program." << std::endl;
     174            orxout(user_error) << "Starting game without requesting GameState. This automatically terminates the program." << endl;
     175
     176        // Update the GameState stack if required. We do this already here to have a properly initialized game before entering the main loop
     177        this->updateGameStateStack();
     178
     179        orxout(user_status) << "Game loaded" << endl;
     180        orxout(internal_status) << "--------------------------------------------------" << endl;
     181        orxout(internal_status) << "starting main loop..." << endl;
    166182
    167183        // START GAME
     
    189205            catch (...)
    190206            {
    191                 COUT(0) << "An exception occurred in the Core preUpdate: " << Exception::handleMessage() << std::endl;
    192                 COUT(0) << "This should really never happen! Closing the program." << std::endl;
     207                orxout(user_error) << "An exception occurred in the Core preUpdate: " << Exception::handleMessage() << endl;
     208                orxout(user_error) << "This should really never happen! Closing the program." << endl;
    193209                this->stop();
    194210                break;
     
    203219            catch (...)
    204220            {
    205                 COUT(0) << "An exception occurred in the Core postUpdate: " << Exception::handleMessage() << std::endl;
    206                 COUT(0) << "This should really never happen! Closing the program." << std::endl;
     221                orxout(user_error) << "An exception occurred in the Core postUpdate: " << Exception::handleMessage() << endl;
     222                orxout(user_error) << "This should really never happen! Closing the program." << endl;
    207223                this->stop();
    208224                break;
     
    217233                this->updateFPSLimiter();
    218234        }
     235
     236        orxout(internal_status) << "finished main loop" << endl;
     237        orxout(internal_status) << "--------------------------------------------------" << endl;
    219238
    220239        // UNLOAD all remaining states
     
    241260                catch (...)
    242261                {
    243                     COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Exception::handleMessage() << std::endl;
     262                    orxout(user_error) << "Loading GameState '" << requestedStateNode->name_ << "' failed: " << Exception::handleMessage() << endl;
    244263                    // All scheduled operations have now been rendered inert --> flush them and issue a warning
    245264                    if (this->requestedStateNodes_.size() > 1)
    246                         COUT(4) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;
     265                        orxout(internal_info) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << endl;
    247266                    this->requestedStateNodes_.clear();
    248267                    break;
     
    272291            catch (...)
    273292            {
    274                 COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Exception::handleMessage() << std::endl;
    275                 COUT(1) << "This should really never happen!" << std::endl;
    276                 COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
     293                orxout(user_error) << "An exception occurred while updating '" << (*it)->getName() << "': " << Exception::handleMessage() << endl;
     294                orxout(user_error) << "This should really never happen!" << endl;
     295                orxout(user_error) << "Unloading all GameStates depending on the one that crashed." << endl;
    277296                shared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_;
    278297                while (current->name_ != (*it)->getName() && current)
     
    338357    void Game::stop()
    339358    {
     359        orxout(user_status) << "Exit" << endl;
    340360        this->bAbort_ = true;
    341361    }
     
    355375        if (!this->checkState(name))
    356376        {
    357             COUT(2) << "Warning: GameState named '" << name << "' doesn't exist!" << std::endl;
     377            orxout(user_warning) << "GameState named '" << name << "' doesn't exist!" << endl;
    358378            return;
    359379        }
     
    361381        if (this->bChangingState_)
    362382        {
    363             COUT(2) << "Warning: Requesting GameStates while loading/unloading a GameState is illegal! Ignoring." << std::endl;
     383            orxout(user_warning) << "Requesting GameStates while loading/unloading a GameState is illegal! Ignoring." << endl;
    364384            return;
    365385        }
     
    372392        if (name == lastRequestedNode->name_)
    373393        {
    374             COUT(2) << "Warning: Requesting the currently active state! Ignoring." << std::endl;
     394            orxout(user_warning) << "Requesting the currently active state! Ignoring." << endl;
    375395            return;
    376396        }
     
    403423
    404424        if (requestedNodes.empty())
    405             COUT(1) << "Error: Requested GameState transition is not allowed. Ignoring." << std::endl;
     425            orxout(user_error) << "Requested GameState transition is not allowed. Ignoring." << endl;
    406426        else
    407427            this->requestedStateNodes_.insert(requestedStateNodes_.end(), requestedNodes.begin(), requestedNodes.end());
     
    425445            this->requestState(lastRequestedNode->parent_.lock()->name_);
    426446        else
    427             COUT(2) << "Warning: Can't pop the internal dummy root GameState" << std::endl;
     447            orxout(internal_warning) << "Can't pop the internal dummy root GameState" << endl;
    428448    }
    429449
     
    437457            std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.find(name);
    438458            if (it != gameStateDeclarations_s.end())
    439                 COUT(1) << "Error: GameState '" << name << "' has not yet been loaded." << std::endl;
     459                orxout(internal_error) << "GameState '" << name << "' has not yet been loaded." << endl;
    440460            else
    441                 COUT(1) << "Error: Could not find GameState '" << name << "'." << std::endl;
     461                orxout(internal_error) << "Could not find GameState '" << name << "'." << endl;
    442462            return shared_ptr<GameState>();
    443463        }
     
    507527        if (!GameMode::showsGraphics())
    508528        {
     529            orxout(user_status) << "Loading graphics" << endl;
     530            orxout(internal_info) << "loading graphics in Game" << endl;
     531
    509532            core_->loadGraphics();
    510533            Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
     
    524547            }
    525548            graphicsUnloader.Dismiss();
     549
     550            orxout(internal_info) << "finished loading graphics in Game" << endl;
    526551        }
    527552    }
     
    531556        if (GameMode::showsGraphics())
    532557        {
     558            orxout(user_status) << "Unloading graphics" << endl;
     559            orxout(internal_info) << "unloading graphics in Game" << endl;
     560
    533561            // Destroy all the GameStates that require graphics
    534562            for (GameStateMap::iterator it = constructedStates_.begin(); it != constructedStates_.end();)
     
    555583    void Game::loadState(const std::string& name)
    556584    {
     585        orxout(internal_status) << "loading state '" << name << "'" << endl;
     586
    557587        this->bChangingState_ = true;
    558588        LOKI_ON_BLOCK_EXIT_OBJ(*this, &Game::resetChangingState); (void)LOKI_ANONYMOUS_VARIABLE(scopeGuard);
     
    577607    void Game::unloadState(const std::string& name)
    578608    {
     609        orxout(internal_status) << "unloading state '" << name << "'" << endl;
     610
    579611        this->bChangingState_ = true;
    580612        try
     
    589621        catch (...)
    590622        {
    591             COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Exception::handleMessage() << std::endl;
    592             COUT(2) << "         There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
     623            orxout(internal_warning) << "Unloading GameState '" << name << "' threw an exception: " << Exception::handleMessage() << endl;
     624            orxout(internal_warning) << "There might be potential resource leaks involved! To avoid this, improve exception-safety." << endl;
    593625        }
    594626        // Check if graphics is still required
Note: See TracChangeset for help on using the changeset viewer.