Update of /cvsroot/playerstage/code/player/server/drivers/map
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10946/server/drivers/map

Modified Files:
        mapfile.cc maptransform.cc vmapfile.cc 
Log Message:
applied Toby's patch to replace fixed-size arrays

Index: mapfile.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/map/mapfile.cc,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** mapfile.cc  21 Sep 2007 03:31:51 -0000      1.31
--- mapfile.cc  1 Nov 2007 22:16:19 -0000       1.32
***************
*** 336,340 ****
      si = mapresp->width = mapreq->width;
      sj = mapresp->height = mapreq->height;
! 
      // Grab the pixels from the map
      for(j = 0; j < sj; j++)
--- 336,341 ----
      si = mapresp->width = mapreq->width;
      sj = mapresp->height = mapreq->height;
!     mapresp->data_count = mapresp->width * mapresp->height;
!     mapresp->data = new int8_t [mapresp->data_count];
      // Grab the pixels from the map
      for(j = 0; j < sj; j++)
***************
*** 342,381 ****
        for(i = 0; i < si; i++)
        {
!         if((i * j) <= PLAYER_MAP_MAX_TILE_SIZE)
!         {
!           if(MAP_VALID(this, i + oi, j + oj))
!             mapresp->data[i + j * si] = this->mapdata[MAP_IDX(this, i+oi, 
j+oj)];
!           else
!           {
!             PLAYER_WARN2("requested cell (%d,%d) is offmap", i+oi, j+oj);
!             mapresp->data[i + j * si] = 0;
!           }
!         }
          else
          {
!           PLAYER_WARN("requested tile is too large; truncating");
!           if(i == 0)
!           {
!             mapresp->width = si-1;
!             mapresp->height = j-1;
!           }
!           else
!           {
!             mapresp->width = i;
!             mapresp->height = j;
!           }
          }
        }
      }
  
-     // recompute size, in case the tile got truncated
-     //mapsize = (sizeof(player_map_data_t) - PLAYER_MAP_MAX_TILE_SIZE + 
-                //(mapresp->width * mapresp->height));
-     mapresp->data_count = mapresp->width * mapresp->height;
-     
      this->Publish(this->device_addr, resp_queue,
                    PLAYER_MSGTYPE_RESP_ACK,
                    PLAYER_MAP_REQ_GET_DATA,
!                   (void*)mapresp, mapsize, NULL);
      free(mapresp);
      return(0);
--- 343,361 ----
        for(i = 0; i < si; i++)
        {
!         if(MAP_VALID(this, i + oi, j + oj))
!           mapresp->data[i + j * si] = this->mapdata[MAP_IDX(this, i+oi, 
j+oj)];
          else
          {
!           PLAYER_WARN2("requested cell (%d,%d) is offmap", i+oi, j+oj);
!           mapresp->data[i + j * si] = 0;
          }
        }
      }
  
      this->Publish(this->device_addr, resp_queue,
                    PLAYER_MSGTYPE_RESP_ACK,
                    PLAYER_MAP_REQ_GET_DATA,
!                   (void*)mapresp);
!     delete [] mapresp->data;
      free(mapresp);
      return(0);

Index: vmapfile.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/map/vmapfile.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** vmapfile.cc 23 Aug 2007 19:58:44 -0000      1.4
--- vmapfile.cc 1 Nov 2007 22:16:19 -0000       1.5
***************
*** 162,165 ****
--- 162,166 ----
  
    this->vmap->segments_count = 0;
+   this->vmap->segments = NULL;
    got_origin = got_width = got_height = 0;
    while(!feof(fp))
***************
*** 200,203 ****
--- 201,208 ----
      if(sscanf(linebuf, "%d %d %d %d", &x0, &y0, &x1, &y1) == 4)
      {
+       this->vmap->segments = (player_segment_t*) realloc(
+         this->vmap->segments, 
+         (this->vmap->segments_count+1)*sizeof(this->vmap->segments[0])
+       );
        this->vmap->segments[this->vmap->segments_count].x0 = x0/1e3;
        this->vmap->segments[this->vmap->segments_count].y0 = y0/1e3;
***************
*** 205,213 ****
        this->vmap->segments[this->vmap->segments_count].y1 = y1/1e3;
        this->vmap->segments_count++;
-       if(this->vmap->segments_count == PLAYER_MAP_MAX_SEGMENTS)
-       {
-         PLAYER_WARN("too many segments in file; truncating");
-         break;
-       }
      }
      else
--- 210,213 ----
***************
*** 226,237 ****
    this->vmap->maxy = (h + oy)/1e3;
  
-   // Resize
-   this->vmapsize = (sizeof(player_map_data_vector_t) - 
-                     ((PLAYER_MAP_MAX_SEGMENTS - 
-                       this->vmap->segments_count) * 
-                      sizeof(player_segment_t)));
- 
-   this->vmap = (player_map_data_vector_t*)realloc(this->vmap,
-                                                   this->vmapsize);
    assert(this->vmap);
  
