From 874df6094110256c0fced79d76a2da2beb8bbca4 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Thu, 24 Feb 2022 11:11:04 +0700 Subject: [PATCH] small refactoring --- Source.cpp | 2 +- engine/Engine.cpp | 4 ++-- engine/World.cpp | 6 ++++-- engine/World.h | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Source.cpp b/Source.cpp index f090076..b5fe3bc 100644 --- a/Source.cpp +++ b/Source.cpp @@ -15,7 +15,7 @@ int main() { //game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); // Optimal for MacBook Pro 16 display: - game.create(2048, 1152, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR); + game.create(2048, 1152, ShooterConsts::PROJECT_NAME, false, Consts::BACKGROUND_COLOR); //game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR); return 0; diff --git a/engine/Engine.cpp b/engine/Engine.cpp index 0d4e25b..4e651bf 100644 --- a/engine/Engine.cpp +++ b/engine/Engine.cpp @@ -58,7 +58,7 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name, Time::startTimer("d projections"); if (_useOpenGL) { GLfloat *view = camera->glInvModel(); - screen->pushGLStates(); + screen->popGLStates(); screen->prepareToGlDrawMesh(); for (auto &it : *world) { if (it.second->isVisible()) { @@ -68,7 +68,7 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name, delete[] model; } } - screen->popGLStates(); + screen->pushGLStates(); delete[] view; } else { // clear triangles from previous frame diff --git a/engine/World.cpp b/engine/World.cpp index 0bbcc17..6879d59 100644 --- a/engine/World.cpp +++ b/engine/World.cpp @@ -12,16 +12,18 @@ using namespace std; -void World::addBody(std::shared_ptr body) { +std::shared_ptr World::addBody(std::shared_ptr body) { _objects.emplace(body->name(), body); Log::log("World::addBody(): inserted body '" + body->name().str() + "' with " + std::to_string(_objects[body->name()]->triangles().size()) + " tris."); + return _objects[body->name()]; } -void World::loadBody(const ObjectNameTag &tag, const string &filename, const Vec3D &scale) { +std::shared_ptr World::loadBody(const ObjectNameTag &tag, const string &filename, const Vec3D &scale) { _objects.emplace(tag, std::make_shared(tag, filename, scale)); Log::log("World::loadBody(): inserted body from " + filename + " with title '" + tag.str() + "' with " + std::to_string(_objects[tag]->triangles().size()) + " tris."); + return _objects[tag]; } IntersectionInformation World::rayCast(const Vec3D &from, const Vec3D &to, const std::string &skipTags) { diff --git a/engine/World.h b/engine/World.h index 8f3f494..6fe1050 100644 --- a/engine/World.h +++ b/engine/World.h @@ -30,10 +30,10 @@ public: void update(); - void addBody(std::shared_ptr mesh); + std::shared_ptr addBody(std::shared_ptr mesh); std::shared_ptr body(const ObjectNameTag &tag); void removeBody(const ObjectNameTag &tag); - void loadBody(const ObjectNameTag &tag, const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1}); + std::shared_ptr loadBody(const ObjectNameTag &tag, const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1}); void loadMap(const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1}); // std::string skipTags is a string that consist of all objects we want to skip in ray casting