Changes between Version 32 and Version 33 of ProtocolOne


Ignore:
Timestamp:
Jun 29, 2011 1:52:21 PM (13 years ago)
Author:
jherwitz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ProtocolOne

    v32 v33  
    4545The user may choose to execute commands by either explicitly instantiating the command objects or calling a relevant function. Internally, all commands are represented as command-specific objects. These objects handle writing the specified command to the server, automatically update data fields with any relevant server data response, and maintain auxiliary data related to the command, such as command [[exitcode]] and runtime. To execute a command explicitly using the object, simply call the member function {{{run()}}}. Function calls automatically instantiate, run, and return the relevant object.
    4646It is important to note that all Commands are implemented as [http://download.oracle.com/javase/1.4.2/docs/api/java/util/TimerTask.html TimerTasks], so a user may easily implement an application involving high-level scheduling or planning using [http://download.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html Timers] (this is actually how the periodic execution is implemented).
    47 It is recommended that users new to Quagents use the command functions, as these provide a more intuitive command interface and also allow the client to record any results in its command history (although this may be moved into the Command class to ensure identical functionality between both methods of execution).
     47It is recommended that users new to Quagents use the command functions, as these provide a more intuitive command interface and also allow the client to record any results in its command history (although this may be moved into the Command class to ensure identical functionality between both methods of execution). Command objects may be reused an arbitrary number of times, to reexecute the same command.
    4848
    4949''Example''
    50 The following two code blocks are identical.
     50The following two code blocks are functionally identical.
    5151''Functional''
    5252{{{
     
    5555''Object-Oriented''
    5656{{{
    57 FireWeapon fw = new FireWeapon();
     57FireWeapon fw = new FireWeapon(2, client.qid, client.getWriter());
    5858fw.run();
    5959}}}
     
    6161
    6262= Retrieving Data =
    63 Client/Server data response in Quagents 3 is asynchronous. Thus, the object-oriented and functional methods of execution do not directly return related data. Instead, the user gets a reference to the related command object. This object automatically updates data specific to itself as it is read from the socket. The user must poll this object using object query functions to gain access to data. The following example illustrates this interaction.
     63Client/Server data response in Quagents 3 is asynchronous. Thus, the object-oriented and functional methods of execution do not directly return related data. Instead, the user gets a reference to the related command object. This object automatically updates data specific to itself as it is read from the socket. The user must poll this object using object query functions to gain access to data. '''It is important to note that these object poll functions block for a response from the server.''' The following example illustrates the interaction.
    6464
    65 The following is an example of a complete Quagents session:
     65''Example''
     66The following code blocks are functionally identical. The functionality of the code is to access the Quagent's current health.
    6667{{{
    67 Client quagent = new Client("127.0.0.1");
    68 
    69 //begin initial phase
    70 quagent.name("Billy");
    71 //end initial phase
    72 quagent.ready();
    73 //begin live phase
    74 quagent.
     68client.currentHealth().getCurrentHealth();
     69}}}
     70{{{
     71CurrentHealth ch = new CurrentHealth(1, client.qid, client.getWriter());
     72ch.getCurrentHealth();
     73}}}
     74{{{
     75CurrentHealth ch = client.currentHealth();
     76ch.getCurrentHealth();
    7577}}}
    7678
    77 Note that using multiple quagents is as simple as creating a new Client object, and following the same steps as above for each.
     79= Periodic Commands =
     80The clientside structure has built-in support for periodic commands. Simply add an integer parameter to the end of any command function or constructor and the client will automatically execute the command systematically using the integer as the period. These commands are useful when it is desired
    7881
    79 = Class structure = 
     82''Example''
     83The following illustrates the usage of a periodic command.
     84{{{
     85CurrentArmor updatedarmor = client.currentArmor(1000);
     86
     87//arbitrary code
     88
     89//now, we can call this whenever we want the Quagent's current armor,
     90from the nearest second.
     91updatedarmor.getCurrentArmor();
     92}}}
     93
     94= Multiple Quagents
     95Using multiple quagents is as simple as creating multiple Client objects, and following the same steps as above for each.
     96
     97''Example''
     98{{{
     99                Client client = new Client("127.0.0.1");
     100                Client client2 = new Client("127.0.0.1");
     101                Client client3 = new Client("127.0.0.1");
     102                client.name("Bo");
     103                client2.name("Luke");
     104                client3.name("Daisy");
     105                client.ready();
     106                client2.ready();
     107                client2.moveForever();
     108                client2.followEntity(client.qid);
     109                client3.ready();
     110                client3.switchWeapon(weapon.SHOTGUN);
     111                client3.say("Y'all get back here!");
     112}}}
     113
    80114
    81115= Example behaviors =