Serialization project and scene

This commit is contained in:
Antoine Pilote
2021-05-19 21:16:30 -04:00
parent 5f364dabb2
commit e14a2f18d9
39 changed files with 479 additions and 179 deletions

View File

@@ -12,6 +12,7 @@
#include "../Core/Input.h"
#include <GLFW/glfw3.h>
#include <src/Vendors/glm/trigonometric.hpp>
#include <src/Scripting/ScriptingEngine.h>
class FPSCamScript : public ScriptableEntity
@@ -56,12 +57,12 @@ public:
if (Pitch < -89.0f)
Pitch = -89.0f;
Ref<Camera> cam = GetComponent<CameraComponent>().CameraInstance;
cam->cameraDirection.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
cam->cameraDirection.y = sin(glm::radians(Pitch));
cam->cameraDirection.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
cam->cameraFront = glm::normalize(cam->cameraDirection);
cam->cameraRight = glm::normalize(glm::cross(cam->up, cam->cameraFront));
//Ref<Camera> cam = GetComponent<CameraComponent>().CameraInstance;
//cam->cameraDirection.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
//cam->cameraDirection.y = sin(glm::radians(Pitch));
//cam->cameraDirection.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
//cam->cameraFront = glm::normalize(cam->cameraDirection);
//cam->cameraRight = glm::normalize(glm::cross(cam->up, cam->cameraFront));
}
};
@@ -105,14 +106,7 @@ public:
right.y = .0f;
glm::vec3 result = velocity.z * glm::normalize(front) + velocity.x * normalize(right);
CharacterControllerComponent& ccc = GetComponent<CharacterControllerComponent>();
if (ccc.CharacterController->IsOnGround && Input::IsKeyPress(GLFW_KEY_SPACE))
{
velocity.y = 100.0f;
}
ccc.CharacterController->MoveAndSlide(result);
}
};
@@ -133,7 +127,7 @@ public:
{
if (nextFlip < deltaTime)
{
GetComponent<LightComponent>().Strength = isOn * strength;
//GetComponent<LightComponent>().Strength = isOn * strength;
isOn = !isOn;
nextFlip = deltaTime + 1.0f;
}
@@ -148,9 +142,9 @@ void CreateScene()
// Main map entity
auto mapEntity = scene->CreateEntity("Map");
mapEntity.AddComponent<QuakeMap>();
mapEntity.GetComponent<QuakeMap>().Load("Res/Maps/texture_test.map", true);
mapEntity.GetComponent<QuakeMap>().HasCollisions = true;
mapEntity.AddComponent<QuakeMapComponent>();
mapEntity.GetComponent<QuakeMapComponent>().Load("Res/Maps/texture_test.map", true);
mapEntity.GetComponent<QuakeMapComponent>().HasCollisions = true;
// Light entity
auto lightEntity = scene->CreateEntity("Light");
@@ -163,6 +157,7 @@ void CreateScene()
auto player = scene->CreateEntity("Player");
player.GetComponent<TransformComponent>().Translation.y = 10.f;
player.AddComponent<CharacterControllerComponent>();
player.AddComponent<NativeScriptComponent>().Bind<MoveScript>();
// Add cam child
@@ -178,6 +173,8 @@ int main()
{
Engine::Init();
// ScriptingEngine::UpdateScript("test.lua");
EditorInterface editor;
editor.BuildFonts();
@@ -193,6 +190,7 @@ int main()
editor.Draw();
Engine::EndDraw();
Engine::Tick();
}

View File

@@ -17,6 +17,8 @@
#include <algorithm>
#include <Dependencies/GLEW/include/GL/glew.h>
#include "src/Resource/Project.h"
#include <src/Scene/Entities/Components/LuaScriptComponent.h>
#include <src/Core/Logger.h>
ImFont* normalFont;
ImFont* bigIconFont;
@@ -35,8 +37,8 @@ void EditorInterface::Init()
void EditorInterface::DrawViewport()
{
ImGui::Begin("ShadowMap");
{
if(ImGui::Begin("ShadowMap"))
{
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
if (m_IsEntitySelected && m_SelectedEntity.HasComponent<LightComponent>()) {
@@ -47,9 +49,10 @@ void EditorInterface::DrawViewport()
else {
ImGui::Text("Please select a light entity");
}
ImGui::End();
}
ImGui::Begin("Viewport");
ImGui::End();
if(ImGui::Begin("Viewport"))
{
Overlay();
ImGuizmo::BeginFrame();
@@ -64,14 +67,14 @@ void EditorInterface::DrawViewport()
ImGuizmo::SetDrawlist();
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight());
if (m_DrawGrid)
if (m_DrawGrid && !Engine::IsPlayMode)
{
ImGuizmo::DrawGrid(glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetTransform()),
glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetPerspective()),
glm::value_ptr(glm::identity<glm::mat4>()), 100.f);
}
if (m_IsEntitySelected)
if (m_IsEntitySelected && !Engine::IsPlayMode)
{
TransformComponent& tc = m_SelectedEntity.GetComponent<TransformComponent>();
glm::mat4 oldTransform = tc.GetTransform();
@@ -97,12 +100,12 @@ void EditorInterface::DrawViewport()
tc.Rotation = glm::vec3(glm::degrees(euler.x), glm::degrees(euler.y), glm::degrees(euler.z));
tc.Scale = scale;
}
}
ImGui::End();
}
ImGui::End();
}
static int selected = 0;
@@ -203,9 +206,10 @@ void EditorInterface::DrawSceneTree()
ImGui::DragFloat("Volumetric scattering", &env->VolumetricFog, .01f, 0.0f, 1.0f);
ImGui::DragFloat("Volumetric step count", &env->VolumetricStepCount, 1.f, 0.0f);
}
}
ImGui::Begin("Scene");
ImGui::End();
if(ImGui::Begin("Scene"))
{
// Buttons to add and remove entity.
ImGui::BeginChild("Buttons", ImVec2(300, 20), false);
@@ -260,7 +264,7 @@ void EditorInterface::DrawSceneTree()
// ImGui::EndPopup();
}
ImGui::End();
}
ImGui::End();
}
@@ -269,7 +273,7 @@ void EditorInterface::DrawSceneTree()
void EditorInterface::DrawEntityPropreties()
{
ImGui::Begin("Propreties");
if(ImGui::Begin("Propreties"))
{
if (!m_IsEntitySelected)
{
@@ -297,14 +301,16 @@ void EditorInterface::DrawEntityPropreties()
}
if (ImGui::BeginPopup("add_component_popup"))
{
if (ImGui::MenuItem("Lua script") && !m_SelectedEntity.HasComponent<LuaScriptComponent>())
m_SelectedEntity.AddComponent<LuaScriptComponent>();
if (ImGui::MenuItem("Light Component") && !m_SelectedEntity.HasComponent<LightComponent>())
m_SelectedEntity.AddComponent<LightComponent>();
if (ImGui::MenuItem("Mesh Component") && !m_SelectedEntity.HasComponent<MeshComponent>())
m_SelectedEntity.AddComponent<MeshComponent>();
if (ImGui::MenuItem("Camera Component") && !m_SelectedEntity.HasComponent<CameraComponent>())
m_SelectedEntity.AddComponent<CameraComponent>();
if (ImGui::MenuItem("Quake map Component") && !m_SelectedEntity.HasComponent<QuakeMap>())
m_SelectedEntity.AddComponent<QuakeMap>();
if (ImGui::MenuItem("Quake map Component") && !m_SelectedEntity.HasComponent<QuakeMapComponent>())
m_SelectedEntity.AddComponent<QuakeMapComponent>();
if (ImGui::MenuItem("Rigidbody Component") && !m_SelectedEntity.HasComponent<RigidBodyComponent>())
{
m_SelectedEntity.AddComponent<RigidBodyComponent>();
@@ -348,6 +354,34 @@ void EditorInterface::DrawEntityPropreties()
}
if (m_SelectedEntity.HasComponent<LuaScriptComponent>()) {
std::string icon = ICON_FA_FILE;
if (ImGui::CollapsingHeader((icon + " " + "Lua script").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
auto& component = m_SelectedEntity.GetComponent<LuaScriptComponent>();
std::string path = component.Script;
char pathBuffer[256];
memset(pathBuffer, 0, sizeof(pathBuffer));
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
if (ImGui::InputText("##ScriptPath", pathBuffer, sizeof(pathBuffer)))
{
path = std::string(pathBuffer);
}
ImGui::SameLine();
if (ImGui::Button("Browse"))
{
path = FileDialog::OpenFile(".map");
}
component.Script = path;
ImGui::Separator();
}
}
if (m_SelectedEntity.HasComponent<CameraComponent>()) {
std::string icon = ICON_FA_LIGHTBULB;
@@ -414,12 +448,12 @@ void EditorInterface::DrawEntityPropreties()
ImGui::Separator();
}
}
if (m_SelectedEntity.HasComponent<QuakeMap>())
if (m_SelectedEntity.HasComponent<QuakeMapComponent>())
{
std::string icon = ICON_FA_BROOM ;
if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
auto& component = m_SelectedEntity.GetComponent<QuakeMap>();
auto& component = m_SelectedEntity.GetComponent<QuakeMapComponent>();
std::string path = component.Path;
@@ -446,8 +480,9 @@ void EditorInterface::DrawEntityPropreties()
}
ImGui::PopFont();
ImGui::End();
}
ImGui::End();
}
void EditorInterface::DrawGizmos()
{
@@ -492,7 +527,9 @@ void EditorInterface::EditorInterfaceDrawFiletree(Ref<Directory> dir)
void EditorInterface::DrawFileSystem()
{
Ref<Directory> rootDirectory = FileSystem::GetFileTree();
ImGui::Begin("Tree browser");
if (!rootDirectory)
return;
if(ImGui::Begin("Tree browser"))
{
if (ImGui::BeginPopupContextItem("item context menu"))
{
@@ -518,8 +555,9 @@ void EditorInterface::DrawFileSystem()
ImGui::TreePop();
}
ImGui::End();
}
ImGui::End();
}
@@ -590,9 +628,8 @@ void EditorInterface::DrawFile(Ref<File> file)
void EditorInterface::DrawDirectoryExplorer()
{
ImGui::Begin("File browser");
if(ImGui::Begin("File browser"))
{
// Wrapping.
int width = ImGui::GetWindowWidth();
ImVec2 buttonSize = ImVec2(100, 100);
@@ -610,6 +647,7 @@ void EditorInterface::DrawDirectoryExplorer()
// Increment item per row tracker.
i++;
}
// Exit if no current directory.
if (!m_CurrentDirectory) {
ImGui::EndTable();
@@ -628,8 +666,6 @@ void EditorInterface::DrawDirectoryExplorer()
ImGui::TableNextRow();
i++;
}
}
if (m_CurrentDirectory && m_CurrentDirectory->Files.size() > 0)
{
@@ -644,23 +680,25 @@ void EditorInterface::DrawDirectoryExplorer()
}
}
ImGui::EndTable();
}
// Display directories first.
// Then files.
ImGui::End();
}
ImGui::End();
}
void EditorInterface::DrawLogger()
{
if (ImGui::Begin("Logger"))
{
for (auto l : Logger::GetLogs())
{
ImGui::Text(l.c_str());
}
}
ImGui::End();
}
@@ -699,6 +737,8 @@ void EditorInterface::Overlay()
if (m_ShowOverlay && ImGui::MenuItem("Close")) m_ShowOverlay = false;
ImGui::EndPopup();
}
}
ImGui::End();
}
@@ -708,7 +748,7 @@ void EditorInterface::DrawRessourceWindow()
{
std::map<std::string, Ref<Material>> materials = MaterialManager::Get()->GetAllMaterials();
ImGui::Begin("Materials");
if(ImGui::Begin("Materials"))
{
int width = ImGui::GetWindowWidth();
ImVec2 buttonSize = ImVec2(100, 100);
@@ -743,10 +783,10 @@ void EditorInterface::DrawRessourceWindow()
}
}
ImGui::End();
}
ImGui::Begin("Material property");
ImGui::End();
if(ImGui::Begin("Material property"))
{
if (m_IsMaterialSelected)
{
@@ -832,50 +872,132 @@ void EditorInterface::DrawRessourceWindow()
ImGui::Text("No material selected.");
}
ImGui::End();
}
ImGui::End();
}
void NewProject()
{
if (Engine::GetProject())
Engine::GetProject()->Save();
// Parse the project and load it.
std::string selectedProject = FileDialog::SaveFile(".project") + ".project";
Ref<Project> project = Project::New("Unnamed project", "no description", selectedProject);
project->FullPath = selectedProject;
Engine::LoadProject(project);
Ref<Scene> scene = Scene::New();
Engine::LoadScene(scene);
}
void OpenProject()
{
// Parse the project and load it.
std::string projectPath = FileDialog::OpenFile(".project");
FileSystem::SetRootDirectory(projectPath + "/../");
Ref<Project> project = Project::New();
if (!project->Deserialize(FileSystem::ReadFile(projectPath, true)))
{
Logger::Log("Error loading project: " + projectPath);
return;
}
project->FullPath = projectPath;
Engine::LoadProject(project);
}
void OpenScene()
{
}
void EditorInterface::DrawInit()
{
}
void EditorInterface::Draw()
{
Init();
auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize;
if (ImGui::BeginPopupModal("Welcome", NULL, flags))
{
ImGui::Text("Welcome to");
ImGui::Text("Nuake engine");
ImGui::Text("Would you like to");
if (ImGui::Button("Start a new project"))
NewProject();
ImGui::SameLine();
if (ImGui::Button("Open a project"))
OpenProject();
ImGui::EndPopup();
}
if (!Engine::GetProject())
{
ImGui::OpenPopup("Welcome");
}
if (ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("New project", "CTRL+N"))
{
if(Engine::GetProject())
Engine::GetProject()->Save();
NewProject();
// Parse the project and load it.
std::string selectedProject = FileDialog::SaveFile(".project") + ".project";
Ref<Project> project = Project::New("Unnamed project", "no description", selectedProject);
Engine::LoadProject(project);
Ref<Scene> scene = Scene::New();
Engine::LoadScene(scene);
m_IsEntitySelected = false;
}
if (ImGui::MenuItem("Open...", "CTRL+O"))
{
// Parse the project and load it.
std::string selectedProject = FileDialog::OpenFile(".project");
Ref<Project> project = Project::Load(selectedProject);
Engine::LoadProject(project);
OpenProject();
m_IsEntitySelected = false;
}
if (ImGui::MenuItem("Save", "CTRL+S"))
{
Engine::GetProject()->Save();
Engine::GetCurrentScene()->Save();
m_IsEntitySelected = false;
}
if (ImGui::MenuItem("Save as...", "CTRL+SHIFT+S"))
{
std::string savePath = FileDialog::SaveFile("*.project");
Engine::GetProject()->SaveAs(savePath);
m_IsEntitySelected = false;
}
ImGui::Separator();
if (ImGui::MenuItem("Open scene...", "CTRL+O"))
{
OpenScene();
m_IsEntitySelected = false;
}
if (ImGui::MenuItem("Save scene", "CTRL+S"))
{
Engine::GetCurrentScene()->Save();
m_IsEntitySelected = false;
}
if (ImGui::MenuItem("Save scene as...", "CTRL+SHIFT+S"))
{
std::string savePath = FileDialog::SaveFile("*.scene");
Engine::GetCurrentScene()->SaveAs(savePath);
m_IsEntitySelected = false;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit"))
@@ -927,7 +1049,7 @@ void EditorInterface::Draw()
if (ImGui::MenuItem("Trenchbroom map"))
{
auto ent = Engine::GetCurrentScene()->CreateEntity("Trenchbroom map");
ent.AddComponent<QuakeMap>();
ent.AddComponent<QuakeMapComponent>();
}
if (ImGui::MenuItem("Mesh")) {
auto ent = Engine::GetCurrentScene()->CreateEntity("Mesh");
@@ -956,17 +1078,17 @@ void EditorInterface::Draw()
DrawGizmos();
DrawRessourceWindow();
DrawViewport();
DrawSceneTree();
DrawFileSystem();
DrawDirectoryExplorer();
DrawEntityPropreties();
DrawRessourceWindow();
DrawViewport();
DrawSceneTree();
DrawFileSystem();
DrawDirectoryExplorer();
DrawEntityPropreties();
DrawLogger();
if(m_ShowImGuiDemo)
ImGui::ShowDemoWindow();
ImGui::Begin("Physics");
if(ImGui::Begin("Toolbar"))
{
if (ImGui::Button(ICON_FA_HAND_POINTER))
CurrentOperation = ImGuizmo::OPERATION::TRANSLATE;
@@ -990,8 +1112,9 @@ void EditorInterface::Draw()
Engine::ExitPlayMode();
}
ImGui::End();
}
ImGui::End();
}

View File

@@ -33,10 +33,12 @@ public:
void DrawGizmos();
void DrawFileSystem();
void DrawDirectoryExplorer();
void DrawLogger();
void DrawDirectory(Ref<Directory> directory);
bool EntityContainsItself(Entity ent1, Entity ent2);
void DrawFile(Ref<File> file);
void DrawRessourceWindow();
void DrawInit();
void EditorInterfaceDrawFiletree(Ref<Directory> dir);
void Overlay();
};

