commit
fcc5d11814
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"texture": "glass",
|
"texture": "glass",
|
||||||
"draw-group": 2,
|
"draw-group": 2,
|
||||||
"light-passing": true
|
"light-passing": true,
|
||||||
|
"sky-light-passing": true
|
||||||
}
|
}
|
||||||
@ -58,9 +58,11 @@ void LightSolver::solve(){
|
|||||||
remqueue.pop();
|
remqueue.pop();
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
int x = entry.x+coords[i*3+0];
|
int imul3 = i*3;
|
||||||
int y = entry.y+coords[i*3+1];
|
int x = entry.x+coords[imul3];
|
||||||
int z = entry.z+coords[i*3+2];
|
int y = entry.y+coords[imul3+1];
|
||||||
|
int z = entry.z+coords[imul3+2];
|
||||||
|
|
||||||
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
int lx = x - chunk->x * CHUNK_W;
|
int lx = x - chunk->x * CHUNK_W;
|
||||||
@ -85,9 +87,11 @@ void LightSolver::solve(){
|
|||||||
addqueue.pop();
|
addqueue.pop();
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
int x = entry.x+coords[i*3+0];
|
int imul3 = i*3;
|
||||||
int y = entry.y+coords[i*3+1];
|
int x = entry.x+coords[imul3];
|
||||||
int z = entry.z+coords[i*3+2];
|
int y = entry.y+coords[imul3+1];
|
||||||
|
int z = entry.z+coords[imul3+2];
|
||||||
|
|
||||||
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
Chunk* chunk = chunks->getChunkByVoxel(x,y,z);
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
int lx = x - chunk->x * CHUNK_W;
|
int lx = x - chunk->x * CHUNK_W;
|
||||||
|
|||||||
@ -152,10 +152,11 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand){
|
|||||||
|
|
||||||
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
||||||
Block* block = content->getIndices()->getBlockDef(id);
|
Block* block = content->getIndices()->getBlockDef(id);
|
||||||
|
solverR->remove(x,y,z);
|
||||||
|
solverG->remove(x,y,z);
|
||||||
|
solverB->remove(x,y,z);
|
||||||
|
|
||||||
if (id == 0){
|
if (id == 0){
|
||||||
solverR->remove(x,y,z);
|
|
||||||
solverG->remove(x,y,z);
|
|
||||||
solverB->remove(x,y,z);
|
|
||||||
solverR->solve();
|
solverR->solve();
|
||||||
solverG->solve();
|
solverG->solve();
|
||||||
solverB->solve();
|
solverB->solve();
|
||||||
@ -178,9 +179,6 @@ void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
|||||||
solverB->solve();
|
solverB->solve();
|
||||||
solverS->solve();
|
solverS->solve();
|
||||||
} else {
|
} else {
|
||||||
solverR->remove(x,y,z);
|
|
||||||
solverG->remove(x,y,z);
|
|
||||||
solverB->remove(x,y,z);
|
|
||||||
if (!block->skyLightPassing){
|
if (!block->skyLightPassing){
|
||||||
solverS->remove(x,y,z);
|
solverS->remove(x,y,z);
|
||||||
for (int i = y-1; i >= 0; i--){
|
for (int i = y-1; i >= 0; i--){
|
||||||
|
|||||||
@ -90,6 +90,78 @@ int l_file_mkdir(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_file_mkdirs(lua_State* L) {
|
||||||
|
fs::path path = resolve_path(L, lua_tostring(L, 1));
|
||||||
|
lua_pushboolean(L, fs::create_directories(path));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_file_read_bytes(lua_State* L) {
|
||||||
|
fs::path path = resolve_path(L, lua_tostring(L, 1));
|
||||||
|
if (fs::is_regular_file(path)) {
|
||||||
|
size_t length = (size_t) fs::file_size(path);
|
||||||
|
|
||||||
|
ubyte* bytes = files::read_bytes(path, length);
|
||||||
|
|
||||||
|
lua_createtable(L, length, 0);
|
||||||
|
int newTable = lua_gettop(L);
|
||||||
|
|
||||||
|
for(int i = 0;i < length;i++) {
|
||||||
|
lua_pushnumber(L, bytes[i]);
|
||||||
|
lua_rawseti(L, newTable, i+1);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return luaL_error(L, "file does not exists '%s'", path.u8string().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_file_write_bytes(lua_State* L) {
|
||||||
|
int pathIndex = 1;
|
||||||
|
|
||||||
|
if(!lua_isstring(L, pathIndex)) {
|
||||||
|
return luaL_error(L, "string expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::path path = resolve_path(L, lua_tostring(L, pathIndex));
|
||||||
|
|
||||||
|
std::vector<ubyte> bytes;
|
||||||
|
|
||||||
|
size_t len = lua_objlen(L, 2);
|
||||||
|
|
||||||
|
int bytesIndex = -1;
|
||||||
|
|
||||||
|
if(!lua_istable(L, bytesIndex)) {
|
||||||
|
return luaL_error(L, "table expected");
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
|
||||||
|
bytesIndex--;
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
while(lua_next(L, bytesIndex) != 0) {
|
||||||
|
if(lua_isnumber(L, -1)) {
|
||||||
|
const int byte = lua_tointeger(L, -1);
|
||||||
|
|
||||||
|
if(byte < 0 || byte > 255) {
|
||||||
|
return luaL_error(L, "byte '%i' at index '%i' is less than 0 or greater than 255", byte, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes.push_back(byte);
|
||||||
|
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
return luaL_error(L, "number expected at index '%i'", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pushboolean(L, files::write_bytes(path, &bytes[0], len));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* == time library == */
|
/* == time library == */
|
||||||
int l_time_uptime(lua_State* L) {
|
int l_time_uptime(lua_State* L) {
|
||||||
lua_pushnumber(L, Window::time());
|
lua_pushnumber(L, Window::time());
|
||||||
|
|||||||
@ -13,6 +13,9 @@ extern int l_file_isfile(lua_State* L);
|
|||||||
extern int l_file_isdir(lua_State* L);
|
extern int l_file_isdir(lua_State* L);
|
||||||
extern int l_file_length(lua_State* L);
|
extern int l_file_length(lua_State* L);
|
||||||
extern int l_file_mkdir(lua_State* L);
|
extern int l_file_mkdir(lua_State* L);
|
||||||
|
extern int l_file_mkdirs(lua_State* L);
|
||||||
|
extern int l_file_read_bytes(lua_State* L);
|
||||||
|
extern int l_file_write_bytes(lua_State* L);
|
||||||
|
|
||||||
static const luaL_Reg filelib [] = {
|
static const luaL_Reg filelib [] = {
|
||||||
{"resolve", lua_wrap_errors<l_file_resolve>},
|
{"resolve", lua_wrap_errors<l_file_resolve>},
|
||||||
@ -23,6 +26,9 @@ static const luaL_Reg filelib [] = {
|
|||||||
{"isdir", lua_wrap_errors<l_file_isdir>},
|
{"isdir", lua_wrap_errors<l_file_isdir>},
|
||||||
{"length", lua_wrap_errors<l_file_length>},
|
{"length", lua_wrap_errors<l_file_length>},
|
||||||
{"mkdir", lua_wrap_errors<l_file_mkdir>},
|
{"mkdir", lua_wrap_errors<l_file_mkdir>},
|
||||||
|
{"mkdirs", lua_wrap_errors<l_file_mkdirs>},
|
||||||
|
{"read_bytes", lua_wrap_errors<l_file_read_bytes>},
|
||||||
|
{"write_bytes", lua_wrap_errors<l_file_write_bytes>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user