Adonthell
0.4
|
00001 /* 00002 $Id: game.h,v 1.25 2002/04/27 17:00:19 gnurou Exp $ 00003 00004 Copyright (C) 1999/2000/2001 Kai Sterker <kaisterker@linuxgames.com> 00005 Copyright (C) 2002 Alexandre Courbot <alexandrecourbot@linuxgames.com> 00006 Part of the Adonthell Project http://adonthell.linuxgames.com 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 00017 /** 00018 * @file game.h 00019 * @author Kai Sterker <kaisterker@linuxgames.com> 00020 * @author Alexandre Courbot <alexandrecourbot@linuxgames.com> 00021 * 00022 * @brief Declares the game class. 00023 * 00024 * 00025 */ 00026 00027 00028 00029 #ifndef GAME_H__ 00030 #define GAME_H__ 00031 00032 00033 #include <string> 00034 #include "types.h" 00035 00036 #ifndef SWIG 00037 using std::string; 00038 #endif 00039 00040 /** 00041 * Holds information about global settings. 00042 * 00043 * This static class should be the first to be initialised in your application, 00044 * because many others depends on it's correct settings. 00045 * 00046 */ 00047 class game 00048 { 00049 public: 00050 static string User_data_dir; 00051 static string Global_data_dir; 00052 static string Game_data_dir; 00053 00054 00055 /** 00056 * Initialise the game framework. 00057 * 00058 * @param game_dir Global data directory. 00059 */ 00060 static void init (string game_dir); 00061 00062 /** 00063 * Specify an additional data directory containing game data. 00064 * 00065 * @param game_dir Game data directory. 00066 */ 00067 static void set_game_data_dir (string game_dir); 00068 00069 /** 00070 * Returns the absolute path to the user data directory (usually ~/.adonthell). 00071 * 00072 * 00073 * @return user data directory 00074 */ 00075 static string user_data_dir () 00076 { 00077 return User_data_dir; 00078 } 00079 00080 /** 00081 * Returns the absolute path to the global data directory. 00082 * 00083 * 00084 * @return global data directory 00085 */ 00086 static string global_data_dir () 00087 { 00088 return Global_data_dir; 00089 } 00090 00091 /** 00092 * Returns the absolute path to the current game's directory (if any). 00093 * 00094 * 00095 * @return current game data directory, or empty string if none set. 00096 */ 00097 static string game_data_dir () 00098 { 00099 return Game_data_dir; 00100 } 00101 00102 /** 00103 * Finds a file in the directories hierarchy, starting searching from 00104 * game_data_dir(), then global_data_dir() and finally user_data_dir(). 00105 * 00106 * If a matching file is found, the full absolute path is returned, else 00107 * an empty string "" is returned. If the path was already absolute, it is 00108 * returned immediatly. 00109 * 00110 * @param fname name of the find to search for. 00111 * 00112 * @return complete absolute path to the file if found, passed string if the given 00113 * path was already absolute, or "" if the file wasn't found. 00114 */ 00115 static string find_file (const string & fname); 00116 00117 /** 00118 * Finds a directory in the directories hierarchy, starting searching from 00119 * game_data_dir(), then global_data_dir() and finally user_data_dir(). 00120 * 00121 * If a matching directory is found, the full absolute path is returned, else 00122 * an empty string "" is returned. If the path was already absolute, it is 00123 * returned immediatly. 00124 * 00125 * @param fname name of the find to search for. 00126 * 00127 * @return complete absolute path to the directory if found, passed string if the given 00128 * path was already absolute, or "" if the directory wasn't found. 00129 */ 00130 static string find_directory (const string & dirname); 00131 00132 private: 00133 static bool directory_exist (const string & dirname); 00134 static bool file_exist (const string & fname); 00135 }; 00136 00137 00138 #endif // GAME_H__