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 / Example4 / GameObject.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  2.9 KB  |  129 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. The base class definition for game objects. See GameObject.cpp
  13. */
  14. #ifndef __GAMEOBJECT_H__
  15. #define __GAMEOBJECT_H__
  16.  
  17. #include "d3dfile.h"
  18. #include <vector>
  19.  
  20. // These classes are accessed via their pointers
  21. namespace RNReplicaNet
  22. {
  23. class ReplicaObject;
  24. }
  25.  
  26. /**
  27.  * This base class defines a game object
  28.  */
  29. class GameObject
  30. {
  31. protected:
  32.     /**
  33.      * Protected ctor means this base class cannot be allocated except with a derived class
  34.      */
  35.     GameObject();
  36.  
  37. public:
  38.     /**
  39.      * Anyone can delete this class
  40.      */
  41.     virtual ~GameObject();
  42.  
  43.  
  44.     /**
  45.      * A virtual method to allow this object to be polled.
  46.      */
  47.     virtual void PollIt(void);
  48.  
  49.     /**
  50.      * This virtual function can be used to supply a method to return a position for an object.
  51.      * If an object doesn't know about position then 'false' will be returned.
  52.      * \param input the D3DXVECTOR4 that will contain the object position, this is not changed if the object has not concept of a position
  53.      * \return true if the object has a concept of a position or false if the object has no concept of a position
  54.      */
  55.     virtual bool GetPosition(D3DXVECTOR4 &input)
  56.     {
  57.         return false;
  58.     }
  59.  
  60.     /**
  61.      * A delete method for a game object since deletion of a class while in a member function is not very good design.
  62.      * This delays the real delete of the game object to a time when the object list is not being iterated
  63.      */
  64.     void Delete(void);
  65.  
  66.     /**
  67.      * Access method for mDeleteMe
  68.      * \return true if the object Delete() method was used
  69.      */
  70.     bool GetDelete(void) const
  71.     {
  72.         return mDeleteMe;
  73.     }
  74.  
  75.     /**
  76.      * The object types known to this example
  77.      */
  78.     enum ObjectType
  79.     {
  80.         kNULL,
  81.         kPlane,
  82.         kCamera
  83.     };
  84.  
  85.     /**
  86.      * This calculates a distance to another GameObject. See GameObject.cpp for more details.
  87.      * \return The distance to the other object or kReplicaObject_InfiniteDistance
  88.      */
  89.     float CalculateDistanceToObject(GameObject *object);
  90.  
  91.     void SetReplicaObject(RNReplicaNet::ReplicaObject *const object)
  92.     {
  93.         mReplica = object;
  94.     }
  95.  
  96.     RNReplicaNet::ReplicaObject *GetReplicaObject(void) const
  97.     {
  98.         return mReplica;
  99.     }
  100.  
  101.     void SetType(const ObjectType type)
  102.     {
  103.         mType = type;
  104.     }
  105.  
  106.     ObjectType GetType(void) const
  107.     {
  108.         return mType;
  109.     }
  110.  
  111. private:
  112.     /**
  113.      * When the Delete() function is used this gets set to be true
  114.      */
  115.     bool mDeleteMe;
  116.  
  117.     /**
  118.      * A pointer held by the class that points to the derived class, as a base class pointer, of this object for forward references
  119.      */
  120.     RNReplicaNet::ReplicaObject *mReplica;
  121.  
  122.     /**
  123.      * The type of this object
  124.      */
  125.     ObjectType mType;
  126. };
  127.  
  128. #endif
  129.