Added SmoothElevationPainter.
This was SVN commit r2441.
This commit is contained in:
parent
e5d648ff5f
commit
a50b118c6c
@ -4,8 +4,8 @@ init(SIZE, ["snow", "snow forest"], 0);
|
||||
|
||||
createAreas(
|
||||
new ClumpPlacer(20.0, 0.01, 0.01),
|
||||
[new LayeredPainter([1], ["snow grass 2", "snow grass 2|wrld_flora_pine"]),
|
||||
new ElevationPainter(3.0)],
|
||||
[new TerrainPainter("snow grass 2"),
|
||||
new SmoothElevationPainter(ELEVATION_SET, 15.0, 3)],
|
||||
new AvoidTextureConstraint("snow grass 2"),
|
||||
150,
|
||||
500
|
||||
|
@ -1,17 +1,25 @@
|
||||
// Object type constants
|
||||
|
||||
const
|
||||
TYPE_RECTPLACER = 1,
|
||||
TYPE_TERRAINPAINTER = 2,
|
||||
TYPE_NULLCONSTRAINT = 3,
|
||||
TYPE_LAYEREDPAINTER = 4,
|
||||
TYPE_AVOIDAREACONSTRAINT = 5,
|
||||
TYPE_CLUMPPLACER = 6,
|
||||
TYPE_AVOIDTEXTURECONSTRAINT = 7,
|
||||
TYPE_ELEVATIONPAINTER = 8;
|
||||
TYPE_RECT_PLACER = 1,
|
||||
TYPE_TERRAIN_PAINTER = 2,
|
||||
TYPE_NULL_CONSTRAINT = 3,
|
||||
TYPE_LAYERED_PAINTER = 4,
|
||||
TYPE_AVOID_AREA_CONSTRAINT = 5,
|
||||
TYPE_CLUMP_PLACER = 6,
|
||||
TYPE_AVOID_TEXTURE_CONSTRAINT = 7,
|
||||
TYPE_ELEVATION_PAINTER = 8,
|
||||
TYPE_SMOOTH_ELEVATION_PAINTER = 9;
|
||||
|
||||
// SmoothElevationPainter constants
|
||||
|
||||
const ELEVATION_SET = 0;
|
||||
const ELEVATION_MODIFY = 1;
|
||||
|
||||
// initFromScenario constants
|
||||
|
||||
const LOAD_NOTHING = 0;
|
||||
const LOAD_TERRAIN = 1
|
||||
const LOAD_TERRAIN = 1;
|
||||
const LOAD_INTERACTIVES = 2;
|
||||
const LOAD_NON_INTERACTIVES = 4;
|
||||
const LOAD_ALL = LOAD_TERRAIN | LOAD_INTERACTIVES | LOAD_NON_INTERACTIVES;
|
||||
@ -44,55 +52,6 @@ function chooseRand() {
|
||||
return ar[randInt(ar.length)];
|
||||
}
|
||||
|
||||
// Area placers
|
||||
|
||||
function RectPlacer(x1, y1, x2, y2) {
|
||||
this.TYPE = TYPE_RECTPLACER;
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
}
|
||||
|
||||
function TerrainPainter(terrain) {
|
||||
this.TYPE = TYPE_TERRAINPAINTER;
|
||||
this.terrain = terrain;
|
||||
}
|
||||
|
||||
function NullConstraint() {
|
||||
this.TYPE = TYPE_NULLCONSTRAINT;
|
||||
}
|
||||
|
||||
function LayeredPainter(widths, terrains) {
|
||||
this.TYPE = TYPE_LAYEREDPAINTER;
|
||||
this.widths = widths;
|
||||
this.terrains = terrains;
|
||||
}
|
||||
|
||||
function AvoidAreaConstraint(area) {
|
||||
this.TYPE = TYPE_AVOIDAREACONSTRAINT;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
function ClumpPlacer(size, coherence, smoothness, x, y) {
|
||||
this.TYPE = TYPE_CLUMPPLACER;
|
||||
this.size = size;
|
||||
this.coherence = coherence;
|
||||
this.smoothness = smoothness;
|
||||
this.x = x ? x : -1;
|
||||
this.y = y ? y : -1;
|
||||
}
|
||||
|
||||
function AvoidTextureConstraint(texture) {
|
||||
this.TYPE = TYPE_AVOIDTEXTURECONSTRAINT;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
function ElevationPainter(elevation) {
|
||||
this.TYPE = TYPE_ELEVATIONPAINTER;
|
||||
this.elevation = elevation;
|
||||
}
|
||||
|
||||
function createAreas(centeredPlacer, painter, constraint, num, maxFail) {
|
||||
var good = 0;
|
||||
var bad = 0;
|
||||
@ -111,3 +70,63 @@ function createAreas(centeredPlacer, painter, constraint, num, maxFail) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Area placers
|
||||
|
||||
function RectPlacer(x1, y1, x2, y2) {
|
||||
this.TYPE = TYPE_RECT_PLACER;
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
}
|
||||
|
||||
function TerrainPainter(terrain) {
|
||||
this.TYPE = TYPE_TERRAIN_PAINTER;
|
||||
this.terrain = terrain;
|
||||
}
|
||||
|
||||
function ClumpPlacer(size, coherence, smoothness, x, y) {
|
||||
this.TYPE = TYPE_CLUMP_PLACER;
|
||||
this.size = size;
|
||||
this.coherence = coherence;
|
||||
this.smoothness = smoothness;
|
||||
this.x = x ? x : -1;
|
||||
this.y = y ? y : -1;
|
||||
}
|
||||
|
||||
// Area painters
|
||||
|
||||
function LayeredPainter(widths, terrains) {
|
||||
this.TYPE = TYPE_LAYERED_PAINTER;
|
||||
this.widths = widths;
|
||||
this.terrains = terrains;
|
||||
}
|
||||
|
||||
function ElevationPainter(elevation) {
|
||||
this.TYPE = TYPE_ELEVATION_PAINTER;
|
||||
this.elevation = elevation;
|
||||
}
|
||||
|
||||
function SmoothElevationPainter(type, elevation, blendRadius) {
|
||||
this.TYPE = TYPE_SMOOTH_ELEVATION_PAINTER;
|
||||
this.type = type;
|
||||
this.elevation = elevation;
|
||||
this.blendRadius = blendRadius;
|
||||
}
|
||||
|
||||
// Constraints
|
||||
|
||||
function NullConstraint() {
|
||||
this.TYPE = TYPE_NULL_CONSTRAINT;
|
||||
}
|
||||
|
||||
function AvoidAreaConstraint(area) {
|
||||
this.TYPE = TYPE_AVOID_AREA_CONSTRAINT;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
function AvoidTextureConstraint(texture) {
|
||||
this.TYPE = TYPE_AVOID_TEXTURE_CONSTRAINT;
|
||||
this.texture = texture;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "rectplacer.h"
|
||||
#include "layeredpainter.h"
|
||||
#include "clumpplacer.h"
|
||||
#include "smoothelevationpainter.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -83,6 +84,8 @@ AreaPainter* ParsePainter(JSContext* cx, jsval val) {
|
||||
jsval jsv, jsv2;
|
||||
Terrain* terrain = 0;
|
||||
float elevation;
|
||||
int type;
|
||||
int blendRadius;
|
||||
vector<Terrain*> terrains;
|
||||
vector<int> widths;
|
||||
|
||||
@ -97,17 +100,23 @@ AreaPainter* ParsePainter(JSContext* cx, jsval val) {
|
||||
}
|
||||
|
||||
switch(GetType(cx, val)) {
|
||||
case TYPE_TERRAINPAINTER:
|
||||
case TYPE_TERRAIN_PAINTER:
|
||||
if(!GetJsvalField(cx, val, "terrain", jsv)) return 0;
|
||||
terrain = ParseTerrain(cx, jsv);
|
||||
if(terrain==0) return 0;
|
||||
return new TerrainPainter(terrain);
|
||||
|
||||
case TYPE_ELEVATIONPAINTER:
|
||||
case TYPE_ELEVATION_PAINTER:
|
||||
if(!GetFloatField(cx, val, "elevation", elevation)) return 0;
|
||||
return new ElevationPainter(elevation);
|
||||
|
||||
case TYPE_LAYEREDPAINTER:
|
||||
case TYPE_SMOOTH_ELEVATION_PAINTER:
|
||||
if(!GetIntField(cx, val, "type", type)) return 0;
|
||||
if(!GetFloatField(cx, val, "elevation", elevation)) return 0;
|
||||
if(!GetIntField(cx, val, "blendRadius", blendRadius)) return 0;
|
||||
return new SmoothElevationPainter(type, elevation, blendRadius);
|
||||
|
||||
case TYPE_LAYERED_PAINTER:
|
||||
if(!GetJsvalField(cx, val, "widths", jsv)) return 0;
|
||||
if(!GetJsvalField(cx, val, "terrains", jsv2)) return 0;
|
||||
if(!ParseArray(cx, jsv, array)) return 0;
|
||||
@ -135,14 +144,14 @@ AreaPlacer* ParsePlacer(JSContext* cx, jsval val) {
|
||||
float size, coherence, smoothness;
|
||||
|
||||
switch(GetType(cx, val)) {
|
||||
case TYPE_RECTPLACER:
|
||||
case TYPE_RECT_PLACER:
|
||||
if(!GetIntField(cx, val, "x1", x1)) return 0;
|
||||
if(!GetIntField(cx, val, "y1", y1)) return 0;
|
||||
if(!GetIntField(cx, val, "x2", x2)) return 0;
|
||||
if(!GetIntField(cx, val, "y2", y2)) return 0;
|
||||
return new RectPlacer(x1, y1, x2, y2);
|
||||
|
||||
case TYPE_CLUMPPLACER:
|
||||
case TYPE_CLUMP_PLACER:
|
||||
if(!GetFloatField(cx, val, "size", size)) return 0;
|
||||
if(!GetFloatField(cx, val, "coherence", coherence)) return 0;
|
||||
if(!GetFloatField(cx, val, "smoothness", smoothness)) return 0;
|
||||
@ -177,15 +186,15 @@ Constraint* ParseConstraint(JSContext* cx, jsval val) {
|
||||
}
|
||||
|
||||
switch(GetType(cx, val)) {
|
||||
case TYPE_NULLCONSTRAINT:
|
||||
case TYPE_NULL_CONSTRAINT:
|
||||
return new NullConstraint();
|
||||
|
||||
case TYPE_AVOIDAREACONSTRAINT:
|
||||
case TYPE_AVOID_AREA_CONSTRAINT:
|
||||
if(!GetIntField(cx, val, "area", areaId)) return 0;
|
||||
if(areaId <= 0 || areaId > theMap->areas.size()) return 0;
|
||||
return new AvoidAreaConstraint(theMap->areas[areaId-1]);
|
||||
|
||||
case TYPE_AVOIDTEXTURECONSTRAINT:
|
||||
case TYPE_AVOID_TEXTURE_CONSTRAINT:
|
||||
if(!GetStringField(cx, val, "texture", texture)) return 0;
|
||||
return new AvoidTextureConstraint(theMap->getId(texture));
|
||||
|
||||
|
@ -11,14 +11,15 @@
|
||||
// Object type constants
|
||||
|
||||
const int
|
||||
TYPE_RECTPLACER = 1,
|
||||
TYPE_TERRAINPAINTER = 2,
|
||||
TYPE_NULLCONSTRAINT = 3,
|
||||
TYPE_LAYEREDPAINTER = 4,
|
||||
TYPE_AVOIDAREACONSTRAINT = 5,
|
||||
TYPE_CLUMPPLACER = 6,
|
||||
TYPE_AVOIDTEXTURECONSTRAINT = 7,
|
||||
TYPE_ELEVATIONPAINTER = 8;
|
||||
TYPE_RECT_PLACER = 1,
|
||||
TYPE_TERRAIN_PAINTER = 2,
|
||||
TYPE_NULL_CONSTRAINT = 3,
|
||||
TYPE_LAYERED_PAINTER = 4,
|
||||
TYPE_AVOID_AREA_CONSTRAINT = 5,
|
||||
TYPE_CLUMP_PLACER = 6,
|
||||
TYPE_AVOID_TEXTURE_CONSTRAINT = 7,
|
||||
TYPE_ELEVATION_PAINTER = 8,
|
||||
TYPE_SMOOTH_ELEVATION_PAINTER = 9;
|
||||
|
||||
// Helper functions to parse objects from JS versions
|
||||
|
||||
|
@ -165,6 +165,9 @@
|
||||
<File
|
||||
RelativePath=".\simplepainters.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\smoothelevationpainter.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp">
|
||||
<FileConfiguration
|
||||
@ -239,6 +242,9 @@
|
||||
<File
|
||||
RelativePath=".\simplepainters.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\smoothelevationpainter.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h">
|
||||
</File>
|
||||
|
Loading…
Reference in New Issue
Block a user