i6engine  1.0
ObjectManager.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_MODULES_OBJECTMANAGER_H__
26 #define __I6ENGINE_MODULES_OBJECTMANAGER_H__
27 
30 
33 
34 namespace i6e {
35 namespace api {
36  typedef utils::weakPtr<Component> WeakComPtr;
37 } /* namespace api */
38 namespace modules {
39 
40  class ObjectMailbox;
41 
42  typedef utils::sharedPtr<api::GameObject, api::GameObject> GOPtr;
43 
44  class ObjectManager {
45  friend class GOFactory;
46  friend class ObjectMailbox;
47 
48  public:
52  ObjectManager();
53 
58 
62  void Tick();
63 
67  void registerCTemplate(const std::string & GOCType, const api::createGOCCallback & fn);
68 
77  api::ComPtr createGOC(const int64_t id, const std::string & GOCType, const api::attributeMap & params, const GOPtr & owner) const;
78 
86  void loadLevel(const std::string & file, const std::string & flags, const std::function<void(uint16_t)> & callback);
87 
88  private:
92  std::unordered_map<int64_t, GOPtr> _GOMap;
93 
95 
96  ComponentFactory _componentFactory;
97  GOFactory _goFactory;
98 
102  bool _paused;
103 
112  void registerGOTemplate(const std::string & file);
113 
117  void NewsCreate(const api::GameMessage::Ptr & msg);
118 
122  void NewsUpdate(const api::GameMessage::Ptr & msg);
123 
127  void NewsDelete(const api::GameMessage::Ptr & msg);
128 
133  void tickComponents();
134 
138  void addTicker(const api::WeakComPtr & c);
139 
143  void removeTicker(int64_t c);
144 
149  void sendObjectMessages(const core::IPKey & receiver) const;
150 
154  void deleteObject(int64_t id);
155 
159  void insertObject(const GOPtr & go);
160 
164  void deleteAllObjectsOfType(const std::string & type);
165 
171  GOPtr getObject(const int64_t guid) const;
172 
176  void sendConditionalMessage(const api::objects::Object_ConditionalMessage_Update & msg);
177 
181  ObjectManager(const ObjectManager &) = delete;
182 
186  ObjectManager & operator=(const ObjectManager &) = delete;
187 
189  };
190 
191 } /* namespace modules */
192 } /* namespace i6e */
193 
194 #endif /* __I6ENGINE_MODULES_OBJECTMANAGER_H__ */
195 
api::ComPtr createGOC(const int64_t id, const std::string &GOCType, const api::attributeMap &params, const GOPtr &owner) const
Creates a new Component.
struct for sending messages to special GameObjects fullfilling the given method never send through ne...
Definition: ObjectConfig.h:229
Factory in order to create Component.
boost::shared_ptr< Message > Ptr
Definition: Message.h:66
std::map< std::string, std::string > attributeMap
Definition: attributeMap.h:42
void loadLevel(const std::string &file, const std::string &flags, const std::function< void(uint16_t)> &callback)
loads a level out of the given file with the given flags
#define ASSERT_THREAD_SAFETY_HEADER
A shared pointer counting references and adds objects being not referenced any more to an internal li...
Definition: sharedPtr.h:50
utils::weakPtr< Component > WeakComPtr
Definition: Component.h:56
boost::function< ComPtr(const int64_t, const attributeMap &)> createGOCCallback
Definition: Component.h:58
void Tick()
tick of the ObjectManager, called by ObjectController to inform ObjectManager there is the next frame...
utils::sharedPtr< api::GameObject, api::GameObject > GOPtr
Definition: GOFactory.h:43
void registerCTemplate(const std::string &GOCType, const api::createGOCCallback &fn)
registers a template with callback for creating a Component
Factory in order to create GameObjects.
Definition: GOFactory.h:52
ObjectManager()
constructor, initializes Object stuff
Extracts the contents of incoming messages on the "Object" channel and calls the corresponding method...
Definition: ObjectMailbox.h:43