ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
Subject: Scanning objects (jeanphi) (Sdk)
Subject: Scanning objects (jeanphi) // Sdkdecastro@cable.a2000.nl (xelag)Feb 8, 1999, 8:26am
Hi jeanphi:
A short diggression about querying in Delphi. Before starting, I install the following: procedure InstallBuild(); var rc, x, z: Integer; begin aw_kallback_set(AW_CALLBACK_QUERY, at cbkQuery); rc := aw_event_set(AW_EVENT_CELL_BEGIN, at evtCellBegin); rc := aw_event_set(AW_EVENT_CELL_OBJECT, at evtCellObject); rc := aw_event_set(AW_EVENT_CELL_END, at evtCellEnd); rc := aw_event_set(AW_EVENT_OBJECT_ADD, at evtObjectAdd); rc := aw_event_set(AW_EVENT_OBJECT_DELETE, at evtObjectDelete); aw_kallback_set(AW_CALLBACK_OBJECT_RESULT, at cbkObjectResult); end; Then I calculate the cell (cNS, cWE) and sector (sNS, sWE) coords for a given position (pNS, pWE) in cm: procedure SectorFromPosition(pNS, pWE: Integer; var cNS, cWE, sNS, sWE: Integer); begin cNS := Round((pNS-499.5)/1000); {is NOT the central cell of sector} cWE := Round((pWE-499.5)/1000); sNS := aw_sector_from_cell(cNS); {central sector of the zone} sWE := aw_sector_from_cell(cWE); end; Your Sequence[<NS from 0 to 2>, <WE from 0 to 2>] array has the following meaning: - each pair "represents" a sector of your 9-sector zone, organised so: (2,2) NW | (2,1) NC | (2,0) NE .... (0,2) SW | (0,1) SC | (0,0) SE the central (2,1) representing your sNS, sWE calculated above. This array of integers should contain zeros or a valid sequence from a previous query, and will be updated in the following order: (1,1), (0,0) etc as in this diagram (thanks Canopus for this tip): 9 8 7 6 1 5 4 3 2 If you use multi-instances, dont forget to set your intstance before querying. aw_instance_set(Instance); rc := aw_query (sWE, sNS, Sector); where Sector, of type SectorSeqs, is my Sequence array in disguise: type SectorSeqs = Array[0..2, 0..2] of Integer; NB: in aw_query you pass in this order: WE, NS, but in the Sequence array the order is reversed: NS, WE! If everything went right, this should start off the query, getting events: AW_EVENT_CELL_BEGIN, my evtCellBegin with the following attributes: aw_instance; aw_int(AW_CELL_Z); aw_int(AW_CELL_X); aw_int(AW_CELL_SIZE); aw_int(AW_CELL_SEQUENCE); and a series of AW_EVENT_CELL_OBJECT, my evtCellObject with attributes: aw_instance; aw_int(AW_OBJECT_NUMBER); aw_int(AW_OBJECT_OWNER); aw_int(AW_OBJECT_BUILD_TIMESTAMP); aw_int(AW_OBJECT_Z); aw_int(AW_OBJECT_X); aw_int(AW_OBJECT_Y); aw_int(AW_OBJECT_YAW); aw_string(AW_OBJECT_MODEL); aw_string(AW_OBJECT_DESCRIPTION); aw_string(AW_OBJECT_ACTION); followed by a useless event AW_EVENT_CELL_END This CellBegin to CellEnd will repeat itself, and then: if you didnt install the the callback AW_CALLBACK_QUERY then aw_query will block until all this is done. If you installed the callback, then this series of events ends inthis callback, my cbkQuery(rc: Integer), where you can retreive the following attributes: aw_instance; aw_bool(AW_QUERY_COMPLETE); If AW_QUERY_COMPLETE is false, you must call aw_query again to continue the query (if you wish a complete query). If it is true, then the query is complete, and live update starts if the event handlers aw_event_set(AW_EVENT_OBJECT_ADD, at evtObjectAdd); aw_event_set(AW_EVENT_OBJECT_DELETE, at evtObjectDelete); are installed. This is the first part of the story. It's in AW_EVENT_CELL_OBJECT where you can test whether your required object was found. XelaG. -- Xelagot 46ADB [Delph] creator: XelaG email: decastro at cable.a2000.nl decastro@cable.a2000.nl (xelag)Feb 8, 1999, 8:29am
Errata:
the central (2,1) representing your sNS, sWE calculated above. This array of integers should contain zeros or a valid sequence from a previous query, and will be updated in the following order: (1,1), (0,0) etc as in this diagram (thanks Canopus for this tip): should read: the central (1,1) .... etc... -- Xelagot 46ADB [Delph] creator: XelaG email: decastro at cable.a2000.nl decastro@cable.a2000.nl (xelag)Feb 8, 1999, 8:59am
Another clarification. In
AW_EVENT_CELL_BEGIN cNS := aw_int(AW_CELL_Z) cWE := aw_int(AW_CELL_X) qSeq := aw_int(AW_CELL_SEQUENCE) sxNS := aw_sector_from_cell(cNS); sxWE := aw_sector_from_cell(cWE); sapNS := sxNS - sNS + 1; sapWE := sxWE - sWE + 1; where sNS, sWE are the central sector coords as calculated above. Overflow := (sapNS < 0) or (sapNS > 2) or (sapWE < 0) or (sapWE > 2); Update the Sequence array, if not Overflow: Sector[sapNS, sapWE] := qSeq; XelaG. -- Xelagot 46ADB [Delph] creator: XelaG email: decastro at cable.a2000.nl |