-
Notifications
You must be signed in to change notification settings - Fork 0
/
Texture.h
53 lines (47 loc) · 1.47 KB
/
Texture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <SDL_render.h>
#include <stdbool.h>
#include "HashMap.h"
#include "Position.h"
#include "Viewport.h"
//##############################
//DEFINITIONS
//##############################
#define ASSET_DIRECTORY "assets"
#define SPRITE_DIRECTORY "/sprites/"
typedef Vector2D Dimensions;
typedef Vector2Df Position;
//##############################
//STRUCTS
//##############################
typedef struct Texture
{
SDL_Texture* sdl_texture;
Dimensions dimensions;
} Texture;
typedef struct Sprite
{
Texture* texture;
Position position;
Vector2Df center;
SDL_RendererFlip flip;
float rotation_angle;
} Sprite;
//##############################
//FUNCTIONS
//##############################
Sprite* LoadSprite(const char* _fileName);
Texture* LoadTextureFromDisk(const char* _fileName);
SDL_Rect SpriteGetSourceSDLRect(const Sprite* _sprite);
SDL_Rect SpriteGetSourceSDLRectAbsolute(const Sprite* _sprite);
SDL_Rect SpriteGetDestinationSDLRect(const Sprite* _sprite, const Viewport* _viewport);
SDL_Point SpriteGetCenter(const Sprite* _sprite);
void FlipSprite(Sprite* _sprite, bool _vertical, bool _horizontal);
void DestroyTextures(void);
//##############################
//PRIVATE
//##############################
static HashMap* texture_hashmap;
static void InitializeTextureHashMap(void);
static void AddTextureToHashMap(const char* _fileName, Texture* _texture);
static Texture* GetTextureFromHashMap(const char* _fileName);