27 (*game) -> fade_value = 20 ;
29 (*game) -> GFX_CONFIG_MODE = GFX_DIRECTX_WIN ;
31 (*game) -> nb_min_particles = 0 ;
32 (*game) -> loop_time = 0 ;
33 (*game) -> draw_time = 0 ;
34 (*game) -> logic_time = 0 ;
35 (*game) -> wait_for_slowing_down_cpu = 0 ;
36 (*game) -> GFX_UPDATE_RATE = 20000 ;
37 (*game) -> LOGIC_RATE = 10000 ;
38 (*game) -> real_framerate = 0 ;
39 (*game) -> draw_time = 0 ;
40 (*game) -> score = 0 ;
41 (*game) -> lifes = 100 ;
42 (*game) -> level = 1 ;
46 (*game) -> left_attack = 0 ;
47 (*game) -> right_attack = 0 ;
48 (*game) -> scrbuf = NULL ;
62 if( (*game) -> scrbuf )
63 destroy_bitmap( (*game) -> scrbuf );
78 char strbuf[ 1024 ] =
"" ;
81 config = fopen( config_name,
"rt" );
85 n_log(
LOG_ERR,
"Error %s opening %s !", strerror( errno ), config_name );
93 n_log(
LOG_ERR,
"Error allocating a new game object for %s !", config_name );
97 if( fgets( strbuf, 1024, config ) == NULL )
99 n_log(
LOG_ERR,
"FATAL ERROR: Can not read comment ( line 1 ) in config.txt file !" );
103 if( fgets( strbuf, 1024, config ) == NULL )
105 n_log(
LOG_ERR,
"FATAL ERROR: Can not read GFX_CONFIG_MODE in config.txt file !" );
109 while( it < 1024 && strbuf[ it ] !=
'\0' )
111 if( strbuf[ it ] ==
'\n' )
112 strbuf[ it ] =
'\0' ;
116 if( strcmp( strbuf,
"GFX_AUTODETECT" ) == 0 )
117 game -> GFX_CONFIG_MODE = GFX_AUTODETECT;
118 else if( strcmp( strbuf,
"GFX_AUTODETECT_WINDOWED" ) == 0 )
119 game -> GFX_CONFIG_MODE = GFX_AUTODETECT_WINDOWED;
120 else if( ustrcmp( strbuf,
"GFX_DIRECTX_WIN" ) == 0 )
121 game -> GFX_CONFIG_MODE = GFX_DIRECTX_WIN;
122 else if( ustrcmp( strbuf,
"GFX_DIRECTX" ) == 0 )
123 game -> GFX_CONFIG_MODE = GFX_DIRECTX;
126 n_log(
LOG_NOTICE,
"WARNING: NO USABLE GFX_MODE LOADED FROM CONFIG FILE ! USING DEFAULT GFX_DIRECTX_WIN! tmpstr:\"%s\"", strbuf );
127 game -> GFX_CONFIG_MODE = GFX_DIRECTX_WIN;
130 if( fgets( strbuf, 1024, config ) == NULL )
132 n_log(
LOG_ERR,
"FATAL ERROR: Can not read comment ( line 3 ) in config.txt file !" );
136 if( fgets( strbuf, 1024, config ) == NULL )
138 n_log(
LOG_ERR,
"FATAL ERROR: Can not read CPU_MODE in config.txt file ! \n");
142 if( strncmp( strbuf,
"CPU_USE_FULL", 12 ) == 0 )
144 else if( strncmp( strbuf,
"CPU_USE_NICE", 12 ) == 0 )
146 else if( strncmp( strbuf,
"CPU_USE_LESS", 12 ) == 0 )
149 n_log(
LOG_NOTICE,
"WARNING: NO USABLE CPU_MODE LOADED FROM CONFIG FILE ! USING DEFAULT CPU_FULL_USE !\n" );
152 if( fgets( strbuf, 1024, config ) == NULL )
154 n_log(
LOG_ERR,
"FATAL ERROR: Can not read comment ( line 7 ) in config.txt file !" );
158 if( fgets( strbuf, 1024, config ) == NULL )
160 n_log(
LOG_ERR,
"FATAL ERROR: Can not read nb_min_particles in config.txt file !");
163 game -> nb_min_particles = strtol( strbuf, NULL, 10 );
164 if( game -> nb_min_particles < 10 )
165 game -> nb_min_particles = 10 ;
167 if( fgets( strbuf, 1024, config ) == NULL )
169 n_log(
LOG_ERR,
"FATAL ERROR: Can not read comment ( line 9 ) in config.txt file !" );
173 if( fgets( strbuf, 1024, config ) == NULL )
175 n_log(
LOG_ERR,
"FATAL ERROR: Can not read DRAWING_UPDATE_RATE in config.txt file !");
179 game -> GFX_UPDATE_RATE = strtol( strbuf, NULL, 10 );
181 if( game -> GFX_UPDATE_RATE < 0 )
183 n_log(
LOG_NOTICE,
"WARNING: You can not have a negative or zero GFX_UPDATE_RATE\nDefault value ( 20000 ) will be used" );
184 game -> GFX_UPDATE_RATE = 20000;
186 else if( game -> GFX_UPDATE_RATE > 1000000 )
188 n_log(
LOG_NOTICE,
"WARNING: You would not want to have a 1 second GFX_UPDATE_RATE, no ?\nDefault value ( 20000 ) will be used" );
189 game -> GFX_UPDATE_RATE = 20000;
192 if( fgets( strbuf, 1024, config ) == NULL )
194 n_log(
LOG_ERR,
"FATAL ERROR: Can not read comment ( line 11 ) in config.txt file ! \n");
198 if( fgets( strbuf, 1024, config ) == NULL )
200 n_log(
LOG_ERR,
"FATAL ERROR: Can not read LOGIC_RATE in config.txt file !");
204 game -> LOGIC_RATE = strtol( strbuf, NULL, 10 );
206 if( game -> LOGIC_RATE < 0 )
208 n_log(
LOG_NOTICE,
"WARNING: You can not have a negative or zero LOGIC_RATE\nDefault value ( 10000 ) will be used" );
209 game -> LOGIC_RATE = 10000;
213 if( game -> LOGIC_RATE > 1000000 )
215 n_log(
LOG_NOTICE,
"WARNING: You would not want to have a 1 second LOGIC_RATE, no ?\nDefault value ( 10000 ) will be used" );
216 game -> LOGIC_RATE = 20000;
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define Free(__ptr)
Free Handler to get errors.
void destroy_game_env(GAME_ENV **game)
#define CPU_USE_LESS
wait more
#define CPU_USE_FULL
full use of CPU
GAME_ENV * load_game_config(char *config_name)
load a config from file
int init_game_env(GAME_ENV **game)
#define CPU_USE_NICE
let the other process have some times
Game Environment structure.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
#define LOG_NOTICE
normal but significant condition