 |
Blamite Game Engine - blam!
00346.12.11.21.0529.blamite
The core library for the Blamite Game Engine.
|
Go to the documentation of this file.
65 #ifndef STB_INCLUDE_STB_RECT_PACK_H
66 #define STB_INCLUDE_STB_RECT_PACK_H
68 #define STB_RECT_PACK_VERSION 1
71 #define STBRP_DEF static
73 #define STBRP_DEF extern
84 #ifdef STBRP_LARGE_RECTS
205 #ifdef STB_RECT_PACK_IMPLEMENTATION
208 #define STBRP_SORT qsort
213 #define STBRP_ASSERT assert
218 #define STBRP__NOTUSED(v) (void)(v)
219 #define STBRP__CDECL __cdecl
221 #define STBRP__NOTUSED(v) (void)sizeof(v)
227 STBRP__INIT_skyline = 1
233 case STBRP__INIT_skyline:
244 if (allow_out_of_mem)
265 #ifndef STBRP_LARGE_RECTS
269 for (i=0; i < num_nodes-1; ++i)
270 nodes[i].next = &nodes[i+1];
272 context->
init_mode = STBRP__INIT_skyline;
286 #ifdef STBRP_LARGE_RECTS
287 context->
extra[1].
y = (1<<30);
289 context->
extra[1].
y = 65535;
299 int min_y, visited_width, waste_area;
307 while (node->
next->
x <= x0)
318 while (node->
x < x1) {
319 if (node->
y > min_y) {
323 waste_area += visited_width * (node->
y - min_y);
327 visited_width += node->
next->
x - x0;
329 visited_width += node->
next->
x - node->
x;
332 int under_width = node->
next->
x - node->
x;
333 if (under_width + visited_width >
width)
334 under_width =
width - visited_width;
335 waste_area += under_width * (min_y - node->
y);
336 visited_width += under_width;
341 *pwaste = waste_area;
353 int best_waste = (1<<30), best_x, best_y = (1 << 30);
354 stbrp__findresult fr;
371 while (node->
x + width <= c->
width) {
373 y = stbrp__skyline_find_min_y(c, node, node->
x,
width, &waste);
384 if (
y < best_y || (
y == best_y && waste < best_waste)) {
395 best_x = (best ==
NULL) ? 0 : (*best)->
x;
422 int xpos = tail->
x -
width;
426 while (node->
next->
x <= xpos) {
431 y = stbrp__skyline_find_min_y(c, node, xpos,
width, &waste);
434 if (
y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
456 stbrp__findresult res = stbrp__skyline_find_best_pos(context,
width,
height);
464 res.prev_link =
NULL;
479 cur = *res.prev_link;
480 if (cur->
x < res.x) {
486 *res.prev_link = node;
502 if (cur->
x < res.x +
width)
507 while (cur->
x < context->
width) {
533 static int STBRP__CDECL rect_height_compare(
const void *a,
const void *b)
541 return (p->
w > q->
w) ? -1 : (p->
w < q->
w);
545 static int STBRP__CDECL rect_original_order(
const void *a,
const void *b)
552 #ifdef STBRP_LARGE_RECTS
553 #define STBRP__MAXVAL 0xffffffff
555 #define STBRP__MAXVAL 0xffff
560 int i, all_rects_packed = 1;
563 for (i=0; i < num_rects; ++i) {
568 STBRP_SORT(rects, num_rects,
sizeof(rects[0]), rect_height_compare);
570 for (i=0; i < num_rects; ++i) {
571 if (rects[i].w == 0 || rects[i].h == 0) {
572 rects[i].
x = rects[i].
y = 0;
574 stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
579 rects[i].
x = rects[i].
y = STBRP__MAXVAL;
585 STBRP_SORT(rects, num_rects,
sizeof(rects[0]), rect_original_order);
588 for (i=0; i < num_rects; ++i) {
589 rects[i].
was_packed = !(rects[i].
x == STBRP__MAXVAL && rects[i].
y == STBRP__MAXVAL);
590 if (!rects[i].was_packed)
591 all_rects_packed = 0;
595 return all_rects_packed;
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
stbrp_coord y
Definition: imstb_rectpack.h:177
int width
Definition: bgfx.cpp:19
@ STBRP_HEURISTIC_Skyline_BL_sortHeight
Definition: imstb_rectpack.h:165
int heuristic
Definition: imstb_rectpack.h:187
stbrp_node extra[2]
Definition: imstb_rectpack.h:191
#define STBRP_SORT
Definition: imgui_draw.cpp:122
stbrp_coord y
Definition: imstb_rectpack.h:124
stbrp_node * free_head
Definition: imstb_rectpack.h:190
Definition: imstb_rectpack.h:175
stbrp_coord h
Definition: imstb_rectpack.h:121
#define STBRP_ASSERT(x)
Definition: imgui_draw.cpp:121
Definition: imstb_rectpack.h:115
font DisplayOffset y
Definition: README.txt:68
Add a fourth parameter to bake specific font ranges NULL
Definition: README.txt:57
stbrp_coord w
Definition: imstb_rectpack.h:121
Definition: imstb_rectpack.h:181
int height
Definition: imstb_rectpack.h:184
int init_mode
Definition: imstb_rectpack.h:186
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
int id
Definition: imstb_rectpack.h:118
int align
Definition: imstb_rectpack.h:185
@ STBRP_HEURISTIC_Skyline_default
Definition: imstb_rectpack.h:164
int height
Definition: bgfx.cpp:20
#define STBRP_DEF
Definition: imstb_rectpack.h:73
stbrp_node * next
Definition: imstb_rectpack.h:178
int was_packed
Definition: imstb_rectpack.h:125
@ STBRP_HEURISTIC_Skyline_BF_sortHeight
Definition: imstb_rectpack.h:166
int num_nodes
Definition: imstb_rectpack.h:188
stbrp_coord x
Definition: imstb_rectpack.h:124
unsigned short stbrp_coord
Definition: imstb_rectpack.h:87
config GlyphExtraSpacing x
Definition: README.txt:30
int width
Definition: imstb_rectpack.h:183
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
stbrp_coord x
Definition: imstb_rectpack.h:177
stbrp_node * active_head
Definition: imstb_rectpack.h:189