Skip to content

Commit 925bb49

Browse files
committed
Events editable inside the editor.
Yet to be tested. Next is JSON serialization/deserialization. Finally work on shadows, demos, docs then release.
1 parent 24dce10 commit 925bb49

10 files changed

Lines changed: 46 additions & 138 deletions

File tree

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Frontend/Controls/EventControl.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <Engine3DRadSpace/Objects/Impl/Objects.hpp>
44
#include <Engine3DRadSpace/Objects/IObject.hpp>
55
#include <Engine3DRadSpace/Reflection/Event.hpp>
6-
#include <Engine3DRadSpace/Projects/EventRepresentation.hpp>
76
#include <Engine3DRadSpace/Reflection/IReflectedFunction.hpp>
87

98
EventControl::EventControl(
@@ -80,6 +79,11 @@ EventControl::EventControl(
8079
nullptr
8180
);
8281

82+
for (auto& invocation : *event)
83+
{
84+
SendMessageA(this->window, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(std::format("Object ID: {}, Function ID: {}", invocation.ObjectID, invocation.FunctionID).c_str()));
85+
}
86+
8387
_cx = 300;
8488
_cy = 400;
8589
}
@@ -88,27 +92,39 @@ void EventControl::HandleClick(HWND clickedWindow)
8892
{
8993
if(clickedWindow == _btnAddCall)
9094
{
95+
if (_findFunction) return;
96+
9197
std::thread openFnFinderWindow([this]()
9298
{
99+
_findFunction = true;
100+
93101
AddFunctionDialog dialog(this->window, this->instance, this->_list);
94-
auto event = dialog.ShowDialog();
102+
auto invocation = dialog.ShowDialog();
95103

96-
if (event.has_value())
104+
if (invocation.has_value())
97105
{
98-
SendMessageA(this->window, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(std::format("Object ID: {}, Function ID: {}", event->OwnerObject, event->FunctionID).c_str()));
99-
100-
auto obj = _list->operator[](event->OwnerObject);
106+
SendMessageA(
107+
this->window,
108+
LB_ADDSTRING,
109+
0,
110+
reinterpret_cast<LPARAM>(std::format("Object ID: {}, Function ID: {}", invocation->OwnerObject, invocation->FunctionID).c_str())
111+
);
112+
113+
auto obj = _list->operator[](invocation->OwnerObject);
101114
auto refl = Engine3DRadSpace::Internal::GetReflDataFromUUID(obj->GetUUID());
102115

103-
for (auto& fnMember : *refl)
104-
{
105-
if (dynamic_cast<Engine3DRadSpace::Reflection::IReflectedFunction*>(fnMember) != nullptr)
106-
{
107-
auto fn = fnMember->Clone().release();
108-
this->_event->Bind(std::unique_ptr<Engine3DRadSpace::Reflection::IReflectedFunction>(dynamic_cast<Engine3DRadSpace::Reflection::IReflectedFunction*>(fn)), event->OwnerObject, event->FunctionID);
109-
}
110-
}
116+
auto fn = invocation->FindFunction(refl, invocation->FunctionID);
117+
118+
this->_event->Bind(
119+
std::move(std::unique_ptr<Engine3DRadSpace::Reflection::IReflectedFunction>(
120+
static_cast<Engine3DRadSpace::Reflection::IReflectedFunction*>(fn->Clone().release())
121+
)),
122+
invocation->OwnerObject,
123+
invocation->FunctionID
124+
);
111125
}
126+
127+
_findFunction = false;
112128
});
113129
openFnFinderWindow.detach();
114130
}

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Frontend/Windows/AddFunctionDialog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <Engine3DRadSpace/Objects/ObjectList.hpp>
55
#include <Engine3DRadSpace/Reflection/ReflectedObject.hpp>
66
#include <Engine3DRadSpace/Reflection/ReflectedMemberFunction.hpp>
7-
#include <Engine3DRadSpace/Projects/EventRepresentation.hpp>
7+
#include <Engine3DRadSpace/Projects/EventInvocationRepresentation.hpp>
88

99
class AddFunctionDialog : public Dialog
1010
{

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Frontend/Windows/EditObjectDialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,9 @@ void EditObjectDialog::setObject()
871871
case FieldRepresentationType::Event:
872872
{
873873
auto eventCtrl = static_cast<EventControl*>(std::get<IControl*>(windows[i++]));
874-
875-
memcpy_s(newStruct.get() + j, sizeof(Event), &eventCtrl->GetEvent(), sizeof(Event));
874+
auto& event = eventCtrl->GetEvent();
875+
876+
new (newStruct.get() + j) Event(std::move(event));
876877
j += sizeof(Event);
877878
break;
878879
}

3DRadSpace/Engine3DRadSpace/Projects/EventInvocationRepresentation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ EventInvocationRepresentation::EventInvocationRepresentation() :
1111
{
1212
}
1313

14-
IReflectedFunction* EventInvocationRepresentation::FindFunction(const Reflection::UUID& uuid, size_t idxFn)
14+
IReflectedFunction* EventInvocationRepresentation::FindFunction(Reflection::ReflectedObject* reflObject, size_t idxFn)
1515
{
16-
auto reflObject = Internal::GetReflDataFromUUID(uuid);
1716
if (reflObject == nullptr) return nullptr;
1817

1918
size_t id = 0;
20-
2119
for (auto& f : *reflObject)
2220
{
2321
auto fn = dynamic_cast<IReflectedFunction*>(f);

3DRadSpace/Engine3DRadSpace/Projects/EventInvocationRepresentation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ namespace Engine3DRadSpace::Projects
2828

2929
EventInvocationRepresentation();
3030

31-
static Reflection::IReflectedFunction* FindFunction(const Reflection::UUID& uuid, size_t idxFn);
31+
static Reflection::IReflectedFunction* FindFunction(Reflection::ReflectedObject* reflObject, size_t idxFn);
3232
};
3333
}

3DRadSpace/Engine3DRadSpace/Projects/EventRepresentation.cpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

3DRadSpace/Engine3DRadSpace/Projects/EventRepresentation.hpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

3DRadSpace/Engine3DRadSpace/Projects/Serialization.cpp

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ json Engine3DRadSpace::Projects::Serializer::SerializeObject(IObject* obj)
307307
}
308308
case FieldRepresentationType::Event:
309309
{
310-
Projects::EventRepresentation e;
311-
jsonField[subFieldName][str_i] = e;
310+
//Projects::EventRepresentation e;
311+
//jsonField[subFieldName][str_i] = e;
312312

313-
offset += sizeof(Event);
313+
//offset += sizeof(Event);
314314
break;
315315
}
316316
case FieldRepresentationType::ObjectID:
@@ -632,12 +632,12 @@ json Engine3DRadSpace::Projects::Serializer::SerializeObject(IObject* obj)
632632
}
633633
case FieldRepresentationType::Event:
634634
{
635-
EventRepresentation eventData = jsonField.get<EventRepresentation>();
636-
Event event = eventData.Reconstruct(uuid).value();
635+
//EventRepresentation eventData = jsonField.get<EventRepresentation>();
636+
//Event event = eventData.Reconstruct(uuid).value();
637637

638-
void* dest = newStruct.get() + offset;
639-
new (dest) Event();
640-
offset += sizeof(Event);
638+
//void* dest = newStruct.get() + offset;
639+
//new (dest) Event();
640+
//offset += sizeof(Event);
641641

642642
break;
643643
}
@@ -749,49 +749,4 @@ bool Engine3DRadSpace::Projects::Serializer::SaveProject(ObjectList* lst, Conten
749749

750750
file << std::setw(4) << j;
751751
return true;
752-
}
753-
754-
void Engine3DRadSpace::Projects::to_json(json& j, const EventRepresentation& event)
755-
{
756-
auto size = event.BoundFunctions.size();
757-
j["numFn"] = size;
758-
759-
for (auto i = 0; i < size; i++)
760-
{
761-
auto& fn = event.BoundFunctions[i];
762-
json jFn;
763-
764-
jFn["OwnerObject"] = fn.OwnerObject;
765-
jFn["FunctionID"] = fn.FunctionID;
766-
767-
json jArgs = json::array();
768-
for (auto& arg : fn.Args)
769-
{
770-
jArgs.push_back(arg.type().name());
771-
}
772-
773-
jFn["Args"] = jArgs;
774-
j["BoundFunctions"].push_back(jFn);
775-
}
776-
}
777-
778-
void Engine3DRadSpace::Projects::from_json(const json& j, EventRepresentation& event)
779-
{
780-
auto size = j["numFn"].get<size_t>();
781-
782-
for (auto i = 0; i < size; i++)
783-
{
784-
auto& jFn = j["BoundFunctions"][i];
785-
EventInvocationRepresentation fn;
786-
787-
fn.OwnerObject = jFn["OwnerObject"].get<size_t>();
788-
fn.FunctionID = jFn["FunctionID"].get<size_t>();
789-
for (auto& jArg : jFn["Args"])
790-
{
791-
std::string typeName = jArg.get<std::string>();
792-
fn.Args.push_back(std::any(typeName));
793-
}
794-
795-
event.BoundFunctions.push_back(fn);
796-
}
797-
}
752+
}

3DRadSpace/Engine3DRadSpace/Projects/Serialization.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22
#include "../Reflection/Reflection.hpp"
33
#include "../Games/Game.hpp"
4-
#include "EventRepresentation.hpp"
54
#include <nlohmann/json.hpp>
65

76
using json = nlohmann::json;
@@ -57,7 +56,4 @@ namespace Engine3DRadSpace::Projects
5756
/// <returns>True if succeded.</returns>
5857
static bool SaveProject(Objects::ObjectList* lst, Content::ContentManager* content, const std::filesystem::path& projectPath);
5958
};
60-
61-
void to_json(json& j, const EventRepresentation& event);
62-
void from_json(const json& j, EventRepresentation& event);
6359
}

3DRadSpace/Engine3DRadSpace/Reflection/Event.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace Engine3DRadSpace::Reflection
4141
/// <summary>
4242
/// Initializes ObjectID and FunctionID to integer maximum values to represent this struct as invalid.
4343
/// </summary>
44-
MemberFunctionInvoker() = default;
44+
MemberFunctionInvoker();
4545
MemberFunctionInvoker(void* object, std::unique_ptr<IReflectedFunction> &&fn, std::type_index returnType, size_t objID, size_t fnID);
4646

4747
MemberFunctionInvoker(MemberFunctionInvoker&& other) noexcept = default;

0 commit comments

Comments
 (0)