From 56343ae9c8806272c21f11edefab9bce4d959e15 Mon Sep 17 00:00:00 2001 From: Matei Date: Mon, 23 May 2005 02:52:37 +0000 Subject: [PATCH] Updated ScEd to no longer repaint when minimized and repaint at only 20 FPS normally. The result is much friendlier on your other applications and on your fan. This was SVN commit r2338. --- source/tools/rmgen/api.cpp | 174 ++++++++++++++--------- source/tools/rmgen/api.h | 8 +- source/tools/rmgen/area.cpp | 14 ++ source/tools/rmgen/area.h | 13 ++ source/tools/rmgen/areapainter.cpp | 10 ++ source/tools/rmgen/areapainter.h | 13 ++ source/tools/rmgen/areaplacer.cpp | 10 ++ source/tools/rmgen/areaplacer.h | 16 +++ source/tools/rmgen/centeredplacer.cpp | 10 ++ source/tools/rmgen/centeredplacer.h | 16 +++ source/tools/rmgen/constraint.cpp | 10 ++ source/tools/rmgen/constraint.h | 12 ++ source/tools/rmgen/entity.cpp | 16 +++ source/tools/rmgen/entity.h | 15 ++ source/tools/rmgen/library.js | 18 +++ source/tools/rmgen/map.cpp | 37 ++++- source/tools/rmgen/map.h | 13 ++ source/tools/rmgen/output.cpp | 41 +++--- source/tools/rmgen/point.cpp | 19 +++ source/tools/rmgen/point.h | 14 ++ source/tools/rmgen/rectplacer.cpp | 29 ++++ source/tools/rmgen/rectplacer.h | 19 +++ source/tools/rmgen/rmgen.vcproj | 66 +++++++++ source/tools/rmgen/simpleconstraints.cpp | 7 + source/tools/rmgen/simpleconstraints.h | 12 ++ source/tools/rmgen/simplepainters.cpp | 18 +++ source/tools/rmgen/simplepainters.h | 16 +++ source/tools/rmgen/stdafx.h | 1 + source/tools/rmgen/test.js | 17 ++- source/tools/sced/ui/ScEd.cpp | 11 +- 30 files changed, 576 insertions(+), 99 deletions(-) create mode 100644 source/tools/rmgen/area.cpp create mode 100644 source/tools/rmgen/area.h create mode 100644 source/tools/rmgen/areapainter.cpp create mode 100644 source/tools/rmgen/areapainter.h create mode 100644 source/tools/rmgen/areaplacer.cpp create mode 100644 source/tools/rmgen/areaplacer.h create mode 100644 source/tools/rmgen/centeredplacer.cpp create mode 100644 source/tools/rmgen/centeredplacer.h create mode 100644 source/tools/rmgen/constraint.cpp create mode 100644 source/tools/rmgen/constraint.h create mode 100644 source/tools/rmgen/entity.cpp create mode 100644 source/tools/rmgen/entity.h create mode 100644 source/tools/rmgen/point.cpp create mode 100644 source/tools/rmgen/point.h create mode 100644 source/tools/rmgen/rectplacer.cpp create mode 100644 source/tools/rmgen/rectplacer.h create mode 100644 source/tools/rmgen/simpleconstraints.cpp create mode 100644 source/tools/rmgen/simpleconstraints.h create mode 100644 source/tools/rmgen/simplepainters.cpp create mode 100644 source/tools/rmgen/simplepainters.h diff --git a/source/tools/rmgen/api.cpp b/source/tools/rmgen/api.cpp index 9daeba8127..102cd7075b 100644 --- a/source/tools/rmgen/api.cpp +++ b/source/tools/rmgen/api.cpp @@ -1,8 +1,10 @@ #include "stdafx.h" #include "api.h" #include "rmgen.h" -#include "map.h" #include "random.h" +#include "map.h" +#include "entity.h" +#include "objparse.h" using namespace std; @@ -19,16 +21,60 @@ JSFunctionSpec globalFunctions[] = { {"setHeight", setHeight, 3}, {"randInt", randInt, 1}, {"randFloat", randFloat, 0}, + {"addEntity", addEntity, 5}, + {"createArea", createArea, 3}, {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: expected %d arguments but got %d", function, num, argc); + } + JSObject* obj; + for(int i=0; iaddEntity(new Entity(type, player, x,0,y, orientation)); + + return JS_TRUE; +} + +JSBool createArea(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + ValidateArgs("***", cx, argc, argv, __FUNCTION__); + if(theMap == 0) { + JS_ReportError(cx, "createArea: cannot be called before init()"); + } + + AreaPlacer* placer; + AreaPainter* painter; + Constraint* constr; + + if(!(placer = ParsePlacer(cx, argv[0]))) { + JS_ReportError(cx, "createArea: argument 1 must be an area placer definition"); + } + if(!(painter = ParsePainter(cx, argv[1]))) { + JS_ReportError(cx, "createArea: argument 1 must be an area painter definition"); + } + if(!(constr = ParseConstraint(cx, argv[2]))) { + JS_ReportError(cx, "createArea: argument 1 must be a constraint definition"); + } + + Area* r = theMap->createArea(placer, painter, constr); + return JS_TRUE; } \ No newline at end of file diff --git a/source/tools/rmgen/api.h b/source/tools/rmgen/api.h index 372c9fe36f..6106bb4023 100644 --- a/source/tools/rmgen/api.h +++ b/source/tools/rmgen/api.h @@ -11,13 +11,17 @@ JSBool init(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); 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); + JSBool getTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); JSBool setTerrain(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 randInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); -JSBool randFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); +JSBool addEntity(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval); + +JSBool createArea(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 new file mode 100644 index 0000000000..9061d7678e --- /dev/null +++ b/source/tools/rmgen/area.cpp @@ -0,0 +1,14 @@ +#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 new file mode 100644 index 0000000000..f24c17fb19 --- /dev/null +++ b/source/tools/rmgen/area.h @@ -0,0 +1,13 @@ +#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 new file mode 100644 index 0000000000..0d9e6a7cbe --- /dev/null +++ b/source/tools/rmgen/areapainter.cpp @@ -0,0 +1,10 @@ +#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 new file mode 100644 index 0000000000..476a5e78e0 --- /dev/null +++ b/source/tools/rmgen/areapainter.h @@ -0,0 +1,13 @@ +#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 new file mode 100644 index 0000000000..0dac124eb0 --- /dev/null +++ b/source/tools/rmgen/areaplacer.cpp @@ -0,0 +1,10 @@ +#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 new file mode 100644 index 0000000000..ca6d192a3f --- /dev/null +++ b/source/tools/rmgen/areaplacer.h @@ -0,0 +1,16 @@ +#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/centeredplacer.cpp b/source/tools/rmgen/centeredplacer.cpp new file mode 100644 index 0000000000..cc6b5f48e4 --- /dev/null +++ b/source/tools/rmgen/centeredplacer.cpp @@ -0,0 +1,10 @@ +#include "stdafx.h" +#include "centeredplacer.h" + +CenteredPlacer::CenteredPlacer(void) +{ +} + +CenteredPlacer::~CenteredPlacer(void) +{ +} diff --git a/source/tools/rmgen/centeredplacer.h b/source/tools/rmgen/centeredplacer.h new file mode 100644 index 0000000000..c517730726 --- /dev/null +++ b/source/tools/rmgen/centeredplacer.h @@ -0,0 +1,16 @@ +#ifndef __CENTEREDPLACER_H__ +#define __CENTEREDPLACER_H__ + +#include "point.h" +#include "constraint.h" + +class CenteredPlacer +{ +public: + virtual bool place(class Map* m, Constraint* constr, std::vector& ret, int x, int y) = 0; + + CenteredPlacer(void); + virtual ~CenteredPlacer(void); +}; + +#endif \ No newline at end of file diff --git a/source/tools/rmgen/constraint.cpp b/source/tools/rmgen/constraint.cpp new file mode 100644 index 0000000000..618d5dc016 --- /dev/null +++ b/source/tools/rmgen/constraint.cpp @@ -0,0 +1,10 @@ +#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 new file mode 100644 index 0000000000..7c9ac717e4 --- /dev/null +++ b/source/tools/rmgen/constraint.h @@ -0,0 +1,12 @@ +#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/entity.cpp b/source/tools/rmgen/entity.cpp new file mode 100644 index 0000000000..5b3d388a76 --- /dev/null +++ b/source/tools/rmgen/entity.cpp @@ -0,0 +1,16 @@ +#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 new file mode 100644 index 0000000000..decf85bc27 --- /dev/null +++ b/source/tools/rmgen/entity.h @@ -0,0 +1,15 @@ +#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/library.js b/source/tools/rmgen/library.js index 456eba6a7d..0fc616a300 100644 --- a/source/tools/rmgen/library.js +++ b/source/tools/rmgen/library.js @@ -1,3 +1,9 @@ +// Object type constants + +const TYPE_RECTPLACER = 1; + +// Utility functions + function println(x) { print(x); print("\n"); @@ -9,4 +15,16 @@ function chooseRand() { } var ar = (arguments.length==1 ? arguments[0] : arguments); return ar[randInt(ar.length)]; +} + +// Area placers + +function RectPlacer(x1, y1, x2, y2) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.raw = function() { + return [TYPE_RECTPLACER, this.x1, this.y1, this.x2, this.y2]; + } } \ No newline at end of file diff --git a/source/tools/rmgen/map.cpp b/source/tools/rmgen/map.cpp index 0dea925730..f06b8edf96 100644 --- a/source/tools/rmgen/map.cpp +++ b/source/tools/rmgen/map.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "rmgen.h" #include "map.h" +#include "entity.h" using namespace std; @@ -23,7 +24,15 @@ Map::Map(int size, const string& baseTerrain, float baseHeight) { terrain[i][j] = baseId; } } - + + area = new Area**[size]; + for(int i=0; i points; + if(!placer->place(this, constr, points)) { + return 0; + } + Area* a = new Area(points); + for(int i=0; ipaint(this, a); + return a; } \ No newline at end of file diff --git a/source/tools/rmgen/map.h b/source/tools/rmgen/map.h index b6775d026d..c8400b0f0a 100644 --- a/source/tools/rmgen/map.h +++ b/source/tools/rmgen/map.h @@ -1,13 +1,22 @@ #ifndef __MAP_H__ #define __MAP_H__ +#include "area.h" +#include "areapainter.h" +#include "areaplacer.h" +#include "constraint.h" +#include "entity.h" + class Map { public: int size; int** terrain; float** height; + Area*** area; std::map nameToId; std::map idToName; + std::vector entities; + std::vector areas; Map(int size, const std::string& baseTerrain, float baseHeight); ~Map(); @@ -22,6 +31,10 @@ public: float getHeight(int x, int y); void setHeight(int x, int y, float height); + + void addEntity(class Entity* ent); + + Area* createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* constr); }; #endif \ No newline at end of file diff --git a/source/tools/rmgen/output.cpp b/source/tools/rmgen/output.cpp index 3006fb321b..712332101e 100644 --- a/source/tools/rmgen/output.cpp +++ b/source/tools/rmgen/output.cpp @@ -2,6 +2,7 @@ #include "rmgen.h" #include "output.h" #include "map.h" +#include "entity.h" using namespace std; @@ -9,31 +10,37 @@ typedef unsigned short u16; typedef unsigned int u32; void OutputXml(Map* m, FILE* f) { - const char* xml = "\ + ostringstream xml; + xml << "\ \n\ \n\ \n\ \n\ - \n\ - \n\ - \n\ - \n\ - \n\ + \n\ + \n\ + \n\ + \n\ + \n\ \n\ - \n\ + \n"; + + for(int i=0; ientities.size(); i++) { + Entity* e = m->entities[i]; + xml << "\ + \n\ + \n\ + " << e->player << "\n\ + x << "\" y=\"" << 4*e->y << "\" z=\"" << 4*e->z << "\" />\n\ + orientation << "\" />\n\ + \n"; + } + + xml << "\ + \ \n\ \n"; - /* - - - 0 - - - - */ - - fprintf(f, "%s", xml); + fprintf(f, "%s", xml.str().c_str()); } struct Tile { diff --git a/source/tools/rmgen/point.cpp b/source/tools/rmgen/point.cpp new file mode 100644 index 0000000000..6e1a95b3cf --- /dev/null +++ b/source/tools/rmgen/point.cpp @@ -0,0 +1,19 @@ +#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 xx1 = 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 new file mode 100644 index 0000000000..7d4b2c9c3f --- /dev/null +++ b/source/tools/rmgen/rectplacer.h @@ -0,0 +1,19 @@ +#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.vcproj b/source/tools/rmgen/rmgen.vcproj index 4c6a184563..05943a2217 100644 --- a/source/tools/rmgen/rmgen.vcproj +++ b/source/tools/rmgen/rmgen.vcproj @@ -116,18 +116,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/tools/rmgen/simpleconstraints.cpp b/source/tools/rmgen/simpleconstraints.cpp new file mode 100644 index 0000000000..bba6c4bb86 --- /dev/null +++ b/source/tools/rmgen/simpleconstraints.cpp @@ -0,0 +1,7 @@ +#include "stdafx.h" +#include "simpleconstraints.h" + +bool NullConstraint::allows(Map* m, int x, int y) +{ + return true; +} diff --git a/source/tools/rmgen/simpleconstraints.h b/source/tools/rmgen/simpleconstraints.h new file mode 100644 index 0000000000..42a9855232 --- /dev/null +++ b/source/tools/rmgen/simpleconstraints.h @@ -0,0 +1,12 @@ +#ifndef __SIMPLECONSTRAINTS_H__ +#define __SIMPLECONSTRAINTS_H__ + +#include "constraint.h" +#include "map.h" + +class NullConstraint : public Constraint { +public: + virtual bool allows(Map* m, int x, int y); +}; + +#endif diff --git a/source/tools/rmgen/simplepainters.cpp b/source/tools/rmgen/simplepainters.cpp new file mode 100644 index 0000000000..46c94ceebe --- /dev/null +++ b/source/tools/rmgen/simplepainters.cpp @@ -0,0 +1,18 @@ +#include "stdafx.h" +#include "simplepainters.h" + +using namespace std; + +TerrainPainter::TerrainPainter(const string& terrain) +{ + this->terrain = terrain; +} + +void TerrainPainter::paint(Map* m, Area* a) +{ + int id = m->getId(terrain); + for (int i=0; ipoints.size(); i++) { + Point p = a->points[i]; + m->terrain[p.x][p.y] = id; + } +} diff --git a/source/tools/rmgen/simplepainters.h b/source/tools/rmgen/simplepainters.h new file mode 100644 index 0000000000..e0668c38f0 --- /dev/null +++ b/source/tools/rmgen/simplepainters.h @@ -0,0 +1,16 @@ +#ifndef __SIMPLEPAINTERS_H__ +#define __SIMPLEPAINTERS_H__ + +#include "areapainter.h" +#include "map.h" +#include "area.h" + +class TerrainPainter : public AreaPainter { +public: + std::string terrain; + + TerrainPainter(const std::string& terrain); + void paint(Map* m, Area* a); +}; + +#endif \ No newline at end of file diff --git a/source/tools/rmgen/stdafx.h b/source/tools/rmgen/stdafx.h index bc949137ef..ba04152a63 100644 --- a/source/tools/rmgen/stdafx.h +++ b/source/tools/rmgen/stdafx.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/source/tools/rmgen/test.js b/source/tools/rmgen/test.js index 982a03c39d..6433838419 100644 --- a/source/tools/rmgen/test.js +++ b/source/tools/rmgen/test.js @@ -1,9 +1,18 @@ -const SIZE = 64; +const SIZE = 48; -init(SIZE, "grass1_a", 1.5); +init(SIZE, "grass1_a", 0); + +var placer = new RectPlacer(0,0,3,4); +placer.y2 = 6; +createArea(placer, 0, 0); for(var x=0; xGetActiveView(); - if (view) { - view->IdleTimeProcess(); - } + if (!mainfrm->IsIconic()) { + CScEdView* view=(CScEdView*) mainfrm->GetActiveView(); + if (view) { + view->IdleTimeProcess(); + } + } + Sleep(50); } }