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 / Test1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  2.6 KB  |  98 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. #include "Test1.h"
  12.  
  13. #define REPORTOBJECT()    \
  14. if (IsMaster())    \
  15. {    \
  16.     printf("Test1 master  $%x SessionID %d UniqueID %d ClassID %d ",(int)this,GetSessionID(),GetUniqueID(),GetClassID());    \
  17. }    \
  18. else    \
  19. {    \
  20.     printf("Test1 replica $%x SessionID %d UniqueID %d ClassID %d ",(int)this,GetSessionID(),GetUniqueID(),GetClassID());    \
  21. }
  22.  
  23.  
  24.  
  25. Test1::Test1()
  26. {
  27.     REPORTOBJECT();
  28.     printf("Test1() Called\n");
  29. }
  30.  
  31. Test1::~Test1()
  32. {
  33.     REPORTOBJECT();
  34.     printf("~Test1() Called\n");
  35. }
  36.  
  37. void Test1::RunTest(void)
  38. {
  39.     REPORTOBJECT();
  40.     printf("RunTest() Called\n");
  41.     float random_float;
  42.     int random_int;
  43.     random_float = float(rand()) / float(RAND_MAX);
  44.     /* This calls the function on the master and replicas because this RunTest() function is called on the master copy. */
  45.     GLOBAL_FUNCTION_CALL(APrivateFunction(random_float));
  46.  
  47.     random_int = rand();
  48.     random_float = float(rand()) / float(RAND_MAX);
  49.     /* This calls the function only on the replicas because this RunTest() function is called on the master copy. */
  50.     ALL_REPLICAS_FUNCTION_CALL(APublicFunction(random_int,random_float));
  51.  
  52.     ExampleCustomType thing;
  53.     thing.mX = 1.0f;
  54.     thing.mY = 2.0f;
  55.     thing.mZ = 3.0f;
  56.     ALL_REPLICAS_FUNCTION_CALL(APublicFunctionWithCustomTypeByValue(thing,4));
  57.  
  58.     ALL_REPLICAS_FUNCTION_CALL(APublicFunctionWithCustomTypeByReference(thing,4));
  59. }
  60.  
  61. void Test1::APrivateFunction(float fvalue)
  62. {
  63.     REPORTOBJECT();
  64.     printf("APrivateFunction() : Called with %f\n",fvalue);
  65. }
  66.  
  67. void Test1::APublicFunction(int ivalue,float fvalue)
  68. {
  69.     REPORTOBJECT();
  70.     printf("APublicFunction() : Called with %d,%f\n",ivalue,fvalue);
  71. }
  72.  
  73. void Test1::APublicFunctionWithCustomTypeByValue(ExampleCustomType thing,int anotherValue)
  74. {
  75.     REPORTOBJECT();
  76.     printf("APublicFunctionWithCustomTypeByValue() : Called with %f,%f,%f and %d\n",thing.mX,thing.mY,thing.mZ,anotherValue);
  77. }
  78.  
  79. void Test1::APublicFunctionWithCustomTypeByReference(ExampleCustomType &thing,int anotherValue)
  80. {
  81.     REPORTOBJECT();
  82.     printf("APublicFunctionWithCustomTypeByReference() : Called with %f,%f,%f and %d\n",thing.mX,thing.mY,thing.mZ,anotherValue);
  83. }
  84.  
  85. void Test1::OwnerChange(void)
  86. {
  87.     REPORTOBJECT();
  88.     printf("Owner changed to be sessid %d\n",GetSessionID());
  89.     if (IsMaster())
  90.     {
  91.         printf("as a master\n");
  92.     }
  93.     else
  94.     {
  95.         printf("as a replica\n");
  96.     }
  97. }
  98.