From f1f974498c1691431a5755d917f674c7cf56eb53 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 25 Apr 2016 19:32:04 +0200 Subject: [PATCH] renamed and cleaned up source files for handling global animations --- src/Android.mk | 3 +- src/Makefile | 4 +- src/{cartoons.c => anim.c} | 77 +++++++++++++++++++++++++++++++++++++- src/{cartoons.h => anim.h} | 13 ++----- src/events.c | 2 +- src/game.c | 1 + src/init.c | 2 +- src/libgame/Makefile | 2 - src/libgame/libgame.h | 1 - src/libgame/toons.c | 70 ---------------------------------- src/libgame/toons.h | 26 ------------- src/screens.c | 2 +- src/tape.c | 2 +- src/tools.c | 14 +++---- 14 files changed, 94 insertions(+), 125 deletions(-) rename src/{cartoons.c => anim.c} (92%) rename src/{cartoons.h => anim.h} (71%) delete mode 100644 src/libgame/toons.c delete mode 100644 src/libgame/toons.h diff --git a/src/Android.mk b/src/Android.mk index 9922a17a..9029cdd4 100644 --- a/src/Android.mk +++ b/src/Android.mk @@ -41,7 +41,6 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \ libgame/sound.c \ libgame/joystick.c \ libgame/snapshot.c \ - libgame/toons.c \ libgame/image.c \ libgame/random.c \ libgame/hash.c \ @@ -97,7 +96,7 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \ editor.c \ files.c \ tape.c \ - cartoons.c \ + anim.c \ network.c \ netserv.c diff --git a/src/Makefile b/src/Makefile index 6e9bd2bc..dcc625cf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -140,7 +140,7 @@ SRCS = main.c \ editor.c \ files.c \ tape.c \ - cartoons.c \ + anim.c \ network.c \ netserv.c @@ -158,7 +158,7 @@ OBJS = main.o \ editor.o \ files.o \ tape.o \ - cartoons.o \ + anim.o \ network.o \ netserv.o diff --git a/src/cartoons.c b/src/anim.c similarity index 92% rename from src/cartoons.c rename to src/anim.c index e572b043..fd6898ea 100644 --- a/src/cartoons.c +++ b/src/anim.c @@ -6,10 +6,10 @@ // info@artsoft.org // http://www.artsoft.org/ // ---------------------------------------------------------------------------- -// cartoons.c +// anim.c // ============================================================================ -#include "cartoons.h" +#include "anim.h" #include "main.h" #include "tools.h" @@ -49,6 +49,18 @@ ANIM_CLASS_MENU | \ ANIM_CLASS_SUBMENU) +/* values for global animation states */ +#define ANIM_STATE_INACTIVE 0 +#define ANIM_STATE_RESTART (1 << 0) +#define ANIM_STATE_WAITING (1 << 1) +#define ANIM_STATE_RUNNING (1 << 2) + +/* values for global animation control */ +#define ANIM_START 0 +#define ANIM_CONTINUE 1 +#define ANIM_STOP 2 + + struct GlobalAnimPartControlInfo { int nr; @@ -171,6 +183,67 @@ static int anim_status_last = GAME_MODE_DEFAULT; static int anim_classes_last = ANIM_CLASS_NONE; +/* ========================================================================= */ +/* generic animation frame calculation */ +/* ========================================================================= */ + +int getAnimationFrame(int num_frames, int delay, int mode, int start_frame, + int sync_frame) +{ + int frame = 0; + + sync_frame += start_frame * delay; + + if (mode & ANIM_LOOP) /* looping animation */ + { + frame = (sync_frame % (delay * num_frames)) / delay; + } + else if (mode & ANIM_LINEAR) /* linear (non-looping) animation */ + { + frame = sync_frame / delay; + + if (frame > num_frames - 1) + frame = num_frames - 1; + } + else if (mode & ANIM_PINGPONG) /* oscillate (border frames once) */ + { + int max_anim_frames = (num_frames > 1 ? 2 * num_frames - 2 : 1); + + frame = (sync_frame % (delay * max_anim_frames)) / delay; + frame = (frame < num_frames ? frame : max_anim_frames - frame); + } + else if (mode & ANIM_PINGPONG2) /* oscillate (border frames twice) */ + { + int max_anim_frames = 2 * num_frames; + + frame = (sync_frame % (delay * max_anim_frames)) / delay; + frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); + } + else if (mode & ANIM_RANDOM) /* play frames in random order */ + { + /* note: expect different frames for the same delay cycle! */ + + if (gfx.anim_random_frame < 0) + frame = GetSimpleRandom(num_frames); + else + frame = gfx.anim_random_frame % num_frames; + } + else if (mode & (ANIM_CE_VALUE | ANIM_CE_SCORE | ANIM_CE_DELAY)) + { + frame = sync_frame % num_frames; + } + + if (mode & ANIM_REVERSE) /* use reverse animation direction */ + frame = num_frames - frame - 1; + + return frame; +} + + +/* ========================================================================= */ +/* global animation functions */ +/* ========================================================================= */ + static int getGlobalAnimationPart(struct GlobalAnimMainControlInfo *anim) { struct GraphicInfo *c = &anim->control_info; diff --git a/src/cartoons.h b/src/anim.h similarity index 71% rename from src/cartoons.h rename to src/anim.h index ff84dd0e..b55a550f 100644 --- a/src/cartoons.h +++ b/src/anim.h @@ -6,19 +6,14 @@ // info@artsoft.org // http://www.artsoft.org/ // ---------------------------------------------------------------------------- -// cartoons.h +// anim.h // ============================================================================ -#ifndef CARTOONS_H -#define CARTOONS_H +#ifndef ANIM_H +#define ANIM_H -/* values for global animations */ -#define ANIM_STATE_INACTIVE 0 -#define ANIM_STATE_RESTART (1 << 0) -#define ANIM_STATE_WAITING (1 << 1) -#define ANIM_STATE_RUNNING (1 << 2) - +int getAnimationFrame(int, int, int, int, int); void InitGlobalAnimations(void); void DrawGlobalAnimations(int); diff --git a/src/events.c b/src/events.c index 2d6e7f85..564f647d 100644 --- a/src/events.c +++ b/src/events.c @@ -19,7 +19,7 @@ #include "editor.h" #include "files.h" #include "tape.h" -#include "cartoons.h" +#include "anim.h" #include "network.h" diff --git a/src/game.c b/src/game.c index d3c403fe..8739b9f8 100644 --- a/src/game.c +++ b/src/game.c @@ -19,6 +19,7 @@ #include "files.h" #include "tape.h" #include "network.h" +#include "anim.h" /* DEBUG SETTINGS */ diff --git a/src/init.c b/src/init.c index 299166c0..79343297 100644 --- a/src/init.c +++ b/src/init.c @@ -21,7 +21,7 @@ #include "files.h" #include "network.h" #include "netserv.h" -#include "cartoons.h" +#include "anim.h" #include "config.h" #include "conf_e2g.c" /* include auto-generated data structure definitions */ diff --git a/src/libgame/Makefile b/src/libgame/Makefile index c27d8216..4693c226 100644 --- a/src/libgame/Makefile +++ b/src/libgame/Makefile @@ -19,7 +19,6 @@ SRCS = system.c \ sound.c \ joystick.c \ snapshot.c \ - toons.c \ image.c \ random.c \ hash.c \ @@ -33,7 +32,6 @@ OBJS = system.o \ sound.o \ snapshot.o \ joystick.o \ - toons.o \ image.o \ random.o \ hash.o \ diff --git a/src/libgame/libgame.h b/src/libgame/libgame.h index 4b40b509..a3a3c803 100644 --- a/src/libgame/libgame.h +++ b/src/libgame/libgame.h @@ -23,7 +23,6 @@ #include "sound.h" #include "snapshot.h" #include "joystick.h" -#include "toons.h" #include "image.h" #include "setup.h" #include "misc.h" diff --git a/src/libgame/toons.c b/src/libgame/toons.c deleted file mode 100644 index 50a164af..00000000 --- a/src/libgame/toons.c +++ /dev/null @@ -1,70 +0,0 @@ -// ============================================================================ -// Artsoft Retro-Game Library -// ---------------------------------------------------------------------------- -// (c) 1995-2014 by Artsoft Entertainment -// Holger Schemel -// info@artsoft.org -// http://www.artsoft.org/ -// ---------------------------------------------------------------------------- -// toons.c -// ============================================================================ - -#include "toons.h" -#include "misc.h" - - -/* ========================================================================= */ -/* generic animation frame calculation */ -/* ========================================================================= */ - -int getAnimationFrame(int num_frames, int delay, int mode, int start_frame, - int sync_frame) -{ - int frame = 0; - - sync_frame += start_frame * delay; - - if (mode & ANIM_LOOP) /* looping animation */ - { - frame = (sync_frame % (delay * num_frames)) / delay; - } - else if (mode & ANIM_LINEAR) /* linear (non-looping) animation */ - { - frame = sync_frame / delay; - - if (frame > num_frames - 1) - frame = num_frames - 1; - } - else if (mode & ANIM_PINGPONG) /* oscillate (border frames once) */ - { - int max_anim_frames = (num_frames > 1 ? 2 * num_frames - 2 : 1); - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame); - } - else if (mode & ANIM_PINGPONG2) /* oscillate (border frames twice) */ - { - int max_anim_frames = 2 * num_frames; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); - } - else if (mode & ANIM_RANDOM) /* play frames in random order */ - { - /* note: expect different frames for the same delay cycle! */ - - if (gfx.anim_random_frame < 0) - frame = GetSimpleRandom(num_frames); - else - frame = gfx.anim_random_frame % num_frames; - } - else if (mode & (ANIM_CE_VALUE | ANIM_CE_SCORE | ANIM_CE_DELAY)) - { - frame = sync_frame % num_frames; - } - - if (mode & ANIM_REVERSE) /* use reverse animation direction */ - frame = num_frames - frame - 1; - - return frame; -} diff --git a/src/libgame/toons.h b/src/libgame/toons.h deleted file mode 100644 index 26867df9..00000000 --- a/src/libgame/toons.h +++ /dev/null @@ -1,26 +0,0 @@ -// ============================================================================ -// Artsoft Retro-Game Library -// ---------------------------------------------------------------------------- -// (c) 1995-2014 by Artsoft Entertainment -// Holger Schemel -// info@artsoft.org -// http://www.artsoft.org/ -// ---------------------------------------------------------------------------- -// toons.h -// ============================================================================ - -#ifndef TOONS_H -#define TOONS_H - -#include "system.h" - - -/* values for toon animation */ -#define ANIM_START 0 -#define ANIM_CONTINUE 1 -#define ANIM_STOP 2 - - -int getAnimationFrame(int, int, int, int, int); - -#endif /* TOONS_H */ diff --git a/src/screens.c b/src/screens.c index d5e65265..f4470146 100644 --- a/src/screens.c +++ b/src/screens.c @@ -18,7 +18,7 @@ #include "editor.h" #include "files.h" #include "tape.h" -#include "cartoons.h" +#include "anim.h" #include "network.h" #include "init.h" #include "config.h" diff --git a/src/tape.c b/src/tape.c index c10edefc..bba4d4d2 100644 --- a/src/tape.c +++ b/src/tape.c @@ -17,7 +17,7 @@ #include "tools.h" #include "files.h" #include "network.h" -#include "cartoons.h" +#include "anim.h" #define DEBUG_TAPE_WHEN_PLAYING FALSE diff --git a/src/tools.c b/src/tools.c index 2c605532..972e5a24 100644 --- a/src/tools.c +++ b/src/tools.c @@ -17,7 +17,7 @@ #include "init.h" #include "game.h" #include "events.h" -#include "cartoons.h" +#include "anim.h" #include "network.h" #include "tape.h" #include "screens.h" @@ -8339,7 +8339,7 @@ void ChangeViewportPropertiesIfNeeded() int new_scr_fieldy_buffers = new_sysize / new_tilesize_var; boolean init_gfx_buffers = FALSE; boolean init_video_buffer = FALSE; - boolean init_gadgets_and_toons = FALSE; + boolean init_gadgets_and_anims = FALSE; boolean init_em_graphics = FALSE; if (new_win_xsize != WIN_XSIZE || @@ -8350,7 +8350,7 @@ void ChangeViewportPropertiesIfNeeded() init_video_buffer = TRUE; init_gfx_buffers = TRUE; - init_gadgets_and_toons = TRUE; + init_gadgets_and_anims = TRUE; // printf("::: video: init_video_buffer, init_gfx_buffers\n"); } @@ -8465,10 +8465,10 @@ void ChangeViewportPropertiesIfNeeded() TILESIZE_VAR = new_tilesize_var; init_gfx_buffers = TRUE; - init_gadgets_and_toons = TRUE; + init_gadgets_and_anims = TRUE; // printf("::: viewports: init_gfx_buffers\n"); - // printf("::: viewports: init_gadgets_and_toons\n"); + // printf("::: viewports: init_gadgets_and_anims\n"); } if (init_gfx_buffers) @@ -8495,9 +8495,9 @@ void ChangeViewportPropertiesIfNeeded() InitImageTextures(); } - if (init_gadgets_and_toons) + if (init_gadgets_and_anims) { - // printf("::: init_gadgets_and_toons\n"); + // printf("::: init_gadgets_and_anims\n"); InitGadgets(); InitGlobalAnimations(); -- 2.34.1