From: Holger Schemel Date: Tue, 12 Mar 2019 20:22:02 +0000 (+0100) Subject: added support for storing multiple event definitions for global animations X-Git-Tag: 4.1.3.0~43 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f93552d6cd84e880ee73d4864018167aefc1bb79;p=rocksndiamonds.git added support for storing multiple event definitions for global animations --- diff --git a/src/anim.c b/src/anim.c index 2234ebe4..861364d7 100644 --- a/src/anim.c +++ b/src/anim.c @@ -14,6 +14,7 @@ #include "anim.h" #include "main.h" #include "tools.h" +#include "files.h" #include "events.h" #include "screens.h" @@ -994,18 +995,20 @@ static boolean isClickablePart(struct GlobalAnimPartControlInfo *part, int mask) struct GraphicInfo *c = &part->control_info; int trigger_mask = ANIM_EVENT_ANIM_MASK | ANIM_EVENT_PART_MASK; int mask_anim_only = mask & ANIM_EVENT_ANIM_MASK; + int init_event = GetGlobalAnimEventValue(c->init_event, 0); + int anim_event = GetGlobalAnimEventValue(c->anim_event, 0); if (mask & ANIM_EVENT_ANY) - return (c->init_event & ANIM_EVENT_ANY || - c->anim_event & ANIM_EVENT_ANY); + return (init_event & ANIM_EVENT_ANY || + anim_event & ANIM_EVENT_ANY); else if (mask & ANIM_EVENT_SELF) - return (c->init_event & ANIM_EVENT_SELF || - c->anim_event & ANIM_EVENT_SELF); + return (init_event & ANIM_EVENT_SELF || + anim_event & ANIM_EVENT_SELF); else - return ((c->init_event & trigger_mask) == mask || - (c->anim_event & trigger_mask) == mask || - (c->init_event & trigger_mask) == mask_anim_only || - (c->anim_event & trigger_mask) == mask_anim_only); + return ((init_event & trigger_mask) == mask || + (anim_event & trigger_mask) == mask || + (init_event & trigger_mask) == mask_anim_only || + (anim_event & trigger_mask) == mask_anim_only); } static boolean isClickedPart(struct GlobalAnimPartControlInfo *part, @@ -1070,8 +1073,8 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part, part->anim_delay_counter = (c->anim_delay_fixed + GetSimpleRandom(c->anim_delay_random)); - part->init_event_state = c->init_event; - part->anim_event_state = c->anim_event; + part->init_event_state = GetGlobalAnimEventValue(c->init_event, 0); + part->anim_event_state = GetGlobalAnimEventValue(c->anim_event, 0); part->initial_anim_sync_frame = (g->anim_global_sync ? 0 : anim_sync_frame + part->init_delay_counter); diff --git a/src/files.c b/src/files.c index 4ac4563f..18207611 100644 --- a/src/files.c +++ b/src/files.c @@ -9941,6 +9941,79 @@ static int getElementFromToken(char *token) return EL_UNDEFINED; } +void FreeGlobalAnimEventInfo(void) +{ + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + + if (gaei->event_list == NULL) + return; + + int i; + + for (i = 0; i < gaei->num_event_lists; i++) + { + checked_free(gaei->event_list[i]->event_value); + checked_free(gaei->event_list[i]); + } + + checked_free(gaei->event_list); + + gaei->event_list = NULL; + gaei->num_event_lists = 0; +} + +static int AddGlobalAnimEventList(void) +{ + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + int list_pos = gaei->num_event_lists++; + + gaei->event_list = checked_realloc(gaei->event_list, gaei->num_event_lists * + sizeof(struct GlobalAnimEventListInfo *)); + + gaei->event_list[list_pos] = + checked_calloc(sizeof(struct GlobalAnimEventListInfo)); + + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + + gaeli->event_value = NULL; + gaeli->num_event_values = 0; + + return list_pos; +} + +static int AddGlobalAnimEventValue(int list_pos, int event_value) +{ + // do not add empty global animation events + if (event_value == ANIM_EVENT_NONE) + return list_pos; + + // if list position is undefined, create new list + if (list_pos == ANIM_EVENT_UNDEFINED) + list_pos = AddGlobalAnimEventList(); + + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + int value_pos = gaeli->num_event_values++; + + gaeli->event_value = checked_realloc(gaeli->event_value, + gaeli->num_event_values * sizeof(int *)); + + gaeli->event_value[value_pos] = event_value; + + return list_pos; +} + +int GetGlobalAnimEventValue(int list_pos, int value_pos) +{ + if (list_pos == ANIM_EVENT_UNDEFINED) + return ANIM_EVENT_NONE; + + struct GlobalAnimEventInfo *gaei = &global_anim_event_info; + struct GlobalAnimEventListInfo *gaeli = gaei->event_list[list_pos]; + + return gaeli->event_value[value_pos]; +} + // This function checks if a string of the format "string1, string2, ..." // exactly contains a string . @@ -10152,6 +10225,9 @@ int get_parameter_value(char *value_raw, char *suffix, int type) // add optional "click:anim_X" or "click:anim_X.part_X" parameter result |= get_anim_parameter_value(value); + + // final result is position in global animation event list + result = AddGlobalAnimEventValue(ANIM_EVENT_UNDEFINED, result); } else if (strEqual(suffix, ".init_event_action") || strEqual(suffix, ".anim_event_action")) diff --git a/src/files.h b/src/files.h index 031349f7..6af3a148 100644 --- a/src/files.h +++ b/src/files.h @@ -86,6 +86,9 @@ void ConvertLevels(void); void CreateLevelSketchImages(void); void CreateCustomElementImages(char *); +void FreeGlobalAnimEventInfo(void); +int GetGlobalAnimEventValue(int, int); + int get_parameter_value(char *, char *, int); #endif // FILES_H diff --git a/src/init.c b/src/init.c index 683bacdb..d3b33ec2 100644 --- a/src/init.c +++ b/src/init.c @@ -1301,8 +1301,8 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->anim_delay_random = 0; g->post_delay_fixed = 0; g->post_delay_random = 0; - g->init_event = ANIM_EVENT_DEFAULT; - g->anim_event = ANIM_EVENT_DEFAULT; + g->init_event = ANIM_EVENT_UNDEFINED; + g->anim_event = ANIM_EVENT_UNDEFINED; g->init_event_action = -1; g->anim_event_action = -1; g->draw_masked = FALSE; @@ -1723,6 +1723,8 @@ static void InitGraphicInfo(void) -1 }; + FreeGlobalAnimEventInfo(); + checked_free(graphic_info); graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo)); diff --git a/src/libgame/system.h b/src/libgame/system.h index 50dc5736..7b45b057 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -353,6 +353,7 @@ #define STYLE_DEFAULT STYLE_NONE // values for special global animation events +#define ANIM_EVENT_UNDEFINED -1 #define ANIM_EVENT_NONE 0 #define ANIM_EVENT_SELF (1 << 16) #define ANIM_EVENT_ANY (1 << 17) diff --git a/src/main.c b/src/main.c index 28eaf649..59faa000 100644 --- a/src/main.c +++ b/src/main.c @@ -7568,6 +7568,11 @@ struct GlobalAnimNameInfo global_anim_name_info[NUM_GLOBAL_ANIM_TOKENS + 1] = { NULL } }; +struct GlobalAnimEventInfo global_anim_event_info = +{ + NULL, 0 +}; + // ---------------------------------------------------------------------------- // music token prefix definitions diff --git a/src/main.h b/src/main.h index 4ae3c627..93874a7e 100644 --- a/src/main.h +++ b/src/main.h @@ -3412,6 +3412,18 @@ struct GlobalAnimInfo int music[NUM_GLOBAL_ANIM_PARTS_ALL][NUM_SPECIAL_GFX_ARGS]; }; +struct GlobalAnimEventListInfo +{ + int *event_value; + int num_event_values; +}; + +struct GlobalAnimEventInfo +{ + struct GlobalAnimEventListInfo **event_list; + int num_event_lists; +}; + struct GraphicInfo { Bitmap **bitmaps; // bitmaps in all required sizes @@ -3701,6 +3713,7 @@ extern struct TokenIntPtrInfo image_config_vars[]; extern struct FontInfo font_info[]; extern struct GlobalAnimInfo global_anim_info[]; extern struct GlobalAnimNameInfo global_anim_name_info[]; +extern struct GlobalAnimEventInfo global_anim_event_info; extern struct MusicPrefixInfo music_prefix_info[]; extern struct GraphicInfo *graphic_info; extern struct SoundInfo *sound_info;