coeng

diff src/comp.h @ 6:2f872a179914

first component test: - prs, xform, physics components with dependencies - topological sort of components to update them in the correct order - debug visualization component todo: remove draw() from components, doesn't make sense
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Feb 2015 07:27:12 +0200
parents 4a1c9597f4d3
children 8cce82794f90
line diff
     1.1 --- a/src/comp.h	Sat Feb 14 01:35:42 2015 +0200
     1.2 +++ b/src/comp.h	Sat Feb 14 07:27:12 2015 +0200
     1.3 @@ -3,13 +3,31 @@
     1.4  
     1.5  #include <string>
     1.6  
     1.7 -class GameObject;
     1.8 +#ifdef NDEBUG
     1.9 +#define COCAST(type, x)	((type*)x)
    1.10 +#else
    1.11 +#define COCAST(type, x)	dynamic_cast<type*>(x)
    1.12 +#endif
    1.13 +
    1.14 +class GObject;
    1.15  
    1.16  class Component {
    1.17  protected:
    1.18  	const char *name;
    1.19 -	GameObject *gobj;
    1.20 -	int upd_prio;	// update priority (0: normal)
    1.21 +	GObject *gobj;
    1.22 +
    1.23 +	/* attach/detach to a particular GObject.
    1.24 +	 * This is only called from GObject::add_component and
    1.25 +	 * GObject::remove_component respectively
    1.26 +	 */
    1.27 +	virtual void attach(GObject *gobj);
    1.28 +	virtual void detach();
    1.29 +
    1.30 +	/* Returns an array of component names which depend on this and
    1.31 +	 * must not be updated first if both exist in the same object.
    1.32 +	 * Terminated by a null pointer.
    1.33 +	 */
    1.34 +	virtual const char **update_before() const;
    1.35  
    1.36  public:
    1.37  	Component();
    1.38 @@ -17,11 +35,10 @@
    1.39  
    1.40  	const char *get_name() const;
    1.41  
    1.42 -	virtual void update();
    1.43 +	virtual void update(float dt);
    1.44 +	virtual void draw() const;
    1.45  
    1.46 -	bool operator <(const Component &c) const;	// for sorting based on priority
    1.47 -
    1.48 -	friend class GameObject;
    1.49 +	friend class GObject;
    1.50  };
    1.51  
    1.52  void register_component(const char *name, Component *(*cons_func)());