Merge branch 'rr1-maint'

This commit is contained in:
Ilari Liusvaara 2012-03-07 14:00:08 +02:00
commit 94cb7ac097
13 changed files with 98 additions and 23 deletions

View file

@ -340,15 +340,7 @@ struct premultiplied_color
struct render_queue
{
/**
* Adds new object to render queue. The object must be allocated by new.
*
* 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.
* Applies all objects in the queue in order.
*
* parameter scr: The screen to apply queue to.
*/
@ -359,11 +351,25 @@ struct render_queue
*/
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.
*/
~render_queue() throw();
private:
void add(struct render_object& obj) throw(std::bad_alloc);
std::list<struct render_object*> q;
};

View file

@ -2162,6 +2162,28 @@ Shift bits-bit (max 48, default 48) number arithmetically right by amount
The new bits are shifted in with copy of the high bit.
\end_layout
\begin_layout Subsubsection
bit.extract(number base[, number bit0[, number bit1,...]])
\end_layout
\begin_layout Standard
Returns number that has bit0-th bit as bit 0, bit1-th bit as 1 and so on.
\end_layout
\begin_layout Standard
Notes:
\end_layout
\begin_layout Itemize
Bit numbers up to 51 should work reliably (then things start falling apart
due to double precision issues).
\end_layout
\begin_layout Itemize
There are two special bit positions, true and false, standing for always
set bit and always clear bit.
\end_layout
\begin_layout Subsection
Table gui:
\end_layout

View file

@ -1047,6 +1047,19 @@ Shift bits-bit (max 48, default 48) number arithmetically right
by amount (default 1) places. The new bits are shifted in with
copy of the high bit.
8.2.10 bit.extract(number base[, number bit0[, number bit1,...]])
Returns number that has bit0-th bit as bit 0, bit1-th bit as 1
and so on.
Notes:
• Bit numbers up to 51 should work reliably (then things start
falling apart due to double precision issues).
• There are two special bit positions, true and false, standing
for always set bit and always clear bit.
8.3 Table gui:
Most of these functions can only be called in on_paint and

View file

@ -327,6 +327,14 @@ void render_queue::clear() throw()
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()
{
clear();

View file

@ -427,7 +427,7 @@ namespace
}
}
#define MAXWAIT 5000000ULL
#define MAXWAIT 100000ULL
void platform::flush_command_queue() throw()

View file

@ -102,6 +102,23 @@ namespace
}
};
function_ptr_luafun lua_print("bit.extract", [](lua_State* LS, const std::string& fname) -> int {
uint64_t num = get_numeric_argument<uint64_t>(LS, 1, fname.c_str());
uint64_t ret = 0;
for(size_t i = 0;; i++) {
if(lua_isnumber(LS, i + 2)) {
uint8_t bit = get_numeric_argument<uint8_t>(LS, i + 2, fname.c_str());
ret |= (((num >> bit) & 1) << i);
} else if(lua_isboolean(LS, i + 2)) {
if(lua_toboolean(LS, i + 2))
ret |= (1ULL << i);
} else
break;
}
lua_pushnumber(LS, ret);
return 1;
});
lua_symmetric_bitwise<combine_none, BITWISE_MASK> bit_none("bit.none");
lua_symmetric_bitwise<combine_none, BITWISE_MASK> bit_bnot("bit.bnot");
lua_symmetric_bitwise<combine_any, 0> bit_any("bit.any");

View file

@ -107,11 +107,11 @@ namespace
lua_class<lua_palette>::get(LS, 4, 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());
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)) {
lua_class<lua_dbitmap>::get(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 {
lua_pushstring(LS, "Expected BITMAP or DBITMAP as argument 3 for gui.bitmap_draw.");
lua_error(LS);
@ -128,10 +128,19 @@ namespace
uint32_t w = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
uint32_t h = get_numeric_argument<uint32_t>(LS, 2, fname.c_str());
bool d = get_boolean_argument(LS, 3, fname.c_str());
if(d)
lua_class<lua_dbitmap>::create(LS, w, h);
else
lua_class<lua_bitmap>::create(LS, w, h);
if(d) {
int64_t c = -1;
get_numeric_argument<int64_t>(LS, 4, c, fname.c_str());
lua_dbitmap* b = lua_class<lua_dbitmap>::create(LS, w, h);
for(size_t i = 0; i < b->width * b->height; i++)
b->pixels[i] = premultiplied_color(c);
} else {
uint16_t c = 0;
get_numeric_argument<uint16_t>(LS, 4, c, fname.c_str());
lua_bitmap* b = lua_class<lua_bitmap>::create(LS, w, h);
for(size_t i = 0; i < b->width * b->height; i++)
b->pixels[i] = c;
}
return 1;
});

View file

@ -69,7 +69,7 @@ namespace
get_numeric_argument<int64_t>(LS, 6, fill, fname.c_str());
premultiplied_color poutline(outline);
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;
});
}

View file

@ -43,7 +43,7 @@ namespace
get_numeric_argument<uint32_t>(LS, 3, length, fname.c_str());
get_numeric_argument<int64_t>(LS, 4, color, fname.c_str());
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;
});
}

View file

@ -92,7 +92,7 @@ nodraw2:
int32_t y2 = get_numeric_argument<int32_t>(LS, 4, fname.c_str());
get_numeric_argument<int64_t>(LS, 5, color, fname.c_str());
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;
});
}

View file

@ -35,7 +35,7 @@ namespace
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
get_numeric_argument<int64_t>(LS, 3, color, fname.c_str());
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;
});
}

View file

@ -58,8 +58,8 @@ namespace
get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
premultiplied_color poutline(outline);
premultiplied_color pfill(fill);
lua_render_ctx->queue->add(*new render_object_rectangle(x, y, width, height, poutline, pfill,
thickness));
lua_render_ctx->queue->create_add<render_object_rectangle>(x, y, width, height, poutline, pfill,
thickness);
return 0;
});
}

View file

@ -40,7 +40,7 @@ namespace
std::string text = get_string_argument(LS, 3, fname.c_str());
premultiplied_color fg(fgc);
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;
}