+ if (part->init_delay_value > 0)
+ {
+ part->init_delay_value--;
+
+ return ANIM_STATE_WAITING;
+ }
+
+ if ((part->x <= -g->width && part->step_xoffset <= 0) ||
+ (part->x >= FULL_SXSIZE && part->step_xoffset >= 0) ||
+ (part->y <= -g->height && part->step_yoffset <= 0) ||
+ (part->y >= FULL_SYSIZE && part->step_yoffset >= 0))
+ return ANIM_STATE_RESTART;
+
+ if (part->anim_delay_value > 0)
+ {
+ part->anim_delay_value--;
+
+ if (part->anim_delay_value == 0)
+ return ANIM_STATE_RESTART | ANIM_STATE_RUNNING;
+ }
+
+ if (!DelayReachedExt(&part->step_delay, part->step_delay_value,
+ anim_sync_frame))
+ return ANIM_STATE_RUNNING;
+
+#if 0
+ {
+ static unsigned int last_counter = -1;
+ unsigned int counter = Counter();
+
+ printf("::: NEXT ANIM PART [%d, %d]\n",
+ anim_sync_frame, counter - last_counter);
+
+ last_counter = counter;
+ }
+#endif
+
+ part->x += part->step_xoffset;
+ part->y += part->step_yoffset;
+
+ return ANIM_STATE_RUNNING;
+}
+
+void HandleGlobalAnim_Main(struct GlobalAnimMainControlInfo *anim, int action)
+{
+ struct GlobalAnimPartControlInfo *part;
+ struct GraphicInfo *c = &anim->control_info;
+ boolean skip = FALSE;
+
+#if 0
+ printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
+ anim->mode_nr, anim->nr, anim->num_parts);
+ printf("::: %d, %d, %d\n", global.num_toons, setup.toons, num_toons);
+#endif
+
+#if 0
+ printf("::: %s(%d): %d, %d, %d [%d]\n",
+ (action == ANIM_START ? "ANIM_START" :
+ action == ANIM_CONTINUE ? "ANIM_CONTINUE" :
+ action == ANIM_STOP ? "ANIM_STOP" : "(should not happen)"),
+ anim->nr,
+ anim->state & ANIM_STATE_RESTART,
+ anim->state & ANIM_STATE_WAITING,
+ anim->state & ANIM_STATE_RUNNING,
+ anim->num_parts);
+#endif
+
+ switch (action)
+ {
+ case ANIM_START:
+ anim->state = ANIM_STATE_RESTART;
+ anim->part_counter = 0;
+ anim->active_part_nr = 0;
+ skip = TRUE;
+
+ break;
+
+ case ANIM_CONTINUE:
+ if (anim->state == ANIM_STATE_INACTIVE)
+ skip = TRUE;
+
+ break;
+
+ case ANIM_STOP:
+ anim->state = ANIM_STATE_INACTIVE;
+ skip = TRUE;
+
+ break;
+
+ default:
+ break;
+ }
+
+ if (c->anim_mode & ANIM_ALL || anim->num_parts == 0)
+ {
+ int num_parts = anim->num_parts + (anim->has_base ? 1 : 0);
+ int i;
+
+#if 0
+ printf("::: HandleGlobalAnim_Main: %d, %d => %d\n",
+ anim->mode_nr, anim->nr, num_parts);
+#endif
+
+ for (i = 0; i < num_parts; i++)
+ {
+ part = &anim->part[i];
+
+ switch (action)
+ {
+ case ANIM_START:
+ anim->state = ANIM_STATE_RUNNING;
+ part->state = ANIM_STATE_RESTART;
+ skip = TRUE;
+
+ break;
+
+ case ANIM_CONTINUE:
+ if (part->state == ANIM_STATE_INACTIVE)
+ skip = TRUE;
+
+ break;
+
+ case ANIM_STOP:
+ part->state = ANIM_STATE_INACTIVE;
+ skip = TRUE;
+
+ break;
+
+ default:
+ break;
+ }
+
+ if (skip)
+ continue;
+
+ part->state = HandleGlobalAnim_Part(part, part->state);
+ }
+
+ return;
+ }
+
+ if (skip)
+ return;
+
+ if (anim->state & ANIM_STATE_RESTART) // directly after restart
+ anim->active_part_nr = getGlobalAnimationPart(anim);
+
+ part = &anim->part[anim->active_part_nr];
+
+ part->state = ANIM_STATE_RUNNING;
+
+ anim->state = HandleGlobalAnim_Part(part, anim->state);
+
+ if (anim->state & ANIM_STATE_RESTART)
+ anim->part_counter++;
+}
+
+void HandleGlobalAnim_Mode(struct GlobalAnimControlInfo *ctrl, int action)
+{
+ int i;
+
+#if 0
+ printf("::: HandleGlobalAnim_Mode: %d => %d\n",
+ ctrl->nr, ctrl->num_anims);
+#endif
+
+ for (i = 0; i < ctrl->num_anims; i++)
+ HandleGlobalAnim_Main(&ctrl->anim[i], action);
+}
+
+void HandleGlobalAnim(int action)
+{
+#if 0
+ printf("::: HandleGlobalAnim [mode == %d]\n", game_status);
+#endif
+
+ HandleGlobalAnim_Mode(&global_anim_ctrl[GAME_MODE_DEFAULT], action);
+ HandleGlobalAnim_Mode(&global_anim_ctrl[game_status], action);
+}
+
+void InitAnimation()
+{
+ // HandleAnimation(ANIM_START);
+
+#if 0
+ printf("::: InitAnimation\n");
+#endif
+
+ // InitCounter();
+
+ InitGlobalAnimControls();
+
+ HandleGlobalAnim(ANIM_START);
+
+ do_animations = TRUE;
+}
+
+void StopAnimation()
+{
+ // HandleAnimation(ANIM_STOP);
+
+#if 0
+ printf("::: StopAnimation\n");
+#endif
+
+ HandleGlobalAnim(ANIM_STOP);
+
+ do_animations = FALSE;
+}
+
+static void DoAnimationExt()
+{
+#if 0
+ printf("::: DoAnimation [%d, %d]\n", anim_sync_frame, Counter());
+#endif
+
+#if 1
+ WaitUntilDelayReached(&anim_sync_frame_delay, anim_sync_frame_delay_value);
+ anim_sync_frame++;
+#else
+ if (DelayReached(&anim_sync_frame_delay, anim_sync_frame_delay_value))
+ anim_sync_frame++;
+#endif
+
+ HandleGlobalAnim(ANIM_CONTINUE);
+
+#if 1
+ // force screen redraw in next frame to continue drawing global animations
+ redraw_mask = REDRAW_ALL;
+#endif
+}
+
+void DoAnimation()
+{
+ // HandleAnimation(ANIM_CONTINUE);
+
+#if 1
+ // force screen redraw in next frame to continue drawing global animations
+ redraw_mask = REDRAW_ALL;
+#endif