Refactor render queue management
This makes it easier to switch render queue object memory management to internal implementation, speeding stuff up.
This commit is contained in:
parent
1a33ad9dc2
commit
2fb19ea144
9 changed files with 32 additions and 18 deletions
|
@ -331,15 +331,7 @@ struct premultiplied_color
|
||||||
struct render_queue
|
struct render_queue
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Adds new object to render queue. The object must be allocated by new.
|
* Applies all objects in the queue in order.
|
||||||
*
|
|
||||||
* parameter obj: The object to add
|
|
||||||
* throws std::bad_alloc: Not enough memory.
|
|
||||||
*/
|
|
||||||
void add(struct render_object& obj) throw(std::bad_alloc);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies all objects in the queue in order, freeing them in progress.
|
|
||||||
*
|
*
|
||||||
* parameter scr: The screen to apply queue to.
|
* parameter scr: The screen to apply queue to.
|
||||||
*/
|
*/
|
||||||
|
@ -350,11 +342,25 @@ struct render_queue
|
||||||
*/
|
*/
|
||||||
void clear() throw();
|
void clear() throw();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get memory from internal allocator.
|
||||||
|
*/
|
||||||
|
void* alloc(size_t block) throw(std::bad_alloc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call object constructor on internal memory.
|
||||||
|
*/
|
||||||
|
template<class T, typename... U> void create_add(U... args)
|
||||||
|
{
|
||||||
|
add(*new(alloc(sizeof(T))) T(args...));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
~render_queue() throw();
|
~render_queue() throw();
|
||||||
private:
|
private:
|
||||||
|
void add(struct render_object& obj) throw(std::bad_alloc);
|
||||||
std::list<struct render_object*> q;
|
std::list<struct render_object*> q;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -305,6 +305,14 @@ void render_queue::clear() throw()
|
||||||
q.clear();
|
q.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* render_queue::alloc(size_t block) throw(std::bad_alloc)
|
||||||
|
{
|
||||||
|
void* ptr = malloc(block);
|
||||||
|
if(!ptr)
|
||||||
|
throw std::bad_alloc();
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
render_queue::~render_queue() throw()
|
render_queue::~render_queue() throw()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -105,11 +105,11 @@ namespace
|
||||||
lua_class<lua_palette>::get(LS, 4, fname.c_str());
|
lua_class<lua_palette>::get(LS, 4, fname.c_str());
|
||||||
auto b = lua_class<lua_bitmap>::pin(LS, 3, fname.c_str());
|
auto b = lua_class<lua_bitmap>::pin(LS, 3, fname.c_str());
|
||||||
auto p = lua_class<lua_palette>::pin(LS, 4, fname.c_str());
|
auto p = lua_class<lua_palette>::pin(LS, 4, fname.c_str());
|
||||||
lua_render_ctx->queue->add(*new render_object_bitmap(x, y, b, p));
|
lua_render_ctx->queue->create_add<render_object_bitmap>(x, y, b, p);
|
||||||
} else if(lua_class<lua_dbitmap>::is(LS, 3)) {
|
} else if(lua_class<lua_dbitmap>::is(LS, 3)) {
|
||||||
lua_class<lua_dbitmap>::get(LS, 3, fname.c_str());
|
lua_class<lua_dbitmap>::get(LS, 3, fname.c_str());
|
||||||
auto b = lua_class<lua_dbitmap>::pin(LS, 3, fname.c_str());
|
auto b = lua_class<lua_dbitmap>::pin(LS, 3, fname.c_str());
|
||||||
lua_render_ctx->queue->add(*new render_object_bitmap(x, y, b));
|
lua_render_ctx->queue->create_add<render_object_bitmap>(x, y, b);
|
||||||
} else {
|
} else {
|
||||||
lua_pushstring(LS, "Expected BITMAP or DBITMAP as argument 3 for gui.bitmap_draw.");
|
lua_pushstring(LS, "Expected BITMAP or DBITMAP as argument 3 for gui.bitmap_draw.");
|
||||||
lua_error(LS);
|
lua_error(LS);
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace
|
||||||
get_numeric_argument<int64_t>(LS, 6, fill, fname.c_str());
|
get_numeric_argument<int64_t>(LS, 6, fill, fname.c_str());
|
||||||
premultiplied_color poutline(outline);
|
premultiplied_color poutline(outline);
|
||||||
premultiplied_color pfill(fill);
|
premultiplied_color pfill(fill);
|
||||||
lua_render_ctx->queue->add(*new render_object_circle(x, y, radius, poutline, pfill, thickness));
|
lua_render_ctx->queue->create_add<render_object_circle>(x, y, radius, poutline, pfill, thickness);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace
|
||||||
get_numeric_argument<uint32_t>(LS, 3, length, fname.c_str());
|
get_numeric_argument<uint32_t>(LS, 3, length, fname.c_str());
|
||||||
get_numeric_argument<int64_t>(LS, 4, color, fname.c_str());
|
get_numeric_argument<int64_t>(LS, 4, color, fname.c_str());
|
||||||
premultiplied_color pcolor(color);
|
premultiplied_color pcolor(color);
|
||||||
lua_render_ctx->queue->add(*new render_object_crosshair(x, y, pcolor, length));
|
lua_render_ctx->queue->create_add<render_object_crosshair>(x, y, pcolor, length);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ nodraw2:
|
||||||
int32_t y2 = get_numeric_argument<int32_t>(LS, 4, fname.c_str());
|
int32_t y2 = get_numeric_argument<int32_t>(LS, 4, fname.c_str());
|
||||||
get_numeric_argument<int64_t>(LS, 5, color, fname.c_str());
|
get_numeric_argument<int64_t>(LS, 5, color, fname.c_str());
|
||||||
premultiplied_color pcolor(color);
|
premultiplied_color pcolor(color);
|
||||||
lua_render_ctx->queue->add(*new render_object_line(x1, x2, y1, y2, pcolor));
|
lua_render_ctx->queue->create_add<render_object_line>(x1, x2, y1, y2, pcolor);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace
|
||||||
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
|
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
|
||||||
get_numeric_argument<int64_t>(LS, 3, color, fname.c_str());
|
get_numeric_argument<int64_t>(LS, 3, color, fname.c_str());
|
||||||
premultiplied_color pcolor(color);
|
premultiplied_color pcolor(color);
|
||||||
lua_render_ctx->queue->add(*new render_object_pixel(x, y, pcolor));
|
lua_render_ctx->queue->create_add<render_object_pixel>(x, y, pcolor);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,8 @@ namespace
|
||||||
get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
|
get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
|
||||||
premultiplied_color poutline(outline);
|
premultiplied_color poutline(outline);
|
||||||
premultiplied_color pfill(fill);
|
premultiplied_color pfill(fill);
|
||||||
lua_render_ctx->queue->add(*new render_object_rectangle(x, y, width, height, poutline, pfill,
|
lua_render_ctx->queue->create_add<render_object_rectangle>(x, y, width, height, poutline, pfill,
|
||||||
thickness));
|
thickness);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace
|
||||||
std::string text = get_string_argument(LS, 3, fname.c_str());
|
std::string text = get_string_argument(LS, 3, fname.c_str());
|
||||||
premultiplied_color fg(fgc);
|
premultiplied_color fg(fgc);
|
||||||
premultiplied_color bg(bgc);
|
premultiplied_color bg(bgc);
|
||||||
lua_render_ctx->queue->add(*new render_object_text(_x, _y, text, fg, bg, hdbl, vdbl));
|
lua_render_ctx->queue->create_add<render_object_text>(_x, _y, text, fg, bg, hdbl, vdbl);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue