refactor and cleanup player controller

This commit is contained in:
MihailRis
2024-07-08 19:43:13 +03:00
parent 487ba84517
commit 3cd0261f3b
8 changed files with 21 additions and 13 deletions
+2 -1
View File
@@ -40,10 +40,11 @@ void LevelController::update(float delta, bool input, bool pause) {
}
}
blocks->update(delta);
player->update(delta, input, pause);
level->entities->updatePhysics(delta);
level->entities->update();
}
player->update(delta, input, pause);
player->postUpdate(delta, input, pause);
// erease null pointers
level->objects.erase(
+7 -2
View File
@@ -239,11 +239,16 @@ void PlayerController::update(float delta, bool input, bool pause) {
} else {
resetKeyboard();
}
updatePlayer(delta);
}
}
void PlayerController::postUpdate(float delta, bool input, bool pause) {
if (!pause) {
updateFootsteps(delta);
updateCamera(delta, input);
updatePlayer(delta);
}
player->postUpdate(this->input, delta);
camControl.refresh();
if (input) {
updateInteraction();
+1 -1
View File
@@ -89,7 +89,7 @@ public:
BlocksController* blocksController
);
void update(float delta, bool input, bool pause);
void postUpdate(float delta, bool input, bool pause);
Player* getPlayer();
void listenBlockInteraction(const on_block_interaction& callback);
+1 -2
View File
@@ -286,11 +286,10 @@ void scripting::on_entity_spawn(
lua::call(L, 1);
}
if (components.size() > 1) {
for (int i = 0; i < components.size()-1; i++) {
for (size_t i = 0; i < components.size()-1; i++) {
lua::pushvalue(L, -1);
}
}
std::cout << "entity duplicated " << (components.size()-1) << " times" << std::endl;
for (auto& component : components) {
auto compenv = create_component_environment(get_root_environment(), -1,
component->name);