dungeon_crawler

changeset 45:dfd3a413ef9e

particle system 1
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 12 Sep 2012 06:04:20 +0300
parents c45c42c3d32e
children f3030df27110
files prototype/src/level.cc prototype/src/level.h prototype/src/tile.cc prototype/src/tile.h
diffstat 4 files changed, 49 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/prototype/src/level.cc	Thu Aug 30 06:08:22 2012 +0300
     1.2 +++ b/prototype/src/level.cc	Wed Sep 12 06:04:20 2012 +0300
     1.3 @@ -208,13 +208,27 @@
     1.4  GridCell::GridCell(Tile *tile)
     1.5  {
     1.6  	if(tile) {
     1.7 -		tiles.push_back(tile);
     1.8 +		add_tile(tile);
     1.9  	}
    1.10  }
    1.11  
    1.12  void GridCell::add_tile(Tile *tile)
    1.13  {
    1.14 +	if(!tile) {
    1.15 +		return;
    1.16 +	}
    1.17 +
    1.18  	tiles.push_back(tile);
    1.19 +
    1.20 +	/* instanciate any particle systems */
    1.21 +	const struct psys_attributes **psattr = tile->get_unique_psys();
    1.22 +	int num_psattr = tile->get_unique_psys_count();
    1.23 +
    1.24 +	for(int i=0; i<num_psattr; i++) {
    1.25 +		struct psys_emitter *emitter = psys_create();
    1.26 +		emitter->attr = *psattr[i];
    1.27 +		psys.push_back(emitter);
    1.28 +	}
    1.29  }
    1.30  
    1.31  void GridCell::update(unsigned long msec, float dt)
    1.32 @@ -222,6 +236,9 @@
    1.33  	for(auto tile : tiles) {
    1.34  		tile->update(msec, dt);
    1.35  	}
    1.36 +	for(auto ps : psys) {
    1.37 +		psys_update(ps, (float)msec / 1000.0f);
    1.38 +	}
    1.39  }
    1.40  
    1.41  void GridCell::draw(unsigned int draw_mask) const
    1.42 @@ -237,3 +254,13 @@
    1.43  		tile->draw_lights(draw_mask);
    1.44  	}
    1.45  }
    1.46 +
    1.47 +void GridCell::draw_post(unsigned int draw_mask) const
    1.48 +{
    1.49 +	for(auto tile : tiles) {
    1.50 +		tile->draw_post(draw_mask);
    1.51 +	}
    1.52 +	for(auto ps : psys) {
    1.53 +		psys_draw(ps);
    1.54 +	}
    1.55 +}
     2.1 --- a/prototype/src/level.h	Thu Aug 30 06:08:22 2012 +0300
     2.2 +++ b/prototype/src/level.h	Wed Sep 12 06:04:20 2012 +0300
     2.3 @@ -3,6 +3,7 @@
     2.4  
     2.5  #include <vector>
     2.6  #include "vmath/vmath.h"
     2.7 +#include "psys/psys.h"
     2.8  
     2.9  class GridCell;
    2.10  class Tile;
    2.11 @@ -43,6 +44,9 @@
    2.12  	// each grid-cell might contain multiple tiles.
    2.13  	std::vector<Tile*> tiles;
    2.14  
    2.15 +	// particle systems
    2.16 +	std::vector<struct psys_emitter*> psys;
    2.17 +
    2.18  public:
    2.19  	GridCell(Tile *tile = 0);
    2.20  
     3.1 --- a/prototype/src/tile.cc	Thu Aug 30 06:08:22 2012 +0300
     3.2 +++ b/prototype/src/tile.cc	Wed Sep 12 06:04:20 2012 +0300
     3.3 @@ -34,6 +34,16 @@
     3.4  	}
     3.5  }
     3.6  
     3.7 +const struct psys_attributes **get_unique_psys() const
     3.8 +{
     3.9 +	return &psattr[0];
    3.10 +}
    3.11 +
    3.12 +int get_unique_psys_count() const
    3.13 +{
    3.14 +	return (int)psattr.size();
    3.15 +}
    3.16 +
    3.17  bool Tile::load(const char *fname)
    3.18  {
    3.19  	if(!fname) {
     4.1 --- a/prototype/src/tile.h	Thu Aug 30 06:08:22 2012 +0300
     4.2 +++ b/prototype/src/tile.h	Wed Sep 12 06:04:20 2012 +0300
     4.3 @@ -25,7 +25,10 @@
     4.4  	std::vector<Mesh*> meshes;
     4.5  	std::vector<unsigned int> mesh_side, light_side;
     4.6  	std::vector<Light*> lights;
     4.7 +	// attributes for gridcell-unique particle systems
     4.8  	std::vector<struct psys_attributes*> psattr;
     4.9 +	// global particle systems (simulated once, drawn for each tile instance).
    4.10 +	std::vector<struct psys_emitter*> psys_global;
    4.11  
    4.12  	int load_lights(const aiScene *scn);
    4.13  	int load_meshes(const aiScene *scn, const std::map<aiMesh*, aiNode*> &nmap);
    4.14 @@ -34,12 +37,16 @@
    4.15  	Tile(TileSet *tileset = 0);
    4.16  	~Tile();
    4.17  
    4.18 +	const struct psys_attributes **get_unique_psys() const;
    4.19 +	int get_unique_psys_count() const;
    4.20 +
    4.21  	bool load(const char *fname);
    4.22  
    4.23  	void update(unsigned long msec, float dt);
    4.24  
    4.25  	void draw(unsigned int drawmask) const;
    4.26  	void draw_lights(unsigned int drawmask) const;
    4.27 +	void draw_psys(unsigned int drawmask) const;
    4.28  };
    4.29  
    4.30