Adonthell  0.4
game.h
Go to the documentation of this file.
1 /*
2  $Id: game.h,v 1.25 2002/04/27 17:00:19 gnurou Exp $
3 
4  Copyright (C) 1999/2000/2001 Kai Sterker <kaisterker@linuxgames.com>
5  Copyright (C) 2002 Alexandre Courbot <alexandrecourbot@linuxgames.com>
6  Part of the Adonthell Project http://adonthell.linuxgames.com
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 
17 /**
18  * @file game.h
19  * @author Kai Sterker <kaisterker@linuxgames.com>
20  * @author Alexandre Courbot <alexandrecourbot@linuxgames.com>
21  *
22  * @brief Declares the game class.
23  *
24  *
25  */
26 
27 
28 
29 #ifndef GAME_H__
30 #define GAME_H__
31 
32 
33 #include <string>
34 #include "types.h"
35 
36 #ifndef SWIG
37 using std::string;
38 #endif
39 
40 /**
41  * Holds information about global settings.
42  *
43  * This static class should be the first to be initialised in your application,
44  * because many others depends on it's correct settings.
45  *
46  */
47 class game
48 {
49 public:
50  static string User_data_dir;
51  static string Global_data_dir;
52  static string Game_data_dir;
53 
54 
55  /**
56  * Initialise the game framework.
57  *
58  * @param game_dir Global data directory.
59  */
60  static void init (string game_dir);
61 
62  /**
63  * Specify an additional data directory containing game data.
64  *
65  * @param game_dir Game data directory.
66  */
67  static void set_game_data_dir (string game_dir);
68 
69  /**
70  * Returns the absolute path to the user data directory (usually ~/.adonthell).
71  *
72  *
73  * @return user data directory
74  */
75  static string user_data_dir ()
76  {
77  return User_data_dir;
78  }
79 
80  /**
81  * Returns the absolute path to the global data directory.
82  *
83  *
84  * @return global data directory
85  */
86  static string global_data_dir ()
87  {
88  return Global_data_dir;
89  }
90 
91  /**
92  * Returns the absolute path to the current game's directory (if any).
93  *
94  *
95  * @return current game data directory, or empty string if none set.
96  */
97  static string game_data_dir ()
98  {
99  return Game_data_dir;
100  }
101 
102  /**
103  * Finds a file in the directories hierarchy, starting searching from
104  * game_data_dir(), then global_data_dir() and finally user_data_dir().
105  *
106  * If a matching file is found, the full absolute path is returned, else
107  * an empty string "" is returned. If the path was already absolute, it is
108  * returned immediatly.
109  *
110  * @param fname name of the find to search for.
111  *
112  * @return complete absolute path to the file if found, passed string if the given
113  * path was already absolute, or "" if the file wasn't found.
114  */
115  static string find_file (const string & fname);
116 
117  /**
118  * Finds a directory in the directories hierarchy, starting searching from
119  * game_data_dir(), then global_data_dir() and finally user_data_dir().
120  *
121  * If a matching directory is found, the full absolute path is returned, else
122  * an empty string "" is returned. If the path was already absolute, it is
123  * returned immediatly.
124  *
125  * @param fname name of the find to search for.
126  *
127  * @return complete absolute path to the directory if found, passed string if the given
128  * path was already absolute, or "" if the directory wasn't found.
129  */
130  static string find_directory (const string & dirname);
131 
132 private:
133  static bool directory_exist (const string & dirname);
134  static bool file_exist (const string & fname);
135 };
136 
137 
138 #endif // GAME_H__
Declares some basic types.
static string find_directory(const string &dirname)
Finds a directory in the directories hierarchy, starting searching from game_data_dir(), then global_data_dir() and finally user_data_dir().
Definition: game.cc:102
static void init(string game_dir)
Initialise the game framework.
Definition: game.cc:38
static string global_data_dir()
Returns the absolute path to the global data directory.
Definition: game.h:86
static string find_file(const string &fname)
Finds a file in the directories hierarchy, starting searching from game_data_dir(), then global_data_dir() and finally user_data_dir().
Definition: game.cc:80
static string game_data_dir()
Returns the absolute path to the current game's directory (if any).
Definition: game.h:97
Holds information about global settings.
Definition: game.h:47
static void set_game_data_dir(string game_dir)
Specify an additional data directory containing game data.
Definition: game.cc:49
static string user_data_dir()
Returns the absolute path to the user data directory (usually ~/.adonthell).
Definition: game.h:75