In process of creating the orthographic camera and camera component

In process of Implementing world rendering and the world view panel in the editor
master
Joey Pollack 3 years ago
parent ed6fdbdb5b
commit 5beb9b2789

@ -75,6 +75,7 @@ set(LUNARIUM_SRC
"src/graphics/opengl/glGraphics.cpp" "src/graphics/opengl/glGraphics.cpp"
"src/graphics/opengl/glText.cpp" "src/graphics/opengl/glText.cpp"
"src/graphics/opengl/glShader.cpp" "src/graphics/opengl/glShader.cpp"
"src/graphics/orthographic_camera.cpp"
"src/gui/gui.cpp" "src/gui/gui.cpp"
"src/gui/imgui_ext.cpp" "src/gui/imgui_ext.cpp"
"src/gui/panel.cpp" "src/gui/panel.cpp"

@ -31,77 +31,102 @@ Core:
✔ Add run mode interface class @done (9/15/2021, 8:22:35 PM) ✔ Add run mode interface class @done (9/15/2021, 8:22:35 PM)
✔ Read the window size and position on shutdown and write these to the state file @done (2/8/2022, 4:39:37 PM) ✔ Read the window size and position on shutdown and write these to the state file @done (2/8/2022, 4:39:37 PM)
Graphics: Graphics:
Re-write the renderer:
☐ Implement BeginScene and EndScene - these are called from the World OnRender
☐ Organize Buffers
☐ Better FrameBuffer system
☐ Texture class - Does NOT load from files - takes raw data to construct
☐ Add view matrix to the shader @critical
☐ Remove projection matrix from the renderer internals @critical
☐ Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic ☐ Move the openGL reference out of the Image class (OpenGL ID) and make the ID more generic
☐ Add layer to interface API for setting the Images ID in a generic way ☐ Add layer to interface API for setting the Images ID in a generic way
☐ Implement batch rendering ☐ Implement batch rendering @high
☐ Allow vertices to be submitted before rendering ☐ Allow vertices to be submitted before rendering
☐ Add texture sampler id to the vertex layout ☐ Add texture sampler id to the vertex layout
✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM) ✔ Decide on a font/text rendering system @done (9/7/2021, 1:39:53 PM)
✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM) ✔ Add FreeType to the project @done (9/7/2021, 2:23:13 PM)
✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM) ✔ Add a new class for font loading/management and text rendering @done (9/7/2021, 3:57:08 PM)
✔ Make the text renderer smarter about breaking up words on multiple lines @low @done (9/8/2021, 2:23:03 PM) ✔ Make the text renderer smarter about breaking up words on multiple lines @low @done (9/8/2021, 2:23:03 PM)
✔ Implement the Image creation methods @done (9/9/2021, 2:50:20 PM) ✔ Implement the Image creation methods @done (9/9/2021, 2:50:20 PM)
✔ Implement Render to Texture @done (9/15/2021, 7:00:33 PM) ✔ Implement Render to Texture @done (9/15/2021, 7:00:33 PM)
✔ Adjust the font loading code to use the binary file buffer instead of ifstream @done (9/17/2021, 6:11:06 PM) ✔ Adjust the font loading code to use the binary file buffer instead of ifstream @done (9/17/2021, 6:11:06 PM)
✔ Find a way to add rotation to shapes and images @done (10/29/2021, 7:35:14 PM) ✔ Find a way to add rotation to shapes and images @done (10/29/2021, 7:35:14 PM)
✔ Add a DrawPolygon method that takes vertices and draws arbirary shapes @done (10/29/2021, 6:24:14 PM) ✔ Add a DrawPolygon method that takes vertices and draws arbirary shapes @done (10/29/2021, 6:24:14 PM)
☐ Allow DrawPolygon to add a texture to the polygon @low ☐ Allow DrawPolygon to add a texture to the polygon @low
✔ Refactor the drawing code to allow for rotation with cleaner code @high @done (10/29/2021, 8:36:24 PM) ✔ Refactor the drawing code to allow for rotation with cleaner code @high @done (10/29/2021, 8:36:24 PM)
✔ Test rotation of images @done (11/1/2021, 2:11:13 PM) ✔ Test rotation of images @done (11/1/2021, 2:11:13 PM)
✔ Fix line rotation @low @done (2/8/2022, 4:39:25 PM) ✔ Fix line rotation @low @done (2/8/2022, 4:39:25 PM)
✔ Add Roboto-Regular.ttf as an internal font @high @done (11/3/2021, 8:35:51 PM) ✔ Add Roboto-Regular.ttf as an internal font @high @done (11/3/2021, 8:35:51 PM)
✔ Allow an image size to be passed in for rendering to an image @high @done (2/3/2022, 4:07:33 PM) ✔ Allow an image size to be passed in for rendering to an image @high @done (2/3/2022, 4:07:33 PM)
Scripting: GUI:
☐ Switch to Wren instead of LUA (https://github.com/wren-lang/wren) @high ☐ Improve the GUI API!
☐ Remove SOL ☐ Implement a better way to handle popup windows and context menus
✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM)
Script Managment class: ✔ Debug log window @done (9/10/2021, 4:44:48 PM)
✘ Manage LUA states @cancelled(22-05-13 17:31) ✔ Add key to show debug log window @done (9/13/2021, 6:47:44 PM)
☐ Initialize new scripts ☐ Add checkboxes to disable log categories and levels
☐ Run given script with given state ✔ Add LUA Console window @done (10/26/2021, 4:43:41 PM)
☐ Add any generated errors to the Script object ✔ Improve the interfaces for the Lua Editor and Console (partial transparancy for one thing) @high @done(22-06-23 15:54)
FileBrowser:
✔ Allow opening of listed directories @done (11/8/2021, 3:16:26 PM)
✔ Add indication that an item is directory @done (11/8/2021, 6:19:20 PM)
✔ Sort items by type (Directories should come first) @done (11/8/2021, 6:26:01 PM)
✔ Allow the user to type in a filename @done (11/9/2021, 3:26:16 PM)
✔ Add a "New Directory" button @done (11/8/2021, 7:15:51 PM)
✔ Selected files should show up in the text box @done(22-04-18 13:33)
Scripting:
☐ Switch to Wren instead of LUA (https://github.com/wren-lang/wren) @high
☐ Remove SOL
Interface Class (Core API): Script Managment class:
☐ Provide Methods that give access to the C++ code ✘ Manage LUA states @cancelled(22-05-13 17:31)
☐ Initialize new scripts
ECS: ☐ Run given script with given state
✔ Figure out how to serialize Entities @done(22-06-28 14:16) ☐ Add any generated errors to the Script object
- Looks like we just need to if check for each component an entity could have...
✔ Research EnTT for the ECS (https://github.com/skypjack/entt/) @done(22-06-01 14:01)
✔ Research using ECS with a quadtree (regions may essentially be a quadtree) @done(22-06-01 14:01)
☐ Use 1 Entt registry with a component that stores the region ID (Index?)
Enitity:
✔ Single UUID @done(22-06-01 14:01)
✔ Functionality for adding/working with components (through EnTT) @done(22-06-01 14:01)
☐ Serialize
☐ JSON
☐ Binary
Components:
✔ Tag @done(22-06-23 15:49)
☐ Transform
☐ SpriteRenderer
☐ Animation Controller
☐ Script
☐ Audio Listener
Physics:
☐ Rigid Body (Box2D)
☐ Box Collider (Box2D)
World (Lunariums version of a "Scene"): Interface Class (Core API):
☐ Implement memento pattern to save the initial state of the world ☐ Provide Methods that give access to the C++ code
☐ Implement running the world and resetting to initial state
☐ Implement the world without Regions first ECS:
✔ Serialize world @done(22-07-06 18:33) ✔ Figure out how to serialize Entities @done(22-06-28 14:16)
✔ JSON @done(22-07-06 18:33) - Looks like we just need to if check for each component an entity could have...
✔ Research EnTT for the ECS (https://github.com/skypjack/entt/) @done(22-06-01 14:01)
✔ Research using ECS with a quadtree (regions may essentially be a quadtree) @done(22-06-01 14:01)
☐ Use 1 Entt registry with a component that stores the region ID (Index?)
Enitity:
✔ Single UUID @done(22-06-01 14:01)
✔ Functionality for adding/working with components (through EnTT) @done(22-06-01 14:01)
☐ Serialize
☐ JSON
☐ Binary ☐ Binary
Implement Regions: Components:
☐ Track/manage active regions ✔ Tag @done(22-06-23 15:49)
☐ Render active Regions ☐ Transform
☐ SpriteRenderer
☐ Animation Controller
☐ Script
☐ Audio Listener
Physics:
☐ Rigid Body (Box2D)
☐ Box Collider (Box2D)
World (Lunariums version of a "Scene"):
☐ Implement memento pattern to save the initial state of the world
☐ Implement running the world and resetting to initial state
☐ Implement the world without Regions first
✔ Serialize world @done(22-07-06 18:33)
✔ JSON @done(22-07-06 18:33)
☐ Binary
Implement Regions:
☐ Track/manage active regions
☐ Render active Regions
Region: Region:
☐ List of renderable images for each layer ☐ List of renderable images for each layer
@ -109,39 +134,21 @@ Core:
☐ Implement image grid within regions ☐ Implement image grid within regions
[Regions could potentially be split into multiple images (an internal grid). [Regions could potentially be split into multiple images (an internal grid).
To support larger region sizes without needing single images that are like 1048576x1048576 or some nonsense.] To support larger region sizes without needing single images that are like 1048576x1048576 or some nonsense.]
GUI:
☐ Improve the GUI API!
☐ Implement a better way to handle popup windows and context menus
✔ Dear ImGui class with basic initialization @done (9/10/2021, 1:42:19 PM)
✔ Debug log window @done (9/10/2021, 4:44:48 PM)
✔ Add key to show debug log window @done (9/13/2021, 6:47:44 PM)
☐ Add checkboxes to disable log categories and levels
✔ Add LUA Console window @done (10/26/2021, 4:43:41 PM)
✔ Improve the interfaces for the Lua Editor and Console (partial transparancy for one thing) @high @done(22-06-23 15:54)
FileBrowser:
✔ Allow opening of listed directories @done (11/8/2021, 3:16:26 PM)
✔ Add indication that an item is directory @done (11/8/2021, 6:19:20 PM)
✔ Sort items by type (Directories should come first) @done (11/8/2021, 6:26:01 PM)
✔ Allow the user to type in a filename @done (11/9/2021, 3:26:16 PM)
✔ Add a "New Directory" button @done (11/8/2021, 7:15:51 PM)
✔ Selected files should show up in the text box @done(22-04-18 13:33)
Input:
✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM)
✔ Add the InputManager to the core @done (9/9/2021, 2:57:06 PM)
Physics:
✔ Research Box2D as a possible physics library @done (10/27/2021, 7:40:44 PM)
✔ Add Box2D to the project as an external library @done (10/27/2021, 7:40:46 PM)
✔ Add a scene to the tester to test Box2D usage @done (10/28/2021, 2:42:45 PM)
☐ Come up with a way to wrap Box2D into an API
Audio:
☐ Research the usage of OpenAL
☐ Add OpenAL to the project
☐ Design Audio API
Input:
✔ Port over the Element2D input system and adjust it to use glfw @done (9/8/2021, 8:20:07 PM)
✔ Add the InputManager to the core @done (9/9/2021, 2:57:06 PM)
Physics:
✔ Research Box2D as a possible physics library @done (10/27/2021, 7:40:44 PM)
✔ Add Box2D to the project as an external library @done (10/27/2021, 7:40:46 PM)
✔ Add a scene to the tester to test Box2D usage @done (10/28/2021, 2:42:45 PM)
☐ Come up with a way to wrap Box2D into an API
Audio:
☐ Research the usage of OpenAL
☐ Add OpenAL to the project
☐ Design Audio API
Utils: Utils:

@ -1,5 +1,6 @@
Editor: Editor:
☐ Design a custom editor style @low
☐ Save and unload world data when a new world is selected ☐ Save and unload world data when a new world is selected
✔ Load the selected world when double clicked on in the asset browser @done(22-07-05 14:29) ✔ Load the selected world when double clicked on in the asset browser @done(22-07-05 14:29)
✔ Asset Location MUST be relative to the project root directory @critical @done(22-05-20 18:35) ✔ Asset Location MUST be relative to the project root directory @critical @done(22-05-20 18:35)

@ -27,6 +27,8 @@ namespace lunarium
bool operator==(const Vec2<T>& rhs) const { return (this->X == rhs.X && this->Y == rhs.Y); } bool operator==(const Vec2<T>& rhs) const { return (this->X == rhs.X && this->Y == rhs.Y); }
bool operator!=(const Vec2<T>& rhs) const { return !((*this) == rhs); } bool operator!=(const Vec2<T>& rhs) const { return !((*this) == rhs); }
operator glm::vec3() { return glm::vec3(X, Y, 0.0f); }
}; };
typedef Vec2<int> Vec2i; typedef Vec2<int> Vec2i;
@ -44,6 +46,10 @@ namespace lunarium
bool operator==(const Size<T>& rhs) const { return (this->Width == rhs.Width && this->Height == rhs.Height); } bool operator==(const Size<T>& rhs) const { return (this->Width == rhs.Width && this->Height == rhs.Height); }
bool operator!=(const Size<T>& rhs) const { return !((*this) == rhs); } bool operator!=(const Size<T>& rhs) const { return !((*this) == rhs); }
operator glm::vec3() { return glm::vec3(Width, Height, 0.0f); }
operator glm::vec2() { return glm::vec2(Width, Height, 0.0f); }
}; };
typedef Size<int> Sizei; typedef Size<int> Sizei;
@ -72,6 +78,8 @@ namespace lunarium
Color(); Color();
Color(float _r, float _g, float _b, float _a = 1.0f); Color(float _r, float _g, float _b, float _a = 1.0f);
operator glm::vec4() { return glm::vec4(R, G, B, A); }
static Color White(); static Color White();
static Color Black(); static Color Black();
static Color Red(); static Color Red();

@ -1,20 +0,0 @@
/******************************************************************************
* File - camera.h
* Author - Joey Pollack
* Date - 2022/01/25 (y/m/d)
* Mod Date - 2022/01/25 (y/m/d)
* Description - A 2D camera to be used with the World
******************************************************************************/
#ifndef CAMERA_H_
#define CAMERA_H_
namespace lunarium
{
class Camera
{
// TODO: class Camera
};
}
#endif // CAMERA_H_

@ -0,0 +1,72 @@
/******************************************************************************
* File - orthographic_camera.cpp
* Author - Joey Pollack
* Date - 2022/01/25 (y/m/d)
* Mod Date - 2022/01/25 (y/m/d)
* Description - A 2D camera to be used with the World
******************************************************************************/
#include "orthographic_camera.h"
#include <glm/gtc/matrix_transform.hpp>
namespace lunarium
{
OrthographicCamera::OrthographicCamera(Vec2f position, Sizef viewport_size)
: mPosition(position), mRotation(0.0f), mViewportSize(viewport_size), mView(1.0f)
{
RecalculateView();
}
void OrthographicCamera::MoveLeft(float amt)
{
mPosition.X += amt;
RecalculateView();
}
void OrthographicCamera::MoveUp(float amt)
{
mPosition.Y += amt;
RecalculateView();
}
void OrthographicCamera::Rotate(float amt)
{
mRotation += amt;
RecalculateView();
}
void OrthographicCamera::SetPosition(Vec2f position)
{
mPosition = position;
RecalculateView();
}
void OrthographicCamera::SetRotation(float rot)
{
mRotation = rot;
RecalculateView();
}
glm::mat4 OrthographicCamera::GetViewProjection()
{
return mViewProj;
}
void OrthographicCamera::SetViewportSize(Sizef size)
{
mViewportSize = size;
RecalculateView();
}
void OrthographicCamera::RecalculateView()
{
mProjection = glm::ortho(0.0f, mViewportSize.Width, mViewportSize.Height, 0.0f, -1.0f, 1.0f);
glm::mat4 transform = glm::translate(glm::mat4(1.0f), (glm::vec3)mPosition);
transform *= glm::rotate(glm::mat4(1.0f), glm::radians(mRotation), glm::vec3(0, 0, 1));
mView = glm::inverse(transform);
mViewProj = mProjection * mView;
}
}

