Skip to content

Commit

Permalink
moved imgui to different folder
Browse files Browse the repository at this point in the history
and other things i forgot
  • Loading branch information
tkpmonke committed Aug 4, 2024
1 parent 7881186 commit 41cea90
Show file tree
Hide file tree
Showing 34 changed files with 75 additions and 23 deletions.
10 changes: 5 additions & 5 deletions bin/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Collapsed=0

[Window][Debug Menu]
Pos=211,19
Size=206,1061
Size=272,1061
Collapsed=0
DockId=0x00000006,0

Expand Down Expand Up @@ -52,10 +52,10 @@ DockId=0x00000005,0

[Docking][Data]
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=0,19 Size=1920,1061 Split=X
DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=417,1061 Split=X Selected=0x82A4B83C
DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=483,1061 Split=X Selected=0x82A4B83C
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=209,1061 Selected=0x82A4B83C
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=206,1061 Selected=0xA0FC9443
DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=1501,1061 Split=X
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=1129,1061 CentralNode=1 Selected=0xE87781F4
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=272,1061 Selected=0xA0FC9443
DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=1435,1061 Split=X
DockNode ID=0x00000001 Parent=0x00000004 SizeRef=1063,1061 CentralNode=1 Selected=0xE87781F4
DockNode ID=0x00000002 Parent=0x00000004 SizeRef=370,1061 Selected=0xE7039252

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions include/ignition/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Ignition {

Camera() = default;
Camera(Window* window) { this->window = window; }
Matrix4 viewProj;
private:
Window* window;
};
Expand Down
2 changes: 1 addition & 1 deletion include/ignition/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ namespace Ignition {
virtual std::string type() const = 0;

bool enabled;
std::shared_ptr<Transform> transform;
Transform* transform;
};
}
2 changes: 1 addition & 1 deletion include/ignition/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define UPDATE_OBJECT() this->transform.UpdateVectors(); \
for (std::shared_ptr<Module> m : modules) { \
m->transform = std::make_shared<Transform>(this->transform); \
m->transform = &this->transform;\
m->Update(); \
}

Expand Down
2 changes: 2 additions & 0 deletions include/ignition/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Ignition {
void WriteSceneToDisk();
void ReadSceneFromDisk();

std::string name;

private:
std::vector<Object> objects;
};
Expand Down
12 changes: 9 additions & 3 deletions include/ignition/serialization/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "input/camera_movement.hpp"

#include <iostream>
#include <filesystem>

bool preferencesChanged;
Implosion::GUI* gui;
Expand All @@ -10,7 +11,11 @@ void PreferencesChanged() { preferencesChanged = true; }