View File

@@ -2,6 +2,12 @@
#include "src/Core/Physics/PhysicsManager.h"
#include <GLFW/glfw3.h>
#include "src/Core/FileSystem.h"
#include "src/Scripting/ScriptingEngine.h"
#include "../Rendering/Renderer.h"
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_impl_opengl3.h>
float Engine::m_LastFrameTime = 0.0f;
Ref<Window> Engine::CurrentWindow;
@@ -9,15 +15,21 @@ bool Engine::IsPlayMode = false;
Ref<Project> Engine::CurrentProject;
#include "../Rendering/Renderer.h"
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_impl_opengl3.h>
void Engine::Init()
{
Logger::Log("Engine initialization...");
PhysicsManager::Get()->Init();
FileSystem::Scan();
Logger::Log("Physics initialized");
ScriptingEngine::Init();
Logger::Log("Scripting engine initialized");
CurrentWindow = std::make_shared<Window>();
Logger::Log("Window initialized");
Logger::Log("Engine initialized succesfully...");
}
void Engine::Tick()
@@ -73,6 +85,7 @@ void Engine::Run()
void Engine::Close()
{
ScriptingEngine::Close();
glfwTerminate();
}
@@ -95,10 +108,8 @@ Ref<Project> Engine::GetProject()
bool Engine::LoadProject(Ref<Project> project)
{
CurrentProject = project;
Ref<Scene> newScene = CreateRef<Scene>();
Engine::LoadScene(newScene);
Engine::LoadScene(CurrentProject->DefaultScene);
FileSystem::SetRootDirectory(project->FullPath + "/../");
return true;
}

