Skip to content

Commit 8d3dc84

Browse files
committed
Move more logic to wren + General cleanup.
1 parent 5801bcc commit 8d3dc84

16 files changed

Lines changed: 143 additions & 66 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ OverEngineProfile-StartUp.json
3333
OverEngineProfile-Runtime.json
3434
OverEngineProfile-Shutdown.json
3535

36-
# Log files
36+
# Other
3737
OverEngine.log
38+
imgui.ini
39+

OverEditor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ target_include_directories(OverEditor PRIVATE
1010
"src"
1111
)
1212

13-
set_property(TARGET OverEditor PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/OverEditor")
13+
set_property(TARGET OverEditor PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1414

1515
target_link_libraries(OverEditor PRIVATE OverEngine)

OverEngine/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ target_include_directories(OverEngine PUBLIC
8080
"vendor/wren/src/include"
8181
)
8282

83+
string(LENGTH "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LEN)
84+
if(CMAKE_BUILD_TYPE_LEN EQUAL 0)
85+
message(SEND_ERROR "No build type is specified. It can cause problems because 'stb_image.cpp' "
86+
"relies on the 'OE_DEBUG' macro which won't be properly defined without an "
87+
"explicit build type. Make sure to run CMake with "
88+
"-DCMAKE_BUILD_TYPE={Debug|Release}")
89+
endif()
90+
8391
target_compile_definitions(
8492
OverEngine
8593

OverEngine/premake5.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
function wren2c_command(name)
2-
return string.format("python ../utils/wren_to_c_string.py src/Wren/" .. name .. ".wren.inc src/Wren/" .. name .. ".wren\n")
2+
return string.format("python ../utils/wren_to_c_string.py %s.inc %s\n", name, name)
33
end
44

5+
function map(tbl, f)
6+
local t = {}
7+
for k, v in pairs(tbl) do
8+
t[k] = f(v)
9+
end
10+
return t
11+
end
12+
13+
wren2c_commands = table.concat(map(os.matchfiles("src/Wren/*.wren"), wren2c_command), '')
14+
515
project "OverEngine"
616
kind "StaticLib"
717

@@ -17,14 +27,7 @@ project "OverEngine"
1727

1828
prebuildcommands
1929
{
20-
wren2c_command("entity") ..
21-
wren2c_command("input") ..
22-
wren2c_command("keycodes") ..
23-
wren2c_command("lib") ..
24-
wren2c_command("math") ..
25-
wren2c_command("scheduler") ..
26-
wren2c_command("script") ..
27-
wren2c_command("time")
30+
wren2c_commands
2831
}
2932

3033
files

OverEngine/src/OverEngine/ImGui/ImGuiLayer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ namespace OverEngine
4343
// Setup Platform/Renderer bindings
4444
ImGuiBinding::Init(&Application::Get().GetWindow());
4545

46-
io.Fonts->AddFontFromMemoryCompressedTTF(&Roboto_compressed_data, Roboto_compressed_size, 15.0f);
46+
ImFontConfig fontTemplate;
47+
strcpy_s(fontTemplate.Name, 40, "Roboto");
48+
io.Fonts->AddFontFromMemoryCompressedTTF(&Roboto_compressed_data, Roboto_compressed_size, 20.0f, &fontTemplate);
4749
}
4850

4951
void ImGuiLayer::OnDetach()

OverEngine/src/OverEngine/Scripting/Wren.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace WrenSources
55
{
66
#include "Wren/components.wren.inc"
77
#include "Wren/entity.wren.inc"
8+
#include "Wren/imgui.wren.inc"
89
#include "Wren/input.wren.inc"
910
#include "Wren/keycodes.wren.inc"
1011
#include "Wren/lib.wren.inc"
@@ -45,6 +46,7 @@ namespace OverEngine
4546

4647
WREN_MOD(components)
4748
WREN_MOD(entity)
49+
WREN_MOD(imgui)
4850
WREN_MOD(input)
4951
WREN_MOD(keycodes)
5052
WREN_MOD(lib)
@@ -112,9 +114,13 @@ namespace OverEngine
112114

113115
Ref<WrenScriptInstance> WrenScriptClass::Construct(const Entity& entity) const
114116
{
115-
m_VM->CallMethod(m_ClassHandle, m_ConstructorHandle, entity);
116-
WrenHandle* instance = wrenGetSlotHandle(m_VM->GetRaw(), 0);
117+
if (m_VM->CallMethod(m_ClassHandle, m_ConstructorHandle, entity) != WREN_RESULT_SUCCESS)
118+
{
119+
OE_CORE_ASSERT(false, "Script instantiation failure!");
120+
return nullptr;
121+
}
117122

123+
WrenHandle* instance = wrenGetSlotHandle(m_VM->GetRaw(), 0);
118124
return CreateRef<WrenScriptInstance>(m_VM, instance);
119125
}
120126

OverEngine/src/OverEngine/Scripting/WrenBindings.cpp

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "Wren.h"
33

44
#include <wren.h>
5+
#include <imgui/imgui.h>
56

67
#include "OverEngine/Input/Input.h"
78
#include "OverEngine/Scene/Entity.h"
@@ -21,10 +22,10 @@ namespace OverEngine
2122
{
2223
namespace WrenBindings
2324
{
24-
#define WREN_INPUT(name, wrenParams, nativeCallParams) \
25-
auto Input_##name(wrenParams) \
26-
{ \
27-
return Input::name(nativeCallParams); \
25+
#define WREN_INPUT(name, wrenParams, nativeCallParams) \
26+
auto Input_##name(wrenParams) \
27+
{ \
28+
return Input::name(nativeCallParams); \
2829
}
2930

3031
WREN_INPUT(IsKeyPressed, int keycode, (KeyCode)keycode)
@@ -33,7 +34,22 @@ namespace OverEngine
3334
WREN_INPUT(GetMouseX,,)
3435
WREN_INPUT(GetMouseY,,)
3536

36-
#define WREN_COMPONENT_HAS(component) \
37+
bool ImGui_begin(const char* name)
38+
{
39+
return ImGui::Begin(name);
40+
}
41+
42+
void ImGui_end()
43+
{
44+
ImGui::End();
45+
}
46+
47+
void ImGui_text(const char* text)
48+
{
49+
ImGui::TextUnformatted(text);
50+
}
51+
52+
#define WREN_COMPONENT_HAS(component) \
3753
bool component##_has(Entity& entity) \
3854
{ \
3955
return entity.HasComponent<component>(); \
@@ -63,6 +79,16 @@ namespace OverEngine
6379
entity.GetComponent<TransformComponent>().SetPosition(position);
6480
}
6581

82+
Vector3 TransformComponent_eulerAngles(Entity& entity)
83+
{
84+
return entity.GetComponent<TransformComponent>().GetEulerAngles();
85+
}
86+
87+
void TransformComponent_set_eulerAngles(Entity& entity, const Vector3& eulerAngles)
88+
{
89+
entity.GetComponent<TransformComponent>().SetEulerAngles(eulerAngles);
90+
}
91+
6692
void RigidBody2DComponent_applyLinearImpulseToCenter(Entity& entity, const Vector2& impulse)
6793
{
6894
entity.GetComponent<RigidBody2DComponent>().RigidBody->ApplyLinearImpulseToCenter(impulse);
@@ -94,6 +120,15 @@ namespace OverEngine
94120
.endClass()
95121
.endModule();
96122

123+
m_VM.beginModule("imgui")
124+
.beginClass("ImGui")
125+
WRENPP_BIND_STATIC(ImGui_begin, "begin(_)")
126+
WRENPP_BIND_STATIC(ImGui_end, "end()")
127+
128+
WRENPP_BIND_STATIC(ImGui_text, "text(_)")
129+
.endClass()
130+
.endModule();
131+
97132
m_VM.beginModule("entity")
98133
.bindClass<Entity>("Entity")
99134
.endClass()
@@ -106,6 +141,8 @@ namespace OverEngine
106141

107142
WRENPP_BIND_STATIC_EXACT(TransformComponent_position, "_")
108143
WRENPP_BIND_STATIC_EXACT(TransformComponent_set_position, "_,_")
144+
WRENPP_BIND_STATIC_EXACT(TransformComponent_eulerAngles, "_")
145+
WRENPP_BIND_STATIC_EXACT(TransformComponent_set_eulerAngles, "_,_")
109146

110147
WRENPP_BIND_STATIC_EXACT(RigidBody2DComponent_applyLinearImpulseToCenter, "_,_")
111148
.endClass()

OverEngine/src/Platform/Linux/LinuxWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace OverEngine
4040
m_Data.Width = props.Width;
4141
m_Data.Height = props.Height;
4242

43-
OE_CORE_INFO("Creating window {0} ({1}, {2})", props.Title, props.Width, props.Height);
43+
OE_CORE_INFO("Creating window '{0}' ({1}x{2})", props.Title, props.Width, props.Height);
4444

4545
if (s_WindowCount == 0)
4646
{

OverEngine/src/Platform/Windows/WindowsWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace OverEngine
4040
m_Data.Width = props.Width;
4141
m_Data.Height = props.Height;
4242

43-
OE_CORE_INFO("Creating window {0} ({1}, {2})", props.Title, props.Width, props.Height);
43+
OE_CORE_INFO("Creating window '{0}' ({1}x{2})", props.Title, props.Width, props.Height);
4444

4545
if (s_WindowCount == 0)
4646
{

OverEngine/src/Wren/components.wren

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class ComponentInternals {
44

55
foreign static TransformComponent_position(entity)
66
foreign static TransformComponent_set_position(entity, position)
7+
foreign static TransformComponent_eulerAngles(entity)
8+
foreign static TransformComponent_set_eulerAngles(entity, eulerAngles)
79

810
foreign static RigidBody2DComponent_applyLinearImpulseToCenter(entity, impulse)
911
}
@@ -29,6 +31,9 @@ class TransformComponent is Component {
2931

3032
position { ComponentInternals.TransformComponent_position(entity) }
3133
position=(rhs) { ComponentInternals.TransformComponent_set_position(entity, rhs) }
34+
35+
eulerAngles { ComponentInternals.TransformComponent_eulerAngles(entity) }
36+
eulerAngles=(rhs) { ComponentInternals.TransformComponent_set_eulerAngles(entity, rhs) }
3237
}
3338

3439
class RigidBody2DComponent is Component {

0 commit comments

Comments
 (0)