void WritePreferences()
{
FS::BeginBinaryWrite(FS::GetHome() + "/Ignition/preferences");
if (!std::filesystem::exists(FS::GetHome() + "/Implosion"))
{
std::filesystem::create_directory(FS::GetHome() + "/Implosion");
}
FS::BeginBinaryWrite(FS::GetHome() + "/Implosion/preferences");

FS::Write8(gui->vsync);
FS::Write8(gui->anti);
Expand Down Expand Up @@ -43,7 +48,9 @@ void WritePreferences()

void ReadPreferences(Implosion::GUI* guis)
{
FS::BeginBinaryRead(FS::GetHome() + "/Ignition/preferences");
gui = guis;
if (!FS::BeginBinaryRead(FS::GetHome() + "/Implosion/preferences"))
return;

if (!FS::CanRead())
return;
Expand Down Expand Up @@ -71,5 +78,4 @@ void ReadPreferences(Implosion::GUI* guis)
guis->camera->fov = FS::ReadFloat();

FS::EndBinaryRead();
gui = guis;
}
5 changes: 4 additions & 1 deletion include/ignition/utils/files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ namespace FS {

std::string GetHome();

void SetProjectHome(std::string);
std::string GetProjectHome();

std::string ReadTextFile(std::string path);
std::string ReadFileFromHome(std::string path);

void WriteFile(std::string path, std::string data);
void WriteFileFromHome(std::string path, std::string data);

void BeginBinaryRead(std::string path);
bool BeginBinaryRead(std::string path);
void BeginBinaryWrite(std::string path);

uint8_t Read8();
Expand Down
4 changes: 3 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ project "implosion"
language "C++"
cppdialect "gnu++17"
targetdir "bin"
includedirs { "include/ignition", "include/ignition/components", "include/implosion", "include/implosion/imgui" }
removefiles "hub/*"
includedirs { "include/ignition", "include/ignition/components", "include/implosion", "imgui" }
files { "**.h", "**.cpp", "**.hpp" }

links { "glfw", "GL", "GLEW", "m" }

filter "configurations:Debug"
defines { "DEBUG" }
optimize "On"
symbols "On"

filter "configurations:Release"
Expand Down
1 change: 1 addition & 0 deletions src/ignition/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ namespace Ignition {
glfwSwapBuffers((GLFWwindow*)*this->window);
Rendering::currentProgram = 9999;
Rendering::currentVao = 9999;
viewProj = Matrix4(0);
}
}
14 changes: 9 additions & 5 deletions src/ignition/components/rendering/meshrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,25 @@ namespace Ignition::Rendering {
if (this->shader.program != currentProgram) {
glUseProgram(this->shader.program);
currentProgram = this->shader.program;


if (camera->viewProj == Matrix4(0)) {
camera->viewProj = camera->view_projection();
}

this->shader.SetMatrix4(camera->view_projection(), "projection");
this->shader.SetMatrix4(camera->viewProj, "projection");
}
if (this->vao != currentVao) {
glBindVertexArray(this->vao);
currentVao = this->vao;
}


Matrix4 model = Matrix4(1.f);
model = glm::translate(model, this->transform->position);
Matrix4 model;

model = glm::translate(Matrix4(1.f), this->transform->position);
model *= glm::mat4_cast(glm::quat(glm::radians(this->transform->rotation)));
model = glm::scale(model, this->transform->scale);

this->shader.SetMatrix4(model, "model");
glActiveTexture(GL_TEXTURE0 );
glBindTexture(GL_TEXTURE_2D, this->shader.albedo);
Expand Down
2 changes: 1 addition & 1 deletion src/ignition/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Ignition {
void Object::AddModule(std::shared_ptr<Module> mod)
{
this->modules.push_back(mod);
mod->transform = std::make_shared<Transform>(this->transform);
//mod->transform = std::make_shared<Transform>(this->transform);
mod->Start();
}

Expand Down
7 changes: 7 additions & 0 deletions src/ignition/scene.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "scene.hpp"
#include "utils/files.hpp"

namespace Ignition {

void Scene::Update()
{
for (int i = 0; i < objects.size(); ++i)
Expand Down Expand Up @@ -36,5 +38,10 @@ namespace Ignition {
return objects.size()-1;
}

void Scene::WriteSceneToDisk()
{
FS::BeginBinaryWrite(FS::GetProjectHome() + "");
}

Scene scene;
}
15 changes: 14 additions & 1 deletion src/ignition/utils/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
#endif

namespace FS {

std::string projectName;
void SetProjectHome(std::string s)
{
projectName = s;
}
std::string GetProjectHome() { return projectName; }

std::string ReadTextFile(std::string path)
{
std::ifstream f(path);
Expand Down Expand Up @@ -56,14 +64,19 @@ namespace FS {
std::string path;
} write;

void BeginBinaryRead(std::string path)
bool BeginBinaryRead(std::string path)
{
read.file = std::ifstream(path);

if (!read.file.is_open())
return false;

std::stringstream s;
s << read.file.rdbuf();
read.data = s.str();
read.size = read.data.size();
read.i = -1;
return true;
}
void BeginBinaryWrite(std::string path)
{
Expand Down
11 changes: 8 additions & 3 deletions src/implosion/gui/gui_addobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ namespace Implosion {
glUseProgram(m.shader.program);
std::shared_ptr<MeshRenderer> ptr = std::make_shared<MeshRenderer>(m);
Ignition::Object* o = &Ignition::scene.GetObjects()->at(Ignition::scene.CreateObject());
int x = -10 + rand() % 20;
int y = -10 + rand() % 20;
int z = -10 + rand() % 20;
int x = -50 + rand() % 100;
int y = -50 + rand() % 100;
int z = -50 + rand() % 100;

int rx = -180 + rand() % 360;
int ry = -180 + rand() % 360;
int rz = -180 + rand() % 360;
o->AddModule(ptr);
o->transform.position = Ignition::Vector3(x,y,z);
o->transform.rotation = Ignition::Vector3(rx,ry,rz);

}
}
Expand Down
7 changes: 7 additions & 0 deletions src/implosion/gui/gui_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include "scene.hpp"

#ifdef __unix__
# ifdef __linux__
const char* os = "Linux";
Expand Down Expand Up @@ -40,6 +42,11 @@ ImGuiWindowFlags flags = ImGuiWindowFlags_NoBackground;
ImGui::Text("Delta Time %f", dt);
ImGui::Text("FPS %f", fps);

ImGui::Separator();

ImGui::Text("Objects %lu", Ignition::scene.GetObjects()->size());
ImGui::Text("Objects with tag \"Bananna\" %lu", Ignition::scene.GetObjectsWithTag("Banana").size());

if (ImGui::CollapsingHeader("Hardware"))
{
ImGui::SeparatorText("GPU Info");
Expand Down
3 changes: 2 additions & 1 deletion src/implosion/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ int main()

Ignition::scene.Update();
gui.NewFrame();

if (Ignition::scene.GetObjects()->size() > 0)
{
gui.Inspector(&Ignition::scene.GetObjects()->at(0));
Expand All @@ -52,7 +53,7 @@ int main()
gui.EndFrame();
camera.EndRender();
}

WritePreferences();
gui.Shutdown();
window.Shutdown();
}

0 comments on commit 41cea90

Please # to comment.