-
Notifications
You must be signed in to change notification settings - Fork 4
/
Sprite.h
68 lines (51 loc) · 1.33 KB
/
Sprite.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include "Asset.h"
#include "sf/Vector.h"
#include "sf/Array.h"
#include "ext/sokol/sokol_defs.h"
namespace sp {
struct Atlas
{
// Texture extents and handle
uint32_t width = 0, height = 0;
sg_image image = { 0 };
// Record a batch break caused by this atlas,
// used for optimizing atlases
void brokeBatch();
// -- Static API
// Query a list of currently active atlases
static void getAtlases(sf::Array<Atlas*> &atlases);
};
struct SpriteProps : AssetProps
{
// Combine sprites with the same `atlasName` into a single atlas.
sf::SmallStringBuf<16> atlasName;
bool tileX = false;
bool tileY = false;
virtual uint32_t hash() const final;
virtual bool equal(const AssetProps &rhs) const final;
virtual void copyTo(AssetProps *rhs) const final;
};
struct Sprite : Asset
{
static AssetType SelfType;
using PropType = SpriteProps;
// -- Only valid for loaded sprites
// Atlas and position
Atlas *atlas = nullptr;
uint32_t x = 0, y = 0;
uint32_t width = 0, height = 0;
uint32_t paddedWidth = 0, paddedHeight = 0;
float aspect = 0.0f;
// Cropped quad vertices
sf::Vec2 minVert, maxVert;
// UV multiply/add from vertex
sf::Vec2 vertUvScale, vertUvBias;
// -- Static API
// Lifecycle
static void globalInit();
static void globalCleanup();
static void globalUpdate();
};
using SpriteRef = Ref<Sprite>;
}