Skip to content

Commit a541015

Browse files
WIP
1 parent 3264640 commit a541015

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1113
-4
lines changed

extensions/pl_animation_ext_m.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
pl_ecs_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] binding apis
9+
// [SECTION] implementations
10+
*/
11+
12+
//-----------------------------------------------------------------------------
13+
// [SECTION] includes
14+
//-----------------------------------------------------------------------------
15+
16+
#include "pilotlight.h"
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] implementations
20+
//-----------------------------------------------------------------------------
21+
22+
PyObject*
23+
plAnimationI_register_ecs_system(PyObject* self)
24+
{
25+
26+
gptAnimation->register_ecs_system();
27+
Py_RETURN_NONE;
28+
}

extensions/pl_camera_ext_m.c

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
pl_ecs_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] binding apis
9+
// [SECTION] implementations
10+
*/
11+
12+
//-----------------------------------------------------------------------------
13+
// [SECTION] includes
14+
//-----------------------------------------------------------------------------
15+
16+
#include "pilotlight.h"
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] implementations
20+
//-----------------------------------------------------------------------------
21+
22+
PyObject*
23+
plCameraI_register_ecs_system(PyObject* self)
24+
{
25+
26+
gptCamera->register_ecs_system();
27+
Py_RETURN_NONE;
28+
}
29+
30+
PyObject*
31+
plCameraI_get_ecs_type_key(PyObject* self)
32+
{
33+
34+
plEcsTypeKey tKey = gptCamera->get_ecs_type_key();
35+
return PyLong_FromUInt32(tKey);
36+
}
37+
38+
PyObject*
39+
plCameraI_create_perspective(PyObject* self, PyObject* args, PyObject* kwargs)
40+
{
41+
42+
PyObject* ptPyLibrary = NULL;
43+
PyObject* ptPyPos = NULL;
44+
45+
static const char* apcKeywords[] = {
46+
"library",
47+
"name",
48+
"pos",
49+
"yfov",
50+
"aspect",
51+
"nearZ",
52+
"farZ",
53+
"reverseZ",
54+
NULL,
55+
};
56+
57+
const char* pcName = NULL;
58+
float fYFov = 0.0f;
59+
float fAspect = 1.0f;
60+
float fNearZ = 0.0f;
61+
float fFarZ = 0.0f;
62+
int bReverseZ = false;
63+
if (!pl_parse("OsOffffp", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
64+
&ptPyLibrary, &pcName, &ptPyPos, &fYFov, &fAspect, &fNearZ, &fFarZ, &bReverseZ))
65+
return NULL;
66+
67+
plComponentLibrary* ptCompLibrary = PyCapsule_GetPointer(ptPyLibrary, "plComponentLibrary");
68+
69+
plEntity tCamera = gptCamera->create_perspective(
70+
ptCompLibrary,
71+
pcName,
72+
pl_get_dvec3_from_python(ptPyPos),
73+
fYFov,
74+
fAspect,
75+
fNearZ,
76+
fFarZ,
77+
bReverseZ,
78+
NULL);
79+
80+
return Py_BuildValue("(III)", gptCamera->get_ecs_type_key(), tCamera.uIndex, tCamera.uGeneration);
81+
}
82+
83+
PyObject*
84+
plCameraI_set_fov(PyObject* self, PyObject* args, PyObject* kwargs)
85+
{
86+
87+
PyObject* ptPyCamera = NULL;
88+
89+
static const char* apcKeywords[] = {
90+
"camera",
91+
"yfov",
92+
NULL,
93+
};
94+
95+
float fYFov = 0.0f;
96+
if (!pl_parse("Of", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
97+
&ptPyCamera, &fYFov))
98+
return NULL;
99+
100+
plCamera* ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
101+
gptCamera->set_fov(ptCamera, fYFov);
102+
Py_RETURN_NONE;
103+
}
104+
105+
PyObject*
106+
plCameraI_update(PyObject* self, PyObject* args, PyObject* kwargs)
107+
{
108+
109+
PyObject* ptPyCamera = NULL;
110+
111+
static const char* apcKeywords[] = {
112+
"camera",
113+
NULL,
114+
};
115+
116+
if (!pl_parse("O", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
117+
&ptPyCamera))
118+
return NULL;
119+
120+
plCamera* ptCamera = PyCapsule_GetPointer(ptPyCamera, "plEntityComponent");
121+
gptCamera->update(ptCamera);
122+
Py_RETURN_NONE;
123+
}

extensions/pl_dearimgui_ext_m.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Index of this file:
3737

3838
bool pl_parse(const char* formatstring, const char** keywords, PyObject* args, PyObject* kwargs, const char* message, ...);
3939

40+
typedef struct _plPythonIntConstantPair
41+
{
42+
const char* pcName;
43+
int iValue;
44+
} plPythonIntConstantPair;
45+
4046
//-----------------------------------------------------------------------------
4147
// [SECTION] includes
4248
//-----------------------------------------------------------------------------
@@ -165,8 +171,40 @@ plImPlot_ShowDemoWindow(PyObject* self, PyObject* arg)
165171
Py_RETURN_NONE;
166172
}
167173

174+
PyObject*
175+
plImgui_begin(PyObject* self, PyObject* args, PyObject* kwargs)
176+
{
177+
178+
static const char* apcKeywords[] = {
179+
"name",
180+
"open",
181+
"flags",
182+
nullptr,
183+
};
184+
const char* pcText = nullptr;
185+
PyObject* ptPointer = nullptr;
186+
int iFlags = 0;
187+
if (!pl_parse("s|Oi", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
188+
&pcText, &ptPointer, &iFlags))
189+
return nullptr;
190+
191+
bool* pbOpen = nullptr;
192+
if(!Py_IsNone(ptPointer))
193+
pbOpen = (bool*)PyCapsule_GetPointer(ptPointer, "pb");
194+
195+
return PyBool_FromLong(ImGui::Begin(pcText, pbOpen, iFlags));
196+
}
197+
198+
PyObject*
199+
plImgui_end(PyObject* self)
200+
{
201+
ImGui::End();
202+
Py_RETURN_NONE;
203+
}
204+
168205

169206
#define PL_PYTHON_COMMAND(ARG, FLAGS, DOCS) {#ARG, (PyCFunction)ARG, FLAGS, DOCS}
207+
#define PL_ADD_INT_CONSTANT(X_ARG) {#X_ARG, X_ARG}
170208

171209
static PyMethodDef gatCommands[] =
172210
{
@@ -176,13 +214,43 @@ static PyMethodDef gatCommands[] =
176214
PL_PYTHON_COMMAND(plImgui_render, METH_VARARGS | METH_KEYWORDS, NULL),
177215
PL_PYTHON_COMMAND(plImgui_cleanup, METH_VARARGS | METH_KEYWORDS, NULL),
178216
PL_PYTHON_COMMAND(plImGui_ShowDemoWindow, METH_O, NULL),
217+
PL_PYTHON_COMMAND(plImgui_begin, METH_VARARGS | METH_KEYWORDS, NULL),
218+
PL_PYTHON_COMMAND(plImgui_end, METH_NOARGS, NULL),
179219

180220
// implot
181221
PL_PYTHON_COMMAND(plImPlot_ShowDemoWindow, METH_O, NULL),
182222

183223
{NULL, NULL, 0, NULL}
184224
};
185225

226+
static plPythonIntConstantPair gatImguiIntPairs[] = {
227+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_None),
228+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoTitleBar),
229+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoResize),
230+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoMove),
231+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoScrollbar),
232+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoScrollWithMouse),
233+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoCollapse),
234+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_AlwaysAutoResize),
235+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoBackground),
236+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoSavedSettings),
237+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoMouseInputs),
238+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_MenuBar),
239+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_HorizontalScrollbar),
240+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoFocusOnAppearing),
241+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoBringToFrontOnFocus),
242+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_AlwaysVerticalScrollbar),
243+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_AlwaysHorizontalScrollbar),
244+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoNavInputs),
245+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoNavFocus),
246+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_UnsavedDocument),
247+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoDocking),
248+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoNav),
249+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoDecoration),
250+
PL_ADD_INT_CONSTANT(ImGuiWindowFlags_NoInputs)
251+
252+
};
253+
186254
PyMODINIT_FUNC
187255
PyInit_imgui(void)
188256
{
@@ -205,6 +273,10 @@ PyInit_imgui(void)
205273
{
206274
return NULL;
207275
}
276+
277+
for(uint32_t i = 0; i < PL_ARRAYSIZE(gatImguiIntPairs); i++)
278+
PyModule_AddIntConstant(ptModule, gatImguiIntPairs[i].pcName, gatImguiIntPairs[i].iValue);
279+
208280
return ptModule;
209281
}
210282

extensions/pl_ecs_ext_m.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
pl_ecs_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] binding apis
9+
// [SECTION] implementations
10+
*/
11+
12+
//-----------------------------------------------------------------------------
13+
// [SECTION] includes
14+
//-----------------------------------------------------------------------------
15+
16+
#include "pilotlight.h"
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] implementations
20+
//-----------------------------------------------------------------------------
21+
22+
PyObject*
23+
plEcsI_initialize(PyObject* self)
24+
{
25+
26+
gptECS->initialize((plEcsInit){0});
27+
Py_RETURN_NONE;
28+
}
29+
30+
PyObject*
31+
plEcsI_finalize(PyObject* self)
32+
{
33+
34+
gptECS->finalize();
35+
Py_RETURN_NONE;
36+
}
37+
38+
PyObject*
39+
plEcsI_cleanup(PyObject* self)
40+
{
41+
42+
gptECS->cleanup();
43+
Py_RETURN_NONE;
44+
}
45+
46+
PyObject*
47+
plEcsI_get_default_library(PyObject* self, PyObject* args, PyObject* kwargs)
48+
{
49+
plComponentLibrary* ptCompLibrary = gptECS->get_default_library();
50+
return PyCapsule_New(ptCompLibrary, "plComponentLibrary", NULL);
51+
}
52+
53+
PyObject*
54+
plEcsI_get_component(PyObject* self, PyObject* args, PyObject* kwargs)
55+
{
56+
static const char* apcKeywords[] = {
57+
"library",
58+
"key",
59+
"entity",
60+
NULL,
61+
};
62+
63+
PyObject* ptPyLibrary = NULL;
64+
uint32_t uEcsKey = 0;
65+
PyObject* ptPyEntity = NULL;
66+
if (!pl_parse("OIO", (const char**)apcKeywords, args, kwargs, __FUNCTION__,
67+
&ptPyLibrary, &uEcsKey, &ptPyEntity))
68+
return NULL;
69+
70+
plComponentLibrary* ptCompLibrary = PyCapsule_GetPointer(ptPyLibrary, "plComponentLibrary");
71+
72+
plPythonEntity tPyEntity = pl_get_entity_from_python(ptPyEntity);
73+
void* pComponent = gptECS->get_component(ptCompLibrary, uEcsKey, tPyEntity.tEntity);
74+
return PyCapsule_New(pComponent, "plEntityComponent", NULL);
75+
}

extensions/pl_material_ext_m.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
pl_ecs_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] binding apis
9+
// [SECTION] implementations
10+
*/
11+
12+
//-----------------------------------------------------------------------------
13+
// [SECTION] includes
14+
//-----------------------------------------------------------------------------
15+
16+
#include "pilotlight.h"
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] implementations
20+
//-----------------------------------------------------------------------------
21+
22+
PyObject*
23+
plMaterialI_register_ecs_system(PyObject* self)
24+
{
25+
26+
gptMaterial->register_ecs_system();
27+
Py_RETURN_NONE;
28+
}

extensions/pl_mesh_ext_m.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
pl_ecs_ext_m.c
3+
*/
4+
5+
/*
6+
Index of this file:
7+
// [SECTION] includes
8+
// [SECTION] binding apis
9+
// [SECTION] implementations
10+
*/
11+
12+
//-----------------------------------------------------------------------------
13+
// [SECTION] includes
14+
//-----------------------------------------------------------------------------
15+
16+
#include "pilotlight.h"
17+
18+
//-----------------------------------------------------------------------------
19+
// [SECTION] implementations
20+
//-----------------------------------------------------------------------------
21+
22+
PyObject*
23+
plMeshI_register_ecs_system(PyObject* self)
24+
{
25+
26+
gptMesh->register_ecs_system();
27+
Py_RETURN_NONE;
28+
}

0 commit comments

Comments
 (0)