diff --git a/source/sound/SoundGroup.cpp b/source/sound/SoundGroup.cpp index 735cc61427..7624a0f8bd 100644 --- a/source/sound/SoundGroup.cpp +++ b/source/sound/SoundGroup.cpp @@ -34,6 +34,7 @@ #include "ps/XML/Xeromyces.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" +#include "ps/Util.h" static const bool DISABLE_INTENSITY = true; // disable for now since it's broken @@ -121,7 +122,7 @@ static void HandleError(const std::wstring& message, const VfsPath& pathname, Li { if(err == ERR::AGAIN) return; // open failed because sound is disabled (don't log this) - LOGERROR(L"%ls: pathname=%ls, error=%ld", message.c_str(), pathname.string().c_str(), err); + LOGERROR(L"%ls: pathname=%ls, error=%ls", message.c_str(), pathname.string().c_str(), ErrorString(err)); } void CSoundGroup::PlayNext(const CVector3D& position) diff --git a/source/tools/rmgen/MathUtil.h b/source/tools/rmgen/MathUtil.h deleted file mode 100644 index 21927d3465..0000000000 --- a/source/tools/rmgen/MathUtil.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MATH_UTIL_H -#define MATH_UTIL_H - -#ifndef PI -#define PI 3.14159265358979323846f -#endif - -#define DEGTORAD(a) ((a) * (PI/180.0f)) -#define RADTODEG(a) ((a) * (180.0f/PI)) -#define SQR(x) ((x) * (x)) - -template -T Interpolate(T& a, T& b, float l) -{ - return a + (b - a) * l; -} - -template -inline T clamp(T value, T min, T max) -{ - if (value <= min) return min; - else if (value >= max) return max; - else return value; -} - -static inline int RoundUpToPowerOf2(int x) -{ - if ((x & (x-1)) == 0) - return x; - int d = x; - while (d & (d-1)) - d &= (d-1); - return d << 1; -} - -inline float sgn(float a) -{ - if (a > 0.0f) return 1.0f; - if (a < 0.0f) return -1.0f; - return 0.0f; -} - -#endif diff --git a/source/tools/rmgen/ReadMe.txt b/source/tools/rmgen/ReadMe.txt deleted file mode 100644 index 9a4de6ce3d..0000000000 --- a/source/tools/rmgen/ReadMe.txt +++ /dev/null @@ -1,32 +0,0 @@ -======================================================================== - CONSOLE APPLICATION : rmgen Project Overview -======================================================================== - -AppWizard has created this rmgen application for you. -This file contains a summary of what you will find in each of the files that -make up your rmgen application. - - -rmgen.vcproj - This is the main project file for VC++ projects generated using an Application Wizard. - It contains information about the version of Visual C++ that generated the file, and - information about the platforms, configurations, and project features selected with the - Application Wizard. - -rmgen.cpp - This is the main application source file. - -///////////////////////////////////////////////////////////////////////////// -Other standard files: - -StdAfx.h, StdAfx.cpp - These files are used to build a precompiled header (PCH) file - named rmgen.pch and a precompiled types file named StdAfx.obj. - -///////////////////////////////////////////////////////////////////////////// -Other notes: - -AppWizard uses "TODO:" comments to indicate parts of the source code you -should add to or customize. - -///////////////////////////////////////////////////////////////////////////// diff --git a/source/tools/rmgen/Vector2D.h b/source/tools/rmgen/Vector2D.h deleted file mode 100644 index 2fc9608c11..0000000000 --- a/source/tools/rmgen/Vector2D.h +++ /dev/null @@ -1,96 +0,0 @@ -//*********************************************************** -// Name: Vector2D.h -// Description: Provides an interface for a vector in R4 and -// allows vector and scalar operations on it -// -//*********************************************************** - -#ifndef VECTOR2D_H -#define VECTOR2D_H - - -#include - -/////////////////////////////////////////////////////////////////////////////// -// CVector2D_Maths: -class CVector2D_Maths -{ -public: - CVector2D_Maths() {} - CVector2D_Maths(float x,float y) { X=x; Y=y; } - CVector2D_Maths(const CVector2D_Maths& p) { X=p.X; Y=p.Y; } - - operator float*() { - return &X; - } - - operator const float*() const { - return &X; - } - - CVector2D_Maths operator-() const { - return CVector2D_Maths(-X, -Y); - } - - CVector2D_Maths operator+(const CVector2D_Maths& t) const { - return CVector2D_Maths(X+t.X, Y+t.Y); - } - - CVector2D_Maths operator-(const CVector2D_Maths& t) const { - return CVector2D_Maths(X-t.X, Y-t.Y); - } - - CVector2D_Maths operator*(float f) const { - return CVector2D_Maths(X*f, Y*f); - } - - CVector2D_Maths operator/(float f) const { - float inv=1.0f/f; - return CVector2D_Maths(X*inv, Y*inv); - } - - CVector2D_Maths& operator+=(const CVector2D_Maths& t) { - X+=t.X; Y+=t.Y; - return *this; - } - - CVector2D_Maths& operator-=(const CVector2D_Maths& t) { - X-=t.X; Y-=t.Y; - return *this; - } - - CVector2D_Maths& operator*=(float f) { - X*=f; Y*=f; - return *this; - } - - CVector2D_Maths& operator/=(float f) { - float invf=1.0f/f; - X*=invf; Y*=invf; - return *this; - } - - float Dot(const CVector2D_Maths& a) const { - return X*a.X + Y*a.Y; - } - - float LengthSquared() const { - return Dot(*this); - } - - float Length() const { - return (float) sqrt(LengthSquared()); - } - - void Normalize() { - float mag=Length(); - X/=mag; Y/=mag; - } - -public: - float X, Y; -}; -////////////////////////////////////////////////////////////////////////////////// - - -#endif diff --git a/source/tools/rmgen/Vector3D.cpp b/source/tools/rmgen/Vector3D.cpp deleted file mode 100644 index ddbb8e7b31..0000000000 --- a/source/tools/rmgen/Vector3D.cpp +++ /dev/null @@ -1,135 +0,0 @@ -//*********************************************************** -// Name: Vector3D.Cpp -/ -// Description: Provides an interface for a vector in R3 and -// allows vector and scalar operations on it -// -//*********************************************************** - -#include "stdafx.h" - -#include "Vector3D.h" - -#include -#include "MathUtil.h" - -int CVector3D::operator ! () const -{ - if (X != 0.0f || - Y != 0.0f || - Z != 0.0f) - - return 0; - - return 1; -} - -bool CVector3D::operator== (const CVector3D &vector) const -{ - return (X == vector.X && Y == vector.Y && Z == vector.Z); -} - -//vector addition -CVector3D CVector3D::operator + (const CVector3D &vector) const -{ - return CVector3D(X+vector.X, Y+vector.Y, Z+vector.Z); -} - -//vector addition/assignment -CVector3D &CVector3D::operator += (const CVector3D &vector) -{ - X += vector.X; - Y += vector.Y; - Z += vector.Z; - - return *this; -} - -//vector subtraction -CVector3D CVector3D::operator - (const CVector3D &vector) const -{ - return CVector3D(X-vector.X, Y-vector.Y, Z-vector.Z); -} - -//vector negation -CVector3D CVector3D::operator-() const -{ - return CVector3D(-X, -Y, -Z); -} -//vector subtrcation/assignment -CVector3D &CVector3D::operator -= (const CVector3D &vector) -{ - X -= vector.X; - Y -= vector.Y; - Z -= vector.Z; - - return *this; -} - -//scalar multiplication -CVector3D CVector3D::operator * (float value) const -{ - return CVector3D(X*value, Y*value, Z*value); -} - -//scalar multiplication/assignment -CVector3D& CVector3D::operator *= (float value) -{ - X *= value; - Y *= value; - Z *= value; - - return *this; -} - -void CVector3D::Set (float x, float y, float z) -{ - X = x; - Y = y; - Z = z; -} - -void CVector3D::Clear () -{ - X = Y = Z = 0.0f; -} - -//Dot product -float CVector3D::Dot (const CVector3D &vector) const -{ - return ( X * vector.X + - Y * vector.Y + - Z * vector.Z ); -} - -//Cross product -CVector3D CVector3D::Cross (const CVector3D &vector) const -{ - CVector3D Temp; - - Temp.X = (Y * vector.Z) - (Z * vector.Y); - Temp.Y = (Z * vector.X) - (X * vector.Z); - Temp.Z = (X * vector.Y) - (Y * vector.X); - - return Temp; -} - - -float CVector3D::LengthSquared () const -{ - return ( SQR(X) + SQR(Y) + SQR(Z) ); -} - -float CVector3D::GetLength () const -{ - return sqrtf ( LengthSquared() ); -} - -void CVector3D::Normalize () -{ - float scale = 1.0f/GetLength (); - - X *= scale; - Y *= scale; - Z *= scale; -} diff --git a/source/tools/rmgen/Vector3D.h b/source/tools/rmgen/Vector3D.h deleted file mode 100644 index f930921934..0000000000 --- a/source/tools/rmgen/Vector3D.h +++ /dev/null @@ -1,65 +0,0 @@ -//*********************************************************** -// Name: Vector3D.H -// Description: Provides an interface for a vector in R3 and -// allows vector and scalar operations on it -// -//*********************************************************** - -#ifndef VECTOR3D_H -#define VECTOR3D_H - -class CVector3D -{ - public: - float X, Y, Z; - - public: - CVector3D () : X(0.0f), Y(0.0f), Z(0.0f) {} - CVector3D (float x, float y, float z) : X(x), Y(y), Z(z) {} - - int operator!() const; - - float& operator[](int index) { return *((&X)+index); } - const float& operator[](int index) const { return *((&X)+index); } - - //vector equality (testing float equality, so please be careful if necessary) - bool operator== (const CVector3D &vector) const; - bool operator!= (const CVector3D &vector) const { return !operator==(vector); } - - //vector addition - CVector3D operator + (const CVector3D &vector) const ; - //vector addition/assignment - CVector3D &operator += (const CVector3D &vector); - - //vector subtraction - CVector3D operator - (const CVector3D &vector) const ; - //vector subtraction/assignment - CVector3D &operator -= (const CVector3D &vector); - - //scalar multiplication - CVector3D operator * (float value) const ; - //scalar multiplication/assignment - CVector3D& operator *= (float value); - - // negation - CVector3D operator-() const; - - public: - void Set (float x, float y, float z); - void Clear (); - - //Dot product - float Dot (const CVector3D &vector) const; - //Cross product - CVector3D Cross (const CVector3D &vector) const; - - //Returns length of the vector - float GetLength () const; - float LengthSquared () const; - void Normalize (); - - // Returns 3 element array of floats, e.g. for glVertex3fv - const float* GetFloatArray() const { return &X; } -}; - -#endif diff --git a/source/tools/rmgen/api.cpp b/source/tools/rmgen/api.cpp deleted file mode 100644 index 927d11d9c0..0000000000 --- a/source/tools/rmgen/api.cpp +++ /dev/null @@ -1,418 +0,0 @@ -#include "stdafx.h" -#include "api.h" -#include "rmgen.h" -#include "random.h" -#include "map.h" -#include "object.h" -#include "convert.h" -#include "terrain.h" -#include "simpleconstraints.h" - -using namespace std; - -// Function specs - -JSFunctionSpec globalFunctions[] = { -// {name, native, args} - {"init", init, 3}, - {"initFromScenario", initFromScenario, 2}, - {"print", print, 1}, - {"error", error, 1}, - {"getTexture", getTexture, 2}, - {"setTexture", setTexture, 3}, - {"getHeight", getHeight, 2}, - {"setHeight", setHeight, 3}, - {"getMapSize", getMapSize, 0}, - {"randInt", randInt, 2}, - {"randFloat", randFloat, 1}, - {"placeTerrain", placeTerrain, 3}, - {"placeObject", placeObject, 4}, - {"createArea", createArea, 3}, - {"createObjectGroup", createObjectGroup, 3}, - {"createTileClass", createTileClass, 0}, - {"addToClass", addToClass, 0}, - {"removeFromClass", removeFromClass, 0}, - {0, 0, 0} -}; - -// Helper function to validate argument types; the types string can contain the following: -// i (integers), s (strings), n (numbers), . (anything); for example ValidateArgs("iin",...) -// would check that arguments 1 and 2 are integers while the third is a number. -void ValidateArgs(const char* types, JSContext* cx, uintN argc, jsval* argv, const char* function) { - int num = strlen(types); - if(argc != num) { - JS_ReportError(cx, "%s: requires %d arguments but got %d", function, num, argc); - } - JSObject* obj; - for(int i=0; igetTexture(x, y); - *rval = NewJSString(texture); - return JS_TRUE; -} - -JSBool setTexture(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("iis", cx, argc, argv, __FUNCTION__); - - int x = JSVAL_TO_INT(argv[0]); - int y = JSVAL_TO_INT(argv[1]); - char* texture = JS_GetStringBytes(JSVAL_TO_STRING(argv[2])); - theMap->setTexture(x, y, texture); - return JS_TRUE; -} - -JSBool getHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("ii", cx, argc, argv, __FUNCTION__); - - int x = JSVAL_TO_INT(argv[0]); - int y = JSVAL_TO_INT(argv[1]); - jsdouble height = theMap->getHeight(x, y); - JS_NewDoubleValue(cx, height, rval); - return JS_TRUE; -} - -JSBool setHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("iin", cx, argc, argv, __FUNCTION__); - - int x = JSVAL_TO_INT(argv[0]); - int y = JSVAL_TO_INT(argv[1]); - jsdouble height; - JS_ValueToNumber(cx, argv[2], &height); - theMap->setHeight(x, y, (float) height); - return JS_TRUE; -} - -JSBool randInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - if(argc!=1 && argc!=2) { - JS_ReportError(cx, "randInt: requires 1 or 2 arguments but got %d", argc); - } - if(!JSVAL_IS_INT(argv[0])) { - JS_ReportError(cx, "randInt: argument 1 must be an integer"); - } - if(argc==2 && !JSVAL_IS_INT(argv[1])) { - JS_ReportError(cx, "randInt: argument 2 must be an integer"); - } - - int minVal = argc==1 ? 0 : JSVAL_TO_INT(argv[0]); - int maxVal = argc==1 ? JSVAL_TO_INT(argv[0]) : JSVAL_TO_INT(argv[1])-1; - if(maxVal < minVal) { - JS_ReportError(cx, argc==1 ? "randInt: argument must be positive" - : "randInt: argument 2 must be greater than or equal to argument 1"); - } - int r = RandInt(minVal, maxVal); - *rval = INT_TO_JSVAL(r); - return JS_TRUE; -} - -JSBool randFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - if(argc!=0 && argc!=2) { - JS_ReportError(cx, "randFloat: requires 0 or 2 arguments but got %d", argc); - } - - jsdouble r; - - if(argc==0) { - r = RandFloat(); - } - else { - if(!JSVAL_IS_NUMBER(argv[0])) { - JS_ReportError(cx, "randFloat: argument 1 must be a number"); - } - if(!JSVAL_IS_NUMBER(argv[1])) { - JS_ReportError(cx, "randFloat: argument 2 must be a number"); - } - - jsdouble minVal, maxVal; - JS_ValueToNumber(cx, argv[0], &minVal); - JS_ValueToNumber(cx, argv[1], &maxVal); - - if(maxVal < minVal) { - JS_ReportError(cx, "randFloat: argument 2 must be greater than or equal to argument 1"); - } - - r = RandFloat(minVal, maxVal); - } - - JS_NewDoubleValue(cx, r, rval); - return JS_TRUE; -} - -JSBool placeObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("sinnn", cx, argc, argv, __FUNCTION__); - - string type = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); - int player = JSVAL_TO_INT(argv[1]); - jsdouble x, y, orientation; - JS_ValueToNumber(cx, argv[2], &x); - JS_ValueToNumber(cx, argv[3], &y); - JS_ValueToNumber(cx, argv[4], &orientation); - - theMap->addObject(new Object(type, player, x,y, orientation)); - - return JS_TRUE; -} - -JSBool placeTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("ii*", cx, argc, argv, __FUNCTION__); - - int x = JSVAL_TO_INT(argv[0]); - int y = JSVAL_TO_INT(argv[1]); - Terrain* terrain = ParseTerrain(cx, argv[2]); - if(!terrain) { - JS_ReportError(cx, "placeTerrain: invalid terrain argument"); - } - theMap->placeTerrain(x, y, terrain); - return JS_TRUE; -} - -JSBool createArea(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - if(argc != 2 && argc != 3) { - JS_ReportError(cx, "createArea: expected 2 or 3 arguments but got %d", argc); - } - - AreaPlacer* placer; - AreaPainter* painter; - Constraint* constr; - - if(!(placer = ParseAreaPlacer(cx, argv[0]))) { - JS_ReportError(cx, "createArea: argument 1 must be a valid area placer"); - } - if(!(painter = ParseAreaPainter(cx, argv[1]))) { - JS_ReportError(cx, "createArea: argument 2 must be a valid area painter"); - } - if(argc == 3) { - if(!(constr = ParseConstraint(cx, argv[2]))) { - JS_ReportError(cx, "createArea: argument 3 must be a valid constraint"); - } - } - else { - constr = new NullConstraint(); - } - - Area* area = theMap->createArea(placer, painter, constr); - - delete placer; - delete painter; - delete constr; - - if(!area) { - *rval = INT_TO_JSVAL(0); - } - else { - *rval = INT_TO_JSVAL(theMap->areas.size()); - } - return JS_TRUE; -} - -JSBool createObjectGroup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - if(argc != 2 && argc != 3) { - JS_ReportError(cx, "createObjectGroup: expected 1 or 2 arguments but got %d", argc); - } - - ObjectGroupPlacer* placer; - Constraint* constr; - - if(!(placer = ParseObjectGroupPlacer(cx, argv[0]))) { - JS_ReportError(cx, "createObjectGroup: argument 1 must be a valid object group placer"); - } - if(!JSVAL_IS_INT(argv[1])) { - JS_ReportError(cx, "createObjectGroup: argument 2 must be a valid player number"); - } - - if(argc == 3) { - if(!(constr = ParseConstraint(cx, argv[2]))) { - JS_ReportError(cx, "createObjectGroup: argument 3 must be a valid constraint"); - } - } - else { - constr = new NullConstraint(); - } - - int player = JSVAL_TO_INT(argv[1]); - - bool ret = theMap->createObjectGroup(placer, player, constr); - - delete placer; - delete constr; - - *rval = BOOLEAN_TO_JSVAL(ret); - return JS_TRUE; -} - -JSBool createTileClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - if(argc != 0) { - JS_ReportError(cx, "createTileClass: expected 0 arguments but got %d", argc); - } - - int id = theMap->createTileClass(); - - *rval = INT_TO_JSVAL(id); - return JS_TRUE; -} - -JSBool addToClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("iii", cx, argc, argv, __FUNCTION__); - - int x = JSVAL_TO_INT(argv[0]); - int y = JSVAL_TO_INT(argv[1]); - int classIndex = JSVAL_TO_INT(argv[2]) - 1; - - if(!theMap->validClass(classIndex) || !theMap->validT(x, y)) { - JS_ReportError(cx, "addToClass: Invalid arguments for addToClass(x, y, class)"); - } - - theMap->tileClasses[classIndex]->add(x, y); - - return JS_TRUE; -} - -JSBool removeFromClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - ValidateArgs("iii", cx, argc, argv, __FUNCTION__); - - int x = JSVAL_TO_INT(argv[0]); - int y = JSVAL_TO_INT(argv[1]); - int classIndex = JSVAL_TO_INT(argv[2]) - 1; - - if(!theMap->validClass(classIndex) || !theMap->validT(x, y)) { - JS_ReportError(cx, "addToClass: Invalid arguments for removeFromClass(x, y, class)"); - } - - theMap->tileClasses[classIndex]->remove(x, y); - - return JS_TRUE; -} - -JSBool getMapSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - CheckInit(true, cx, __FUNCTION__); - if(argc != 0) { - JS_ReportError(cx, "getMapSize: expected 0 arguments but got %d", argc); - } - - *rval = INT_TO_JSVAL(theMap->size); - return JS_TRUE; -} diff --git a/source/tools/rmgen/api.h b/source/tools/rmgen/api.h deleted file mode 100644 index 1dc27c6d5c..0000000000 --- a/source/tools/rmgen/api.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __API_H__ -#define __API_H__ - -// Function specs (registered by rmgen.cpp) -extern JSFunctionSpec globalFunctions[]; - -// JS API implementation - -// Map creation functions -JSBool init(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool initFromScenario(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); - -// Utility functions -JSBool error(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool randInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool randFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); - -// Low-level access to map data -JSBool getTexture(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool setTexture(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool getHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool setHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool getMapSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); - -// Low-level placement functions -JSBool placeTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool placeObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); - -// Medium-level placement functions (high level JS API sits on top of these) -JSBool createArea(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool createObjectGroup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); - -// Tile class functions -JSBool createTileClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool addToClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool removeFromClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/area.cpp b/source/tools/rmgen/area.cpp deleted file mode 100644 index 9dc4b1f1a6..0000000000 --- a/source/tools/rmgen/area.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "StdAfx.h" -#include ".\area.h" - -Area::Area(void) -{ -} - -Area::Area(const std::vector& points) { - this->points = points; -} - -Area::~Area(void) -{ -} diff --git a/source/tools/rmgen/area.h b/source/tools/rmgen/area.h deleted file mode 100644 index e6c03a4521..0000000000 --- a/source/tools/rmgen/area.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "point.h" - -class Area -{ -public: - std::vector points; - - Area(void); - Area(const std::vector& points); - ~Area(void); -}; diff --git a/source/tools/rmgen/areapainter.cpp b/source/tools/rmgen/areapainter.cpp deleted file mode 100644 index 30ae1606fc..0000000000 --- a/source/tools/rmgen/areapainter.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "StdAfx.h" -#include ".\areapainter.h" - -AreaPainter::AreaPainter(void) -{ -} - -AreaPainter::~AreaPainter(void) -{ -} diff --git a/source/tools/rmgen/areapainter.h b/source/tools/rmgen/areapainter.h deleted file mode 100644 index eb8d8479a5..0000000000 --- a/source/tools/rmgen/areapainter.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __AREAPAINTER_H__ -#define __AREAPAINTER_H__ - -class AreaPainter -{ -public: - virtual void paint(class Map* m, class Area* a) = 0; - - AreaPainter(void); - virtual ~AreaPainter(void); -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/areaplacer.cpp b/source/tools/rmgen/areaplacer.cpp deleted file mode 100644 index 17b65bf242..0000000000 --- a/source/tools/rmgen/areaplacer.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdafx.h" -#include "areaplacer.h" - -AreaPlacer::AreaPlacer(void) -{ -} - -AreaPlacer::~AreaPlacer(void) -{ -} diff --git a/source/tools/rmgen/areaplacer.h b/source/tools/rmgen/areaplacer.h deleted file mode 100644 index 3f4ab23426..0000000000 --- a/source/tools/rmgen/areaplacer.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __AREAPLACER_H__ -#define __AREAPLACER_H__ - -#include "point.h" -#include "constraint.h" - -class AreaPlacer -{ -public: - virtual bool place(class Map* m, Constraint* constr, std::vector& ret) = 0; - - AreaPlacer(void); - virtual ~AreaPlacer(void); -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/clumpplacer.cpp b/source/tools/rmgen/clumpplacer.cpp deleted file mode 100644 index 0440a40494..0000000000 --- a/source/tools/rmgen/clumpplacer.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "stdafx.h" -#include "clumpplacer.h" -#include "random.h" -#include "pointmap.h" - -using namespace std; - -ClumpPlacer::ClumpPlacer(float size, float coherence, float smoothness, float failFraction, int x, int y) -{ - this->size = size; - this->coherence = coherence; - this->smoothness = smoothness; - this->x = x; - this->y = y; - this->failFraction = failFraction; -} - -ClumpPlacer::~ClumpPlacer() -{ -} - -bool ClumpPlacer::place(class Map* m, Constraint* constr, std::vector& retVec) { - if(!m->validT(x, y) || !constr->allows(m, x, y)) { - return false; - } - - PointMap gotRet; - - float radius = sqrt(size / PI); - float perim = 4 * radius * 2 * PI; - int intPerim = (int)(ceil(perim)); - vector noise(intPerim); - - int ctrlPts = 1 + (int)(1.0/max(smoothness,1.0f/intPerim)); - if(ctrlPts > radius * 2 * PI) ctrlPts = (int) (radius * 2 * PI) + 1; - vector ctrlCoords(ctrlPts+1); - vector ctrlVals(ctrlPts+1); - for(int i=0; ivalidT(i, j) && constr->allows(m, i, j)) { - Point p(i,j); - if(!gotRet[p]) { - gotRet[p] = 1; - retVec.push_back(p); - } - } - else { - failed++; - } - xx += s; - yy += c; - } - } - - return (failed > size*failFraction ? false : true); -} \ No newline at end of file diff --git a/source/tools/rmgen/clumpplacer.h b/source/tools/rmgen/clumpplacer.h deleted file mode 100644 index 345029b12f..0000000000 --- a/source/tools/rmgen/clumpplacer.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __CLUMPPLACER_H__ -#define __CLUMPPLACER_H__ - -#include "areaplacer.h" -#include "map.h" - -class ClumpPlacer : public AreaPlacer -{ -private: - float size; - float coherence; - float smoothness; - float failFraction; - int x, y; -public: - virtual bool place(Map* m, Constraint* constr, std::vector& ret); - - ClumpPlacer(float size, float coherence, float smoothness, float failFraction, int x, int y); - virtual ~ClumpPlacer(); -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/constraint.cpp b/source/tools/rmgen/constraint.cpp deleted file mode 100644 index 39f94d21f0..0000000000 --- a/source/tools/rmgen/constraint.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdafx.h" -#include "constraint.h" - -Constraint::Constraint(void) -{ -} - -Constraint::~Constraint(void) -{ -} diff --git a/source/tools/rmgen/constraint.h b/source/tools/rmgen/constraint.h deleted file mode 100644 index 23f6e52137..0000000000 --- a/source/tools/rmgen/constraint.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __CONSTRAINT_H__ -#define __CONSTRAINT_H__ - -class Constraint -{ -public: - Constraint(void); - virtual ~Constraint(void); - virtual bool allows(class Map* m, int x, int y) = 0; -}; - -#endif diff --git a/source/tools/rmgen/convert.cpp b/source/tools/rmgen/convert.cpp deleted file mode 100644 index b23d657b01..0000000000 --- a/source/tools/rmgen/convert.cpp +++ /dev/null @@ -1,306 +0,0 @@ -#include "stdafx.h" -#include "convert.h" -#include "rmgen.h" -#include "simpleconstraints.h" -#include "simplepainters.h" -#include "rectplacer.h" -#include "layeredpainter.h" -#include "clumpplacer.h" -#include "smoothelevationpainter.h" -#include "simplegroup.h" - -using namespace std; - -bool GetTileClassField(JSContext* cx, jsval obj, const char* name, TileClass*& ret) { - jsval val; - if(!GetJsvalField(cx, obj, name, val)) return false; - if(JSVAL_IS_NULL(val)) { - ret = 0; - return true; - } - if(!JSVAL_IS_INT(val)) return false; - int id = JSVAL_TO_INT(val); - if(id < 0 || id > theMap->tileClasses.size()) return false; - ret = (id==0? 0 : theMap->tileClasses[id-1]); - return true; -} - -int GetType(JSContext* cx, jsval val) { - int ret; - if(!GetIntField(cx, val, "TYPE", ret)) return 0; - return ret; -} - -bool GetIntField(JSContext* cx, jsval obj, const char* name, int& ret) { - jsval val; - if(!GetJsvalField(cx, obj, name, val)) return false; - if(!JSVAL_IS_INT(val)) return false; - ret = JSVAL_TO_INT(val); - return true; -} - -bool GetBoolField(JSContext* cx, jsval obj, const char* name, bool& ret) { - jsval val; - if(!GetJsvalField(cx, obj, name, val)) return false; - if(!JSVAL_IS_BOOLEAN(val)) return false; - ret = JSVAL_TO_BOOLEAN(val); - return true; -} - -bool GetFloatField(JSContext* cx, jsval obj, const char* name, float& ret) { - jsval val; - if(!GetJsvalField(cx, obj, name, val)) return false; - if(!JSVAL_IS_NUMBER(val)) return false; - jsdouble jsdbl; - JS_ValueToNumber(cx, val, &jsdbl); - ret = jsdbl; - return true; -} - -bool GetStringField(JSContext* cx, jsval obj, const char* name, std::string& ret) { - jsval val; - if(!GetJsvalField(cx, obj, name, val)) return false; - if(!JSVAL_IS_STRING(val)) return false; - ret = JS_GetStringBytes(JSVAL_TO_STRING(val)); - return true; -} - -bool GetArrayField(JSContext* cx, jsval obj, const char* name, std::vector& ret) { - ret.clear(); - jsval val; - if(!GetJsvalField(cx, obj, name, val)) return false; - if(!ParseArray(cx, val, ret)) return false; - return true; -} - -bool GetJsvalField(JSContext* cx, jsval obj, const char* name, jsval& ret) { - if(!JSVAL_IS_OBJECT(obj)) return false; - JSObject* fieldObj = JSVAL_TO_OBJECT(obj); - return JS_GetProperty(cx, fieldObj, name, &ret); -} - -bool ParseArray(JSContext* cx, jsval val, vector& ret) { - ret.clear(); - if(!JSVAL_IS_OBJECT(val)) return false; - JSObject* obj = JSVAL_TO_OBJECT(val); - if(!JS_IsArrayObject(cx, obj)) return false; - jsuint len; - JS_GetArrayLength(cx, obj, &len); - for(int i=0; i array; - jsval jsv, jsv2; - Terrain* terrain = 0; - float elevation; - int type; - int blendRadius; - TileClass* tileClass; - vector terrains; - vector widths; - - if(ParseArray(cx, val, array)) { - // MultiPainter is encoded as an array of painters - vector painters(array.size()); - for(int i=0; i array; - int x, y; - bool avoidSelf; - TileClass* tileClass; - vector elements; - - switch(GetType(cx, val)) { - case TYPE_SIMPLE_GROUP: - // convert x and y - if(!GetIntField(cx, val, "x", x)) return 0; - if(!GetIntField(cx, val, "y", y)) return 0; - if(!GetBoolField(cx, val, "avoidSelf", avoidSelf)) return 0; - if(!GetTileClassField(cx, val, "tileClass", tileClass)) return 0; - // convert the elements (which will be JS SimpleElement objects) - if(!GetJsvalField(cx, val, "elements", jsv)) return 0; - if(!ParseArray(cx, jsv, array)) return 0; - elements.resize(array.size()); - for(int i=0; i array; - int areaId; - TileClass* tileClass; - float distance; - float distance2; - string texture; - jsval jsv, jsv2; - - if(JSVAL_IS_NULL(val)) { - // convenience way of specifying a NullConstraint - return new NullConstraint(); - } - - if(ParseArray(cx, val, array)) { - // AndConstraint is encoded as an array of constraints - vector constraints(array.size()); - for(int i=0; i theMap->areas.size()) return 0; - return new AvoidAreaConstraint(theMap->areas[areaId-1]); - - case TYPE_AVOID_TEXTURE_CONSTRAINT: - if(!GetStringField(cx, val, "texture", texture)) return 0; - return new AvoidTextureConstraint(theMap->getId(texture)); - - case TYPE_AVOID_TILE_CLASS_CONSTRAINT: - if(!GetFloatField(cx, val, "distance", distance)) return 0; - if(!GetTileClassField(cx, val, "tileClass", tileClass)) return 0; - return new AvoidTileClassConstraint(tileClass, distance); - - case TYPE_STAY_IN_TILE_CLASS_CONSTRAINT: - if(!GetFloatField(cx, val, "distance", distance)) return 0; - if(!GetTileClassField(cx, val, "tileClass", tileClass)) return 0; - return new StayInTileClassConstraint(tileClass, distance); - - case TYPE_BORDER_TILE_CLASS_CONSTRAINT: - if(!GetFloatField(cx, val, "distanceInside", distance)) return 0; - if(!GetFloatField(cx, val, "distanceOutside", distance2)) return 0; - if(!GetTileClassField(cx, val, "tileClass", tileClass)) return 0; - return new BorderTileClassConstraint(tileClass, distance, distance2); - - default: - return 0; - } -} - -Terrain* ParseTerrain(JSContext* cx, jsval val) { - vector array; - - if(JSVAL_IS_STRING(val)) { - // simple terrains are just encoded as strings - string str = JS_GetStringBytes(JS_ValueToString(cx, val)); - return SimpleTerrain::parse(str); - } - - if(ParseArray(cx, val, array)) { - // RandomTerrain is encoded as an array of terrains - vector terrains(array.size()); - for(int i=0; i& ret); -bool GetJsvalField(JSContext* cx, jsval obj, const char* name, jsval& ret); - -bool ParseArray(JSContext* cx, jsval val, std::vector& ret); - -Terrain* ParseTerrain(JSContext* cx, jsval val); -AreaPainter* ParseAreaPainter(JSContext* cx, jsval val); -AreaPlacer* ParseAreaPlacer(JSContext* cx, jsval val); -ObjectGroupPlacer* ParseObjectGroupPlacer(JSContext* cx, jsval val); -Constraint* ParseConstraint(JSContext* cx, jsval val); - -#endif diff --git a/source/tools/rmgen/layeredpainter.cpp b/source/tools/rmgen/layeredpainter.cpp deleted file mode 100644 index 7f1c9359ad..0000000000 --- a/source/tools/rmgen/layeredpainter.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "stdafx.h" -#include "layeredpainter.h" -#include "area.h" -#include "terrain.h" -#include "map.h" -#include "pointmap.h" - -using namespace std; - -LayeredPainter::LayeredPainter(const vector& ts, const vector& ws) -{ - terrains = ts; - widths = ws; -} - -LayeredPainter::~LayeredPainter(void) -{ -} - -void LayeredPainter::paint(Map* m, Area* a) { - PointMap saw; - PointMap dist; - - queue q; - - // push edge points - vector& pts = a->points; - for(int i=0; ivalidT(nx, ny) && m->area[nx][ny]!=a && !saw[np]) { - saw[np] = 1; - dist[np] = 0; - q.push(np); - } - } - } - } - - // do BFS inwards to find distances to edge - while(!q.empty()) { - Point p = q.front(); - q.pop(); - - int d = dist[p]; - - // paint if in area - if(m->area[p.x][p.y] == a) { - int w=0, i=0; - for(; i=d) { - break; - } - } - terrains[i]->place(m, p.x, p.y); - } - - // enqueue neighbours - for(int dx=-1; dx<=1; dx++) { - for(int dy=-1; dy<=1; dy++) { - int nx = p.x+dx, ny = p.y+dy; - Point np(nx, ny); - if(m->validT(nx, ny) && m->area[nx][ny]==a && !saw[np]) { - saw[np] = 1; - dist[np] = d+1; - q.push(np); - } - } - } - } -} \ No newline at end of file diff --git a/source/tools/rmgen/layeredpainter.h b/source/tools/rmgen/layeredpainter.h deleted file mode 100644 index 655b4fb584..0000000000 --- a/source/tools/rmgen/layeredpainter.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __LAYEREDPAINTER_H__ -#define __LAYEREDPAINTER_H__ - -#include "areapainter.h" -#include "terrain.h" - -class LayeredPainter : - public AreaPainter -{ -private: - std::vector terrains; - std::vector widths; -public: - LayeredPainter(const std::vector& terrains, const std::vector& widths); - ~LayeredPainter(void); - - virtual void paint(class Map* m, class Area* a); -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/map.cpp b/source/tools/rmgen/map.cpp deleted file mode 100644 index 5879e93057..0000000000 --- a/source/tools/rmgen/map.cpp +++ /dev/null @@ -1,297 +0,0 @@ -#include "stdafx.h" -#include "rmgen.h" -#include "map.h" -#include "object.h" -#include "pmp_file.h" - -using namespace std; - -Map::Map(int size, Terrain* baseTerrain, float baseHeight) { - if(size<0 || size>1024) { - JS_ReportError(cx, "init: map size out of range"); - } - else if(size%16 != 0) { - JS_ReportError(cx, "init: map size must be divisible by 16"); - } - - this->size = size; - - texture = new int*[size]; - for(int i=0; i*[size]; - for(int i=0; i[size]; - } - - area = new Area**[size]; - for(int i=0; iplace(this, i, j); - } - } -} - -Map::Map(string fileName, int loadLevel) -{ - const int LOAD_NOTHING = 0; - const int LOAD_TERRAIN = 1<<0; - const int LOAD_INTERACTIVES = 1 << 1; - const int LOAD_NONINTERACTIVES = 1 << 2; - //const int SOMETHINGELSE = 1 << 3; - - - // HACK, this should probably be in a struct and be shared with the code in output.cpp - pmp_header hdr; - u32 map_size; - - //HACK, also in rmgen.cpp - const string SCENARIO_PATH = "../data/mods/public/maps/scenarios/"; - - std::string pmpFile = SCENARIO_PATH + fileName + ".pmp"; - std::string xmlFile = SCENARIO_PATH + fileName + ".xml"; - - if (loadLevel & LOAD_TERRAIN) - { - - FILE* f = fopen(pmpFile.c_str(), "rb"); - - fread(&hdr, sizeof(pmp_header), 1, f); - - /*TODO - - if (hdr.marker !== "PSMP") - JS_ReportError(cx, ""); - - if (hdr.version !== 4) - JS_ReportError(cx, ""); */ - - - fread(&map_size, sizeof(int), 1, f); - - size = map_size * 16; - - // Load height data - u16* heightmap = new u16[(size+1) * (size+1)]; - fread(heightmap, 2, ((size+1)*(size+1)), f); - - height = new float*[(size+1)]; - for(int i=0; i<(size+1); i++) - { - height[i] = new float[(size+1)]; - for(int j=0; j<(size+1); j++) - { - height[i][j] = (float) (heightmap[(j*(size+1)) + i] / 256.0f) * 0.35f; - } - } - - - // Load the list of used textures - - int numTextures; - int strLength; - - fread(&numTextures, sizeof(int), 1, f); - - for (int i=0; i buf(strLength+1); - fread(&buf[0], 1, strLength, f); - name = &buf[0]; - - // This will add the texture to the NameToId and idToName vectors if it - // doesn't already exist. And in this case it shouldn't. - getId( name.substr(0, name.length()-4)); - } - - texture = new int*[size]; - for(int i=0; itexture[x][y] = t.texture1; - } - } - - terrainObjects = new vector*[size]; - for(int i=0; i[size]; - } - - area = new Area**[size]; - for(int i=0; i Map::getTerrainObjects(int x, int y) { - if(!validT(x,y)) JS_ReportError(cx, "getTerrainObjects: invalid tile position"); - return terrainObjects[x][y]; -} - -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::addObject(Object* ent) { - objects.push_back(ent); -} - -Area* Map::createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* constr) { - vector points; - if(!placer->place(this, constr, points)) { - return 0; - } - Area* a = new Area(points); - for(int i=0; ipaint(this, a); - areas.push_back(a); - return a; -} - -bool Map::createObjectGroup(ObjectGroupPlacer* placer, int player, Constraint* constr) { - return placer->place(this, player, constr); -} - -int Map::createTileClass() { - tileClasses.push_back(new TileClass(size)); - return tileClasses.size(); -} - -float Map::getExactHeight(float x, float y) { - // copied & modified from ScEd - - int xi = min((int) floor(x), size); - int yi = min((int) floor(y), size); - float xf = x - xi; - float yf = y - yi; - - float h00 = height[xi][yi]; - float h01 = height[xi][yi+1]; - float h10 = height[xi+1][yi]; - float h11 = height[xi+1][yi+1]; - - return ( 1 - yf ) * ( ( 1 - xf ) * h00 + xf * h10 ) + yf * ( ( 1 - xf ) * h01 + xf * h11 ) ; -} diff --git a/source/tools/rmgen/map.h b/source/tools/rmgen/map.h deleted file mode 100644 index 49e4128863..0000000000 --- a/source/tools/rmgen/map.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __MAP_H__ -#define __MAP_H__ - -#include "area.h" -#include "areapainter.h" -#include "areaplacer.h" -#include "constraint.h" -#include "object.h" -#include "terrain.h" -#include "objectgroupplacer.h" -#include "tileclass.h" - -class Map { -public: - int size; - int** texture; - std::vector** terrainObjects; - float** height; - Area*** area; - std::map nameToId; - std::map idToName; - std::vector objects; - std::vector areas; - std::vector tileClasses; - - Map(int size, Terrain* baseTerrain, float baseHeight); - Map(std::string fileName, int loadLevel); - ~Map(); - - int getId(std::string texture); - - bool validT(int x, int y) { return x>=0 && y>=0 && x=0 && y>=0 && x<=size && y<=size; } - - bool validClass(int c) { return c>=0 && c<(int)tileClasses.size(); } - - std::string getTexture(int x, int y); - void setTexture(int x, int y, const std::string& texture); - - float getHeight(int x, int y); - void setHeight(int x, int y, float height); - - 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 addObject(class Object* ent); - - Area* createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* constr); - bool createObjectGroup(ObjectGroupPlacer* placer, int player, Constraint* constr); - - int createTileClass(); // returns ID of the new class - - float getExactHeight(float x, float y); // get height taking into account terrain curvature -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/noise.cpp b/source/tools/rmgen/noise.cpp deleted file mode 100644 index cdd8dc4055..0000000000 --- a/source/tools/rmgen/noise.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "stdafx.h" -#include "Noise.h" -#include -#include "random.h" - -using namespace std; - -namespace -{ - /// Utility function used in both noises as an ease curve - float easeCurve(float t) - { - return t*t*t*(t*(t*6-15)+10); - } -} - -Noise2D::Noise2D(int f) -{ - freq = f; - grads = new CVector2D_Maths*[freq]; - for(int i=0; i 1 || v.LengthSquared() < 0.1); - v.Normalize(); - grads[i][j][k] = CVector3D(v.X, v.Y, v.Z); - } - } - } -} - -Noise3D::~ Noise3D() -{ - for(int i=0; iname = name; - this->player = player; - this->x = x; - this->y = y; - this->orientation = orientation; -} - -bool Object::isEntity() { - for(int i=0; i - -using namespace std; - -// Sea level elevation -const float SEA_LEVEL = 20.0f; - -void OutputObject(Map* m, Object* e, ostringstream& xml) { - float height = m->getExactHeight(e->x, e->y) + SEA_LEVEL; - - if(e->isEntity()) { - xml << "\ - \n\ - \n\ - " << e->player << "\n\ - x << "\" y=\"" << height << "\" z=\"" << 4*e->y << "\" />\n\ - orientation << "\" />\n\ - \n"; - } - else { - xml << "\ - \n\ - " << e->name << "\n\ - x << "\" y=\"" << height << "\" z=\"" << 4*e->y << "\" />\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, 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(m, vec[i], xml); - } - } - } - } -} - -void OutputXml(Map* m, FILE* f) { - ostringstream xml; - xml << "\ -\n\ -\n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - " << SEA_LEVEL-0.1f << "\n\ - \n\ - \n"; - OutputObjects(xml, m, true); // print entities - xml << "\ - \n\ - \n"; - OutputObjects(xml, m, false); // print nonentities - xml << "\ - \n\ -\n"; - - fprintf(f, "%s", xml.str().c_str()); -} - - -void OutputPmp(Map* m, FILE* f) { -/* -struct String { - u32 length; - char data[length]; // not NUL-terminated -}; -struct PMP { - char header[4]; // == "PSMP" - u32 version; // == 4 - u32 data_size; // == filesize-12 - - - u32 map_size; // number of patches (16x16 tiles) per side - - u16 heightmap[(mapsize*16 + 1)^2]; // (squared, not xor) - vertex heights - - u32 num_texture_textures; - String texture_textures[num_texture_textures]; // filenames (no path), e.g. "cliff1.dds" - - Tile tiles[(mapsize*16)^2]; -};*/ - int size = m->size; - int numTextures = m->idToName.size(); - - // header - fwrite("PSMP", sizeof(char), 4, f); - - // file format version - u32 version = 4; - fwrite(&version, sizeof(u32), 1, f); - - // data size (write 0 for now, calculate it at the end) - int temp = 0; - fwrite(&temp, sizeof(u32), 1, f); - - // map size in patches - u32 sizeInPatches = size/16; - fwrite(&sizeInPatches, sizeof(u32), 1, f); - - // heightmap - u16* heightmap = new u16[(size+1)*(size+1)]; - for(int x=0; xheight[x][y]+SEA_LEVEL) * 256.0f / 0.35f); - if(intHeight > 0xFFFF) { - intHeight = 0xFFFF; - } - else if(intHeight < 0) { - intHeight = 0; - } - heightmap[y*(size+1)+x] = intHeight; - } - } - fwrite(heightmap, sizeof(u16), (size+1)*(size+1), f); - - // num texture textures - fwrite(&numTextures, sizeof(u32), 1, f); - - // texture names - for(int i=0; iidToName[i] + ".dds"; - int len = fname.length(); - fwrite(&len, sizeof(u32), 1, f); - fwrite(fname.c_str(), sizeof(char), fname.length(), f); - } - - - // texture; note that this is an array of 16x16 patches for some reason - Tile* tiles = new Tile[size*size]; - for(int x=0; xtexture[x][y]; - t.texture2 = 0xFFFF; - t.priority = 0; - } - } - fwrite(tiles, sizeof(Tile), size*size, f); - - - - // data size (file size - 12) - fseek(f, 0, SEEK_END); - int fsize = ftell(f); - u32 dataSize = fsize-12; - fseek(f, 8, SEEK_SET); - fwrite(&dataSize, sizeof(u32), 1, f); -} - -void OutputMap(Map* m, const string& outputName) { - string xmlName = outputName + ".xml"; - FILE* xmlFile = fopen(xmlName.c_str(), "w"); - if(!xmlFile) { - cerr << "Cannot open " << xmlName << endl; - Shutdown(1); - } - OutputXml(m, xmlFile); - fclose(xmlFile); - - string pmpName = outputName + ".pmp"; - FILE* pmpFile = fopen(pmpName.c_str(), "wb"); - if(!pmpFile) { - cerr << "Cannot open " << pmpName << endl; - Shutdown(1); - } - OutputPmp(m, pmpFile); - fclose(pmpFile); - - cout << "Map outputted to " << outputName << ".*" << endl; -} diff --git a/source/tools/rmgen/output.h b/source/tools/rmgen/output.h deleted file mode 100644 index 089d34db2e..0000000000 --- a/source/tools/rmgen/output.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __OUTPUT_H__ -#define __OUTPUT_H__ - -#include "map.h" - -void OutputMap(Map* map, const std::string& path); - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/pmp_file.h b/source/tools/rmgen/pmp_file.h deleted file mode 100644 index 862d8a1013..0000000000 --- a/source/tools/rmgen/pmp_file.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __PMP_FILE_H__ -#define __PMP_FILE_H__ - - -typedef unsigned short u16; -typedef unsigned int u32; - -struct Tile { - u16 texture1; // index into texture_textures[] - u16 texture2; // index, or 0xFFFF for 'none' - u32 priority; // ??? -}; - -struct pmp_header -{ - char marker[4]; - u32 version; - u32 data_size; -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/point.cpp b/source/tools/rmgen/point.cpp deleted file mode 100644 index dcdd8fce8c..0000000000 --- a/source/tools/rmgen/point.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "stdafx.h" -#include "point.h" - -Point::Point(void) -{ - x = y = 0; -} - -Point::Point(int x_, int y_) : x(x_), y(y_) -{ -} - -Point::~Point(void) -{ -} - -bool Point::operator <(const Point& p) const { - return x class PointMap -{ - static const int T = 5, P = 5; - static const int T_VAL = (1<> T) * P_VAL + (p.y >> T); - int tileIndex = (p.x & T_MASK) * T_VAL + (p.y & T_MASK); - - if(patches[patchIndex] == 0) - { - patches[patchIndex] = new E[1<<(T+T)]; - memset(patches[patchIndex], 0, (1<<(T+T)) * sizeof(E)); - } - - return patches[patchIndex][tileIndex]; - } -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/random.cpp b/source/tools/rmgen/random.cpp deleted file mode 100644 index 12a4c39181..0000000000 --- a/source/tools/rmgen/random.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "stdafx.h" -#include "random.h" - -using namespace boost; - -mt19937 rng; - -void SeedRand(unsigned long s) { - rng.seed(s); -} - -int RandInt(int maxVal) { - return rng()%maxVal; -} - -float RandFloat() { - return float(rng()) * (1.0f/4294967296.0f); -} - -float RandFloat(float minVal, float maxVal) { - return minVal + RandFloat() * (maxVal - minVal); -} - -int RandInt(int minVal, int maxVal) { - return minVal + RandInt(maxVal - minVal + 1); -} - - diff --git a/source/tools/rmgen/random.h b/source/tools/rmgen/random.h deleted file mode 100644 index d3968bd593..0000000000 --- a/source/tools/rmgen/random.h +++ /dev/null @@ -1,5 +0,0 @@ -void SeedRand(unsigned long seed); -int RandInt(int maxVal); // in range [0, maxVal-1] -float RandFloat(); // in range [0, 1) -int RandInt(int minVal, int maxVal); // in range [minVal, maxVal] -float RandFloat(float minVal, float maxVal); // in range [minVal, maxVal) diff --git a/source/tools/rmgen/rangeop.cpp b/source/tools/rmgen/rangeop.cpp deleted file mode 100644 index 8e0bc02540..0000000000 --- a/source/tools/rmgen/rangeop.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "stdafx.h" -#include "rangeop.h" - -RangeOp::RangeOp(int size) { - nn = 1; - while(nn < size) { - nn *= 2; - } - vals = new int[2*nn]; - memset(vals, 0, 2*nn*sizeof(int)); -} - -RangeOp::~RangeOp() { - delete[] vals; -} - -int RangeOp::get(int pos) { - return vals[nn + pos]; -} - -void RangeOp::set(int pos, int amt) { - add(pos, amt-get(pos)); -} - -void RangeOp::add(int pos, int amt) { - for(int s=nn; s>0; s/=2) { - vals[s + pos] += amt; - pos /= 2; - } -} - -int RangeOp::get(int start, int end) { - int ret = 0; - int i; - for(i=1; start+i<=end; i*=2) { - if(start & i) { - ret += vals[nn/i + start/i]; - start += i; - } - } - while(i) { - if(start+i <= end) { - ret += vals[nn/i + start/i]; - start += i; - } - i /= 2; - } - return ret; -} \ No newline at end of file diff --git a/source/tools/rmgen/rangeop.h b/source/tools/rmgen/rangeop.h deleted file mode 100644 index 432c5a71d4..0000000000 --- a/source/tools/rmgen/rangeop.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __RANGEOP_H__ -#define __RANGEOP_H__ - -class RangeOp { -private: - int* vals; // has size 2*nn - int nn; // smallest power of 2 >= size -public: - RangeOp(int size); - ~RangeOp(); - void set(int pos, int amt); - void add(int pos, int amt); - int get(int pos); - int get(int start, int end); -}; - -#endif diff --git a/source/tools/rmgen/rectplacer.cpp b/source/tools/rmgen/rectplacer.cpp deleted file mode 100644 index 063d6eab99..0000000000 --- a/source/tools/rmgen/rectplacer.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "stdafx.h" -#include "rectplacer.h" -#include "map.h" - -RectPlacer::RectPlacer(int x1, int y1, int x2, int y2) -{ - this->x1 = x1; - this->y1 = y1; - this->x2 = x2; - this->y2 = y2; -} - -RectPlacer::~RectPlacer(void) -{ -} - -bool RectPlacer::place(Map* m, Constraint* constr, std::vector& ret) { - for(int x=x1; xvalidT(x,y) && constr->allows(m,x,y)) { - ret.push_back(Point(x,y)); - } - else { - return false; - } - } - } - return true; -} diff --git a/source/tools/rmgen/rectplacer.h b/source/tools/rmgen/rectplacer.h deleted file mode 100644 index ebe0b39019..0000000000 --- a/source/tools/rmgen/rectplacer.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __RECTPLACER_H__ -#define __RECTPLACER_H__ - -#include "areaplacer.h" -#include "map.h" - -class RectPlacer : - public AreaPlacer -{ -public: - int x1, y1, x2, y2; - - bool place(Map* m, Constraint* constr, std::vector& ret); - - RectPlacer(int x1, int y1, int x2, int y2); - ~RectPlacer(void); -}; - -#endif \ No newline at end of file diff --git a/source/tools/rmgen/rmgen.cpp b/source/tools/rmgen/rmgen.cpp deleted file mode 100644 index 840ee06c0e..0000000000 --- a/source/tools/rmgen/rmgen.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "stdafx.h" -#include "rmgen.h" -#include "map.h" -#include "output.h" -#include "api.h" -#include "scripting.h" -#include "random.h" -#include "noise.h" - -using namespace std; -using namespace js; - -JSRuntime *rt = 0; -JSContext *cx = 0; -JSObject *global = 0; - -Map* theMap = 0; - -// JS support functions - -template JSClass Class::jsClass = { - "T", JSCLASS_HAS_PRIVATE, - JS_PropertyStub, JS_PropertyStub, Class::getProperty, Class::setProperty, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub - // Note: the finalize stub should really be replaced by some function which - // deletes the object if it must be deleted; this requires that we use some - // kind of smart handles instead of just pointers though, so we don't delete - // objects that we actually want C++ to use (which is most objects) -}; -template JSNative Class::constructor; -template vector Class::methodSpecs; -template vector Class::propertySpecs; -template vector Class::properties; - -void ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) { - string path = string(report->filename); - int lastSlash = -1; - for(int i = ((int) path.size()) - 1; i >= 0; i--) { - if(path[i]=='/' || path[i]=='\\') { - lastSlash = i; - break; - } - } - string filename = path.substr(lastSlash+1); - cerr << "Error at " << filename << ":" << report->lineno << ":\n\t" - << message << endl; - Shutdown(1); -} - -void InitJS() { - rt = JS_NewRuntime(8L * 1024L * 1024L); - cx = JS_NewContext(rt, 8192); - - JS_SetErrorReporter(cx, ErrorReporter); - - static JSClass globalClass = { - "global",0, - JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub, - JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub - }; - global = JS_NewObject(cx, &globalClass, NULL, NULL); - JS_InitStandardClasses(cx, global); - - JS_DefineFunctions(cx, global, globalFunctions); - - Class::addMethod(Method, 2, "eval"); - Class::init("Noise2D", Constructor); -} - -void Shutdown(int status) { - JS_DestroyContext(cx); - JS_DestroyRuntime(rt); - JS_ShutDown(); - system("pause"); - exit(status); -} - -char* ValToString(jsval val) { - return JS_GetStringBytes(JS_ValueToString(cx, val)); -} - -jsval NewJSString(const string& str) { - char* buf = (char*) JS_malloc(cx, str.length()); - memcpy(buf, str.c_str(), str.length()); - return STRING_TO_JSVAL(JS_NewString(cx, buf, str.length())); -} - -void ExecuteFile(const string& fileName) { - FILE* f = fopen(fileName.c_str(), "r"); - if(!f) { - cerr << "Cannot open " << fileName << endl; - Shutdown(1); - } - - string code; - char buf[1025]; - while(fgets(buf, 1024, f)) { - code += buf; - } - - jsval rval; - JSBool ok = JS_EvaluateScript(cx, global, code.c_str(), code.length(), fileName.c_str(), 1, &rval); - if(!ok) Shutdown(1); -} - -// Program entry point - -int main(int argc, char* argv[]) -{ - const string LIBRARY_FILE = "../data/mods/public/maps/rmlibrary.js"; - const string RMS_PATH = "../data/mods/public/maps/random/"; - const string SCENARIO_PATH = "../data/mods/public/maps/scenarios/"; - - clock_t start = clock(); - - InitJS(); - - if(argc!=3 && argc!=4) { - cerr << "Usage: rmgen