Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

main.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 /**
00010  *
00011  * \mainpage
00012  * 
00013  * GenGine is work name for our Game Engine.
00014  * Engine architecture composes of agents responsible for specific action.
00015  * 
00016  * \section AgentPack
00017  * 
00018  * AgentPack groups agents which have something to do. It inits agents, update them and shutdown them at the end.
00019  * 
00020  * Every agent has init(), update() and shutdown() methods. These methods are empty by default.
00021  * 
00022  * Available agents:
00023  *  - MessagerAgent - allows sending messages to agent and other listeners
00024  *  - ScriptAgent - makes scripting possible
00025  *  - OptionAgent - contains global game options
00026  *  - VideoAgent - inits video mode and calls drawers drawOn() method
00027  *  - SoundAgent - plays music and sound
00028  *  - TimerAgent - sleeps constant delay = makes stable FPS
00029  *  - InputAgent - reads input events and handles keystrokes
00030  *  - SubTitleAgent - scrolls subtitles on display
00031  *  - GameAgent - updates game states
00032  * 
00033  * AgentPack will call agents ordered by their names. See Name.cpp for names.
00034  * AgentPack::init() calls init() on all agents. AgentPack::update() calls
00035  * update() on all agents. AgentPack::shutdown() calls shutdown() on all agents.
00036  * 
00037  * 
00038  * \subsection mini_app Minimal application
00039  * \code
00040  * 
00041  * AgentPack *agents = new AgentPack();
00042  * try {
00043  *     agents->addAgent(new ScriptAgent());
00044  *     agents->addAgent(new OptionAgent());
00045  *     agents->init();
00046  * 
00047  *     while (true) {
00048  *         agents->update();
00049  *     }
00050  * }
00051  * catch (BaseException &e) {
00052  *     LOG_ERROR(e.info());
00053  *     agents->shutdown();
00054  * }
00055  * 
00056  * delete agents;
00057  * \endcode
00058  * 
00059  * 
00060  * \note
00061  * MessagerAgent is always included in AgentPack.
00062  * It is need to register every agent as listener during AgentPack::addAgent().
00063  * 
00064  * \section BaseAgent
00065  * 
00066  * Every agent inherits from BaseAgent.
00067  * 
00068  * Rules for agents:
00069  *  -# Agent must not call other agents in his constructor.
00070  *  -# Agent can call only agents with lower names and oneself in his init().
00071  *  -# Agent can call only agents with higher names
00072  *     and oneself in his shutdown().
00073  * 
00074  * For example,
00075  * agent "30video" can ask agent "20option" about screen_width in his init().
00076  * 
00077  * \section Communication
00078  * 
00079  * Every agent has static method agent(). It asks AgentPack::getAgent()
00080  * for agent instance.
00081  * 
00082  * agent() method is made by AGENT(TYPE, NAME) macro. This allows us
00083  * to obtain agent of preferred type and is not need
00084  * to write agent() method for every agent.
00085  * 
00086  * \subsection comm-example How to get screen_width
00087  * \code 
00088  * OptionAgent::agent()->getAsInt("screen_width");
00089  * \endcode
00090  * 
00091  */
00092 
00093 #include "SDL.h"
00094 
00095 #include "Log.h"
00096 #include "Application.h"
00097 #include "HelpException.h"
00098 #include "BaseException.h"
00099 
00100 #include <stdio.h> //printf
00101 
00102 //-----------------------------------------------------------------
00103     int
00104 main(int argc, char *argv[])
00105 {
00106     try {
00107         Application app;
00108 
00109         try {
00110             app.init(argc, argv);
00111             app.run();
00112         }
00113         catch (HelpException &e) {
00114             printf("%s\n", e.what());
00115         }
00116         catch (BaseException &e) {
00117             LOG_ERROR(e.info());
00118         }
00119         app.shutdown();
00120         return 0;
00121     }
00122     catch (BaseException &e) {
00123         LOG_ERROR(e.info());
00124     }
00125     catch (std::exception &e) {
00126         LOG_ERROR(ExInfo("std::exception")
00127                 .addInfo("what", e.what()));
00128     }
00129     catch (...) {
00130         LOG_ERROR(ExInfo("unknown exception"));
00131     }
00132 
00133     return 1;
00134 }
00135 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2