1 //----------------------------------------------------------------------------- 2 // App 3 //----------------------------------------------------------------------------- 4 5 #ifndef __APP_H__ 6 #define __APP_H__ 7 8 #include "world.h" 9 #include "demo.h" 10 11 /** 12 * App class. 13 * The app class is the main application class. Every program using the 14 * cake library must create this class. 15 * @bug When I tried to open a map several times, the FPS were not the same. In 16 * fact there was a factor two in difference. Check why. 17 * @bug When path includes missionpack directory, texture colors are not 18 * correct. Lava is green and some walls have a blue tint. 19 * @see World 20 */ 21 class App 22 { 23 private: 24 char app_path[PATH_LENGTH]; /**< current application path */ 25 26 World* world; /**< world map */ 27 28 Client* clients; /**< clients table */ 29 Demo* demos; /**< demos (same number as clients) */ 30 int numclients; /**< number of clients (size of table) */ 31 int curr_client; /**< current client */ 32 33 char curr_map[32]; /**< Currently running map mame*/ 34 bool reloading; /**< Is currently reloading a map */ 35 36 public: 37 App(void); /**< Create application and global variables */ 38 ~App(void); 39 40 /** 41 * Application initialization. 42 * Loads config file, initialize environment files, get system infos, 43 * get shaders list, etc. 44 */ 45 void Init(void); 46 47 void Run(void); 48 void Shut(void); 49 50 /** 51 * Draws a new frame. 52 * This is the main entry to world refresh and redraw. 53 */ 54 void DrawWorld(void); 55 56 /** 57 * Draws the interface. 58 */ 59 void DrawInterface(void); 60 61 /** 62 * Gets the FPS for current frame. 63 * @return the current fps as a double value 64 */ 65 double GetFPS(void); 66 67 /** 68 * Get a pointer to current world. 69 * Return a NULL pointer of no world is currently defined. 70 * @return The current world or a null pointer if no world is defined. 71 */ 72 World* GetWorld(void); 73 74 /** 75 * Get the current loaded map name. 76 * The returned name is the name of the file, and not the name 77 * of the worldspawn entity. 78 * If no map is currently loaded, this function return a null-ended 79 * empty string. 80 * @return The current map name. 81 */ 82 const char* GetCurrentMapName(void); 83 84 /** 85 * Loads a map. 86 * The function loads the given file (if it can) by creating a new world 87 * and new clients. It returns a non zero value if loading could be done 88 * successfully. 89 * @return An integer value that indicates if map could be loaded (non 90 * zero) or not (0). 91 */ 92 int LoadMap(const char* mapname); 93 94 /** 95 * Reload the current map. 96 * The function deletes the current world and reload the current map 97 * in a new world. Clients are not deleted and stay "alive". 98 * @return The same value as LoadMap function. 99 */ 100 int ReloadMap(void); 101 102 /** 103 * Unloads the current map. 104 * The function delete the current world (if defined) but does not 105 * destroy existing clients. Those are destroyed and re-created by the 106 * LoadMap function. 107 */ 108 void UnloadMap(void); 109 110 /** 111 * Start recording a demo. 112 * The recording of a demo can only start if almost one client is defined. 113 * @param framesinterval The interval between demo keyframes. 114 */ 115 void RecordDemo(float framesinterval = 0.1f); 116 117 /** 118 * Stops the current demo. 119 * The function checks if demo is playing or recording and stop it. If the 120 * demo is recording and the parameter is defined, the demo is saved into the 121 * given filename. If demo is recording and no destination file is given, the 122 * function generates a default filename and save the demo into it. Default 123 * filenames are defined as "cakeXXX.demo" where XXX is the demo number. 124 * @param destfile The destination filename for recorded demo saving. 125 */ 126 int StopDemo(const char *destfile = NULL); 127 128 /** 129 * Plays an existing demo. 130 * The function loads a demo and plays it into current client. If the current 131 * client is already playing of recording a demo, the function has no effect. 132 * The function can load a new world if needed by demo. 133 * @param demofile The demo filename to load. 134 * @param loop A boolean value defining if demo must loop when it comes at the 135 * end. 136 * @param mode The interpolation mode for demo playback. 137 */ 138 void PlayDemo(const char *demofile, bool loop, enum_InterpolationMode mode); 139 140 /** 141 * Creates new clients. 142 * This function destroys existing clients and creates new ones. The function 143 * has no effect if one of existing clients is currently playing or recording 144 * a demo. In this case, the function returns 0. 145 * @param num The number of clients to be created. 146 * @return A zero if clients couldn't be created and a non-zero if clients 147 * could be created. 148 */ 149 int CreateClients(int num); 150 151 /** 152 * Gets the number of existing clients. 153 * @return The number of existing clients. 154 */ 155 int GetNumClients(void); 156 157 /** 158 * Sets a client as current default client. 159 * @param num The number of client to be set as default client. 160 */ 161 void SetCurrentClient(int num); 162 163 /** 164 * Get a client. 165 * @param num The index of client in the clients array. 166 * @return A pointer to wished client or a null pointer if it doesn't 167 * exist. 168 */ 169 Client* GetClient(int num); 170 171 /** 172 * Get the current default client. 173 * @return A pointer to current default client or a null pointer if it 174 * doesn't exist. 175 */ 176 Client* GetCurrentClient(void); 177 178 /** 179 * Get the index of current default client. 180 * If no client is available, the function returns -1. 181 * @return The index of current default client. 182 */ 183 int GetCurrentClientIndex(void); 184 185 /** 186 * Initialize the clients. 187 * The function calculates the clients viewport position and size so 188 * they are all visible simultaneous. It is automatically called by 189 * the CreateClients() function and should be called each time the 190 * main window is resized. 191 */ 192 void InitClients(void); 193 }; 194 195 #endif /* __APP_H__ */ 196