@ -0,0 +1,47 @@
/******************************************************************************
* File - orthographic_camera.h
* Author - Joey Pollack
* Date - 2022/01/25 (y/m/d)
* Mod Date - 2022/01/25 (y/m/d)
* Description - A 2D camera to be used with the World
******************************************************************************/
#ifndef CAMERA_H_
#define CAMERA_H_
#include <core/types.h>
namespace lunarium
{
class OrthographicCamera
{
public:
OrthographicCamera(Vec2f position = { 0.0f, 0.0f }, Sizef viewport_size = {0.0f, 0.0f });
void MoveLeft(float amt);
void MoveUp(float amt);
void Rotate(float amt);
void SetPosition(Vec2f position);
void SetRotation(float rot);
void SetViewportSize(Sizef size);
glm::mat4 GetViewProjection();
private:
void RecalculateView();
private:
Vec2f mPosition;
float mRotation;
Sizef mViewportSize;
glm::mat4 mProjection;
glm::mat4 mView;
glm::mat4 mViewProj;
};
}
#endif // CAMERA_H_

@ -13,7 +13,8 @@
namespace lunarium namespace lunarium
{ {
Panel::Panel(std::string name, PanelDockZone dock_zone, bool isOpen, int window_flags) Panel::Panel(std::string name, PanelDockZone dock_zone, bool isOpen, int window_flags)
: mIsOpen(isOpen), mPanelName(name), mDockZone(dock_zone), mWindowFlags(window_flags) : mIsOpen(isOpen), mPanelName(name), mDockZone(dock_zone), mWindowFlags(window_flags),
mX(-1), mY(-1), mWidth(-1), mHeight(-1)
{ {
} }

@ -17,7 +17,7 @@
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
World::World(std::filesystem::path name) World::World(std::filesystem::path name)
: EditorAsset(AssetType::EATYPE_WORLD), mpWorld(new lunarium::World) : EditorAsset(AssetType::EATYPE_WORLD), mpWorld(new lunarium::World(name.stem().string()))
{ {
mLocation = name.string() + ".wld"; mLocation = name.string() + ".wld";
} }

@ -183,7 +183,7 @@ namespace editor
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{ {
// TODO: Open relevant editor // TODO: Open relevant editor
Logger::Info(Editor::LogCat, "Directory double clicked on. Open Folder"); //Logger::Info(Editor::LogCat, "Directory double clicked on. Open Folder");
// This will force open the tree nodes on the next update so the tree is synced with the content window // This will force open the tree nodes on the next update so the tree is synced with the content window
mSelectedDir = dir_entry.path(); mSelectedDir = dir_entry.path();
@ -203,7 +203,7 @@ namespace editor
if (ImGui::Selectable((*iter)->GetFileLocation().stem().string().c_str())) if (ImGui::Selectable((*iter)->GetFileLocation().stem().string().c_str()))
{ {
// TODO: Show properties if this is new selection (meaning wasn't selected last frame) // TODO: Show properties if this is new selection (meaning wasn't selected last frame)
Logger::Info(Editor::LogCat, "Asset selected. Properties shold show in the PropertiesView Panel"); // Logger::Info(Editor::LogCat, "Asset selected. Properties shold show in the PropertiesView Panel");
} }
if (ImGui::BeginDragDropSource()) if (ImGui::BeginDragDropSource())
{ {

@ -7,6 +7,9 @@
******************************************************************************/ ******************************************************************************/
#include "world_view.h" #include "world_view.h"
#include <core/core.h>
#include <graphics/graphics.h>
#include <assets/types/image.h>
#include <utils/logger.h> #include <utils/logger.h>
#include <world/world.h> #include <world/world.h>
#include <dearimgui/imgui.h> #include <dearimgui/imgui.h>
@ -16,13 +19,51 @@
namespace lunarium { namespace editor namespace lunarium { namespace editor
{ {
WorldView::WorldView() WorldView::WorldView()
: Panel("World View", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpWorld(nullptr) : Panel("World View", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpWorld(nullptr),
mFrameBuffer(-1), mPrevWidth(0), mPrevHeight(0), mpCanvasImage(nullptr)
{ {
} }
void WorldView::Update(float delta)
{
// Need to remake the frame buffer if the window size has changed
int width, height;
GetSize(width, height);
if ((width > 0 && height > 0) && (mPrevWidth != width || mPrevHeight != height))
{
mPrevWidth = width;
mPrevHeight = height;
if (mFrameBuffer > -1)
{
Core::Graphics().DestroyRenderTexture(mFrameBuffer);
}
mFrameBuffer = Core::Graphics().CreateRenderTexture(width, height, 4);
}
// TODO: Handle view navigation input
// Render the current state of the world
if (mpWorld)
{
Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat);
mpWorld->Render(&Core::Graphics());
mpCanvasImage = Core::GetInstance().EndRenderToTexture();
}
}
void WorldView::DoFrame() void WorldView::DoFrame()
{ {
// TODO: Draw toolbar
// Draw world render
if (mpCanvasImage)
{
ImGui::Image((ImTextureID)mpCanvasImage->GetGLTextureID64(),
ImVec2(mpCanvasImage->GetWidth(), mpCanvasImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0));
}
} }
}} }}

@ -13,8 +13,8 @@
namespace lunarium namespace lunarium
{ {
class Image;
class World; // TODO: Use the editor::World class instead? class World;
namespace editor namespace editor
{ {
@ -25,12 +25,18 @@ namespace editor
WorldView(); WorldView();
void DoFrame(); void DoFrame();
void Update(float delta) override;
void SetWorld(World* pWorld); void SetWorld(World* pWorld);
World* GetWorld(); World* GetWorld();
private: private:
World* mpWorld; lunarium::World* mpWorld;
Editor* mpEditor; Editor* mpEditor;
int mPrevWidth;
int mPrevHeight;
int mFrameBuffer;
Image* mpCanvasImage;
}; };
}} // lunarium::editor }} // lunarium::editor

@ -16,6 +16,8 @@
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/quaternion.hpp> #include <glm/gtx/quaternion.hpp>
#include <graphics/orthographic_camera.h>
#include <string> #include <string>
namespace lunarium namespace lunarium
@ -29,6 +31,8 @@ namespace lunarium
Info.reserve(256); Info.reserve(256);
Info.insert(0, _info); Info.insert(0, _info);
} }
TagComponent(const TagComponent&) = default;
}; };
struct TransformComponent struct TransformComponent
@ -43,6 +47,8 @@ namespace lunarium
} }
TransformComponent(const TransformComponent&) = default;
glm::mat4 GetTransform() glm::mat4 GetTransform()
{ {
// Quaternion code taken from Hazel engine // Quaternion code taken from Hazel engine
@ -50,6 +56,14 @@ namespace lunarium
return (glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)) * glm::scale(glm::mat4(1.0f), Scale )); return (glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)) * glm::scale(glm::mat4(1.0f), Scale ));
} }
}; };
struct CameraComponent
{
OrthographicCamera Camera;
CameraComponent() = default;
CameraComponent(const CameraComponent&) = default;
};
} }
#endif // LUNARIUM_COMPONENTS_H_ #endif // LUNARIUM_COMPONENTS_H_

