Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / persistent_spawnable.h
blobd87f971978fd8449854de712937c1943f746b04a
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _PERSISTENT_SPAWNABLE_
20 #define _PERSISTENT_SPAWNABLE_
22 // SpawnObject
23 template <class T>
24 class CSpawnable :
25 public NLMISC::CDbgRefCount< CSpawnable<T> >,
26 public NLMISC::CRefCount
28 public:
29 CSpawnable(T& owner) : _Owner(owner)
32 virtual ~CSpawnable()
36 inline T& getPersistent () const
38 return _Owner;
41 private:
42 T& _Owner;
45 // SpawnObject
46 template <class T>
47 class CPersistent
49 public:
50 CPersistent ( )
52 _Spawnable = NULL;
54 virtual ~CPersistent ( )
56 _Spawnable = NULL;
59 bool isSpawned () const
61 return !_Spawnable.isNull();
63 void setSpawn (const NLMISC::CSmartPtr<T> &spawnable)
65 _Spawnable=spawnable;
66 #if !FINAL_VERSION
67 nlassert((!spawnable) || (static_cast<CPersistent<T>*>(&spawnable->getPersistent())==static_cast<CPersistent<T>*>(this)));
68 #endif
71 inline T *getSpawnObj() const // you must overload this access to cast the objet with a custom more proper type. ( you know what i mean ? )
73 return _Spawnable;
76 protected:
78 // virtual bool spawn () = 0;
79 // virtual void despawn () = 0;
81 private:
82 NLMISC::CSmartPtr<T> _Spawnable;
85 #endif