Skip to content

Commit e8e9743

Browse files
author
Roberto De Ioris
committed
various improvements from pull request 20tab#232
1 parent edf038a commit e8e9743

File tree

5 files changed

+85
-31
lines changed

5 files changed

+85
-31
lines changed

Source/UnrealEnginePython/Private/UEPyModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static PyMethodDef ue_PyUObject_methods[] = {
738738
{ "get_hud", (PyCFunction)py_ue_controller_get_hud, METH_VARARGS, "" },
739739
{ "get_controlled_pawn", (PyCFunction)py_ue_get_controlled_pawn, METH_VARARGS, "" },
740740
{ "get_pawn", (PyCFunction)py_ue_get_controlled_pawn, METH_VARARGS, "" },
741-
741+
{ "project_world_location_to_screen", (PyCFunction)py_ue_controller_project_world_location_to_screen, METH_VARARGS, "" },
742742

743743
// Attaching
744744

Source/UnrealEnginePython/Private/UObject/UEPyController.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include "UnrealEnginePythonPrivatePCH.h"
22

33

4-
PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args) {
4+
PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args)
5+
{
56

67
ue_py_check(self);
78

89
PyObject *obj;
9-
if (!PyArg_ParseTuple(args, "O:posses", &obj)) {
10+
if (!PyArg_ParseTuple(args, "O:posses", &obj))
11+
{
1012
return NULL;
1113
}
1214

@@ -24,7 +26,8 @@ PyObject *py_ue_controller_posses(ue_PyUObject * self, PyObject * args) {
2426
return Py_None;
2527
}
2628

27-
PyObject *py_ue_controller_get_hud(ue_PyUObject * self, PyObject * args) {
29+
PyObject *py_ue_controller_get_hud(ue_PyUObject * self, PyObject * args)
30+
{
2831

2932
ue_py_check(self);
3033

@@ -39,7 +42,8 @@ PyObject *py_ue_controller_get_hud(ue_PyUObject * self, PyObject * args) {
3942
return (PyObject *)ret;
4043
}
4144

42-
PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args) {
45+
PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args)
46+
{
4347

4448
ue_py_check(self);
4549

@@ -52,7 +56,8 @@ PyObject *py_ue_controller_unposses(ue_PyUObject * self, PyObject * args) {
5256
Py_RETURN_NONE;
5357
}
5458

55-
PyObject *py_ue_get_controlled_pawn(ue_PyUObject * self, PyObject * args) {
59+
PyObject *py_ue_get_controlled_pawn(ue_PyUObject * self, PyObject * args)
60+
{
5661

5762
ue_py_check(self);
5863

@@ -65,7 +70,8 @@ PyObject *py_ue_get_controlled_pawn(ue_PyUObject * self, PyObject * args) {
6570
#else
6671
APawn *pawn = controller->GetControlledPawn();
6772
#endif
68-
if (!pawn) {
73+
if (!pawn)
74+
{
6975
Py_RETURN_NONE;
7076
}
7177

@@ -74,4 +80,33 @@ PyObject *py_ue_get_controlled_pawn(ue_PyUObject * self, PyObject * args) {
7480
return PyErr_Format(PyExc_Exception, "uobject is in invalid state");
7581
Py_INCREF(ret);
7682
return (PyObject *)ret;
83+
}
84+
85+
PyObject *py_ue_controller_project_world_location_to_screen(ue_PyUObject * self, PyObject * args)
86+
{
87+
88+
ue_py_check(self);
89+
90+
PyObject *py_obj_point;
91+
PyObject *py_relative = nullptr;
92+
93+
if (!PyArg_ParseTuple(args, "O|O:project_world_location_to_screen", &py_obj_point, &py_relative))
94+
return nullptr;
95+
96+
APlayerController *controller = ue_py_check_type<APlayerController>(self);
97+
if (!controller)
98+
return PyErr_Format(PyExc_Exception, "uobject is not an AController");
99+
100+
ue_PyFVector *point = py_ue_is_fvector(py_obj_point);
101+
if (!point)
102+
return PyErr_Format(PyExc_Exception, "argument is not a FVector");
103+
104+
// TODO: Check return value:
105+
FVector2D screenLocation;
106+
if (!controller->ProjectWorldLocationToScreen(point->vec, screenLocation, (py_relative && PyObject_IsTrue(py_relative))))
107+
{
108+
return PyErr_Format(PyExc_Exception, "unable to project coordinates");
109+
}
110+
111+
return Py_BuildValue("(ff)", screenLocation.X, screenLocation.Y);
77112
}

Source/UnrealEnginePython/Private/UObject/UEPyController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
PyObject *py_ue_controller_posses(ue_PyUObject *, PyObject *);
88
PyObject *py_ue_controller_unposses(ue_PyUObject *, PyObject *);
99
PyObject *py_ue_controller_get_hud(ue_PyUObject *, PyObject *);
10-
PyObject *py_ue_get_controlled_pawn(ue_PyUObject *, PyObject *);
10+
PyObject *py_ue_get_controlled_pawn(ue_PyUObject *, PyObject *);
11+
PyObject *py_ue_controller_project_world_location_to_screen(ue_PyUObject *, PyObject *);

Source/UnrealEnginePython/Private/UObject/UEPyTraceAndSweep.cpp

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
#include "Kismet/KismetSystemLibrary.h"
44

5-
PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * args) {
5+
PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * args)
6+
{
67

78
ue_py_check(self);
89

@@ -15,7 +16,8 @@ PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * arg
1516
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
1617

1718

18-
if (!PyArg_ParseTuple(args, "OOi:line_trace_single_by_channel", &py_obj_start, &py_obj_end, &channel)) {
19+
if (!PyArg_ParseTuple(args, "OOi:line_trace_single_by_channel", &py_obj_start, &py_obj_end, &channel))
20+
{
1921
return NULL;
2022
}
2123

@@ -29,16 +31,17 @@ PyObject *py_ue_line_trace_single_by_channel(ue_PyUObject * self, PyObject * arg
2931

3032
bool got_hit = world->LineTraceSingleByChannel(hit, start->vec, end->vec, (ECollisionChannel)channel);
3133

32-
if (got_hit) {
34+
if (got_hit)
35+
{
3336
return py_ue_new_fhitresult(hit);
3437
}
3538

36-
Py_INCREF(Py_None);
37-
return Py_None;
39+
Py_RETURN_NONE;
3840

3941
}
4042

41-
PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args) {
43+
PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args)
44+
{
4245

4346
ue_py_check(self);
4447

@@ -51,7 +54,8 @@ PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args
5154
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
5255

5356

54-
if (!PyArg_ParseTuple(args, "OOOi:line_trace_multi_by_channel", &py_obj_start, &py_obj_end, &channel)) {
57+
if (!PyArg_ParseTuple(args, "OOi:line_trace_multi_by_channel", &py_obj_start, &py_obj_end, &channel))
58+
{
5559
return NULL;
5660
}
5761

@@ -68,8 +72,10 @@ PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args
6872

6973
bool got_hits = world->LineTraceMultiByChannel(hits, start->vec, end->vec, (ECollisionChannel)channel);
7074

71-
if (got_hits) {
72-
for (int i = 0; i < hits.Num(); i++) {
75+
if (got_hits)
76+
{
77+
for (int i = 0; i < hits.Num(); i++)
78+
{
7379
FHitResult hit = hits[i];
7480
PyList_Append(hits_list, py_ue_new_fhitresult(hit));
7581
}
@@ -78,26 +84,29 @@ PyObject *py_ue_line_trace_multi_by_channel(ue_PyUObject * self, PyObject * args
7884

7985
}
8086

81-
PyObject *py_ue_get_hit_result_under_cursor(ue_PyUObject * self, PyObject * args) {
87+
PyObject *py_ue_get_hit_result_under_cursor(ue_PyUObject * self, PyObject * args)
88+
{
8289

8390
ue_py_check(self);
8491

8592
int channel;
86-
PyObject *trace_complex = NULL;
93+
PyObject *trace_complex = nullptr;
8794
int controller_id = 0;
8895

8996
UWorld *world = ue_get_uworld(self);
9097
if (!world)
9198
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
9299

93100

94-
if (!PyArg_ParseTuple(args, "i|Oi:get_hit_result_under_cursor", &channel, &trace_complex, &controller_id)) {
95-
return NULL;
101+
if (!PyArg_ParseTuple(args, "i|Oi:get_hit_result_under_cursor", &channel, &trace_complex, &controller_id))
102+
{
103+
return nullptr;
96104
}
97105

98106

99107
bool complex = false;
100-
if (trace_complex && PyObject_IsTrue(trace_complex)) {
108+
if (trace_complex && PyObject_IsTrue(trace_complex))
109+
{
101110
complex = true;
102111
}
103112

@@ -109,30 +118,33 @@ PyObject *py_ue_get_hit_result_under_cursor(ue_PyUObject * self, PyObject * args
109118

110119
bool got_hit = controller->GetHitResultUnderCursor((ECollisionChannel)channel, complex, hit);
111120

112-
if (got_hit) {
121+
if (got_hit)
122+
{
113123
return py_ue_new_fhitresult(hit);
114124
}
115125

116-
Py_INCREF(Py_None);
117-
return Py_None;
126+
Py_RETURN_NONE;
118127

119128
}
120129

121-
PyObject *py_ue_draw_debug_line(ue_PyUObject * self, PyObject * args) {
130+
PyObject *py_ue_draw_debug_line(ue_PyUObject * self, PyObject * args)
131+
{
122132

123133
ue_py_check(self);
124134

125135
PyObject *py_obj_start;
126136
PyObject *py_obj_end;
127-
uint8 r = 1, g = 0, b = 0;
137+
PyObject *py_color;
128138
float duration = 0;
139+
float thickness = 0;
129140

130141
UWorld *world = ue_get_uworld(self);
131142
if (!world)
132143
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
133144

134145

135-
if (!PyArg_ParseTuple(args, "OO|iiif:draw_debug_line", &py_obj_start, &py_obj_end, &r, &g, &b, &duration)) {
146+
if (!PyArg_ParseTuple(args, "OOO|ff:draw_debug_line", &py_obj_start, &py_obj_end, &py_color, &duration, &thickness))
147+
{
136148
return NULL;
137149
}
138150

@@ -142,8 +154,11 @@ PyObject *py_ue_draw_debug_line(ue_PyUObject * self, PyObject * args) {
142154
if (!start || !end)
143155
return PyErr_Format(PyExc_Exception, "start and end location must be vectors");
144156

145-
UKismetSystemLibrary::DrawDebugLine(world, start->vec, end->vec, FColor(r, g, b), false, duration);
157+
ue_PyFLinearColor *py_linear_color = py_ue_is_flinearcolor(py_color);
158+
if (!py_linear_color)
159+
return PyErr_Format(PyExc_Exception, "argument is not a FLinearColor");
160+
161+
UKismetSystemLibrary::DrawDebugLine(world, start->vec, end->vec, py_linear_color->color, duration, thickness);
146162

147-
Py_INCREF(Py_None);
148-
return Py_None;
163+
Py_RETURN_NONE;
149164
}

Source/UnrealEnginePython/UnrealEnginePython.Build.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class UnrealEnginePython : ModuleRules
3030
"/Library/Frameworks/Python.framework/Versions/3.6",
3131
"/Library/Frameworks/Python.framework/Versions/3.5",
3232
"/Library/Frameworks/Python.framework/Versions/2.7",
33+
"/System/Library/Frameworks/Python.framework/Versions/3.6",
34+
"/System/Library/Frameworks/Python.framework/Versions/3.5",
35+
"/System/Library/Frameworks/Python.framework/Versions/2.7"
3336
};
3437

3538
private string[] linuxKnownIncludesPaths =

0 commit comments

Comments
 (0)