add player.create, test.set_setting, test.sleep_until, world.count_chunks
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "maths/voxmaths.hpp"
|
||||
#include "objects/Entities.hpp"
|
||||
#include "objects/Players.hpp"
|
||||
#include "objects/Player.hpp"
|
||||
#include "physics/Hitbox.hpp"
|
||||
#include "scripting/scripting.hpp"
|
||||
#include "settings.hpp"
|
||||
@@ -29,6 +30,18 @@ LevelController::LevelController(Engine* engine, std::unique_ptr<Level> levelPtr
|
||||
}
|
||||
|
||||
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) {
|
||||
// update all objects that needed
|
||||
blocks->update(delta);
|
||||
|
||||
@@ -250,6 +250,14 @@ static int l_set_name(lua::State* L) {
|
||||
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[] = {
|
||||
{"get_pos", lua::wrap<l_get_pos>},
|
||||
{"set_pos", lua::wrap<l_set_pos>},
|
||||
@@ -277,5 +285,6 @@ const luaL_Reg playerlib[] = {
|
||||
{"set_camera", lua::wrap<l_set_camera>},
|
||||
{"get_name", lua::wrap<l_get_name>},
|
||||
{"set_name", lua::wrap<l_set_name>},
|
||||
{"create", lua::wrap<l_create>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "lighting/Lighting.hpp"
|
||||
#include "voxels/Chunk.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "voxels/ChunksStorage.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "world/World.hpp"
|
||||
|
||||
@@ -231,6 +232,13 @@ static int l_set_chunk_data(lua::State* L) {
|
||||
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[] = {
|
||||
{"is_open", lua::wrap<l_is_open>},
|
||||
{"get_list", lua::wrap<l_get_list>},
|
||||
@@ -246,5 +254,6 @@ const luaL_Reg worldlib[] = {
|
||||
{"exists", lua::wrap<l_exists>},
|
||||
{"get_chunk_data", lua::wrap<l_get_chunk_data>},
|
||||
{"set_chunk_data", lua::wrap<l_set_chunk_data>},
|
||||
{"count_chunks", lua::wrap<l_count_chunks>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user