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 / Example1 / GameObject.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  1.4 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. /*
  12. This file is the base class for any type of game object.
  13. When an object is allocated or deleted the gGameObjects array tracks the list of allocated objects
  14. */
  15.  
  16. #include "Network.h"
  17. #include "GameObject.h"
  18.  
  19. std::vector<GameObject *> gGameObjects;
  20.  
  21. GameObject::GameObject() : mDeleteMe(false) , mReplica(0)
  22. {
  23.     // Lock our own object list on delete
  24.     gNetwork->LockObjects();
  25.  
  26.     gGameObjects.push_back(this);
  27.  
  28.     // UnLock our own object list on delete
  29.     gNetwork->UnLockObjects();
  30. };
  31.  
  32. GameObject::~GameObject()
  33. {
  34.     // Lock our own object list on delete
  35.     gNetwork->LockObjects();
  36.  
  37.     std::vector<GameObject *>::iterator st,en;
  38.     st = gGameObjects.begin();
  39.     en = gGameObjects.end();
  40.     while (st != en)
  41.     {
  42.         GameObject *object = *st;
  43.         if (object == this)
  44.         {
  45.             gGameObjects.erase(st);
  46.             break;
  47.         }
  48.         st++;
  49.     }
  50.  
  51.     // UnLock our own object list on delete
  52.     gNetwork->UnLockObjects();
  53. };
  54.  
  55. void GameObject::PollIt(void)
  56. {
  57.     printf("Default PollIt()\n");
  58. };
  59.  
  60. void GameObject::Delete(void)
  61. {
  62.     mDeleteMe = true;
  63. }
  64.