From 03f608c34690ae21d5d9e1dff193512da438c810 Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 4 May 2008 10:32:18 +0000 Subject: [PATCH] spawn ents right after adding them in editmode git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1858 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entity.h | 4 ++++ source/src/world.cpp | 10 +++++++--- source/src/worldlight.cpp | 3 +-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/src/entity.h b/source/src/entity.h index 7eb37351..e50ffa1c 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -21,12 +21,16 @@ struct persistent_entity // map entity short attr1; uchar type; // type is one of the above uchar attr2, attr3, attr4; + persistent_entity(short x, short y, short z, uchar type, short attr1, uchar attr2, uchar attr3, uchar attr4) : x(x), y(y), z(z), type(type), attr1(attr1), attr2(attr2), attr3(attr3), attr4(attr4) {}; + persistent_entity(){}; }; struct entity : public persistent_entity { bool spawned; //the only dynamic state of a map entity bool soundinuse; + entity(short x, short y, short z, uchar type, short attr1, uchar attr2, uchar attr3, uchar attr4) : persistent_entity(x, y, z, type, attr1, attr2, attr3, attr4), spawned(false), soundinuse(false) {}; + entity(){}; }; struct itemstat { int add, start, max, sound; }; diff --git a/source/src/world.cpp b/source/src/world.cpp index 9a257c84..dddaf9fd 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -173,11 +173,14 @@ int findtype(char *what) entity *newentity(int x, int y, int z, char *what, int v1, int v2, int v3, int v4) { int type = findtype(what); - persistent_entity e = { x, y, z, v1, type, v2, v3, v4 }; + if(type==NOTUSED) return NULL; + + entity e(x, y, z, type, v1, v2, v3, v4); + switch(type) { case LIGHT: - if(v1>64) v1 = 64;//if(v1>32) v1=32; + if(v1>64) v1 = 64; if(!v1) e.attr1 = 16; if(!v2 && !v3 && !v4) e.attr2 = 255; break; @@ -193,7 +196,8 @@ entity *newentity(int x, int y, int z, char *what, int v1, int v2, int v3, int v break; } addmsg(SV_EDITENT, "ri9", ents.length(), type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4); - ents.add(*((entity *)&e)); // unsafe! + e.spawned = true; + ents.add(e); if(type==LIGHT) calclight(); return &ents.last(); } diff --git a/source/src/worldlight.cpp b/source/src/worldlight.cpp index 9318369f..de57ec5b 100644 --- a/source/src/worldlight.cpp +++ b/source/src/worldlight.cpp @@ -184,8 +184,7 @@ void dodynlight(vec &vold, vec &v, int reach, int strength, dynent *owner) if(b.ys+b.y>ssize-2) b.ys = ssize-2-b.y; dlights.add(blockcopy(b)); // backup area before rendering in dynlight - - persistent_entity l = { (int)v.x, (int)v.y, (int)v.z, reach, LIGHT, strength, 0, 0 }; + persistent_entity l((int)v.x, (int)v.y, (int)v.z, LIGHT, reach, strength, 0, 0); calclightsource(l); postlightarea(b); }