FIFE
be64c707dea6b3250bd4355bf5c825d25920087d
atlasbook.h
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (C) 2005-2019 by the FIFE team *
3
* http://www.fifengine.net *
4
* This file is part of FIFE. *
5
* *
6
* FIFE is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Lesser General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2.1 of the License, or (at your option) any later version. *
10
* *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14
* Lesser General Public License for more details. *
15
* *
16
* You should have received a copy of the GNU Lesser General Public *
17
* License along with this library; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20
***************************************************************************/
21
22
#ifndef FIFE_VIDEO_ATLASBOOK_H
23
#define FIFE_VIDEO_ATLASBOOK_H
24
25
// Standard C++ library includes
26
#include <vector>
27
#include <cassert>
28
#include <cmath>
29
#include <algorithm>
30
31
// 3rd party library includes
32
33
// FIFE includes
34
// These includes are split up in two parts, separated by one empty line
35
// First block: files included from the FIFE root src directory
36
// Second block: files included from the same folder
37
#include "
util/structures/rect.h
"
38
39
namespace
FIFE
{
40
41
class
AtlasBlock
{
42
public
:
43
uint32_t
page
;
44
uint32_t
left
,
right
,
top
,
bottom
;
45
46
AtlasBlock
(
const
Rect
& rect,
uint32_t
page)
47
: page(page),
48
left(rect.x), right(rect.right()),
49
top(rect.y), bottom(rect.bottom()){
50
}
51
52
AtlasBlock
() {
53
}
54
55
// (0,0) [left] [right]
56
// +--------------------
57
// |
58
// [top] | +---------+
59
// | | |
60
// | | |
61
// | | |
62
// | | |
63
// [bottom] | +---------+
64
// |
65
66
// bottom > top
67
// right > left
68
69
void
setTrivial
() {
70
left = right = top = bottom = 0;
71
}
72
73
bool
isTrivial
()
const
{
74
return
getWidth
() == 0 ||
getHeight
() == 0;
75
}
76
77
uint32_t
getWidth
()
const
{
return
right -
left
; }
78
uint32_t
getHeight
()
const
{
return
bottom -
top
; }
79
80
AtlasBlock
intersects
(
AtlasBlock
const
& rect)
const
;
81
void
merge
(
AtlasBlock
const
& rect);
82
};
83
84
class
AtlasPage
{
85
public
:
86
AtlasPage
(
uint32_t
width,
uint32_t
height,
87
uint32_t
pixelSize,
uint32_t
page
)
88
: width(width), height(height), pixelSize(pixelSize),
89
page(page), freePixels(width*height*pixelSize){
90
}
91
92
AtlasBlock
* getBlock(
uint32_t
width,
uint32_t
height);
93
void
shrink(
bool
pot);
94
95
uint32_t
getWidth
()
const
{
96
return
width;
97
}
98
99
uint32_t
getHeight
()
const
{
100
return
height;
101
}
102
103
private
:
104
AtlasBlock
const
*
intersects
(
AtlasBlock
const
* block)
const
;
105
106
uint32_t
width
, height;
107
uint32_t
pixelSize
;
108
uint32_t
page
;
109
int32_t
freePixels
;
110
111
typedef
std::vector<AtlasBlock>
Blocks
;
112
Blocks
blocks
;
113
};
114
115
class
AtlasBook
{
116
public
:
117
118
AtlasBook
(
uint32_t
pageWidth,
uint32_t
pageHeight,
119
uint32_t
pixelSize = 4)
120
: pageWidth(pageWidth), pageHeight(pageHeight),
121
pixelSize(pixelSize) {
122
}
123
124
AtlasBlock
* getBlock(
uint32_t
width,
uint32_t
height);
125
126
// try to shrink every atlas page
127
void
shrink(
bool
pot);
128
129
AtlasPage
&
getPage
(
size_t
index) {
130
return
pages[index];
131
}
132
133
private
:
134
// add new atlas to atlas container
135
AtlasPage
* extendCache(
uint32_t
minPageWidth,
uint32_t
minPageHeight);
136
137
// How big the new atlases should be
138
uint32_t
pageWidth
, pageHeight;
139
uint32_t
pixelSize
;
140
141
typedef
std::vector<AtlasPage>
Pages
;
142
Pages
pages
;
143
};
144
}
145
146
#endif
FIFE::AtlasBlock::page
uint32_t page
Definition:
atlasbook.h:43
FIFE::AtlasBook::pageWidth
uint32_t pageWidth
Definition:
atlasbook.h:138
FIFE::AtlasBook::pixelSize
uint32_t pixelSize
Definition:
atlasbook.h:139
FIFE::RectType< int32_t >
FIFE::AtlasPage::freePixels
int32_t freePixels
Definition:
atlasbook.h:109
FIFE::AtlasPage::Blocks
std::vector< AtlasBlock > Blocks
Definition:
atlasbook.h:111
FIFE::AtlasBlock::AtlasBlock
AtlasBlock()
Definition:
atlasbook.h:52
FIFE::AtlasBlock::bottom
uint32_t bottom
Definition:
atlasbook.h:44
FIFE::AtlasPage::getWidth
uint32_t getWidth() const
Definition:
atlasbook.h:95
FIFE::AtlasBlock
Definition:
atlasbook.h:41
FIFE::AtlasBook
Definition:
atlasbook.h:115
FIFE::AtlasBlock::AtlasBlock
AtlasBlock(const Rect &rect, uint32_t page)
Definition:
atlasbook.h:46
FIFE::AtlasPage::pixelSize
uint32_t pixelSize
Definition:
atlasbook.h:107
FIFE::AtlasBlock::right
uint32_t right
Definition:
atlasbook.h:44
FIFE::AtlasBlock::isTrivial
bool isTrivial() const
Definition:
atlasbook.h:73
rect.h
FIFE::AtlasBlock::merge
void merge(AtlasBlock const &rect)
Definition:
atlasbook.cpp:46
FIFE::AtlasBook::AtlasBook
AtlasBook(uint32_t pageWidth, uint32_t pageHeight, uint32_t pixelSize=4)
Definition:
atlasbook.h:118
FIFE::AtlasBlock::top
uint32_t top
Definition:
atlasbook.h:44
FIFE::AtlasPage::width
uint32_t width
Definition:
atlasbook.h:106
FIFE::AtlasPage::getHeight
uint32_t getHeight() const
Definition:
atlasbook.h:99
FIFE::AtlasBook::getPage
AtlasPage & getPage(size_t index)
Definition:
atlasbook.h:129
FIFE::AtlasPage
Definition:
atlasbook.h:84
FIFE::AtlasBook::pages
Pages pages
Definition:
atlasbook.h:142
FIFE::AtlasPage::blocks
Blocks blocks
Definition:
atlasbook.h:112
FIFE::AtlasBlock::getHeight
uint32_t getHeight() const
Definition:
atlasbook.h:78
FIFE::AtlasBook::Pages
std::vector< AtlasPage > Pages
Definition:
atlasbook.h:141
FIFE::AtlasPage::page
uint32_t page
Definition:
atlasbook.h:108
FIFE::AtlasPage::AtlasPage
AtlasPage(uint32_t width, uint32_t height, uint32_t pixelSize, uint32_t page)
Definition:
atlasbook.h:86
FIFE::AtlasBlock::left
uint32_t left
Definition:
atlasbook.h:44
FIFE::AtlasBlock::intersects
AtlasBlock intersects(AtlasBlock const &rect) const
Definition:
atlasbook.cpp:31
utf8::uint32_t
unsigned int uint32_t
Definition:
core.h:40
FIFE::AtlasBlock::setTrivial
void setTrivial()
Definition:
atlasbook.h:69
FIFE
Definition:
actionaudio.cpp:37
FIFE::AtlasBlock::getWidth
uint32_t getWidth() const
Definition:
atlasbook.h:77
engine
core
video
atlasbook.h
Generated on Sun Feb 5 2023 01:00:06 for FIFE by
1.8.13