Skip to content

Commit

Permalink
commit for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanbaburajan committed Mar 14, 2024
1 parent 436e955 commit 2d63b51
Show file tree
Hide file tree
Showing 27 changed files with 495 additions and 153 deletions.
4 changes: 3 additions & 1 deletion Editor/EditorCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ namespace DT

using BaseCamera::BaseCamera;

EditorCamera(Context *ctx) : BaseCamera(ctx), transform(ctx) {}

void Recalculate(Window *window)
{
PROFILE();

view = glm::lookAtLH(transform.translation, transform.translation + transform.Forward(), transform.Up());

glm::vec2 winSize = window->GetWindowSize();
float aspect = (float)winSize.x/winSize.y;
float aspect = (float)winSize.x / winSize.y;
if (isOrthographic)
projection = glm::orthoLH(-aspect, aspect, -1.0f, 1.0f, nearPlane, farPlane);
else
Expand Down
2 changes: 1 addition & 1 deletion Editor/Panels/Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace DT
{
auto components = sceneManager->activeScene.View(worldOutliner->GetSelectedEntity()).Fatal("InspectorPanel::Fatal()");
for (auto component : components)
component.second->InspectorMenu(ctx, dt);
component.second->InspectorMenu(&ctx, dt);
}

ImGui::End();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Panels/WorldView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace DT
public:
EditorCamera editorCamera;

WorldViewPanel(Context &ctx) : editorCamera(ctx),
WorldViewPanel(Context &ctx) : editorCamera(&ctx),
translateIcon(Texture::Load(ctx.projectPath / "Engine" / "Icons" / "translate.png").Fatal("WorldViewPanel::WorldViewPanel()")),
rotateIcon(Texture::Load(ctx.projectPath / "Engine" / "Icons" / "rotate.png").Fatal("WorldViewPanel::WorldViewPanel()")),
scaleIcon(Texture::Load(ctx.projectPath / "Engine" / "Icons" / "scale.png").Fatal("WorldViewPanel::WorldViewPanel()")) {}
Expand Down
8 changes: 4 additions & 4 deletions Engine/Components/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ SOFTWARE.

namespace DT
{
void Camera::Init(Context &ctx)
void Camera::Init(Context *ctx)
{
PROFILE();

transform = scene->Require<Transform>(entity).Fatal("Camera::Init()");
window = ctx.GetService<Window>().Fatal("Camera::Init()");
window = ctx->GetService<Window>().Fatal("Camera::Init()");
}

void Camera::Tick(Context &ctx, const float &dt)
void Camera::Tick(Context *ctx, const float &dt)
{
PROFILE();

Expand All @@ -48,7 +48,7 @@ namespace DT
projection = glm::perspectiveLH(glm::radians(fieldOfView), window->GetWindowSize().x / window->GetWindowSize().y, nearPlane, farPlane);
}

void Camera::InspectorMenu(Context &ctx, const float &dt)
void Camera::InspectorMenu(Context *ctx, const float &dt)
{
if (ImGui::CollapsingHeader("Camera"))
{
Expand Down
8 changes: 4 additions & 4 deletions Engine/Components/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace DT
class Camera : public Component, public BaseCamera
{
public:
Camera(Context &ctx) : BaseCamera(ctx)
Camera(Context *ctx) : BaseCamera(ctx)
{
activeCamera = std::shared_ptr<Camera>(this);
}

void Init(Context &ctx) override;
void Tick(Context &ctx, const float &dt) override;
void InspectorMenu(Context &ctx, const float &dt) override;
void Init(Context *ctx) override;
void Tick(Context *ctx, const float &dt) override;
void InspectorMenu(Context *ctx, const float &dt) override;

glm::vec3 GetPosition() override
{
Expand Down
49 changes: 49 additions & 0 deletions Engine/Components/ComponentRegister.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
MIT License
Copyright (c) 2021 - 2023 Aryan Baburajan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#pragma once

#include <ECS/Component.h>
#include <Components/Camera.h>
#include <Components/SpriteRenderer.h>
#include <Components/Tag.h>
#include <Components/Transform.h>

#define REGISTER_COMPONENT(component) \
DT_DLL_EXPORT std::shared_ptr<DT::Component> GetInstanceOf##component(Context *ctx) \
{ \
return std::make_shared<component>(ctx); \
} \
DT_DLL_EXPORT std::type_index GetTypeIndexOf##component() \
{ \
return std::type_index(typeid(component)); \
}

namespace DT
{
REGISTER_COMPONENT(Camera);
REGISTER_COMPONENT(SpriteRenderer);
REGISTER_COMPONENT(Tag);
REGISTER_COMPONENT(Transform);
}
23 changes: 15 additions & 8 deletions Engine/Components/SpriteRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,40 @@ SOFTWARE.

namespace DT
{
SpriteRenderer::SpriteRenderer(Context *ctx, const std::filesystem::path &texturePath) :
SpriteRenderer::SpriteRenderer(Context *ctx) :
material(Shader::Default(*ctx))
{
PROFILE();

material.diffuseMap = Texture::Load(texturePath).Fatal("SpriteRenderer::SpriteRenderer()");
renderer = ctx->GetService<Renderer>().Fatal("SpriteRenderer::SpriteRenderer()");
}

void SpriteRenderer::Init(Context &ctx)
void SpriteRenderer::SetSprite(const std::filesystem::path &texturePath)
{
PROFILE();

transform = scene->Require<Transform>(entity).Fatal("SpriteRenderer::SpriteRenderer()");
material.diffuseMap = Texture::Load(texturePath).Fatal("SpriteRenderer::SetSprite()");
}

void SpriteRenderer::Tick(Context &ctx, const float &dt)
void SpriteRenderer::Init(Context *ctx)
{
PROFILE();

mesh.Draw(*renderer, transform->GetModelMatrix(), material);
transform = scene->Require<Transform>(entity).Fatal("SpriteRenderer::Init()");
}

void SpriteRenderer::EditorTick(Context &ctx, const float &dt)
void SpriteRenderer::Tick(Context *ctx, const float &dt)
{
PROFILE();

mesh.Draw(*renderer, transform->GetModelMatrix(), material);
if (material.diffuseMap.has_value())
mesh.Draw(*renderer, transform->GetModelMatrix(), material);
}

void SpriteRenderer::EditorTick(Context *ctx, const float &dt)
{
PROFILE();

Tick(ctx, dt);
}
}
10 changes: 6 additions & 4 deletions Engine/Components/SpriteRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ namespace DT
class SpriteRenderer : public Component
{
public:
SpriteRenderer(Context *ctx, const std::filesystem::path &texturePath);
SpriteRenderer(Context *ctx);

void SetSprite(const std::filesystem::path &texturePath);

void Init(Context &ctx) override;
void Tick(Context &ctx, const float &dt) override;
void EditorTick(Context &ctx, const float &dt) override;
void Init(Context *ctx) override;
void Tick(Context *ctx, const float &dt) override;
void EditorTick(Context *ctx, const float &dt) override;

private:
Mesh &mesh = Mesh::Quad();
Expand Down
8 changes: 2 additions & 6 deletions Engine/Components/Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ SOFTWARE.

#pragma once

#include <Core/Context.h>
#include <ECS/Component.h>

namespace DT
Expand All @@ -34,12 +33,9 @@ namespace DT
public:
std::string name = "Untitled Entity";

Tag(const std::string &_name) : name(_name)
{
PROFILE();
}
Tag(Context *ctx) {}

void InspectorMenu(Context &ctx, const float &dt) override
void InspectorMenu(Context *ctx, const float &dt) override
{
if (ImGui::CollapsingHeader("Tag"))
{
Expand Down
2 changes: 1 addition & 1 deletion Engine/Components/Transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace DT
rotation = glm::quatLookAtLH(glm::normalize(at - translation), {0.f, 1.f, 0.f});
}

void Transform::InspectorMenu(Context &ctx, const float &dt)
void Transform::InspectorMenu(Context *ctx, const float &dt)
{
if (ImGui::CollapsingHeader("Transform"))
{
Expand Down
4 changes: 3 additions & 1 deletion Engine/Components/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace DT
glm::quat rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f);

Transform(Context *ctx) {}

glm::mat4 GetModelMatrix();
void SetModelMatrix(glm::mat4 model);
glm::vec3 Right();
Expand All @@ -45,6 +47,6 @@ namespace DT
void SetEulerRotation(glm::vec3 eulerRotation);
void LookAt(const glm::vec3 &at);

void InspectorMenu(Context &ctx, const float &dt) override;
void InspectorMenu(Context *ctx, const float &dt) override;
};
}
22 changes: 11 additions & 11 deletions Engine/Core/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ namespace DT
std::cout << "[FATAL] Unhandled error: " + error.value() << ".\n";
abort();
}

T GetValue()
{
PROFILE();

handled = true;
return value.value();
}

bool HasError()
{
Expand All @@ -92,7 +100,7 @@ namespace DT
PROFILE();

handled = true;
if (!HasError()) return Value();
if (!HasError()) return GetValue();
std::cout << "[LOG] " << (errorContext != "" ? errorContext + "\n " : "") << error.value();
}

Expand All @@ -101,7 +109,7 @@ namespace DT
PROFILE();

handled = true;
if (!HasError()) return Value();
if (!HasError()) return GetValue();
std::cout << "[ERR] " << (errorContext != "" ? errorContext + "\n " : "") << error.value();
}

Expand All @@ -110,7 +118,7 @@ namespace DT
PROFILE();

handled = true;
if (!HasError()) return Value();
if (!HasError()) return GetValue();
std::cout << "[FATAL] " << (errorContext != "" ? errorContext + "\n " : "") << error.value();
abort();
}
Expand All @@ -119,13 +127,5 @@ namespace DT
std::optional<std::string> error;
std::optional<T> value;
bool handled = true;

T Value()
{
PROFILE();

handled = true;
return value.value();
}
};
}
2 changes: 1 addition & 1 deletion Engine/Core/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SOFTWARE.

namespace DT
{
InputManager::InputManager(Context &ctx, const json &data)
InputManager::InputManager(Context &ctx)
{
PROFILE();

Expand Down
6 changes: 3 additions & 3 deletions Engine/Core/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ SOFTWARE.
#define KEY_MENU 348
#define KEY_LAST 348

#define MOD_SHIFT 0x0001
#define DT_MOD_SHIFT 0x0001
#define MOD_CONTROL 0x0002
#define MOD_ALT 0x0004
#define DT_MOD_ALT 0x0004
#define MOD_SUPER 0x0008
#define MOD_CAPS_LOCK 0x0010
#define MOD_NUM_LOCK 0x0020
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace DT
class InputManager
{
public:
InputManager(Context &ctx, const json &data);
InputManager(Context &ctx);

void Process();

Expand Down
54 changes: 54 additions & 0 deletions Engine/Core/Module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
MIT License
Copyright (c) 2021 - 2023 Aryan Baburajan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <Core/Platform.h>
#include <Core/Module.h>

namespace DT
{
Module::Module(std::filesystem::path path, Error *err)
{
#ifdef _WIN32
module = LoadLibrary(path.string().c_str());
#endif
#ifdef __linux__
module = dlopen(path.string().c_str(), RTLD_LAZY);
#endif

if (!module)
*err = Error("Error loading GameModule at " + path.string() + ".\nError: " + Platform::GetLastErrorAsString());
else
std::cout << "[LOG] Loaded GameModule at " << path << ".\n";
}

Module::~Module()
{
#ifdef _WIN32
FreeLibrary(module);
#endif
#ifdef __linux__
dlclose(module);
#endif
}
}
Loading

0 comments on commit 2d63b51

Please sign in to comment.