@ -14,7 +14,7 @@
#include <assets/types/script.h> #include <assets/types/script.h>
#include <assets/types/image.h> #include <assets/types/image.h>
#include <graphics/graphics.h> #include <graphics/graphics.h>
#include <graphics/camera.h> #include <graphics/orthographic_camera.h>
#include "entity.h" #include "entity.h"
namespace lunarium namespace lunarium
@ -25,8 +25,8 @@ namespace lunarium
// mActiveRegion = { 0, 0 }; // mActiveRegion = { 0, 0 };
// } // }
World::World() World::World(std::string name)
: mUUID(UUID::GetNewID()) : mUUID(UUID::GetNewID()), mName(name), mpActiveCamera(nullptr)
{ {
} }
@ -43,19 +43,27 @@ namespace lunarium
void World::Update(float dt) void World::Update(float dt)
{ {
// TODO: Call Update in the world script and on each region script // TODO: Update all entities
} }
void World::Render(Graphics* pGraphics) const void World::Render(lunarium::IGraphics* pGraphics) const
{ {
// TODO: Call Render in the world script and on each region OrthographicCamera* pCam = mpActiveCamera;
}
if (!pCam)
{
// Get a camera component from an entity
}
// Get ViewProject matrix
// Render each entity that has a renderable component and a transform
}
void World::RenderToTexture(Graphics* pGraphics, Image* pTexture) const void World::SetActiveCamera(OrthographicCamera* pCam)
{ {
mpActiveCamera = pCam;
} }
entt::registry* World::GetEntityRegistry() entt::registry* World::GetEntityRegistry()
{ {
@ -116,7 +124,7 @@ namespace lunarium
for (int i = 0; i < mEntities.size(); i++) for (int i = 0; i < mEntities.size(); i++)
{ {
nlohmann::ordered_json e; nlohmann::ordered_json e;
mEntities[i]->Serialize(e); mEntities[i]->Serialize(e).LogIfFailed(LogCategory::GAME_SYSTEM);
ents.emplace_back(e); ents.emplace_back(e);
} }
@ -142,7 +150,7 @@ namespace lunarium
return OpRes::Fail("Invalid entity node"); return OpRes::Fail("Invalid entity node");
} }
new_ent->Deserialize(ent); new_ent->Deserialize(ent).LogIfFailed(LogCategory::GAME_SYSTEM);
mEntities.push_back(new_ent); mEntities.push_back(new_ent);
} }

