Skip to content

Commit 1b56d8a

Browse files
committed
Added script init if cloned entity
1 parent d3c307a commit 1b56d8a

6 files changed

Lines changed: 15 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ set(CMAKE_CXX_STANDARD 20)
1111
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1212
set(CMAKE_CXX_EXTENSIONS OFF)
1313

14+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
15+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
16+
1417
# ------------------------
1518
# Force-disable unneeded vendor targets
1619
# ------------------------

src/RealEngine/Asset/AssetImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ namespace RealEngine {
1515

1616
return s_AssetImportFunctions.at(metadata.Type)(metadata);
1717
}
18-
}
18+
}

src/RealEngine/Scene/Components.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace RealEngine {
100100
};
101101

102102
struct TransformComponent {
103-
void SetTransation(const glm::vec3& transation) { Transation = transation; dirty = true; }
103+
void SetTransation(const glm::vec3& transation) { Transation = transation; dirty = true; }
104104
void SetRotationEuler(const glm::vec3& rotation) { Rotation = glm::quat(rotation); dirty = true; }
105105
void SetRotationQuat(const glm::quat& rotation) { Rotation = rotation; dirty = true; }
106106
void SetScale(const glm::vec3& scale) { Scale = scale; dirty = true; }

src/RealEngine/Scene/Scene.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ namespace RealEngine {
148148
Entity newEntity = CreateEntity(name);
149149
Utils::CopyComponentIfExists(ComponentList::GetAllComponents(), newEntity, entity);
150150

151+
// If the scene is running, we need to create the script instance for the cloned entity
152+
if (m_IsRunning && newEntity.HasComponent<ScriptComponent>()) {
153+
auto& script = newEntity.GetComponent<ScriptComponent>();
154+
155+
script.Instance = Project::GetScriptEngine()->CreateObject(newEntity.GetUUID(), script.ClassName);
156+
}
157+
151158
return newEntity;
152159
}
153160

src/RealEngine/Scripting/ScriptGlue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace RealEngine {
7373
return s_EntityComponentFuncs.at(&componentType).AddComponent(entity);
7474
}
7575

76-
static UUID Entity_Instantiate(UUID entityID) {
76+
static uint64_t Entity_Instantiate(UUID entityID) {
7777
RE_PROFILE_FUNCTION();
7878
Ref<Scene> scene = Project::GetCurrentScene();
7979
RE_CORE_ASSERT(scene);

src/RealEngine/Types/UUID.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <random>
44

55
namespace RealEngine {
6-
static std::mt19937_64 s_RandomEngine;
6+
static std::random_device s_RandomDevice;
7+
static std::mt19937_64 s_RandomEngine(s_RandomDevice());
78
static std::uniform_int_distribution<uint64_t> s_UniformDistribution;
89

910
UUID::UUID(uint64_t uuid)

0 commit comments

Comments
 (0)