diff --git a/CMakeLists.txt b/CMakeLists.txt index 94fb8a9..1b47688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,7 @@ target_link_libraries(checklight_engine_system PRIVATE checklight_shared_system checklight_render_system checklight_sound_system + checklight_physics_system ) target_link_libraries(checklight_render_system PRIVATE diff --git a/src/const.hpp b/src/const.hpp index 80983a9..12dec39 100644 --- a/src/const.hpp +++ b/src/const.hpp @@ -13,4 +13,4 @@ # define ENGINE_DEBUG false #endif -#define TICK_DURATION 0.02 \ No newline at end of file +#define TICK_DURATION 0.02 diff --git a/src/engine/board.cpp b/src/engine/board.cpp index 6c78194..beb4e4a 100644 --- a/src/engine/board.cpp +++ b/src/engine/board.cpp @@ -15,11 +15,11 @@ Board::Board() { void Board::queueRemove(const std::shared_ptr& p_to_remove) const { #if ENGINE_DEBUG - if (p_to_remove->to_remove && p_to_remove->getState() != PawnState::REMOVED) { + if(p_to_remove->to_remove && p_to_remove->getState() != PawnState::REMOVED) { FAULT("Pawn unprepared to be removed!"); } #endif - if (p_to_remove->is_tracked_on_hash) { + if(p_to_remove->is_tracked_on_hash) { //pawn needs to be removed from hashmap pawns_to_remove->push(p_to_remove); pawns_to_remove_from_hashmap->push(p_to_remove); @@ -35,7 +35,7 @@ void Board::queueRemove(const std::shared_ptr& pawns_to_remove) { void Board::updateBoard(double delta, std::mutex& mtx) { pawns.updateTree(delta, mtx); SoundListener::setPosition(this->getCamPos()); - SoundListener::setOrientation(this->getCamForward(), {0.0f,1.0f,0.0f}); + SoundListener::setOrientation(this->getCamForward(), {0.0f, 1.0f, 0.0f}); } @@ -57,7 +57,7 @@ std::shared_ptr Board::findPawnByID(const uint32_t id) { std::shared_ptr Board::findPawnByID(const uint32_t id, const size_t position) { std::vector query_result = pawns.findAllByID(id); - if (query_result.size() > position) { + if(query_result.size() > position) { return query_result[position]; } @@ -66,7 +66,7 @@ std::shared_ptr Board::findPawnByID(const uint32_t id, const size_t positi std::shared_ptr Board::findPawnByID(const int32_t id) { - if (id < 0) { + if(id < 0) { FAULT("ID can't be negative!"); } @@ -75,12 +75,12 @@ std::shared_ptr Board::findPawnByID(const int32_t id) { std::shared_ptr Board::findPawnByID(const int32_t id, const size_t position) { - if (id < 0) { + if(id < 0) { FAULT("ID can't be negative!"); } std::vector query_result = pawns.findAllByID(static_cast(id)); - if (query_result.size() > position) { + if(query_result.size() > position) { return query_result[position]; } @@ -100,7 +100,7 @@ std::shared_ptr Board::findPawnByName(const std::string& name) { std::shared_ptr Board::findPawnByName(const std::string& name, const size_t position) { std::vector query_result = pawns.findAllByName(name); - if (query_result.size() > position) { + if(query_result.size() > position) { return query_result[position]; } @@ -148,12 +148,12 @@ Board::~Board() { } void Board::dequeueRemove(const size_t amount) { - while (!pawns_to_remove->empty()) { + while(!pawns_to_remove->empty()) { std::shared_ptr to_be_removed = pawns_to_remove->front(); std::destroy(to_be_removed->children.begin(), to_be_removed->children.end()); - if (std::weak_ptr parent = to_be_removed->parent; !parent.expired()) { + if(std::weak_ptr parent = to_be_removed->parent; !parent.expired()) { auto& children = parent.lock()->getChildren(); std::erase_if(children, [id = to_be_removed->id](const std::shared_ptr& x) { @@ -164,12 +164,12 @@ void Board::dequeueRemove(const size_t amount) { to_be_removed->parent.reset(); #if ENGINE_DEBUG - if (!to_be_removed.get()->is_tracked_on_hash) { + if(!to_be_removed.get()->is_tracked_on_hash) { //pawn should die here std::weak_ptr check = to_be_removed; pawns_to_remove->pop(); - if (!check.expired()) { + if(!check.expired()) { FAULT("There is some reference to a pawn, not good..."); } } else { @@ -180,12 +180,12 @@ void Board::dequeueRemove(const size_t amount) { pawns_to_remove->pop(); #endif } - for (size_t i = 0; - i < (pawns_to_remove_from_hashmap->size() > amount ? amount : pawns_to_remove_from_hashmap->size()); i++) { + for(size_t i = 0; + i < (pawns_to_remove_from_hashmap->size() > amount ? amount : pawns_to_remove_from_hashmap->size()); i++) { const std::shared_ptr to_be_removed = pawns_to_remove_from_hashmap->front(); #if ENGINE_DEBUG - if (!to_be_removed.get()->is_tracked_on_hash) { + if(!to_be_removed.get()->is_tracked_on_hash) { FAULT("Trying to remove pawn from hashmap that is explicitly mark for net being in the hashmap"); } #endif @@ -193,7 +193,7 @@ void Board::dequeueRemove(const size_t amount) { pawns_to_remove_from_hashmap->pop(); } - for (size_t i = 0; i < (components_to_remove->size() > amount ? amount : components_to_remove->size()); i++) { + for(size_t i = 0; i < (components_to_remove->size() > amount ? amount : components_to_remove->size()); i++) { std::shared_ptr* to_be_removed = &components_to_remove->front(); //todo removing from components hashmap after adding it diff --git a/src/engine/board.hpp b/src/engine/board.hpp index 3213c20..2bb59ca 100644 --- a/src/engine/board.hpp +++ b/src/engine/board.hpp @@ -29,6 +29,16 @@ class Board : public std::enable_shared_from_this { void dequeueRemove(size_t amount); + /** + * registers physicsComponent to be included in physics update + */ + void registerPhysicsComponent(const std::shared_ptr& physics_component); + + /** + * removes physicsComponent from registry that stores components to update in physics update + */ + void removePhysicsComponent(const std::shared_ptr& physics_component); + public: Board(); @@ -129,15 +139,6 @@ class Board : public std::enable_shared_from_this { */ int pawnsToRemove() const; - /** - * registers physicsComponent to be included in physics update - */ - void registerPhysicsComponent(const std::shared_ptr& physics_component); - - /** - * removes physicsComponent from registry that stores components to update in physics update - */ - void removePhysicsComponent(const std::shared_ptr& physics_component); PawnTree& getTree() { return pawns; diff --git a/src/engine/boardManager.cpp b/src/engine/boardManager.cpp index c6a5d2d..f03193e 100644 --- a/src/engine/boardManager.cpp +++ b/src/engine/boardManager.cpp @@ -32,7 +32,7 @@ void BoardManager::standardSetup() { const auto cameraPawn = std::make_shared(); const auto cam = cameraPawn->createComponent(); - if (dispatcher) dispatcher->registerListener(cam); + if(dispatcher) dispatcher->registerListener(cam); cameraPawn->setName("Main Camera"); @@ -44,7 +44,7 @@ void BoardManager::standardSetup() { } void BoardManager::addBoard(const std::shared_ptr& new_board) { - boardList.push_back(new_board); + board_list.push_back(new_board); current_board = new_board; } @@ -57,11 +57,11 @@ void BoardManager::updateCycle() { std::shared_ptr usingBoard; - if (!current_board.expired()) usingBoard = current_board.lock(); + if(!current_board.expired()) usingBoard = current_board.lock(); else { bool success; current_board = findWorkingBoard(success); - if (success) usingBoard = current_board.lock(); + if(success) usingBoard = current_board.lock(); else FAULT("There is no available board!"); } @@ -74,11 +74,11 @@ void BoardManager::updateCycle() { auto next_tick = std::chrono::steady_clock::now(); - if (next_tick > physics_next_tick) { + if(next_tick > physics_next_tick) { physics_next_tick = next_tick + std::chrono::duration_cast( - std::chrono::duration(TICK_DURATION)); + std::chrono::duration(TICK_DURATION)); - if (!current_board.expired()) { + if(!current_board.expired()) { current_board.lock()->fixedUpdateBoard(); physics_engine.physicsUpdate(); } @@ -95,7 +95,7 @@ void BoardManager::updateCycle() { //-----------remove-------------- - if (usingBoard->pawnsToRemove() > 0) { + if(usingBoard->pawnsToRemove() > 0) { //maybe someday it will be smarter physics_mutex.lock(); usingBoard->dequeueRemove(100); @@ -147,9 +147,9 @@ void BoardManager::fixedUpdateCycle() { std::shared_ptr BoardManager::findWorkingBoard(bool& success) { std::shared_ptr new_board; - switch (board_recovery) { + switch(board_recovery) { case BoardRevocery::DEFAULT: - if (!default_board.expired()) { + if(!default_board.expired()) { new_board = default_board.lock(); success = true; } else { @@ -160,12 +160,12 @@ std::shared_ptr BoardManager::findWorkingBoard(bool& success) { success = false; break; case BoardRevocery::SEARCH: - if (default_board.expired()) { + if(default_board.expired()) { new_board = default_board.lock(); success = true; } else { - if (boardList.size() > 0) { - new_board = boardList[0]; + if(board_list.size() > 0) { + new_board = board_list[0]; success = true; } else { success = false; diff --git a/src/engine/boardManager.hpp b/src/engine/boardManager.hpp index 823f555..25702d4 100644 --- a/src/engine/boardManager.hpp +++ b/src/engine/boardManager.hpp @@ -21,7 +21,7 @@ class BoardManager { PhysicsEngine physics_engine; unsigned long long global_tick_number; std::weak_ptr current_board; - std::vector> boardList; + std::vector> board_list; ///board that generates when current_board suddenly disappears, (to avoid crashing the program), needs to be set by user std::weak_ptr default_board; ///current board recovery mode @@ -45,6 +45,11 @@ class BoardManager { void addBoard(const std::shared_ptr& new_board); + /** + * if board expires it tries to load other one if board recovery is set to true... + */ + std::shared_ptr findWorkingBoard(bool& success); + public: BoardManager(const std::shared_ptr& disp = nullptr); @@ -60,10 +65,6 @@ class BoardManager { */ void fixedUpdateCycle(); - /** - * if board expires it tries to load other one if board recovery is set to true... - */ - std::shared_ptr findWorkingBoard(bool& success); /** * returns currently used board diff --git a/src/engine/data/collider.cpp b/src/engine/data/collider.cpp index cc710a7..97a7f9e 100644 --- a/src/engine/data/collider.cpp +++ b/src/engine/data/collider.cpp @@ -58,7 +58,7 @@ void Collider::setTriangles(const std::vector& triangles) { this->triangles = triangles; } -void Collider::LoadFromModel(std::shared_ptr) { +void Collider::loadFromModel(std::shared_ptr) { //TODO replace this with actual code this->vertices = Collider::getCube().getVertices(); this->triangles = Collider::getCube().getTriangles(); @@ -70,8 +70,8 @@ void Collider::LoadFromModel(std::shared_ptr) { void Collider::calculateSphereColliderRadius() { sphere_collider_radius = 0; - for (glm::vec3 vec3: vertices) { - if (glm::length(vec3) > sphere_collider_radius) { + for(glm::vec3 vec3 : vertices) { + if(glm::length(vec3) > sphere_collider_radius) { sphere_collider_radius = glm::length(vec3); } } @@ -114,7 +114,7 @@ glm::vec3 Collider::findCenterOfMass() { double total_volume = 0; glm::vec3 center = glm::vec3(0, 0, 0); - for (glm::ivec3 triangle: triangles) { + for(glm::ivec3 triangle : triangles) { //get vertices of a given face glm::vec3 v1 = vertices[triangle[0]]; glm::vec3 v2 = vertices[triangle[1]]; @@ -125,8 +125,8 @@ glm::vec3 Collider::findCenterOfMass() { // given by the formula V = — | v2x v2y v2z | // 6 | v3x v3y v3z | float local_volume = (v1[0] * (v2[1] * v3[2] - v2[2] * v3[1]) - - v1[1] * (v2[0] * v3[2] - v2[2] * v3[0]) - + v1[2] * (v2[0] * v3[1] - v2[1] * v3[0])) / 6.0; + - v1[1] * (v2[0] * v3[2] - v2[2] * v3[0]) + + v1[2] * (v2[0] * v3[1] - v2[1] * v3[0])) / 6.0; //compute center of given tetrahedron glm::vec3 centroid = glm::vec3((v1[0] + v2[0] + v3[0]) / 4.0, (v1[1] + v2[1] + v3[1]) / 4.0, @@ -147,7 +147,7 @@ float Collider::findVolume() { double total_volume = 0; const glm::vec3 offset = vertices[0]; - for (glm::ivec3 triangle: triangles) { + for(glm::ivec3 triangle : triangles) { //get vertices of a given face offset in a way to make origin fall on 1 of the points of the polygon //While calculating the local_volume of the tetrahedrons it didn't matter whether the origin fell outside the polygon //due to the "force of pull" of each polygon being additive with the distance from origin, but now the added @@ -163,8 +163,8 @@ float Collider::findVolume() { // given by the formula V = — | v2x v2y v2z | // 6 | v3x v3y v3z | const float local_volume = (v1[0] * (v2[1] * v3[2] - v2[2] * v3[1]) - - v1[1] * (v2[0] * v3[2] - v2[2] * v3[0]) - + v1[2] * (v2[0] * v3[1] - v2[1] * v3[0])) / 6.0; + - v1[1] * (v2[0] * v3[2] - v2[2] * v3[0]) + + v1[2] * (v2[0] * v3[1] - v2[1] * v3[0])) / 6.0; //update local_volume and mass total_volume += local_volume; diff --git a/src/engine/data/collider.hpp b/src/engine/data/collider.hpp index cd56fc8..ca8d73b 100644 --- a/src/engine/data/collider.hpp +++ b/src/engine/data/collider.hpp @@ -36,7 +36,7 @@ class Collider { void setTriangles(const std::vector& triangles); - void LoadFromModel(std::shared_ptr); + void loadFromModel(std::shared_ptr); void setAutoCenter(); diff --git a/src/engine/entity/component.cpp b/src/engine/entity/component.cpp index e3c1bdf..1a1972e 100644 --- a/src/engine/entity/component.cpp +++ b/src/engine/entity/component.cpp @@ -16,4 +16,4 @@ std::string Component::toString() { void Component::remove() { to_remove = true; -} \ No newline at end of file +} diff --git a/src/engine/entity/component.hpp b/src/engine/entity/component.hpp index f6410d2..09104c3 100644 --- a/src/engine/entity/component.hpp +++ b/src/engine/entity/component.hpp @@ -26,7 +26,6 @@ class Component : public Entity, public InputListener { InputResult onEvent(const InputEvent& event) override = 0; - /** * Executes when it's added to a pawn */ diff --git a/src/engine/entity/component/camera.cpp b/src/engine/entity/component/camera.cpp index 35d73d6..2c9aab2 100644 --- a/src/engine/entity/component/camera.cpp +++ b/src/engine/entity/component/camera.cpp @@ -25,31 +25,31 @@ Camera::Camera(SpatialPawn* s) : GameComponent(s) { } void Camera::onUpdate(Context c) { - float distance_multiplier = c.deltaTime * speed * speed_modifier; + float distance_multiplier = c.delta * speed * speed_modifier; glm::vec3 pos = getPosition(); glm::quat rot = getRotation(); glm::vec3 forward = getForwardVector(); - if (pressed_forward) { + if(pressed_forward) { pos += forward * distance_multiplier; } - if (pressed_backwards) { + if(pressed_backwards) { pos -= forward * distance_multiplier; } - if (pressed_down) { + if(pressed_down) { pos += glm::vec3{0.0f, -1.0f, 0.0f} * distance_multiplier; } - if (pressed_up) { + if(pressed_up) { pos += glm::vec3{0.0f, 1.0f, 0.0f} * distance_multiplier; } - if (pressed_left) { + if(pressed_left) { pos -= normalize(glm::cross(forward, math::UP)) * distance_multiplier; } - if (pressed_right) { + if(pressed_right) { pos += normalize(glm::cross(forward, math::UP)) * distance_multiplier; } - if (mouse_move) { + if(mouse_move) { glm::vec2 mouse_difference = mouse_position - mouse_position_old; mouse_position_old = mouse_position; @@ -74,7 +74,7 @@ void Camera::onUpdate(Context c) { setPosition(pos); setRotation(rot); - auto* s = (SpatialPawn *) parent; + auto* s = (SpatialPawn*) parent; position = s->getPosition(); direction = s->getForwardVector(); } @@ -99,51 +99,51 @@ void Camera::setSpeed(double speed) { } InputResult Camera::onEvent(const InputEvent& event) { - if (const auto* key_event = event.as()) { + if(const auto* key_event = event.as()) { //forward - if (key_event->wasPressed(GLFW_KEY_W)) pressed_forward = true; - else if (key_event->wasReleased(GLFW_KEY_W)) pressed_forward = false; + if(key_event->wasPressed(GLFW_KEY_W)) pressed_forward = true; + else if(key_event->wasReleased(GLFW_KEY_W)) pressed_forward = false; //left - else if (key_event->wasPressed(GLFW_KEY_A)) pressed_left = true; - else if (key_event->wasReleased(GLFW_KEY_A)) pressed_left = false; + else if(key_event->wasPressed(GLFW_KEY_A)) pressed_left = true; + else if(key_event->wasReleased(GLFW_KEY_A)) pressed_left = false; //back - else if (key_event->wasPressed(GLFW_KEY_S)) pressed_backwards = true; - else if (key_event->wasReleased(GLFW_KEY_S)) pressed_backwards = false; + else if(key_event->wasPressed(GLFW_KEY_S)) pressed_backwards = true; + else if(key_event->wasReleased(GLFW_KEY_S)) pressed_backwards = false; //right - else if (key_event->wasPressed(GLFW_KEY_D)) pressed_right = true; - else if (key_event->wasReleased(GLFW_KEY_D)) pressed_right = false; + else if(key_event->wasPressed(GLFW_KEY_D)) pressed_right = true; + else if(key_event->wasReleased(GLFW_KEY_D)) pressed_right = false; //down - else if (key_event->wasPressed(GLFW_KEY_Q) || key_event->wasPressed(GLFW_KEY_LEFT_SHIFT)) + else if(key_event->wasPressed(GLFW_KEY_Q) || key_event->wasPressed(GLFW_KEY_LEFT_SHIFT)) //TODO make two separate ifs? pressed_down = true; - else if (key_event->wasReleased(GLFW_KEY_Q) || key_event->wasReleased(GLFW_KEY_LEFT_SHIFT)) + else if(key_event->wasReleased(GLFW_KEY_Q) || key_event->wasReleased(GLFW_KEY_LEFT_SHIFT)) pressed_down = false; //up - else if (key_event->wasPressed(GLFW_KEY_E) || key_event->wasPressed(GLFW_KEY_SPACE)) + else if(key_event->wasPressed(GLFW_KEY_E) || key_event->wasPressed(GLFW_KEY_SPACE)) pressed_up = true; - else if (key_event->wasReleased(GLFW_KEY_E) || key_event->wasReleased(GLFW_KEY_SPACE)) + else if(key_event->wasReleased(GLFW_KEY_E) || key_event->wasReleased(GLFW_KEY_SPACE)) pressed_up = false; //change speed - else if (key_event->wasPressed(GLFW_KEY_1)) speed_modifier = 0.04; - else if (key_event->wasPressed(GLFW_KEY_2)) speed_modifier = 0.2; - else if (key_event->wasPressed(GLFW_KEY_3)) speed_modifier = 1.0; - else if (key_event->wasPressed(GLFW_KEY_4)) speed_modifier = 5.0; - else if (key_event->wasPressed(GLFW_KEY_5)) speed_modifier = 25.0; + else if(key_event->wasPressed(GLFW_KEY_1)) speed_modifier = 0.04; + else if(key_event->wasPressed(GLFW_KEY_2)) speed_modifier = 0.2; + else if(key_event->wasPressed(GLFW_KEY_3)) speed_modifier = 1.0; + else if(key_event->wasPressed(GLFW_KEY_4)) speed_modifier = 5.0; + else if(key_event->wasPressed(GLFW_KEY_5)) speed_modifier = 25.0; //uncapture - else if (key_event->wasReleased(GLFW_KEY_ESCAPE)) { + else if(key_event->wasReleased(GLFW_KEY_ESCAPE)) { mouse_captured = false; mouse_init = false; } } - if (const auto* button_event = event.as()) { - if (button_event->wasPressed(GLFW_MOUSE_BUTTON_LEFT)) { + if(const auto* button_event = event.as()) { + if(button_event->wasPressed(GLFW_MOUSE_BUTTON_LEFT)) { mouse_captured = true; } } - if (const auto* mouse_event = event.as()) { - if (mouse_captured) { + if(const auto* mouse_event = event.as()) { + if(mouse_captured) { mouse_move = true; - if (!mouse_init) { + if(!mouse_init) { mouse_position_old = mouse_event->getMouse(); mouse_position = mouse_event->getMouse(); } else { @@ -153,8 +153,8 @@ InputResult Camera::onEvent(const InputEvent& event) { return InputResult::ACCEPT; } } - if (const auto* frame_event = event.as()) { - if (mouse_captured) frame_event->capture(); + if(const auto* frame_event = event.as()) { + if(mouse_captured) frame_event->capture(); } return InputResult::PASS; } diff --git a/src/engine/entity/component/camera.hpp b/src/engine/entity/component/camera.hpp index 39adff3..615a7ac 100644 --- a/src/engine/entity/component/camera.hpp +++ b/src/engine/entity/component/camera.hpp @@ -19,12 +19,12 @@ class Camera : public GameComponent { bool mouse_captured; bool pressed_left, - pressed_right, - pressed_up, - pressed_down, - pressed_forward, - pressed_backwards, - mouse_move; + pressed_right, + pressed_up, + pressed_down, + pressed_forward, + pressed_backwards, + mouse_move; void onUpdate(Context c) override; diff --git a/src/engine/entity/component/game.cpp b/src/engine/entity/component/game.cpp index 3adeee0..04e5884 100644 --- a/src/engine/entity/component/game.cpp +++ b/src/engine/entity/component/game.cpp @@ -8,13 +8,11 @@ * GameComponent */ - GameComponent::GameComponent(SpatialPawn* t) : OwnedComponent(t) { - } SpatialPawn* GameComponent::getSpatialParent() const { - return (SpatialPawn *) parent; + return (SpatialPawn*) parent; } glm::vec3 GameComponent::getPosition() const { @@ -52,5 +50,3 @@ void GameComponent::setVelocity(const glm::vec3 velocity) { void GameComponent::setAngularVelocity(const glm::vec3 angularVelocity) { getSpatialParent()->setAngularVelocity(angularVelocity); } - - diff --git a/src/engine/entity/component/game.hpp b/src/engine/entity/component/game.hpp index 7000f48..d123725 100644 --- a/src/engine/entity/component/game.hpp +++ b/src/engine/entity/component/game.hpp @@ -30,4 +30,3 @@ class GameComponent : public OwnedComponent { void setAngularVelocity(glm::vec3 angularVelocity); }; - diff --git a/src/engine/entity/component/matrixAnimation.cpp b/src/engine/entity/component/matrixAnimation.cpp index 181c8f3..8d64c88 100644 --- a/src/engine/entity/component/matrixAnimation.cpp +++ b/src/engine/entity/component/matrixAnimation.cpp @@ -30,8 +30,8 @@ void MatrixAnimation::onUpdate(Context c) { void MatrixAnimation::onFixedUpdate(FixedContext c) { old_percentage = percentage; percentage += TICK_DURATION * animation_speed; - if (percentage > 1) percentage -= 1; - switch (type) { + if(percentage > 1) percentage -= 1; + switch(type) { case NONE: break; case ROTATE: diff --git a/src/engine/entity/component/physics.cpp b/src/engine/entity/component/physics.cpp index 4c59789..f11fa91 100644 --- a/src/engine/entity/component/physics.cpp +++ b/src/engine/entity/component/physics.cpp @@ -8,7 +8,7 @@ PhysicsComponent::PhysicsComponent(SpatialPawn* sp, Collider collider, bool is_s this->material = material; this->collider = collider; this->mass = calculateMass(); - this->initMass = true; + this->init_mass = true; this->collider.setInertiaTensor(glm::mat3x3(mass)); } @@ -18,13 +18,13 @@ PhysicsComponent::PhysicsComponent(SpatialPawn* sp): GameComponent(sp) { this->material = Material(0.4, 0.5, 1); this->collider = Collider::getCube(); this->mass = calculateMass(); - this->initMass = true; + this->init_mass = true; this->collider.setInertiaTensor(glm::mat3x3(mass)); } void PhysicsComponent::onFixedUpdate(FixedContext c) { - initMass = false; + init_mass = false; } void PhysicsComponent::setCollider(const Collider& c) { @@ -39,8 +39,8 @@ void PhysicsComponent::setMass(float mass) { this->mass = mass; } -void PhysicsComponent::setSurface(Surface surface) { - this->material = surface; +void PhysicsComponent::setMaterial(Material material) { + this->material = material; } void PhysicsComponent::setStatic(bool is_static) { @@ -51,7 +51,7 @@ glm::vec3 PhysicsComponent::getGravityScale() const { return gravity_scale; } -Surface& PhysicsComponent::getMaterial() { +Material& PhysicsComponent::getMaterial() { return material; } @@ -63,20 +63,16 @@ Collider& PhysicsComponent::getCollider() { return collider; } -std::shared_ptr PhysicsComponent::getRenderObject() { - return render_object; -} - glm::vec3 PhysicsComponent::furthestPointInDirection(glm::vec3 direction) { const glm::vec3 position = getPosition(); const glm::quat rotation = getRotation(); double dot_result = -INFINITY; glm::vec3 returnal{0, 0, 0}; - for (glm::vec3 vertex: collider.getVertices()) { + for(glm::vec3 vertex : collider.getVertices()) { glm::vec3 rotated = glm::rotate(rotation, vertex); double dr = glm::dot(rotated, direction); - if (dr > dot_result) { + if(dr > dot_result) { dot_result = dr; returnal = rotated; } @@ -89,7 +85,7 @@ float PhysicsComponent::calculateMass() { } float PhysicsComponent::getMass() { - if (!initMass) mass = calculateMass(); + if(!init_mass) mass = calculateMass(); return mass; } diff --git a/src/engine/entity/component/physics.hpp b/src/engine/entity/component/physics.hpp index 2162aa1..93e0127 100644 --- a/src/engine/entity/component/physics.hpp +++ b/src/engine/entity/component/physics.hpp @@ -7,15 +7,13 @@ class PhysicsComponent : public GameComponent { protected: - std::shared_ptr render_object; - Collider collider; bool is_static; glm::vec3 gravity_scale; float mass; - bool initMass; + bool init_mass; Material material; @@ -35,7 +33,7 @@ class PhysicsComponent : public GameComponent { void setMass(float mass); /// Sets the surface properties of the object - void setSurface(Surface surface); + void setMaterial(Material material); /// Sets whether the object is static (non-movable) void setStatic(bool is_static); @@ -47,7 +45,7 @@ class PhysicsComponent : public GameComponent { glm::vec3 getGravityScale() const; /// Gets the surface properties - Surface& getMaterial(); + Material& getMaterial(); /// Returns true if the object is static bool isStatic() const; @@ -55,9 +53,6 @@ class PhysicsComponent : public GameComponent { /// Gets the collider Collider& getCollider(); - /// Gets the associated render object - std::shared_ptr getRenderObject(); - /// Returns the furthest point from object origin in a given direction in relation to the world space glm::vec3 furthestPointInDirection(glm::vec3 direction); @@ -73,4 +68,5 @@ class PhysicsComponent : public GameComponent { void remove() override; ~PhysicsComponent() override; + }; diff --git a/src/engine/entity/component/render.cpp b/src/engine/entity/component/render.cpp index 5af3ae3..0e62e89 100644 --- a/src/engine/entity/component/render.cpp +++ b/src/engine/entity/component/render.cpp @@ -14,7 +14,7 @@ RenderComponent::RenderComponent(SpatialPawn* sp, Models::Shape s) : GameCompone } void RenderComponent::onUpdate(Context c) { - render_object->setMatrix(dynamic_cast(parent)->getMatrix()); //TODO if move byte + render_object->setMatrix(dynamic_cast(parent)->getMatrix()); //TODO if move byte } void RenderComponent::onFixedUpdate(FixedContext c) { @@ -29,7 +29,7 @@ void RenderComponent::onConnected() { } void RenderComponent::setRendering(bool is_rendering) { - if (is_rendering != rendering) { + if(is_rendering != rendering) { render_object->setActive(is_rendering); } rendering = is_rendering; diff --git a/src/engine/entity/component/sound.cpp b/src/engine/entity/component/sound.cpp index 315e9f3..179bf91 100644 --- a/src/engine/entity/component/sound.cpp +++ b/src/engine/entity/component/sound.cpp @@ -1,6 +1,6 @@ #include "sound.hpp" -SoundComponent::SoundComponent(SpatialPawn* t,const std::string& path) : GameComponent(t) { +SoundComponent::SoundComponent(SpatialPawn* t, const std::string& path) : GameComponent(t) { SoundManager& sound_manager = SoundManager::getInstance(); sound_source_object = std::make_shared(); @@ -26,12 +26,11 @@ InputResult SoundComponent::onEvent(const InputEvent& event) { } void SoundComponent::onConnected() { - } void SoundComponent::debugDraw(ImmediateRenderer& renderer) { const glm::vec3 position = getPosition(); renderer.setBillboardMode(BillboardMode::TWO_AXIS); renderer.setSprite(default_file_name); - renderer.drawRect3D(position.x,position.y,position.z,1.0f,1.0f); + renderer.drawRect3D(position.x, position.y, position.z, 1.0f, 1.0f); } diff --git a/src/engine/entity/component/sound.hpp b/src/engine/entity/component/sound.hpp index c97066f..b8e1d20 100644 --- a/src/engine/entity/component/sound.hpp +++ b/src/engine/entity/component/sound.hpp @@ -4,13 +4,11 @@ class SoundComponent : public GameComponent { - static inline std::string default_file_name = "assets/image/speaker.png"; std::shared_ptr sound_source_object; -public: - +public: SoundComponent(SpatialPawn* t, const std::string& path); ~SoundComponent() override; diff --git a/src/engine/entity/context.cpp b/src/engine/entity/context.cpp index 0fe054e..079904e 100644 --- a/src/engine/entity/context.cpp +++ b/src/engine/entity/context.cpp @@ -5,7 +5,7 @@ */ -Context::Context(const float delta, const std::shared_ptr& pawn) { - parent_pawn = pawn; - deltaTime = delta; +Context::Context(const float delta, const std::shared_ptr& parent_pawn) { + this->parent_pawn = parent_pawn; + this->delta = delta; } diff --git a/src/engine/entity/context.hpp b/src/engine/entity/context.hpp index e38dade..16096f4 100644 --- a/src/engine/entity/context.hpp +++ b/src/engine/entity/context.hpp @@ -2,7 +2,7 @@ #include "pawn.hpp" struct Context { - double deltaTime; + double delta; std::shared_ptr parent_pawn; Context(float delta, const std::shared_ptr& pawn); diff --git a/src/engine/entity/pawn.cpp b/src/engine/entity/pawn.cpp index 8df3b92..db88c2c 100644 --- a/src/engine/entity/pawn.cpp +++ b/src/engine/entity/pawn.cpp @@ -13,23 +13,23 @@ */ std::string PawnState::to_str(const PawnState::State p) { - switch (p) { - case State::NEW: return "new"; - case State::LOCAL: return "local"; - case State::TRACKED: return "tracked"; - case State::UNPINNED: return "unpinned"; - case State::REMOVED: return "removed"; - case State::UNLISTED: return "unlisted"; - case State::SINGLE: return "single"; + switch(p) { + case NEW: return "new"; + case LOCAL: return "local"; + case TRACKED: return "tracked"; + case UNPINNED: return "unpinned"; + case REMOVED: return "removed"; + case UNLISTED: return "unlisted"; + case SINGLE: return "single"; default: return "unknown"; } } bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { - PawnState::State childState = new_child->getState(); - switch (new_parent->getState()) { + State childState = new_child->getState(); + switch(new_parent->getState()) { case NEW: - switch (childState) { + switch(childState) { case NEW: //parent - NEW, child - NEW new_child->pawn_state = LOCAL; break; @@ -57,7 +57,7 @@ bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { new_parent->pawn_state = LOCAL; break; case LOCAL: - switch (childState) { + switch(childState) { case NEW: // parent - LOCAL, child - NEW new_child->pawn_state = LOCAL; break; @@ -84,7 +84,7 @@ bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { } break; case TRACKED: - switch (childState) { + switch(childState) { case NEW: // parent - TRACKED, child - NEW new_child->pawn_state = TRACKED; break; @@ -111,7 +111,7 @@ bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { } break; case UNPINNED: - switch (childState) { + switch(childState) { case NEW: // parent - UNPINNED, child - NEW new_child->pawn_state = UNPINNED; break; @@ -140,7 +140,7 @@ bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { case REMOVED: FAULT("Cant add child, the parent is marked as REMOVED"); case UNLISTED: - switch (childState) { + switch(childState) { case NEW: // parent - UNLISTED, child - NEW new_child->pawn_state = LOCAL; break; @@ -167,7 +167,7 @@ bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { } break; case SINGLE: - switch (childState) { + switch(childState) { case NEW: // parent - SINGLE, child - NEW new_child->pawn_state = LOCAL; break; @@ -207,14 +207,14 @@ bool PawnState::convert(Pawn* new_child, Pawn* new_parent) { void Pawn::onUpdate(double delta) { std::shared_ptr p = shared_from_this(); Context cntx(delta, p); - for (const std::shared_ptr& c: components) { + for(const std::shared_ptr& c : components) { c->onUpdate(cntx); } } void Pawn::onFixedUpdate() { FixedContext cntx; - for (const std::shared_ptr& c: components) { + for(const std::shared_ptr& c : components) { c->onFixedUpdate(cntx); } } @@ -235,9 +235,9 @@ Pawn::Pawn(const std::string& s) : Pawn() { std::shared_ptr& Pawn::addComponent(std::shared_ptr c) { c->parent = this; c->onConnected(); - if (auto const pc = std::dynamic_pointer_cast(c)) { + if(auto const pc = std::dynamic_pointer_cast(c)) { physics_component = pc; - if (isRooted()) { + if(isRooted()) { board->registerPhysicsComponent(pc); } } @@ -249,13 +249,13 @@ void Pawn::setBoard(Board* s) { } void Pawn::propagateRemove() { - for (const std::shared_ptr& c: children) { + for(const std::shared_ptr& c : children) { c->safeRemove(); } } bool Pawn::isRooted() { - if (!root_pawn.expired()) { + if(!root_pawn.expired()) { return true; } @@ -263,8 +263,8 @@ bool Pawn::isRooted() { std::shared_ptr recursive_parent = parent.lock(); // recursive_parent will be nullptr if parent expired - while (recursive_parent) { - if (recursive_parent->isRoot()) { + while(recursive_parent) { + if(recursive_parent->isRoot()) { rooted = true; root_pawn = std::static_pointer_cast(recursive_parent); } @@ -278,12 +278,12 @@ std::string Pawn::getPawnName() const { } std::shared_ptr Pawn::getParent() const { - if (parent.expired()) return nullptr; + if(parent.expired()) return nullptr; else return parent.lock(); } Board* Pawn::getScene() { - if (is_mounted_to_board) return board; + if(is_mounted_to_board) return board; else return nullptr; } @@ -297,19 +297,19 @@ void Pawn::addChild(const std::shared_ptr& new_child) { PawnState::convert(new_child.get(), this); children.push_back(new_child); //cannot be std move (it would destroy the argument) - if (isRooted()) { - if (root_pawn.expired()) { + if(isRooted()) { + if(root_pawn.expired()) { FAULT("Root Pawn shouldn't have expired after isRooted() call!"); } PawnTree* pt = root_pawn.lock()->getTree(); - if (pt == nullptr) { + if(pt == nullptr) { FAULT("Pawn Tree shouldn't be null, all Root Pawns should be children of one Pawn Tree!"); } pt->mountPawn(new_child); } else { - if (!isRoot()) { + if(!isRoot()) { unregistered_child_added = true; //only when the change is not instantly commited to a data structure } } @@ -336,35 +336,35 @@ bool Pawn::isMountedToBoard() const { } std::string Pawn::toString() const { - if (name != "") return name; + if(name != "") return name; else return "Unnamed Pawn"; } std::string Pawn::toStringVerbose() const { std::string result; result += - "{ id: " + - std::to_string(id) + - ", name: \"" + - Pawn::toString() + - "\", children: " + - std::to_string(children.size()) + - ", update: " + - std::to_string(unregistered_child_added) + - ", remove: " + - std::to_string(to_remove) + - ", state: " + - PawnState::to_str(pawn_state) + - ", components: " + - std::to_string(components.size()) + - ", parent: " + - (getParent() != nullptr ? "1" : "0") + - "}"; + "{ id: " + + std::to_string(id) + + ", name: \"" + + Pawn::toString() + + "\", children: " + + std::to_string(children.size()) + + ", update: " + + std::to_string(unregistered_child_added) + + ", remove: " + + std::to_string(to_remove) + + ", state: " + + PawnState::to_str(pawn_state) + + ", components: " + + std::to_string(components.size()) + + ", parent: " + + (getParent() != nullptr ? "1" : "0") + + "}"; return result; } std::shared_ptr Pawn::getRoot() { - if (isRooted()) return root_pawn.lock(); + if(isRooted()) return root_pawn.lock(); else return nullptr; } @@ -373,12 +373,12 @@ PawnState::State Pawn::getState() const { } bool Pawn::remove() { - if (isRoot()) { + if(isRoot()) { FAULT("Cant remove root pawn!"); } - if (!to_remove) { + if(!to_remove) { #if ENGINE_DEBUG - if (pawn_state == PawnState::REMOVED) + if(pawn_state == PawnState::REMOVED) FAULT("Pawn state is REMOVED before using remove() function on it"); #endif to_remove = true; @@ -391,15 +391,15 @@ bool Pawn::remove() { board->queueRemove(shared_from_this()); //removing components - for (auto c: components) { + for(auto c : components) { c->remove(); board->queueRemove(c); } return true; } else { #if ENGINE_DEBUG - for (const auto& c: components) { - if (c->to_remove) FAULT("all children should be removed in a pawn described as removed!"); + for(const auto& c : components) { + if(c->to_remove) FAULT("all children should be removed in a pawn described as removed!"); } #endif out::warn("Trying to remove() the same pawn more than once!"); @@ -412,23 +412,23 @@ std::vector>& Pawn::getComponents() { } void Pawn::debugDraw(ImmediateRenderer& renderer) { - for (std::shared_ptr& p : children) { + for(std::shared_ptr& p : children) { p->debugDraw(renderer); } - for (std::shared_ptr& c : components) { + for(std::shared_ptr& c : components) { c->debugDraw(renderer); } } bool Pawn::safeRemove() { #if ENGINE_DEBUG - if (isRoot()) { + if(isRoot()) { FAULT("This shouldn't be root as its as this function should only be called for children of removed pawn"); } #endif - if (to_remove) { + if(to_remove) { #if ENGINE_DEBUG - if (pawn_state == PawnState::REMOVED) + if(pawn_state == PawnState::REMOVED) FAULT("Pawn state is REMOVED before using remove() function on it"); #endif to_remove = true; @@ -449,7 +449,7 @@ void Pawn::setTracked(bool v) { } void Pawn::removeComponents() { - for (const auto& c: components) { + for(const auto& c : components) { c->setActive(false); } } diff --git a/src/engine/entity/pawn.hpp b/src/engine/entity/pawn.hpp index 30abf7e..9dd60a4 100644 --- a/src/engine/entity/pawn.hpp +++ b/src/engine/entity/pawn.hpp @@ -92,19 +92,24 @@ class Pawn : public Entity, public std::enable_shared_from_this { */ void setTracked(bool v); + /** + * Adds a new component to a pawn + */ + //todo fix + std::shared_ptr& addComponent(std::shared_ptr c); void removeComponents(); + /** + * returns true if there were some additive changes to pawn tree (like new children added) that requires changes to PawnTree structure + */ + bool unregisteredChildAdded() const; + public: Pawn(); Pawn(const std::string& s); - /** - * Adds a new component to a pawn - */ - //todo fix - std::shared_ptr& addComponent(std::shared_ptr c); COMPONENT_BIND_POINT @@ -154,11 +159,6 @@ class Pawn : public Entity, public std::enable_shared_from_this { */ virtual bool isRoot(); - /** - * returns true if there were some additive changes to pawn tree (like new children added) that requires changes to PawnTree structure - */ - bool unregisteredChildAdded() const; - /** * returns true if there were some subtractive changes to pawn tree (like removed a children) that requires changes to PawnTree structure */ diff --git a/src/engine/entity/pawns/spatialPawn.hpp b/src/engine/entity/pawns/spatialPawn.hpp index 58dd5de..8a05b66 100644 --- a/src/engine/entity/pawns/spatialPawn.hpp +++ b/src/engine/entity/pawns/spatialPawn.hpp @@ -11,7 +11,7 @@ class SpatialPawn : public Pawn { glm::quat rotation; glm::vec3 scale; - glm::mat4x3 affineTransformMatrix; + glm::mat4x3 affine_transform_matrix; public: SpatialPawn(); diff --git a/src/engine/pawnTree.cpp b/src/engine/pawnTree.cpp index 286a249..73b53a0 100644 --- a/src/engine/pawnTree.cpp +++ b/src/engine/pawnTree.cpp @@ -7,14 +7,13 @@ PawnTree::PawnTree() { root = std::make_shared(); - //TODO adding root to hashmap (?) root->pawn_state = PawnState::TRACKED; root->tr = this; } std::shared_ptr PawnTree::findByName(const std::string& name) { std::unordered_multimap>::iterator result = name_map.find(name); - if (result != name_map.end()) { + if(result != name_map.end()) { return result->second; } return nullptr; @@ -22,7 +21,7 @@ std::shared_ptr PawnTree::findByName(const std::string& name) { std::shared_ptr PawnTree::findByID(uint32_t id) { std::unordered_multimap>::iterator result = id_map.find(id); - if (result != id_map.end()) { + if(result != id_map.end()) { return result->second; } return nullptr; @@ -33,8 +32,8 @@ bool PawnTree::removeFromMaps(const std::string& name, uint32_t id) { auto results = name_map.equal_range(name); - for (auto it = results.first; it != results.second;) { - if (it->second->id == id) { + for(auto it = results.first; it != results.second;) { + if(it->second->id == id) { it = name_map.erase(it); erasedAmount++; continue; @@ -42,7 +41,7 @@ bool PawnTree::removeFromMaps(const std::string& name, uint32_t id) { ++it; } - if (erasedAmount == 1) { + if(erasedAmount == 1) { } else { FAULT("There should be only one entity with given name and ID"); } @@ -55,7 +54,7 @@ bool PawnTree::removeFromMaps(const std::string& name, uint32_t id) { std::vector> PawnTree::findAllByName(const std::string& name) { std::vector> result; auto range = name_map.equal_range(name); - for (auto r = range.first; r != range.second; ++r) { + for(auto r = range.first; r != range.second; ++r) { result.push_back(r->second); } return result; @@ -64,7 +63,7 @@ std::vector> PawnTree::findAllByName(const std::string& na std::vector> PawnTree::findAllByID(const uint32_t id) { std::vector> result; auto range = id_map.equal_range(id); - for (auto r = range.first; r != range.second; ++r) { + for(auto r = range.first; r != range.second; ++r) { result.push_back(r->second); } return result; @@ -87,34 +86,34 @@ void PawnTree::mountPawn(const std::shared_ptr& pawn) { bool isCopy = false; bool isChanged = pawn->unregisteredChildAdded(); - if (id_map.count(pawn->getEntityID()) > 0) { + if(id_map.count(pawn->getEntityID()) > 0) { auto range = id_map.equal_range(pawn->getEntityID()); - for (auto r = range.first; r != range.second; ++r) { - if (r->second == pawn) { + for(auto r = range.first; r != range.second; ++r) { + if(r->second == pawn) { isCopy = true; } } } - if (!pawn->physics_component.expired()) { + if(!pawn->physics_component.expired()) { physics_components_to_update.insert(pawn->physics_component.lock()); } //TODO test if it works - if (!isCopy) { + if(!isCopy) { const std::string p_name = pawn->getName(); const uint32_t p_id = pawn->getEntityID(); addPawnToHash(p_name, p_id, pawn); } - if (isChanged) { + if(isChanged) { updatePawnsChildren(pawn); isChanged = false; } } void PawnTree::updatePawnsChildren(const std::shared_ptr& pawn) { - for (std::shared_ptr& pawn_child: pawn->getChildren()) { + for(std::shared_ptr& pawn_child : pawn->getChildren()) { mountPawn(pawn_child); } } @@ -124,7 +123,7 @@ std::shared_ptr PawnTree::getRoot() { } void PawnTree::updateTree(double delta, std::mutex& mtx) { - for (std::shared_ptr& pawn_child: root->getChildren()) { + for(std::shared_ptr& pawn_child : root->getChildren()) { updateTreeRecursion(pawn_child, delta, mtx); } } @@ -135,13 +134,13 @@ void PawnTree::updateTreeRecursion(std::shared_ptr pawn_to_update, double mtx.unlock(); //TODO maybe create iterator of some kind with lambda - for (std::shared_ptr& pawn_child: pawn_to_update->getChildren()) { + for(std::shared_ptr& pawn_child : pawn_to_update->getChildren()) { updateTreeRecursion(pawn_child, delta, mtx); } } void PawnTree::fixedUpdateTree() { - for (std::shared_ptr& pawn_child: root->getChildren()) { + for(std::shared_ptr& pawn_child : root->getChildren()) { fixedUpdateTreeRecursion(pawn_child); } } @@ -150,7 +149,7 @@ void PawnTree::fixedUpdateTreeRecursion(std::shared_ptr pawn_to_fixed_upda pawn_to_fixed_update->onFixedUpdate(); //TODO maybe create iterator of some kind with lambda - for (std::shared_ptr& pawn_child: pawn_to_fixed_update->getChildren()) { + for(std::shared_ptr& pawn_child : pawn_to_fixed_update->getChildren()) { fixedUpdateTreeRecursion(pawn_child); } } @@ -175,10 +174,10 @@ void PawnTree::removePhysicsComponent(const std::shared_ptr& p std::string PawnTree::printStart(bool verbose) { std::string result; std::string n; - if (!verbose) n = root->toString(); + if(!verbose) n = root->toString(); else n = root->toStringVerbose(); result += "Root:" + n + "\n"; - for (const auto& c: root->getChildren()) { + for(const auto& c : root->getChildren()) { result += recursiveString(c, 1, verbose); } return result; @@ -187,19 +186,19 @@ std::string PawnTree::printStart(bool verbose) { std::string PawnTree::recursiveString(const std::shared_ptr& p, const int depth, const bool verbose) { std::string result; - for (int i = 0; i < depth; i++) { + for(int i = 0; i < depth; i++) { result += " "; } std::string n; - if (!verbose) n = p->toString(); + if(!verbose) n = p->toString(); else n = p->toStringVerbose(); result += "Pawn:" + n + "\n"; - if (verbose) { - for (const auto& component: p->components) { - for (int i = 0; i <= depth; i++) { + if(verbose) { + for(const auto& component : p->components) { + for(int i = 0; i <= depth; i++) { result += " "; } result += "Component:" + component->toString() + "\n"; @@ -207,7 +206,7 @@ std::string PawnTree::recursiveString(const std::shared_ptr& p, const int } std::vector> p_children = p->getChildren(); - for (const auto& i: p_children) { + for(const auto& i : p_children) { result += recursiveString(i, depth + 1, verbose); } return result; diff --git a/src/engine/pawnTree.hpp b/src/engine/pawnTree.hpp index 521b078..136db70 100644 --- a/src/engine/pawnTree.hpp +++ b/src/engine/pawnTree.hpp @@ -7,7 +7,6 @@ class PawnTree { protected: std::shared_ptr root; - std::unordered_multimap> name_map; std::unordered_multimap> id_map; std::set> physics_components_to_update; diff --git a/src/external.hpp b/src/external.hpp index 9c30325..00a17a7 100644 --- a/src/external.hpp +++ b/src/external.hpp @@ -1,4 +1,3 @@ - #include "const.hpp" // C libs @@ -85,4 +84,4 @@ #define NULLABLE // allows us to use time literals -using namespace std::chrono_literals; \ No newline at end of file +using namespace std::chrono_literals; diff --git a/src/main.cpp b/src/main.cpp index 528bfe7..f20f4e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,9 +51,7 @@ static void entry(Args& args) { BoardManager manager(dispacher); manager.setGravity(glm::vec3(0, -10, 0)); - std::shared_ptr sp = manager.getCurrentBoard().lock(); - - { + std::shared_ptr sp = manager.getCurrentBoard().lock(); { auto invisible_pawn = std::make_shared(); invisible_pawn->setPosition(glm::vec3(0, 10, 0)); invisible_pawn->createComponent("assets/sounds/4.ogg"); @@ -72,21 +70,19 @@ static void entry(Args& args) { sphere->createComponent(Models::SPHERE); sphere->createComponent(MatrixAnimation::TRANSLATE); sphere->createComponent("assets/sounds/5.ogg"); - sp->addPawnToRoot(sphere); - { - auto cube_2 = std::make_shared(); - cube_2->setPosition({30, 1.1, 5}); - cube_2->createComponent(Models::CUBE); - cube_2->setRotation(rotate(glm::quat(), {0, 0, 0})); - cube_2->createComponent("assets/sounds/1.ogg"); - auto pc = cube_2->createComponent(); - pc->setVelocity({0, 10, 0}); - pc->setAngularVelocity({0, 0, 0}); - pc->setGravityScale({0, 1, 0}); - pc->getMaterial().coefficient_of_restitution = -0.2f; - sp->addPawnToRoot(cube_2); - } - { + sp->addPawnToRoot(sphere); { + auto cube_2 = std::make_shared(); + cube_2->setPosition({30, 1.1, 5}); + cube_2->createComponent(Models::CUBE); + cube_2->setRotation(rotate(glm::quat(), {0, 0, 0})); + cube_2->createComponent("assets/sounds/1.ogg"); + auto pc = cube_2->createComponent(); + pc->setVelocity({0, 10, 0}); + pc->setAngularVelocity({0, 0, 0}); + pc->setGravityScale({0, 1, 0}); + pc->getMaterial().coefficient_of_restitution = -0.2f; + sp->addPawnToRoot(cube_2); + } { auto cube_2 = std::make_shared(); cube_2->setPosition({30, 1.1, 10}); cube_2->createComponent(Models::CUBE); @@ -96,33 +92,30 @@ static void entry(Args& args) { pc->setVelocity({0, 10, 0}); pc->setAngularVelocity({0, 0, 0}); pc->setGravityScale({0, 1, 0}); - pc->getMaterial().coefficient_of_restitution = 0.5f; + pc->getMaterial().coefficient_of_restitution = 0.5f; sp->addPawnToRoot(cube_2); - } - { - auto cube_2_5 = std::make_shared(); - cube_2_5->setPosition({30, 1.1, 15}); - cube_2_5->createComponent(Models::CUBE); - cube_2_5->setRotation(rotate(glm::quat(), {0, 0, 0})); - cube_2_5->createComponent("assets/sounds/1.ogg"); - auto pc = cube_2_5->createComponent(); - pc->setVelocity({0, 10, 0}); - pc->setAngularVelocity({0, 0, 0}); - pc->setGravityScale({0, 1, 0}); - pc->getMaterial().coefficient_of_restitution = 1.f; - sp->addPawnToRoot(cube_2_5); - } - { + } { + auto cube_2_5 = std::make_shared(); + cube_2_5->setPosition({30, 1.1, 15}); + cube_2_5->createComponent(Models::CUBE); + cube_2_5->setRotation(rotate(glm::quat(), {0, 0, 0})); + cube_2_5->createComponent("assets/sounds/1.ogg"); + auto pc = cube_2_5->createComponent(); + pc->setVelocity({0, 10, 0}); + pc->setAngularVelocity({0, 0, 0}); + pc->setGravityScale({0, 1, 0}); + pc->getMaterial().coefficient_of_restitution = 1.f; + sp->addPawnToRoot(cube_2_5); + } { auto cube_3 = std::make_shared(); cube_3->setPosition({30, 1.1, 20}); cube_3->createComponent(Models::CUBE); cube_3->createComponent("assets/sounds/3.ogg"); auto pc = cube_3->createComponent(); pc->setVelocity({0, 10, 0}); - pc->getMaterial().coefficient_of_restitution = 1.3f; + pc->getMaterial().coefficient_of_restitution = 1.8f; sp->addPawnToRoot(cube_3); - } - { + } { auto floor = std::make_shared(); floor->setPosition({0, -1000, 0}); auto pc = floor->createComponent(); @@ -150,14 +143,14 @@ static void entry(Args& args) { std::vector> objects; - for (auto& model: models) { + for(auto& model : models) { auto object = system.createRenderObject(); object->setMatrix(glm::identity()); object->setModel(model); objects.push_back(object); } - for (auto& model: cube) { + for(auto& model : cube) { auto object = system.createRenderObject(); object->setMatrix(glm::translate(glm::identity(), glm::vec3(4, 0, 4))); object->setModel(model); @@ -189,7 +182,7 @@ static void entry(Args& args) { //window.getInputDispatcher().registerListener(std::make_shared()); - while (!window.shouldClose()) { + while(!window.shouldClose()) { window.poll(); //physics update before rendering @@ -239,7 +232,7 @@ int main(int argc, const char* argv[]) { std::string path = std::filesystem::current_path().generic_string(); out::info("Current working directory: %s", path.c_str()); - if (args.has("--verbose")) { + if(args.has("--verbose")) { out::logger.setLogLevelMask(Logger::LEVEL_VERBOSE); } diff --git a/src/render/vulkan/setup/swapchain.cpp b/src/render/vulkan/setup/swapchain.cpp index aeaba99..4ec4b71 100644 --- a/src/render/vulkan/setup/swapchain.cpp +++ b/src/render/vulkan/setup/swapchain.cpp @@ -176,11 +176,10 @@ const std::vector& SwapchainInfo::getModes() const { return modes; } -VkExtent2D SwapchainInfo::getExtent(Window& window) const { - +VkExtent2D SwapchainInfo::getExtent(const Window& window) const { // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSurfaceCapabilitiesKHR.html // check agains the special value specified in the spec - if (capabilities.currentExtent.width == SWAPCHAIN_EXTENT_AUTO && capabilities.currentExtent.height == SWAPCHAIN_EXTENT_AUTO) { + if (capabilities.currentExtent.width != SWAPCHAIN_EXTENT_AUTO && capabilities.currentExtent.height != SWAPCHAIN_EXTENT_AUTO) { return capabilities.currentExtent; } diff --git a/src/render/vulkan/setup/swapchain.hpp b/src/render/vulkan/setup/swapchain.hpp index 712d048..dd1ce55 100644 --- a/src/render/vulkan/setup/swapchain.hpp +++ b/src/render/vulkan/setup/swapchain.hpp @@ -91,7 +91,7 @@ class SwapchainInfo { const std::vector& getModes() const; /// Get extend for a given window, supported by the swapchain - VkExtent2D getExtent(Window& window) const; + VkExtent2D getExtent(const Window& window) const; /// Clamp desired image number into a supported range uint32_t getImageCount(uint32_t images) const; diff --git a/src/shared/thread/mailbox.cpp b/src/shared/thread/mailbox.cpp index 21c5093..b38640f 100644 --- a/src/shared/thread/mailbox.cpp +++ b/src/shared/thread/mailbox.cpp @@ -13,5 +13,5 @@ void MailboxTaskDelegator::enqueue(const Task& task) { } void MailboxTaskDelegator::wait() { - std::lock_guard {mutex}; + std::lock_guard lock{mutex}; } \ No newline at end of file diff --git a/src/test.cpp b/src/test.cpp index 2c9ef18..c7b7ed0 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -50,7 +50,7 @@ TEST(util_pyramid) { }; TEST(util_weighed_set) { - WeighedSet > set; + WeighedSet> set; ASSERT(set.empty()); @@ -68,7 +68,7 @@ TEST(util_weighed_set) { std::vector order; - for (int i: set) { + for(int i : set) { order.push_back(i); } @@ -80,7 +80,7 @@ TEST(util_weighed_set) { }; TEST(util_weighed_set_limit) { - WeighedSet > set; + WeighedSet> set; EXPECT(std::length_error, { set.lowest(); @@ -106,7 +106,7 @@ TEST(util_weighed_set_limit) { }; TEST(util_weighed_set_repeated) { - WeighedSet > set; + WeighedSet> set; set.insert(20, 111); set.insert(10, 132); @@ -116,7 +116,7 @@ TEST(util_weighed_set_repeated) { CHECK(set.size(), 4); int sum = 0; - for (auto &i: set) { + for(auto& i : set) { sum += i; } @@ -127,11 +127,11 @@ TEST(util_weighed_set_repeated) { }; TEST(util_program_args) { - const char *argv[] = { + const char* argv[] = { "program.exe", "--verbose", "--test", "value", "--another", "-f", "X", "-r", "-w" }; - int argc = sizeof(argv) / sizeof(char *); + int argc = sizeof(argv) / sizeof(char*); Args args(argc, argv); @@ -154,7 +154,7 @@ TEST(util_program_args) { }; TEST(gui_simple_padded_absolute) { - for (Flow flow: {Flow::LEFT_TO_RIGHT, Flow::RIGHT_TO_LEFT, Flow::TOP_TO_BOTTOM, Flow::BOTTOM_TO_TOP}) { + for(Flow flow : {Flow::LEFT_TO_RIGHT, Flow::RIGHT_TO_LEFT, Flow::TOP_TO_BOTTOM, Flow::BOTTOM_TO_TOP}) { auto context = std::make_shared(); auto root = std::make_shared(10, 10); auto sub = std::make_shared(); @@ -196,7 +196,7 @@ TEST(gui_simple_padded_absolute) { }; TEST(gui_simple_padded_fit) { - for (Flow flow: {Flow::LEFT_TO_RIGHT, Flow::RIGHT_TO_LEFT, Flow::TOP_TO_BOTTOM, Flow::BOTTOM_TO_TOP}) { + for(Flow flow : {Flow::LEFT_TO_RIGHT, Flow::RIGHT_TO_LEFT, Flow::TOP_TO_BOTTOM, Flow::BOTTOM_TO_TOP}) { auto context = std::make_shared(); auto root = std::make_shared(10, 10); auto sub = std::make_shared(); @@ -668,22 +668,22 @@ TEST(get_multiple_by_name) { std::shared_ptr a[10]; std::shared_ptr b[7]; - for (int i = 0; i < 10; i++) { + for(int i = 0; i < 10; i++) { a[i] = std::make_shared("SetA"); } - for (int i = 0; i < 7; i++) { + for(int i = 0; i < 7; i++) { b[i] = std::make_shared("SetB"); } CHECK(board->findPawnByName("SetA"), nullptr); ASSERT(board->findPawnsByName("SetA").empty()); - for (int i = 0; i < 10; i++) { + for(int i = 0; i < 10; i++) { board->addPawnToRoot(a[i]); } - for (int i = 0; i < 7; i++) { + for(int i = 0; i < 7; i++) { board->addPawnToRoot(b[i]); } @@ -701,12 +701,12 @@ TEST(get_multiple_by_id) { //cant check for multiple instances of the same id (would require creating more than bilion elements) std::shared_ptr a[10]; - for (int i = 0; i < 10; i++) { + for(int i = 0; i < 10; i++) { a[i] = std::make_shared("SetA"); board->addPawnToRoot(a[i]); } - for (int i = 0; i < 10; i++) { + for(int i = 0; i < 10; i++) { CHECK(board->findPawnsByID(a[i]->getEntityID()).size(), 1); CHECK(board->findPawnsByID(a[i]->getEntityID())[0], a[i]); }