Cleanup
This commit is contained in:
@@ -2,6 +2,6 @@
|
||||
#include "Entity.h"
|
||||
#pragma once
|
||||
|
||||
class Camera : public Entity {
|
||||
class Camera : public Engine::Entity {
|
||||
|
||||
};
|
||||
|
@@ -2,7 +2,11 @@
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <vector>
|
||||
|
||||
class Entity {
|
||||
namespace Engine {
|
||||
class Entity;
|
||||
}
|
||||
|
||||
class Engine::Entity {
|
||||
protected:
|
||||
std::vector<Entity*> children{};
|
||||
Vector2 position = {0, 0};
|
||||
|
@@ -1,7 +1,11 @@
|
||||
#pragma once
|
||||
#include "Renderable.h"
|
||||
#include <Engine/Entity/Renderable.h>
|
||||
|
||||
class Hud : public Renderable {
|
||||
namespace Engine {
|
||||
class Hud;
|
||||
}
|
||||
|
||||
class Engine::Hud : public Engine::Renderable {
|
||||
public:
|
||||
Hud() : Renderable({0, 0}, 0) {};
|
||||
};
|
||||
|
@@ -3,7 +3,11 @@
|
||||
#include <Engine/Entity/Entity.h>
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
class Renderable : public Entity {
|
||||
namespace Engine {
|
||||
class Renderable;
|
||||
}
|
||||
|
||||
class Engine::Renderable : public Entity {
|
||||
public:
|
||||
virtual void Render() {}
|
||||
public:
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#pragma once
|
||||
|
||||
class Camera;
|
||||
class DemoGameWindow : public ReWindow::RWindow {
|
||||
namespace Engine {
|
||||
class DemoGameWindow;
|
||||
}
|
||||
class Engine::DemoGameWindow : public ReWindow::RWindow {
|
||||
public:
|
||||
void InitGL();
|
||||
void Display();
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <Engine/GameWindow.h>
|
||||
|
||||
namespace Globals {
|
||||
using namespace Engine;
|
||||
|
||||
inline std::vector<Scene*> SceneList{};
|
||||
inline Scene* CurrentScene = nullptr;
|
||||
inline DemoGameWindow* Window = nullptr;
|
||||
|
@@ -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:
|
||||
|
@@ -5,7 +5,11 @@
|
||||
#include <Engine/Entity/Hud.h>
|
||||
#include <Engine/Level/Fixed.h>
|
||||
|
||||
class Scene {
|
||||
namespace Engine {
|
||||
class Scene;
|
||||
}
|
||||
|
||||
class Engine::Scene {
|
||||
protected:
|
||||
std::string name;
|
||||
Hud* HeadsUpDisplay = nullptr;
|
||||
|
@@ -1,8 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <Engine/Entity/Renderable.h>
|
||||
#include "Engine/Globals.h"
|
||||
class Box final : public Renderable {
|
||||
#include <Engine/Globals.h>
|
||||
|
||||
namespace Game {
|
||||
class Box;
|
||||
}
|
||||
|
||||
class Game::Box final : public Engine::Renderable {
|
||||
public:
|
||||
void Render() final;
|
||||
void Update() final;
|
||||
|
@@ -1,6 +1,10 @@
|
||||
#include <Engine/Entity/Hud.h>
|
||||
|
||||
class DemoGameHud : public Hud {
|
||||
namespace Game {
|
||||
class DemoGameHud;
|
||||
}
|
||||
|
||||
class Game::DemoGameHud : public Engine::Hud {
|
||||
public:
|
||||
void Render() override;
|
||||
public:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <Engine/Level/Scene.h>
|
||||
|
||||
class ControllableBox final : public Scene {
|
||||
class ControllableBox final : public Engine::Scene {
|
||||
public:
|
||||
void Init() final;
|
||||
public:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <Engine/Level/Scene.h>
|
||||
|
||||
class LoadingScreen final : public Scene {
|
||||
class LoadingScreen final : public Engine::Scene {
|
||||
protected:
|
||||
float elapsed = 0.0f;
|
||||
float angle = 0.0f;
|
||||
|
9
main.cpp
9
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");
|
||||
|
@@ -1,38 +1,38 @@
|
||||
#include "J3ML/J3ML.hpp"
|
||||
#include "Engine/Entity/Entity.h"
|
||||
#include "Engine/Globals.h"
|
||||
#include <J3ML/J3ML.hpp>
|
||||
#include <Engine/Entity/Entity.h>
|
||||
#include <Engine/Globals.h>
|
||||
|
||||
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);
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "Engine/GameWindow.h"
|
||||
#include "Engine/Globals.h"
|
||||
#include "Engine/Entity/Camera.h"
|
||||
#include "JGL/JGL.h"
|
||||
#include <Engine/GameWindow.h>
|
||||
#include <Engine/Globals.h>
|
||||
#include <Engine/Entity/Camera.h>
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
@@ -1,35 +1,35 @@
|
||||
#include "Engine/Level/Fixed.h"
|
||||
#include <Engine/Level/Fixed.h>
|
||||
|
||||
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<Vector2i> Fixed::GetCollision() {
|
||||
std::vector<Vector2i> Engine::Fixed::GetCollision() {
|
||||
return collision;
|
||||
}
|
||||
|
||||
const Texture* Fixed::GetTexture() {
|
||||
const Texture* Engine::Fixed::GetTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
@@ -1,33 +1,33 @@
|
||||
#include <Engine/Level/Scene.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#include <Game/Entity/Box.h>
|
||||
|
||||
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))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <Game/Entity/DemoGameHud.h>
|
||||
#include <Engine/Globals.h>
|
||||
|
||||
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);
|
||||
|
@@ -3,8 +3,8 @@
|
||||
#include <Game/Entity/Box.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user