From 547c80b3f08109a65233a45c3c179c52e8ef717f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 7 Mar 2024 11:11:40 +0300 Subject: [PATCH] Player.cpp indents fix --- src/objects/Player.cpp | 278 ++++++++++++++++++++--------------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/src/objects/Player.cpp b/src/objects/Player.cpp index 93b294cd..42900c84 100644 --- a/src/objects/Player.cpp +++ b/src/objects/Player.cpp @@ -19,14 +19,14 @@ const float CHEAT_SPEED_MUL = 5.0f; const float JUMP_FORCE = 8.0f; Player::Player(glm::vec3 position, float speed, std::shared_ptr inv) : - speed(speed), - chosenSlot(0), - inventory(inv), - camera(new Camera(position, glm::radians(90.0f))), - spCamera(new Camera(position, glm::radians(90.0f))), - tpCamera(new Camera(position, glm::radians(90.0f))), + speed(speed), + chosenSlot(0), + inventory(inv), + camera(new Camera(position, glm::radians(90.0f))), + spCamera(new Camera(position, glm::radians(90.0f))), + tpCamera(new Camera(position, glm::radians(90.0f))), currentCamera(camera), - hitbox(new Hitbox(position, glm::vec3(0.3f,0.9f,0.3f))) + hitbox(new Hitbox(position, glm::vec3(0.3f,0.9f,0.3f))) { } @@ -34,116 +34,116 @@ Player::~Player() { } void Player::updateInput( - Level* level, - PlayerInput& input, - float delta) { - bool crouch = input.shift && hitbox->grounded && !input.sprint; - float speed = this->speed; - if (flight){ - speed *= FLIGHT_SPEED_MUL; - } - if (input.cheat){ - speed *= CHEAT_SPEED_MUL; - } + Level* level, + PlayerInput& input, + float delta) { + bool crouch = input.shift && hitbox->grounded && !input.sprint; + float speed = this->speed; + if (flight){ + speed *= FLIGHT_SPEED_MUL; + } + if (input.cheat){ + speed *= CHEAT_SPEED_MUL; + } - if (crouch) { - speed *= CROUCH_SPEED_MUL; - } else if (input.sprint) { - speed *= RUN_SPEED_MUL; - } + if (crouch) { + speed *= CROUCH_SPEED_MUL; + } else if (input.sprint) { + speed *= RUN_SPEED_MUL; + } - glm::vec3 dir(0,0,0); - if (input.moveForward){ - dir.x += camera->dir.x; - dir.z += camera->dir.z; - } - if (input.moveBack){ - dir.x -= camera->dir.x; - dir.z -= camera->dir.z; - } - if (input.moveRight){ - dir.x += camera->right.x; - dir.z += camera->right.z; - } - if (input.moveLeft){ - dir.x -= camera->right.x; - dir.z -= camera->right.z; - } - if (glm::length(dir) > 0.0f){ - dir = glm::normalize(dir); - hitbox->velocity.x += dir.x * speed * delta * 9; - hitbox->velocity.z += dir.z * speed * delta * 9; - } + glm::vec3 dir(0,0,0); + if (input.moveForward){ + dir.x += camera->dir.x; + dir.z += camera->dir.z; + } + if (input.moveBack){ + dir.x -= camera->dir.x; + dir.z -= camera->dir.z; + } + if (input.moveRight){ + dir.x += camera->right.x; + dir.z += camera->right.z; + } + if (input.moveLeft){ + dir.x -= camera->right.x; + dir.z -= camera->right.z; + } + if (glm::length(dir) > 0.0f){ + dir = glm::normalize(dir); + hitbox->velocity.x += dir.x * speed * delta * 9; + hitbox->velocity.z += dir.z * speed * delta * 9; + } float vel = std::max(glm::length(hitbox->velocity * 0.25f), 1.0f); - int substeps = int(delta * vel * 1000); - substeps = std::min(100, std::max(1, substeps)); - level->physics->step(level->chunks.get(), hitbox.get(), - delta, substeps, - crouch, flight ? 0.0f : 1.0f, - !noclip); + int substeps = int(delta * vel * 1000); + substeps = std::min(100, std::max(1, substeps)); + level->physics->step(level->chunks.get(), hitbox.get(), + delta, substeps, + crouch, flight ? 0.0f : 1.0f, + !noclip); - if (flight && hitbox->grounded) { - flight = false; - } + if (flight && hitbox->grounded) { + flight = false; + } - if (input.jump && hitbox->grounded){ - hitbox->velocity.y = JUMP_FORCE; - } + if (input.jump && hitbox->grounded){ + hitbox->velocity.y = JUMP_FORCE; + } - if ((input.flight && !noclip) || - (input.noclip && flight == noclip)){ - flight = !flight; - if (flight){ - hitbox->grounded = false; - } - } - if (input.noclip) { - noclip = !noclip; - } + if ((input.flight && !noclip) || + (input.noclip && flight == noclip)){ + flight = !flight; + if (flight){ + hitbox->grounded = false; + } + } + if (input.noclip) { + noclip = !noclip; + } - hitbox->linear_damping = PLAYER_GROUND_DAMPING; - if (flight){ - hitbox->linear_damping = PLAYER_AIR_DAMPING; - hitbox->velocity.y *= 1.0f - delta * 9; - if (input.jump){ - hitbox->velocity.y += speed * delta * 9; - } - if (input.shift){ - hitbox->velocity.y -= speed * delta * 9; - } - } - if (!hitbox->grounded) { - hitbox->linear_damping = PLAYER_AIR_DAMPING; - } + hitbox->linear_damping = PLAYER_GROUND_DAMPING; + if (flight){ + hitbox->linear_damping = PLAYER_AIR_DAMPING; + hitbox->velocity.y *= 1.0f - delta * 9; + if (input.jump){ + hitbox->velocity.y += speed * delta * 9; + } + if (input.shift){ + hitbox->velocity.y -= speed * delta * 9; + } + } + if (!hitbox->grounded) { + hitbox->linear_damping = PLAYER_AIR_DAMPING; + } - input.noclip = false; - input.flight = false; + input.noclip = false; + input.flight = false; - if (spawnpoint.y <= 0.1) { - attemptToFindSpawnpoint(level); - } + if (spawnpoint.y <= 0.1) { + attemptToFindSpawnpoint(level); + } } void Player::teleport(glm::vec3 position) { - hitbox->position = position; + hitbox->position = position; } void Player::attemptToFindSpawnpoint(Level* level) { - glm::vec3 ppos = hitbox->position; - glm::vec3 newpos {ppos.x + (rand() % 200 - 100), - rand() % 80 + 100, - ppos.z + (rand() % 200 - 100)}; - while (newpos.y > 0 && !level->chunks->isObstacleBlock(newpos.x, newpos.y-2, newpos.z)) { - newpos.y--; - } + glm::vec3 ppos = hitbox->position; + glm::vec3 newpos {ppos.x + (rand() % 200 - 100), + rand() % 80 + 100, + ppos.z + (rand() % 200 - 100)}; + while (newpos.y > 0 && !level->chunks->isObstacleBlock(newpos.x, newpos.y-2, newpos.z)) { + newpos.y--; + } - voxel* headvox = level->chunks->get(newpos.x, newpos.y+1, newpos.z); - if (level->chunks->isObstacleBlock(newpos.x, newpos.y, newpos.z) || - headvox == nullptr || headvox->id != 0) - return; - spawnpoint = newpos + glm::vec3(0.5f, 0.0f, 0.5f); - teleport(spawnpoint); + voxel* headvox = level->chunks->get(newpos.x, newpos.y+1, newpos.z); + if (level->chunks->isObstacleBlock(newpos.x, newpos.y, newpos.z) || + headvox == nullptr || headvox->id != 0) + return; + spawnpoint = newpos + glm::vec3(0.5f, 0.0f, 0.5f); + teleport(spawnpoint); } void Player::setChosenSlot(int index) { @@ -155,7 +155,7 @@ int Player::getChosenSlot() const { } float Player::getSpeed() const { - return speed; + return speed; } std::shared_ptr Player::getInventory() const { @@ -163,62 +163,62 @@ std::shared_ptr Player::getInventory() const { } void Player::setSpawnPoint(glm::vec3 spawnpoint) { - this->spawnpoint = spawnpoint; + this->spawnpoint = spawnpoint; } glm::vec3 Player::getSpawnPoint() const { - return spawnpoint; + return spawnpoint; } std::unique_ptr Player::serialize() const { - glm::vec3 position = hitbox->position; - auto root = std::make_unique(); - auto& posarr = root->putList("position"); - posarr.put(position.x); - posarr.put(position.y); - posarr.put(position.z); + glm::vec3 position = hitbox->position; + auto root = std::make_unique(); + auto& posarr = root->putList("position"); + posarr.put(position.x); + posarr.put(position.y); + posarr.put(position.z); - auto& rotarr = root->putList("rotation"); - rotarr.put(cam.x); - rotarr.put(cam.y); + auto& rotarr = root->putList("rotation"); + rotarr.put(cam.x); + rotarr.put(cam.y); - auto& sparr = root->putList("spawnpoint"); - sparr.put(spawnpoint.x); - sparr.put(spawnpoint.y); - sparr.put(spawnpoint.z); + auto& sparr = root->putList("spawnpoint"); + sparr.put(spawnpoint.x); + sparr.put(spawnpoint.y); + sparr.put(spawnpoint.z); - root->put("flight", flight); - root->put("noclip", noclip); + root->put("flight", flight); + root->put("noclip", noclip); root->put("chosen-slot", chosenSlot); root->put("inventory", inventory->serialize().release()); return root; } void Player::deserialize(dynamic::Map *src) { - auto posarr = src->list("position"); - glm::vec3& position = hitbox->position; - position.x = posarr->num(0); - position.y = posarr->num(1); - position.z = posarr->num(2); - camera->position = position; + auto posarr = src->list("position"); + glm::vec3& position = hitbox->position; + position.x = posarr->num(0); + position.y = posarr->num(1); + position.z = posarr->num(2); + camera->position = position; - auto rotarr = src->list("rotation"); - cam.x = rotarr->num(0); - cam.y = rotarr->num(1); + auto rotarr = src->list("rotation"); + cam.x = rotarr->num(0); + cam.y = rotarr->num(1); - if (src->has("spawnpoint")) { - auto sparr = src->list("spawnpoint"); - setSpawnPoint(glm::vec3( - sparr->num(0), - sparr->num(1), - sparr->num(2) - )); - } else { - setSpawnPoint(position); - } + if (src->has("spawnpoint")) { + auto sparr = src->list("spawnpoint"); + setSpawnPoint(glm::vec3( + sparr->num(0), + sparr->num(1), + sparr->num(2) + )); + } else { + setSpawnPoint(position); + } - src->flag("flight", flight); - src->flag("noclip", noclip); + src->flag("flight", flight); + src->flag("noclip", noclip); setChosenSlot(src->getInt("chosen-slot", getChosenSlot())); auto invmap = src->map("inventory");