From 780a0d771edbe21dcfa3405163ffbdf7f7fa4604 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Mon, 13 Oct 2014 13:16:34 -0700 Subject: Convert container lookups to use Option> --- src/map/map.hpp | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'src/map/map.hpp') diff --git a/src/map/map.hpp b/src/map/map.hpp index aeb8821..cb4273f 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -98,11 +98,13 @@ struct NpcEvent }; bool extract(XString str, NpcEvent *ev); +extern map_local undefined_gat; + struct block_list { dumb_ptr bl_next, bl_prev; BlockId bl_id; - map_local *bl_m; + Borrowed bl_m = borrow(undefined_gat); short bl_x, bl_y; BL bl_type; @@ -186,7 +188,19 @@ struct map_session_data : block_list, SessionData unsigned char tmw_version; // tmw client version CharKey status_key; CharData status; - GenericArray> inventory_data; + GenericArray>, InventoryIndexing> inventory_data = + {{ + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + }}; // explicit is better than implicit earray equip_index_maybe; int weight, max_weight; MapName mapname_; @@ -206,7 +220,7 @@ struct map_session_data : block_list, SessionData int npc_amount; // I have no idea exactly what these are doing ... // but one should probably be replaced with a ScriptPointer ??? - const ScriptBuffer *npc_script, *npc_scriptroot; + Option> npc_script = None, npc_scriptroot = None; std::vector npc_stackbuf; RString npc_str; struct @@ -433,7 +447,7 @@ struct mob_data : block_list MobMode mode; struct { - map_local *m; + Borrowed m = borrow(undefined_gat); short x0, y0, xs, ys; interval_t delay1, delay2; } spawn; @@ -508,6 +522,8 @@ struct map_abstract // gat is nullptr for map_remote and non-nullptr for map_local std::unique_ptr gat; + map_abstract() = default; + map_abstract(map_abstract&&) = default; virtual ~map_abstract() {} }; extern @@ -532,7 +548,7 @@ struct map_remote : map_abstract }; inline -MapCell read_gatp(map_local *m, int x, int y) +MapCell read_gatp(Borrowed m, int x, int y) { assert (0 <= x && x < m->xs); assert (0 <= y && y < m->ys); @@ -574,21 +590,21 @@ public: int map_addblock(dumb_ptr); int map_delblock(dumb_ptr); void map_foreachinarea(std::function)>, - map_local *, + Borrowed, int, int, int, int, BL); // -- moonsoul (added map_foreachincell) void map_foreachincell(std::function)>, - map_local *, + Borrowed, int, int, BL); void map_foreachinmovearea(std::function)>, - map_local *, + Borrowed, int, int, int, int, int, int, BL); //block関連に追加 -int map_count_oncell(map_local *m, int x, int y); +int map_count_oncell(Borrowed m, int x, int y); // 一時的object関連 BlockId map_addobject(dumb_ptr); void map_delobject(BlockId, BL type); @@ -598,7 +614,7 @@ void map_foreachobject(std::function)>, // void map_quit(dumb_ptr); // npc -int map_addnpc(map_local *, dumb_ptr); +int map_addnpc(Borrowed, dumb_ptr); void map_log(XString line); #define MAP_LOG(format, ...) \ @@ -606,7 +622,7 @@ void map_log(XString line); #define MAP_LOG_PC(sd, fmt, ...) \ MAP_LOG("PC%d %s:%d,%d " fmt, \ - sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish("undefined.gat"_s)), sd->bl_x, sd->bl_y, ## __VA_ARGS__) + sd->status_key.char_id, (sd->bl_m->name_), sd->bl_x, sd->bl_y, ## __VA_ARGS__) // 床アイテム関連 void map_clearflooritem_timer(TimerData *, tick_t, BlockId); @@ -616,11 +632,11 @@ void map_clearflooritem(BlockId id) map_clearflooritem_timer(nullptr, tick_t(), id); } BlockId map_addflooritem_any(Item *, int amount, - map_local *m, int x, int y, + Borrowed m, int x, int y, dumb_ptr *owners, interval_t *owner_protection, interval_t lifetime, int dispersal); BlockId map_addflooritem(Item *, int, - map_local *, int, int, + Borrowed, int, int, dumb_ptr, dumb_ptr, dumb_ptr); @@ -665,8 +681,8 @@ dumb_ptr map_id_is_spell(BlockId id) } -map_local *map_mapname2mapid(MapName); -int map_mapname2ipport(MapName, IP4Address *, int *); +Option> map_mapname2mapid(MapName); +int map_mapname2ipport(MapName, Borrowed, Borrowed); int map_setipport(MapName name, IP4Address ip, int port); void map_addiddb(dumb_ptr); void map_deliddb(dumb_ptr bl); @@ -683,14 +699,14 @@ dumb_ptr map_get_prev_session( dumb_ptr current); // gat関連 -MapCell map_getcell(map_local *, int, int); -void map_setcell(map_local *, int, int, MapCell); +MapCell map_getcell(Borrowed, int, int); +void map_setcell(Borrowed, int, int, MapCell); // その他 bool map_check_dir(DIR s_dir, DIR t_dir); DIR map_calc_dir(dumb_ptr src, int x, int y); -std::pair map_randfreecell(map_local *m, +std::pair map_randfreecell(Borrowed m, uint16_t x, uint16_t y, uint16_t w, uint16_t h); inline dumb_ptr block_list::as_player() { return dumb_ptr(static_cast(this)) ; } -- cgit v1.2.3-60-g2f50