| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
/** |
| 10 |
* |
| 11 |
* \mainpage |
| 12 |
* |
| 13 |
* GenGine is work name for our Game Engine. |
| 14 |
* Engine architecture composes of agents responsible for specific action. |
| 15 |
* |
| 16 |
* \section AgentPack |
| 17 |
* |
| 18 |
* AgentPack groups agents which have something to do. It inits agents, update them and shutdown them at the end. |
| 19 |
* |
| 20 |
* Every agent has init(), update() and shutdown() methods. These methods are empty by default. |
| 21 |
* |
| 22 |
* Available agents: |
| 23 |
* - MessagerAgent - allows sending messages to agent and other listeners |
| 24 |
* - ScriptAgent - makes scripting possible |
| 25 |
* - OptionAgent - contains global game options |
| 26 |
* - VideoAgent - inits video mode and calls drawers drawOn() method |
| 27 |
* - SoundAgent - plays music and sound |
| 28 |
* - TimerAgent - sleeps constant delay = makes stable FPS |
| 29 |
* - InputAgent - reads input events and handles keystrokes |
| 30 |
* - SubTitleAgent - scrolls subtitles on display |
| 31 |
* - GameAgent - updates game states |
| 32 |
* |
| 33 |
* AgentPack will call agents ordered by their names. See Name.cpp for names. |
| 34 |
* AgentPack::init() calls init() on all agents. AgentPack::update() calls |
| 35 |
* update() on all agents. AgentPack::shutdown() calls shutdown() on all agents. |
| 36 |
* |
| 37 |
* |
| 38 |
* \subsection mini_app Minimal application |
| 39 |
* \code |
| 40 |
* |
| 41 |
* AgentPack *agents = new AgentPack(); |
| 42 |
* try { |
| 43 |
* agents->addAgent(new ScriptAgent()); |
| 44 |
* agents->addAgent(new OptionAgent()); |
| 45 |
* agents->init(); |
| 46 |
* |
| 47 |
* while (true) { |
| 48 |
* agents->update(); |
| 49 |
* } |
| 50 |
* } |
| 51 |
* catch (BaseException &e) { |
| 52 |
* LOG_ERROR(e.info()); |
| 53 |
* agents->shutdown(); |
| 54 |
* } |
| 55 |
* |
| 56 |
* delete agents; |
| 57 |
* \endcode |
| 58 |
* |
| 59 |
* |
| 60 |
* \note |
| 61 |
* MessagerAgent is always included in AgentPack. |
| 62 |
* It is need to register every agent as listener during AgentPack::addAgent(). |
| 63 |
* |
| 64 |
* \section BaseAgent |
| 65 |
* |
| 66 |
* Every agent inherits from BaseAgent. |
| 67 |
* |
| 68 |
* Rules for agents: |
| 69 |
* -# Agent must not call other agents in his constructor. |
| 70 |
* -# Agent can call only agents with lower names and oneself in his init(). |
| 71 |
* -# Agent can call only agents with higher names |
| 72 |
* and oneself in his shutdown(). |
| 73 |
* |
| 74 |
* For example, |
| 75 |
* agent "30video" can ask agent "20option" about screen_width in his init(). |
| 76 |
* |
| 77 |
* \section Communication |
| 78 |
* |
| 79 |
* Every agent has static method agent(). It asks AgentPack::getAgent() |
| 80 |
* for agent instance. |
| 81 |
* |
| 82 |
* agent() method is made by AGENT(TYPE, NAME) macro. This allows us |
| 83 |
* to obtain agent of preferred type and is not need |
| 84 |
* to write agent() method for every agent. |
| 85 |
* |
| 86 |
* \subsection comm-example How to get screen_width |
| 87 |
* \code |
| 88 |
* OptionAgent::agent()->getAsInt("screen_width"); |
| 89 |
* \endcode |
| 90 |
* |
| 91 |
*/ |
| 92 |
|
| 93 |
#include "SDL.h" |
| 94 |
|
| 95 |
#include "Log.h" |
| 96 |
#include "Application.h" |
| 97 |
#include "HelpException.h" |
| 98 |
#include "BaseException.h" |
| 99 |
|
| 100 |
#include <stdio.h> //printf |
| 101 |
|
| 102 |
//----------------------------------------------------------------- |
| 103 |
int |
| 104 |
main(int argc, char *argv[]) |
| 105 |
{ |
| 106 |
try { |
| 107 |
Application app; |
| 108 |
|
| 109 |
try { |
| 110 |
app.init(argc, argv); |
| 111 |
app.run(); |
| 112 |
} |
| 113 |
catch (HelpException &e) { |
| 114 |
printf("%s\n", e.what()); |
| 115 |
} |
| 116 |
catch (BaseException &e) { |
| 117 |
LOG_ERROR(e.info()); |
| 118 |
} |
| 119 |
app.shutdown(); |
| 120 |
return 0; |
| 121 |
} |
| 122 |
catch (BaseException &e) { |
| 123 |
LOG_ERROR(e.info()); |
| 124 |
} |
| 125 |
catch (std::exception &e) { |
| 126 |
LOG_ERROR(ExInfo("std::exception") |
| 127 |
.addInfo("what", e.what())); |
| 128 |
} |
| 129 |
catch (...) { |
| 130 |
LOG_ERROR(ExInfo("unknown exception")); |
| 131 |
} |
| 132 |
|
| 133 |
return 1; |
| 134 |
} |
| 135 |
|