Aw query 5x5

From ActiveWiki
Jump to: navigation, search


Minimum requirements
Added in version 3.2
SDKbuild 21
Worldbuild 33


int aw_query_5x5 (int x_sector, int z_sector, int sequence[5][5])

Description

Queries for property in a five by five sector area.

Callback

AW_CALLBACK_QUERY

Notes

This method functions identically to aw_query except that it queries a five by five sector area instead of a three by three sector area. This allows the application to query a larger area (200 meters in all directions) in a single call.

For a complete description of how to user this method, see aw_query and Property.

Arguments

x_sector
z_sector
sequence

Argument attributes

None

Return values

RC_SUCCESS (1) (2)
RC_NOT_INITIALIZED (1)
RC_NO_INSTANCE (1)
RC_NO_CONNECTION (1)
The connection to the world is down.
RC_QUERY_IN_PROGRESS (1)
RC_TIMEOUT

(1) Possible return values when a callback is installed.

(2) Returned by the world server.

Returned attributes

AW_QUERY_COMPLETE

Usage

Count the number of objects in the 5x5 sector area around 500N 500W.

int sequence[5][5];
int object_count;

void handle_cell_begin (void)
{
  int cell_x = aw_int (AW_CELL_X);
  int cell_z = aw_int (AW_CELL_Z);
  int sector_x = aw_sector_from_cell (cell_x);
  int sector_z = aw_sector_from_cell (cell_z);
  
  if (sector_x < -2 || sector_x > 2 || sector_z < -2 || sector_z > 2)
    return;
  
  sequence[sector_z + 2][sector_x + 2] = aw_int (AW_CELL_SEQUENCE);
}

void handle_cell_object (void)
{
  object_count += 1;
}

int main (int argc, char *argv[])
{
  int rc;
  
  /* ... */
  
  aw_event_set (AW_EVENT_CELL_BEGIN, handle_cell_begin);
  aw_event_set (AW_EVENT_CELL_OBJECT, handle_cell_object);
  
  memset (sequence, 0, sizeof (sequence));
  
  for (;;)
  {
    rc = aw_query_5x5 (0, 0, sequence);
    if (rc != RC_SUCCESS)
    {
      printf ("Query failed (reason %d)\n", rc);
      return 0;
    }
    if (!aw_bool (AW_QUERY_COMPLETE))
      break;
  }
  
  printf ("%d objects at sector (0, 0)\n", object_count);   
  
  /* ... */
  
  return 0;
}

This trick allows an application to immediately receive AW_EVENT_OBJECT_ADD and AW_EVENT_OBJECT_DELETE events for an area.

 int sequence[5][5];
 
 memset (sequence, -1, sizeof (sequence));
 aw_query_5x5 (query_x, query_z, sequence);

See also