#define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2"
+/* ========================================================================= */
+/* level file functions */
+/* ========================================================================= */
+
static void setLevelInfoToDefaults()
{
int i, x, y;
SetFilePermissions(filename, PERMS_PRIVATE);
}
+
+/* ========================================================================= */
+/* tape file functions */
+/* ========================================================================= */
+
static void setTapeInfoToDefaults()
{
int i;
printf("-------------------------------------------------------------------------------\n");
}
+
+/* ========================================================================= */
+/* score file functions */
+/* ========================================================================= */
+
void LoadScore(int level_nr)
{
int i;
SetFilePermissions(filename, PERMS_PUBLIC);
}
+
+
+/* ========================================================================= */
+/* setup file functions */
+/* ========================================================================= */
+
+#define TOKEN_STR_PLAYER_PREFIX "player_"
+
+/* global setup */
+#define SETUP_TOKEN_PLAYER_NAME 0
+#define SETUP_TOKEN_SOUND 1
+#define SETUP_TOKEN_SOUND_LOOPS 2
+#define SETUP_TOKEN_SOUND_MUSIC 3
+#define SETUP_TOKEN_SOUND_SIMPLE 4
+#define SETUP_TOKEN_SCROLL_DELAY 5
+#define SETUP_TOKEN_SOFT_SCROLLING 6
+#define SETUP_TOKEN_FADING 7
+#define SETUP_TOKEN_AUTORECORD 8
+#define SETUP_TOKEN_QUICK_DOORS 9
+#define SETUP_TOKEN_TEAM_MODE 10
+#define SETUP_TOKEN_HANDICAP 11
+#define SETUP_TOKEN_TIME_LIMIT 12
+#define SETUP_TOKEN_FULLSCREEN 13
+
+#define NUM_GLOBAL_SETUP_TOKENS 14
+
+/* player setup */
+#define SETUP_TOKEN_USE_JOYSTICK 0
+#define SETUP_TOKEN_JOY_DEVICE_NAME 1
+#define SETUP_TOKEN_JOY_XLEFT 2
+#define SETUP_TOKEN_JOY_XMIDDLE 3
+#define SETUP_TOKEN_JOY_XRIGHT 4
+#define SETUP_TOKEN_JOY_YUPPER 5
+#define SETUP_TOKEN_JOY_YMIDDLE 6
+#define SETUP_TOKEN_JOY_YLOWER 7
+#define SETUP_TOKEN_JOY_SNAP 8
+#define SETUP_TOKEN_JOY_BOMB 9
+#define SETUP_TOKEN_KEY_LEFT 10
+#define SETUP_TOKEN_KEY_RIGHT 11
+#define SETUP_TOKEN_KEY_UP 12
+#define SETUP_TOKEN_KEY_DOWN 13
+#define SETUP_TOKEN_KEY_SNAP 14
+#define SETUP_TOKEN_KEY_BOMB 15
+
+#define NUM_PLAYER_SETUP_TOKENS 16
+
+static struct SetupInfo si;
+static struct SetupInputInfo sii;
+
+static struct TokenInfo global_setup_tokens[] =
+{
+ /* global setup */
+ { TYPE_STRING, &si.player_name, "player_name" },
+ { TYPE_SWITCH, &si.sound, "sound" },
+ { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" },
+ { TYPE_SWITCH, &si.sound_music, "background_music" },
+ { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" },
+ { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" },
+ { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" },
+ { TYPE_SWITCH, &si.fading, "screen_fading" },
+ { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" },
+ { TYPE_SWITCH, &si.quick_doors, "quick_doors" },
+ { TYPE_SWITCH, &si.team_mode, "team_mode" },
+ { TYPE_SWITCH, &si.handicap, "handicap" },
+ { TYPE_SWITCH, &si.time_limit, "time_limit" },
+ { TYPE_SWITCH, &si.fullscreen, "fullscreen" }
+};
+
+static struct TokenInfo player_setup_tokens[] =
+{
+ /* player setup */
+ { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" },
+ { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" },
+ { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" },
+ { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" },
+ { TYPE_INTEGER, &sii.joy.xright, ".joy.xright" },
+ { TYPE_INTEGER, &sii.joy.yupper, ".joy.yupper" },
+ { TYPE_INTEGER, &sii.joy.ymiddle, ".joy.ymiddle" },
+ { TYPE_INTEGER, &sii.joy.ylower, ".joy.ylower" },
+ { TYPE_INTEGER, &sii.joy.snap, ".joy.snap_field" },
+ { TYPE_INTEGER, &sii.joy.bomb, ".joy.place_bomb" },
+ { TYPE_KEY, &sii.key.left, ".key.move_left" },
+ { TYPE_KEY, &sii.key.right, ".key.move_right" },
+ { TYPE_KEY, &sii.key.up, ".key.move_up" },
+ { TYPE_KEY, &sii.key.down, ".key.move_down" },
+ { TYPE_KEY, &sii.key.snap, ".key.snap_field" },
+ { TYPE_KEY, &sii.key.bomb, ".key.place_bomb" }
+};
+
+static void setSetupInfoToDefaults(struct SetupInfo *si)
+{
+ int i;
+
+ si->player_name = getStringCopy(getLoginName());
+
+ si->sound = TRUE;
+ si->sound_loops = TRUE;
+ si->sound_music = TRUE;
+ si->sound_simple = TRUE;
+ si->toons = TRUE;
+ si->double_buffering = TRUE;
+ si->direct_draw = !si->double_buffering;
+ si->scroll_delay = TRUE;
+ si->soft_scrolling = TRUE;
+ si->fading = FALSE;
+ si->autorecord = TRUE;
+ si->quick_doors = FALSE;
+ si->team_mode = FALSE;
+ si->handicap = TRUE;
+ si->time_limit = TRUE;
+ si->fullscreen = FALSE;
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ si->input[i].use_joystick = FALSE;
+ si->input[i].joy.device_name=getStringCopy(getDeviceNameFromJoystickNr(i));
+ si->input[i].joy.xleft = JOYSTICK_XLEFT;
+ si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
+ si->input[i].joy.xright = JOYSTICK_XRIGHT;
+ si->input[i].joy.yupper = JOYSTICK_YUPPER;
+ si->input[i].joy.ymiddle = JOYSTICK_YMIDDLE;
+ si->input[i].joy.ylower = JOYSTICK_YLOWER;
+ si->input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0);
+ si->input[i].joy.bomb = (i == 0 ? JOY_BUTTON_2 : 0);
+ si->input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KSYM_UNDEFINED);
+ si->input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KSYM_UNDEFINED);
+ si->input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KSYM_UNDEFINED);
+ si->input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KSYM_UNDEFINED);
+ si->input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KSYM_UNDEFINED);
+ si->input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KSYM_UNDEFINED);
+ }
+}
+
+static void decodeSetupFileList(struct SetupFileList *setup_file_list)
+{
+ int i, pnr;
+
+ if (!setup_file_list)
+ return;
+
+ /* handle global setup values */
+ si = setup;
+ for (i=0; i<NUM_GLOBAL_SETUP_TOKENS; i++)
+ setSetupInfo(global_setup_tokens, i,
+ getTokenValue(setup_file_list, global_setup_tokens[i].text));
+ setup = si;
+
+ /* handle player specific setup values */
+ for (pnr=0; pnr<MAX_PLAYERS; pnr++)
+ {
+ char prefix[30];
+
+ sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
+
+ sii = setup.input[pnr];
+ for (i=0; i<NUM_PLAYER_SETUP_TOKENS; i++)
+ {
+ char full_token[100];
+
+ sprintf(full_token, "%s%s", prefix, player_setup_tokens[i].text);
+ setSetupInfo(player_setup_tokens, i,
+ getTokenValue(setup_file_list, full_token));
+ }
+ setup.input[pnr] = sii;
+ }
+}
+
+void LoadSetup()
+{
+ char *filename = getSetupFilename();
+ struct SetupFileList *setup_file_list = NULL;
+
+ /* always start with reliable default values */
+ setSetupInfoToDefaults(&setup);
+
+ setup_file_list = loadSetupFileList(filename);
+
+ if (setup_file_list)
+ {
+ checkSetupFileListIdentifier(setup_file_list, getCookie("SETUP"));
+ decodeSetupFileList(setup_file_list);
+
+ setup.direct_draw = !setup.double_buffering;
+
+ freeSetupFileList(setup_file_list);
+
+ /* needed to work around problems with fixed length strings */
+ if (strlen(setup.player_name) > MAX_PLAYER_NAME_LEN)
+ setup.player_name[MAX_PLAYER_NAME_LEN] = '\0';
+ else if (strlen(setup.player_name) < MAX_PLAYER_NAME_LEN)
+ {
+ char *new_name = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
+
+ strcpy(new_name, setup.player_name);
+ free(setup.player_name);
+ setup.player_name = new_name;
+ }
+ }
+ else
+ Error(ERR_WARN, "using default setup values");
+}
+
+void SaveSetup()
+{
+ char *filename = getSetupFilename();
+ FILE *file;
+ int i, pnr;
+
+ InitUserDataDirectory();
+
+ if (!(file = fopen(filename, MODE_WRITE)))
+ {
+ Error(ERR_WARN, "cannot write setup file '%s'", filename);
+ return;
+ }
+
+ fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
+ getCookie("SETUP")));
+ fprintf(file, "\n");
+
+ /* handle global setup values */
+ si = setup;
+ for (i=0; i<NUM_GLOBAL_SETUP_TOKENS; i++)
+ {
+ fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));
+
+ /* just to make things nicer :) */
+ if (i == SETUP_TOKEN_PLAYER_NAME)
+ fprintf(file, "\n");
+ }
+
+ /* handle player specific setup values */
+ for (pnr=0; pnr<MAX_PLAYERS; pnr++)
+ {
+ char prefix[30];
+
+ sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
+ fprintf(file, "\n");
+
+ sii = setup.input[pnr];
+ for (i=0; i<NUM_PLAYER_SETUP_TOKENS; i++)
+ fprintf(file, "%s\n", getSetupLine(player_setup_tokens, prefix, i));
+ }
+
+ fclose(file);
+
+ SetFilePermissions(filename, PERMS_PRIVATE);
+}
void LoadScore(int);
void SaveScore(int);
+void LoadSetup(void);
+void SaveSetup(void);
+
#endif /* FILES_H */
InitProgramInfo(UNIX_USERDATA_DIRECTORY,
PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
- MSDOS_POINTER_FILENAME);
+ MSDOS_POINTER_FILENAME,
+ COOKIE_PREFIX, GAME_VERSION_ACTUAL);
InitPlayerInfo();
StartSoundserver();
}
-void InitJoysticks()
-{
-#if defined(TARGET_SDL)
- static boolean sdl_joystick_subsystem_initialized = FALSE;
-#endif
-
- int i;
-
- /* always start with reliable default values */
- joystick.status = JOYSTICK_NOT_AVAILABLE;
- for (i=0; i<MAX_PLAYERS; i++)
- joystick.fd[i] = -1; /* joystick device closed */
-
- if (global_joystick_status == JOYSTICK_NOT_AVAILABLE)
- return;
-
-#if defined(TARGET_SDL)
-
- if (!sdl_joystick_subsystem_initialized)
- {
- sdl_joystick_subsystem_initialized = TRUE;
-
- if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
- {
- Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
- return;
- }
- }
-
- for (i=0; i<MAX_PLAYERS; i++)
- {
- char *device_name = setup.input[i].joy.device_name;
- int joystick_nr = getJoystickNrFromDeviceName(device_name);
-
- if (joystick_nr >= SDL_NumJoysticks())
- joystick_nr = -1;
-
- /* misuse joystick file descriptor variable to store joystick number */
- joystick.fd[i] = joystick_nr;
-
- /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
- if (Check_SDL_JoystickOpened(joystick_nr))
- Close_SDL_Joystick(joystick_nr);
-
- if (!setup.input[i].use_joystick)
- continue;
-
- if (!Open_SDL_Joystick(joystick_nr))
- {
- Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
- continue;
- }
-
- joystick.status = JOYSTICK_ACTIVATED;
- }
-
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
- for (i=0; i<MAX_PLAYERS; i++)
- {
- char *device_name = setup.input[i].joy.device_name;
-
- /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
- if (joystick.fd[i] != -1)
- {
- close(joystick.fd[i]);
- joystick.fd[i] = -1;
- }
-
- if (!setup.input[i].use_joystick)
- continue;
-
- if (access(device_name, R_OK) != 0)
- {
- Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
- continue;
- }
-
- if ((joystick.fd[i] = open(device_name, O_RDONLY)) < 0)
- {
- Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
- continue;
- }
-
- joystick.status = JOYSTICK_ACTIVATED;
- }
-
-#else /* !PLATFORM_UNIX */
-
- /* try to access two joysticks; if that fails, try to access just one */
- if (install_joystick(JOY_TYPE_2PADS) == 0 ||
- install_joystick(JOY_TYPE_AUTODETECT) == 0)
- joystick.status = JOYSTICK_ACTIVATED;
-
- /*
- load_joystick_data(JOYSTICK_FILENAME);
- */
-
- for (i=0; i<MAX_PLAYERS; i++)
- {
- char *device_name = setup.input[i].joy.device_name;
- int joystick_nr = getJoystickNrFromDeviceName(device_name);
-
- if (joystick_nr >= num_joysticks)
- joystick_nr = -1;
-
- /* misuse joystick file descriptor variable to store joystick number */
- joystick.fd[i] = joystick_nr;
- }
-#endif
-
-#endif /* !TARGET_SDL */
-}
-
void InitGfx()
{
int i;
void OpenAll(void);
void CloseAllAndExit(int);
-void InitJoysticks(void);
#endif
#include "misc.h"
-#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
-#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
+/* ========================================================================= */
+/* platform dependant joystick functions */
+/* ========================================================================= */
+
+#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL)
+void UnixInitJoysticks()
+{
+ int i;
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ char *device_name = setup.input[i].joy.device_name;
+
+ /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
+ if (joystick.fd[i] != -1)
+ {
+ close(joystick.fd[i]);
+ joystick.fd[i] = -1;
+ }
+
+ if (!setup.input[i].use_joystick)
+ continue;
-#if 0
-static int joystick_device = 0;
-char *joystick_device_name[MAX_PLAYERS] =
+ if (access(device_name, R_OK) != 0)
+ {
+ Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
+ continue;
+ }
+
+ if ((joystick.fd[i] = open(device_name, O_RDONLY)) < 0)
+ {
+ Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
+ continue;
+ }
+
+ joystick.status = JOYSTICK_ACTIVATED;
+ }
+}
+
+boolean UnixReadJoystick(int fd, int *x, int *y, boolean *b1, boolean *b2)
{
- DEV_JOYSTICK_0,
- DEV_JOYSTICK_1,
- DEV_JOYSTICK_2,
- DEV_JOYSTICK_3
-};
+#if defined(PLATFORM_FREEBSD)
+ struct joystick joy_ctrl;
+#else
+ struct joystick_control
+ {
+ int buttons;
+ int x;
+ int y;
+ } joy_ctrl;
+#endif
+
+ if (read(fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
+ return FALSE;
+
+ if (x != NULL)
+ *x = joy_ctrl.x;
+ if (y != NULL)
+ *y = joy_ctrl.y;
+
+#if defined(PLATFORM_FREEBSD)
+ if (b1 != NULL)
+ *b1 = joy_ctrl.b1;
+ if (b2 != NULL)
+ *b2 = joy_ctrl.b2;
+#else
+ if (b1 != NULL)
+ *b1 = joy_ctrl.buttons & 1;
+ if (b2 != NULL)
+ *b2 = joy_ctrl.buttons & 2;
#endif
+ return TRUE;
+}
+#endif /* PLATFORM_UNIX && !TARGET_SDL */
+
+
+/* ========================================================================= */
+/* platform independant joystick functions */
+/* ========================================================================= */
+
+#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
+#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
void translate_joyname(int *joysymbol, char **name, int mode)
{
joystick_device_name[joystick_nr] : "");
}
-#if !defined(PLATFORM_MSDOS)
-static int JoystickPosition(int middle, int margin, int actual)
-{
- long range, pos;
- int percentage;
-
- if (margin < middle && actual > middle)
- return 0;
- if (margin > middle && actual < middle)
- return 0;
-
- range = ABS(margin - middle);
- pos = ABS(actual - middle);
- percentage = (int)(pos * 100 / range);
-
- if (percentage > 100)
- percentage = 100;
-
- return percentage;
-}
-#endif
-
-#if defined(TARGET_SDL)
-
-static SDL_Joystick *sdl_joystick[MAX_PLAYERS] = { NULL, NULL, NULL, NULL };
-static int sdl_js_axis[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
-static int sdl_js_button[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
-
-SDL_Joystick *Get_SDL_Joystick(int nr)
-{
- return sdl_joystick[nr];
-}
-
-boolean Open_SDL_Joystick(int nr)
-{
- if (nr < 0 || nr > MAX_PLAYERS)
- return FALSE;
-
- return ((sdl_joystick[nr] = SDL_JoystickOpen(nr)) == NULL ? FALSE : TRUE);
-}
-
-void Close_SDL_Joystick(int nr)
-{
- if (nr < 0 || nr > MAX_PLAYERS)
- return;
-
- SDL_JoystickClose(sdl_joystick[nr]);
-}
-
-boolean Check_SDL_JoystickOpened(int nr)
-{
- if (nr < 0 || nr > MAX_PLAYERS)
- return FALSE;
-
- return (SDL_JoystickOpened(nr) ? TRUE : FALSE);
-}
-
-void HandleJoystickEvent(Event *event)
-{
- switch(event->type)
- {
- case SDL_JOYAXISMOTION:
- if (event->jaxis.axis < 2)
- {
- sdl_js_axis[event->jaxis.which][event->jaxis.axis]= event->jaxis.value;
-
-#if 0
- printf("js_%d %s-axis: %d\n",
- event->jaxis.which,
- (event->jaxis.axis == 0 ? "x" : "y"),
- event->jaxis.value);
-#endif
- }
- break;
-
- case SDL_JOYBUTTONDOWN:
- if (event->jbutton.button < 2)
- {
- sdl_js_button[event->jbutton.which][event->jbutton.button] = TRUE;
-
-#if 0
- printf("js_%d button %d: pressed\n",
- event->jbutton.which,
- event->jbutton.button);
-#endif
- }
- break;
-
- case SDL_JOYBUTTONUP:
- if (event->jbutton.button < 2)
- {
- sdl_js_button[event->jbutton.which][event->jbutton.button] = FALSE;
-
-#if 0
- printf("js_%d button %d: released\n",
- event->jbutton.which,
- event->jbutton.button);
-#endif
- }
- break;
-
- default:
- break;
- }
-}
-
-int Get_SDL_Joystick_Axis(int nr, int axis)
-{
- if (nr < 0 || nr > MAX_PLAYERS)
- return 0;
-
- if (axis < 0 || axis > 1)
- return 0;
-
- return sdl_js_axis[nr][axis];
-}
-
-void CheckJoystickData()
-{
-}
-
-int Joystick(int player_nr)
+static int JoystickPositionPercent(int center, int border, int actual)
{
-#if 0
- int joystick_nr = stored_player[player_nr].joystick_fd;
-#else
- int joystick_nr = joystick.fd[player_nr];
-#endif
- int js_x,js_y, js_b1,js_b2;
- int left, right, up, down;
- int result = 0;
+ long range, position;
+ int percent;
- if (joystick.status != JOYSTICK_ACTIVATED)
+ if (border < center && actual > center)
return 0;
-
- if (!setup.input[player_nr].use_joystick ||
- !Check_SDL_JoystickOpened(joystick_nr))
+ if (border > center && actual < center)
return 0;
- js_x = sdl_js_axis[joystick_nr][0];
- js_y = sdl_js_axis[joystick_nr][1];
-
- js_b1 = sdl_js_button[joystick_nr][0];
- js_b2 = sdl_js_button[joystick_nr][1];
-
-
-
-#if 0
- printf("JOYSTICK %d: js_x == %d, js_y == %d, js_b1 == %d, js_b2 == %d\n",
- joystick_nr, js_x, js_y, js_b1, js_b2);
-#endif
-
-
-
- left = JoystickPosition(setup.input[player_nr].joy.xmiddle,
- setup.input[player_nr].joy.xleft, js_x);
- right = JoystickPosition(setup.input[player_nr].joy.xmiddle,
- setup.input[player_nr].joy.xright, js_x);
- up = JoystickPosition(setup.input[player_nr].joy.ymiddle,
- setup.input[player_nr].joy.yupper, js_y);
- down = JoystickPosition(setup.input[player_nr].joy.ymiddle,
- setup.input[player_nr].joy.ylower, js_y);
-
- if (left > JOYSTICK_PERCENT)
- result |= JOY_LEFT;
- else if (right > JOYSTICK_PERCENT)
- result |= JOY_RIGHT;
- if (up > JOYSTICK_PERCENT)
- result |= JOY_UP;
- else if (down > JOYSTICK_PERCENT)
- result |= JOY_DOWN;
-
- if (js_b1)
- result |= JOY_BUTTON_1;
- if (js_b2)
- result |= JOY_BUTTON_2;
-
+ range = ABS(border - center);
+ position = ABS(actual - center);
+ percent = (int)(position * 100 / range);
-#if 0
- printf("result == 0x%08x\n", result);
-#endif
-
+ if (percent > 100)
+ percent = 100;
-
- return result;
+ return percent;
}
-#else /* !TARGET_SDL */
-
void CheckJoystickData()
{
int i;
for(i=0; i<MAX_PLAYERS; i++)
{
- if (setup.input[i].joy.xmiddle <= distance)
- setup.input[i].joy.xmiddle = distance;
- if (setup.input[i].joy.ymiddle <= distance)
- setup.input[i].joy.ymiddle = distance;
-
if (setup.input[i].joy.xleft >= setup.input[i].joy.xmiddle)
setup.input[i].joy.xleft = setup.input[i].joy.xmiddle - distance;
if (setup.input[i].joy.xright <= setup.input[i].joy.xmiddle)
}
}
-#if defined(PLATFORM_UNIX)
int Joystick(int player_nr)
{
-#if defined(PLATFORM_FREEBSD)
- struct joystick joy_ctrl;
-#else
- struct joystick_control
- {
- int buttons;
- int x;
- int y;
- } joy_ctrl;
-#endif
-
-#if 0
- int joystick_fd = stored_player[player_nr].joystick_fd;
-#else
int joystick_fd = joystick.fd[player_nr];
-#endif
- int js_x,js_y, js_b1,js_b2;
+ int js_x, js_y;
+ boolean js_b1, js_b2;
int left, right, up, down;
- int result = 0;
+ int result = JOY_NO_ACTION;
if (joystick.status != JOYSTICK_ACTIVATED)
- return 0;
+ return JOY_NO_ACTION;
if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
- return 0;
+ return JOY_NO_ACTION;
- if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
+ if (!ReadJoystick(joystick_fd, &js_x, &js_y, &js_b1, &js_b2))
{
Error(ERR_WARN, "cannot read joystick device '%s'",
setup.input[player_nr].joy.device_name);
+
joystick.status = JOYSTICK_NOT_AVAILABLE;
- return 0;
+ return JOY_NO_ACTION;
}
- js_x = joy_ctrl.x;
- js_y = joy_ctrl.y;
-
-#if defined(PLATFORM_FREEBSD)
- js_b1 = joy_ctrl.b1;
- js_b2 = joy_ctrl.b2;
-#else
- js_b1 = joy_ctrl.buttons & 1;
- js_b2 = joy_ctrl.buttons & 2;
-#endif
-
- left = JoystickPosition(setup.input[player_nr].joy.xmiddle,
- setup.input[player_nr].joy.xleft, js_x);
- right = JoystickPosition(setup.input[player_nr].joy.xmiddle,
- setup.input[player_nr].joy.xright, js_x);
- up = JoystickPosition(setup.input[player_nr].joy.ymiddle,
- setup.input[player_nr].joy.yupper, js_y);
- down = JoystickPosition(setup.input[player_nr].joy.ymiddle,
- setup.input[player_nr].joy.ylower, js_y);
+ left = JoystickPositionPercent(setup.input[player_nr].joy.xmiddle,
+ setup.input[player_nr].joy.xleft, js_x);
+ right = JoystickPositionPercent(setup.input[player_nr].joy.xmiddle,
+ setup.input[player_nr].joy.xright, js_x);
+ up = JoystickPositionPercent(setup.input[player_nr].joy.ymiddle,
+ setup.input[player_nr].joy.yupper, js_y);
+ down = JoystickPositionPercent(setup.input[player_nr].joy.ymiddle,
+ setup.input[player_nr].joy.ylower, js_y);
if (left > JOYSTICK_PERCENT)
result |= JOY_LEFT;
return result;
}
-#else /* PLATFORM_MSDOS */
-
-/* allegro global variables for joystick control */
-extern int num_joysticks;
-extern JOYSTICK_INFO joy[];
-
-int Joystick(int player_nr)
-{
-#if 0
- int joystick_nr = stored_player[player_nr].joystick_fd;
-#else
- int joystick_nr = joystick.fd[player_nr];
-#endif
- int result = 0;
-
- if (joystick.status != JOYSTICK_ACTIVATED)
- return 0;
-
- if (joystick_nr < 0)
- return 0;
-
- /* the allegro global variable 'num_joysticks' contains the number
- of joysticks found at initialization under MS-DOS / Windows */
-
-#if 0
- if (joystick_nr >= num_joysticks || !setup.input[player_nr].use_joystick)
- return 0;
-#else
-
-#if 1
- /*
- if (joystick_nr >= num_joysticks ||
- (game_status == PLAYING && !setup.input[player_nr].use_joystick))
- return 0;
- */
-
- if (joystick_nr >= num_joysticks || !setup.input[player_nr].use_joystick)
- return 0;
-
-#else
- if (joystick_nr >= num_joysticks)
- return 0;
-#endif
-
-#endif
-
- poll_joystick();
-
- if (joy[joystick_nr].stick[0].axis[0].d1)
- result |= JOY_LEFT;
- else if (joy[joystick_nr].stick[0].axis[0].d2)
- result |= JOY_RIGHT;
- if (joy[joystick_nr].stick[0].axis[1].d1)
- result |= JOY_UP;
- else if (joy[joystick_nr].stick[0].axis[1].d2)
- result |= JOY_DOWN;
-
- if (joy[joystick_nr].button[0].b)
- result |= JOY_BUTTON_1;
- if (joy[joystick_nr].button[1].b)
- result |= JOY_BUTTON_2;
-
- return result;
-}
-#endif /* PLATFORM_MSDOS */
-
-#endif /* !TARGET_SDL */
-
int JoystickButton(int player_nr)
{
static int last_joy_button[MAX_PLAYERS] = { 0, 0, 0, 0 };
int result = 0;
for (i=0; i<MAX_PLAYERS; i++)
- {
-
- /*
- if (!setup.input[i].use_joystick)
- continue;
- */
-
-
result |= Joystick(i);
- }
return result;
}
for (i=0; i<MAX_PLAYERS; i++)
{
-
- /*
- if (!setup.input[i].use_joystick)
- continue;
- */
-
- /*
- result |= JoystickButton(i);
- */
-
result = JoystickButton(i);
if (result != JOY_BUTTON_NOT_PRESSED)
break;
#include "system.h"
-/* values for the joystick */
#define JOYSTICK_NOT_AVAILABLE 0
#define JOYSTICK_AVAILABLE (1 << 0)
#define JOYSTICK_ACTIVE (1 << 1)
-
#define JOYSTICK_ACTIVATED (JOYSTICK_AVAILABLE | JOYSTICK_ACTIVE)
#if defined(PLATFORM_FREEBSD)
#define JOYSTICK_YMIDDLE 0
#define JOYSTICK_YLOWER 32767
#else
-#define JOYSTICK_XLEFT 30
-#define JOYSTICK_XMIDDLE 530
-#define JOYSTICK_XRIGHT 1250
-#define JOYSTICK_YUPPER 40
-#define JOYSTICK_YMIDDLE 680
-#define JOYSTICK_YLOWER 1440
+#define JOYSTICK_XLEFT 1
+#define JOYSTICK_XMIDDLE 128
+#define JOYSTICK_XRIGHT 255
+#define JOYSTICK_YUPPER 1
+#define JOYSTICK_YMIDDLE 128
+#define JOYSTICK_YLOWER 255
#endif
#define JOYSTICK_PERCENT 25
+#define JOY_NO_ACTION 0
#define JOY_LEFT MV_LEFT
#define JOY_RIGHT MV_RIGHT
#define JOY_UP MV_UP
#define JOY_BUTTON_NEW_PRESSED 2
#define JOY_BUTTON_NEW_RELEASED 3
-#ifdef NO_JOYSTICK
-#define JOYSTICK_STATUS JOYSTICK_NOT_AVAILABLE
-#else
-#define JOYSTICK_STATUS JOYSTICK_AVAILABLE
+#if defined(PLATFORM_UNIX)
+void UnixInitJoysticks(void);
+boolean UnixReadJoystick(int, int *, int *, boolean *, boolean *);
#endif
-
char *getJoyNameFromJoySymbol(int);
int getJoySymbolFromJoyName(char *);
int getJoystickNrFromDeviceName(char *);
char *getDeviceNameFromJoystickNr(int);
-#if defined(TARGET_SDL)
-SDL_Joystick *Get_SDL_Joystick(int);
-boolean Open_SDL_Joystick(int);
-void Close_SDL_Joystick(int);
-boolean Check_SDL_JoystickOpened(int);
-void HandleJoystickEvent(Event *);
-int Get_SDL_Joystick_Axis(int, int);
-#endif
-
void CheckJoystickData(void);
int Joystick(int);
int JoystickButton(int);
#include "system.h"
-/* functions for version handling */
-#define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
-#define VERSION_MAJOR(x) ((x) / 10000)
-#define VERSION_MINOR(x) (((x) % 10000) / 100)
-#define VERSION_PATCH(x) ((x) % 100)
-
/* values for InitCounter() and Counter() */
#define INIT_COUNTER 0
#define READ_COUNTER 1
#if defined(PLATFORM_MSDOS)
#include "sound.h"
+#include "joystick.h"
#include "misc.h"
#include "pcx.h"
Error(ERR_WARN, "networking not supported in DOS version");
}
+
+/* ========================================================================= */
+/* joystick functions */
+/* ========================================================================= */
+
+void MSDOSInitJoysticks()
+{
+ int i;
+
+ /* start from scratch */
+ remove_joystick();
+
+ /* try to access two joysticks; if that fails, try to access just one */
+ if (install_joystick(JOY_TYPE_2PADS) == 0 ||
+ install_joystick(JOY_TYPE_AUTODETECT) == 0)
+ joystick.status = JOYSTICK_ACTIVATED;
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ char *device_name = setup.input[i].joy.device_name;
+ int joystick_nr = getJoystickNrFromDeviceName(device_name);
+
+ if (joystick_nr >= num_joysticks)
+ joystick_nr = -1;
+
+ /* misuse joystick file descriptor variable to store joystick number */
+ joystick.fd[i] = joystick_nr;
+ }
+}
+
+boolean MSDOSReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
+{
+ /* the allegro global variable 'num_joysticks' contains the number
+ of joysticks found at initialization under MS-DOS / Windows */
+
+ if (nr < 0 || nr >= num_joysticks)
+ return FALSE;
+
+ poll_joystick();
+
+ if (x != NULL)
+ *x = joy[nr].stick[0].axis[0].pos;
+ if (y != NULL)
+ *y = joy[nr].stick[0].axis[1].pos;
+
+ if (b1 != NULL)
+ *b1 = joy[nr].button[0].b;
+ if (b2 != NULL)
+ *b2 = joy[nr].button[1].b;
+
+ return TRUE;
+}
+
#endif /* PLATFORM_MSDOS */
#define XRES 800
#define YRES 600
+/* allegro defines some macros that bother the rest of the program */
+#ifdef joy_x
+#undef joy_x
+#undef joy_y
+#undef joy_left
+#undef joy_right
+#undef joy_up
+#undef joy_down
+#undef joy_b1
+#undef joy_b2
+#endif
+
/* additional Allegro keyboard mapping */
/* The following are all undefined in Allegro */
/* end of X11 keyboard mapping */
-#define JOYSTICK_FILENAME "joystick.cnf"
#define screen myscreen
void NetworkServer(int, int);
+void MSDOSInitJoysticks();
+boolean MSDOSReadJoystick(int, int *, int *, boolean *, boolean *);
+
#endif /* MSDOS_H */
#include "system.h"
#include "sound.h"
+#include "joystick.h"
#include "misc.h"
#endif
}
+
+/* ========================================================================= */
+/* joystick functions */
+/* ========================================================================= */
+
+static SDL_Joystick *sdl_joystick[MAX_PLAYERS] = { NULL, NULL, NULL, NULL };
+static int sdl_js_axis[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
+static int sdl_js_button[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
+
+static boolean SDLOpenJoystick(int nr)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return FALSE;
+
+ return ((sdl_joystick[nr] = SDL_JoystickOpen(nr)) == NULL ? FALSE : TRUE);
+}
+
+static void SDLCloseJoystick(int nr)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return;
+
+ SDL_JoystickClose(sdl_joystick[nr]);
+}
+
+static boolean SDLCheckJoystickOpened(int nr)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return FALSE;
+
+ return (SDL_JoystickOpened(nr) ? TRUE : FALSE);
+}
+
+void HandleJoystickEvent(Event *event)
+{
+ switch(event->type)
+ {
+ case SDL_JOYAXISMOTION:
+ if (event->jaxis.axis < 2)
+ sdl_js_axis[event->jaxis.which][event->jaxis.axis]= event->jaxis.value;
+ break;
+
+ case SDL_JOYBUTTONDOWN:
+ if (event->jbutton.button < 2)
+ sdl_js_button[event->jbutton.which][event->jbutton.button] = TRUE;
+ break;
+
+ case SDL_JOYBUTTONUP:
+ if (event->jbutton.button < 2)
+ sdl_js_button[event->jbutton.which][event->jbutton.button] = FALSE;
+ break;
+
+ default:
+ break;
+ }
+}
+
+void SDLInitJoysticks()
+{
+ static boolean sdl_joystick_subsystem_initialized = FALSE;
+ int i;
+
+ if (!sdl_joystick_subsystem_initialized)
+ {
+ sdl_joystick_subsystem_initialized = TRUE;
+
+ if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
+ {
+ Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
+ return;
+ }
+ }
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ char *device_name = setup.input[i].joy.device_name;
+ int joystick_nr = getJoystickNrFromDeviceName(device_name);
+
+ if (joystick_nr >= SDL_NumJoysticks())
+ joystick_nr = -1;
+
+ /* misuse joystick file descriptor variable to store joystick number */
+ joystick.fd[i] = joystick_nr;
+
+ /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
+ if (SDLCheckJoystickOpened(joystick_nr))
+ SDLCloseJoystick(joystick_nr);
+
+ if (!setup.input[i].use_joystick)
+ continue;
+
+ if (!SDLOpenJoystick(joystick_nr))
+ {
+ Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
+ continue;
+ }
+
+ joystick.status = JOYSTICK_ACTIVATED;
+ }
+}
+
+boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
+{
+ if (nr < 0 || nr >= MAX_PLAYERS)
+ return FALSE;
+
+ if (x != NULL)
+ *x = sdl_js_axis[nr][0];
+ if (y != NULL)
+ *y = sdl_js_axis[nr][1];
+
+ if (b1 != NULL)
+ *b1 = sdl_js_button[nr][0];
+ if (b2 != NULL)
+ *b2 = sdl_js_button[nr][1];
+
+ return TRUE;
+}
+
#endif /* TARGET_SDL */
inline void SDLNextEvent(Event *);
+void HandleJoystickEvent(Event *);
+void SDLInitJoysticks(void);
+boolean SDLReadJoystick(int, int *, int *, boolean *, boolean *);
+
#endif /* SDL_H */
#include "text.h"
#include "misc.h"
-
-/* file identifier strings */
-#define SETUP_COOKIE "ROCKSNDIAMONDS_SETUP_FILE_VERSION_1.2"
-#define LEVELSETUP_COOKIE "ROCKSNDIAMONDS_LEVELSETUP_FILE_VERSION_1.2"
-#define LEVELINFO_COOKIE "ROCKSNDIAMONDS_LEVELINFO_FILE_VERSION_1.2"
-
/* file names and filename extensions */
#if !defined(PLATFORM_MSDOS)
#define LEVELSETUP_DIRECTORY "levelsetup"
IS_LEVELCLASS_USER(n) ? 7 : \
9)
-/* values for setup file stuff */
-#define TYPE_BOOLEAN 1
-#define TYPE_SWITCH 2
-#define TYPE_KEY 3
-#define TYPE_INTEGER 4
-#define TYPE_STRING 5
-
-#define TOKEN_STR_FILE_IDENTIFIER "file_identifier"
-
#define TOKEN_VALUE_POSITION 30
-struct SetupFileList
-{
- char *token;
- char *value;
- struct SetupFileList *next;
-};
-
-struct TokenInfo
-{
- int type;
- void *value;
- char *text;
-};
+#define MAX_COOKIE_LEN 256
/* ------------------------------------------------------------------------- */
/* file functions */
/* ------------------------------------------------------------------------- */
-/*
-int get_string_integer_value(char *);
-boolean get_string_boolean_value(char *);
-char *getFormattedSetupEntry(char *, char *);
-void freeSetupFileList(struct SetupFileList *);
-char *getTokenValue(struct SetupFileList *, char *);
-struct SetupFileList *loadSetupFileList(char *);
-void checkSetupFileListIdentifier(struct SetupFileList *, char *);
-*/
-
char *getLevelClassDescription(struct LevelDirInfo *ldi)
{
int position = ldi->sort_priority / 100;
return "Unknown Level Class";
}
-/* for 'InitUserLevelDir()' */
-static void SaveUserLevelInfo();
-
-/* for 'SaveUserLevelInfo()' */
-static char *getSetupLine(struct TokenInfo *, char *, int);
-
static char *getUserLevelDir(char *level_subdir)
{
static char *userlevel_dir = NULL;
return filename;
}
+char *getSetupFilename()
+{
+ static char *filename = NULL;
+
+ if (filename != NULL)
+ free(filename);
+
+ filename = getPath2(getSetupDir(), SETUP_FILENAME);
+
+ return filename;
+}
+
void InitTapeDirectory(char *level_subdir)
{
createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE);
createDirectory(getScoreDir(level_subdir), "level score", PERMS_PUBLIC);
}
+static void SaveUserLevelInfo();
+
void InitUserLevelDirectory(char *level_subdir)
{
if (access(getUserLevelDir(level_subdir), F_OK) != 0)
FILE_PERMS_PRIVATE : FILE_PERMS_PUBLIC));
}
+char *getCookie(char *file_type)
+{
+ static char cookie[MAX_COOKIE_LEN + 1];
+
+ if (strlen(program.cookie_prefix) + 1 +
+ strlen(file_type) + strlen("_FILE_VERSION_x.x") > MAX_COOKIE_LEN)
+ return "[COOKIE ERROR]"; /* should never happen */
+
+ sprintf(cookie, "%s_%s_FILE_VERSION_%d.%d",
+ program.cookie_prefix, file_type,
+ program.version_major, program.version_minor);
+
+ return cookie;
+}
+
int getFileVersionFromCookieString(const char *cookie)
{
const char *ptr_cookie1, *ptr_cookie2;
if (strcmp(setup_file_list->token, TOKEN_STR_FILE_IDENTIFIER) == 0)
{
- if (strcmp(setup_file_list->value, identifier) != 0)
+ if (!checkCookieString(setup_file_list->value, identifier))
{
- Error(ERR_WARN, "configuration file has wrong version");
+ Error(ERR_WARN, "configuration file has wrong file identifier");
return;
}
else
checkSetupFileListIdentifier(setup_file_list->next, identifier);
else
{
- Error(ERR_WARN, "configuration file has no version information");
+ Error(ERR_WARN, "configuration file has no file identifier");
return;
}
}
#define TOKEN_STR_LAST_LEVEL_SERIES "last_level_series"
#define TOKEN_STR_LAST_PLAYED_LEVEL "last_played_level"
#define TOKEN_STR_HANDICAP_LEVEL "handicap_level"
-#define TOKEN_STR_PLAYER_PREFIX "player_"
-
-/* global setup */
-#define SETUP_TOKEN_PLAYER_NAME 0
-#define SETUP_TOKEN_SOUND 1
-#define SETUP_TOKEN_SOUND_LOOPS 2
-#define SETUP_TOKEN_SOUND_MUSIC 3
-#define SETUP_TOKEN_SOUND_SIMPLE 4
-#define SETUP_TOKEN_SCROLL_DELAY 5
-#define SETUP_TOKEN_SOFT_SCROLLING 6
-#define SETUP_TOKEN_FADING 7
-#define SETUP_TOKEN_AUTORECORD 8
-#define SETUP_TOKEN_QUICK_DOORS 9
-#define SETUP_TOKEN_TEAM_MODE 10
-#define SETUP_TOKEN_HANDICAP 11
-#define SETUP_TOKEN_TIME_LIMIT 12
-#define SETUP_TOKEN_FULLSCREEN 13
-
-/* player setup */
-#define SETUP_TOKEN_USE_JOYSTICK 0
-#define SETUP_TOKEN_JOY_DEVICE_NAME 1
-#define SETUP_TOKEN_JOY_XLEFT 2
-#define SETUP_TOKEN_JOY_XMIDDLE 3
-#define SETUP_TOKEN_JOY_XRIGHT 4
-#define SETUP_TOKEN_JOY_YUPPER 5
-#define SETUP_TOKEN_JOY_YMIDDLE 6
-#define SETUP_TOKEN_JOY_YLOWER 7
-#define SETUP_TOKEN_JOY_SNAP 8
-#define SETUP_TOKEN_JOY_BOMB 9
-#define SETUP_TOKEN_KEY_LEFT 10
-#define SETUP_TOKEN_KEY_RIGHT 11
-#define SETUP_TOKEN_KEY_UP 12
-#define SETUP_TOKEN_KEY_DOWN 13
-#define SETUP_TOKEN_KEY_SNAP 14
-#define SETUP_TOKEN_KEY_BOMB 15
/* level directory info */
#define LEVELINFO_TOKEN_NAME 0
#define LEVELINFO_TOKEN_LEVEL_GROUP 8
#define LEVELINFO_TOKEN_READONLY 9
-#define FIRST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_PLAYER_NAME
-#define LAST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_FULLSCREEN
-
-#define FIRST_PLAYER_SETUP_TOKEN SETUP_TOKEN_USE_JOYSTICK
-#define LAST_PLAYER_SETUP_TOKEN SETUP_TOKEN_KEY_BOMB
+#define NUM_LEVELINFO_TOKENS 10
-#define FIRST_LEVELINFO_TOKEN LEVELINFO_TOKEN_NAME
-#define LAST_LEVELINFO_TOKEN LEVELINFO_TOKEN_READONLY
-
-static struct SetupInfo si;
-static struct SetupInputInfo sii;
static struct LevelDirInfo ldi;
-static struct TokenInfo global_setup_tokens[] =
-{
- /* global setup */
- { TYPE_STRING, &si.player_name, "player_name" },
- { TYPE_SWITCH, &si.sound, "sound" },
- { TYPE_SWITCH, &si.sound_loops, "repeating_sound_loops" },
- { TYPE_SWITCH, &si.sound_music, "background_music" },
- { TYPE_SWITCH, &si.sound_simple, "simple_sound_effects" },
- { TYPE_SWITCH, &si.scroll_delay, "scroll_delay" },
- { TYPE_SWITCH, &si.soft_scrolling, "soft_scrolling" },
- { TYPE_SWITCH, &si.fading, "screen_fading" },
- { TYPE_SWITCH, &si.autorecord, "automatic_tape_recording" },
- { TYPE_SWITCH, &si.quick_doors, "quick_doors" },
- { TYPE_SWITCH, &si.team_mode, "team_mode" },
- { TYPE_SWITCH, &si.handicap, "handicap" },
- { TYPE_SWITCH, &si.time_limit, "time_limit" },
- { TYPE_SWITCH, &si.fullscreen, "fullscreen" }
-};
-
-static struct TokenInfo player_setup_tokens[] =
-{
- /* player setup */
- { TYPE_BOOLEAN, &sii.use_joystick, ".use_joystick" },
- { TYPE_STRING, &sii.joy.device_name, ".joy.device_name" },
- { TYPE_INTEGER, &sii.joy.xleft, ".joy.xleft" },
- { TYPE_INTEGER, &sii.joy.xmiddle, ".joy.xmiddle" },
- { TYPE_INTEGER, &sii.joy.xright, ".joy.xright" },
- { TYPE_INTEGER, &sii.joy.yupper, ".joy.yupper" },
- { TYPE_INTEGER, &sii.joy.ymiddle, ".joy.ymiddle" },
- { TYPE_INTEGER, &sii.joy.ylower, ".joy.ylower" },
- { TYPE_INTEGER, &sii.joy.snap, ".joy.snap_field" },
- { TYPE_INTEGER, &sii.joy.bomb, ".joy.place_bomb" },
- { TYPE_KEY, &sii.key.left, ".key.move_left" },
- { TYPE_KEY, &sii.key.right, ".key.move_right" },
- { TYPE_KEY, &sii.key.up, ".key.move_up" },
- { TYPE_KEY, &sii.key.down, ".key.move_down" },
- { TYPE_KEY, &sii.key.snap, ".key.snap_field" },
- { TYPE_KEY, &sii.key.bomb, ".key.place_bomb" }
-};
static struct TokenInfo levelinfo_tokens[] =
{
ldi->next = NULL;
}
-static void setSetupInfoToDefaults(struct SetupInfo *si)
-{
- int i;
-
- si->player_name = getStringCopy(getLoginName());
-
- si->sound = TRUE;
- si->sound_loops = TRUE;
- si->sound_music = TRUE;
- si->sound_simple = TRUE;
- si->toons = TRUE;
- si->double_buffering = TRUE;
- si->direct_draw = !si->double_buffering;
- si->scroll_delay = TRUE;
- si->soft_scrolling = TRUE;
- si->fading = FALSE;
- si->autorecord = TRUE;
- si->quick_doors = FALSE;
- si->team_mode = FALSE;
- si->handicap = TRUE;
- si->time_limit = TRUE;
- si->fullscreen = FALSE;
-
- for (i=0; i<MAX_PLAYERS; i++)
- {
- si->input[i].use_joystick = FALSE;
- si->input[i].joy.device_name=getStringCopy(getDeviceNameFromJoystickNr(i));
- si->input[i].joy.xleft = JOYSTICK_XLEFT;
- si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
- si->input[i].joy.xright = JOYSTICK_XRIGHT;
- si->input[i].joy.yupper = JOYSTICK_YUPPER;
- si->input[i].joy.ymiddle = JOYSTICK_YMIDDLE;
- si->input[i].joy.ylower = JOYSTICK_YLOWER;
- si->input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0);
- si->input[i].joy.bomb = (i == 0 ? JOY_BUTTON_2 : 0);
- si->input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KSYM_UNDEFINED);
- si->input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KSYM_UNDEFINED);
- si->input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KSYM_UNDEFINED);
- si->input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KSYM_UNDEFINED);
- si->input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KSYM_UNDEFINED);
- si->input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KSYM_UNDEFINED);
- }
-}
-
-static void setSetupInfo(struct TokenInfo *token_info,
- int token_nr, char *token_value)
+void setSetupInfo(struct TokenInfo *token_info,
+ int token_nr, char *token_value)
{
int token_type = token_info[token_nr].type;
void *setup_value = token_info[token_nr].value;
}
}
-static void decodeSetupFileList(struct SetupFileList *setup_file_list)
-{
- int i, pnr;
-
- if (!setup_file_list)
- return;
-
- /* handle global setup values */
- si = setup;
- for (i=FIRST_GLOBAL_SETUP_TOKEN; i<=LAST_GLOBAL_SETUP_TOKEN; i++)
- setSetupInfo(global_setup_tokens, i,
- getTokenValue(setup_file_list, global_setup_tokens[i].text));
- setup = si;
-
- /* handle player specific setup values */
- for (pnr=0; pnr<MAX_PLAYERS; pnr++)
- {
- char prefix[30];
-
- sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
-
- sii = setup.input[pnr];
- for (i=FIRST_PLAYER_SETUP_TOKEN; i<=LAST_PLAYER_SETUP_TOKEN; i++)
- {
- char full_token[100];
-
- sprintf(full_token, "%s%s", prefix, player_setup_tokens[i].text);
- setSetupInfo(player_setup_tokens, i,
- getTokenValue(setup_file_list, full_token));
- }
- setup.input[pnr] = sii;
- }
-}
-
static int compareLevelDirInfoEntries(const void *object1, const void *object2)
{
const struct LevelDirInfo *entry1 = *((struct LevelDirInfo **)object1);
struct LevelDirInfo *leveldir_new = newLevelDirInfo();
int i;
- checkSetupFileListIdentifier(setup_file_list, LEVELINFO_COOKIE);
+ checkSetupFileListIdentifier(setup_file_list, getCookie("LEVELINFO"));
setLevelDirInfoToDefaultsFromParent(leveldir_new, node_parent);
/* set all structure fields according to the token/value pairs */
ldi = *leveldir_new;
- for (i=FIRST_LEVELINFO_TOKEN; i<=LAST_LEVELINFO_TOKEN; i++)
+ for (i=0; i<NUM_LEVELINFO_TOKENS; i++)
setSetupInfo(levelinfo_tokens, i,
getTokenValue(setup_file_list, levelinfo_tokens[i].text));
*leveldir_new = ldi;
ldi.sort_priority = LEVELCLASS_USER_START;
ldi.readonly = FALSE;
- fprintf(file, "%s\n\n",
- getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, LEVELINFO_COOKIE));
+ fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
+ getCookie("LEVELINFO")));
- for (i=FIRST_LEVELINFO_TOKEN; i<=LAST_LEVELINFO_TOKEN; i++)
+ for (i=0; i<NUM_LEVELINFO_TOKENS; i++)
if (i != LEVELINFO_TOKEN_NAME_SHORT &&
i != LEVELINFO_TOKEN_NAME_SORTING &&
i != LEVELINFO_TOKEN_IMPORTED_FROM)
SetFilePermissions(filename, PERMS_PRIVATE);
}
-void LoadSetup()
-{
- char *filename;
- struct SetupFileList *setup_file_list = NULL;
-
- /* always start with reliable default values */
- setSetupInfoToDefaults(&setup);
-
- filename = getPath2(getSetupDir(), SETUP_FILENAME);
-
- setup_file_list = loadSetupFileList(filename);
-
- if (setup_file_list)
- {
- checkSetupFileListIdentifier(setup_file_list, SETUP_COOKIE);
- decodeSetupFileList(setup_file_list);
-
- setup.direct_draw = !setup.double_buffering;
-
- freeSetupFileList(setup_file_list);
-
- /* needed to work around problems with fixed length strings */
- if (strlen(setup.player_name) > MAX_PLAYER_NAME_LEN)
- setup.player_name[MAX_PLAYER_NAME_LEN] = '\0';
- else if (strlen(setup.player_name) < MAX_PLAYER_NAME_LEN)
- {
- char *new_name = checked_malloc(MAX_PLAYER_NAME_LEN + 1);
-
- strcpy(new_name, setup.player_name);
- free(setup.player_name);
- setup.player_name = new_name;
- }
- }
- else
- Error(ERR_WARN, "using default setup values");
-
- free(filename);
-}
-
-static char *getSetupLine(struct TokenInfo *token_info,
- char *prefix, int token_nr)
+char *getSetupLine(struct TokenInfo *token_info, char *prefix, int token_nr)
{
int i;
static char entry[MAX_LINE_LEN];
return entry;
}
-void SaveSetup()
-{
- int i, pnr;
- char *filename;
- FILE *file;
-
- InitUserDataDirectory();
-
- filename = getPath2(getSetupDir(), SETUP_FILENAME);
-
- if (!(file = fopen(filename, MODE_WRITE)))
- {
- Error(ERR_WARN, "cannot write setup file '%s'", filename);
- free(filename);
- return;
- }
-
- fprintf(file, "%s\n",
- getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER, SETUP_COOKIE));
- fprintf(file, "\n");
-
- /* handle global setup values */
- si = setup;
- for (i=FIRST_GLOBAL_SETUP_TOKEN; i<=LAST_GLOBAL_SETUP_TOKEN; i++)
- {
- fprintf(file, "%s\n", getSetupLine(global_setup_tokens, "", i));
-
- /* just to make things nicer :) */
- if (i == SETUP_TOKEN_PLAYER_NAME)
- fprintf(file, "\n");
- }
-
- /* handle player specific setup values */
- for (pnr=0; pnr<MAX_PLAYERS; pnr++)
- {
- char prefix[30];
-
- sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, pnr + 1);
- fprintf(file, "\n");
-
- sii = setup.input[pnr];
- for (i=FIRST_PLAYER_SETUP_TOKEN; i<=LAST_PLAYER_SETUP_TOKEN; i++)
- fprintf(file, "%s\n", getSetupLine(player_setup_tokens, prefix, i));
- }
-
- fclose(file);
- free(filename);
-
- SetFilePermissions(filename, PERMS_PRIVATE);
-}
-
void LoadLevelSetup_LastSeries()
{
char *filename;
leveldir_current = getFirstValidLevelSeries(leveldir_first);
/* ----------------------------------------------------------------------- */
- /* ~/.rocksndiamonds/levelsetup.conf */
+ /* ~/.<program>/levelsetup.conf */
/* ----------------------------------------------------------------------- */
filename = getPath2(getSetupDir(), LEVELSETUP_FILENAME);
if (leveldir_current == NULL)
leveldir_current = leveldir_first;
- checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE);
+ checkSetupFileListIdentifier(level_setup_list, getCookie("LEVELSETUP"));
freeSetupFileList(level_setup_list);
}
FILE *file;
/* ----------------------------------------------------------------------- */
- /* ~/.rocksndiamonds/levelsetup.conf */
+ /* ~/.<program>/levelsetup.conf */
/* ----------------------------------------------------------------------- */
InitUserDataDirectory();
}
fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
- LEVELSETUP_COOKIE));
+ getCookie("LEVELSETUP")));
fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_LEVEL_SERIES,
level_subdir));
checkSeriesInfo(leveldir_current);
/* ----------------------------------------------------------------------- */
- /* ~/.rocksndiamonds/levelsetup/<level series>/levelsetup.conf */
+ /* ~/.<program>/levelsetup/<level series>/levelsetup.conf */
/* ----------------------------------------------------------------------- */
level_subdir = leveldir_current->filename;
leveldir_current->handicap_level = level_nr;
}
- checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE);
+ checkSetupFileListIdentifier(level_setup_list, getCookie("LEVELSETUP"));
freeSetupFileList(level_setup_list);
}
FILE *file;
/* ----------------------------------------------------------------------- */
- /* ~/.rocksndiamonds/levelsetup/<level series>/levelsetup.conf */
+ /* ~/.<program>/levelsetup/<level series>/levelsetup.conf */
/* ----------------------------------------------------------------------- */
InitLevelSetupDirectory(level_subdir);
}
fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
- LEVELSETUP_COOKIE));
+ getCookie("LEVELSETUP")));
fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_PLAYED_LEVEL,
level_nr_str));
fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL,
#include "system.h"
+/* values for setup file handling */
+#define TYPE_BOOLEAN 1
+#define TYPE_SWITCH 2
+#define TYPE_KEY 3
+#define TYPE_INTEGER 4
+#define TYPE_STRING 5
+
+#define TOKEN_STR_FILE_IDENTIFIER "file_identifier"
+
+/* structures for setup file handling */
+struct SetupFileList
+{
+ char *token;
+ char *value;
+ struct SetupFileList *next;
+};
+
+struct TokenInfo
+{
+ int type;
+ void *value;
+ char *text;
+};
+
/* sort priorities of level series (also used as level series classes) */
#define LEVELCLASS_TUTORIAL_START 10
#define LEVELCLASS_TUTORIAL_END 99
char *getLevelFilename(int);
char *getTapeFilename(int);
char *getScoreFilename(int);
+char *getSetupFilename(void);
+
void InitTapeDirectory(char *);
void InitScoreDirectory(char *);
void InitUserLevelDirectory(char *);
void createDirectory(char *, char *, int);
void InitUserDataDirectory(void);
void SetFilePermissions(char *, int);
+
+char *getCookie(char *);
int getFileVersionFromCookieString(const char *);
boolean checkCookieString(const char *, const char *);
+char *getFormattedSetupEntry(char *, char *);
+void freeSetupFileList(struct SetupFileList *);
+char *getTokenValue(struct SetupFileList *, char *);
+struct SetupFileList *loadSetupFileList(char *);
+void checkSetupFileListIdentifier(struct SetupFileList *, char *);
+void setSetupInfo(struct TokenInfo *, int, char *);
+char *getSetupLine(struct TokenInfo *, char *, int);
+
void LoadLevelInfo(void);
-void LoadSetup(void);
-void SaveSetup(void);
void LoadLevelSetup_LastSeries(void);
void SaveLevelSetup_LastSeries(void);
void LoadLevelSetup_SeriesInfo(void);
#include "system.h"
#include "sound.h"
#include "setup.h"
+#include "joystick.h"
#include "misc.h"
void InitProgramInfo(char *unix_userdata_directory, char *program_title,
char *window_title, char *icon_title,
char *x11_icon_basename, char *x11_iconmask_basename,
- char *msdos_pointer_basename)
+ char *msdos_pointer_basename,
+ char *cookie_prefix, int program_version)
{
char *x11_icon_filename =
getPath2(options.graphics_directory, x11_icon_basename);
program.x11_icon_filename = x11_icon_filename;
program.x11_iconmask_filename = x11_iconmask_filename;
program.msdos_pointer_filename = msdos_pointer_filename;
+ program.cookie_prefix = cookie_prefix;
+ program.version_major = VERSION_MAJOR(program_version);
+ program.version_minor = VERSION_MINOR(program_version);
+ program.version_patch = VERSION_PATCH(program_version);
}
void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
#if defined(TARGET_SDL)
SDLOpenAudio();
-#elif defined(PLATFORM_MSDOS)
- MSDOSOpenAudio();
#elif defined(PLATFORM_UNIX)
UnixOpenAudio();
+#elif defined(PLATFORM_MSDOS)
+ MSDOSOpenAudio();
#endif
}
{
#if defined(TARGET_SDL)
SDLCloseAudio();
-#elif defined(PLATFORM_MSDOS)
- MSDOSCloseAudio();
#elif defined(PLATFORM_UNIX)
UnixCloseAudio();
+#elif defined(PLATFORM_MSDOS)
+ MSDOSCloseAudio();
#endif
audio.sound_enabled = FALSE;
}
-inline void dummy(void)
+/* ========================================================================= */
+/* joystick functions */
+/* ========================================================================= */
+
+inline void InitJoysticks()
{
-#ifdef TARGET_SDL
-#else
+ int i;
+
+#ifdef NO_JOYSTICK
+ return; /* joysticks generally deactivated by compile-time directive */
+#endif
+
+ /* always start with reliable default values */
+ joystick.status = JOYSTICK_NOT_AVAILABLE;
+ for (i=0; i<MAX_PLAYERS; i++)
+ joystick.fd[i] = -1; /* joystick device closed */
+
+#if defined(TARGET_SDL)
+ SDLInitJoysticks();
+#elif defined(PLATFORM_UNIX)
+ UnixInitJoysticks();
+#elif defined(PLATFORM_MSDOS)
+ MSDOSInitJoysticks();
+#endif
+}
+
+inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
+{
+#if defined(TARGET_SDL)
+ return SDLReadJoystick(nr, x, y, b1, b2);
+#elif defined(PLATFORM_UNIX)
+ return UnixReadJoystick(nr, x, y, b1, b2);
+#elif defined(PLATFORM_MSDOS)
+ return MSDOSReadJoystick(nr, x, y, b1, b2);
#endif
}
#endif
-/* contant definitions */
-
/* the additional 'b' is needed for Win32 to open files in binary mode */
#define MODE_READ "rb"
#define MODE_WRITE "wb"
#define DOOR_GFX_PAGEY1 (0)
#define DOOR_GFX_PAGEY2 (gfx.dysize)
+/* functions for version handling */
+#define VERSION_IDENT(x,y,z) ((x) * 10000 + (y) * 100 + (z))
+#define VERSION_MAJOR(x) ((x) / 10000)
+#define VERSION_MINOR(x) (((x) % 10000) / 100)
+#define VERSION_PATCH(x) ((x) % 100)
-/* type definitions */
+/* type definitions */
typedef int (*EventFilter)(const Event *);
char *program_title;
char *window_title;
char *icon_title;
+
char *x11_icon_filename;
char *x11_iconmask_filename;
char *msdos_pointer_filename;
+ char *cookie_prefix;
+
+ int version_major;
+ int version_minor;
+ int version_patch;
+
void (*exit_function)(int);
};
void InitPlatformDependantStuff(void);
void ClosePlatformDependantStuff(void);
-void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *);
+void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
+ char *, int);
void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
void InitGfxDoor1Info(int, int, int, int);
inline Key GetEventKey(KeyEvent *, boolean);
inline boolean CheckCloseWindowEvent(ClientMessageEvent *);
+inline void InitJoysticks();
+inline boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
+
#endif /* SYSTEM_H */
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <sys/types.h>
typedef unsigned char boolean;
boolean network_playing = FALSE;
int key_joystick_mapping = 0;
-int global_joystick_status = JOYSTICK_STATUS;
boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
int redraw_x1 = 0, redraw_y1 = 0;
extern DrawBuffer *fieldbuffer;
extern DrawBuffer *drawto_field;
-extern int joystick_device;
-extern char *joystick_device_name[];
-
extern int game_status;
extern boolean level_editor_test_game;
extern boolean network_playing;
extern int key_joystick_mapping;
-extern int global_joystick_status;
extern boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
extern int redraw_x1, redraw_y1;
#define WINDOW_SUBTITLE_STRING PROGRAM_RIGHTS_STRING " " PROGRAM_AUTHOR_STRING
#define ICON_TITLE_STRING PROGRAM_TITLE_STRING
#define UNIX_USERDATA_DIRECTORY ".rocksndiamonds"
+#define COOKIE_PREFIX "ROCKSNDIAMONDS"
#define X11_ICON_FILENAME "rocks_icon.xbm"
#define X11_ICONMASK_FILENAME "rocks_iconmask.xbm"
DrawSetupInputScreen();
redraw = TRUE;
}
- else if (y==pos_end-1 || y==pos_end)
+ else if (y == pos_end - 1 || y == pos_end)
{
- if (y==pos_end)
- {
+ if (y == pos_end)
SaveSetup();
- /*
- SaveJoystickData();
- */
-
-#if defined(PLATFORM_MSDOS)
- save_joystick_data(JOYSTICK_FILENAME);
-#endif
-
-
- }
-
game_status = MAINMENU;
DrawMainMenu();
redraw = TRUE;
setJoystickDeviceToNr(device_name, new_device_nr);
}
-
- /*
- InitJoysticks();
- */
-
-
-#if 0
- int one_joystick_nr = (dx >= 0 ? 0 : 1);
- int the_other_joystick_nr = (dx >= 0 ? 1 : 0);
-
- if (setup.input[player_nr].use_joystick)
- {
- if (setup.input[player_nr].joystick_nr == one_joystick_nr)
- setup.input[player_nr].joystick_nr = the_other_joystick_nr;
- else
- setup.input[player_nr].use_joystick = FALSE;
- }
- else
- {
- setup.input[player_nr].use_joystick = TRUE;
- setup.input[player_nr].joystick_nr = one_joystick_nr;
- }
-#endif
-
drawPlayerSetupInputInfo(player_nr);
}
else if (y == 5)
DrawSetupInputScreen();
}
-void CalibrateJoystick(int player_nr)
+static boolean CalibrateJoystickMain(int player_nr)
{
-#ifdef __FreeBSD__
- struct joystick joy_ctrl;
-#else
- struct joystick_control
- {
- int buttons;
- int x;
- int y;
- } joy_ctrl;
-#endif
-
-#if !defined(PLATFORM_MSDOS)
- int new_joystick_xleft = 128, new_joystick_xright = 128;
- int new_joystick_yupper = 128, new_joystick_ylower = 128;
+ int new_joystick_xleft = JOYSTICK_XMIDDLE;
+ int new_joystick_xright = JOYSTICK_XMIDDLE;
+ int new_joystick_yupper = JOYSTICK_YMIDDLE;
+ int new_joystick_ylower = JOYSTICK_YMIDDLE;
int new_joystick_xmiddle, new_joystick_ymiddle;
-#else
- int calibration_step = 1;
-#endif
int joystick_fd = joystick.fd[player_nr];
int x, y, last_x, last_y, xpos = 8, ypos = 3;
boolean check[3][3];
- int check_remaining;
+ int check_remaining = 3 * 3;
+ int joy_x, joy_y;
int joy_value;
int result = -1;
- if (joystick.status == JOYSTICK_NOT_AVAILABLE ||
- joystick_fd < 0 ||
- !setup.input[player_nr].use_joystick)
- goto error_out;
+ if (joystick.status == JOYSTICK_NOT_AVAILABLE)
+ return FALSE;
- ClearWindow();
+ if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
+ return FALSE;
-#if !defined(PLATFORM_MSDOS)
- DrawText(SX, SY + 6*32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 7*32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
- DrawText(SX + 16, SY + 9*32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 10*32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
- check_remaining = 3 * 3;
-#else
- DrawText(SX, SY + 7*32, " MOVE JOYSTICK ", FS_BIG, FC_YELLOW);
- DrawText(SX + 16, SY + 8*32, " TO ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 9*32, " CENTER POSITION ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 10*32, " AND ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
- check_remaining = 0;
-#endif
+ ClearWindow();
for(y=0; y<3; y++)
{
}
}
+ DrawText(SX, SY + 6 * 32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
+ DrawText(SX, SY + 7 * 32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
+ DrawText(SX + 16, SY + 9 * 32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
+ DrawText(SX, SY + 10 * 32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
+ DrawText(SX, SY + 11 * 32, " CENTER JOYSTICK ", FS_BIG, FC_YELLOW);
+ DrawText(SX, SY + 12 * 32, " AND ", FS_BIG, FC_YELLOW);
+ DrawText(SX, SY + 13 * 32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
+
joy_value = Joystick(player_nr);
last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
- DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
- BackToFront();
+ /* eventually uncalibrated center position (joystick could be uncentered) */
+ if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
+ return FALSE;
-#ifdef __FreeBSD__
- joy_ctrl.b1 = joy_ctrl.b2 = 0;
-#else
- joy_ctrl.buttons = 0;
-#endif
+ new_joystick_xmiddle = joy_x;
+ new_joystick_ymiddle = joy_y;
- while(Joystick(player_nr) & JOY_BUTTON);
+ DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
+ BackToFront();
+ while(Joystick(player_nr) & JOY_BUTTON); /* wait for released button */
InitAnimation();
while(result < 0)
}
}
-#if !defined(PLATFORM_MSDOS)
-
-#if defined(TARGET_SDL)
- joy_ctrl.x = Get_SDL_Joystick_Axis(joystick_fd, 0);
- joy_ctrl.y = Get_SDL_Joystick_Axis(joystick_fd, 1);
-#else
- if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
- {
- joystick.status = JOYSTICK_NOT_AVAILABLE;
- goto error_out;
- }
-#endif
+ if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
+ return FALSE;
- new_joystick_xleft = MIN(new_joystick_xleft, joy_ctrl.x);
- new_joystick_xright = MAX(new_joystick_xright, joy_ctrl.x);
- new_joystick_yupper = MIN(new_joystick_yupper, joy_ctrl.y);
- new_joystick_ylower = MAX(new_joystick_ylower, joy_ctrl.y);
-
- new_joystick_xmiddle =
- new_joystick_xleft + (new_joystick_xright - new_joystick_xleft) / 2;
- new_joystick_ymiddle =
- new_joystick_yupper + (new_joystick_ylower - new_joystick_yupper) / 2;
+ new_joystick_xleft = MIN(new_joystick_xleft, joy_x);
+ new_joystick_xright = MAX(new_joystick_xright, joy_x);
+ new_joystick_yupper = MIN(new_joystick_yupper, joy_y);
+ new_joystick_ylower = MAX(new_joystick_ylower, joy_y);
setup.input[player_nr].joy.xleft = new_joystick_xleft;
setup.input[player_nr].joy.yupper = new_joystick_yupper;
setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
CheckJoystickData();
-#endif
joy_value = Joystick(player_nr);
if (joy_value & JOY_BUTTON && check_remaining == 0)
- {
result = 1;
-#if defined(PLATFORM_MSDOS)
- if (calibration_step == 1)
- {
- remove_joystick();
- InitJoysticks();
- }
- else if (calibrate_joystick(joystick_fd) != 0)
- {
- joystick.status = JOYSTICK_NOT_AVAILABLE;
- goto error_out;
- }
-
- if (joy[joystick_fd].flags & JOYFLAG_CALIBRATE)
- {
- calibration_step++;
- result = -1;
-
- DrawText(SX, SY + 7*32, " MOVE JOYSTICK ", FS_BIG, FC_YELLOW);
- DrawText(SX + 16, SY + 8*32, " TO ", FS_BIG, FC_YELLOW);
-
- if (calibration_step == 2)
- DrawText(SX + 16, SY + 9*32," THE UPPER LEFT ", FS_BIG, FC_YELLOW);
- else
- DrawText(SX, SY + 9*32," THE LOWER RIGHT ", FS_BIG, FC_YELLOW);
-
- DrawText(SX, SY + 10*32, " AND ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
-
- BackToFront();
-
- while(Joystick(player_nr) & JOY_BUTTON)
- DoAnimation();
- }
-#endif
- }
-
x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
if (x != last_x || y != last_y)
{
-#if !defined(PLATFORM_MSDOS)
DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
-#else
- DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_BLAU);
-#endif
DrawGraphic(xpos + x, ypos + y, GFX_KUGEL_ROT);
last_x = x;
}
#if 0
+#ifdef DEBUG
printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
setup.input[player_nr].joy.xleft,
setup.input[player_nr].joy.xmiddle,
setup.input[player_nr].joy.yupper,
setup.input[player_nr].joy.ymiddle,
setup.input[player_nr].joy.ylower);
+#endif
#endif
}
Delay(10);
}
+ /* calibrated center position (joystick should now be centered) */
+ if (!ReadJoystick(joystick_fd, &joy_x, &joy_y, NULL, NULL))
+ return FALSE;
+
+ new_joystick_xmiddle = joy_x;
+ new_joystick_ymiddle = joy_y;
+
StopAnimation();
DrawSetupInputScreen();
/* wait until the last pressed button was released */
- while(Joystick(player_nr) & JOY_BUTTON)
+ while (Joystick(player_nr) & JOY_BUTTON)
{
if (PendingEvent()) /* got event */
{
Delay(10);
}
}
- return;
- error_out:
+ return TRUE;
+}
- ClearWindow();
- DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
- DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
- BackToFront();
- Delay(2000);
- DrawSetupInputScreen();
+void CalibrateJoystick(int player_nr)
+{
+ if (!CalibrateJoystickMain(player_nr))
+ {
+ ClearWindow();
+
+ DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
+ DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
+ BackToFront();
+ Delay(2000); /* show error message for two seconds */
+ }
}
void HandleGameActions()
* tools.c *
***********************************************************/
-#if 0
-#include <stdarg.h>
-
-#if defined(PLATFORM_FREEBSD)
-#include <machine/joystick.h>
-#endif
-#endif
-
#include "libgame/libgame.h"
#include "tools.h"