From: Holger Schemel Date: Fri, 25 Mar 2016 12:23:57 +0000 (+0100) Subject: added support for '.draw_order' for global animations X-Git-Tag: 4.0.0.0-rc1~30 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=ec5f4027a019ebf435b41577ab1234849c77a059;p=rocksndiamonds.git added support for '.draw_order' for global animations --- diff --git a/src/cartoons.c b/src/cartoons.c index 0563e1de..1d175186 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -160,6 +160,38 @@ static int getGlobalAnimationPart(struct GlobalAnimMainControlInfo *anim) return part_nr; } +static int compareGlobalAnimPartControlInfo(const void *obj1, const void *obj2) +{ + const struct GlobalAnimPartControlInfo *o1 = + (struct GlobalAnimPartControlInfo *)obj1; + const struct GlobalAnimPartControlInfo *o2 = + (struct GlobalAnimPartControlInfo *)obj2; + int compare_result; + + if (o1->control_info.draw_order != o2->control_info.draw_order) + compare_result = o1->control_info.draw_order - o2->control_info.draw_order; + else + compare_result = o1->nr - o2->nr; + + return compare_result; +} + +static int compareGlobalAnimMainControlInfo(const void *obj1, const void *obj2) +{ + const struct GlobalAnimMainControlInfo *o1 = + (struct GlobalAnimMainControlInfo *)obj1; + const struct GlobalAnimMainControlInfo *o2 = + (struct GlobalAnimMainControlInfo *)obj2; + int compare_result; + + if (o1->control_info.draw_order != o2->control_info.draw_order) + compare_result = o1->control_info.draw_order - o2->control_info.draw_order; + else + compare_result = o1->nr - o2->nr; + + return compare_result; +} + static void PrepareBackbuffer() { if (game_status != GAME_MODE_PLAYING) @@ -382,6 +414,27 @@ void InitGlobalAnimControls() InitToonControls(); + /* sort all animations according to draw_order and animation number */ + for (m = 0; m < NUM_GAME_MODES; m++) + { + struct GlobalAnimControlInfo *ctrl = &global_anim_ctrl[m]; + + /* sort all main animations for this game mode */ + qsort(ctrl->anim, ctrl->num_anims, + sizeof(struct GlobalAnimMainControlInfo), + compareGlobalAnimMainControlInfo); + + for (a = 0; a < ctrl->num_anims; a++) + { + struct GlobalAnimMainControlInfo *anim = &ctrl->anim[a]; + + /* sort all animation parts for this main animation */ + qsort(anim->part, anim->num_parts, + sizeof(struct GlobalAnimPartControlInfo), + compareGlobalAnimPartControlInfo); + } + } + for (i = 0; i < NUM_GAME_MODES; i++) game_mode_anim_classes[i] = ANIM_CLASS_NONE; for (i = 0; game_mode_anim_classes_list[i].game_mode != -1; i++) diff --git a/src/init.c b/src/init.c index 943839ed..922fc11a 100644 --- a/src/init.c +++ b/src/init.c @@ -1136,6 +1136,7 @@ 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->draw_order = 0; g->fade_mode = FADE_MODE_DEFAULT; g->fade_delay = -1; g->post_delay = -1; @@ -1369,7 +1370,8 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->draw_masked = parameter[GFX_ARG_DRAW_MASKED]; /* used for toon animations and global animations */ - g->draw_order = parameter[GFX_ARG_DRAW_ORDER]; + if (parameter[GFX_ARG_DRAW_ORDER] != ARG_UNDEFINED_VALUE) + g->draw_order = parameter[GFX_ARG_DRAW_ORDER]; /* optional graphic for cloning all graphics settings */ if (parameter[GFX_ARG_CLONE_FROM] != ARG_UNDEFINED_VALUE)