mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51:51 +00:00
patched code after code review from MihailRis
This commit is contained in:
parent
67da57d870
commit
f8a44c023f
2 changed files with 23 additions and 21 deletions
|
|
@ -4,13 +4,14 @@ local FFI = ffi
|
||||||
|
|
||||||
FFI.cdef[[
|
FFI.cdef[[
|
||||||
void* malloc(size_t);
|
void* malloc(size_t);
|
||||||
void *realloc(void *, size_t);
|
void* realloc(void*, size_t);
|
||||||
void free(void*);
|
void free(void*);
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned char* bytes;
|
unsigned char* bytes;
|
||||||
int size;
|
int size;
|
||||||
int capacity;
|
int capacity;
|
||||||
} bytearray_t;
|
} bytearray_t;
|
||||||
|
void* memmove(void*, const void*, size_t);
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local free = FFI.C.free
|
local free = FFI.C.free
|
||||||
|
|
@ -172,29 +173,27 @@ local function slice(self, offset, length)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function copy(self, srcindex, dst, dstindex, size)
|
local function copy(self, srcindex, dst, dstindex, size)
|
||||||
if srcindex > 0 and dstindex > 0 and size > 0 and
|
if size <= 0 then error("size of byte range must be positive non-zero integer") end
|
||||||
srcindex + size - 1 <= self.size and
|
if srcindex < 1 or srcindex + size - 1 > self.size then
|
||||||
dstindex + size - 1 <= dst.size
|
error("specified source byte range is out of source array bounds")
|
||||||
then
|
|
||||||
FFI.copy(dst.bytes + dstindex - 1, self.bytes + srcindex - 1, size)
|
|
||||||
end
|
end
|
||||||
|
if dstindex < 1 or dstindex + size - 1 > dst.size then
|
||||||
|
error("specified destination byte range is out of destination array bounds")
|
||||||
|
end
|
||||||
|
|
||||||
|
FFI.copy(dst.bytes + dstindex - 1, self.bytes + srcindex - 1, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function move(self, fromindex, toindex, size)
|
local function move(self, fromindex, toindex, size)
|
||||||
if fromindex > 0 and toindex > 0 and size > 0 and
|
if size <= 0 then error("size of byte range must be positive non-zero integer") end
|
||||||
fromindex + size - 1 <= self.size and
|
if fromindex < 1 or fromindex + size - 1 > self.size then
|
||||||
toindex + size - 1 <= self.size
|
error("specified source byte range is out of array bounds")
|
||||||
then
|
|
||||||
if toindex >= fromindex and toindex < fromindex + size then
|
|
||||||
local buff = malloc(size)
|
|
||||||
FFI.copy(buff, self.bytes + fromindex - 1, size)
|
|
||||||
FFI.copy(self.bytes + toindex - 1, buff, size)
|
|
||||||
free(buff)
|
|
||||||
else
|
|
||||||
-- убери(-те) это ветвление, если FFI будет производить копирование не побайтово, и оставь(-те) только верхний блок без условия вообще.
|
|
||||||
FFI.copy(self.bytes + toindex - 1, self.bytes + fromindex - 1, size)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
if toindex < 1 or toindex + size - 1 > self.size then
|
||||||
|
error("specified destination byte range is out of array bounds")
|
||||||
|
end
|
||||||
|
|
||||||
|
FFI.C.memmove(self.bytes + self.toindex - 1, self.bytes + self.fromindex - 1, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
local bytearray_methods = {
|
local bytearray_methods = {
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,11 @@ static int l_clear(State* L) {
|
||||||
size_t pixelscount = image.getWidth() * image.getHeight();
|
size_t pixelscount = image.getWidth() * image.getHeight();
|
||||||
uint32_t* data = reinterpret_cast<uint32_t*>(image.getData());
|
uint32_t* data = reinterpret_cast<uint32_t*>(image.getData());
|
||||||
|
|
||||||
if (gettop(L) == 1) std::fill(data, data + pixelscount, 0);
|
if (gettop(L) == 1) {
|
||||||
else std::fill(data, data + pixelscount, get_rgba(L, 2).rgba);
|
std::fill(data, data + pixelscount, 0);
|
||||||
|
} else {
|
||||||
|
std::fill(data, data + pixelscount, get_rgba(L, 2).rgba);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue