From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 24 Feb 2016 23:25:13 +0000 (+0100)
Subject: Server: Outsource part of update_map_memory to C library.
X-Git-Tag: tce~156
X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/templates?a=commitdiff_plain;h=fcfdd7a530813c0f23389fb217920c4dc2bbbde7;p=plomrogue

Server: Outsource part of update_map_memory to C library.
---

diff --git a/libplomrogue.c b/libplomrogue.c
index d0b656b..37cc8ef 100644
--- a/libplomrogue.c
+++ b/libplomrogue.c
@@ -618,3 +618,20 @@ extern uint8_t set_cells_passable_on_memmap_to_65534_on_scoremap(char * mem_map,
     }
     return 0;
 }
+
+
+extern void update_mem_and_memdepthmap_via_fovmap(char * map, char * fovmap,
+                                                  char * memdepthmap,
+                                                  char * memmap)
+{
+    uint32_t map_size = maplength * maplength;
+    uint16_t pos;
+    for (pos = 0; pos < map_size; pos++)
+    {
+        if ('v' == fovmap[pos])
+        {
+            memdepthmap[pos] = '0';
+            memmap[pos] = map[pos];
+        }
+    }
+}
diff --git a/server/update_map_memory.py b/server/update_map_memory.py
index d018e84..5d6ae68 100644
--- a/server/update_map_memory.py
+++ b/server/update_map_memory.py
@@ -24,18 +24,27 @@ def update_map_memory(t, age_map=True):
         fovmap = c_pointer_to_bytearray(t["fovmap"])
         libpr.age_some_memdepthmap_on_nonfov_cells(memdepthmap, fovmap)
 
+    def update_mem_and_memdepthmap_via_fovmap():
+        # OUTSOURCED FOR PERFORMANCE REASONS TO libplomrogue.so:
+        # for pos in [pos for pos in range(world_db["MAP_LENGTH"] ** 2)
+        #             if ord_v == t["fovmap"][pos]]:
+        #     t["T_MEMDEPTHMAP"][pos] = ord_0
+        #     t["T_MEMMAP"][pos] = world_db["MAP"][pos]
+        memdepthmap = c_pointer_to_bytearray(t["T_MEMDEPTHMAP"])
+        memmap = c_pointer_to_bytearray(t["T_MEMMAP"])
+        fovmap = c_pointer_to_bytearray(t["fovmap"])
+        map = c_pointer_to_bytearray(world_db["MAP"])
+        libpr.update_mem_and_memdepthmap_via_fovmap(map, fovmap, memdepthmap,
+                                                    memmap)
+
     if not t["T_MEMMAP"]:
         t["T_MEMMAP"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
     if not t["T_MEMDEPTHMAP"]:
         t["T_MEMDEPTHMAP"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
-    ord_v = ord("v")
-    ord_0 = ord("0")
-    for pos in [pos for pos in range(world_db["MAP_LENGTH"] ** 2)
-                if ord_v == t["fovmap"][pos]]:
-        t["T_MEMDEPTHMAP"][pos] = ord_0
-        t["T_MEMMAP"][pos] = world_db["MAP"][pos]
+    update_mem_and_memdepthmap_via_fovmap()
     if age_map:
         age_some_memdepthmap_on_nonfov_cells()
+    ord_v = ord("v")
     t["T_MEMTHING"] = [mt for mt in t["T_MEMTHING"]
                        if ord_v != t["fovmap"][(mt[1] * world_db["MAP_LENGTH"])
                                                + mt[2]]]