add player.create, test.set_setting, test.sleep_until, world.count_chunks
This commit is contained in:
parent
8a5042f2a2
commit
9ec8788838
@ -1 +1,12 @@
|
|||||||
print("hello world")
|
test.set_setting("chunks.load-distance", 2)
|
||||||
|
test.set_setting("chunks.load-speed", 16)
|
||||||
|
|
||||||
|
test.new_world("demo", "2019", "core:default")
|
||||||
|
local pid = player.create("Xerxes")
|
||||||
|
assert(player.get_name(pid) == "Xerxes")
|
||||||
|
test.sleep_until(function() return world.count_chunks() >= 9 end, 1000)
|
||||||
|
print(world.count_chunks())
|
||||||
|
assert(block.get(0, 0, 0) == block.index("core:obstacle"))
|
||||||
|
block.destruct(0, 0, 0, pid)
|
||||||
|
assert(block.get(0, 0, 0) == 0)
|
||||||
|
test.close_world(true)
|
||||||
|
|||||||
@ -16,7 +16,19 @@ if test then
|
|||||||
test.open_world = core.open_world
|
test.open_world = core.open_world
|
||||||
test.close_world = core.close_world
|
test.close_world = core.close_world
|
||||||
test.reconfig_packs = core.reconfig_packs
|
test.reconfig_packs = core.reconfig_packs
|
||||||
|
test.set_setting = core.set_setting
|
||||||
test.tick = coroutine.yield
|
test.tick = coroutine.yield
|
||||||
|
|
||||||
|
function test.sleep_until(predicate, max_ticks)
|
||||||
|
max_ticks = max_ticks or 1e9
|
||||||
|
local ticks = 0
|
||||||
|
while ticks < max_ticks and not predicate() do
|
||||||
|
test.tick()
|
||||||
|
end
|
||||||
|
if ticks == max_ticks then
|
||||||
|
error("max ticks exceed")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|||||||
@ -187,17 +187,6 @@ void LevelScreen::update(float delta) {
|
|||||||
level->getWorld()->updateTimers(delta);
|
level->getWorld()->updateTimers(delta);
|
||||||
animator->update(delta);
|
animator->update(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 position = player->getPosition();
|
|
||||||
level->loadMatrix(
|
|
||||||
position.x,
|
|
||||||
position.z,
|
|
||||||
settings.chunks.loadDistance.get() + settings.chunks.padding.get() * 2
|
|
||||||
);
|
|
||||||
controller->getChunksController()->update(
|
|
||||||
settings.chunks.loadSpeed.get(), settings.chunks.loadDistance.get(),
|
|
||||||
floordiv(position.x, CHUNK_W), floordiv(position.z, CHUNK_D)
|
|
||||||
);
|
|
||||||
if (!hud->isPause()) {
|
if (!hud->isPause()) {
|
||||||
playerController->update(delta, !inputLocked);
|
playerController->update(delta, !inputLocked);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,11 +86,12 @@ void Lighting::buildSkyLight(int cx, int cz){
|
|||||||
solverS->solve();
|
solverS->solve();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lighting::onChunkLoaded(int cx, int cz, bool expand){
|
|
||||||
LightSolver* solverR = this->solverR.get();
|
void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
||||||
LightSolver* solverG = this->solverG.get();
|
auto& solverR = *this->solverR;
|
||||||
LightSolver* solverB = this->solverB.get();
|
auto& solverG = *this->solverG;
|
||||||
LightSolver* solverS = this->solverS.get();
|
auto& solverB = *this->solverB;
|
||||||
|
auto& solverS = *this->solverS;
|
||||||
|
|
||||||
auto blockDefs = content->getIndices()->blocks.getDefs();
|
auto blockDefs = content->getIndices()->blocks.getDefs();
|
||||||
auto chunk = chunks->getChunk(cx, cz);
|
auto chunk = chunks->getChunk(cx, cz);
|
||||||
@ -103,9 +104,9 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand){
|
|||||||
int gx = x + cx * CHUNK_W;
|
int gx = x + cx * CHUNK_W;
|
||||||
int gz = z + cz * CHUNK_D;
|
int gz = z + cz * CHUNK_D;
|
||||||
if (block->rt.emissive){
|
if (block->rt.emissive){
|
||||||
solverR->add(gx,y,gz,block->emission[0]);
|
solverR.add(gx,y,gz,block->emission[0]);
|
||||||
solverG->add(gx,y,gz,block->emission[1]);
|
solverG.add(gx,y,gz,block->emission[1]);
|
||||||
solverB->add(gx,y,gz,block->emission[2]);
|
solverB.add(gx,y,gz,block->emission[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,10 +120,10 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand){
|
|||||||
int gz = z + cz * CHUNK_D;
|
int gz = z + cz * CHUNK_D;
|
||||||
int rgbs = chunk->lightmap.get(x, y, z);
|
int rgbs = chunk->lightmap.get(x, y, z);
|
||||||
if (rgbs){
|
if (rgbs){
|
||||||
solverR->add(gx,y,gz, Lightmap::extract(rgbs, 0));
|
solverR.add(gx,y,gz, Lightmap::extract(rgbs, 0));
|
||||||
solverG->add(gx,y,gz, Lightmap::extract(rgbs, 1));
|
solverG.add(gx,y,gz, Lightmap::extract(rgbs, 1));
|
||||||
solverB->add(gx,y,gz, Lightmap::extract(rgbs, 2));
|
solverB.add(gx,y,gz, Lightmap::extract(rgbs, 2));
|
||||||
solverS->add(gx,y,gz, Lightmap::extract(rgbs, 3));
|
solverS.add(gx,y,gz, Lightmap::extract(rgbs, 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,19 +135,19 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand){
|
|||||||
int gz = z + cz * CHUNK_D;
|
int gz = z + cz * CHUNK_D;
|
||||||
int rgbs = chunk->lightmap.get(x, y, z);
|
int rgbs = chunk->lightmap.get(x, y, z);
|
||||||
if (rgbs){
|
if (rgbs){
|
||||||
solverR->add(gx,y,gz, Lightmap::extract(rgbs, 0));
|
solverR.add(gx,y,gz, Lightmap::extract(rgbs, 0));
|
||||||
solverG->add(gx,y,gz, Lightmap::extract(rgbs, 1));
|
solverG.add(gx,y,gz, Lightmap::extract(rgbs, 1));
|
||||||
solverB->add(gx,y,gz, Lightmap::extract(rgbs, 2));
|
solverB.add(gx,y,gz, Lightmap::extract(rgbs, 2));
|
||||||
solverS->add(gx,y,gz, Lightmap::extract(rgbs, 3));
|
solverS.add(gx,y,gz, Lightmap::extract(rgbs, 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
solverR->solve();
|
solverR.solve();
|
||||||
solverG->solve();
|
solverG.solve();
|
||||||
solverB->solve();
|
solverB.solve();
|
||||||
solverS->solve();
|
solverS.solve();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "maths/voxmaths.hpp"
|
#include "maths/voxmaths.hpp"
|
||||||
#include "objects/Entities.hpp"
|
#include "objects/Entities.hpp"
|
||||||
#include "objects/Players.hpp"
|
#include "objects/Players.hpp"
|
||||||
|
#include "objects/Player.hpp"
|
||||||
#include "physics/Hitbox.hpp"
|
#include "physics/Hitbox.hpp"
|
||||||
#include "scripting/scripting.hpp"
|
#include "scripting/scripting.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
@ -29,6 +30,18 @@ LevelController::LevelController(Engine* engine, std::unique_ptr<Level> levelPtr
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LevelController::update(float delta, bool pause) {
|
void LevelController::update(float delta, bool pause) {
|
||||||
|
for (const auto& [uid, player] : *level->players) {
|
||||||
|
glm::vec3 position = player->getPosition();
|
||||||
|
level->loadMatrix(
|
||||||
|
position.x,
|
||||||
|
position.z,
|
||||||
|
settings.chunks.loadDistance.get() + settings.chunks.padding.get() * 2
|
||||||
|
);
|
||||||
|
chunks->update(
|
||||||
|
settings.chunks.loadSpeed.get(), settings.chunks.loadDistance.get(),
|
||||||
|
floordiv(position.x, CHUNK_W), floordiv(position.z, CHUNK_D)
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!pause) {
|
if (!pause) {
|
||||||
// update all objects that needed
|
// update all objects that needed
|
||||||
blocks->update(delta);
|
blocks->update(delta);
|
||||||
|
|||||||
@ -250,6 +250,14 @@ static int l_set_name(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_create(lua::State* L) {
|
||||||
|
auto player = level->players->create();
|
||||||
|
if (lua::isstring(L, 1)) {
|
||||||
|
player->setName(lua::require_string(L, 1));
|
||||||
|
}
|
||||||
|
return lua::pushinteger(L, player->getId());
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg playerlib[] = {
|
const luaL_Reg playerlib[] = {
|
||||||
{"get_pos", lua::wrap<l_get_pos>},
|
{"get_pos", lua::wrap<l_get_pos>},
|
||||||
{"set_pos", lua::wrap<l_set_pos>},
|
{"set_pos", lua::wrap<l_set_pos>},
|
||||||
@ -277,5 +285,6 @@ const luaL_Reg playerlib[] = {
|
|||||||
{"set_camera", lua::wrap<l_set_camera>},
|
{"set_camera", lua::wrap<l_set_camera>},
|
||||||
{"get_name", lua::wrap<l_get_name>},
|
{"get_name", lua::wrap<l_get_name>},
|
||||||
{"set_name", lua::wrap<l_set_name>},
|
{"set_name", lua::wrap<l_set_name>},
|
||||||
|
{"create", lua::wrap<l_create>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "lighting/Lighting.hpp"
|
#include "lighting/Lighting.hpp"
|
||||||
#include "voxels/Chunk.hpp"
|
#include "voxels/Chunk.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
|
#include "voxels/ChunksStorage.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
|
|
||||||
@ -231,6 +232,13 @@ static int l_set_chunk_data(lua::State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_count_chunks(lua::State* L) {
|
||||||
|
if (level == nullptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return lua::pushinteger(L, level->chunksStorage->size());
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg worldlib[] = {
|
const luaL_Reg worldlib[] = {
|
||||||
{"is_open", lua::wrap<l_is_open>},
|
{"is_open", lua::wrap<l_is_open>},
|
||||||
{"get_list", lua::wrap<l_get_list>},
|
{"get_list", lua::wrap<l_get_list>},
|
||||||
@ -246,5 +254,6 @@ const luaL_Reg worldlib[] = {
|
|||||||
{"exists", lua::wrap<l_exists>},
|
{"exists", lua::wrap<l_exists>},
|
||||||
{"get_chunk_data", lua::wrap<l_get_chunk_data>},
|
{"get_chunk_data", lua::wrap<l_get_chunk_data>},
|
||||||
{"set_chunk_data", lua::wrap<l_set_chunk_data>},
|
{"set_chunk_data", lua::wrap<l_set_chunk_data>},
|
||||||
|
{"count_chunks", lua::wrap<l_count_chunks>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -27,7 +27,7 @@ namespace util {
|
|||||||
std::fill(secondBuffer.begin(), secondBuffer.end(), T{});
|
std::fill(secondBuffer.begin(), secondBuffer.end(), T{});
|
||||||
for (TCoord y = 0; y < sizeY; y++) {
|
for (TCoord y = 0; y < sizeY; y++) {
|
||||||
for (TCoord x = 0; x < sizeX; x++) {
|
for (TCoord x = 0; x < sizeX; x++) {
|
||||||
auto& value = firstBuffer[y * sizeX + x];
|
auto value = std::move(firstBuffer[y * sizeX + x]);
|
||||||
auto nx = x - dx;
|
auto nx = x - dx;
|
||||||
auto ny = y - dy;
|
auto ny = y - dy;
|
||||||
if (value == T{}) {
|
if (value == T{}) {
|
||||||
@ -40,7 +40,7 @@ namespace util {
|
|||||||
valuesCount--;
|
valuesCount--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
secondBuffer[ny * sizeX + nx] = value;
|
secondBuffer[ny * sizeX + nx] = std::move(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::swap(firstBuffer, secondBuffer);
|
std::swap(firstBuffer, secondBuffer);
|
||||||
|
|||||||
@ -109,3 +109,7 @@ std::shared_ptr<Chunk> ChunksStorage::create(int x, int z) {
|
|||||||
chunk->blocksMetadata = regions.getBlocksData(chunk->x, chunk->z);
|
chunk->blocksMetadata = regions.getBlocksData(chunk->x, chunk->z);
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ChunksStorage::size() const {
|
||||||
|
return chunksMap->size();
|
||||||
|
}
|
||||||
|
|||||||
@ -17,4 +17,6 @@ public:
|
|||||||
|
|
||||||
std::shared_ptr<Chunk> fetch(int x, int z);
|
std::shared_ptr<Chunk> fetch(int x, int z);
|
||||||
std::shared_ptr<Chunk> create(int x, int z);
|
std::shared_ptr<Chunk> create(int x, int z);
|
||||||
|
|
||||||
|
size_t size() const;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user