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 / Example8 / Test1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  1.6 KB  |  64 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. #include "RNReplicaNet/Inc/DataBlock_Function.h"
  13.  
  14. using namespace RNReplicaNet;
  15.  
  16. #define REPORTOBJECT()    \
  17. if (IsMaster())    \
  18. {    \
  19.     printf("Test1 master  $%x SessionID %d UniqueID %d ClassID %d ",(int)this,GetSessionID(),GetUniqueID(),GetClassID());    \
  20. }    \
  21. else    \
  22. {    \
  23.     printf("Test1 replica $%x SessionID %d UniqueID %d ClassID %d ",(int)this,GetSessionID(),GetUniqueID(),GetClassID());    \
  24. }
  25.  
  26.  
  27.  
  28. Test1::Test1()
  29. {
  30.     REPORTOBJECT();
  31.     printf("Test1() created\n");
  32. }
  33.  
  34. Test1::~Test1()
  35. {
  36.     REPORTOBJECT();
  37.     printf("~Test1() deleted\n");
  38. }
  39.  
  40. bool first = true;
  41.  
  42. void Test1::RunTest(const int numSessionIDs,const int *sessionIDs)
  43. {
  44.     REPORTOBJECT();
  45.     printf("RunTest() Called\n");
  46.     float random_float;
  47.     int random_int;
  48.  
  49.     random_int = rand();
  50.     random_float = float(rand()) / float(RAND_MAX);
  51.     /* This calls the function only on the nominated replicas */
  52.     DataBlock_Function::SetSessionIDFilter(numSessionIDs,sessionIDs);
  53.     ALL_REPLICAS_FUNCTION_CALL(APublicFunction(random_int,random_float));
  54.  
  55.     // The same functionality is offered by using the macro
  56.     NOMINATED_REPLICAS_FUNCTION_CALL(numSessionIDs,sessionIDs,APublicFunction(random_int,random_float));
  57. }
  58.  
  59. void Test1::APublicFunction(int ivalue,float fvalue)
  60. {
  61.     REPORTOBJECT();
  62.     printf("APublicFunction() : Called with %d,%f\n",ivalue,fvalue);
  63. }
  64.