home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8d4de89
)
Server: Refactoring of initialization of empty maps.
author
Christian Heller
<c.heller@plomlompom.de>
Tue, 27 Jan 2015 03:58:04 +0000
(
04:58
+0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Tue, 27 Jan 2015 03:58:04 +0000
(
04:58
+0100)
src/server/field_of_view.c
patch
|
blob
|
history
src/server/field_of_view.h
patch
|
blob
|
history
src/server/god_commands.c
patch
|
blob
|
history
src/server/io.c
patch
|
blob
|
history
src/server/map.c
patch
|
blob
|
history
src/server/map.h
patch
|
blob
|
history
diff --git
a/src/server/field_of_view.c
b/src/server/field_of_view.c
index 7ab567833a1bd67eb3087c67e80e9fc92eb28c70..d6b3a8d1278124c6de9694823a416cb1c24b2663 100644
(file)
--- a/
src/server/field_of_view.c
+++ b/
src/server/field_of_view.c
@@
-13,7
+13,7
@@
#include "../common/rexit.h" /* exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
#include "../common/rexit.h" /* exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
-#include "map.h" /* mv_yx_in_dir_legal() */
+#include "map.h" /* mv_yx_in_dir_legal()
, init_empty_map()
*/
#include "things.h" /* Thing, ThingInMemory, add_thing_to_memory_map() */
#include "world.h" /* world */
#include "things.h" /* Thing, ThingInMemory, add_thing_to_memory_map() */
#include "world.h" /* world */
@@
-266,8
+266,7
@@
extern void update_map_memory(struct Thing * t_eye)
{
if (!t_eye->mem_map)
{
{
if (!t_eye->mem_map)
{
- t_eye->mem_map = try_malloc(world.map.length*world.map.length,__func__);
- memset(t_eye->mem_map, ' ', world.map.length * world.map.length);
+ init_empty_map(&(t_eye->mem_map));
}
uint32_t i;
for (i = 0; i < (uint32_t) (world.map.length * world.map.length); i++)
}
uint32_t i;
for (i = 0; i < (uint32_t) (world.map.length * world.map.length); i++)
diff --git
a/src/server/field_of_view.h
b/src/server/field_of_view.h
index 5cc9edb6601b871b1ba824d0076715722b023fc0..41fde34ef156b16211844b0ca4b4c77be3a06105 100644
(file)
--- a/
src/server/field_of_view.h
+++ b/
src/server/field_of_view.h
@@
-16,7
+16,7
@@
struct Thing;
/* Update "t"'s .mem_map memory with what's in its current FOV, remove from its
/* Update "t"'s .mem_map memory with what's in its current FOV, remove from its
- * .t_mem all memorized things in FOV and add inanim
i
ate things in FOV to it.
+ * .t_mem all memorized things in FOV and add inanimate things in FOV to it.
*/
extern void update_map_memory(struct Thing * t_eye);
*/
extern void update_map_memory(struct Thing * t_eye);
diff --git
a/src/server/god_commands.c
b/src/server/god_commands.c
index a190682edbd1c28efcfed80891b14ba7277a7c71..87564043d6836433ba5e2f7ad11a7f74e558493a 100644
(file)
--- a/
src/server/god_commands.c
+++ b/
src/server/god_commands.c
@@
-18,7
+18,7
@@
#include "field_of_view.h" /* build_fov_map(), update_map_memory() */
#include "hardcoded_strings.h" /* s */
#include "init.h" /* remake_world() */
#include "field_of_view.h" /* build_fov_map(), update_map_memory() */
#include "hardcoded_strings.h" /* s */
#include "init.h" /* remake_world() */
-#include "map.h" /* remake_map() */
+#include "map.h" /*
init_empty_map(),
remake_map() */
#include "thing_actions.h" /* ThingAction, actor_wait(), actor_move(),
* actor_use(), actor_pickup(), actor_drop()
*/
#include "thing_actions.h" /* ThingAction, actor_wait(), actor_move(),
* actor_use(), actor_pickup(), actor_drop()
*/
@@
-466,9
+466,7
@@
extern uint8_t parse_god_command_2arg(char * tok0, char * tok1, char * tok2)
}
if (!t->mem_map)
{
}
if (!t->mem_map)
{
- uint32_t map_size = world.map.length * world.map.length;
- t->mem_map = try_malloc(map_size, __func__);
- memset(t->mem_map, ' ', map_size);
+ init_empty_map(&(t->mem_map));
}
memcpy(t->mem_map + y * world.map.length, tok2, world.map.length);
}
}
memcpy(t->mem_map + y * world.map.length, tok2, world.map.length);
}
diff --git
a/src/server/io.c
b/src/server/io.c
index 227be3fd4e192a4886c29617771cc2637a245696..d28eeb65da99372f6f583af963bc9363d22f77c2 100644
(file)
--- a/
src/server/io.c
+++ b/
src/server/io.c
@@
-13,7
+13,7
@@
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, UINT8_MAX */
#include <stdio.h> /* defines FILE, sprintf(), fprintf() */
#include <stdlib.h> /* free() */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, UINT8_MAX */
#include <stdio.h> /* defines FILE, sprintf(), fprintf() */
#include <stdlib.h> /* free() */
-#include <string.h> /* strlen(), snprintf(), memcpy(),
memset(),
strchr() */
+#include <string.h> /* strlen(), snprintf(), memcpy(), strchr() */
#include <sys/types.h> /* time_t */
#include <time.h> /* time(), nanosleep() */
#include "../common/readwrite.h" /* atomic_write_start(), atomic_write_finish(),
#include <sys/types.h> /* time_t */
#include <time.h> /* time(), nanosleep() */
#include "../common/readwrite.h" /* atomic_write_start(), atomic_write_finish(),
@@
-24,6
+24,7
@@
#include "../common/try_malloc.h" /* try_malloc() */
#include "cleanup.h" /* set_cleanup_flag() */
#include "hardcoded_strings.h" /* s */
#include "../common/try_malloc.h" /* try_malloc() */
#include "cleanup.h" /* set_cleanup_flag() */
#include "hardcoded_strings.h" /* s */
+#include "map.h" /* init_empty_map() */
#include "run.h" /* send_to_outfile() */
#include "things.h" /* Thing, ThingType, ThingInMemory, ThingAction,
* get_thing_type(), get_player()
#include "run.h" /* send_to_outfile() */
#include "things.h" /* Thing, ThingType, ThingInMemory, ThingAction,
* get_thing_type(), get_player()
@@
-262,13
+263,12
@@
static void write_inventory(struct Thing * player, FILE * file)
static char * build_visible_map(struct Thing * player)
{
static char * build_visible_map(struct Thing * player)
{
- uint32_t map_size = world.map.length * world.map.length;
- char * visible_map = try_malloc(map_size, __func__);
- memset(visible_map, ' ', map_size);
+ char * visible_map;
+ init_empty_map(&visible_map);
if (player->fov_map) /* May fail if player thing was created / positioned */
{ /* by god command after turning off FOV building. */
if (player->fov_map) /* May fail if player thing was created / positioned */
{ /* by god command after turning off FOV building. */
- uint32_t pos_i;
- for (
pos_i = 0; pos_i < map_size
; pos_i++)
+ uint32_t pos_i
= 0
;
+ for (
; pos_i < (uint32_t) world.map.length * world.map.length
; pos_i++)
{
if (player->fov_map[pos_i] == 'v')
{
{
if (player->fov_map[pos_i] == 'v')
{
diff --git
a/src/server/map.c
b/src/server/map.c
index 4cce02ae3c5cd08831f96f0d0bb49b5f0224959d..3a5a0a213d1c6f8f644739f1410a0778bb66a9fa 100644
(file)
--- a/
src/server/map.c
+++ b/
src/server/map.c
@@
-8,6
+8,7
@@
#include "map.h"
#include <stdint.h> /* uint8_t, int8_t, uint16_t, uint32_t, (U)INT*_(MIN|MAX) */
#include <stdlib.h> /* free() */
#include "map.h"
#include <stdint.h> /* uint8_t, int8_t, uint16_t, uint32_t, (U)INT*_(MIN|MAX) */
#include <stdlib.h> /* free() */
+#include <string.h> /* memset() */
#include "../common/rexit.h" /* exit_err() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
#include "../common/rexit.h" /* exit_err() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
@@
-230,3
+231,11
@@
extern uint8_t mv_yx_in_dir_legal(char dir, struct yx_uint8 * yx)
}
return 0;
}
}
return 0;
}
+
+
+
+extern void init_empty_map(char ** map)
+{
+ *map = try_malloc(world.map.length * world.map.length, __func__);
+ memset(*map, ' ', world.map.length * world.map.length);
+}
diff --git
a/src/server/map.h
b/src/server/map.h
index 9f09c02fcf64df87777e29e9759bde9778bb43e0..d9ebf7476fc8a38f584a8dd1c29f42b8012065d1 100644
(file)
--- a/
src/server/map.h
+++ b/
src/server/map.h
@@
-40,6
+40,8
@@
extern void remake_map();
*/
extern uint8_t mv_yx_in_dir_legal(char dir, struct yx_uint8 * yx);
*/
extern uint8_t mv_yx_in_dir_legal(char dir, struct yx_uint8 * yx);
+/* Initialize (empty) map array at "map". */
+extern void init_empty_map(char ** map);
#endif
#endif