Skip to content
This repository was archived by the owner on Apr 3, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ project(user-interface)

include(FetchContent)

set(CMAKE_CXX_STANDARD 20)
if(MSVC)
# see https://gitlab.kitware.com/cmake/cmake/-/issues/22606
set(CMAKE_CXX_STANDARD 23)
else()
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

message(STATUS "Looking for lld")
Expand All @@ -23,7 +28,7 @@ if (LOCAL_PIVOT_DIRECTORY STREQUAL "")
FetchContent_Declare(
pivot
GIT_REPOSITORY https://github.com/EIP-Pivot/pivot.git
GIT_TAG v0.1.0-a.2
GIT_TAG c1f3b50a477909dfbdaf800794096d8375089656
)
if (NOT pivot_POPULATED)
message(STATUS "Populating pivot")
Expand Down
41 changes: 7 additions & 34 deletions include/ImGuiCore/ComponentEditor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <pivot/graphics/types/RenderObject.hxx>
#include <pivot/graphics/types/UniformBufferObject.hxx>

#include <pivot/ecs/Core/Component/index.hxx>

#include <iostream>

#include <pivot/ecs/Core/SceneManager.hxx>
Expand All @@ -20,6 +22,8 @@ extern SceneManager gSceneManager;

using ObjectVector = std::vector<std::reference_wrapper<const RenderObject>>;

using namespace pivot::ecs::component;

class ComponentEditor
{
public:
Expand All @@ -29,36 +33,10 @@ public:
void setVectorObject(LevelId scene);
std::unordered_map<LevelId, ObjectVector> &getVectorObject();
ObjectVector getObject();

template <typename T>
void addComponent(Entity entity, T component)
{
if (!gSceneManager.getCurrentLevel().isRegister<T>()) gSceneManager.getCurrentLevel().RegisterComponent<T>();
gSceneManager.getCurrentLevel().AddComponent<T>(entity, component);
}
private:
template <typename T>
void addComponent(T component)
{
if (!gSceneManager.getCurrentLevel().isRegister<T>())
gSceneManager.getCurrentLevel().RegisterComponent<T>();
gSceneManager.getCurrentLevel().AddComponent<T>(currentEntity, component);
}
template <typename T>
void displayComponent(std::string name)
{
if (gSceneManager.getCurrentLevel().hasComponent<T>(currentEntity)) {
if (ImGui::TreeNode(name.c_str())) {
ImGui::TreePop();
createComponent(gSceneManager.getCurrentLevel().GetComponent<T>(currentEntity));
}
}
}

void addComponent(const Description &description);
void displayComponent();
void createPopUp();
void createComponent(RigidBody &rigidBody);
void createComponent(Gravity &gravity);
void createComponent(RenderObject &renderObject);

private :
Entity currentEntity;
Expand All @@ -68,9 +46,4 @@ private :
std::unordered_map<LevelId, ObjectVector> sceneObject;
std::array<std::string, 8> textures = {"rouge", "vert", "bleu", "cyan", "orange", "jaune", "blanc", "violet"};
std::array<std::string, 2> models = {"cube", "plane"};
};

template <>
void ComponentEditor::addComponent(Entity entity, RenderObject renderObject);
template <>
void ComponentEditor::addComponent(RenderObject renderObject);
};
2 changes: 1 addition & 1 deletion include/ImGuiCore/Editor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <ImGuizmo.h>

#include <pivot/ecs/Core/SceneManager.hxx>
#include <pivot/graphics/config.hxx>
#include <pivot/graphics/types/common.hxx>

