Skip to content

Fixup #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# define ENGINE_DEBUG false
#endif

#define TICK_DURATION 0.02
#define TICK_DURATION 0.02
32 changes: 16 additions & 16 deletions src/engine/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Board::Board() {

void Board::queueRemove(const std::shared_ptr<Pawn>& 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);
Expand All @@ -35,7 +35,7 @@ void Board::queueRemove(const std::shared_ptr<Component>& 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});
}


Expand All @@ -57,7 +57,7 @@ std::shared_ptr<Pawn> Board::findPawnByID(const uint32_t id) {

std::shared_ptr<Pawn> 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];
}

Expand All @@ -66,7 +66,7 @@ std::shared_ptr<Pawn> Board::findPawnByID(const uint32_t id, const size_t positi


std::shared_ptr<Pawn> Board::findPawnByID(const int32_t id) {
if (id < 0) {
if(id < 0) {
FAULT("ID can't be negative!");
}

Expand All @@ -75,12 +75,12 @@ std::shared_ptr<Pawn> Board::findPawnByID(const int32_t id) {


std::shared_ptr<Pawn> 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<uint32_t>(id));
if (query_result.size() > position) {
if(query_result.size() > position) {
return query_result[position];
}

Expand All @@ -100,7 +100,7 @@ std::shared_ptr<Pawn> Board::findPawnByName(const std::string& name) {

std::shared_ptr<Pawn> 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];
}

Expand Down Expand Up @@ -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<Pawn> 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<Pawn>& x) {
Expand All @@ -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<Pawn> 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 {
Expand All @@ -180,20 +180,20 @@ 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<Pawn> 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
pawns.removeFromMaps(to_be_removed->name, to_be_removed->id);

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<Component>* to_be_removed = &components_to_remove->front();

//todo removing from components hashmap after adding it
Expand Down
19 changes: 10 additions & 9 deletions src/engine/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class Board : public std::enable_shared_from_this<Board> {

void dequeueRemove(size_t amount);

/**
* registers physicsComponent to be included in physics update
*/
void registerPhysicsComponent(const std::shared_ptr<PhysicsComponent>& physics_component);

/**
* removes physicsComponent from registry that stores components to update in physics update
*/
void removePhysicsComponent(const std::shared_ptr<PhysicsComponent>& physics_component);

public:
Board();

Expand Down Expand Up @@ -129,15 +139,6 @@ class Board : public std::enable_shared_from_this<Board> {
*/
int pawnsToRemove() const;

/**
* registers physicsComponent to be included in physics update
*/
void registerPhysicsComponent(const std::shared_ptr<PhysicsComponent>& physics_component);

/**
* removes physicsComponent from registry that stores components to update in physics update
*/
void removePhysicsComponent(const std::shared_ptr<PhysicsComponent>& physics_component);

PawnTree& getTree() {
return pawns;
Expand Down
26 changes: 13 additions & 13 deletions src/engine/boardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void BoardManager::standardSetup() {
const auto cameraPawn = std::make_shared<SpatialPawn>();
const auto cam = cameraPawn->createComponent<Camera>();

if (dispatcher) dispatcher->registerListener(cam);
if(dispatcher) dispatcher->registerListener(cam);

cameraPawn->setName("Main Camera");

Expand All @@ -44,7 +44,7 @@ void BoardManager::standardSetup() {
}

void BoardManager::addBoard(const std::shared_ptr<Board>& new_board) {
boardList.push_back(new_board);
board_list.push_back(new_board);
current_board = new_board;
}

Expand All @@ -57,11 +57,11 @@ void BoardManager::updateCycle() {

std::shared_ptr<Board> 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!");
}

Expand All @@ -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::steady_clock::duration>(
std::chrono::duration<double>(TICK_DURATION));
std::chrono::duration<double>(TICK_DURATION));

if (!current_board.expired()) {
if(!current_board.expired()) {
current_board.lock()->fixedUpdateBoard();
physics_engine.physicsUpdate();
}
Expand All @@ -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);
Expand Down Expand Up @@ -147,9 +147,9 @@ void BoardManager::fixedUpdateCycle() {

std::shared_ptr<Board> BoardManager::findWorkingBoard(bool& success) {
std::shared_ptr<Board> 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 {
Expand All @@ -160,12 +160,12 @@ std::shared_ptr<Board> 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;
Expand Down
11 changes: 6 additions & 5 deletions src/engine/boardManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BoardManager {
PhysicsEngine physics_engine;
unsigned long long global_tick_number;
std::weak_ptr<Board> current_board;
std::vector<std::shared_ptr<Board>> boardList;
std::vector<std::shared_ptr<Board>> board_list;
///board that generates when current_board suddenly disappears, (to avoid crashing the program), needs to be set by user
std::weak_ptr<Board> default_board;
///current board recovery mode
Expand All @@ -45,6 +45,11 @@ class BoardManager {

void addBoard(const std::shared_ptr<Board>& new_board);

/**
* if board expires it tries to load other one if board recovery is set to true...
*/
std::shared_ptr<Board> findWorkingBoard(bool& success);

public:
BoardManager(const std::shared_ptr<InputDispatcher>& disp = nullptr);

Expand All @@ -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<Board> findWorkingBoard(bool& success);

/**
* returns currently used board
Expand Down
18 changes: 9 additions & 9 deletions src/engine/data/collider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Collider::setTriangles(const std::vector<glm::ivec3>& triangles) {
this->triangles = triangles;
}

void Collider::LoadFromModel(std::shared_ptr<RenderMesh>) {
void Collider::loadFromModel(std::shared_ptr<RenderMesh>) {
//TODO replace this with actual code
this->vertices = Collider::getCube().getVertices();
this->triangles = Collider::getCube().getTriangles();
Expand All @@ -70,8 +70,8 @@ void Collider::LoadFromModel(std::shared_ptr<RenderMesh>) {

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);
}
}
Expand Down Expand Up @@ -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]];
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/data/collider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Collider {

void setTriangles(const std::vector<glm::ivec3>& triangles);

void LoadFromModel(std::shared_ptr<RenderMesh>);
void loadFromModel(std::shared_ptr<RenderMesh>);

void setAutoCenter();

Expand Down
2 changes: 1 addition & 1 deletion src/engine/entity/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ std::string Component::toString() {

void Component::remove() {
to_remove = true;
}
}
1 change: 0 additions & 1 deletion src/engine/entity/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading