Merge branch 'main' into main
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "ChunksController.h"
|
||||
|
||||
#include "scripting/scripting.h"
|
||||
#include "../interfaces/Object.h"
|
||||
|
||||
LevelController::LevelController(EngineSettings& settings, Level* level)
|
||||
: settings(settings), level(level) {
|
||||
@@ -23,7 +24,20 @@ void LevelController::update(float delta, bool input, bool pause) {
|
||||
player->update(delta, input, pause);
|
||||
level->update();
|
||||
chunks->update(settings.chunks.loadSpeed);
|
||||
|
||||
// erease null pointers
|
||||
level->objects.remove_if([](auto obj) { return obj == nullptr; });
|
||||
|
||||
if (!pause) {
|
||||
// update all objects that needed
|
||||
for(auto obj : level->objects)
|
||||
{
|
||||
if(obj) {
|
||||
if(obj->shouldUpdate) {
|
||||
obj->update(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
blocks->update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ const float C_ZOOM = 0.1f;
|
||||
const float CROUCH_SHIFT_Y = -0.2f;
|
||||
|
||||
|
||||
CameraControl::CameraControl(Player* player, const CameraSettings& settings)
|
||||
CameraControl::CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings)
|
||||
: player(player),
|
||||
camera(player->camera),
|
||||
currentViewCamera(player->currentCamera),
|
||||
@@ -202,13 +202,13 @@ void PlayerController::resetKeyboard() {
|
||||
}
|
||||
|
||||
void PlayerController::updateControls(float delta){
|
||||
player->update(level, input, delta);
|
||||
player->updateInput(level, input, delta);
|
||||
}
|
||||
|
||||
void PlayerController::updateInteraction(){
|
||||
auto indices = level->content->getIndices();
|
||||
Chunks* chunks = level->chunks;
|
||||
Player* player = level->player;
|
||||
Player* player = level->player.get();
|
||||
Lighting* lighting = level->lighting;
|
||||
Camera* camera = player->camera.get();
|
||||
glm::vec3 end;
|
||||
|
||||
@@ -12,7 +12,7 @@ class Level;
|
||||
class BlocksController;
|
||||
|
||||
class CameraControl {
|
||||
Player* player;
|
||||
std::shared_ptr<Player> player;
|
||||
std::shared_ptr<Camera> camera, currentViewCamera;
|
||||
const CameraSettings& settings;
|
||||
glm::vec3 offset;
|
||||
@@ -20,7 +20,7 @@ class CameraControl {
|
||||
float shakeTimer = 0.0f;
|
||||
glm::vec3 interpVel {0.0f};
|
||||
public:
|
||||
CameraControl(Player* player, const CameraSettings& settings);
|
||||
CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings);
|
||||
void updateMouse(PlayerInput& input);
|
||||
void update(PlayerInput& input, float delta, Chunks* chunks);
|
||||
void refresh();
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
class PlayerController {
|
||||
Level* level;
|
||||
Player* player;
|
||||
std::shared_ptr<Player> player;
|
||||
PlayerInput input;
|
||||
CameraControl camControl;
|
||||
BlocksController* blocksController;
|
||||
|
||||
@@ -103,6 +103,29 @@ static bool getattr(lua_State* L, gui::FullCheckBox* box, const std::string& att
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool getattr(lua_State* L, gui::TextBox* box, const std::string& attr) {
|
||||
if (box == nullptr)
|
||||
return false;
|
||||
if (attr == "text") {
|
||||
lua_pushstring(L, util::wstr2str_utf8(box->getText()).c_str());
|
||||
return true;
|
||||
} else if (attr == "placeholder") {
|
||||
lua_pushstring(L, util::wstr2str_utf8(box->getPlaceholder()).c_str());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool setattr(lua_State* L, gui::FullCheckBox* box, const std::string& attr) {
|
||||
if (box == nullptr)
|
||||
return false;
|
||||
if (attr == "checked") {
|
||||
box->setChecked(lua_toboolean(L, 4));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool setattr(lua_State* L, gui::Button* button, const std::string& attr) {
|
||||
if (button == nullptr)
|
||||
return false;
|
||||
@@ -115,11 +138,14 @@ static bool setattr(lua_State* L, gui::Button* button, const std::string& attr)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool setattr(lua_State* L, gui::FullCheckBox* box, const std::string& attr) {
|
||||
static bool setattr(lua_State* L, gui::TextBox* box, const std::string& attr) {
|
||||
if (box == nullptr)
|
||||
return false;
|
||||
if (attr == "checked") {
|
||||
box->setChecked(lua_toboolean(L, 4));
|
||||
if (attr == "text") {
|
||||
box->setText(util::str2wstr_utf8(lua_tostring(L, 4)));
|
||||
return true;
|
||||
} else if (attr == "placeholder") {
|
||||
box->setPlaceholder(util::str2wstr_utf8(lua_tostring(L, 4)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -161,6 +187,8 @@ int l_gui_getattr(lua_State* L) {
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<gui::Label*>(node), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<gui::TextBox*>(node), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<gui::TrackBar*>(node), attr))
|
||||
return 1;
|
||||
if (getattr(L, dynamic_cast<gui::FullCheckBox*>(node), attr))
|
||||
@@ -197,6 +225,8 @@ int l_gui_setattr(lua_State* L) {
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<gui::Label*>(node), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<gui::TextBox*>(node), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<gui::TrackBar*>(node), attr))
|
||||
return 0;
|
||||
if (setattr(L, dynamic_cast<gui::FullCheckBox*>(node), attr))
|
||||
|
||||
@@ -57,7 +57,7 @@ int l_player_get_inv(lua_State* L) {
|
||||
int playerid = lua_tointeger(L, 1);
|
||||
if (playerid != 1)
|
||||
return 0;
|
||||
Player* player = scripting::level->player;
|
||||
auto player = scripting::level->player;
|
||||
lua_pushinteger(L, player->getInventory()->getId());
|
||||
lua_pushinteger(L, player->getChosenSlot());
|
||||
return 2;
|
||||
|
||||
@@ -124,6 +124,9 @@ void scripting::on_world_quit() {
|
||||
state->callNoThrow(0);
|
||||
}
|
||||
}
|
||||
if (state->getglobal("__scripts_cleanup")) {
|
||||
state->callNoThrow(0);
|
||||
}
|
||||
scripting::level = nullptr;
|
||||
scripting::content = nullptr;
|
||||
scripting::indices = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user