class Editor
{
Expand Down
3 changes: 3 additions & 0 deletions include/ImGuiCore/EntityModule.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <pivot/ecs/Core/types.hxx>

#include <pivot/ecs/Core/Component/manager.hxx>
#include <pivot/ecs/Core/Component/index.hxx>

class EntityModule
{
public:
Expand Down
22 changes: 4 additions & 18 deletions include/ImGuiCore/SystemsEditor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,18 @@
#include "Systems/PhysicsSystem.hxx"

#include <pivot/ecs/Core/SceneManager.hxx>
#include <pivot/ecs/Core/Systems/index.hxx>

extern SceneManager gSceneManager;

using namespace pivot::ecs::systems;

class SystemsEditor
{
public:
void create();
void addSystem();

template <typename T>
void addSystem()
{
auto system = gSceneManager.getCurrentLevel().RegisterSystem<T>();
gSceneManager.getCurrentLevel().SetSystemSignature<T>(system->getSignature());
system->Init();
}
private:
template <typename T>
void displaySystem(std::string name)
{
if (gSceneManager.getCurrentLevel().hasSystem<T>()) {
if (ImGui::TreeNode(name.c_str())) {
ImGui::TreePop();
}
}
}
void displaySystem();

void createPopUp();
};
44 changes: 44 additions & 0 deletions include/ImGuiCore/TypeTemplate/Template.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <glm/gtc/type_ptr.hpp>
#include <glm/vec3.hpp>
#include <pivot/ecs/Core/Component/description.hxx>
#include <pivot/ecs/Core/Data/value.hxx>

#include <ImGuizmo.h>
#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>

using namespace pivot::ecs::component;
using namespace pivot::ecs::data;

void draw(Value &value, std::string name);
void draw(glm::vec3 &value, std::string name) { ImGui::InputFloat3(name.c_str(), glm::value_ptr(value)); }

void draw(std::string &value, std::string name) { ImGui::InputText(name.c_str(), &value); }

void draw(int &value, std::string name)
{
// ImGui::InputText("Name", &value);
}

void draw(bool &value, std::string name)
{
// ImGui::InputText("Name", &value);
}

void draw(double &value, std::string name)
{
ImGui::InputDouble(name.c_str(), &value);
// ImGui::InputText("Name", &value);
}

void draw(Record &values, std::string name)
{
for (auto &[name, value]: values) draw(value, name);
}

void draw(Value &value, std::string name)
{
std::visit([&name](auto &&arg) { draw(arg, name); }, static_cast<Value::variant &>(value));
}
42 changes: 42 additions & 0 deletions include/ImGuiCore/TypeTemplate/createValue.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <glm/gtc/type_ptr.hpp>
#include <glm/vec3.hpp>
#include <pivot/ecs/Core/Component/description.hxx>
#include <pivot/ecs/Core/Data/value.hxx>

#include <ImGuizmo.h>
#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>

using namespace pivot::ecs::component;
using namespace pivot::ecs::data;

Value createValue(const BasicType &type);
Value createValue(const RecordType &types);

Value createValue(const Type &type)
{
return std::visit([](auto &t) {return createValue(t);}, static_cast<const Type::variant &>(type));
}

Value createValue(const BasicType &type)
{
switch (type) {
case BasicType::String: return Value{""};
case BasicType::Number: return Value{0.0};
case BasicType::Integer: return Value{0};
case BasicType::Boolean: return Value{false};
case BasicType::Vec3: return Value{glm::vec3(0.0f)};
}
throw std::runtime_error("Illegal BasicType value.");
}

Value createValue(const RecordType &types)
{
Record record;
for (auto &[name, type]: types) {
record.insert({name, createValue(type)});
}
return {record};
}
10 changes: 3 additions & 7 deletions include/Systems/PhysicsSystem.hxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#pragma once

#include "pivot/ecs/Core/System.hxx"
#include <pivot/ecs/Core/Systems/description.hxx>

class PhysicsSystem : public System
{
public:
void Update(float dt);
using namespace pivot::ecs;

Signature getSignature();
};
void physicsSystem(const systems::Description &, systems::Description::systemArgs &, const event::Event &);
26 changes: 26 additions & 0 deletions scripts/components.pvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
component Najo
Vector3 position
Number note

component Thomas
String leopard
Number QI

component ZAC
Number PEPETTE
Number QI

component Position
Number pos_x
Number pos_y
Number pos_z

component Velocity
Number vel_x
Number vel_y
Number vel_z

system onTickPhysics(anyEntity<Position, Velocity>)
anyEntity.Position.pos_x = anyEntity.Position.pos_x + anyEntity.Velocity.vel_x
anyEntity.Position.pos_y = anyEntity.Position.pos_y + anyEntity.Velocity.vel_y
anyEntity.Position.pos_z = anyEntity.Position.pos_z + anyEntity.Velocity.vel_z
Loading