This was SVN commit r2567.

This commit is contained in:
Matei
2005-07-30 20:57:18 +00:00
parent e63d314f74
commit 5cd416d82f
13 changed files with 123 additions and 101 deletions
+3 -3
View File
@@ -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<Entity*>* ret = theMap->createObjectGroup(placer, constr);
vector<Object*>* ret = theMap->createObjectGroup(placer, constr);
delete placer;
delete constr;
+1 -1
View File
@@ -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"
-16
View File
@@ -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;
}
-15
View File
@@ -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
+23 -23
View File
@@ -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<Entity*>*[size];
terrainObjects = new vector<Object*>*[size];
for(int i=0; i<size; i++) {
terrainEntities[i] = new vector<Entity*>[size];
terrainObjects[i] = new vector<Object*>[size];
}
area = new Area**[size];
@@ -148,9 +148,9 @@ Map::Map(string fileName, int loadLevel)
}
}
terrainEntities = new vector<Entity*>*[size];
terrainObjects = new vector<Object*>*[size];
for(int i=0; i<size; i++) {
terrainEntities[i] = new vector<Entity*>[size];
terrainObjects[i] = new vector<Object*>[size];
}
area = new Area**[size];
@@ -193,9 +193,9 @@ Map::~Map() {
delete[] texture;
for(int i=0; i<size; i++) {
delete[] terrainEntities[i];
delete[] terrainObjects[i];
}
delete[] terrainEntities;
delete[] terrainObjects;
for(int i=0; i<size+1; i++) {
delete[] height[i];
@@ -207,8 +207,8 @@ Map::~Map() {
}
delete[] area;
for(int i=0; i<entities.size(); i++) {
delete entities[i];
for(int i=0; i<objects.size(); i++) {
delete objects[i];
}
}
@@ -252,22 +252,22 @@ void Map::setHeight(int x, int y, float h) {
height[x][y] = h;
}
vector<Entity*> Map::getTerrainEntities(int x, int y) {
if(!validT(x,y)) JS_ReportError(cx, "getTerrainEntities: invalid tile position");
return terrainEntities[x][y];
vector<Object*> 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<Entity*> &entities) {
if(!validT(x,y)) JS_ReportError(cx, "setTerrainEntities: invalid tile position");
terrainEntities[x][y] = entities;
void Map::setTerrainObjects(int x, int y, vector<Object*> &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<Entity*>* Map::createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr) {
vector<Entity*>* entities = new vector<Entity*>;
if(!placer->place(this, constr, *entities)) {
vector<Object*>* Map::createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr) {
vector<Object*>* objects = new vector<Object*>;
if(!placer->place(this, constr, *objects)) {
return 0;
}
for(int i=0; i<entities->size(); i++) {
addEntity((*entities)[i]);
for(int i=0; i<objects->size(); i++) {
addObject((*objects)[i]);
}
return entities;
return objects;
}
+7 -7
View File
@@ -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<Entity*>** terrainEntities;
std::vector<Object*>** terrainObjects;
float** height;
Area*** area;
std::map<std::string, int> nameToId;
std::map<int, std::string> idToName;
std::vector<Entity*> entities;
std::vector<Object*> objects;
std::vector<Area*> 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<Entity*> getTerrainEntities(int x, int y);
void setTerrainEntities(int x, int y, std::vector<Entity*> &entities);
std::vector<Object*> getTerrainObjects(int x, int y);
void setTerrainObjects(int x, int y, std::vector<Object*> &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<Entity*>* createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr);
std::vector<Object*>* createObjectGroup(ObjectGroupPlacer* placer, Constraint* constr);
};
#endif
+11 -4
View File
@@ -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<name.size(); i++) {
if(name[i]=='/') return false;
}
return true;
}
+8 -7
View File
@@ -1,15 +1,16 @@
#ifndef __ENTITY_H__
#define __ENTITY_H__
#ifndef __OBJECT_H__
#define __OBJECT_H__
class Entity {
class Object {
public:
std::string type; // called "template" in XML?
int player;
std::string name; // "template" field for objects, "actor" field for nonobjects
int player; // -1 for nonobjects
float x, y, z;
float orientation;
Entity();
Entity(const std::string& type, int player, float x, float y, float z, float orientation);
Object();
Object(const std::string& name, int player, float x, float y, float z, float orientation);
bool isEntity();
};
#endif
+11
View File
@@ -0,0 +1,11 @@
#include "stdafx.h"
#include "rmgen.h"
#include "objectgroupplacer.h"
ObjectGroupPlacer::ObjectGroupPlacer() {
}
ObjectGroupPlacer::~ObjectGroupPlacer() {
}
using namespace std;
+16
View File
@@ -0,0 +1,16 @@
#ifndef __OBJECTGROUPPLACER_H__
#define __OBJECTGROUPPLACER_H__
#include "constraint.h"
#include "object.h"
class ObjectGroupPlacer
{
public:
virtual bool place(class Map* m, Constraint* constr, std::vector<Object*>& ret) = 0;
ObjectGroupPlacer(void);
virtual ~ObjectGroupPlacer(void);
};
#endif
+37 -19
View File
@@ -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 << "\
<Entity>\n\
<Template>" << e->type << "</Template>\n\
<Template>" << e->name << "</Template>\n\
<Player>" << e->player << "</Player>\n\
<Position x=\"" << 4*e->x << "\" y=\"" << 4*e->y << "\" z=\"" << 4*e->z << "\" />\n\
<Orientation angle=\"" << e->orientation << "\" />\n\
</Entity>\n";
}
else {
xml << "\
<Nonentity>\n\
<Actor>" << e->name << "</Actor>\n\
<Position x=\"" << 4*e->x << "\" y=\"" << 4*e->y << "\" z=\"" << 4*e->z << "\" />\n\
<Orientation angle=\"" << e->orientation << "\" />\n\
</Nonentity>\n";
}
}
void OutputObjects(ostringstream& xml, Map* m, bool entities) {
for(int i=0; i<m->objects.size(); i++) {
if(m->objects[i]->isEntity() == entities) {
OutputObject(m->objects[i], xml);
}
}
for(int x=0; x<m->size; x++) {
for(int y=0; y<m->size; y++) {
vector<Object*>& vec = m->terrainObjects[x][y];
for(int i=0; i<vec.size(); i++) {
if(vec[i]->isEntity() == entities) {
OutputObject(vec[i], xml);
}
}
}
}
}
void OutputXml(Map* m, FILE* f) {
@@ -33,23 +62,12 @@ void OutputXml(Map* m, FILE* f) {
<UnitsAmbientColour r=\"0.4\" g=\"0.4\" b=\"0.4\" />\n\
</Environment>\n\
<Entities>\n";
for(int i=0; i<m->entities.size(); i++) {
OutputEntity(m->entities[i], xml);
}
for(int x=0; x<m->size; x++) {
for(int y=0; y<m->size; y++) {
vector<Entity*>& vec = m->terrainEntities[x][y];
for(int i=0; i<vec.size(); i++) {
OutputEntity(vec[i], xml);
}
}
}
OutputObjects(xml, m, true); // print entities
xml << "\
</Entities>\n\
<Nonentities />\n\
<Nonentities>\n";
OutputObjects(xml, m, false); // print nonentities
xml << "</Nonentities>\n\
</Scenario>\n";
fprintf(f, "%s", xml.str().c_str());
+2 -2
View File
@@ -136,7 +136,7 @@
RelativePath=".\convert.cpp">
</File>
<File
RelativePath=".\entity.cpp">
RelativePath=".\object.cpp">
</File>
<File
RelativePath=".\layeredpainter.cpp">
@@ -219,7 +219,7 @@
RelativePath=".\convert.h">
</File>
<File
RelativePath=".\entity.h">
RelativePath=".\object.h">
</File>
<File
RelativePath=".\layeredpainter.h">
+4 -4
View File
@@ -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<Entity*>& vec = m->terrainEntities[x][y];
vector<Object*>& vec = m->terrainObjects[x][y];
for(int i=0; i<vec.size(); i++) {
delete vec[i];
}
@@ -37,9 +37,9 @@ SimpleTerrain::SimpleTerrain(const std::string& texture, const std::string& tree
}
void SimpleTerrain::placeNew(Map* m, int x, int y) {
vector<Entity*>& vec = m->terrainEntities[x][y];
vector<Object*>& 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);
}