/
py_world.i
86 lines (71 loc) · 2.16 KB
/
py_world.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
%module world
%feature("autodoc", "1"); // enable docstrings for python wrappers
%{
#include "base/types.h"
#include "python/callback.h"
#include "world/area_manager.h"
#include "world/object.h"
#include "world/character.h"
#include "world/mapview.h"
#include "world/schedule.h"
using namespace world;
%}
%include "stdint.i"
%include "std_string.i"
%import "base/types.h"
%import "py_gfx.i"
// typemap for returning a string pointer as python string
%typemap(out) std::string * {
if ($1 == NULL) $result = Py_None;
else $result = PyString_FromString ($1->c_str ());
}
// typemap for returning a list<chunk_info*> as python list
%typemap(out) std::list<chunk_info*> {
unsigned int index = 0;
$result = PyList_New ($1.size ());
for (std::list<chunk_info*>::const_iterator i = $1.begin (); i != $1.end (); i++)
PyList_SET_ITEM ($result, index++, python::pass_instance (*i));
}
%typemap(freearg) std::list<chunk_info*> "delete $1;"
// object is an existing python class
%rename(mapobject) world::object;
%include "world/vector3.h"
%template(vector3i) world::vector3<s_int32>;
%include "python/script.h"
%include "world/placeable_model.h"
%include "world/placeable.h"
%include "world/object.h"
%include "world/coordinates.h"
%include "world/moving.h"
%include "world/action.h"
%include "world/character.h"
%include "world/chunk.h"
%include "world/chunk_info.h"
%include "world/entity.h"
%include "world/area.h"
%include "world/area_manager.h"
%include "world/pathfinding_manager.h"
%include "world/placeable_shape.h"
%include "world/renderer.h"
%include "world/mapview.h"
%include "world/schedule.h"
%pythoncode %{
class coordinates (vector3i):
pass
%}
/// no downcasting in python, so we have to improvise ...
%extend world::area {
/// get a character from the map
world::character* get_character (const std::string & name)
{
return dynamic_cast<world::character*> (self->get_entity (name));
}
};
// class extension to handle Python callbacks
%extend world::pathfinding_manager
{
void set_callback (const s_int16 id, PyObject * callback)
{
self->set_callback (id, new python::functor_1<const s_int32>(callback));
}
};