diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-05-12 21:28:45 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-05-12 21:28:45 (GMT) |
| commit | 724c99102e1d2ed3a2c347eedb05d9818bac7513 (patch) | |
| tree | 036b97a683491243f79e42daf65c4f00ecf36c97 /src/simulation | |
| parent | 7128188048395f503b2f70ace2880459acdf7515 (diff) | |
| download | powder-724c99102e1d2ed3a2c347eedb05d9818bac7513.zip powder-724c99102e1d2ed3a2c347eedb05d9818bac7513.tar.gz | |
Stupid git
Diffstat (limited to 'src/simulation')
| -rw-r--r-- | src/simulation/SaveLoader.cpp | 49 | ||||
| -rw-r--r-- | src/simulation/Simulation.cpp | 7 | ||||
| -rw-r--r-- | src/simulation/Simulation.h | 15 |
3 files changed, 40 insertions, 31 deletions
diff --git a/src/simulation/SaveLoader.cpp b/src/simulation/SaveLoader.cpp index 9bfb131..b07ba08 100644 --- a/src/simulation/SaveLoader.cpp +++ b/src/simulation/SaveLoader.cpp @@ -86,6 +86,10 @@ int SaveLoader::PSVLoad(unsigned char * data, int dataLength, Simulation * sim, int nf=0, new_format = 0, ttv = 0; Particle *parts = sim->parts; int *fp = (int *)malloc(NPART*sizeof(int)); + + std::vector<sign> tempSigns; + char tempSignText[255]; + sign tempSign("", 0, 0, sign::Left); //New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures //This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error @@ -665,31 +669,32 @@ int SaveLoader::PSVLoad(unsigned char * data, int dataLength, Simulation * sim, { if (p+6 > dataLength) goto corrupt; - for (k=0; k<MAXSIGNS; k++) - if (!sim->signs[k].text[0]) - break; x = d[p++]; x |= ((unsigned)d[p++])<<8; - if (k<MAXSIGNS) - sim->signs[k].x = x+x0; + tempSign.x = x+x0; x = d[p++]; x |= ((unsigned)d[p++])<<8; - if (k<MAXSIGNS) - sim->signs[k].y = x+y0; + tempSign.y = x+y0; x = d[p++]; - if (k<MAXSIGNS) - sim->signs[k].ju = x; + tempSign.ju = (sign::Justification)x; x = d[p++]; if (p+x > dataLength) - goto corrupt; - if (k<MAXSIGNS) - { - memcpy(sim->signs[k].text, d+p, x); - sim->signs[k].text[x] = 0; - //clean_text(signs[k].text, 158-14 /* Current max sign length */); //TODO: Text cleanup for signs - } + goto corrupt; + if(x>254) + x = 254; + memcpy(tempSignText, d+p, x); + tempSignText[x] = 0; + tempSign.text = tempSignText; + tempSigns.push_back(tempSign); p += x; } + + for (i = 0; i < tempSigns.size(); i++) + { + if(i == MAXSIGNS) + break; + sim->signs.push_back(tempSigns[i]); + } version1: if (m) free(m); @@ -868,14 +873,14 @@ unsigned char * SaveLoader::PSVBuild(int & dataLength, Simulation * sim, int ori } j = 0; - for (i=0; i<MAXSIGNS; i++) - if (sim->signs[i].text[0] && + for (i=0; i<sim->signs.size(); i++) + if (sim->signs[i].text.length() && sim->signs[i].x>=x0 && sim->signs[i].x<x0+w && sim->signs[i].y>=y0 && sim->signs[i].y<y0+h) j++; d[p++] = j; - for (i=0; i<MAXSIGNS; i++) - if (sim->signs[i].text[0] && + for (i=0; i<sim->signs.size(); i++) + if (sim->signs[i].text.length() && sim->signs[i].x>=x0 && sim->signs[i].x<x0+w && sim->signs[i].y>=y0 && sim->signs[i].y<y0+h) { @@ -884,9 +889,9 @@ unsigned char * SaveLoader::PSVBuild(int & dataLength, Simulation * sim, int ori d[p++] = (sim->signs[i].y-y0); d[p++] = (sim->signs[i].y-y0)>>8; d[p++] = sim->signs[i].ju; - x = strlen(sim->signs[i].text); + x = sim->signs[i].text.length(); d[p++] = x; - memcpy(d+p, sim->signs[i].text, x); + memcpy(d+p, sim->signs[i].text.c_str(), x); p+=x; } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 914df7e..41565a2 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1347,8 +1347,7 @@ void Simulation::create_arc(int sx, int sy, int dx, int dy, int midpoints, int v void Simulation::clear_sim(void) { int i, x, y; - if(signs) - memset(signs, 0, sizeof(sign)*MAXSIGNS); + signs.clear(); memset(bmap, 0, sizeof(bmap)); memset(emap, 0, sizeof(emap)); memset(parts, 0, sizeof(Particle)*NPART); @@ -3806,7 +3805,6 @@ void Simulation::update_particles()//doesn't update the particles themselves, bu Simulation::~Simulation() { - free(signs); delete grav; delete air; } @@ -3844,9 +3842,6 @@ Simulation::Simulation(): pv = air->pv; hv = air->hv; - //Clear signs - signs = (sign*)calloc(MAXSIGNS, sizeof(sign)); - int menuCount; menu_section * msectionsT = LoadMenus(menuCount); memcpy(msections, msectionsT, menuCount * sizeof(menu_section)); diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 71f233d..f4f8f5b 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -113,8 +113,17 @@ typedef struct menu_section menu_section; struct sign { - int x,y,ju; - char text[256]; +public: + enum Justification { Left = 0, Centre = 1, Right = 2 }; + sign(std::string text_, int x_, int y_, Justification justification_): + text(text_), + x(x_), + y(y_), + ju(justification_) + {} + int x, y; + Justification ju; + std::string text; }; typedef struct sign sign; @@ -139,6 +148,7 @@ public: Gravity * grav; Air * air; + vector<sign> signs; Element * elements; vector<SimTool*> tools; unsigned int * platent; @@ -165,7 +175,6 @@ public: int NUM_PARTS; int elementCount[PT_NUM]; int ISWIRE; - sign * signs; //Gol sim int CGOL; int ISGOL; |
