mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
refactor and cleanup player controller
This commit is contained in:
parent
487ba84517
commit
3cd0261f3b
8 changed files with 21 additions and 13 deletions
|
|
@ -66,7 +66,6 @@ entityid_t Entities::spawn(
|
|||
dynamic::Map_sptr saved,
|
||||
entityid_t uid)
|
||||
{
|
||||
std::cout << "spawn entity " << def.name << std::endl;
|
||||
auto rig = level->content->getRig(def.rigName);
|
||||
if (rig == nullptr) {
|
||||
throw std::runtime_error("rig "+def.rigName+" not found");
|
||||
|
|
@ -109,10 +108,8 @@ entityid_t Entities::spawn(
|
|||
componentName, entity_funcs_set {}, nullptr);
|
||||
scripting.components.emplace_back(std::move(component));
|
||||
}
|
||||
std::cout << "on_entity_spawn" << std::endl;
|
||||
scripting::on_entity_spawn(
|
||||
def, id, scripting.components, std::move(args), std::move(saved));
|
||||
std::cout << "done" << std::endl;
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,9 +96,15 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||
dir = glm::normalize(dir);
|
||||
hitbox->velocity += dir * speed * delta * 9.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::postUpdate(PlayerInput& input, float delta) {
|
||||
auto hitbox = getHitbox();
|
||||
if (hitbox == nullptr) {
|
||||
return;
|
||||
}
|
||||
position = hitbox->position;
|
||||
|
||||
// physics calculation was here
|
||||
|
||||
if (flight && hitbox->grounded) {
|
||||
flight = false;
|
||||
}
|
||||
|
|
@ -272,7 +278,6 @@ void Player::deserialize(dynamic::Map *src) {
|
|||
if (auto invmap = src->map("inventory")) {
|
||||
getInventory()->deserialize(invmap.get());
|
||||
}
|
||||
std::cout << "Player::DESERIALIZE " << eid << std::endl;
|
||||
}
|
||||
|
||||
void Player::convert(dynamic::Map* data, const ContentLUT* lut) {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public:
|
|||
void teleport(glm::vec3 position);
|
||||
void updateEntity();
|
||||
void updateInput(PlayerInput& input, float delta);
|
||||
void postUpdate(PlayerInput& input, float delta);
|
||||
|
||||
void attemptToFindSpawnpoint();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue