Skip to content

Commit f0035c5

Browse files
committed
GameFramework: Update method now being called and GameObjects can now translate from C#
1 parent 5d62e02 commit f0035c5

File tree

7 files changed

+34
-2
lines changed

7 files changed

+34
-2
lines changed

src/Managed/ExeonScript.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ namespace Exeon
66
public class ExeonScript
77
{
88
public static void Init()
9+
{
10+
Console.Debug("C# Scripting working");
11+
}
12+
13+
public static void Update()
914
{
1015
Scene sampleScene = SceneManager.GetScene("SampleScene");
1116

12-
Console.Debug("C# Scripting working");
1317
GameObject obj = sampleScene.GetObject("Sponza Atrium");
1418
Transform transform = obj.transform;
15-
Console.Debug(transform.location.x.ToString());
19+
// transform.Translate(1.0f, 0.0f, 0.0f);
1620
}
1721
}
1822
}

src/Managed/Math/Transform.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class Transform
2020

2121
[MethodImpl(MethodImplOptions.InternalCall)]
2222
private static extern CVector3 GetLocation_Impl(UIntPtr ptr);
23+
[MethodImpl(MethodImplOptions.InternalCall)]
24+
private static extern void Translate_Impl(UIntPtr ptr, float x, float y, float z);
2325

2426
private Vector3 GetLocation(UIntPtr ptr)
2527
{
@@ -38,6 +40,11 @@ public Transform(UIntPtr ptr)
3840
this.nativePtr = ptr;
3941
}
4042

43+
public void Translate(float x, float y, float z)
44+
{
45+
Translate_Impl(this.nativePtr, x, y, z);
46+
}
47+
4148
public Vector3 location
4249
{
4350
get => GetLocation(this.nativePtr);

src/private/Core/Core.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Core::Core() {
88
this->m_sceneManager = SceneManager::GetInstance();
99
this->m_resMgr = nullptr;
1010
this->m_mono = nullptr;
11+
this->m_status = GAME_STATUS::STOPPED;
1112
}
1213

1314
void Core::Init() {
@@ -33,6 +34,7 @@ void Core::SetHWND(HWND& hwnd) {
3334
void Core::MainLoop() {
3435
this->m_sceneManager->Update();
3536
this->m_renderer->Update();
37+
this->m_mono->Update();
3638
}
3739

3840
void Core::GetWindowSize(UINT& nWidth, UINT& nHeight) {

src/private/Runtime/GameObjectImpl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ extern "C" CVector3 Transform_GetLocation(uintptr_t ptr) {
1212
Vector3 loc = transform->location;
1313
CVector3 vec(loc.x, loc.y, loc.z);
1414
return vec;
15+
}
16+
17+
extern "C" void Transform_Translate(uintptr_t ptr, float x, float y, float z) {
18+
Transform* transform = reinterpret_cast<Transform*>(ptr);
19+
transform->Translate(x, y, z);
20+
return;
1521
}

src/private/Runtime/MonoScript.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ void MonoScript::Init() {
4949
mono_add_internal_call("Exeon.Scene::ObjectExists_Impl", reinterpret_cast<const void*>(Scene_ObjectExists));
5050
mono_add_internal_call("Exeon.GameObject::GetTransform_Impl", reinterpret_cast<const void*>(GameObject_GetTransform));
5151
mono_add_internal_call("Exeon.Transform::GetLocation_Impl", reinterpret_cast<const void*>(Transform_GetLocation));
52+
mono_add_internal_call("Exeon.Transform::Translate_Impl", reinterpret_cast<const void*>(Transform_Translate));
5253

5354
mono_runtime_invoke(initMethod, nullptr, nullptr, nullptr);
5455
}
5556

5657
void MonoScript::Update() {
58+
MonoClass* gameScriptClass = mono_class_from_name(this->m_image, "Exeon", "ExeonScript");
59+
MonoMethod* updateMethod = mono_class_get_method_from_name(gameScriptClass, "Update", 0);
60+
mono_runtime_invoke(updateMethod, nullptr, nullptr, nullptr);
5761

5862
}
5963

src/public/Core/Core.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#include "Renderer/ResourceManager.h"
88
#include "Runtime/MonoScript.h"
99

10+
enum GAME_STATUS {
11+
STOPPED = 0x00,
12+
PLAYING = 0x01,
13+
PAUSED = 0x02
14+
};
15+
1016
class Core {
1117
private:
1218
static Core* m_instance;
@@ -22,6 +28,8 @@ class Core {
2228
UINT m_nHeight;
2329

2430
MonoScript* m_mono;
31+
32+
GAME_STATUS m_status;
2533
public:
2634
Core();
2735
void Init();

src/public/Runtime/GameObjectImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ extern "C" {
1414

1515
uintptr_t GameObject_GetTransform(uintptr_t ptr);
1616
CVector3 Transform_GetLocation(uintptr_t ptr);
17+
void Transform_Translate(uintptr_t ptr, float x, float y, float z);
1718
}

0 commit comments

Comments
 (0)