--- 226,229 ----
***************
*** 244,247 ****
--- 236,240 ----
  VMapFile::Shutdown()
  {
+   free(this->vmap->segments);
    free(this->vmap);
    return(0);
***************
*** 263,267 ****
                    PLAYER_MSGTYPE_RESP_ACK,
                    PLAYER_MAP_REQ_GET_VECTOR,
!                   (void*)this->vmap, this->vmapsize, NULL);
      return(0);
    }
--- 256,260 ----
                    PLAYER_MSGTYPE_RESP_ACK,
                    PLAYER_MAP_REQ_GET_VECTOR,
!                   (void*)this->vmap);
      return(0);
    }

Index: maptransform.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/map/maptransform.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** maptransform.cc     23 Aug 2007 19:58:44 -0000      1.2
--- maptransform.cc     1 Nov 2007 22:16:19 -0000       1.3
***************
*** 121,131 ****
    unsigned int si,sj;
  
!   reqlen = sizeof(player_map_data_t) - PLAYER_MAP_MAX_TILE_SIZE + 4;
!   data_req = (player_map_data_t*)calloc(1, reqlen);
    assert(data_req);
  
!   // Tile size
!   sy = sx = (int)sqrt(PLAYER_MAP_MAX_TILE_SIZE);
!   assert(sx * sy < (int)PLAYER_MAP_MAX_TILE_SIZE);
    oi=oj=0;
    while((oi < this->source_map.width) && (oj < this->source_map.height))
--- 121,129 ----
    unsigned int si,sj;
  
!   data_req = (player_map_data_t*)malloc(sizeof(player_map_data_t));
    assert(data_req);
  
!   // Tile size, limit to sensible default of about 640x640
!   sy = sx = 640;
    oi=oj=0;
    while((oi < this->source_map.width) && (oj < this->source_map.height))
***************
*** 216,220 ****
      PLAYER_MSG0(9,"ProcessMessage called for MapTransform Driver: 
PLAYER_MAP_REQ_GET_DATA");
      assert(new_data);
!       player_map_data_t & map_data = *reinterpret_cast<player_map_data_t *> 
(data);
  
      unsigned int i, j;
--- 214,220 ----
      PLAYER_MSG0(9,"ProcessMessage called for MapTransform Driver: 
PLAYER_MAP_REQ_GET_DATA");
      assert(new_data);
!     player_map_data_t & map_data = *reinterpret_cast<player_map_data_t *> 
(data);
!     player_map_data_t resp_data;
!     memcpy(&resp_data, &map_data, sizeof(map_data));
  
      unsigned int i, j;
***************
*** 227,230 ****
--- 227,232 ----
      sj = map_data.height;
      PLAYER_MSG4(9,"Block Requested is: %d,%d + %d,%d",oi,oj,si,sj);
+     resp_data.data_count = map_data.width * map_data.height;
+     resp_data.data = new int8_t [resp_data.data_count];
  
      // Grab the pixels from the map
***************
*** 233,264 ****
        for(i = 0; i < si; i++)
        {
!         if((i * j) <= PLAYER_MAP_MAX_TILE_SIZE)
!         {
!           if(MAP_VALID(new_map, i + oi, j + oj))
!             map_data.data[i + j * si] = this->new_data[MAP_IDX(new_map, i+oi, 
j+oj)];
!           else
!           {
!             PLAYER_WARN2("requested cell (%d,%d) is offmap", i+oi, j+oj);
!             map_data.data[i + j * si] = 0;
!           }
!         }
          else
          {
!           PLAYER_WARN("requested tile is too large; truncating");
!           if(i == 0)
!           {
!             map_data.width = (si-1);
!             map_data.height = (j-1);
!           }
!           else
!           {
!             map_data.width = (i);
!             map_data.height = (j);
!           }
          }
        }
      }
!     map_data.data_count = map_data.width * map_data.height;
!       Publish(device_addr, resp_queue, PLAYER_MSGTYPE_RESP_ACK, 
PLAYER_MAP_REQ_GET_DATA, &map_data, sizeof(map_data),NULL);
      return 0;
    }
--- 235,249 ----
        for(i = 0; i < si; i++)
        {
!         if(MAP_VALID(new_map, i + oi, j + oj))
!           resp_data.data[i + j * si] = this->new_data[MAP_IDX(new_map, i+oi, 
j+oj)];
          else
          {
!           PLAYER_WARN2("requested cell (%d,%d) is offmap", i+oi, j+oj);
!           resp_data.data[i + j * si] = 0;
          }
        }
      }
!     Publish(device_addr, resp_queue, PLAYER_MSGTYPE_RESP_ACK, 
PLAYER_MAP_REQ_GET_DATA, &resp_data);
!     delete [] resp_data.data;
      return 0;
    }


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to