diff options
author | panikon <panikon@zoho.com> | 2014-07-22 16:54:38 -0300 |
---|---|---|
committer | panikon <panikon@zoho.com> | 2014-07-22 16:55:58 -0300 |
commit | ca39e47dc650e60bff54a8d276d8f7126ad1a5df (patch) | |
tree | fdd9767d2363652d53ce706ae722ab84ad223284 | |
parent | 9a36b78fc3d07be4ad4d352df41e5ca5a90aa742 (diff) | |
download | hercules-ca39e47dc650e60bff54a8d276d8f7126ad1a5df.tar.gz hercules-ca39e47dc650e60bff54a8d276d8f7126ad1a5df.tar.bz2 hercules-ca39e47dc650e60bff54a8d276d8f7126ad1a5df.tar.xz hercules-ca39e47dc650e60bff54a8d276d8f7126ad1a5df.zip |
Fixed some issues with CELL_NOSTACK
- Crashing issue when loading maps using map cache (issue: 8270) http://hercules.ws/board/tracker/issue-8270-enable-cell-nostack-crash/
- Counter was not being decrease correctly when leaving a cell
Merged map_addblcell and map_delblcell
-rw-r--r-- | src/map/map.c | 58 | ||||
-rw-r--r-- | src/map/map.h | 5 |
2 files changed, 35 insertions, 28 deletions
diff --git a/src/map/map.c b/src/map/map.c index a89478cb1..b254b6792 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -167,31 +167,32 @@ int map_freeblock_timer(int tid, int64 tick, int id, intptr_t data) { return 0; } -/*========================================== - * These pair of functions update the counter of how many objects - * lie on a tile. - *------------------------------------------*/ -void map_addblcell(struct block_list *bl) { +/** + * Updates the counter (cell.cell_bl) of how many objects are on a tile. + * @param add Whether the counter should be increased or decreased + **/ +void map_update_cell_bl( struct block_list *bl, bool increase ) { #ifdef CELL_NOSTACK + int pos; + if( bl->m < 0 || bl->x < 0 || bl->x >= map->list[bl->m].xs || bl->y < 0 || bl->y >= map->list[bl->m].ys || !(bl->type&BL_CHAR) ) return; - map->list[bl->m].cell[bl->x+bl->y*map->list[bl->m].xs].cell_bl++; -#else - return; -#endif -} -void map_delblcell(struct block_list *bl) { -#ifdef CELL_NOSTACK - if( bl->m < 0 || bl->x < 0 || bl->x >= map->list[bl->m].xs - || bl->y < 0 || bl->y >= map->list[bl->m].ys - || !(bl->type&BL_CHAR) ) - map->list[bl->m].cell[bl->x+bl->y*map->list[bl->m].xs].cell_bl--; -#else - return; + // When reading from mapcache the cell isn't initialized + // TODO: Maybe start initializing cells when they're loaded instead of + // having to get them here? [Panikon] + if( map->list[bl->m].cell == (struct mapcell *)0xdeadbeaf ) + map->cellfromcache(&map->list[bl->m]); + + pos = bl->x + bl->y*map->list[bl->m].xs; + if( increase ) + map->list[bl->m].cell[pos].cell_bl++; + else + map->list[bl->m].cell[pos].cell_bl--; #endif + return; } /*========================================== @@ -237,7 +238,7 @@ int map_addblock(struct block_list* bl) } #ifdef CELL_NOSTACK - map->addblcell(bl); + map->update_cell_bl(bl, true); #endif return 0; @@ -261,7 +262,7 @@ int map_delblock(struct block_list* bl) } #ifdef CELL_NOSTACK - map->delblcell(bl); + map->update_cell_bl(bl, false); #endif pos = bl->x/BLOCK_SIZE+(bl->y/BLOCK_SIZE)*map->list[bl->m].bxs; @@ -319,13 +320,13 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { if (moveblock) map->delblock(bl); #ifdef CELL_NOSTACK - else map->delblcell(bl); + else map->update_cell_bl(bl, false); #endif bl->x = x1; bl->y = y1; if (moveblock) map->addblock(bl); #ifdef CELL_NOSTACK - else map->addblcell(bl); + else map->update_cell_bl(bl, true); #endif if (bl->type&BL_CHAR) { @@ -2521,8 +2522,13 @@ void map_cellfromcache(struct map_data *m) { decode_zip(decode_buffer, &size, m->cellPos+sizeof(struct map_cache_map_info), info->len); CREATE(m->cell, struct mapcell, size); - for( xy = 0; xy < size; ++xy ) + // Set cell properties + for( xy = 0; xy < size; ++xy ) { m->cell[xy] = map->gat2cell(decode_buffer[xy]); +#ifdef CELL_NOSTACK + m->cell[xy].cell_bl = 0; +#endif + } m->getcellp = map->getcellp; m->setcell = map->setcell; @@ -3293,6 +3299,9 @@ int map_readgat (struct map_data* m) type = 3; // Cell is 0 (walkable) but under water level, set to 3 (walkable water) m->cell[xy] = map->gat2cell(type); +#ifdef CELL_NOSTACK + m->cell[xy].cell_bl = 0; +#endif } aFree(gat); @@ -6126,8 +6135,7 @@ void map_defaults(void) { map->versionscreen = map_versionscreen; map->arg_next_value = map_arg_next_value; - map->addblcell = map_addblcell; - map->delblcell = map_delblcell; + map->update_cell_bl = map_update_cell_bl; map->get_new_bonus_id = map_get_new_bonus_id; diff --git a/src/map/map.h b/src/map/map.h index 35fe0d7e1..4f7f09131 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -486,7 +486,7 @@ struct mapcell { icewall : 1; #ifdef CELL_NOSTACK - unsigned char cell_bl; //Holds amount of bls in this cell. + int cell_bl; //Holds amount of bls in this cell. #endif }; @@ -1059,8 +1059,7 @@ struct map_interface { void (*helpscreen) (bool do_exit); void (*versionscreen) (bool do_exit); bool (*arg_next_value) (const char *option, int i, int argc, bool must); - void (*addblcell) (struct block_list *bl); - void (*delblcell) (struct block_list *bl); + void (*update_cell_bl) (struct block_list *bl, bool increase); int (*get_new_bonus_id) (void); void (*add_questinfo) (int m, struct questinfo *qi); bool (*remove_questinfo) (int m, struct npc_data *nd); |