From 081c58990e9445e34131f110fd0d86c9fda5961f Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 10 Jul 2013 17:59:16 -0400 Subject: [PATCH] fix floodfill and prop floodfil with photons --- src/simulation/Simulation.cpp | 58 +++++++++++++++++------------------ src/simulation/Simulation.h | 1 + 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 747a019d5..f6f0110e5 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -332,26 +332,6 @@ void Simulation::Restore(const Snapshot & snap) signs = snap.signs; } -/*int Simulation::Load(unsigned char * data, int dataLength) -{ - return SaveLoader::Load(data, dataLength, this, true, 0, 0); -} - -int Simulation::Load(int x, int y, unsigned char * data, int dataLength) -{ - return SaveLoader::Load(data, dataLength, this, false, x, y); -} - -unsigned char * Simulation::Save(int & dataLength) -{ - return SaveLoader::Build(dataLength, this, 0, 0, XRES, YRES); -} - -unsigned char * Simulation::Save(int x1, int y1, int x2, int y2, int & dataLength) -{ - return SaveLoader::Build(dataLength, this, x1, y1, x2-x1, y2-y1); -}*/ - void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h) { int cx = 0; @@ -376,13 +356,23 @@ void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h) } } +bool Simulation::FloodFillPmapCheck(int x, int y, int type) +{ + if (type == 0) + return !pmap[y][x] && !photons[y][x]; + if (elements[type].Properties&TYPE_ENERGY) + return (photons[y][x]&0xFF) == type; + else + return (pmap[y][x]&0xFF) == type; +} + int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue, StructProperty::PropertyType proptype, int parttype, char * bitmap) { int x1, x2, i, dy = 1; x1 = x2 = x; while (x1>=CELL) { - if ((pmap[y][x1-1]&0xFF)!=parttype || bitmap[(y*XRES)+x1-1]) + if (!FloodFillPmapCheck(x1-1, y, parttype) || bitmap[(y*XRES)+x1-1]) { break; } @@ -390,7 +380,7 @@ int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue, } while (x2>8; + if (!i) + i = photons[y][x]>>8; + if (!i) + continue; switch (proptype) { case StructProperty::Float: *((float*)(((char*)&parts[i])+propoffset)) = *((float*)propvalue); @@ -420,12 +414,12 @@ int Simulation::flood_prop_2(int x, int y, size_t propoffset, void * propvalue, } if (y>=CELL+dy) for (x=x1; x<=x2; x++) - if ((pmap[y-dy][x]&0xFF)==parttype && !bitmap[((y-dy)*XRES)+x]) + if (FloodFillPmapCheck(x, y-dy, parttype) && !bitmap[((y-dy)*XRES)+x]) if (!flood_prop_2(x, y-dy, propoffset, propvalue, proptype, parttype, bitmap)) return 0; if (y=CELL) { - if ((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm) + if (!FloodFillPmapCheck(x1-1, y, cm) || bmap[y/CELL][(x1-1)/CELL]!=bm) { break; } @@ -1479,7 +1479,7 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) // go right as far as possible while (x2=CELL+dy) for (x=x1; x<=x2; x++) - if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm) + if (FloodFillPmapCheck(x, y-dy, cm) && bmap[(y-dy)/CELL][x/CELL]==bm) { coord_stack[coord_stack_size][0] = x; coord_stack[coord_stack_size][1] = y-dy; @@ -1508,7 +1508,7 @@ int Simulation::FloodParts(int x, int y, int fullc, int cm, int bm, int flags) if (y