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.
This commit is contained in:
Matei 2005-05-23 02:52:37 +00:00
parent aa027d20ec
commit 56343ae9c8
30 changed files with 576 additions and 99 deletions

View File

@ -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; i<num; i++) {
switch(types[i]) {
case 'i':
if(!JSVAL_IS_INT(argv[i])) {
JS_ReportError(cx, "%s: argument %d must be an integer", function, i+1);
}
break;
case 's':
if(!JSVAL_IS_STRING(argv[i])) {
JS_ReportError(cx, "%s: argument %d must be an integer", function, i+1);
}
break;
case 'n':
if(!JSVAL_IS_NUMBER(argv[i])) {
JS_ReportError(cx, "%s: argument %d must be an integer", function, i+1);
}
break;
case 'a':
if(!JSVAL_IS_OBJECT(argv[i])) {
JS_ReportError(cx, "%s: argument %d must be an array", function, i+1);
}
obj = JSVAL_TO_OBJECT(argv[i]);
if(!JS_IsArrayObject(cx, obj)) {
JS_ReportError(cx, "%s: argument %d must be an array", function, i+1);
}
break;
case '*':
break;
default:
cerr << "Internal Error: Invalid type passed to ValidateArgs: " << types[i] << "." << endl;
Shutdown(1);
}
}
}
// JS API implementation
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);
}
ValidateArgs("*", cx, argc, argv, __FUNCTION__);
cout << JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
return JS_TRUE;
@ -36,10 +82,7 @@ JSBool print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSBool error(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 1) {
// wow, you made an error calling the error() function!
JS_ReportError(cx, "error: expected 1 argument but got %d", argc);
}
ValidateArgs("*", cx, argc, argv, __FUNCTION__);
JS_ReportError(cx, JS_GetStringBytes(JS_ValueToString(cx, argv[0])));
return JS_TRUE;
@ -47,18 +90,7 @@ JSBool error(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSBool init(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 3) {
JS_ReportError(cx, "init: expected 3 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(!JSVAL_IS_NUMBER(argv[2])) {
JS_ReportError(cx, "init: third argument must be a number");
}
ValidateArgs("isn", cx, argc, argv, __FUNCTION__);
if(theMap != 0) {
JS_ReportError(cx, "init: cannot be called twice");
}
@ -74,18 +106,10 @@ JSBool init(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
JSBool getTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 2) {
JS_ReportError(cx, "getTerrain: expected 2 arguments but got %d", argc);
}
ValidateArgs("ii", cx, argc, argv, __FUNCTION__);
if(theMap == 0) {
JS_ReportError(cx, "getTerrain: cannot be called before init()");
}
if(!JSVAL_IS_INT(argv[0])) {
JS_ReportError(cx, "getTerrain: first argument must be an integer");
}
if(!JSVAL_IS_INT(argv[1])) {
JS_ReportError(cx, "getTerrain: second argument must be an integer");
}
int x = JSVAL_TO_INT(argv[0]);
int y = JSVAL_TO_INT(argv[1]);
@ -96,21 +120,10 @@ JSBool getTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
JSBool setTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 3) {
JS_ReportError(cx, "setTerrain: expected 3 arguments but got %d", argc);
}
ValidateArgs("iis", cx, argc, argv, __FUNCTION__);
if(theMap == 0) {
JS_ReportError(cx, "setTerrain: cannot be called before init()");
}
if(!JSVAL_IS_INT(argv[0])) {
JS_ReportError(cx, "setTerrain: first argument must be an integer");
}
if(!JSVAL_IS_INT(argv[1])) {
JS_ReportError(cx, "setTerrain: second argument must be an integer");
}
if(!JSVAL_IS_STRING(argv[2])) {
JS_ReportError(cx, "setTerrain: third argument must be a string");
}
int x = JSVAL_TO_INT(argv[0]);
int y = JSVAL_TO_INT(argv[1]);
@ -121,18 +134,10 @@ JSBool setTerrain(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
JSBool getHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 2) {
JS_ReportError(cx, "getHeight: expected 2 arguments but got %d", argc);
}
ValidateArgs("ii", cx, argc, argv, __FUNCTION__);
if(theMap == 0) {
JS_ReportError(cx, "getHeight: cannot be called before init()");
}
if(!JSVAL_IS_INT(argv[0])) {
JS_ReportError(cx, "getHeight: first argument must be an integer");
}
if(!JSVAL_IS_INT(argv[1])) {
JS_ReportError(cx, "getHeight: second argument must be an integer");
}
int x = JSVAL_TO_INT(argv[0]);
int y = JSVAL_TO_INT(argv[1]);
@ -143,21 +148,10 @@ JSBool getHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
JSBool setHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 3) {
JS_ReportError(cx, "setHeight: expected 3 arguments but got %d", argc);
}
ValidateArgs("iin", cx, argc, argv, __FUNCTION__);
if(theMap == 0) {
JS_ReportError(cx, "setHeight: cannot be called before init()");
}
if(!JSVAL_IS_INT(argv[0])) {
JS_ReportError(cx, "setHeight: first argument must be an integer");
}
if(!JSVAL_IS_INT(argv[1])) {
JS_ReportError(cx, "setHeight: second argument must be an integer");
}
if(!JSVAL_IS_NUMBER(argv[2])) {
JS_ReportError(cx, "setHeight: third argument must be a number");
}
int x = JSVAL_TO_INT(argv[0]);
int y = JSVAL_TO_INT(argv[1]);
@ -169,12 +163,7 @@ JSBool setHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
JSBool randInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 1) {
JS_ReportError(cx, "randInt: expected 1 argument but got %d", argc);
}
if(!JSVAL_IS_INT(argv[0])) {
JS_ReportError(cx, "randInt: first argument must be an integer");
}
ValidateArgs("i", cx, argc, argv, __FUNCTION__);
int x = JSVAL_TO_INT(argv[0]);
if(x<=0) {
@ -187,11 +176,54 @@ JSBool randInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
JSBool randFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if(argc != 0) {
JS_ReportError(cx, "randFloat: expected 0 arguments but got %d", argc);
}
ValidateArgs("", cx, argc, argv, __FUNCTION__);
jsdouble r = RandFloat();
JS_NewDoubleValue(cx, r, rval);
return JS_TRUE;
}
JSBool addEntity(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
ValidateArgs("sinnn", cx, argc, argv, __FUNCTION__);
if(theMap == 0) {
JS_ReportError(cx, "addEntity: cannot be called before init()");
}
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[5], &orientation);
theMap->addEntity(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;
}

View File

@ -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

View File

@ -0,0 +1,14 @@
#include "StdAfx.h"
#include ".\area.h"
Area::Area(void)
{
}
Area::Area(const std::vector<Point>& points) {
this->points = points;
}
Area::~Area(void)
{
}

13
source/tools/rmgen/area.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "point.h"
class Area
{
public:
std::vector<Point> points;
Area(void);
Area(const std::vector<Point>& points);
~Area(void);
};

View File

@ -0,0 +1,10 @@
#include "StdAfx.h"
#include ".\areapainter.h"
AreaPainter::AreaPainter(void)
{
}
AreaPainter::~AreaPainter(void)
{
}

View File

@ -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

View File

@ -0,0 +1,10 @@
#include "stdafx.h"
#include "areaplacer.h"
AreaPlacer::AreaPlacer(void)
{
}
AreaPlacer::~AreaPlacer(void)
{
}

View File

@ -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<Point>& ret) = 0;
AreaPlacer(void);
virtual ~AreaPlacer(void);
};
#endif

View File

@ -0,0 +1,10 @@
#include "stdafx.h"
#include "centeredplacer.h"
CenteredPlacer::CenteredPlacer(void)
{
}
CenteredPlacer::~CenteredPlacer(void)
{
}

View File

@ -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<Point>& ret, int x, int y) = 0;
CenteredPlacer(void);
virtual ~CenteredPlacer(void);
};
#endif

View File

@ -0,0 +1,10 @@
#include "stdafx.h"
#include "constraint.h"
Constraint::Constraint(void)
{
}
Constraint::~Constraint(void)
{
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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];
}
}

View File

@ -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<size; i++) {
area[i] = new Area*[size];
for(int j=0; j<size; j++) {
area[i][j] = 0;
}
}
height = new float*[size+1];
for(int i=0; i<size+1; i++) {
height[i] = new float[size+1];
@ -39,10 +48,19 @@ Map::~Map() {
}
delete[] terrain;
for(int i=0; i<size; i++) {
delete[] area[i];
}
delete[] area;
for(int i=0; i<size+1; i++) {
delete[] height[i];
}
delete[] height;
for(int i=0; i<entities.size(); i++) {
delete entities[i];
}
}
int Map::getId(string terrain) {
@ -83,4 +101,21 @@ float Map::getHeight(int x, int y) {
void Map::setHeight(int x, int y, float h) {
if(!validH(x,y)) JS_ReportError(cx, "setHeight: invalid point position");
height[x][y] = h;
}
void Map::addEntity(Entity* ent) {
entities.push_back(ent);
}
Area* Map::createArea(AreaPlacer* placer, AreaPainter* painter, Constraint* constr) {
vector<Point> points;
if(!placer->place(this, constr, points)) {
return 0;
}
Area* a = new Area(points);
for(int i=0; i<points.size(); i++) {
area[points[i].x][points[i].y] = a;
}
painter->paint(this, a);
return a;
}

View File

@ -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<std::string, int> nameToId;
std::map<int, std::string> idToName;
std::vector<Entity*> entities;
std::vector<Area*> 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

View File

@ -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 << "\
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n\
<!DOCTYPE Scenario SYSTEM \"/maps/scenario_v4.dtd\">\n\
<Scenario>\n\
<Environment>\n\
<SunColour r=\"1\" g=\"1\" b=\"1\" />\n\
<SunElevation angle=\"0.785398\" />\n\
<SunRotation angle=\"4.712389\" />\n\
<TerrainAmbientColour r=\"0\" g=\"0\" b=\"0\" />\n\
<UnitsAmbientColour r=\"0.4\" g=\"0.4\" b=\"0.4\" />\n\
<SunColour r=\"1\" g=\"1\" b=\"1\" />\n\
<SunElevation angle=\"0.785398\" />\n\
<SunRotation angle=\"4.712389\" />\n\
<TerrainAmbientColour r=\"0\" g=\"0\" b=\"0\" />\n\
<UnitsAmbientColour r=\"0.4\" g=\"0.4\" b=\"0.4\" />\n\
</Environment>\n\
<Entities />\n\
<Entities>\n";
for(int i=0; i<m->entities.size(); i++) {
Entity* e = m->entities[i];
xml << "\
<Entity>\n\
<Template>" << e->type << "</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";
}
xml << "\
</Entities>\
<Nonentities />\n\
</Scenario>\n";
/*
<Entity>
<Template>hele_hc</Template>
<Player>0</Player>
<Position x="182.122" y="30.0133" z="426.143" />
<Orientation angle="-3.0442" />
</Entity>
*/
fprintf(f, "%s", xml);
fprintf(f, "%s", xml.str().c_str());
}
struct Tile {

View File

@ -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 x<p.x || (x==p.x && y<p.y);
}

View File

@ -0,0 +1,14 @@
#ifndef __POINT_H_
#define __POINT_H_
class Point
{
public:
int x, y;
Point(void);
Point(int x, int y);
~Point(void);
bool operator<(const Point& p) const;
};
#endif

View File

@ -0,0 +1,29 @@
#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<Point>& ret) {
for(int x=x1; x<x2; x++) {
for(int y=y1; y<y2; y++) {
if(m->validT(x,y) && constr->allows(m,x,y)) {
ret.push_back(Point(x,y));
}
else {
return false;
}
}
}
return true;
}