@ -23,10 +23,10 @@
namespace lunarium namespace lunarium
{ {
class Graphics; class IGraphics;
class Image; class Image;
class Script; class Script;
//class Camera; class OrthographicCamera;
//class GameObject; //class GameObject;
class Entity; class Entity;
} }
@ -54,17 +54,14 @@ namespace lunarium
public: // INTERFACE public: // INTERFACE
//World(Camera* pCam, Sizei region_size, Sizei world_size); //World(Camera* pCam, Sizei region_size, Sizei world_size);
World(); World(std::string name);
void OnLoad(); void OnLoad();
void OnUnload(); void OnUnload();
void Update(float dt); void Update(float dt);
void Render(Graphics* pGraphics) const; void Render(lunarium::IGraphics* pGraphics) const;
void RenderToTexture(Graphics* pGraphics, Image* pTexture) const;
OpRes SetRegion(Region* region, Vec2i at); void SetActiveCamera(OrthographicCamera* pCam);
Region* GetRegion(Vec2i at);
bool RemoveRegion(Vec2i at);
entt::registry* GetEntityRegistry(); entt::registry* GetEntityRegistry();
LUUID CreateEntity(); LUUID CreateEntity();
@ -82,10 +79,12 @@ namespace lunarium
private: private:
LUUID mUUID; LUUID mUUID;
std::string mWorldName; std::string mName;
entt::registry mECSRegistry; entt::registry mECSRegistry;
std::vector<Entity*> mEntities; std::vector<Entity*> mEntities;
OrthographicCamera* mpActiveCamera;
// TODO: Move these into a TileMap class? // TODO: Move these into a TileMap class?
// This would allow worlds to support non-tile based levels/worlds // This would allow worlds to support non-tile based levels/worlds
Sizei mRegionSize; // in tiles Sizei mRegionSize; // in tiles

Loading…
Cancel
Save