home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / ReplicaNetFreewareV5_4.exe / data1.cab / Program_Executable_Files / Example2 / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  1.7 KB  |  71 lines

  1. /* START_LICENSE_HEADER
  2.  
  3. Copyright (C) 2000 Martin Piper, original design and program code
  4. Copyright (C) 2001-2005 Replica Software
  5.  
  6. This program file is copyright (C) Replica Software and can only be used under license.
  7. For more information visit: http://www.replicanet.com/
  8. Or email: info@replicanet.com
  9.  
  10. END_LICENSE_HEADER */
  11. /*
  12. This example shows the use of networked member functions in classes
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string>
  17. #include "RNReplicaNet/Inc/ReplicaNet.h"
  18. #include "Test1.h"
  19.  
  20. using namespace RNReplicaNet;
  21.  
  22. int main(int argc,char **argv)
  23. {
  24.     ReplicaNet *network;
  25.  
  26.     // Allocate a ReplicaNet session
  27.     network = new ReplicaNet();
  28.  
  29.     // Start to find a session
  30.     printf("Searching for a game...\n");
  31.     network->SessionFind();
  32.  
  33.     // Sleep for half a second to wait for replies
  34.     CurrentThread::Sleep(500);
  35.  
  36.     // Enumerate the first found session
  37.     std::string found = network->SessionEnumerateFound();
  38.  
  39.     // If no session name is found then...
  40.     if (found == "")
  41.     {
  42.         // Create a new session
  43.         network->SessionCreate("Example2");
  44.         printf("New game started '%s'\n",network->SessionExportURL().c_str());
  45.     }
  46.     else
  47.     {
  48.         // Join the found session
  49.         printf("Joining session '%s'\n",found.c_str());
  50.         network->SessionJoin(found);
  51.     }
  52.  
  53.     // Now allocate our test object
  54.     Test1 *object;
  55.     object = new Test1();
  56.     // Publish the object on to the network
  57.     object->Publish();
  58.  
  59.     // Go around in an endless loop
  60.     while(1)
  61.     {
  62.         // RunTest() is the member function that shows how to call the network shared member functions
  63.         object->RunTest();
  64.  
  65.         // Sleep for five seconds
  66.         CurrentThread::Sleep(5000);
  67.     }
  68.  
  69.     return 0;
  70. }
  71.