No Description

objects.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file objects.h
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Helpful operations and structure on object entities.
  27. *
  28. * This header provides a framework for working with the object engine.
  29. * Methods are used to create, destroy, manipulate and update the object
  30. * entities.
  31. */
  32. #ifndef OBJECTS_H_
  33. #define OBJECTS_H_
  34. #include "types.h"
  35. /* === STRUCTURES === */
  36. struct obj_frame {
  37. u16 data;
  38. u16 duration;
  39. };
  40. struct obj_rotscale_frame {
  41. u16 scale_delta_x;
  42. u16 scale_delta_y;
  43. u8 rot_delta;
  44. u8 duration;
  45. u16 field_6;
  46. };
  47. struct obj_oam_attributes {
  48. u16 attr0;
  49. u16 attr1;
  50. u16 attr2;
  51. u16 rotscale;
  52. };
  53. struct obj_entity {
  54. struct obj_oam_attributes final_oam;
  55. struct obj_frame **animation_table;
  56. u32 *gfx_table;
  57. u32 *rotscale_table;
  58. struct obj_template *template;
  59. u32 field18;
  60. u32 *callback;
  61. u16 x;
  62. u16 y;
  63. u16 x2;
  64. u16 y2;
  65. u8 x_centre;
  66. u8 y_centre;
  67. u8 anim_number;
  68. u8 anim_frame;
  69. u8 anim_delay;
  70. u8 counter;
  71. u16 private[8];
  72. u8 bitfield2;
  73. u8 bitfield;
  74. u16 anim_data_offset;
  75. u8 field42;
  76. u8 field43;
  77. };
  78. extern struct obj_entity objects[64];
  79. typedef void (*object_callback)(struct obj_entity*);
  80. struct obj_template {
  81. u16 tiles_tag;
  82. u16 pal_tag;
  83. struct obj_oam_attributes *oam;
  84. struct obj_frame **animation;
  85. u32 *graphics;
  86. struct obj_rotscale_frame **rotscale;
  87. object_callback callback;
  88. };
  89. struct obj_resource {
  90. void *data;
  91. u16 size;
  92. u16 tag;
  93. };
  94. /* === EXTERN METHODS === */
  95. /**
  96. *
  97. * @param t pointer to obj_template structure which should be instancinated
  98. * @param x x position
  99. * @param y y position
  100. * @param b index to start searching at ( ? )
  101. * @return id of the newly generated obj_entity structure [in objects array]
  102. */
  103. extern u8 obj_template_instanciate_forward_search(struct obj_template *t, u16 x, u16 y, u8 b);
  104. /**
  105. *
  106. * @param src obj_resource structure to allocate
  107. * @return tag of the allocated resource
  108. */
  109. extern u16 obj_gpu_tile_decompress_alloc_tag_and_upload(struct obj_resource *src);
  110. /**
  111. * @brief parses and uploads the objects in memory to the object hardware
  112. */
  113. extern void obj_gpu_sprites_upload();
  114. /**
  115. *
  116. * @param pal palette resource to create
  117. * @return success ( ? )
  118. */
  119. extern u8 obj_gpu_pal_alloc_tag_and_apply(struct obj_resource *pal);
  120. /**
  121. *
  122. * @param tag tag of tile resource to free
  123. */
  124. extern void obj_gpu_tile_free_by_tag(u16 tag);
  125. /**
  126. *
  127. * @param obj obj_entitiy structure to free and delete
  128. */
  129. extern void obj_delete_and_free_tiles(struct obj_entity *obj);
  130. /**
  131. * @brief delete all object entities in game
  132. */
  133. extern void obj_delete_all();
  134. /**
  135. * @brief execute object callbacks
  136. */
  137. extern void objc_exec();
  138. /**
  139. * @brief synchronize object data with object hardware memory
  140. */
  141. void obj_sync();
  142. #endif