home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 7 Games / 07-Games.zip / cycles.zip / CYCLES.DOC < prev    next >
Text File  |  1993-04-01  |  25KB  |  459 lines

  1.   COPYRIGHT
  2.  
  3.   The program to which this file relates is made available by IBM on an AS IS
  4.   basis.  Anyone receiving the program is considered to be licensed under IBM
  5.   copyrights to use the IBM-provided program in any way he or she deems fit,
  6.   including copying it and redistributing it.  No license under IBM patents
  7.   or patent applications is to be implied from this copyright license.
  8.  
  9.   Any user of the program should understand that IBM cannot provide technical
  10.   support for the program and will not be responsible for any consequences of
  11.   use of the program.
  12.  
  13.   Any person who transfers the program must include the IBM copyright notice,
  14.   this paragraph and the preceding two paragraphs in documentation
  15.   accompanying the program.
  16.  
  17.  
  18.                                                          CYCLES -- USER'S GUIDE
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.                                                                December 1, 1992
  27.  
  28.  
  29.                                                                   Bruce W. Dean
  30.                                                             bwdean@vnet.ibm.com
  31.  
  32.  
  33.                                                          APPC Market Enablement
  34.                                                                        Dept AB7
  35.                                                                   P.O.Box 12195
  36.                                                              RTP, NC 27709  USA
  37.  
  38.  
  39.   WHAT IS LIGHT CYCLES?
  40.   _____________________
  41.  
  42.                       Light Cycles is a multi-player video game in which each
  43.                       player controls a cycle driving across the screen.  The
  44.                       cycles can only turn at 90-degree angles and they leave a
  45.                       permanent trail behind them.  A cycle is out of the game
  46.                       when it crashes into the screen's borders or a cycle
  47.                       trail.  The last cycle alive wins.
  48.  
  49.                       Light Cycles is played across a network that supports
  50.                       APPC.  Each cycle can be located at a different machine,
  51.                       and the server program that calculates all the moves and
  52.                       collisions can run in an entirely separate machine, or in
  53.                       a machine running one or more cycle programs.  Each of
  54.                       the cycle programs communicates with the server program
  55.                       using two APPC conversations to provide a form of asyn-
  56.                       chronous communication between the two.
  57.  
  58.                       Light Cycles was written as a sample of APPC programming.
  59.                       The design objectives of this APPC sample were:
  60.  
  61.                       o   Implement a single Server program which services mul-
  62.                           tiple Clients simultaneously.
  63.  
  64.                       o   The communication between any Client and the Server
  65.                           is asynchronous,
  66.  
  67.                       o   and the program must be fun to run.
  68.  
  69.                       Light Cycles meets these objectives.  A typical operating
  70.                       scenario is this:  someone runs the program CYCLE.EXE
  71.                       (this person is known as the Originating Cycle).  The
  72.                       Originating Cycle then begins a game by specifying a
  73.                       Server to control the game.  This server provides the
  74.                       Originating Cycle with a list of Remote Cycles that could
  75.                       potentially be contacted by the Server.  The Originating
  76.                       Cycle selects those opponents that should be asked if
  77.                       they want to play.  The Server then starts CYCLE.EXE on
  78.                       each of the Remote Cycle's machines.  If the user at any
  79.                       of those machines answers that they'd like to play, they
  80.                       are entered into the game.  When all Remote Cycles have
  81.                       responded, anyone who is entered in the game can start
  82.                       play.
  83.  
  84.                       The rules of the game are simple: Each cycle moves around
  85.                       on the playing field until it hits a wall (either a
  86.                       playing field wall, or the trail left behind each moving
  87.                       Cycle).  When a Cycle hits a wall, that Cycle is out of
  88.                       the game.  When only one Cycle remains, that Cycle is
  89.                       deemed the winner.
  90.  
  91.                       During the game, at regular intervals, the Server calcu-
  92.                       lates the new position of all Cycles and sends a message
  93.                       to each Cycle with that information.  At any time during
  94.                       a game, any Cycle may notify the Server that it wants to
  95.                       turn.  The Server will then use the Cycle's new direction
  96.                       in its calculations until the Cycle sends another new
  97.                       direction.
  98.  
  99.  
  100.   PREREQUISITES
  101.   _____________
  102.  
  103.                       Before Light Cycles can be run over a network, the fol-
  104.                       lowing prerequistes must be satisfied:
  105.  
  106.                       1.  The machines that will run the cycle or server
  107.                           program must:
  108.  
  109.                           a.  Have OS/2 1.3 and Networking Services/2 OR OS/2
  110.                               2.0 and Extended Services installed
  111.  
  112.                       2.  The machine that an Originating Cycle can run on
  113.                           should be able to APING the Server machine.  While it
  114.                           is not actually necessary to configure the two
  115.                           machines to run APING, APING is an excellent tool for
  116.                           identifying APPC configuration errors.  It provides
  117.                           much more diagnostic information when a session
  118.                           cannot be established between two machines than the
  119.                           Light Cycles programs provide.
  120.  
  121.                       3.  The Server should be able to APING any of the Remote
  122.                           Cycles that it will contact to play a game.
  123.  
  124.                       NOTE:  APING is a separately available program that tests
  125.                       for APPC connectivity between two machines on a network
  126.                       by echoing data between the two machines.  APING is
  127.                       available on Compuserve (GO APPC).  The APING documenta-
  128.                       tion details how to configure your machines to run APPC.
  129.                       This document describes only how to add transaction
  130.                       program (TP) definitions to an already-configured APPC
  131.                       setup.
  132.  
  133.  
  134.   WORKSTATION CONFIGURATION
  135.   _________________________
  136.  
  137.  
  138.  
  139.   RUNNING AS AN ORIGINATING CYCLE
  140.  
  141.                       To run as an Originating Cycle on your machine, no addi-
  142.                       tional TPs need to be defined on your machine.  You just
  143.                       have to have CYCLE.EXE, and be able to APING the machine
  144.                       where the Cycles Server is installed and configured.
  145.  
  146.   RUNNING AS A REMOTE CYCLE
  147.  
  148.                       To enable your machine to run as a Remote Cycle, you must
  149.                       define a TP in your .NDF file to allow the Cycles Server
  150.                       to start the program on your machine.  To do this, follow
  151.                       these steps:
  152.  
  153.                       1.  Determine the name of the .NDF file to change:
  154.  
  155.                           a.  While Communications Manager is running, look at
  156.                               the main Communications Manager screen, "Communi-
  157.                               cations Manager Main Menu."
  158.  
  159.                           b.  Note the value near the top of the screen by the
  160.                               prompt "Active Configuration File".  This is the
  161.                               name of the configuration file you are using.
  162.                               For our example, let's use the name CFGFILE.  The
  163.                               .NDF file to edit will be
  164.                               C:\CMLIB\APPN\CFGFILE.NDF.  The drive may be dif-
  165.                               ferent if you have Communications Manager
  166.                               installed on a drive other than your C:  drive.
  167.  
  168.                       2.  Edit the .NDF file you found in the first step, and
  169.                           add the following lines at the end of the file,
  170.                           changing the value in parentheses by "FILESPEC" as
  171.                           specified in the note below.
  172.  
  173.                             DEFINE_TP  TP_NAME(LC.REMOTE)
  174.                                          FILESPEC(e:\cycle\cycle.exe)
  175.                                          PARM_STRING(REMOTE)
  176.                                          SYNC_LEVEL(EITHER)
  177.                                          TP_OPERATION(NONQUEUED_AM_STARTED)
  178.                                          PROGRAM_TYPE(PRESENTATION_MANAGER)
  179.                                          RECEIVE_ALLOCATE_TIMEOUT(INFINITE);
  180.  
  181.                           NOTE:  The path specified in parentheses on the
  182.                           FILESPEC line must be changed to point to the
  183.                           location of CYCLE.EXE.
  184.  
  185.                           The preceding .NDF statement is described below:
  186.  
  187.    DEFINE_TP  TP_NAME(LC.REMOTE) <----- the TP name that is specified by the
  188.                                         server
  189.  
  190.                 FILESPEC(e:\cycle\cycle.exe) <----- the fully specified
  191.                                                     name of the program to
  192.                                                     start when this TP is
  193.                                                     started
  194.  
  195.                 PARM_STRING(REMOTE)    <----- this parameter is passed to
  196.                                               CYCLE.EXE and allows the
  197.                                               program to know that is is
  198.                                               being started by the server
  199.  
  200.                 SYNC_LEVEL(EITHER) <--- this allows the Remote Cycle and
  201.                                         the Server to use Confirm verbs
  202.                                         in their conversation
  203.  
  204.                 TP_OPERATION(NONQUEUED_AM_STARTED)  <---- this tells the
  205.                                                           Attach Manager
  206.                                                           to start a new
  207.                                                           instance of
  208.                                                           CYCLE.EXE each
  209.                                                           time the Server
  210.                                                           starts this TP on
  211.                                                           this machine
  212.  
  213.                 PROGRAM_TYPE(PRESENTATION_MANAGER) <---- CYCLE.EXE is a
  214.                                                          Presentation
  215.                                                          Manager program
  216.  
  217.                 RECEIVE_ALLOCATE_TIMEOUT(INFINITE); <---- the Attach
  218.                                                           Manager will
  219.                                                           wait indefinitely
  220.                                                           for CYCLE.EXE to
  221.                                                           issue a Receive_
  222.                                                                                    Allocate verb
  223.  
  224.                       3.  After saving the .NDF file, verify and execute the
  225.                           changed file by executing the following command:
  226.  
  227.                             APPNV cfgfile -E
  228.  
  229.                           NOTE:  Substitute the name of your configuration file
  230.                           for "cfgfile" in the command above.
  231.  
  232.                       In addition to defining this TP in your .NDF file, you
  233.                       must also tell the Server that you are a potential player
  234.                       of the game.  You do this by adding an entry in the
  235.                       Potential Players File that specifies your LU and the TP
  236.                       name you just configured.  The Potential Players File is
  237.                       described later in this document.
  238.  
  239.   RUNNING AS THE CYCLES SERVER ON YOUR MACHINE
  240.  
  241.                       To configure your workstation to run the Cycles Server,
  242.                       you must have CYCLED.EXE on your machine.  You must then
  243.                       add a TP definition to your .NDF file.  Finally, you
  244.                       should create a Potential Players File that specifies the
  245.                       LUs and TP names of the Remote Cycles that can be started
  246.                       by your Cycles Server.
  247.  
  248.                       To add a TP definition for the Cycles Server to your .NDF
  249.                       file, add the following statement to your .NDF file and
  250.                       then verify that file by running APPNV CFGFILE -E. (The
  251.                       steps to determine where your .NDF file is and what it is
  252.                       called are in the previous section, "Running as a Remote
  253.                       Cycle.")
  254.  
  255.                         DEFINE_TP  TP_NAME(CYCLED)
  256.                                      FILESPEC(e:\cycle\cycled.exe)
  257.                                      PARM_STRING(e:\cycle\players.lst)
  258.                                      SYNC_LEVEL(EITHER)
  259.                                      TP_OPERATION(NONQUEUED_AM_STARTED)
  260.                                      PROGRAM_TYPE(PRESENTATION_MANAGER)
  261.                                      RECEIVE_ALLOCATE_TIMEOUT(INFINITE);
  262.  
  263.                       NOTE:  Be sure to replace the path specified in paren-
  264.                       theses on the FILESPEC line with the path and filename of
  265.                       CYCLED.EXE on your machine.  Replace the file specifica-
  266.                       tion in parentheses on the PARM_STRING line with the path
  267.                       and filename of the list of Potential Players which is
  268.                       described below.
  269.  
  270.                       This TP specification is similar to the LC.REMOTE TP spec-
  271.                       ified above.
  272.  
  273.  
  274.   POTENTIAL PLAYERS FILE
  275.   ______________________
  276.  
  277.                       When a player requests to play against other players, the
  278.                       server searches the file specified in the PARM_STRING
  279.                       parameter of the CYCLED TP definition for a list of
  280.                       potential opponents.  This list specifies the LUs that
  281.                       may want to be asked to play Light Cycles.  It also spec-
  282.                       ifies the names of the TPs on those LUs that should be
  283.                       started when requested by the server.  This list of
  284.                       players is then sent to the Originating Cycle TP which
  285.                       presents the list to the user.  Note that there can be
  286.                       multiple TPs with a particular LU.  This will allow
  287.                       someone on the network to supply multiple potential oppo-
  288.                       nents.  Perhaps one is an automatic cycle program, and
  289.                       one is the original CYCLE.EXE.
  290.  
  291.                       The Potential Players file must have the following
  292.                       format:  One line per TP, maximum 255 characters per
  293.                       line.  Each line contains the LU name (alias or fully
  294.                       qualified), TP name, and a textual description of the TP
  295.                       on that LU.  The LU name must begin at the beginning of
  296.                       the line.  It is separated by at least one space from the
  297.                       TP name.  The next non-space character begins the TP
  298.                       name.  The TP name is separated from the textual
  299.                       description by a space.  The next non-space character up
  300.                       to the end of the line is a textual description of the
  301.                       TP.
  302.  
  303.                       The location and name of this file is specified in the
  304.                       CYCLED TP definition using the PARM_STRING parameter.
  305.                       primary return code.
  306.  
  307.  
  308.   HOW WAS CYCLES WRITTEN?
  309.   _______________________
  310.  
  311.                       Cycles was written using native OS/2 APPC.  Typically,
  312.                       CPI-C is recommended for writing APPC applications, but
  313.                       the requirement that the communication between the Cycles
  314.                       and the Server be asynchronous meant that two parallel
  315.                       conversations had to be established between each Cycle
  316.                       and the Server -- one session to notify the Server that
  317.                       the Cycle wanted to turn, and one session to notify the
  318.                       Cycle of each new board position.  The current version of
  319.                       CPI-C available on OS/2 does not support two conversa-
  320.                       tions within the same OS/2 process.  Native OS/2 APPC
  321.                       does.  (CPI-C version 1.2 contains the architecture for
  322.                       full-duplex conversations.  When this level of CPI-C
  323.                       becomes available in OS/2, Light Cycles will be re-
  324.                       written to use that preferred interface for APPC applica-
  325.                       tions.)  The result of this implementation choice is that
  326.                       the communications code written for Cycles is not port-
  327.                       able to other platforms, such as VM.  Had it been written
  328.                       in CPI-C, it could be completely portable.
  329.  
  330.                       Another variation from recommended APPC programming style
  331.                       is the method by which the TP_BUSY return code is
  332.                       handled.  The Communications Manager APPC Programming
  333.                       Reference recommends issuing verbs for a TP from a single
  334.                       thread or to synchronize issuances from different threads
  335.                       to avoid getting a TP_BUSY return code.  But since Light
  336.                       Cycles is designed to perform asynchronous communication,
  337.                       neither of these options is viable.  Instead, the APPC
  338.                       verbs in Light Cycles are written to retry the APPC call
  339.                       up to 10 times when TP_BUSY is encountered.  If TP_BUSY
  340.                       is still encountered, the APPC call fails with TP_BUSY as
  341.                       its primary return code.
  342.  
  343.   WHAT'S HAPPENING BEHIND THE APPC COVERS?
  344.   ________________________________________
  345.  
  346.                       This section describes the flows of data between the
  347.                       Cycles Server and the various machines running the
  348.                       CYCLE.EXE code.
  349.  
  350.                       When someone starts a Cycle on their machine and speci-
  351.                       fies a valid Cycles Server LU on the  "Register to
  352.                       play..." dialog,  two APPC conversations are allocated
  353.                       between the Cycle's local LU and the Server's LU.  The
  354.                       Cycle code then does a series of Receive_and_Wait's to
  355.                       get the list of potential players from the Server.  After
  356.                       the CYCLE.EXE user selects a set of users, the Server
  357.                       does a series of Receive_and_wait's to get that list of
  358.                       requested partners.  The flows for these APPC trans-
  359.                       actions is shown below:
  360.  
  361. * OVERVIEW of Originating Cycle <--> Server APPC Flows
  362.  
  363. *   Client (CYCLE)                                  Server (CYCLED)
  364.     --------------                                  ---------------
  365. * Set up conversation
  366.     1-Allocate (TP=CYCLED)
  367.     1-Send Data (callback TP)
  368.     1-Confirm                -------------------> 1-Receive_Allocate
  369.                                                   1-Receive Data (callback TP)
  370.                                                   2-Allocate (TP=callback TP)
  371.                              <------------------- 1-Confirmed
  372.     2-Receive_Allocate       <------------------- 2-Confirm
  373.     2-Receive Data (this allows us to do Confirmed)
  374.     2-Confirmed              ------------------->
  375. * Get list of potential partners from the Server:
  376.     while Server sends non-null partners do:       While there are partners to
  377.                                                   send, do:
  378.                                                     2-Send Data (partner info,
  379.       2-Receive Data         <-------------------                FLUSH)
  380.                              <------------------- 2-Send Data (null data,
  381.                                                                FLUSH)
  382. * Send the Originating Cycle's player name
  383.       1-Send Data (cycle name, FLUSH)
  384.                              -------------------> 1-Receive Data
  385.  
  386. * Send the selected partners to the Server:
  387.     While there are partners to send, do:         While Cycle sends non-null
  388.                                                   partners, do:
  389.       1-Send Data(partner info, FLUSH)
  390.                             -------------------->   1-Receive Data
  391.     1-Send Data (null data, FLUSH)
  392.                             -------------------->
  393.  
  394. Each time the Server receives the name of a selected
  395. partner, it starts a thread that attempts to establish
  396. two conversations with that partner in much the same was
  397. as the original two conversations are established.  Here
  398. are the flows that occur between the Server and each of
  399. the selected partners:
  400.  
  401.  
  402.    * OVERVIEW of Server <--> Remote Cycle APPC flows
  403.  
  404.    *   Server (CYCLED)                                 Client (LC.REMOTE)
  405.        ---------------                                 -----------------
  406.    * Set up conversation
  407.        3-Allocate (TP=LC.REMOTE)
  408.        3-Send Data (callback TP)
  409.        3-Send Data (originator's name)
  410.        3-Send Data (remote cycle's number)
  411.        3-Confirm                -------------------> 3-Receive_Allocate
  412.                                                      3-Receive Data (callback TP)
  413.                                                      3-Receive Data (originator's
  414.                                                                      name)
  415.                                                      3-Receive Data (cycle number)
  416.                                                      4-Allocate (TP=callback TP)
  417.                                 <------------------- 3-Confirmed
  418.        4-Receive_Allocate       <------------------- 4-Confirm
  419.        4-Receive Data (this allows us to do Confirmed)
  420.        4-Confirmed              ------------------->
  421.  
  422.                       If the allocation of these conversations fails (due to a
  423.                       communication error or the Remote Cycle decided not to
  424.                       play), this Remote Cycle does not become part of the
  425.                       game.
  426.  
  427.                       At this point there are two conversations between each
  428.                       Cycle and the Server.  One will be used to send data from
  429.                       the Server to the Cycle, and one will be used to send
  430.                       data from the Cycle to Server.  So that these two flows
  431.                       of data can operate independently, CYCLE.EXE and
  432.                       CYCLED.EXE spawn threads to poll the other one for data.
  433.                       For example, CYCLE.EXE has a thread that does a
  434.                       Receive_and_Wait on the APPC conversation that expects
  435.                       data sent from the Server.  Receive_and_Wait means that
  436.                       thread will be blocked and do no processing until data is
  437.                       received (or until the conversation is terminated due to
  438.                       some error).  When data is received, the polling thread
  439.                       posts a message back to the Cycle's main thread.  This
  440.                       message contains the data sent from the Server.  The
  441.                       Cycle's main thread can then process this data while the
  442.                       polling thread loops back to another Receive_and_Wait.
  443.  
  444.                       All of the Send_Data's are done from within the proc-
  445.                       esses' main thread.
  446.  
  447.  
  448.   COMMENTS & SUGGESTIONS
  449.   ______________________
  450.  
  451.                       If you have any comments about Light Cycles, or have any
  452.                       suggestions for improving the program or its
  453.                       documentation, please forward them to the author, Bruce
  454.                       Dean, at internet bwdean@vnet.ibm.com, or in the
  455.                       CompuServe APPC Info Exchange Forum (he's in APPC Market
  456.                       Enablement, so send comments to that ID).
  457.  
  458.  
  459.