Index: ps/trunk/source/tools/rmgen/stdafx.h =================================================================== --- ps/trunk/source/tools/rmgen/stdafx.h (nonexistent) +++ ps/trunk/source/tools/rmgen/stdafx.h (revision 2293) @@ -0,0 +1,30 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#define XP_WIN +#else +#define XP_UNIX // TODO: Someone should actually test this on Linux +#endif +#include "jsapi.h" + +// TODO: reference additional headers your program requires here Index: ps/trunk/source/tools/rmgen/output.cpp =================================================================== --- ps/trunk/source/tools/rmgen/output.cpp (nonexistent) +++ ps/trunk/source/tools/rmgen/output.cpp (revision 2293) @@ -0,0 +1,142 @@ +#include "stdafx.h" +#include "rmgen.h" +#include "output.h" +#include "map.h" + +using namespace std; + +const char* OUTPUT_PATH = "../../../binaries/data/mods/official/maps/scenarios/"; + +typedef unsigned short u16; +typedef unsigned int u32; + + +void OutputXml(Map* m, FILE* f) { + const char* xml = "\ +\n\ +\n\ +\n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ +\n"; + fprintf(f, "%s", xml); +} + +struct Tile { + u16 texture1; // index into terrain_textures[] + u16 texture2; // index, or 0xFFFF for 'none' + u32 priority; // ??? +}; + +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_terrain_textures; + String terrain_textures[num_terrain_textures]; // filenames (no path), e.g. "cliff1.dds" + + Tile tiles[(mapsize*16)^2]; +};*/ + int size = m->size; + int numTerrains = m->idToName.size(); + + // header + fwrite("PSMP", sizeof(char), 4, f); + + // file format version + u32 version = 4; + fwrite(&version, sizeof(u32), 1, f); + + // data size + /*int numTextureChars = 0; + for(int i=0; iidToName[i]+".dds").length(); + } + u32 dataSize = sizeof(u32) // size in patches + + (size+1)*(size+1)*sizeof(u16) // heightmap + + sizeof(u32) // num textures + + m->idToName.size()*sizeof(u32) // texture string lengths + + numTextureChars*sizeof(char) // texture string chars + + size*size*sizeof(Tile); // tiles*/ + 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)]; + memset(heightmap, 0, (size+1)*(size+1)*sizeof(u16)); + fwrite(heightmap, sizeof(u16), (size+1)*(size+1), f); + + // num terrain textures + fwrite(&numTerrains, sizeof(u32), 1, f); + + // terrain 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); + } + + // terrains + Tile* tiles = new Tile[size*size]; + for(int i=0; iterrain[i][j]; + t.texture2 = 0xFFFF; + t.priority = 0; + } + } + fwrite(tiles, sizeof(Tile), size*size, f); + + // data size + 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, string outputName) { + string pmpName = OUTPUT_PATH + outputName + ".pmp"; + string xmlName = OUTPUT_PATH + outputName + ".xml"; + + FILE* xmlFile = fopen(xmlName.c_str(), "w"); + if(!xmlFile) { + cerr << "Cannot open " << xmlName << endl; + Shutdown(1); + } + OutputXml(m, xmlFile); + fclose(xmlFile); + + FILE* pmpFile = fopen(pmpName.c_str(), "wb"); + if(!pmpFile) { + cerr << "Cannot open " << xmlName << endl; + Shutdown(1); + } + OutputPmp(m, pmpFile); + fclose(pmpFile); +} Index: ps/trunk/source/tools/rmgen/map.h =================================================================== --- ps/trunk/source/tools/rmgen/map.h (nonexistent) +++ ps/trunk/source/tools/rmgen/map.h (revision 2293) @@ -0,0 +1,16 @@ +#pragma once + +typedef int TerrainId; + +class Map { +public: + int size; + TerrainId** terrain; + std::map nameToId; + std::map idToName; + + Map(int size, std::string baseTerrain); + ~Map(); + + TerrainId getId(std::string terrain); +}; \ No newline at end of file Index: ps/trunk/source/tools/rmgen/rmgen.sln =================================================================== --- ps/trunk/source/tools/rmgen/rmgen.sln (nonexistent) +++ ps/trunk/source/tools/rmgen/rmgen.sln (revision 2293) @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rmgen", "rmgen.vcproj", "{ED804376-98E9-4732-A1E9-717D5C6773FA}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {ED804376-98E9-4732-A1E9-717D5C6773FA}.Debug.ActiveCfg = Debug|Win32 + {ED804376-98E9-4732-A1E9-717D5C6773FA}.Debug.Build.0 = Debug|Win32 + {ED804376-98E9-4732-A1E9-717D5C6773FA}.Release.ActiveCfg = Release|Win32 + {ED804376-98E9-4732-A1E9-717D5C6773FA}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal Index: ps/trunk/source/tools/rmgen/Debug/rmgen.exe =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: ps/trunk/source/tools/rmgen/Debug/rmgen.exe =================================================================== --- ps/trunk/source/tools/rmgen/Debug/rmgen.exe (nonexistent) +++ ps/trunk/source/tools/rmgen/Debug/rmgen.exe (revision 2293) Property changes on: ps/trunk/source/tools/rmgen/Debug/rmgen.exe ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: ps/trunk/source/tools/rmgen/Debug/js32.dll =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: ps/trunk/source/tools/rmgen/Debug/js32.dll =================================================================== --- ps/trunk/source/tools/rmgen/Debug/js32.dll (nonexistent) +++ ps/trunk/source/tools/rmgen/Debug/js32.dll (revision 2293) Property changes on: ps/trunk/source/tools/rmgen/Debug/js32.dll ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: ps/trunk/source/tools/rmgen/output.h =================================================================== --- ps/trunk/source/tools/rmgen/output.h (nonexistent) +++ ps/trunk/source/tools/rmgen/output.h (revision 2293) @@ -0,0 +1,5 @@ +#pragma once + +#include "map.h" + +void OutputMap(Map* map, std::string path); \ No newline at end of file Index: ps/trunk/source/tools/rmgen/rmgen.cpp =================================================================== --- ps/trunk/source/tools/rmgen/rmgen.cpp (nonexistent) +++ ps/trunk/source/tools/rmgen/rmgen.cpp (revision 2293) @@ -0,0 +1,123 @@ +#include "stdafx.h" +#include "rmgen.h" +#include "map.h" +#include "output.h" + +using namespace std; + +JSRuntime *rt = 0; +JSContext *cx = 0; +JSObject *global = 0; + +Map* theMap = 0; + +JSFunctionSpec globalFunctions[] = { +/* name native args */ + {"print", print, 1}, + {"init", init, 3}, + {0} +}; + +void ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) { + cerr << "Error at " << report->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); +} + +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)); +} + +JSBool print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if(argc != 1) { + JS_ReportError(cx, "print: expected 1 argument but got %d", argc); + return JS_FALSE; + } + + cout << JS_GetStringBytes(JS_ValueToString(cx, argv[0])); + return JS_TRUE; +} + +JSBool init(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + if(argc != 2) { + JS_ReportError(cx, "init: expected 2 arguments but got %d", argc); + } + if(!JSVAL_IS_INT(argv[0])) { + JS_ReportError(cx, "init: first argument must be an integer"); + } + if(!JSVAL_IS_STRING(argv[1])) { + JS_ReportError(cx, "init: second argument must be a string"); + } + if(theMap != 0) { + JS_ReportError(cx, "init: cannot be called twice"); + } + + int size = JSVAL_TO_INT(argv[0]); + char* baseTerrain = JS_GetStringBytes(JSVAL_TO_STRING(argv[1])); + + theMap = new Map(size, baseTerrain); + return JS_TRUE; +} + +int main(int argc, char* argv[]) +{ + InitJS(); + + if(argc!=3) { + cerr << "Usage: rmgen