'entity only' grid update, saves lots of throughput on larger grids
This commit is contained in:
parent
34feb226e4
commit
9441f357df
|
@ -582,7 +582,7 @@ PyObject* McRFPy_API::_listGrids(PyObject*, PyObject*) {
|
|||
grid->visible? Py_True: Py_False);
|
||||
|
||||
grid->visible ? Py_INCREF(Py_True) : Py_INCREF(Py_False);
|
||||
std::cout << PyUnicode_AsUTF8(PyObject_Repr(grid_args)) << std::endl;
|
||||
//std::cout << PyUnicode_AsUTF8(PyObject_Repr(grid_args)) << std::endl;
|
||||
|
||||
PyObject* gridobj = PyObject_CallObject((PyObject*) grid_type, grid_args);
|
||||
//std::cout << (long)gridobj << std::flush <<std::endl;
|
||||
|
@ -634,8 +634,9 @@ PyObject* McRFPy_API::_listGrids(PyObject*, PyObject*) {
|
|||
|
||||
PyObject* McRFPy_API::_modGrid(PyObject* self, PyObject* args) {
|
||||
PyObject* o;
|
||||
if (!PyArg_ParseTuple(args, "O", &o)) return NULL;
|
||||
//std::cout << PyUnicode_AsUTF8(PyObject_Repr(o)) << std::endl;
|
||||
PyObject* bool_is_entityonly = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "O|O", &o, &bool_is_entityonly)) return NULL;
|
||||
std::cout << "EntOnly Flag: " << PyUnicode_AsUTF8(PyObject_Repr(bool_is_entityonly)) << std::endl;
|
||||
std::string title = PyUnicode_AsUTF8(PyObject_GetAttrString(o, "title"));
|
||||
int grid_x = PyLong_AsLong(PyObject_GetAttrString(o, "grid_x"));
|
||||
int grid_y = PyLong_AsLong(PyObject_GetAttrString(o, "grid_y"));
|
||||
|
@ -653,6 +654,7 @@ PyObject* McRFPy_API::_modGrid(PyObject* self, PyObject* args) {
|
|||
grid->visible = visible;
|
||||
|
||||
//iterate over gridpoints
|
||||
if (!PyObject_IsTrue(bool_is_entityonly)) {
|
||||
PyObject* gpointlist = PyObject_GetAttrString(o, "points");
|
||||
//std::cout << PyUnicode_AsUTF8(PyObject_Repr(gpointlist)) << std::endl;
|
||||
for (int i = 0; i < grid->points.size(); i++) {
|
||||
|
@ -679,7 +681,7 @@ PyObject* McRFPy_API::_modGrid(PyObject* self, PyObject* args) {
|
|||
grid->points[i].tile_overlay = PyLong_AsLong(PyObject_GetAttrString(gpointobj, "tile_overlay"));
|
||||
grid->points[i].uisprite = PyLong_AsLong(PyObject_GetAttrString(gpointobj, "uisprite"));
|
||||
}
|
||||
|
||||
}
|
||||
PyObject* entlist = PyObject_GetAttrString(o, "entities");
|
||||
//std::cout << PyUnicode_AsUTF8(PyObject_Repr(entlist)) << std::endl;
|
||||
for (int i = 0; i < grid->entities.size(); i++) {
|
||||
|
|
|
@ -10,6 +10,9 @@ DARKRED, DARKGREEN, DARKBLUE = (192, 0, 0), (0, 192, 0), (0, 0, 192)
|
|||
|
||||
animations_in_progress = 0
|
||||
|
||||
# don't load grid over and over, use the global scene
|
||||
scene = None
|
||||
|
||||
class TestEntity:
|
||||
def __init__(self, grid, label, tex_index, basesprite, x, y, texture_width=64, walk_frames=5, attack_frames=6):
|
||||
self.grid = grid
|
||||
|
@ -30,8 +33,8 @@ class TestEntity:
|
|||
def move(self, dx, dy):
|
||||
# select animation direction
|
||||
# prefer left or right for diagonals.
|
||||
grids = mcrfpy.listGrids()
|
||||
for g in grids:
|
||||
#grids = mcrfpy.listGrids()
|
||||
for g in scene.grids:
|
||||
if g.title == self.grid:
|
||||
if not g.at(self.x + dx, self.y + dy).walkable:
|
||||
print("Blocked at target location.")
|
||||
|
@ -74,11 +77,12 @@ class TestEntity:
|
|||
pos = animove
|
||||
self.x, self.y = animove
|
||||
#scene.move_entity(self.grid, self.entity_index, pos)
|
||||
for g in mcrfpy.listGrids():
|
||||
#for g in mcrfpy.listGrids():
|
||||
for g in scene.grids:
|
||||
if g.title == self.grid:
|
||||
g.entities[self.entity_index].x = pos[0]
|
||||
g.entities[self.entity_index].y = pos[1]
|
||||
mcrfpy.modGrid(g)
|
||||
mcrfpy.modGrid(g, True)
|
||||
if animove:
|
||||
mcrfpy.createAnimation(
|
||||
0.25, # duration, seconds
|
||||
|
@ -147,7 +151,7 @@ class TestScene:
|
|||
|
||||
print("Create grid")
|
||||
# create grid (title, gx, gy, gs, x, y, w, h)
|
||||
mcrfpy.createGrid(grid_name, 20, 20, 16, 20, 20, 800, 500)
|
||||
mcrfpy.createGrid(grid_name, 100, 100, 16, 20, 20, 800, 500)
|
||||
self.grids = mcrfpy.listGrids()
|
||||
print(self.grids)
|
||||
|
||||
|
@ -250,10 +254,10 @@ class TestScene:
|
|||
mcrfpy.modMenu(self.menus[0])
|
||||
|
||||
def gridgen(self):
|
||||
#print(f"[Python] modifying {len(self.grids[0].points)} grid points")
|
||||
print(f"[Python] modifying {len(self.grids[0].points)} grid points")
|
||||
for p in self.grids[0].points:
|
||||
p.color = (randint(0, 255), randint(64, 192), 0)
|
||||
#print("[Python] Modifying:")
|
||||
print("[Python] Modifying:")
|
||||
self.grids[0].at(10, 10).color = (255, 255, 255)
|
||||
self.grids[0].at(10, 10).walkable = False
|
||||
self.grids[0].visible = True
|
||||
|
@ -297,7 +301,6 @@ class TestScene:
|
|||
[0, 1, 2, 1, 2, 0]
|
||||
)
|
||||
|
||||
scene = None
|
||||
def start():
|
||||
global scene
|
||||
print("TestScene.start called")
|
||||
|
|
Loading…
Reference in New Issue