View File

@ -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<Point>& ret);
RectPlacer(int x1, int y1, int x2, int y2);
~RectPlacer(void);
};
#endif

View File

@ -116,18 +116,51 @@
<File
RelativePath=".\api.cpp">
</File>
<File
RelativePath=".\area.cpp">
</File>
<File
RelativePath=".\areapainter.cpp">
</File>
<File
RelativePath=".\areaplacer.cpp">
</File>
<File
RelativePath=".\centeredplacer.cpp">
</File>
<File
RelativePath=".\constraint.cpp">
</File>
<File
RelativePath=".\entity.cpp">
</File>
<File
RelativePath=".\map.cpp">
</File>
<File
RelativePath=".\objparse.cpp">
</File>
<File
RelativePath=".\output.cpp">
</File>
<File
RelativePath=".\point.cpp">
</File>
<File
RelativePath=".\random.cpp">
</File>
<File
RelativePath=".\rectplacer.cpp">
</File>
<File
RelativePath=".\rmgen.cpp">
</File>
<File
RelativePath=".\simpleconstraints.cpp">
</File>
<File
RelativePath=".\simplepainters.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
@ -151,18 +184,51 @@
<File
RelativePath=".\api.h">
</File>
<File
RelativePath=".\area.h">
</File>
<File
RelativePath=".\areapainter.h">
</File>
<File
RelativePath=".\areaplacer.h">
</File>
<File
RelativePath=".\centeredplacer.h">
</File>
<File
RelativePath=".\constraint.h">
</File>
<File
RelativePath=".\entity.h">
</File>
<File
RelativePath=".\map.h">
</File>
<File
RelativePath=".\objparse.h">
</File>
<File
RelativePath=".\output.h">
</File>
<File
RelativePath=".\point.h">
</File>
<File
RelativePath=".\random.h">
</File>
<File
RelativePath=".\rectplacer.h">
</File>
<File
RelativePath=".\rmgen.h">
</File>
<File
RelativePath=".\simpleconstraints.h">
</File>
<File
RelativePath=".\simplepainters.h">
</File>
<File
RelativePath=".\stdafx.h">
</File>

View File

@ -0,0 +1,7 @@
#include "stdafx.h"
#include "simpleconstraints.h"
bool NullConstraint::allows(Map* m, int x, int y)
{
return true;
}

View File

@ -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

View File

@ -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; i<a->points.size(); i++) {
Point p = a->points[i];
m->terrain[p.x][p.y] = id;
}
}

View File

@ -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

View File

@ -12,6 +12,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <ctime>
#include <fstream>
#include <iostream>

View File

@ -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; x<SIZE; x++) {
for(var y=0; y<SIZE; y++) {
setTerrain(x,y, chooseRand("grass1_a","dirta","snow","road1"));
var t = chooseRand("grass1_a", "grass2", "grass1_dense", "grass_dry_25", "forrestfloor");
setTerrain(x, y, t);
setHeight(x, y, randFloat()*3);
if(t=="forrestfloor") {
addEntity("wrld_flora_oak", 3, x+0.5, y+0.5, randFloat()*2.0*Math.PI);
}
}
}
}

View File

@ -187,10 +187,13 @@ int CScEdApp::Run()
// do idle time processing
CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
if (mainfrm) {
CScEdView* view=(CScEdView*) mainfrm->GetActiveView();
if (view) {
view->IdleTimeProcess();
}
if (!mainfrm->IsIconic()) {
CScEdView* view=(CScEdView*) mainfrm->GetActiveView();
if (view) {
view->IdleTimeProcess();
}
}
Sleep(50);
}
}