View File

@@ -3,6 +3,8 @@
#include "src/Window.h"
#include "src/Scene/Scene.h"
#include "src/Resource/Project.h"
#include "src/Scripting/ScriptLoader.h"
#include "src/Core/Logger.h"
class Engine {
private:
@@ -30,4 +32,4 @@ public:
static Ref<Project> GetProject();
static bool LoadProject(Ref<Project> project);
};
};

View File

@@ -1,5 +1,5 @@
#include "FileSystem.h"
#include <filesystem>
#include "../../Engine.h"
#define GLFW_EXPOSE_NATIVE_WIN32
@@ -10,6 +10,8 @@
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;
std::string FileDialog::OpenFile(const char* filter)
{
@@ -50,9 +52,10 @@ std::string FileDialog::SaveFile(const char* filter)
return std::string();
}
std::string FileSystem::Root = "resources\\";
std::string FileSystem::Root = "";
Ref<Directory> FileSystem::RootDirectory;
void FileSystem::ScanDirectory(Ref<Directory> directory)
{
for (const auto& entry : std::filesystem::directory_iterator(directory->fullPath))
@@ -79,10 +82,18 @@ void FileSystem::ScanDirectory(Ref<Directory> directory)
}
}
}
bool FileSystem::DirectoryExists(const std::string path)
{
return false;
}
void FileSystem::SetRootDirectory(const std::string path)
{
Root = path;
Scan();
}
void FileSystem::Scan()
{
RootDirectory = CreateRef<Directory>();
@@ -93,6 +104,35 @@ void FileSystem::Scan()
ScanDirectory(RootDirectory);
}
std::string FileSystem::AbsoluteToRelative(const std::string& path)
{
const fs::path rootPath(Root);
const fs::path absolutePath(path);
return fs::relative(absolutePath, rootPath).generic_string();
}
std::string FileSystem::ReadFile(const std::string& path, bool absolute)
{
std::string finalPath = path;
if (!absolute)
finalPath = Root + path;
std::ifstream MyReadFile(finalPath);
std::string fileContent = "";
std::string allFile = "";
// Use a while loop together with the getline() function to read the file line by line
while (getline(MyReadFile, fileContent))
{
allFile.append(fileContent);
}
// Close the file
MyReadFile.close();
return allFile;
}
Ref<Directory> FileSystem::GetFileTree()
{
return RootDirectory;

View File

@@ -3,7 +3,7 @@
#include <filesystem>
#include "Core.h"
class __declspec(dllexport) FileDialog
class FileDialog
{
public:
static std::string OpenFile(const char* filter);
@@ -36,7 +36,10 @@ public:
static Ref<Directory> RootDirectory;
static void SetRootDirectory(const std::string path);
static void Scan();
static std::string AbsoluteToRelative(const std::string& path);
static Ref<Directory> GetFileTree();
static void ScanDirectory(Ref<Directory> directory);
static void GetDirectories();
@@ -44,5 +47,8 @@ public:
static bool DirectoryExists(const std::string path);
static bool FileExists(const std::string path);
static std::string ReadFile(const std::string& path, bool absolute = false);
};

View File

@@ -2,7 +2,7 @@
#include <utility>
class __declspec(dllexport) Input
class Input
{
public:
static bool IsKeyPressed(int keycode);

View File

@@ -5,7 +5,7 @@
class Material;
class __declspec(dllexport) MaterialManager {
class MaterialManager {
private:
static Ref<MaterialManager> s_Instance;

View File

@@ -11,9 +11,9 @@ void BulletDebugDrawer::drawLine(const btVector3& from, const btVector3& to, con
tc.Rotation = glm::vec3(0.0f);
glBegin(GL_LINES);
glColor3f(color.x(), color.y(), color.z());
glVertex3f(from.x(), from.y(), from.z());
glVertex3f(to.x(), to.y(), to.z());
glColor3f((float)(color.x()), (float)(color.y()), (float)(color.z()));
glVertex3f((float)(from.x()), (float)(from.y()), (float)(from.z()));
glVertex3f((float)(to.x()), (float)(to.y()), (float)(to.z()));
glEnd();
//Renderer::DrawCube(tc, glm::vec4(color.x(), color.y(), color.z(), 1.0f));

View File

@@ -17,7 +17,7 @@ namespace Physics {
};
class __declspec(dllexport) Box : public PhysicShape {
class Box : public PhysicShape {
private:
glm::vec3 Size;
btCollisionShape* bShape;
@@ -30,7 +30,7 @@ namespace Physics {
btCollisionShape* GetBulletShape() override;
};
class __declspec(dllexport) Sphere : public PhysicShape {
class Sphere : public PhysicShape {
private:
float Radius;
btCollisionShape* bShape;
@@ -43,7 +43,7 @@ namespace Physics {
btCollisionShape* GetBulletShape() override;
};
class __declspec(dllexport) MeshShape : public PhysicShape {
class MeshShape : public PhysicShape {
private:
Ref<Mesh> m_Mesh;
btCollisionShape* bShape;

View File

@@ -4,7 +4,7 @@
#include "../Core/Core.h"
class Texture;
class __declspec(dllexport) TextureManager
class TextureManager
{
private:
static TextureManager* s_Instance;

View File

@@ -1,6 +1,6 @@
#pragma once
class __declspec(dllexport) Timestep {
class Timestep {
public:
Timestep(float time = 0.0f) : m_Time(time) { }
operator float() const { return m_Time; }

View File

@@ -14,6 +14,7 @@ Camera::Camera(CAMERA_TYPE type, glm::vec3 position) {
up = glm::vec3(0.0f, 1.0f, 0.0f);
cameraRight = glm::normalize(glm::cross(up, cameraDirection));
cameraUp = glm::cross(cameraDirection, cameraRight);
cameraFront = cameraDirection;
}
Camera::Camera() {
@@ -77,6 +78,13 @@ json Camera::Serialize()
bool Camera::Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
j = j["CameraInstance"];
this->m_Type = (CAMERA_TYPE)j["m_Type"];
this->AspectRatio = j["AspectRatio"];
this->Fov = j["Fov"];
this->Exposure = j["Exposure"];
this->Speed = j["Speed"];
return false;
}

View File

@@ -31,8 +31,8 @@ private:
float mouseLastY = 0;
public:
glm::vec3 up; // = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraFront; // = glm::vec3(0.0f, 0.0f, 1.0f);
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, 1.0f);
glm::vec3 cameraTarget; // = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 cameraDirection; // = glm::normalize(Translation - cameraTarget);

View File

@@ -1,7 +1,7 @@
#pragma once
#include "imgui/imgui.h"
__declspec(dllexport) class ImGUI
class ImGUI
{
};

View File

@@ -11,7 +11,7 @@ struct MeshVertex
};
class __declspec(dllexport) Mesh
class Mesh
{
public:
std::vector<Texture> m_Textures;

View File

@@ -7,14 +7,14 @@
class Camera;
class ProceduralSky : ISerializable {
public:
float SurfaceRadius = 6360e3;
float AtmosphereRadius = 6380e3;
glm::vec3 RayleighScattering = glm::vec3(58e-7, 135e-7, 331e-7);
glm::vec3 MieScattering = glm::vec3(2e-5);
float SurfaceRadius = 6360e3f;
float AtmosphereRadius = 6380e3f;
glm::vec3 RayleighScattering = glm::vec3(58e-7f, 135e-7f, 331e-7f);
glm::vec3 MieScattering = glm::vec3(2e-5f);
float SunIntensity = 100.0;
glm::vec3 CenterPoint = glm::vec3(0, -SurfaceRadius, 0);
glm::vec3 SunDirection = glm::vec3(0.20000, 0.95917, 0.20000);
glm::vec3 CenterPoint = glm::vec3(0.f, -SurfaceRadius, 0.f);
glm::vec3 SunDirection = glm::vec3(0.20000f, 0.95917f, 0.20000f);
unsigned int VAO;
unsigned int VBO;
ProceduralSky();

View File

@@ -3,7 +3,7 @@
#include "Texture.h"
#include <glm\ext\vector_float3.hpp>
#include "../Core/Core.h"
class __declspec(dllexport) Material
class Material
{
private:
std::string m_Name;

View File

@@ -4,7 +4,7 @@
#include "glm/vec2.hpp"
typedef unsigned int GLenum;
class __declspec(dllexport) Texture
class Texture
{
private:
unsigned int m_RendererId;

View File

@@ -3,4 +3,20 @@
class TrenchbroomMap
{
};
};
struct Vec3
{
float x;
float y;
float z;
};
struct Vec4
{
float x;
float y;
float z;
float w;
};

View File

@@ -12,6 +12,4 @@ void CameraComponent::DrawEditor() {
ImGui::SliderFloat("Exposure", &CameraInstance->Exposure, 0.0f, 2.0f, "%.2f", 1.0f);
ImGui::SliderFloat("FOV", &CameraInstance->Fov, 1.0f, 180.0f, "%.2f", 1.0f);
ImGui::SliderFloat("Speed", &CameraInstance->Speed, 0.1f, 5.0f, "%.2f", 1.0f);
}

View File

@@ -17,4 +17,11 @@ public:
SERIALIZE_OBJECT(CameraInstance);
END_SERIALIZE();
}
bool Deserialize(std::string str)
{
CameraInstance = CreateRef<Camera>();
return CameraInstance->Deserialize(str);
}
};

View File

@@ -4,7 +4,7 @@
#include "TransformComponent.h"
#include "../Rendering/Camera.h"
#include "../../../Rendering/Framebuffer.h"
#include "BaseComponent.h";
#include "BaseComponent.h"
#include "../Resource/Serializable.h"
enum LightType {
@@ -214,4 +214,9 @@ public:
SERIALIZE_VAL(CastShadows);
END_SERIALIZE();
}
bool Deserialize(std::string str)
{
return true;
}
};

View File

@@ -1,7 +1,7 @@
#pragma once
#include "../../../Rendering/Textures/Material.h"
#include <glm\ext\matrix_float4x4.hpp>
#include "BaseComponent.h";
#include "BaseComponent.h"
class MeshComponent {

View File

@@ -6,7 +6,7 @@
#include "assimp/Importer.hpp"
#include <assimp/scene.h>
#include <assimp/postprocess.h>
class __declspec(dllexport) ModelComponent
class ModelComponent
{
public:
ModelComponent()

View File

@@ -11,4 +11,11 @@ public:
SERIALIZE_VAL(Name);
END_SERIALIZE();
}
bool Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
Name = j["Name"];
return true;
}
};

View File

@@ -16,4 +16,10 @@ struct ParentComponent
SERIALIZE_VAL_LBL("Parent", Parent.GetHandle());
END_SERIALIZE();
}
bool Deserialize(std::string str)
{
return true;
}
};

View File

@@ -8,7 +8,7 @@ extern "C" {
#include <libmap/h/surface_gatherer.h>
}
void QuakeMap::Draw()
void QuakeMapComponent::Draw()
{
for (auto m : m_Meshes) {
m->Draw();
@@ -17,7 +17,7 @@ void QuakeMap::Draw()
void QuakeMap::Load(std::string path, bool collisions)
void QuakeMapComponent::Load(std::string path, bool collisions)
{
if (Path == path)
return;
@@ -27,7 +27,7 @@ void QuakeMap::Load(std::string path, bool collisions)
Build();
}
void QuakeMap::Build()
void QuakeMapComponent::Build()
{
m_Meshes.clear();
map_parser_load(Path.c_str());
@@ -125,7 +125,7 @@ void QuakeMap::Build()
}
}
}
void QuakeMap::DrawEditor()
void QuakeMapComponent::DrawEditor()
{
}

View File

@@ -5,7 +5,7 @@
#include "../Resource/TrenchbroomMap.h"
#include "../Resource/Serializable.h"
class QuakeMap {
class QuakeMapComponent {
private:
@@ -27,4 +27,12 @@ public:
SERIALIZE_VAL(Path);
END_SERIALIZE();
}
bool Deserialize(std::string str)
{
BEGIN_DESERIALIZE();
this->Path = j["Path"];
return true;
}
};

View File

@@ -1,14 +1,14 @@
#pragma once
#include "TransformComponent.h"
#include "BaseComponent.h";
#include "BaseComponent.h"
#include "../Core/Core.h"
namespace Physics{
class RigidBody;
};
class __declspec(dllexport) RigidBodyComponent
class RigidBodyComponent
{
public:
float mass = 0.0f;

View File

@@ -1,7 +1,8 @@
#pragma once
#include <glm\ext\matrix_float4x4.hpp>
#include "BaseComponent.h";
#include "BaseComponent.h"
#include "../Resource/Serializable.h"
class TransformComponent {
public:
glm::vec3 Translation;
@@ -22,4 +23,14 @@ public:
SERIALIZE_VEC3(Scale);
END_SERIALIZE();
}
bool Deserialize(std::string str)
{
BEGIN_DESERIALIZE();
this->Translation = glm::vec3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]);
this->Rotation = glm::vec3(j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]);
this->Scale = glm::vec3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]);
return true;
}
};

View File

@@ -7,6 +7,7 @@
#include "Components/CameraComponent.h"
#include "Components/QuakeMap.h"
#include "Components/LightComponent.h"
#include "Components/QuakeMap.h"
void Entity::AddChild(Entity ent)
{
if ((int)m_EntityHandle != ent.GetHandle())
@@ -26,8 +27,8 @@ json Entity::Serialize()
SERIALIZE_OBJECT_REF_LBL("TransformComponent", GetComponent<TransformComponent>());
if(HasComponent<CameraComponent>())
SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent<CameraComponent>());
if(HasComponent<QuakeMap>())
SERIALIZE_OBJECT_REF_LBL("QuakemapComponent", GetComponent<QuakeMap>());
if(HasComponent<QuakeMapComponent>())
SERIALIZE_OBJECT_REF_LBL("QuakeMapComponent", GetComponent<QuakeMapComponent>());
if (HasComponent<LightComponent>())
SERIALIZE_OBJECT_REF_LBL("LightComponent", GetComponent<LightComponent>());
END_SERIALIZE();
@@ -35,7 +36,14 @@ json Entity::Serialize()
bool Entity::Deserialize(const std::string& str)
{
return false;
BEGIN_DESERIALIZE();
DESERIALIZE_COMPONENT(TransformComponent);
DESERIALIZE_COMPONENT(NameComponent);
DESERIALIZE_COMPONENT(ParentComponent);
DESERIALIZE_COMPONENT(CameraComponent);
DESERIALIZE_COMPONENT(QuakeMapComponent);
DESERIALIZE_COMPONENT(LightComponent);
return true;
}
Entity::Entity(entt::entity handle, Scene* scene)

View File

@@ -5,7 +5,7 @@
#include "Components/BaseComponent.h"
#include "../Resource/Serializable.h"
class __declspec(dllexport) Entity : public ISerializable
class Entity : public ISerializable
{
public:
Entity(entt::entity handle, Scene* scene);

View File

@@ -7,17 +7,9 @@
class ScriptableEntity
{
public:
template<typename T>
T& GetComponent()
{
return m_Entity.GetComponent<T>();
}
virtual void OnCreate() {}
virtual void OnDestroy() {}
virtual void OnUpdate(Timestep ts){}
Entity m_Entity;
friend class Scene;
};

View File

@@ -10,7 +10,7 @@
#include "Entities/Components/BoxCollider.h"
#include "../../Engine.h"
#include "../Core/FileSystem.h"
#include "../Scene/Entities/Components/LuaScriptComponent.h"
#include <fstream>
#include <streambuf>
@@ -21,9 +21,6 @@ Ref<Scene> Scene::New()
Scene::Scene()
{
auto camEntity = CreateEntity("Camera");
camEntity.AddComponent<CameraComponent>().transformComponent = &camEntity.GetComponent<TransformComponent>();
m_EditorCamera = CreateRef<EditorCamera>();
m_Environement = CreateRef<Environment>();
}
@@ -82,10 +79,10 @@ void Scene::OnInit()
PhysicsManager::Get()->RegisterCharacterController(cc.CharacterController);
}
auto quakeMapview = m_Registry.view<TransformComponent, QuakeMap>();
auto quakeMapview = m_Registry.view<TransformComponent, QuakeMapComponent>();
for (auto e : quakeMapview)
{
auto [transform, quake] = quakeMapview.get<TransformComponent, QuakeMap>(e);
auto [transform, quake] = quakeMapview.get<TransformComponent, QuakeMapComponent>(e);
if (quake.HasCollisions)
{
@@ -100,14 +97,9 @@ void Scene::OnInit()
// Instanciate scripts.
{
m_Registry.view<NativeScriptComponent>().each([=](auto entity, auto& nsc)
m_Registry.view<LuaScriptComponent>().each([=](auto entity, auto& nsc)
{
if (!nsc.Instance)
{
nsc.Instance = nsc.InstantiateScript();
nsc.Instance->m_Entity = Entity{ entity, this };
}
nsc.Instance->OnCreate();
});
}
}
@@ -163,7 +155,7 @@ void Scene::DrawShadows()
{
auto modelView = m_Registry.view<TransformComponent, ModelComponent>();
auto quakeView = m_Registry.view<TransformComponent, QuakeMap>();
auto quakeView = m_Registry.view<TransformComponent, QuakeMapComponent>();
auto view = m_Registry.view<TransformComponent, LightComponent>();
Ref<Camera> cam = nullptr;
@@ -202,7 +194,7 @@ void Scene::DrawShadows()
}
for (auto e : quakeView) {
auto [transform, model] = quakeView.get<TransformComponent, QuakeMap>(e);
auto [transform, model] = quakeView.get<TransformComponent, QuakeMapComponent>(e);
glm::vec3 pos = lightTransform.Translation;
glm::mat4 lightView = glm::lookAt(pos, pos - light.GetDirection(), glm::vec3(0.0f, 1.0f, 0.0f));
@@ -317,9 +309,9 @@ void Scene::Draw()
model.Draw();
}
auto quakeView = m_Registry.view<TransformComponent, QuakeMap, ParentComponent>();
auto quakeView = m_Registry.view<TransformComponent, QuakeMapComponent, ParentComponent>();
for (auto e : quakeView) {
auto [transform, model, parent] = quakeView.get<TransformComponent, QuakeMap, ParentComponent>(e);
auto [transform, model, parent] = quakeView.get<TransformComponent, QuakeMapComponent, ParentComponent>(e);
TransformComponent copyT = transform;
if (parent.HasParent)
@@ -395,9 +387,6 @@ void Scene::EditorDraw()
{
Renderer::m_Shader->SetUniform1f("u_Exposure", m_EditorCamera->Exposure);
auto view = m_Registry.view<TransformComponent, ModelComponent, ParentComponent>();
for (auto e : view) {
auto [transform, model, parent] = view.get<TransformComponent, ModelComponent, ParentComponent>(e);
@@ -423,9 +412,9 @@ void Scene::EditorDraw()
model.Draw();
}
auto quakeView = m_Registry.view<TransformComponent, QuakeMap, ParentComponent>();
auto quakeView = m_Registry.view<TransformComponent, QuakeMapComponent, ParentComponent>();
for (auto e : quakeView) {
auto [transform, model, parent] = quakeView.get<TransformComponent, QuakeMap, ParentComponent>(e);
auto [transform, model, parent] = quakeView.get<TransformComponent, QuakeMapComponent, ParentComponent>(e);
TransformComponent copyT = transform;
@@ -511,7 +500,7 @@ void Scene::EditorDraw()
std::vector<Entity> Scene::GetAllEntities() {
std::vector<Entity> allEntities;
auto view = m_Registry.view<TransformComponent, NameComponent>();
auto view = m_Registry.view<NameComponent>();
for (auto e : view) {
allEntities.push_back(Entity(e, this));
}
@@ -543,6 +532,11 @@ Entity Scene::GetEntity(const std::string& name)
}
}
Entity Scene::CreateEmptyEntity(const std::string& name) {
Entity entity = { m_Registry.create(), this };
return entity;
}
Entity Scene::CreateEntity(const std::string& name) {
Entity entity = { m_Registry.create(), this };
@@ -554,8 +548,7 @@ Entity Scene::CreateEntity(const std::string& name) {
ParentComponent& parentComponent = entity.AddComponent<ParentComponent>();
std::string str = "Created entity: " + nameComponent.Name + "\n";
printf(str.c_str());
Logger::Log("Created entity: " + nameComponent.Name + "\n");
return entity;
}
@@ -590,7 +583,7 @@ Ref<Environment> Scene::GetEnvironment() {
bool Scene::Save()
{
if (Path == "")
Path = FileDialog::SaveFile("*.scene") + ".scene";
Path = FileSystem::AbsoluteToRelative(FileDialog::SaveFile("*.scene") + ".scene");
return SaveAs(Path);
}
@@ -598,9 +591,11 @@ bool Scene::Save()
bool Scene::SaveAs(const std::string& path)
{
std::ofstream sceneFile;
sceneFile.open(path);
sceneFile.open(FileSystem::Root + path);
sceneFile << Serialize().dump(4);
sceneFile.close();
Logger::Log("Scene saved successfully");
return true;
}
@@ -620,5 +615,34 @@ json Scene::Serialize()
bool Scene::Deserialize(const std::string& str)
{
return false;
if (str == "")
return false;
BEGIN_DESERIALIZE();
if (!j.contains("Name"))
return false;
Name = j["Name"];
m_Environement = CreateRef<Environment>();
if (j.contains("m_Environement"))
{
m_Environement = CreateRef<Environment>();
std::string env = j["m_Environement"].dump();
m_Environement->Deserialize(env);
}
// Parse entities
{
if (j.contains("Entities"))
{
for (json e : j["Entities"])
{
std::string name = e["NameComponent"]["Name"];
Entity ent = CreateEmptyEntity(name);
ent.Deserialize(e.dump());
}
}
}
return true;
}

View File

@@ -20,9 +20,10 @@ private:
entt::registry m_Registry;
Ref<EditorCamera> m_EditorCamera;
std::string Name;
std::string Path = "";
bool has_changed = true;
public:
std::string Path = "";
static Ref<Scene> New();
Scene();
~Scene();
@@ -45,6 +46,7 @@ public:
std::vector<Entity> GetAllEntities();
glm::vec3 GetGlobalPosition(Entity ent);
Entity GetEntity(const std::string& name);
Entity CreateEmptyEntity(const std::string& name);
Entity CreateEntity(const std::string& name);
void DestroyEntity(Entity entity);

View File

@@ -4,7 +4,7 @@
#include "Scene/Scene.h"
#include "Core/Core.h"
struct GLFWwindow;
class __declspec(dllexport) Window
class Window
{
private:
static Window* s_Instance;
@@ -22,8 +22,6 @@ public:
static Window* Get();
GLFWwindow* GetHandle();
int Init();
void Update(Timestep ts);
void Draw();

View File

@@ -9,6 +9,33 @@ workspace "Nuake"
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
project "DemoModule"
location "DemoModule"
kind "SharedLib"
language "C++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
filter "system:windows"
cppdialect "C++17"
includedirs
{
"%{prj.name}/../Nuake",
"%{prj.name}/../Nuake/src/Vendors",
"%{prj.name}/../Nuake/Dependencies/GLEW/include",
"%{prj.name}/../Nuake/Dependencies/GLFW/x64/include",
"%{prj.name}/../Nuake/Dependencies/bullet/src",
"%{prj.name}/../Nuake/Dependencies/assimp/include"
}
files
{
"%{prj.name}/**.h",
"%{prj.name}/**.cpp"
}
project "Nuake"
location "Nuake"
kind "StaticLib"
@@ -37,11 +64,12 @@ project "Nuake"
includedirs
{
"%{prj.name}/src/Vendors",
"%{prj.name}/Dependencies/GLEW/include",
"%{prj.name}/Dependencies/GLFW/x64/include",
"%{prj.name}/Dependencies/bullet/src",
"%{prj.name}/Dependencies/assimp/include"
"%{prj.name}/../Nuake",
"%{prj.name}/../Nuake/src/Vendors",
"%{prj.name}/../Nuake/Dependencies/GLEW/include",
"%{prj.name}/../Nuake/Dependencies/GLFW/x64/include",
"%{prj.name}/../Nuake/Dependencies/bullet/src",
"%{prj.name}/../Nuake/Dependencies/assimp/include"
}
filter "system:windows"