From 5cd416d82feaed3e4ff7bc7dffcf4100081b8df2 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 30 Jul 2005 20:57:18 +0000 Subject: [PATCH] This was SVN commit r2567. --- source/tools/rmgen/api.cpp | 6 +-- source/tools/rmgen/convert.h | 2 +- source/tools/rmgen/entity.cpp | 16 ------- source/tools/rmgen/entity.h | 15 ------- source/tools/rmgen/map.cpp | 46 +++++++++---------- source/tools/rmgen/map.h | 14 +++--- source/tools/rmgen/object.cpp | 15 +++++-- source/tools/rmgen/object.h | 15 ++++--- source/tools/rmgen/objectgroupplacer.cpp | 11 +++++ source/tools/rmgen/objectgroupplacer.h | 16 +++++++ source/tools/rmgen/output.cpp | 56 ++++++++++++++++-------- source/tools/rmgen/rmgen.vcproj | 4 +- source/tools/rmgen/terrain.cpp | 8 ++-- 13 files changed, 123 insertions(+), 101 deletions(-) delete mode 100644 source/tools/rmgen/entity.cpp delete mode 100644 source/tools/rmgen/entity.h create mode 100644 source/tools/rmgen/objectgroupplacer.cpp create mode 100644 source/tools/rmgen/objectgroupplacer.h diff --git a/source/tools/rmgen/api.cpp b/source/tools/rmgen/api.cpp index a101589a4e..8c616fd633 100644 --- a/source/tools/rmgen/api.cpp +++ b/source/tools/rmgen/api.cpp @@ -3,7 +3,7 @@ #include "rmgen.h" #include "random.h" #include "map.h" -#include "entity.h" +#include "object.h" #include "convert.h" #include "terrain.h" #include "simpleconstraints.h" @@ -223,7 +223,7 @@ JSBool placeObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval JS_ValueToNumber(cx, argv[3], &y); JS_ValueToNumber(cx, argv[4], &orientation); - theMap->addEntity(new Entity(type, player, x,0,y, orientation)); + theMap->addObject(new Object(type, player, x,0,y, orientation)); return JS_TRUE; } @@ -309,7 +309,7 @@ JSBool createObjectGroup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, constr = new NullConstraint(); } - vector* ret = theMap->createObjectGroup(placer, constr); + vector* ret = theMap->createObjectGroup(placer, constr); delete placer; delete constr; diff --git a/source/tools/rmgen/convert.h b/source/tools/rmgen/convert.h index 02b413ad30..73d8e4c283 100644 --- a/source/tools/rmgen/convert.h +++ b/source/tools/rmgen/convert.h @@ -2,7 +2,7 @@ #define __CONVERT_H__ #include "map.h" -#include "entity.h" +#include "object.h" #include "constraint.h" #include "areapainter.h" #include "areaplacer.h" diff --git a/source/tools/rmgen/entity.cpp b/source/tools/rmgen/entity.cpp deleted file mode 100644 index 1f09428788..0000000000 --- a/source/tools/rmgen/entity.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "stdafx.h" -#include "entity.h" - -using namespace std; - -Entity::Entity() { -} - -Entity::Entity(const string& type, int player, float x, float y, float z, float orientation) { - this->type = type; - this->player = player; - this->x = x; - this->y = y; - this->z = z; - this->orientation = orientation; -} \ No newline at end of file diff --git a/source/tools/rmgen/entity.h b/source/tools/rmgen/entity.h deleted file mode 100644 index 06453d5f5f..0000000000 --- a/source/tools/rmgen/entity.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __ENTITY_H__ -#define __ENTITY_H__ - -class Entity { -public: - std::string type; // called "template" in XML? - int player; - float x, y, z; - float orientation; - - Entity(); - Entity(const std::string& type, int player, float x, float y, float z, float orientation); -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/map.cpp b/source/tools/rmgen/map.cpp index d2e885e945..bb86278408 100644 --- a/source/tools/rmgen/map.cpp +++ b/source/tools/rmgen/map.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "rmgen.h" #include "map.h" -#include "entity.h" +#include "object.h" using namespace std; @@ -24,9 +24,9 @@ Map::Map(int size, Terrain* baseTerrain, float baseHeight) { texture[i] = new int[size]; } - terrainEntities = new vector*[size]; + terrainObjects = new vector*[size]; for(int i=0; i[size]; + terrainObjects[i] = new vector[size]; } area = new Area**[size]; @@ -148,9 +148,9 @@ Map::Map(string fileName, int loadLevel) } } - terrainEntities = new vector*[size]; + terrainObjects = new vector*[size]; for(int i=0; i[size]; + terrainObjects[i] = new vector[size]; } area = new Area**[size]; @@ -193,9 +193,9 @@ Map::~Map() { delete[] texture; for(int i=0; i Map::getTerrainEntities(int x, int y) { - if(!validT(x,y)) JS_ReportError(cx, "getTerrainEntities: invalid tile position"); - return terrainEntities[x][y]; +vector Map::getTerrainObjects(int x, int y) { + if(!validT(x,y)) JS_ReportError(cx, "getTerrainObjects: invalid tile position"); + return terrainObjects[x][y]; } -void Map::setTerrainEntities(int x, int y, vector &entities) { - if(!validT(x,y)) JS_ReportError(cx, "setTerrainEntities: invalid tile position"); - terrainEntities[x][y] = entities; +void Map::setTerrainObjects(int x, int y, vector &objects) { + if(!validT(x,y)) JS_ReportError(cx, "setTerrainObjects: invalid tile position"); + terrainObjects[x][y] = objects; } void Map::placeTerrain(int x, int y, Terrain* t) { t->place(this, x, y); } -void Map::addEntity(Entity* ent) { - entities.push_back(ent); +void Map::addObject(Object* ent) { + objects.push_back(ent); } Area* Map::createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* constr) { @@ -284,13 +284,13 @@ Area* Map::createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* cons return a; } -vector* Map::createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr) { - vector* entities = new vector; - if(!placer->place(this, constr, *entities)) { +vector* Map::createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr) { + vector* objects = new vector; + if(!placer->place(this, constr, *objects)) { return 0; } - for(int i=0; isize(); i++) { - addEntity((*entities)[i]); + for(int i=0; isize(); i++) { + addObject((*objects)[i]); } - return entities; + return objects; } \ No newline at end of file diff --git a/source/tools/rmgen/map.h b/source/tools/rmgen/map.h index 5f1405333c..3eb40d59cb 100644 --- a/source/tools/rmgen/map.h +++ b/source/tools/rmgen/map.h @@ -5,7 +5,7 @@ #include "areapainter.h" #include "areaplacer.h" #include "constraint.h" -#include "entity.h" +#include "object.h" #include "terrain.h" #include "objectgroupplacer.h" @@ -13,12 +13,12 @@ class Map { public: int size; int** texture; - std::vector** terrainEntities; + std::vector** terrainObjects; float** height; Area*** area; std::map nameToId; std::map idToName; - std::vector entities; + std::vector objects; std::vector areas; Map(int size, Terrain* baseTerrain, float baseHeight); @@ -36,15 +36,15 @@ public: float getHeight(int x, int y); void setHeight(int x, int y, float height); - std::vector getTerrainEntities(int x, int y); - void setTerrainEntities(int x, int y, std::vector &entities); + std::vector getTerrainObjects(int x, int y); + void setTerrainObjects(int x, int y, std::vector &objects); void placeTerrain(int x, int y, Terrain* t); - void addEntity(class Entity* ent); + void addObject(class Object* ent); Area* createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* constr); - std::vector* createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr); + std::vector* createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr); }; #endif \ No newline at end of file diff --git a/source/tools/rmgen/object.cpp b/source/tools/rmgen/object.cpp index 1f09428788..0c6c3f1bfc 100644 --- a/source/tools/rmgen/object.cpp +++ b/source/tools/rmgen/object.cpp @@ -1,16 +1,23 @@ #include "stdafx.h" -#include "entity.h" +#include "object.h" using namespace std; -Entity::Entity() { +Object::Object() { } -Entity::Entity(const string& type, int player, float x, float y, float z, float orientation) { - this->type = type; +Object::Object(const string& name, int player, float x, float y, float z, float orientation) { + this->name = name; this->player = player; this->x = x; this->y = y; this->z = z; this->orientation = orientation; +} + +bool Object::isEntity() { + for(int i=0; i& ret) = 0; + + ObjectGroupPlacer(void); + virtual ~ObjectGroupPlacer(void); +}; + +#endif \ No newline at end of file diff --git a/source/tools/rmgen/output.cpp b/source/tools/rmgen/output.cpp index 17dd6a161f..5f55d38e95 100644 --- a/source/tools/rmgen/output.cpp +++ b/source/tools/rmgen/output.cpp @@ -2,21 +2,50 @@ #include "rmgen.h" #include "output.h" #include "map.h" -#include "entity.h" +#include "object.h" using namespace std; typedef unsigned short u16; typedef unsigned int u32; -void OutputEntity(Entity* e, ostringstream& xml) { - xml << "\ +void OutputObject(Object* e, ostringstream& xml) { + if(e->isEntity()) { + xml << "\ \n\ - \n\ + \n\ " << e->player << "\n\ x << "\" y=\"" << 4*e->y << "\" z=\"" << 4*e->z << "\" />\n\ orientation << "\" />\n\ \n"; + } + else { + xml << "\ + \n\ + " << e->name << "\n\ + x << "\" y=\"" << 4*e->y << "\" z=\"" << 4*e->z << "\" />\n\ + orientation << "\" />\n\ + \n"; + } +} + +void OutputObjects(ostringstream& xml, Map* m, bool entities) { + for(int i=0; iobjects.size(); i++) { + if(m->objects[i]->isEntity() == entities) { + OutputObject(m->objects[i], xml); + } + } + + for(int x=0; xsize; x++) { + for(int y=0; ysize; y++) { + vector& vec = m->terrainObjects[x][y]; + for(int i=0; iisEntity() == entities) { + OutputObject(vec[i], xml); + } + } + } + } } void OutputXml(Map* m, FILE* f) { @@ -33,23 +62,12 @@ void OutputXml(Map* m, FILE* f) { \n\ \n\ \n"; - - for(int i=0; ientities.size(); i++) { - OutputEntity(m->entities[i], xml); - } - - for(int x=0; xsize; x++) { - for(int y=0; ysize; y++) { - vector& vec = m->terrainEntities[x][y]; - for(int i=0; i\n\ - \n\ + \n"; + OutputObjects(xml, m, false); // print nonentities + xml << "\n\ \n"; fprintf(f, "%s", xml.str().c_str()); diff --git a/source/tools/rmgen/rmgen.vcproj b/source/tools/rmgen/rmgen.vcproj index ebc7dfa427..3ead46d7b8 100644 --- a/source/tools/rmgen/rmgen.vcproj +++ b/source/tools/rmgen/rmgen.vcproj @@ -136,7 +136,7 @@ RelativePath=".\convert.cpp"> + RelativePath=".\object.cpp"> @@ -219,7 +219,7 @@ RelativePath=".\convert.h"> + RelativePath=".\object.h"> diff --git a/source/tools/rmgen/terrain.cpp b/source/tools/rmgen/terrain.cpp index e39ba44e9a..a266993d78 100644 --- a/source/tools/rmgen/terrain.cpp +++ b/source/tools/rmgen/terrain.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "terrain.h" #include "map.h" -#include "entity.h" +#include "object.h" #include "random.h" #include "rmgen.h" @@ -14,7 +14,7 @@ Terrain::Terrain() {} Terrain::~Terrain() {} void Terrain::place(Map* m, int x, int y) { - vector& vec = m->terrainEntities[x][y]; + vector& vec = m->terrainObjects[x][y]; for(int i=0; i& vec = m->terrainEntities[x][y]; + vector& vec = m->terrainObjects[x][y]; if(treeType != "") { - vec.push_back(new Entity(treeType, 0, x+0.5f, 0, y+0.5f, RandFloat()*PI)); + vec.push_back(new Object(treeType, 0, x+0.5f, 0, y+0.5f, RandFloat()*PI)); } m->texture[x][y] = m->getId(texture); }