about summary refs log tree commit diff
path: root/src/game/client/components/flow.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-27 15:48:50 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-27 15:48:50 +0000
commitdfe499248f1b1236487156b28e4a535d7963fe35 (patch)
treea750b0f28cfd3f3e252602681412ac1adc6d29c7 /src/game/client/components/flow.cpp
parentd711dd190cac809a9bd278fba03ed974812bb863 (diff)
downloadzcatch-dfe499248f1b1236487156b28e4a535d7963fe35.tar.gz
zcatch-dfe499248f1b1236487156b28e4a535d7963fe35.zip
major commit. game client restructure. not complete, loads of stuff not working, but the structure is there
Diffstat (limited to 'src/game/client/components/flow.cpp')
-rw-r--r--src/game/client/components/flow.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/game/client/components/flow.cpp b/src/game/client/components/flow.cpp
new file mode 100644
index 00000000..b2f983e6
--- /dev/null
+++ b/src/game/client/components/flow.cpp
@@ -0,0 +1,84 @@
+#include <game/mapitems.hpp>
+#include <game/layers.hpp>
+#include "flow.hpp"
+
+FLOW::FLOW()
+{
+	cells = 0;
+	height = 0;
+	width = 0;
+	spacing = 16;
+}
+	
+void FLOW::dbg_render()
+{
+	if(!cells)
+		return;
+
+	gfx_texture_set(-1);
+	gfx_lines_begin();
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+		{
+			vec2 pos(x*spacing, y*spacing);
+			vec2 vel = cells[y*width+x].vel * 0.01f;
+			gfx_lines_draw(pos.x, pos.y, pos.x+vel.x, pos.y+vel.y);
+		}
+		
+	gfx_lines_end();
+}
+
+void FLOW::init()
+{
+	if(cells)
+	{
+		mem_free(cells);
+		cells = 0;
+	}
+	
+	MAPITEM_LAYER_TILEMAP *tilemap = layers_game_layer();
+	width = tilemap->width*32/spacing;
+	height = tilemap->height*32/spacing;
+
+	// allocate and clear	
+	cells = (CELL *)mem_alloc(sizeof(CELL)*width*height, 1);
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+			cells[y*width+x].vel = vec2(0.0f, 0.0f);
+}
+
+void FLOW::update()
+{
+	if(!cells)
+		return;
+		
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+			cells[y*width+x].vel *= 0.85f;
+}
+
+vec2 FLOW::get(vec2 pos)
+{
+	if(!cells)
+		return vec2(0,0);
+	
+	int x = (int)(pos.x / spacing);
+	int y = (int)(pos.y / spacing);
+	if(x < 0 || y < 0 || x >= width || y >= height)
+		return vec2(0,0);
+	
+	return cells[y*width+x].vel;	
+}
+
+void FLOW::add(vec2 pos, vec2 vel, float size)
+{
+	if(!cells)
+		return;
+		
+	int x = (int)(pos.x / spacing);
+	int y = (int)(pos.y / spacing);
+	if(x < 0 || y < 0 || x >= width || y >= height)
+		return;
+	
+	cells[y*width+x].vel += vel;
+}