diff --git a/include/Engine/Entity/Camera.h b/include/Engine/Entity/Camera.h index cab3339..70bee05 100644 --- a/include/Engine/Entity/Camera.h +++ b/include/Engine/Entity/Camera.h @@ -2,6 +2,6 @@ #include "Entity.h" #pragma once -class Camera : public Entity { +class Camera : public Engine::Entity { }; diff --git a/include/Engine/Entity/Entity.h b/include/Engine/Entity/Entity.h index a25d17f..2494c86 100644 --- a/include/Engine/Entity/Entity.h +++ b/include/Engine/Entity/Entity.h @@ -2,7 +2,11 @@ #include #include -class Entity { +namespace Engine { + class Entity; +} + +class Engine::Entity { protected: std::vector children{}; Vector2 position = {0, 0}; diff --git a/include/Engine/Entity/Hud.h b/include/Engine/Entity/Hud.h index 979a5de..a8c04fa 100644 --- a/include/Engine/Entity/Hud.h +++ b/include/Engine/Entity/Hud.h @@ -1,7 +1,11 @@ #pragma once -#include "Renderable.h" +#include -class Hud : public Renderable { +namespace Engine { + class Hud; +} + +class Engine::Hud : public Engine::Renderable { public: Hud() : Renderable({0, 0}, 0) {}; }; diff --git a/include/Engine/Entity/Renderable.h b/include/Engine/Entity/Renderable.h index 962cc2f..811042d 100644 --- a/include/Engine/Entity/Renderable.h +++ b/include/Engine/Entity/Renderable.h @@ -3,7 +3,11 @@ #include #include -class Renderable : public Entity { +namespace Engine { + class Renderable; +} + +class Engine::Renderable : public Entity { public: virtual void Render() {} public: diff --git a/include/Engine/GameWindow.h b/include/Engine/GameWindow.h index c1f1659..92d208d 100644 --- a/include/Engine/GameWindow.h +++ b/include/Engine/GameWindow.h @@ -1,8 +1,10 @@ #include #pragma once -class Camera; -class DemoGameWindow : public ReWindow::RWindow { +namespace Engine { + class DemoGameWindow; +} +class Engine::DemoGameWindow : public ReWindow::RWindow { public: void InitGL(); void Display(); diff --git a/include/Engine/Globals.h b/include/Engine/Globals.h index ad719d7..f1d08aa 100644 --- a/include/Engine/Globals.h +++ b/include/Engine/Globals.h @@ -4,6 +4,8 @@ #include namespace Globals { + using namespace Engine; + inline std::vector SceneList{}; inline Scene* CurrentScene = nullptr; inline DemoGameWindow* Window = nullptr; diff --git a/include/Engine/Level/Fixed.h b/include/Engine/Level/Fixed.h index 923527e..96789f7 100644 --- a/include/Engine/Level/Fixed.h +++ b/include/Engine/Level/Fixed.h @@ -7,9 +7,13 @@ using J3ML::LinearAlgebra::Vector2i; using JGL::Texture; +namespace Engine { + class Fixed; +} + // Things that are considered non-movable parts of the level. // TODO instanced textures. -class Fixed { +class Engine::Fixed { private: void GenerateCollision(); protected: diff --git a/include/Engine/Level/Scene.h b/include/Engine/Level/Scene.h index 51ab73f..e9b7c44 100644 --- a/include/Engine/Level/Scene.h +++ b/include/Engine/Level/Scene.h @@ -5,7 +5,11 @@ #include #include -class Scene { +namespace Engine { + class Scene; +} + +class Engine::Scene { protected: std::string name; Hud* HeadsUpDisplay = nullptr; diff --git a/include/Game/Entity/Box.h b/include/Game/Entity/Box.h index 6d78abe..23ed758 100644 --- a/include/Game/Entity/Box.h +++ b/include/Game/Entity/Box.h @@ -1,8 +1,13 @@ #pragma once #include -#include "Engine/Globals.h" -class Box final : public Renderable { +#include + +namespace Game { + class Box; +} + +class Game::Box final : public Engine::Renderable { public: void Render() final; void Update() final; diff --git a/include/Game/Entity/DemoGameHud.h b/include/Game/Entity/DemoGameHud.h index 9736b8b..e0f9493 100644 --- a/include/Game/Entity/DemoGameHud.h +++ b/include/Game/Entity/DemoGameHud.h @@ -1,6 +1,10 @@ #include -class DemoGameHud : public Hud { +namespace Game { + class DemoGameHud; +} + +class Game::DemoGameHud : public Engine::Hud { public: void Render() override; public: diff --git a/include/Game/Scene/ControllableBox.h b/include/Game/Scene/ControllableBox.h index 959709b..052d7a6 100644 --- a/include/Game/Scene/ControllableBox.h +++ b/include/Game/Scene/ControllableBox.h @@ -1,7 +1,7 @@ #pragma once #include -class ControllableBox final : public Scene { +class ControllableBox final : public Engine::Scene { public: void Init() final; public: diff --git a/include/Game/Scene/Loading.h b/include/Game/Scene/Loading.h index a9531ba..ca135b2 100644 --- a/include/Game/Scene/Loading.h +++ b/include/Game/Scene/Loading.h @@ -1,7 +1,7 @@ #pragma once #include -class LoadingScreen final : public Scene { +class LoadingScreen final : public Engine::Scene { protected: float elapsed = 0.0f; float angle = 0.0f; diff --git a/main.cpp b/main.cpp index 91e145f..d480b35 100644 --- a/main.cpp +++ b/main.cpp @@ -14,15 +14,16 @@ void CreateScenes() { }; int main() { - Globals::Window = new DemoGameWindow("Demo Game", 1024, 896); + ReWindow::Logger::Error.EnableConsole(false); + ReWindow::Logger::Warning.EnableConsole(false); + ReWindow::Logger::Debug.EnableConsole(false); + + Globals::Window = new Engine::DemoGameWindow("Demo Game", 1024, 896); Globals::Window->SetRenderer(RenderingAPI::OPENGL); Globals::Window->Open(); Globals::Window->InitGL(); Globals::Window->SetResizable(false); Globals::Window->SetVsyncEnabled(false); - ReWindow::Logger::Error.EnableConsole(false); - ReWindow::Logger::Warning.EnableConsole(false); - ReWindow::Logger::Debug.EnableConsole(false); CreateScenes(); Globals::ChangeScene("LoadingScreen"); diff --git a/src/Engine/Entity/Entity.cpp b/src/Engine/Entity/Entity.cpp index 86a8d58..6d470b3 100644 --- a/src/Engine/Entity/Entity.cpp +++ b/src/Engine/Entity/Entity.cpp @@ -1,38 +1,38 @@ -#include "J3ML/J3ML.hpp" -#include "Engine/Entity/Entity.h" -#include "Engine/Globals.h" +#include +#include +#include using namespace J3ML; -void Entity::MoveX(float speed) { +void Engine::Entity::MoveX(float speed) { position.x = position.x + (speed * Globals::Window->GetDeltaTime()); } -void Entity::MoveY(float speed) { +void Engine::Entity::MoveY(float speed) { position.y = position.y + (speed * Globals::DeltaTime()); } -void Entity::MoveForward(float speed) { +void Engine::Entity::MoveForward(float speed) { position.x = position.x + (speed * Globals::DeltaTime()) * Math::Cos(face_angle); position.y = position.y + (speed * Globals::DeltaTime()) * Math::Sin(face_angle); } -void Entity::MoveBackward(float speed) { +void Engine::Entity::MoveBackward(float speed) { speed = -speed; position.x = position.x + (speed * Globals::DeltaTime()) * Math::Cos(face_angle); position.y = position.y + (speed * Globals::DeltaTime()) * Math::Sin(face_angle); } -void Entity::MoveLeft(float speed) { +void Engine::Entity::MoveLeft(float speed) { position.x = position.x + (speed * Globals::DeltaTime()) * -Math::Sin(face_angle); position.y = position.y + (speed * Globals::DeltaTime()) * Math::Cos(face_angle); } -void Entity::MoveRight(float speed) { +void Engine::Entity::MoveRight(float speed) { position.x = position.x + (speed * Globals::DeltaTime()) * Math::Sin(face_angle); position.y = position.y + (speed * Globals::DeltaTime()) * -Math::Cos(face_angle); } -void Entity::SetRotation(float new_face_angle) { +void Engine::Entity::SetRotation(float new_face_angle) { face_angle = new_face_angle; if (face_angle < 0) @@ -41,33 +41,33 @@ void Entity::SetRotation(float new_face_angle) { face_angle = fmod(face_angle, Math::Pi * 2); } -void Entity::Rotate(float speed) { +void Engine::Entity::Rotate(float speed) { SetRotation(face_angle + speed * Globals::DeltaTime()); } -float Entity::GetRotation() const { +float Engine::Entity::GetRotation() const { return face_angle; } -Vector2 Entity::GetPosition() const { +Vector2 Engine::Entity::GetPosition() const { return position; } -bool Entity::AppendChild(Entity* entity) { +bool Engine::Entity::AppendChild(Entity* entity) { bool success = false; if (!Globals::CurrentScene->EntityListContains(entity)) children.push_back(entity), success = true; return success; } -Entity::~Entity() { +Engine::Entity::~Entity() { for (auto* e : children) delete e; children = {}; } -void Entity::UpdateChildren() { +void Engine::Entity::UpdateChildren() { for (auto& e : children) { e->Update(); if (!e->children.empty()) @@ -75,13 +75,13 @@ void Entity::UpdateChildren() { } } -void Entity::DestroyChild(Entity* entity) { +void Engine::Entity::DestroyChild(Entity* entity) { auto it = std::find(children.begin(), children.end(), entity); if (it != children.end()) delete *it, children.erase(it); } -void Entity::RemoveChild(Entity* entity) { +void Engine::Entity::RemoveChild(Entity* entity) { auto it = std::find(children.begin(), children.end(), entity); if (it != children.end()) children.erase(it); diff --git a/src/Engine/GameWindow.cpp b/src/Engine/GameWindow.cpp index 34812f4..9572d60 100644 --- a/src/Engine/GameWindow.cpp +++ b/src/Engine/GameWindow.cpp @@ -1,17 +1,17 @@ -#include "Engine/GameWindow.h" -#include "Engine/Globals.h" -#include "Engine/Entity/Camera.h" -#include "JGL/JGL.h" +#include +#include +#include +#include -void DemoGameWindow::InitGL() { +void Engine::DemoGameWindow::InitGL() { if (!JGL::Init(GetSize(), 0, 0)) exit(-1); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } -void DemoGameWindow::Display() { +void Engine::DemoGameWindow::Display() { JGL::Update(GetSize()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -24,9 +24,9 @@ void DemoGameWindow::Display() { if (Globals::CurrentScene) Globals::CurrentScene->Render(); - DemoGameWindow::GLSwapBuffers(); + Engine::DemoGameWindow::GLSwapBuffers(); } -void DemoGameWindow::OnRefresh(float elapsed) { +void Engine::DemoGameWindow::OnRefresh(float elapsed) { Display(); } diff --git a/src/Engine/Level/Fixed.cpp b/src/Engine/Level/Fixed.cpp index d5694c9..de2fad2 100644 --- a/src/Engine/Level/Fixed.cpp +++ b/src/Engine/Level/Fixed.cpp @@ -1,35 +1,35 @@ -#include "Engine/Level/Fixed.h" +#include -bool Fixed::Collidable() const { +bool Engine::Fixed::Collidable() const { return collidable; } -Vector2i Fixed::GetPosition() const { +Vector2i Engine::Fixed::GetPosition() const { return position; } -AABB2D Fixed::GetBounds() const { +AABB2D Engine::Fixed::GetBounds() const { auto maximum = Vector2(position.x + texture->GetDimensions().x, position.y + texture->GetDimensions().y); return { Vector2(position), maximum }; } -bool Fixed::Enabled() const { +bool Engine::Fixed::Enabled() const { return enabled; } -void Fixed::Enable() { +void Engine::Fixed::Enable() { enabled = true; } -void Fixed::Disable() { +void Engine::Fixed::Disable() { enabled = false; } -Fixed::~Fixed() { +Engine::Fixed::~Fixed() { delete texture; } -void Fixed::GenerateCollision() { +void Engine::Fixed::GenerateCollision() { if (!Collidable() || !Enabled() || !texture) return; @@ -43,10 +43,10 @@ void Fixed::GenerateCollision() { collision = result; } -std::vector Fixed::GetCollision() { +std::vector Engine::Fixed::GetCollision() { return collision; } -const Texture* Fixed::GetTexture() { +const Texture* Engine::Fixed::GetTexture() { return texture; } diff --git a/src/Engine/Level/Scene.cpp b/src/Engine/Level/Scene.cpp index 43b0cbd..a0aaad8 100644 --- a/src/Engine/Level/Scene.cpp +++ b/src/Engine/Level/Scene.cpp @@ -1,33 +1,33 @@ #include -bool Scene::EntityListContains(const Entity* entity) const { +bool Engine::Scene::EntityListContains(const Entity* entity) const { for (auto* e : EntityList) if (e == entity) return true; return false; } -bool Scene::FixedListContains(const Fixed* fixed) const { +bool Engine::Scene::FixedListContains(const Fixed* fixed) const { for (auto* f : FixedList) if (f == fixed) return true; return false; } -size_t Scene::FixedCount() const { +size_t Engine::Scene::FixedCount() const { return FixedList.size(); } -size_t Scene::EntityCount() const { +size_t Engine::Scene::EntityCount() const { return EntityList.size(); } -void Scene::Update() { +void Engine::Scene::Update() { for (auto& e : EntityList) e->Update(); } -void Scene::Render() { +void Engine::Scene::Render() { for (auto& f : FixedList) if (f->Enabled()) f->Render(); @@ -41,7 +41,7 @@ void Scene::Render() { HeadsUpDisplay->Render(); } -Scene::~Scene() { +Engine::Scene::~Scene() { for (auto* f : FixedList) delete f; @@ -51,7 +51,7 @@ Scene::~Scene() { delete HeadsUpDisplay; } -void Scene::Unload() { +void Engine::Scene::Unload() { for (auto* f : FixedList) delete f; @@ -61,42 +61,42 @@ void Scene::Unload() { delete HeadsUpDisplay; } -void Scene::AppendEntity(Entity* entity) { +void Engine::Scene::AppendEntity(Entity* entity) { if (!EntityListContains(entity)) EntityList.push_back(entity); } -void Scene::AppendFixed(Fixed* fixed) { +void Engine::Scene::AppendFixed(Fixed* fixed) { if (!FixedListContains(fixed)) FixedList.push_back(fixed); } -void Scene::DestroyEntity(Entity *entity) { +void Engine::Scene::DestroyEntity(Entity *entity) { auto it = std::find(EntityList.begin(), EntityList.end(), entity); if (it != EntityList.end()) delete *it, EntityList.erase(it); } -void Scene::DestroyFixed(Fixed* fixed) { +void Engine::Scene::DestroyFixed(Fixed* fixed) { auto it = std::find(FixedList.begin(), FixedList.end(), fixed); if (it != FixedList.end()) delete *it, FixedList.erase(it); } -void Scene::RemoveEntity(Entity* entity) { +void Engine::Scene::RemoveEntity(Entity* entity) { auto it = std::find(EntityList.begin(), EntityList.end(), entity); if (it != EntityList.end()) EntityList.erase(it); } -void Scene::RemoveFixed(Fixed* fixed) { +void Engine::Scene::RemoveFixed(Fixed* fixed) { auto it = std::find(FixedList.begin(), FixedList.end(), fixed); if (it != FixedList.end()) FixedList.erase(it); } -std::string Scene::GetName() const { +std::string Engine::Scene::GetName() const { return name; } diff --git a/src/Game/Entities/Box.cpp b/src/Game/Entities/Box.cpp index afd7ae1..248373c 100644 --- a/src/Game/Entities/Box.cpp +++ b/src/Game/Entities/Box.cpp @@ -1,12 +1,12 @@ #include -void Box::Render() { +void Game::Box::Render() { J2D::Begin(nullptr, true); J2D::FillRect(Colors::Red, Vector2(position), {20, 20}); J2D::End(); } -void Box::Update() { +void Game::Box::Update() { if (Globals::Window->IsKeyDown(Keys::W)) MoveY(-500); if (Globals::Window->IsKeyDown(Keys::S)) diff --git a/src/Game/Entities/DemoGameHud.cpp b/src/Game/Entities/DemoGameHud.cpp index d83a10d..2d16003 100644 --- a/src/Game/Entities/DemoGameHud.cpp +++ b/src/Game/Entities/DemoGameHud.cpp @@ -1,7 +1,7 @@ #include #include -void DemoGameHud::Render() { +void Game::DemoGameHud::Render() { float framerate = Globals::Window->GetRefreshRate(); J2D::Begin(nullptr, true); J2D::DrawString(Colors::Whites::Ivory, "Framerate: " + std::to_string((int) framerate), 0, 0, 1, 16); diff --git a/src/Game/Scene/ControllableBox.cpp b/src/Game/Scene/ControllableBox.cpp index 01f06a0..b35be70 100644 --- a/src/Game/Scene/ControllableBox.cpp +++ b/src/Game/Scene/ControllableBox.cpp @@ -3,8 +3,8 @@ #include void ControllableBox::Init() { - auto* hud = new DemoGameHud(); - auto* b = new Box({0, 0}); + auto* hud = new Game::DemoGameHud(); + auto* b = new Game::Box({0, 0}); HeadsUpDisplay = hud; AppendEntity(b); }