1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include "stdio.h"
#include <unistd.h>
#include "SDL.h"
extern SDLKey THRUST_KEY,ANTITHRUST_KEY,LEFT_KEY,RIGHT_KEY;
extern SDLKey FIRE_KEY,ATRACTOR_KEY;
extern SDLKey PAUSE_KEY;
extern bool fullscreen;
extern int PIXEL_SIZE;
extern char *datadir;
extern char *confdir;
bool load_configuration(void)
{
int a,b,c,d,e,f,g;
FILE *fp;
chdir(confdir);
fp=fopen("transball.cfg","r");
chdir(datadir);
if (fp==0) return false;
if (7!=fscanf(fp,"%i %i %i %i %i %i %i",&a,&b,&c,&d,&e,&f,&g)) {
fclose(fp);
return false;
} /* if */
if (2!=fscanf(fp,"%i %i",&fullscreen,&PIXEL_SIZE)) {
fclose(fp);
return false;
} /* if */
THRUST_KEY=(SDLKey)a;
ANTITHRUST_KEY=(SDLKey)b;
LEFT_KEY=(SDLKey)c;
RIGHT_KEY=(SDLKey)d;
FIRE_KEY=(SDLKey)e;
ATRACTOR_KEY=(SDLKey)f;
PAUSE_KEY=(SDLKey)g;
fclose(fp);
return true;
} /* load_configuration */
void save_configuration(void)
{
FILE *fp;
chdir(confdir);
fp=fopen("transball.cfg","w");
chdir(datadir);
if (fp==0) return;
fprintf(fp,"%i %i %i %i %i %i %i\n",(int)THRUST_KEY,(int)ANTITHRUST_KEY,(int)LEFT_KEY,(int)RIGHT_KEY,
(int)FIRE_KEY,(int)ATRACTOR_KEY,(int)PAUSE_KEY);
fprintf(fp,"%i %i\n",(int)fullscreen,PIXEL_SIZE);
fclose(fp);
} /* save_configuration */
|