2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

96 lines
2.0 KiB

  1. #ifndef IZ_VIDEO_H
  2. #define IZ_VIDEO_H
  3. #include <stdio.h>
  4. #include "minIni.h"
  5. #include "SDL_render.h"
  6. #include <SDL_image.h>
  7. #include "../../../net/IZ_net_client.h"
  8. #include "../../../config/IZ_config.h"
  9. #include "../../../common/IZ_common.h"
  10. #include "../../geometry/IZ_vector2d.h"
  11. #include "../../input/IZ_input.h"
  12. #define MAX_ACTIVE_SPRITES 512u
  13. typedef enum {
  14. // eyecandy, e.g. sparks
  15. IZ_VIDEO_SPRITE_PRIORITY_LOWEST,
  16. // bottom backgrounds
  17. IZ_VIDEO_SPRITE_PRIORITY_LOWER,
  18. // top backgrounds
  19. IZ_VIDEO_SPRITE_PRIORITY_LOW,
  20. // projectiles
  21. IZ_VIDEO_SPRITE_PRIORITY_MEDIUM,
  22. // foreground objects
  23. IZ_VIDEO_SPRITE_PRIORITY_HIGH,
  24. // pickups
  25. IZ_VIDEO_SPRITE_PRIORITY_HIGHER,
  26. // player, enemies, weapons
  27. IZ_VIDEO_SPRITE_PRIORITY_HIGHEST,
  28. } IZ_VideoSpritePriority;
  29. typedef struct {
  30. SDL_Texture* texture;
  31. IZ_Vector2D position;
  32. f32 original_width;
  33. f32 original_height;
  34. f32 scale_factor;
  35. f32 rotate_degrees;
  36. bool flip_x;
  37. bool flip_y;
  38. } IZ_Sprite;
  39. typedef struct {
  40. const char* dir;
  41. const char* filename;
  42. IZ_VideoSpritePriority priority;
  43. } IZ_VideoLoadSpriteParams;
  44. typedef struct {
  45. u16 width;
  46. u16 height;
  47. u8 max_fps;
  48. } IZ_VideoConfig;
  49. typedef struct {
  50. IZ_Sprite sprite;
  51. u64 requested_at;
  52. IZ_VideoSpritePriority priority;
  53. } IZ_SpriteSlot;
  54. typedef struct {
  55. void* user_data;
  56. IZ_VideoConfig config;
  57. u64 last_update_at;
  58. SDL_Window* window;
  59. SDL_Renderer* renderer;
  60. IZ_SpriteSlot active_sprites[MAX_ACTIVE_SPRITES];
  61. } IZ_VideoState;
  62. static const IZ_VideoState IZ_VIDEO_DEFAULT_STATE = {
  63. .user_data = NULL,
  64. .config = {
  65. .width = 320u,
  66. .height = 240u,
  67. .max_fps = 30u,
  68. },
  69. .last_update_at = 0,
  70. .renderer = NULL,
  71. .window = NULL,
  72. .active_sprites = {},
  73. };
  74. IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, void*, const char*, u8, const char*[]);
  75. IZ_ProcedureResult IZ_VideoSaveConfig(IZ_VideoState*, const char*);
  76. u16 IZ_VideoGetNextFreeSpriteSlot(IZ_VideoState*, IZ_VideoSpritePriority);
  77. void IZ_VideoLoadSprite(IZ_VideoState*, IZ_VideoLoadSpriteParams, IZ_SpriteSlot*);
  78. void IZ_VideoTeardown(IZ_VideoState*);
  79. #endif