1 /*! \file 2 * \brief BK animation data handling. 3 * \details Functions and structs for reading, writing and modifying OMF:2097 BK specific animation structures. 4 * \copyright MIT license. 5 * \date 2013-2014 6 * \author Andrew Thompson 7 * \author Tuomas Virtanen 8 */ 9 10 #ifndef _SD_BK_ANIMS 11 #define _SD_BK_ANIMS 12 13 #include <stdint.h> 14 #include "shadowdive/animation.h" 15 #ifdef SD_USE_INTERNAL 16 #include "shadowdive/internal/reader.h" 17 #include "shadowdive/internal/writer.h" 18 #endif 19 20 #define SD_BK_FOOTER_STRING_MAX 512 ///< Max BK footer string length 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /*! \brief BK specific animation information 27 * 28 * Information about the BK specific animation things. 29 */ 30 typedef struct { 31 uint8_t null; ///< Always 0 ? 32 uint8_t chain_hit; ///< Animation to chain to if collision/hit 33 uint8_t chain_no_hit; ///< Animation to chain to on no collision/hit 34 uint8_t load_on_start; ///< Actually repeat flag 35 uint16_t probability; ///< Probability of animation 36 uint8_t hazard_damage; ///< Hazard damage on hit 37 char footer_string[SD_BK_FOOTER_STRING_MAX]; ///< Footer string 38 sd_animation *animation; ///< Animation ptr or NULL. On BK save, must be != NULL. 39 } sd_bk_anim; 40 41 42 /*! \brief Initialize BK animation info structure 43 * 44 * Initializes the BK animation info structure with empty values. 45 * 46 * \retval SD_INVALID_INPUT BK struct pointer was NULL 47 * \retval SD_SUCCESS Success. 48 * 49 * \param bka Allocated BK animation info struct pointer. 50 */ 51 int sd_bk_anim_create(sd_bk_anim *bka); 52 53 /*! \brief Copy BK animation info structure 54 * 55 * Copies the contents of a BK animation info structure. _ALL_ internals will be copied. 56 * The copied structure must be freed using sd_bk_anim_free(). 57 * 58 * Destination buffer does not need to be cleared. Source buffer must be a valid 59 * move structure, or problems are likely to appear. 60 * 61 * \retval SD_OUT_OF_MEMORY Memory ran out. Destination struct should now be considered invalid and freed. 62 * \retval SD_INVALID_INPUT Either input value was NULL. 63 * \retval SD_SUCCESS Success. 64 * 65 * \param dst Destination BK animation info struct pointer. 66 * \param src Source BK animation info struct pointer. 67 */ 68 int sd_bk_anim_copy(sd_bk_anim *dst, const sd_bk_anim *src); 69 70 /*! \brief Free BK animation info structure 71 * 72 * Frees up all memory reserved by the BK animation info structure. 73 * All contents will be freed, all pointers to contents will be invalid. 74 * 75 * \param bka BK animation info struct to modify. 76 */ 77 void sd_bk_anim_free(sd_bk_anim *bka); 78 79 /*! \brief Set animation struct for BK animation info struct 80 * 81 * Sets an animation for the BK animation info struct. Animation will be copied, 82 * so remember to free your local copy yourself. Note that any valid 83 * BK anim info struct should ALWAYS contain an animation. Otherwise there will be problems 84 * eg. saving the BK file. 85 * 86 * A NULL value for animation field will result in bka->animation field getting freed. 87 * 88 * \retval SD_OUT_OF_MEMORY Memory ran out. Animation field will be NULL. 89 * \retval SD_INVALID_INPUT Move struct pointer was NULL. 90 * \retval SD_SUCCESS Success. 91 * 92 * \param bka BK animation info struct to modify. 93 * \param animation Animation to set. This will be copied. 94 */ 95 int sd_bk_anim_set_animation(sd_bk_anim *bka, const sd_animation *animation); 96 97 /*! \brief Get the current animation 98 * 99 * Returns a pointer to the current animation for the BK animation info struct. 100 * If animation is not set, NULL will be returned. 101 * 102 * \retval NULL Animation does not exist 103 * \retval sd_animation* Success. 104 * 105 * \param bka BK animation info struct to modify. 106 */ 107 sd_animation* sd_bk_anim_get_animation(const sd_bk_anim *bka); 108 109 /*! \brief Set BK animation info footer string 110 * 111 * Sets the BK animation info footer string for the struct. Maximum length is 112 * 512 bytes. Longer strings will result in error. 113 * 114 * \retval SD_INVALID_INPUT Input string was too long. 115 * \retval SD_SUCCESS Success. 116 * 117 * \param bka BK animation info struct to modify. 118 * \param data String to set. 119 */ 120 int sd_bk_set_anim_string(sd_bk_anim *bka, const char *data); 121 122 #ifdef SD_USE_INTERNAL 123 int sd_bk_anim_load(sd_reader *reader, sd_bk_anim *bka); 124 int sd_bk_anim_save(sd_writer *writer, const sd_bk_anim *bka); 125 #endif 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif // _SD_BK_ANIMS 132