--- deliantra/server/socket/request.C 2006/08/13 17:16:06 1.1 +++ deliantra/server/socket/request.C 2006/08/17 20:23:32 1.2 @@ -1,6 +1,6 @@ /* * static char *rcsid_init_c = - * "$Id: request.C,v 1.1 2006/08/13 17:16:06 elmex Exp $"; + * "$Id: request.C,v 1.2 2006/08/17 20:23:32 root Exp $"; */ /* @@ -106,39 +106,114 @@ -1 /* Disease - not fully done yet */ }; +static void +socket_map_scroll (NewSocket *ns, int dx, int dy) +{ + struct Map newmap; + int x,y, mx, my; + + { + char buf[MAXSOCKBUF]; + + sprintf(buf,"map_scroll %d %d", dx, dy); + Write_String_To_Socket(ns, buf, strlen (buf)); + } + + /* If we are using the Map1aCmd, we may in fact send + * head information that is outside the viewable map. + * So set the mx,my to the max value we want to + * look for. Removed code to do so - it caused extra + * complexities for the client, and probably doesn't make + * that much difference in bandwidth. + */ + mx = ns->mapx; + my = ns->mapy; + + if (ns->mapmode == Map1aCmd) { + mx += MAX_HEAD_OFFSET; + my += MAX_HEAD_OFFSET; + } + + /* the x and y here are coordinates for the new map, i.e. if we moved + * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, + * if the destination x or y coordinate is outside the viewable + * area, we clear the values - otherwise, the old values + * are preserved, and the check_head thinks it needs to clear them. + */ + for(x=0; x= ns->mapx || y >= ns->mapy) { + /* clear cells outside the viewable area */ + memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); + } + else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { + /* clear newly visible tiles within the viewable area */ + memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); + } + else { + memcpy(&(newmap.cells[x][y]), + &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); + } + } + } + + memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); + + /* Make sure that the next "map1" command will be sent (even if it is + * empty). + */ + ns->sent_scroll = 1; +} + /** check for map change and send new map data */ static void check_map_change (player *pl) { + NewSocket &socket = pl->socket; + object *ob = pl->ob; char buf[MAX_BUF]; /* eauugggh */ - object *ob = pl->ob; + if (socket.current_map != ob->map) + { + socket.current_map = ob->map; + memset (&socket.lastmap, 0, sizeof(socket.lastmap)); - if (!pl->socket.mapinfocmd) - return; + if (socket.newmapcmd == 1) + Write_String_To_Socket (&socket, "newmap", 6); - if (pl->socket.current_map != ob->map) - { - pl->socket.current_map = ob->map; + socket.update_look = 1; + socket.look_position =0; - if (ob->map && ob->map->path [0]) + if (socket.mapinfocmd) { - int flags = 0; + if (ob->map && ob->map->path [0]) + { + int flags = 0; - if (ob->map->tile_path [0]) flags |= 1; - if (ob->map->tile_path [1]) flags |= 2; - if (ob->map->tile_path [2]) flags |= 4; - if (ob->map->tile_path [3]) flags |= 8; - - snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s", - flags, pl->socket.mapx / 2 - ob->x, pl->socket.mapy / 2 - ob->y, - ob->map->width, ob->map->height, ob->map->path); - } - else - snprintf (buf, MAX_BUF, "mapinfo current"); + if (ob->map->tile_path [0]) flags |= 1; + if (ob->map->tile_path [1]) flags |= 2; + if (ob->map->tile_path [2]) flags |= 4; + if (ob->map->tile_path [3]) flags |= 8; + + snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s", + flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, + ob->map->width, ob->map->height, ob->map->path); + } + else + snprintf (buf, MAX_BUF, "mapinfo current"); - Write_String_To_Socket (&pl->socket, buf, strlen (buf)); + Write_String_To_Socket (&socket, buf, strlen (buf)); + } } + else if (socket.current_x != ob->x || socket.current_y != ob->y) + { + socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); + socket.update_look = 1; + socket.look_position = 0; + } + + socket.current_x = ob->x; + socket.current_y = ob->y; } void ExtCmd (char *buf, int len, player *pl) @@ -790,18 +865,6 @@ #endif } -/** Newmap command */ -void MapNewmapCmd( player *pl) -{ - if( pl->socket.newmapcmd == 1) { - memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); - Write_String_To_Socket( &pl->socket, "newmap", 6); - } - pl->socket.current_map = 0; -} - - - /** * Moves an object (typically, container to inventory). * syntax is: move (to) (tag) (nrof) @@ -1563,6 +1626,8 @@ uint8 extendedinfos; mapstruct *m; + check_map_change (pl->contr); + sl.buf=(unsigned char*)malloc(MAXSOCKBUF); if (pl->contr->socket.mapmode == Map1Cmd) strcpy((char*)sl.buf,"map1 "); @@ -1851,8 +1916,6 @@ pl->contr->socket.sent_scroll = 0; } free(sl.buf); - - check_map_change (pl->contr); } /** @@ -1980,61 +2043,6 @@ } -void esrv_map_scroll(NewSocket *ns,int dx,int dy) -{ - struct Map newmap; - int x,y, mx, my; - char buf[MAXSOCKBUF]; - - sprintf(buf,"map_scroll %d %d", dx, dy); - Write_String_To_Socket(ns, buf, strlen(buf)); - - /* If we are using the Map1aCmd, we may in fact send - * head information that is outside the viewable map. - * So set the mx,my to the max value we want to - * look for. Removed code to do so - it caused extra - * complexities for the client, and probably doesn't make - * that much difference in bandwidth. - */ - mx = ns->mapx; - my = ns->mapy; - - if (ns->mapmode == Map1aCmd) { - mx += MAX_HEAD_OFFSET; - my += MAX_HEAD_OFFSET; - } - - /* the x and y here are coordinates for the new map, i.e. if we moved - * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, - * if the destination x or y coordinate is outside the viewable - * area, we clear the values - otherwise, the old values - * are preserved, and the check_head thinks it needs to clear them. - */ - for(x=0; x= ns->mapx || y >= ns->mapy) { - /* clear cells outside the viewable area */ - memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); - } - else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { - /* clear newly visible tiles within the viewable area */ - memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); - } - else { - memcpy(&(newmap.cells[x][y]), - &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); - } - } - } - - memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); - - /* Make sure that the next "map1" command will be sent (even if it is - * empty). - */ - ns->sent_scroll = 1; -} - /*****************************************************************************/ /* GROS: The following one is used to allow a plugin to send a generic cmd to*/ /* a player. Of course, the client need to know the command to be able to */