home · contact · privacy
Server: Refactor writing of field of view to Thing struct.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 30 Jul 2014 04:38:31 +0000 (06:38 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 30 Jul 2014 04:38:31 +0000 (06:38 +0200)
src/server/field_of_view.c
src/server/field_of_view.h
src/server/god_commands.c
src/server/init.c
src/server/thing_actions.c

index 1a9acd588654f6d44b523ff18180a2201493fab9..f34885de66d073a771f848c200032d820d8182bc 100644 (file)
@@ -327,7 +327,7 @@ static void eval_position(uint16_t dist, uint16_t hex_i, uint8_t * fov_map,
 
 
 
-extern uint8_t * build_fov_map(struct Thing * eye)
+extern void build_fov_map(struct Thing * eye)
 {
     uint32_t map_size = world.map.length * world.map.length;
     uint8_t * fov_map = try_malloc(map_size, __func__);
@@ -363,5 +363,6 @@ extern uint8_t * build_fov_map(struct Thing * eye)
     }
     mv_yx_in_dir_wrap(0, NULL, 1);
     free_angles(shadows);
-    return fov_map;
+    free(eye->fov_map);
+    eye->fov_map = fov_map;
 }
index 85a414f8e84e8a2835484be5ce5b8c815e77cfc8..555ae63c12a2e4780615342a65983282f8570078 100644 (file)
@@ -19,8 +19,8 @@ enum fov_cell_states {
     VISIBLE = 0x01
 };
 
-/* Return field of view map of the world as seen from the position of "eye". */
-extern uint8_t * build_fov_map(struct Thing * eye);
+/* Build "eye"'s field of view. */
+extern void build_fov_map(struct Thing * eye);
 
 
 
index b0aa86aabf2d6e927065d486d7cd92ecb543107a..6eec5722d6bddcf729f9264d104a1490e9d9de5c 100644 (file)
@@ -239,10 +239,9 @@ static uint8_t parse_position(char* tok0, char * tok1, struct Thing * t)
             {
                 t->pos.x = length;
             }
-            free(t->fov_map);
             if (world.exists && t->lifepoints)
             {
-                t->fov_map = build_fov_map(t);
+                build_fov_map(t);
             }
         }
         return 1;
@@ -302,7 +301,7 @@ static uint8_t parse_thing_manipulation(char * tok0, char * tok1)
             t = add_thing(id, world.thing_types->id, 0, 0);
             if (world.exists && t->lifepoints)
             {
-                t->fov_map = build_fov_map(t);
+                build_fov_map(t);
             }
         }
     }
@@ -371,11 +370,7 @@ static uint8_t parse_world_active(char * tok0, char * tok1)
                 {
                     if (ti->lifepoints)
                     {
-                        if (ti->fov_map)
-                        {
-                            free(ti->fov_map);
-                        }
-                        ti->fov_map = build_fov_map(ti);
+                        build_fov_map(ti);
                     }
                 }
                 world.exists = 1;
index 01950bcac3111f455dabd97eb515090e8c89d3e2..42ec699a921d067f237c7eb67c9bafaa78454463 100644 (file)
@@ -215,7 +215,10 @@ extern uint8_t remake_world()
     struct Thing * t;
     for (t = world.things; NULL != t; t = t->next)
     {
-        t->fov_map = t->lifepoints ? build_fov_map(t) : NULL;
+        if (t->lifepoints)
+        {
+            build_fov_map(t);
+        }
     }
     world.turn = 1;
     world.do_update = 1;
index bcf9e455f4d382d538633f75681f77b6d76d7b3d..8d6a802417ea6df95068892fe3b89b77cad7057f 100644 (file)
@@ -266,8 +266,7 @@ extern void actor_move(struct Thing * t)
     if (passable)
     {
         set_thing_position(t, target);
-        free(t->fov_map);
-        t->fov_map = build_fov_map(t);
+        build_fov_map(t);
     }
     if (t == get_player())
     {