X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ffiles.c;h=3162e629cf126ba102c242a32018ccad2074f711;hp=fa807e8f323dd0161959467fb6553ca5a703da52;hb=2174ec0a6b545b47aaea3153ef9a67993fc59a93;hpb=90cd4dc88df3f891ecaa0ee9b9010fe432154503 diff --git a/src/files.c b/src/files.c index fa807e8f..3162e629 100644 --- a/src/files.c +++ b/src/files.c @@ -1733,9 +1733,6 @@ static void setLevelInfoToDefaults_Level(struct LevelInfo *level) // set all bug compatibility flags to "false" => do not emulate this bug level->use_action_after_change_bug = FALSE; - // other flags that may be set due to certain level properties - level->has_mouse_events = FALSE; - if (leveldir_current) { // try to determine better author name than 'anonymous' @@ -3989,7 +3986,7 @@ static void CopyNativeTape_SP_to_RND(struct LevelInfo *level) int demo_repeat = (demo->data[i] & 0xf0) >> 4; int tape_action = map_key_SP_to_RND(demo_action); int tape_repeat = demo_repeat + 1; - byte action[MAX_PLAYERS] = { tape_action, 0, 0, 0 }; + byte action[MAX_TAPE_ACTIONS] = { tape_action }; boolean success = 0; int j; @@ -6564,18 +6561,6 @@ static void LoadLevel_InitCustomElements(struct LevelInfo *level) element_info[element].ignition_delay = 8; } } - - // check for custom elements which have mouse click events defined - for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) - { - int element = EL_CUSTOM_START + i; - - if (HAS_CHANGE_EVENT(element, CE_CLICKED_BY_MOUSE) || - HAS_CHANGE_EVENT(element, CE_PRESSED_BY_MOUSE) || - HAS_CHANGE_EVENT(element, CE_MOUSE_CLICKED_ON_X) || - HAS_CHANGE_EVENT(element, CE_MOUSE_PRESSED_ON_X)) - level->has_mouse_events = TRUE; - } } static void LoadLevel_InitElements(struct LevelInfo *level) @@ -6807,8 +6792,8 @@ static int SaveLevel_BODY(FILE *file, struct LevelInfo *level) int chunk_size = 0; int x, y; - for (y = 0; y < level->fieldy; y++) - for (x = 0; x < level->fieldx; x++) + for (y = 0; y < level->fieldy; y++) + for (x = 0; x < level->fieldx; x++) if (level->encoding_16bit_field) chunk_size += putFile16BitBE(file, level->field[x][y]); else @@ -7634,6 +7619,42 @@ static void setTapeInfoToDefaults(void) tape.no_valid_file = FALSE; } +static int getTapePosSize(struct TapeInfo *tape) +{ + int tape_pos_size = 0; + + if (tape->use_key_actions) + tape_pos_size += tape->num_participating_players; + + if (tape->use_mouse_actions) + tape_pos_size += 3; // x and y position and mouse button mask + + tape_pos_size += 1; // tape action delay value + + return tape_pos_size; +} + +static void setTapeActionFlags(struct TapeInfo *tape, int value) +{ + tape->use_key_actions = FALSE; + tape->use_mouse_actions = FALSE; + + if (value != TAPE_USE_MOUSE_ACTIONS_ONLY) + tape->use_key_actions = TRUE; + + if (value != TAPE_USE_KEY_ACTIONS_ONLY) + tape->use_mouse_actions = TRUE; +} + +static int getTapeActionValue(struct TapeInfo *tape) +{ + return (tape->use_key_actions && + tape->use_mouse_actions ? TAPE_USE_KEY_AND_MOUSE_ACTIONS : + tape->use_key_actions ? TAPE_USE_KEY_ACTIONS_ONLY : + tape->use_mouse_actions ? TAPE_USE_MOUSE_ACTIONS_ONLY : + TAPE_ACTIONS_DEFAULT); +} + static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape) { tape->file_version = getFileVersion(file); @@ -7669,7 +7690,7 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) } } - tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE); + setTapeActionFlags(tape, getFile8Bit(file)); ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -7706,8 +7727,7 @@ static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape) static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) { int i, j; - int tape_pos_size = - (tape->use_mouse ? 3 : tape->num_participating_players) + 1; + int tape_pos_size = getTapePosSize(tape); int chunk_size_expected = tape_pos_size * tape->length; if (chunk_size_expected != chunk_size) @@ -7725,20 +7745,12 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) // tape too large; read and ignore remaining tape data from this chunk for (;i < tape->length; i++) - ReadUnusedBytesFromFile(file, tape->num_participating_players + 1); + ReadUnusedBytesFromFile(file, tape_pos_size); break; } - if (tape->use_mouse) - { - tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file); - tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file); - tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file); - - tape->pos[i].action[TAPE_ACTION_UNUSED] = 0; - } - else + if (tape->use_key_actions) { for (j = 0; j < MAX_PLAYERS; j++) { @@ -7749,6 +7761,13 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) } } + if (tape->use_mouse_actions) + { + tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file); + tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file); + tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file); + } + tape->pos[i].delay = getFile8Bit(file); if (tape->file_version == FILE_VERSION_1_0) @@ -8072,7 +8091,7 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) putFile8Bit(file, store_participating_players); - putFile8Bit(file, (tape->use_mouse ? 1 : 0)); + putFile8Bit(file, getTapeActionValue(tape)); // unused bytes not at the end here for 4-byte alignment of engine_version WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -8099,19 +8118,20 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) for (i = 0; i < tape->length; i++) { - if (tape->use_mouse) - { - putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]); - putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]); - putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]); - } - else + if (tape->use_key_actions) { for (j = 0; j < MAX_PLAYERS; j++) if (tape->player_participates[j]) putFile8Bit(file, tape->pos[i].action[j]); } + if (tape->use_mouse_actions) + { + putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]); + putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]); + putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]); + } + putFile8Bit(file, tape->pos[i].delay); } } @@ -8120,7 +8140,6 @@ void SaveTape(int nr) { char *filename = getTapeFilename(nr); FILE *file; - int num_participating_players = 0; int tape_pos_size; int info_chunk_size; int body_chunk_size; @@ -8137,12 +8156,14 @@ void SaveTape(int nr) tape.file_version = FILE_VERSION_ACTUAL; tape.game_version = GAME_VERSION_ACTUAL; + tape.num_participating_players = 0; + // count number of participating players for (i = 0; i < MAX_PLAYERS; i++) if (tape.player_participates[i]) - num_participating_players++; + tape.num_participating_players++; - tape_pos_size = (tape.use_mouse ? 3 : num_participating_players) + 1; + tape_pos_size = getTapePosSize(&tape); info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2; body_chunk_size = tape_pos_size * tape.length; @@ -8484,6 +8505,10 @@ static struct TokenInfo global_setup_tokens[] = TYPE_SWITCH, &setup.prefer_aga_graphics, "prefer_aga_graphics" }, + { + TYPE_SWITCH, + &setup.prefer_lowpass_sounds, "prefer_lowpass_sounds" + }, { TYPE_SWITCH, &setup.game_speed_extended, "game_speed_extended" @@ -9155,6 +9180,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->quick_switch = FALSE; si->input_on_focus = FALSE; si->prefer_aga_graphics = TRUE; + si->prefer_lowpass_sounds = FALSE; si->game_speed_extended = FALSE; si->game_frame_delay = GAME_FRAME_DELAY; si->sp_show_border_elements = FALSE;