comparison engine/core/model/structures/instance.h @ 209:044d1fead5d2

* Applying icelus' "leader is not around anymore" patch from #350 * Close #350
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 15 Mar 2009 22:20:20 +0000
parents 3d0cc4545938
children be246fb3a0df
comparison
equal deleted inserted replaced
208:e281223a03a6 209:044d1fead5d2
68 public: 68 public:
69 virtual ~InstanceChangeListener() {}; 69 virtual ~InstanceChangeListener() {};
70 virtual void onInstanceChanged(Instance* instance, InstanceChangeInfo info) = 0; 70 virtual void onInstanceChanged(Instance* instance, InstanceChangeInfo info) = 0;
71 }; 71 };
72 72
73
74 class InstanceDeleteListener {
75 public:
76 virtual ~InstanceDeleteListener() {};
77 virtual void onInstanceDeleted(Instance* instance) =0;
78 };
79
73 /** 80 /**
74 * An Instance is an "instantiation" of an Object at a Location. 81 * An Instance is an "instantiation" of an Object at a Location.
75 */ 82 */
76 class Instance : public ResourceClass { 83 class Instance : public ResourceClass, public InstanceDeleteListener {
77 public: 84 public:
78 85
79 /** Constructor 86 /** Constructor
80 * Instances are created by calling addInstance from layer, thus 87 * Instances are created by calling addInstance from layer, thus
81 * this method should really be called only by layer or test code 88 * this method should really be called only by layer or test code
167 /** Removes associated instance change listener 174 /** Removes associated instance change listener
168 * @param listener to remove 175 * @param listener to remove
169 */ 176 */
170 void removeChangeListener(InstanceChangeListener* listener); 177 void removeChangeListener(InstanceChangeListener* listener);
171 178
179 /** Adds new instance delete listener
180 * @param listener to add
181 */
182 void addDeleteListener(InstanceDeleteListener* listener) const;
183
184 /** Removes associated instance delete listener
185 * @param listener to remove
186 */
187 void removeDeleteListener(InstanceDeleteListener* listener) const;
188
172 /** Gets the currently active action. This is owned by 189 /** Gets the currently active action. This is owned by
173 * the instance's object, so don't delete it! 190 * the instance's object, so don't delete it!
174 * @return current action, NULL in case there is none 191 * @return current action, NULL in case there is none
175 */ 192 */
176 Action* getCurrentAction() const; 193 Action* getCurrentAction() const;
258 void refresh(); 275 void refresh();
259 276
260 /** Returns a bitmask of changes since previous update 277 /** Returns a bitmask of changes since previous update
261 */ 278 */
262 inline InstanceChangeInfo getChangeInfo(); 279 inline InstanceChangeInfo getChangeInfo();
280
281 /** callback so other instances we depend on can notify us if they go away
282 */
283 void onInstanceDeleted(Instance* instance);
263 284
264 private: 285 private:
265 std::string m_id; 286 std::string m_id;
266 287
267 // The rotation offset of this instance. This is in addition to possible camera rotation and 288 // The rotation offset of this instance. This is in addition to possible camera rotation and
310 TimeProvider* m_timeprovider; 331 TimeProvider* m_timeprovider;
311 }; 332 };
312 InstanceActivity* m_activity; 333 InstanceActivity* m_activity;
313 // bitmask stating current changes 334 // bitmask stating current changes
314 InstanceChangeInfo m_changeinfo; 335 InstanceChangeInfo m_changeinfo;
336 // listeners for deletion of the instance
337 mutable std::vector<InstanceDeleteListener*> m_deletelisteners;
315 338
316 // object where instantiated from 339 // object where instantiated from
317 Object* m_object; 340 Object* m_object;
318 // current location 341 // current location
319 Location m_location; 342 Location m_location;