# HG changeset patch # User John Tsiombikas # Date 1346199756 -10800 # Node ID 862461b686f46d3ae8c681a2e6af8c41cf70f9cb # Parent 84a56fb2485052262efcc00228ede95ff42e75e9 start work on particle systems diff -r 84a56fb24850 -r 862461b686f4 prototype/Makefile.in --- a/prototype/Makefile.in Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/Makefile.in Wed Aug 29 03:22:36 2012 +0300 @@ -10,7 +10,7 @@ CFLAGS = -pedantic $(warn) $(dbg) $(opt) $(inc) CXXFLAGS = $(CFLAGS) $(cxx11_cflags) -LDFLAGS = $(cxx11_ldflags) $(libgl) -lm -lassimp -limago `pkg-config --libs freetype2` +LDFLAGS = $(cxx11_ldflags) $(libgl) -lm -lassimp -limago -lpsys `pkg-config --libs freetype2` ifeq ($(shell uname -s), Darwin) libgl = -framework OpenGL -framework GLUT -lglew diff -r 84a56fb24850 -r 862461b686f4 prototype/src/level.cc --- a/prototype/src/level.cc Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/level.cc Wed Aug 29 03:22:36 2012 +0300 @@ -17,6 +17,10 @@ Level::~Level() { delete [] cells; + + for(auto cell : cell_list) { + delete cell; + } } bool Level::load(const char *fname) @@ -65,7 +69,9 @@ } if(isalpha(buf[i]) || buf[i] == ' ') { - *grid_row = new GridCell(deftile); + GridCell *cell = new GridCell(deftile); + *grid_row = cell; + cell_list.push_back(*grid_row); } grid_row++; } @@ -117,12 +123,17 @@ return dmask; } +void Level::update(unsigned long msec, float dt) +{ + for(auto cell : cell_list) { + cell->update(msec, dt); + } +} + void Level::draw() const { glMatrixMode(GL_MODELVIEW); - //draw_grid(); - for(int i=0; iupdate(msec, dt); + } +} + void GridCell::draw(unsigned int draw_mask) const { for(auto tile : tiles) { diff -r 84a56fb24850 -r 862461b686f4 prototype/src/level.h --- a/prototype/src/level.h Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/level.h Wed Aug 29 03:22:36 2012 +0300 @@ -15,6 +15,9 @@ int xsz, ysz; float cell_size; + // secondary data structure, simple list of all populated cells + std::vector cell_list; + void draw_grid() const; public: @@ -28,6 +31,8 @@ Vector3 get_cell_pos(int x, int y) const; unsigned int get_cell_dirmask(int x, int y) const; + void update(unsigned long msec, float dt); + void draw() const; void draw_lights() const; }; @@ -35,12 +40,14 @@ class GridCell { private: // each grid-cell might contain multiple tiles. - std::vector tiles; + std::vector tiles; public: - GridCell(const Tile *tile = 0); + GridCell(Tile *tile = 0); - void add_tile(const Tile *tile); + void add_tile(Tile *tile); + + void update(unsigned long msec, float dt); void draw(unsigned int draw_mask) const; void draw_lights(unsigned int draw_mask) const; diff -r 84a56fb24850 -r 862461b686f4 prototype/src/light.cc --- a/prototype/src/light.cc Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/light.cc Wed Aug 29 03:22:36 2012 +0300 @@ -1,6 +1,8 @@ +#include #include "opengl.h" #include "light.h" #include "renderer.h" +#include "timer.h" Light::Light(const Color &col) : color(col) @@ -8,6 +10,8 @@ intensity = 1.0; vbo = 0; num_faces = 0; + + flicker_offset = 2.0 * (float)rand() / (float)RAND_MAX; } Light::~Light() {} @@ -117,7 +121,9 @@ glUniform1f(loc, radius); } if((loc = glGetUniformLocation(sdr, "light_color")) != -1) { - glUniform3f(loc, color.x, color.y, color.z); + float t = get_time_msec() / 1000.0 + flicker_offset * 4.0; + float intens = fbm1(t * 2.0, 2) * 0.5 + 1.0; + glUniform3f(loc, color.x * intens, color.y * intens, color.z * intens); } } diff -r 84a56fb24850 -r 862461b686f4 prototype/src/light.h --- a/prototype/src/light.h Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/light.h Wed Aug 29 03:22:36 2012 +0300 @@ -8,6 +8,8 @@ float intensity; Color color; + float flicker_offset; + // VBO for rendering the light source unsigned int vbo; unsigned int num_faces; diff -r 84a56fb24850 -r 862461b686f4 prototype/src/main.cc --- a/prototype/src/main.cc Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/main.cc Wed Aug 29 03:22:36 2012 +0300 @@ -10,6 +10,7 @@ #include "renderer.h" #include "cmdcon.h" #include "cfg.h" +#include "timer.h" bool init(int xsz, int ysz); void cleanup(); @@ -126,7 +127,7 @@ void disp() { - update(glutGet(GLUT_ELAPSED_TIME)); + update(get_time_msec()); if(cfg.stereo) { glDrawBuffer(GL_BACK_LEFT); @@ -227,6 +228,8 @@ cam.input_move(dx, 0, dy); + level->update(msec, dt); + last_upd = msec; } diff -r 84a56fb24850 -r 862461b686f4 prototype/src/renderer.h --- a/prototype/src/renderer.h Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/renderer.h Wed Aug 29 03:22:36 2012 +0300 @@ -11,6 +11,7 @@ void resize_renderer(int xsz, int ysz); +void update_renderer(unsigned long msec, float dt); void render_deferred(const Level *level); #endif // RENDERER_H_ diff -r 84a56fb24850 -r 862461b686f4 prototype/src/tile.cc --- a/prototype/src/tile.cc Wed Aug 29 01:04:01 2012 +0300 +++ b/prototype/src/tile.cc Wed Aug 29 03:22:36 2012 +0300 @@ -20,6 +20,20 @@ tset = tileset; } +Tile::~Tile() +{ + for(auto m : meshes) { + delete m; + } + for(auto lt : lights) { + delete lt; + } + for(auto ps : psattr) { + psys_destroy_attr(ps); + delete ps; + } +} + bool Tile::load(const char *fname) { if(!fname) { @@ -54,9 +68,16 @@ load_meshes(scn, nodemap); printf("loaded tile %s: %d meshes, %d lights\n", saved_fname, (int)meshes.size(), (int)lights.size()); + + aiReleaseImport(scn); return true; } +void Tile::update(unsigned long msec, float dt) +{ + // TODO particle system update +} + void Tile::draw(unsigned int draw_mask) const { for(size_t i=0; i #include #include +#include #include "mesh.h" #include "light.h" @@ -24,15 +25,19 @@ std::vector meshes; std::vector mesh_side, light_side; std::vector lights; + std::vector psattr; int load_lights(const aiScene *scn); int load_meshes(const aiScene *scn, const std::map &nmap); public: Tile(TileSet *tileset = 0); + ~Tile(); bool load(const char *fname); + void update(unsigned long msec, float dt); + void draw(unsigned int drawmask) const; void draw_lights(unsigned int drawmask) const; }; diff -r 84a56fb24850 -r 862461b686f4 prototype/src/timer.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prototype/src/timer.cc Wed Aug 29 03:22:36 2012 +0300 @@ -0,0 +1,18 @@ +#include +#include "timer.h" + +using namespace std::chrono; + +static bool timer_initialized; +static time_point start_time; + +unsigned long get_time_msec(void) +{ + if(!timer_initialized) { + start_time = steady_clock::now(); + timer_initialized = true; + } + + auto dur = steady_clock::now() - start_time; + return duration_cast(dur).count(); +} diff -r 84a56fb24850 -r 862461b686f4 prototype/src/timer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prototype/src/timer.h Wed Aug 29 03:22:36 2012 +0300 @@ -0,0 +1,6 @@ +#ifndef TIMER_H_ +#define TIMER_H_ + +unsigned long get_time_msec(void); + +#endif // TIMER_H_