Added sharedTerrain library

This commit is contained in:
Anonymous
2014-01-14 09:33:54 -07:00
parent f4243cffeb
commit 8342abaeec
159 changed files with 37404 additions and 0 deletions
+1
View File
@@ -15,5 +15,6 @@ add_subdirectory(sharedNetworkMessages)
add_subdirectory(sharedObject)
add_subdirectory(sharedRandom)
add_subdirectory(sharedSynchronization)
add_subdirectory(sharedTerrain)
add_subdirectory(sharedThread)
add_subdirectory(sharedUtility)
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.8)
project(sharedTerrain)
if(WIN32)
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
add_subdirectory(src)
@@ -0,0 +1 @@
#include "../../src/shared/generator/Affector.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorColor.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorEnvironment.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorExclude.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorFloraDynamic.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorFloraStatic.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorHeight.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorPassable.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorRibbon.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorRiver.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorRoad.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/AffectorShader.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/Array2d.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/BitmapGroup.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/Boundary.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/ColorRamp256.h"
@@ -0,0 +1 @@
#include "../../src/shared/core/ConfigSharedTerrain.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/CoordinateHash.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/EnvironmentGroup.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/FastKeyList.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/FastList.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/Feather.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/Filter.h"
@@ -0,0 +1 @@
#include "../../src/shared/core/FirstSharedTerrain.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/FloraGroup.h"
@@ -0,0 +1 @@
#include "../../src/shared/flora/FloraManager.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/FractalGroup.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/HeightData.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ProceduralTerrainAppearance.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ProceduralTerrainAppearanceTemplate.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/RadialGroup.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/SamplerProceduralTerrainAppearance.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/SamplerProceduralTerrainAppearanceTemplate.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/SamplerProceduralTerrainAppearance_Cache.h"
@@ -0,0 +1 @@
#include "../../src/shared/flora/ServerFloraManager.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ServerProceduralTerrainAppearance.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ServerProceduralTerrainAppearanceTemplate.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ServerProceduralTerrainAppearance_Cache.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ServerSpaceTerrainAppearance.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/ServerSpaceTerrainAppearanceTemplate.h"
@@ -0,0 +1 @@
#include "../../src/shared/core/SetupSharedTerrain.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/ShaderGroup.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/SpaceTerrainAppearance.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/SpaceTerrainAppearanceTemplate.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/TerrainAppearance.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/TerrainGenerator.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/TerrainGeneratorLoader.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/TerrainGeneratorType.def"
@@ -0,0 +1 @@
#include "../../src/shared/generator/TerrainGeneratorType.h"
@@ -0,0 +1 @@
#include "../../src/shared/generator/TerrainModificationHelper.h"
@@ -0,0 +1 @@
#include "../../src/shared/object/TerrainObject.h"
@@ -0,0 +1 @@
#include "../../src/shared/appearance/TerrainQuadTree.h"
@@ -0,0 +1 @@
#include "../../src/shared/object/TerrainReferenceObjectNotification.h"
@@ -0,0 +1 @@
#include "../../src/shared/core/WaterTypeManager.h"
@@ -0,0 +1,140 @@
set(SHARED_SOURCES
shared/appearance/ProceduralTerrainAppearance.cpp
shared/appearance/ProceduralTerrainAppearance.h
shared/appearance/ProceduralTerrainAppearanceTemplate.cpp
shared/appearance/ProceduralTerrainAppearanceTemplate.h
shared/appearance/SamplerProceduralTerrainAppearance.cpp
shared/appearance/SamplerProceduralTerrainAppearance.h
shared/appearance/SamplerProceduralTerrainAppearance_Cache.cpp
shared/appearance/SamplerProceduralTerrainAppearance_Cache.h
shared/appearance/SamplerProceduralTerrainAppearanceTemplate.cpp
shared/appearance/SamplerProceduralTerrainAppearanceTemplate.h
shared/appearance/ServerProceduralTerrainAppearance_Cache.cpp
shared/appearance/ServerProceduralTerrainAppearance_Cache.h
shared/appearance/ServerProceduralTerrainAppearance.cpp
shared/appearance/ServerProceduralTerrainAppearance.h
shared/appearance/ServerProceduralTerrainAppearanceTemplate.cpp
shared/appearance/ServerProceduralTerrainAppearanceTemplate.h
shared/appearance/ServerSpaceTerrainAppearance.cpp
shared/appearance/ServerSpaceTerrainAppearance.h
shared/appearance/ServerSpaceTerrainAppearanceTemplate.cpp
shared/appearance/ServerSpaceTerrainAppearanceTemplate.h
shared/appearance/SpaceTerrainAppearance.cpp
shared/appearance/SpaceTerrainAppearance.h
shared/appearance/SpaceTerrainAppearanceTemplate.cpp
shared/appearance/SpaceTerrainAppearanceTemplate.h
shared/appearance/TerrainAppearance.cpp
shared/appearance/TerrainAppearance.h
shared/appearance/TerrainQuadTree.cpp
shared/appearance/TerrainQuadTree.h
shared/core/ConfigSharedTerrain.cpp
shared/core/ConfigSharedTerrain.h
shared/core/FirstSharedTerrain.h
shared/core/SetupSharedTerrain.cpp
shared/core/SetupSharedTerrain.h
shared/core/WaterTypeManager.cpp
shared/core/WaterTypeManager.h
shared/flora/FloraManager.cpp
shared/flora/FloraManager.h
shared/flora/ServerFloraManager.cpp
shared/flora/ServerFloraManager.h
shared/generator/AffectorColor.cpp
shared/generator/AffectorColor.h
shared/generator/Affector.cpp
shared/generator/AffectorEnvironment.cpp
shared/generator/AffectorEnvironment.h
shared/generator/AffectorExclude.cpp
shared/generator/AffectorExclude.h
shared/generator/AffectorFloraDynamic.cpp
shared/generator/AffectorFloraDynamic.h
shared/generator/AffectorFloraStatic.cpp
shared/generator/AffectorFloraStatic.h
shared/generator/Affector.h
shared/generator/AffectorHeight.cpp
shared/generator/AffectorHeight.h
shared/generator/AffectorPassable.cpp
shared/generator/AffectorPassable.h
shared/generator/AffectorRibbon.cpp
shared/generator/AffectorRibbon.h
shared/generator/AffectorRiver.cpp
shared/generator/AffectorRiver.h
shared/generator/AffectorRoad.cpp
shared/generator/AffectorRoad.h
shared/generator/AffectorShader.cpp
shared/generator/AffectorShader.h
shared/generator/Array2d.h
shared/generator/BitmapGroup.cpp
shared/generator/BitmapGroup.h
shared/generator/Boundary.cpp
shared/generator/Boundary.h
shared/generator/ColorRamp256.cpp
shared/generator/ColorRamp256.h
shared/generator/CoordinateHash.cpp
shared/generator/CoordinateHash.h
shared/generator/EnvironmentGroup.cpp
shared/generator/EnvironmentGroup.h
shared/generator/FastKeyList.h
shared/generator/FastList.h
shared/generator/Feather.h
shared/generator/Filter.cpp
shared/generator/Filter.h
shared/generator/FloraGroup.cpp
shared/generator/FloraGroup.h
shared/generator/FractalGroup.cpp
shared/generator/FractalGroup.h
shared/generator/HeightData.cpp
shared/generator/HeightData.h
shared/generator/RadialGroup.cpp
shared/generator/RadialGroup.h
shared/generator/ShaderGroup.cpp
shared/generator/ShaderGroup.h
shared/generator/TerrainGenerator.cpp
shared/generator/TerrainGenerator.h
shared/generator/TerrainGeneratorLoader.cpp
shared/generator/TerrainGeneratorLoader.h
shared/generator/TerrainGeneratorType.def
shared/generator/TerrainGeneratorType.h
shared/generator/TerrainModificationHelper.cpp
shared/generator/TerrainModificationHelper.h
shared/object/TerrainObject.cpp
shared/object/TerrainObject.h
shared/object/TerrainReferenceObjectNotification.cpp
shared/object/TerrainReferenceObjectNotification.h
)
if(WIN32)
set(PLATFORM_SOURCES
win32/FirstSharedTerrain.cpp
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32)
else()
set(PLATFORM_SOURCES "")
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/shared
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCollision/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFractal/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedImage/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedObject/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRandom/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedUtility/include/public
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/fileInterface/include/public
)
add_library(sharedTerrain STATIC
${SHARED_SOURCES}
${PLATFORM_SOURCES}
)
@@ -0,0 +1,456 @@
//===================================================================
//
// ProceduralTerrainAppearance.h
// asommers 9-11-2000
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_ProceduralTerrainAppearance_H
#define INCLUDED_ProceduralTerrainAppearance_H
//===================================================================
#include "sharedCollision/BoxExtent.h"
#include "sharedMath/Sphere.h"
#include "sharedMath/Vector.h"
#include "sharedTerrain/TerrainAppearance.h"
#include "sharedTerrain/TerrainGenerator.h"
class Appearance;
class Camera;
class Iff;
class Object;
class ObjectList;
class ObjectTemplate;
class ProceduralTerrainAppearanceTemplate;
class Rectangle2d;
class SpatialSubdivisionHandle;
//-------------------------------------------------------------------
//
// ProceduralTerrainAppearance holds a list of generated terrain chunks
//
// data for the template is as follows:
//
// mapWidthInMeters supplied by designers/artists (i.e. 4096m x 4096m)
//
// chunkWidthInMeters supplied by designers/artists (i.e. 32m)
//
// tileWidthInMeters width of a terrain tile in meters
// tiles are composed of a fan of 8 polygons
//
// numberOfTilesPerChunk number of tiles per chunk for width and height (square)
// total number of tiles per chunk is numberOfTilesPerChunk^2
//
// numberOfTiles along width = numberOfChunks * numberOfTilesPerChunk
// total number of tiles = numberOfTiles^2
//
// tiles are organized in the following vertex structure. the purpose of
// indirection is to allow me to create the tile vertex arrays in a loop
//
// 2 3 4
// x-----x-----x
// |\ | /|
// | \ | / |
// | 0\|/ |
// 1 x-----x-----x 5
// | /|\ |
// | / | \ |
// |/ | \|
// x-----x-----x
// 8 7 6
//
class ProceduralTerrainAppearance : public TerrainAppearance
{
public:
typedef void (*CreateFloraHookFunction) (Object& object);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// CreateChunkData defines the data needed to generate a chunk in the terrain system
//
struct CreateChunkData
{
public:
//-- scratchpad (using TerrainGenerator::createChunkBuffer)
TerrainGenerator::CreateChunkBuffer* createChunkBuffer;
//-- coordinate of chunk (x,z) in chunk space
int chunkX;
int chunkZ;
//-- number of shader tiles
int numberOfTilesPerChunk;
//-- chunk width
float chunkWidthInMeters;
float tileWidthInMeters;
Vector start;
int originOffset;
int numberOfPoles;
//--
const ShaderGroup* shaderGroup;
const FloraGroup* floraGroup;
const RadialGroup* radialGroup;
const EnvironmentGroup* environmentGroup;
const FractalGroup* fractalGroup;
const BitmapGroup* bitmapGroup;
uint8 hasLargerNeighborFlags;
private:
CreateChunkData ();
CreateChunkData (const CreateChunkData& rhs);
CreateChunkData& operator= (const CreateChunkData& rhs);
public:
explicit CreateChunkData (TerrainGenerator::CreateChunkBuffer* newCreateChunkBuffer);
virtual ~CreateChunkData ();
virtual void validate () const;
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// SurfaceData returns the object template at a given tile of the terrain system
//
struct SurfaceData
{
public:
const ObjectTemplate* objectTemplate;
public:
SurfaceData ();
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// StaticFloraData defines information about what flora exists at a point
//
struct StaticFloraData
{
public:
//-- family data
bool floats;
float childChoice;
//-- family child data
FloraGroup::FamilyChildData const * familyChildData;
public:
StaticFloraData ();
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Chunk defines a chunk of terrain in the terrain system
//
class Chunk : public Appearance
{
public:
explicit Chunk (ProceduralTerrainAppearance& proceduralTerrainAppearance);
virtual ~Chunk ();
const ProceduralTerrainAppearanceTemplate *getAppearanceTemplate() const { return m_proceduralTerrainAppearance.proceduralTerrainAppearanceTemplate; }
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParameters, CollisionInfo & result) const = 0;
virtual bool getHeightAt (const Vector& pos, float* height) const = 0;
virtual bool getHeightAt (const Vector& pos, float* height, Vector* normal) const = 0;
const BoxExtent& getBoxExtent() const { return m_boxExtent; }
//-- coordinate of chunk (x,z) in chunk space
int getChunkX() const { return chunkX; }
int getChunkZ() const { return chunkZ; }
float getChunkWidthInMeters () const { return chunkWidthInMeters; }
bool getHasLargerNeighbor (int dir) const;
bool getHasAnyLargerNeighbors () const { return hasLargerNeighborFlags!=0; }
bool findSurface (const Vector& position, SurfaceData& data) const;
void setPassable(int tileX, int tileZ, bool isPassable);
bool isPassable(const Vector& position) const;
bool isExcluded(const Vector& position) const;
bool isExcluded(int tileX, int tileZ) const;
bool floraAllowed(const Vector& position) const { return _floraAllowed(position.x, position.z); }
bool findStaticCollidableFlora (const Vector& position, StaticFloraData& data, bool& floraAllowed) const;
bool findStaticCollidableFlora (const Vector& position, FloraGroup::Info& data, bool& floraAllowed) const;
virtual int getChunkMemorySize () const;
#ifdef _DEBUG
virtual bool debugRenderingEnabled () const;
#endif
SpatialSubdivisionHandle *getSpatialSubdivisionHandle() const { return m_spatialSubdivisionHandle; }
void setSpatialSubdivisionHandle(SpatialSubdivisionHandle *h) const { m_spatialSubdivisionHandle = h; }
public:
static void setDrawVertexNormals (bool drawVertexNormals);
static bool getDrawVertexNormals ();
static void setDrawExtent (bool drawExtent);
static bool getDrawExtent ();
protected:
void _findMapXz (const Vector& position, int& x, int& z) const;
void _findTileXz(Vector const & position, int & x, int & z) const;
void _makeStaticFloraData(StaticFloraData& o_data, const FloraGroup::Info &i_groupInfo) const;
bool _floraAllowed(float positionX, float positionZ) const;
bool _findStaticFlora(const Array2d<FloraGroup::Info>& floraMap, float positionX, float positionZ, StaticFloraData& data, bool& floraAllowed) const;
bool _findStaticFlora(const Array2d<FloraGroup::Info>& floraMap, float positionX, float positionZ, FloraGroup::Info &data, bool& floraAllowed) const;
void _prepareForDelete();
void _setExcluded(int tileX, int tileZ);
protected:
ProceduralTerrainAppearance & m_proceduralTerrainAppearance;
//-- coordinate of chunk (x,z) in chunk space
int chunkX;
int chunkZ;
float chunkWidthInMeters;
uint8 hasLargerNeighborFlags;
int originOffset;
int numberOfPoles;
BoxExtent m_boxExtent;
Array2d<ShaderGroup::Info>* shaderMap;
Array2d<FloraGroup::Info> * m_floraStaticCollidableMap;
unsigned m_excluded, m_passable;
mutable SpatialSubdivisionHandle * m_spatialSubdivisionHandle;
private:
Chunk ();
Chunk (const Chunk& rhs);
Chunk& operator= (const Chunk& rhs);
private:
static bool ms_drawVertexNormals;
static bool ms_drawExtent;
};
friend class Chunk;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public:
ProceduralTerrainAppearance (const ProceduralTerrainAppearanceTemplate* appearanceTemplate);
virtual ~ProceduralTerrainAppearance () = 0;
virtual const Sphere& getSphere () const;
virtual bool getHeight (const Vector& position_o, float& height) const;
virtual bool getHeight (const Vector& position_o, float& height, Vector& normal) const;
virtual bool getHeightForceChunkCreation (const Vector& position_o, float& height) const;
virtual const ObjectTemplate* getSurfaceProperties (const Vector& position_o) const;
virtual bool getWaterHeight (const Vector& position_o, float& height) const;
virtual bool getWaterHeight (const Vector& position_o, float& height, TerrainGeneratorWaterType& waterType, bool ignoreNonTransparentWater=false) const;
TerrainGeneratorWaterType getWaterType (const Vector& position_o) const;
virtual bool getWater (int chunkX, int chunkZ) const;
virtual bool getSlope (int chunkX, int chunkZ) const;
virtual bool getWater (const Rectangle2d& rectangle) const;
virtual bool getSlope (const Rectangle2d& rectangle) const;
virtual float getChunkWidthInMeters () const;
virtual float getMapWidthInMeters () const;
virtual float getEnvironmentCycleTime () const;
virtual int getNumberOfChunks () const = 0;
virtual int calculateChunkX (float positionX) const;
virtual int calculateChunkZ (float positionZ) const;
virtual float getChunkHeight (int chunkX, int chunkZ) const;
virtual const BoxExtent* getChunkExtent (const Vector& position_o) const;
virtual const BoxExtent* getChunkExtentForceChunkCreation (const Vector& position_o) const;
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParamters, CollisionInfo & result) const = 0;
virtual float alter (float time) = 0;
int getNumberOfTilesPerChunk () const;
bool findSurface (const Vector& position, SurfaceData& data) const;
bool findStaticCollidableFlora (const Vector& position, StaticFloraData& data, bool& floraAllowed) const;
virtual bool isPassable(const Vector& position) const;
virtual bool isPassableForceChunkCreation(const Vector& position) const;
//-- run-time rule addition interface
void addLayer (const TerrainGenerator::Layer* layer);
void removeLayer (const TerrainGenerator::Layer* layer);
void prepareGenerator ();
float generateHeight_expensive (const Vector2d& position_w);
virtual void addClearCollidableFloraObject (const Object* object, const Vector& position_w, float radius);
virtual void removeClearCollidableFloraObject (const Object* object);
virtual void debugDump () const;
ShaderGroup const & getShaderGroup() const;
FloraGroup const & getFloraGroup() const;
RadialGroup const & getRadialGroup() const;
EnvironmentGroup const & getEnvironmentGroup() const;
virtual bool hasPassableAffectors() const;
public:
static void install ();
static void setCreateFloraHookFunction (CreateFloraHookFunction createFloraHookFunction);
static void setMaximumNumberOfChunksAllowed (int newMaximumNumberOfChunksAllowed);
protected:
class ClearCollidableFloraEntry
{
public:
Vector position;
float radius;
};
protected:
typedef stdmap<const Object*, ClearCollidableFloraEntry>::fwd ClearCollidableFloraMap;
protected:
virtual const Chunk* findChunk (int x, int z, int chunkSize) const = 0;
virtual const Chunk* findFirstRenderableChunk (int x, int z) const = 0;
virtual const Chunk* findAnyChunk () const;
virtual void addChunk (Chunk* chunk, int chunkSize) = 0;
virtual void createChunk (int x, int z, int chunkSize, unsigned hasLargerNeighborFlags) = 0;
virtual void removeUnnecessaryChunk () = 0;
bool areValidChunkIndices (int x, int z) const;
const Chunk* findChunk (const Vector& position, int chunkSize) const;
const Chunk* findFirstRenderableChunk (const Vector& position) const;
const Chunk* findFirstRenderableChunk2D(float positionX, float positionZ) const;
void createChunk (const Vector& position, int chunkSize);
virtual void prepareForDelete (const Chunk* chunk);
bool _legacyGetStaticCollidableFloraData(StaticFloraData &o_data, const Chunk* const chunk, const Vector &floraPosition);
void _legacyCreateFlora (const Chunk* chunk);
void createFlora (const Chunk* chunk);
void destroyFlora (const Chunk* chunk);
void verifyChunk (const Chunk* chunk) const;
void setClient ();
const ClearCollidableFloraMap* getClearCollidableFloraMap () const;
protected:
//--
const int originOffset;
const int upperPad;
const int numberOfPoles;
//-- culling sphere
mutable Sphere sphere;
//-- scratchpad for creating chunks
TerrainGenerator::CreateChunkBuffer createChunkBuffer;
//-- scratchpad for [expensively] creating just height data
TerrainGenerator::CreateChunkBuffer generateHeightChunkBuffer;
//-- maximum number of chunks to hold
int maximumNumberOfChunksAllowed;
int maximumNumberOfChunksAlongSide;
const ProceduralTerrainAppearanceTemplate* proceduralTerrainAppearanceTemplate;
typedef stdvector<TerrainGenerator::Layer*>::fwd RunTimeRuleList;
RunTimeRuleList* m_runTimeRuleList;
int m_chunksGeneratedThisFrame;
protected:
static CreateFloraHookFunction ms_createFloraHookFunction;
private:
static void remove ();
private:
bool shouldClearCollidableFlora (const Vector& position) const;
private:
ProceduralTerrainAppearance ();
ProceduralTerrainAppearance (const ProceduralTerrainAppearance&);
ProceduralTerrainAppearance& operator= (const ProceduralTerrainAppearance&);
private:
bool m_server;
typedef stdmap<uint32, Object*>::fwd FloraMap;
FloraMap* const m_floraMap;
FloraMap* const m_cachedFloraMap;
ClearCollidableFloraMap* const m_clearCollidableFloraMap;
bool m_hasPassableAffectors;
};
//-------------------------------------------------------------------
inline
bool ProceduralTerrainAppearance::Chunk::getHasLargerNeighbor (int direction) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE (0, direction, 4);
return 0!=(hasLargerNeighborFlags & (1<<direction));
}
//-------------------------------------------------------------------
inline
bool ProceduralTerrainAppearance::Chunk::findStaticCollidableFlora (const Vector& position, StaticFloraData& data, bool& floraAllowed) const
{
NOT_NULL (m_floraStaticCollidableMap);
return _findStaticFlora(*m_floraStaticCollidableMap, position.x, position.z, data, floraAllowed);
}
//-------------------------------------------------------------------
inline
bool ProceduralTerrainAppearance::Chunk::findStaticCollidableFlora (const Vector& position, FloraGroup::Info& data, bool& floraAllowed) const
{
NOT_NULL (m_floraStaticCollidableMap);
return _findStaticFlora(*m_floraStaticCollidableMap, position.x, position.z, data, floraAllowed);
}
//===================================================================
#endif
@@ -0,0 +1,249 @@
//===================================================================
//
// ProceduralTerrainAppearanceTemplate.h
// asommers 9-11-2000
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_ProceduralTerrainAppearanceTemplate_H
#define INCLUDED_ProceduralTerrainAppearanceTemplate_H
//===================================================================
#include "sharedMath/Vector2d.h"
#include "sharedObject/AppearanceTemplate.h"
#include "sharedTerrain/TerrainGenerator.h"
#include "sharedTerrain/Boundary.h"
class BakedTerrain;
class Iff;
class PackedIntegerMap;
class PackedFixedPointMap;
//===================================================================
class ProceduralTerrainAppearanceTemplate : public AppearanceTemplate
{
public:
explicit ProceduralTerrainAppearanceTemplate(
const char* filename,
Iff* iff,
bool legacyMode,
int chunkOriginOffset, // size of sample pad on lower side of chunk.
int chunkUpperPad, // size of sample pad on upper side of chunk.
bool samplingMode=false
);
virtual ~ProceduralTerrainAppearanceTemplate ()=0;
const char* getName () const;
float getMapWidthInMeters () const;
float getChunkWidthInMeters () const;
int getNumberOfTilesPerChunk () const;
bool getUseGlobalWaterTable () const;
float getGlobalWaterTableHeight () const;
const char* getGlobalWaterTableShaderTemplateName () const;
float getGlobalWaterTableShaderSize () const;
float getEnvironmentCycleTime () const;
float getCollidableMinimumDistance () const;
float getCollidableMaximumDistance () const;
float getCollidableTileSize () const;
float getCollidableTileBorder () const;
uint32 getCollidableSeed () const;
float getNonCollidableMinimumDistance () const;
float getNonCollidableMaximumDistance () const;
float getNonCollidableTileSize () const;
float getNonCollidableTileBorder () const;
uint32 getNonCollidableSeed () const;
float getRadialMinimumDistance () const;
float getRadialMaximumDistance () const;
float getRadialTileSize () const;
float getRadialTileBorder () const;
uint32 getRadialSeed () const;
float getFarRadialMinimumDistance () const;
float getFarRadialMaximumDistance () const;
float getFarRadialTileSize () const;
float getFarRadialTileBorder () const;
uint32 getFarRadialSeed () const;
float getTileWidthInMeters () const;
bool getLegacyMap() const { return m_legacyMap; }
bool getLegacyMode() const { return m_legacyMode; }
int getChunkOriginOffset() const { return m_chunkOriginOffset; }
int getChunkUpperPad() const { return m_chunkUpperPad; }
const TerrainGenerator* getTerrainGenerator () const;
const BakedTerrain* getBakedTerrain () const;
bool getWaterHeight (const Vector& position, float& height) const;
bool getWaterHeight (const Vector& position, float& height, TerrainGeneratorWaterType& waterType, bool ignoreNonTransparentWater = false) const;
TerrainGeneratorWaterType getWaterType (const Vector& position_w) const;
// --
float getFloraTileWidthInMeters() const { return m_floraTileWidthInMeters; }
int getMapWidthInFlora() const { return m_mapWidthInFlora; }
int getStaticCollidableFloraFamily(int floraTileX, int floraTileY) const;
float getStaticCollidableFloraHeight(int floraTileX, int floraTileY) const;
protected:
struct RibbonQuad
{
TerrainGeneratorWaterType waterType;
Vector points[4];
};
struct RibbonEndCap
{
TerrainGeneratorWaterType waterType;
Vector2d points[8];
Rectangle2d extent;
float height;
};
struct WaterTable
{
TerrainGeneratorWaterType waterType;
const TerrainGenerator::Boundary* boundary;
float height;
};
protected:
char* m_name;
float m_mapWidthInMeters;
float m_chunkWidthInMeters;
int m_numberOfTilesPerChunk;
bool m_useGlobalWaterTable;
float m_globalWaterTableHeight;
char* m_globalWaterTableShaderTemplateName;
float m_globalWaterTableShaderSize;
float m_environmentCycleTime;
float m_collidableMinimumDistance;
float m_collidableMaximumDistance;
float m_collidableTileSize;
float m_collidableTileBorder;
uint32 m_collidableSeed;
float m_nonCollidableMinimumDistance;
float m_nonCollidableMaximumDistance;
float m_nonCollidableTileSize;
float m_nonCollidableTileBorder;
uint32 m_nonCollidableSeed;
float m_radialMinimumDistance;
float m_radialMaximumDistance;
float m_radialTileSize;
float m_radialTileBorder;
uint32 m_radialSeed;
float m_farRadialMinimumDistance;
float m_farRadialMaximumDistance;
float m_farRadialTileSize;
float m_farRadialTileBorder;
uint32 m_farRadialSeed;
bool m_legacyMap;
bool m_legacyMode;
const bool m_samplingMode;
float m_tileWidthInMeters;
int m_chunkOriginOffset;
int m_chunkUpperPad;
TerrainGenerator* m_terrainGenerator;
BakedTerrain* m_bakedTerrain;
typedef stdvector<WaterTable>::fwd WaterTableList;
WaterTableList* m_waterTableList;
typedef stdvector<RibbonQuad>::fwd RibbonQuadList;
RibbonQuadList* m_ribbonQuadList;
typedef stdvector<RibbonEndCap>::fwd RibbonEndCapList;
RibbonEndCapList* m_ribbonEndCapList;
float m_floraTileWidthInMeters;
int m_mapWidthInFlora;
PackedIntegerMap *m_staticCollidableFloraMap;
PackedFixedPointMap *m_staticCollidableFloraHeightMap;
protected:
void load (Iff& iff); //lint !e1511 //-- member hides non-virtual member
void _load(Iff& iff, Tag version);
void createWaterTableAndRibbonQuadLists ();
void createWaterTableAndRibbonQuadLists (const TerrainGenerator::Layer* layer);
void _setSamplingParameters(bool legacyMode, int chunkOriginOffset, int chunkUpperPad);
void _setStaticCollidableFloraInfo(FloraGroup::Info *infoMap, float *heightMap);
void _destroyStaticCollidableFloraMaps();
void _createDefaultStaticCollidableFloraMaps();
private:
ProceduralTerrainAppearanceTemplate ();
ProceduralTerrainAppearanceTemplate (const ProceduralTerrainAppearanceTemplate&);
ProceduralTerrainAppearanceTemplate& operator= (const ProceduralTerrainAppearanceTemplate&);
// ------------------------------------------------------------------
public:
struct WriterData
{
public:
const char* name;
float mapWidthInMeters;
float chunkWidthInMeters;
int numberOfTilesPerChunk;
bool useGlobalWaterTable;
float globalWaterTableHeight;
float globalWaterTableShaderSize;
const char* globalWaterTableShaderTemplateName;
float environmentCycleTime;
float collidableMinimumDistance;
float collidableMaximumDistance;
float collidableTileSize;
float collidableTileBorder;
uint32 collidableSeed;
float nonCollidableMinimumDistance;
float nonCollidableMaximumDistance;
float nonCollidableTileSize;
float nonCollidableTileBorder;
uint32 nonCollidableSeed;
float radialMinimumDistance;
float radialMaximumDistance;
float radialTileSize;
float radialTileBorder;
uint32 radialSeed;
float farRadialMinimumDistance;
float farRadialMaximumDistance;
float farRadialTileSize;
float farRadialTileBorder;
uint32 farRadialSeed;
bool legacyMap;
// ------------------------------------
const TerrainGenerator *terrainGenerator;
const BakedTerrain *bakedTerrain;
const PackedIntegerMap *staticCollidableFloraMap;
const PackedFixedPointMap *staticCollidableFloraHeightMap;
public:
WriterData();
};
void prepareWriterData(WriterData &writerData);
static void write (Iff& iff, const WriterData& data);
};
//===================================================================
#endif
@@ -0,0 +1,158 @@
//===================================================================
//
// SamplerProceduralTerrainAppearance.h
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_SamplerProceduralTerrainAppearance_h
#define INCLUDED_SamplerProceduralTerrainAppearance_h
//===================================================================
#include "sharedFoundation/MemoryBlockManagerMacros.h"
#include "sharedTerrain/ProceduralTerrainAppearance.h"
class Plane;
class MemoryBlockManager;
//===================================================================
class SamplerProceduralTerrainAppearanceTemplate;
class SamplerProceduralTerrainAppearance : public ProceduralTerrainAppearance
{
public:
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Chunk defines a chunk of terrain in the terrain system
//
class SamplerChunk : public ProceduralTerrainAppearance::Chunk
{
MEMORY_BLOCK_MANAGER_INTERFACE_WITHOUT_INSTALL;
protected:
// indexList is a list of triplets indexing the vertex positions used in each triangle of the chunk.
static ArrayList<int>* ms_indexList;
protected:
// vertexList is a list of 3D positions for the chunk's height poles. size is (numberOfHeightPoles-2)^2
ArrayList<Vector>* m_vertexList;
// planeList is a list of planes corresponding to the above triangles
ArrayList<Plane>* m_planeList;
time_t m_timeStamp;
private:
static void createIndexList (int numberOfTilesPerChunk, int actualNumberOfPoles);
private:
SamplerChunk ();
SamplerChunk (const SamplerChunk& rhs);
SamplerChunk& operator= (const SamplerChunk& rhs);
public:
static void install ();
static void remove ();
static bool compareTimestampsGreater(SamplerChunk const * lhs, SamplerChunk const * rhs);
public:
explicit SamplerChunk (ProceduralTerrainAppearance& proceduralTerrainAppearance);
virtual ~SamplerChunk ();
virtual bool getHeightAt (const Vector& worldPos, float* height) const;
virtual bool getHeightAt (const Vector& worldPos, float* height, Vector* normal) const;
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParameters, CollisionInfo & result) const;
virtual int getChunkMemorySize () const;
void create (const ProceduralTerrainAppearance::CreateChunkData& newCreateChunkData);
void writeChunkData (const char* filename) const;
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Cache;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public:
SamplerProceduralTerrainAppearance (SamplerProceduralTerrainAppearanceTemplate* appearanceTemplate);
virtual ~SamplerProceduralTerrainAppearance ();
virtual float alter (float time);
virtual void render () const;
virtual void writeChunkData (int chunkX, int chunkZ) const;
virtual int getTerrainType (const Vector& position_o) const;
virtual void invalidateRegion (const Rectangle2d& extent2d);
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParameters, CollisionInfo & result) const;
virtual bool collideForceChunkCreation (Vector const & start_o, Vector const & end_o, CollisionInfo & result);
virtual int getNumberOfChunks () const;
virtual bool hasHighLevelOfDetailTerrain (const Vector& position_o) const;
bool isStaticCollidableFloraChunk(const int x, const int z, const int chunkSize);
SamplerChunk *createChunk(const int x, const int z, const int chunkSize);
virtual void createChunk (int x, int z, int chunkSize, unsigned hasLargerNeighborFlags);
virtual void purgeChunks();
void createFlora (const Chunk* const chunk);
protected:
typedef stdmap<uint32, Chunk const *>::fwd ChunkMap;
typedef stdvector<Chunk const *>::fwd ChunkList;
typedef stdvector<SamplerChunk const *>::fwd SamplerChunkList;
typedef stdset<uint32>::fwd ChunkSet;
protected:
virtual void removeUnnecessaryChunk ();
virtual void addChunk (Chunk* chunk, int chunkSize);
virtual const Chunk* findChunk (int x, int z, int chunkSize) const;
virtual const Chunk* findFirstRenderableChunk (int x, int z) const;
virtual const Chunk* findAnyChunk () const;
virtual uint32 computeChunkMapKey (int x, int z) const;
virtual void prepareForDelete (Chunk const * chunk);
void generateBetween(Vector const & start_o, Vector const & end_o, ChunkList & chunkList);
bool collideChunkList(ChunkList const & chunkList, Vector const & start_o, Vector const & end_o, CollisionInfo & result) const;
protected:
SamplerProceduralTerrainAppearanceTemplate &terrainSamplerTemplate;
ChunkMap* const m_chunkMap;
private:
class CollisionChunkSorter;
private:
SamplerProceduralTerrainAppearance ();
SamplerProceduralTerrainAppearance (const SamplerProceduralTerrainAppearance&);
SamplerProceduralTerrainAppearance& operator= (const SamplerProceduralTerrainAppearance&);
private:
int m_chunkMapKeyOffset;
SamplerChunkList* const m_highUsedChunkList;
SamplerChunkList* const m_lowUsedChunkList;
SamplerChunkList* const m_unusedChunkList;
ChunkList* const m_invalidateChunkList;
};
//===================================================================
#endif
@@ -0,0 +1,501 @@
//===================================================================
//
// SamplerProceduralTerrainAppearanceTemplate.cpp
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/SamplerProceduralTerrainAppearanceTemplate.h"
#include "sharedTerrain/SamplerProceduralTerrainAppearance.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedUtility/PackedIntegerMap.h"
#include "sharedUtility/PackedFixedPointMap.h"
#include "sharedObject/AppearanceTemplateList.h"
#include "sharedTerrain/ConfigSharedTerrain.h"
#include "fileInterface/StdioFile.h"
#include "sharedFile/TreeFile.h"
#include <malloc.h>
#if defined(PLATFORM_LINUX)
#include <alloca.h>
#endif
//===================================================================
struct StaticFloraSampleFileHeader
{
char terrainName[64];
float floraTileWidthInMeters;
int numberOfFloraSampled;
};
struct StaticFloraSampleHeightPlaneHeader
{
int version;
float minHeight;
float maxHeight;
float scale;
int nibblesPerEntry;
};
struct CollidableFloraSampleFileHeader
{
uint32 type;
int version;
char terrainName[64];
float floraTileWidthInMeters;
int minFloraTileX;
int minFloraTileZ;
int maxFloraTileX;
int maxFloraTileZ;
int numberOfFloraSampled;
float minHeight;
float maxHeight;
};
//===================================================================
AppearanceTemplate* SamplerProceduralTerrainAppearanceTemplate::create (const char* filename, Iff* iff)
{
return new SamplerProceduralTerrainAppearanceTemplate (filename, iff);
}
//===================================================================
SamplerProceduralTerrainAppearanceTemplate::SamplerProceduralTerrainAppearanceTemplate (const char* filename, Iff* iff) :
ProceduralTerrainAppearanceTemplate (filename, iff, false, 0, 1, true),
m_staticCollidableFloraHeightMin(0),
m_staticCollidableFloraHeightMax(0),
m_staticCollidableFloraHeightSamples(0),
m_staticCollidableFloraSamples(0),
m_numberOfSampledFlora(0)
{
if (m_legacyMap)
{
_setSamplingParameters(true, 3, 3);
}
}
//-------------------------------------------------------------------
SamplerProceduralTerrainAppearanceTemplate::~SamplerProceduralTerrainAppearanceTemplate ()
{
delete [] m_staticCollidableFloraHeightSamples;
m_staticCollidableFloraHeightSamples=0;
delete [] m_staticCollidableFloraSamples;
m_staticCollidableFloraSamples=0;
}
//-------------------------------------------------------------------
Appearance* SamplerProceduralTerrainAppearanceTemplate::createAppearance () const
{
return new SamplerProceduralTerrainAppearance (const_cast<SamplerProceduralTerrainAppearanceTemplate *>(this));
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearanceTemplate::setMapsToSample(unsigned maps)
{
m_terrainGenerator->setMapsToSample(maps);
}
//-------------------------------------------------------------------
bool SamplerProceduralTerrainAppearanceTemplate::getFloraHeightSample(int key, float &o_height) const
{
if (!m_staticCollidableFloraHeightSamples)
{
o_height=0;
return false;
}
else
{
o_height = m_staticCollidableFloraHeightSamples[key];
return true;
}
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearanceTemplate::beginStaticCollidableFloraSampling()
{
m_staticCollidableFloraHeightMin = FLT_MAX;
m_staticCollidableFloraHeightMax = -FLT_MAX;
const int numElements = sqr(getMapWidthInFlora());
float *staticCollidableFloraHeightSamples = new float[numElements];
memset(staticCollidableFloraHeightSamples, 0, numElements*sizeof(*staticCollidableFloraHeightSamples));
m_staticCollidableFloraHeightSamples=staticCollidableFloraHeightSamples;
FloraGroup::Info *staticCollidableFloraSamples = new FloraGroup::Info[numElements];
memset(staticCollidableFloraSamples, 0, numElements*sizeof(*staticCollidableFloraSamples));
m_staticCollidableFloraSamples = staticCollidableFloraSamples;
m_numberOfSampledFlora=0;
}
//-------------------------------------------------------------------
bool SamplerProceduralTerrainAppearanceTemplate::loadStaticCollidableFloraFile(const char *i_filename)
{
if (!m_staticCollidableFloraHeightSamples)
{
beginStaticCollidableFloraSampling();
}
// -------------------------------------------------------
AbstractFile *mapFile = TreeFile::open(i_filename, AbstractFile::PriorityData, true);
if (!mapFile)
{
REPORT_LOG_PRINT(true, ("Could not open sample file %s\n", i_filename));
return false;
}
// -------------------------------------------------------
CollidableFloraSampleFileHeader fileHeader;
mapFile->read(&fileHeader, sizeof(fileHeader));
if (fileHeader.type!=TGM_floraStaticCollidable)
{
return false;
}
if (fileHeader.version!=1)
{
return false;
}
if (fileHeader.floraTileWidthInMeters!=getFloraTileWidthInMeters())
{
return false;
}
// -------------------------------------------------------
int xWidth = fileHeader.maxFloraTileX - fileHeader.minFloraTileX;
int z;
for (z=fileHeader.minFloraTileZ;z<fileHeader.maxFloraTileZ;z++)
{
FloraGroup::Info *row = m_staticCollidableFloraSamples + z*getMapWidthInFlora();
mapFile->read(row+fileHeader.minFloraTileX, xWidth*sizeof(*row));
}
for (z=fileHeader.minFloraTileZ;z<fileHeader.maxFloraTileZ;z++)
{
float *row = m_staticCollidableFloraHeightSamples + z*getMapWidthInFlora();
mapFile->read(row+fileHeader.minFloraTileX, xWidth*sizeof(*row));
}
// -------------------------------------------------------
delete mapFile;
return true;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearanceTemplate::setFloraTileSample(int key, const FloraGroup::Info &i_data, float height)
{
FloraGroup::Info &info = m_staticCollidableFloraSamples[key];
if (!info.getFamilyId())
{
info=i_data;
if (i_data.getFamilyId())
{
if (height>m_staticCollidableFloraHeightMax)
{
m_staticCollidableFloraHeightMax=height;
}
if (height<m_staticCollidableFloraHeightMin)
{
m_staticCollidableFloraHeightMin=height;
}
m_staticCollidableFloraHeightSamples[key]=height;
m_numberOfSampledFlora++;
}
}
}
//-------------------------------------------------------------------
static bool _extractPlanetName(char *o_buffer, const char *i_filename)
{
o_buffer[0]=0;
if (!i_filename || !*i_filename || i_filename[0]=='.')
{
return false;
}
const char *iter;
iter=strrchr(i_filename, 0);
while (iter>i_filename)
{
if ( iter[-1]=='/'
|| iter[-1]=='\\'
|| iter[-1]==':'
)
{
break;
}
iter--;
}
// iter should now point to beginning of planet name
char *oiter=o_buffer;
while (*iter && *iter!='.')
{
*oiter++=*iter++;
}
*oiter++=0;
return true;
}
//-------------------------------------------------------------------
bool SamplerProceduralTerrainAppearanceTemplate::writeStaticCollidableFloraFile(const char *i_filename, int tileBounds[4]) const
{
if (!m_samplingMode)
{
return false;
}
AbstractFile *of = StdioFileFactory().createFile(i_filename, "wb");
if (!of)
{
return false;
}
char planetname[256];
strcpy(planetname, "terrain\\");
if (!_extractPlanetName(strrchr(planetname, 0), i_filename))
{
return false;
}
strcat(planetname, ".trn");
// --------------------------------------------
CollidableFloraSampleFileHeader fileHeader;
Zero(fileHeader);
fileHeader.type=TGM_floraStaticCollidable;
fileHeader.version=1;
strcpy(fileHeader.terrainName, planetname);
fileHeader.floraTileWidthInMeters = getFloraTileWidthInMeters();
fileHeader.minFloraTileX = tileBounds[0];
fileHeader.minFloraTileZ = tileBounds[1];
fileHeader.maxFloraTileX = tileBounds[2];
fileHeader.maxFloraTileZ = tileBounds[3];
fileHeader.numberOfFloraSampled=0;
fileHeader.minHeight = FLT_MAX;
fileHeader.maxHeight = -FLT_MAX;
// --------------------------------------------
int x, z;
for (z=tileBounds[1];z<tileBounds[3];z++)
{
const float *heightRow = m_staticCollidableFloraHeightSamples + z*getMapWidthInFlora();
for (x=tileBounds[0];x<tileBounds[2];x++)
{
if (heightRow[x]<fileHeader.minHeight)
{
fileHeader.minHeight=heightRow[x];
}
if (heightRow[x]>fileHeader.maxHeight)
{
fileHeader.maxHeight=heightRow[x];
}
}
const FloraGroup::Info *infoRow = m_staticCollidableFloraSamples + z*getMapWidthInFlora();
for (x=tileBounds[0];x<tileBounds[2];x++)
{
FloraGroup::Info fgi = infoRow[x];
if (fgi.getFamilyId())
{
fileHeader.numberOfFloraSampled++;
}
}
}
// --------------------------------------------
of->write(sizeof(fileHeader), &fileHeader);
int xWidth = tileBounds[2] - tileBounds[0];
for (z=tileBounds[1];z<tileBounds[3];z++)
{
const FloraGroup::Info *row = m_staticCollidableFloraSamples + z*getMapWidthInFlora();
of->write(xWidth*sizeof(*row), row+tileBounds[0]);
}
for (z=tileBounds[1];z<tileBounds[3];z++)
{
const float *row = m_staticCollidableFloraHeightSamples + z*getMapWidthInFlora();
of->write(xWidth*sizeof(*row), row+tileBounds[0]);
}
of->close();
delete of;
// --------------------------------------------------------
return true;
}
//-------------------------------------------------------------------
bool SamplerProceduralTerrainAppearanceTemplate::writeOldStaticCollidableFloraFile(const char *i_filename) const
{
if (!m_samplingMode)
{
return false;
}
AbstractFile *of = StdioFileFactory().createFile(i_filename, "wb");
if (!of)
{
return false;
}
char planetname[256];
strcpy(planetname, "terrain\\");
if (!_extractPlanetName(strrchr(planetname, 0), i_filename))
{
return false;
}
strcat(planetname, ".trn");
StaticFloraSampleFileHeader fileHeader;
Zero(fileHeader);
strcpy(fileHeader.terrainName, planetname);
fileHeader.floraTileWidthInMeters = getFloraTileWidthInMeters();
fileHeader.numberOfFloraSampled=m_numberOfSampledFlora;
of->write(sizeof(fileHeader), &fileHeader);
of->write(sqr(getMapWidthInFlora())*sizeof(*m_staticCollidableFloraSamples), m_staticCollidableFloraSamples);
of->close();
delete of;
// --------------------------------------------------------
char buffer[1024];
strcpy(buffer, i_filename);
strcat(buffer, "2");
writeOldStaticCollidableFloraHeightFile(buffer);
// --------------------------------------------------------
return true;
}
//-------------------------------------------------------------------
bool SamplerProceduralTerrainAppearanceTemplate::writeOldStaticCollidableFloraHeightFile(const char *i_filename) const
{
if (!m_samplingMode)
{
return false;
}
AbstractFile *of = StdioFileFactory().createFile(i_filename, "wb");
if (!of)
{
return false;
}
char planetname[256];
strcpy(planetname, "terrain\\");
if (!_extractPlanetName(strrchr(planetname, 0), i_filename))
{
return false;
}
strcat(planetname, ".trn");
StaticFloraSampleHeightPlaneHeader fileHeader;
Zero(fileHeader);
//strcpy(fileHeader.terrainName, planetname);
fileHeader.version = 1;
fileHeader.minHeight = m_staticCollidableFloraHeightMin;
fileHeader.maxHeight = m_staticCollidableFloraHeightMax;
fileHeader.scale = 1.0f / 50.0f;
fileHeader.nibblesPerEntry = 8;
of->write(sizeof(fileHeader), &fileHeader);
size_t heightSize = sqr(getMapWidthInFlora());
of->write(heightSize*sizeof(*m_staticCollidableFloraHeightSamples), m_staticCollidableFloraHeightSamples);
of->close();
delete of;
return true;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearanceTemplate::commitStaticCollidableFloraSamples(int *tileBounds)
{
const int mapWidthInFlora = getMapWidthInFlora();
if (tileBounds)
{
int x, z;
// initialize everything outside the bounds with the original data.
const int xstart = (tileBounds) ? clamp(0, tileBounds[0], mapWidthInFlora) : 0;
const int zstart = (tileBounds) ? clamp(0, tileBounds[1], mapWidthInFlora) : 0;
const int xstop = (tileBounds) ? clamp(0, tileBounds[2], mapWidthInFlora) : mapWidthInFlora;
const int zstop = (tileBounds) ? clamp(0, tileBounds[3], mapWidthInFlora) : mapWidthInFlora;
for (z=0;z<mapWidthInFlora;z++)
{
if (z>=zstart && z<zstop)
{
continue;
}
for (x=0;x<xstart;x++)
{
int familyId = getStaticCollidableFloraFamily(x, z);
float height = getStaticCollidableFloraHeight(x, z);
const int index = z*mapWidthInFlora + x;
m_staticCollidableFloraSamples[index].setFamilyId(familyId);
m_staticCollidableFloraHeightSamples[index]=height;
}
for (x=xstop;x<mapWidthInFlora;x++)
{
int familyId = getStaticCollidableFloraFamily(x, z);
float height = getStaticCollidableFloraHeight(x, z);
const int index = z*mapWidthInFlora + x;
m_staticCollidableFloraSamples[index].setFamilyId(familyId);
m_staticCollidableFloraHeightSamples[index]=height;
}
}
}
// --------------------------------------------------------
_setStaticCollidableFloraInfo(m_staticCollidableFloraSamples, m_staticCollidableFloraHeightSamples);
}
//-------------------------------------------------------------------
//===================================================================
@@ -0,0 +1,70 @@
//===================================================================
//
// SamplerProceduralTerrainAppearanceTemplate.h
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_SamplerProceduralTerrainAppearanceTemplate_h
#define INCLUDED_SamplerProceduralTerrainAppearanceTemplate_h
//===================================================================
#include "sharedTerrain/ProceduralTerrainAppearanceTemplate.h"
class Iff;
//===================================================================
class SamplerProceduralTerrainAppearanceTemplate : public ProceduralTerrainAppearanceTemplate
{
public:
static AppearanceTemplate* create (const char* filename, Iff* iff);
public:
SamplerProceduralTerrainAppearanceTemplate (const char* filename, Iff* iff);
virtual ~SamplerProceduralTerrainAppearanceTemplate ();
void setMapsToSample(unsigned maps);
virtual Appearance* createAppearance () const;
int getNumberOfSampledFlora() const { return m_numberOfSampledFlora; }
void setFloraTileSample(int key, const FloraGroup::Info &i_data, float height);
bool getFloraHeightSample(int key, float &o_height) const;
void beginStaticCollidableFloraSampling();
bool loadStaticCollidableFloraFile(const char *i_filename);
bool writeStaticCollidableFloraFile(const char *i_filename, int tileBounds[4]) const;
bool writeOldStaticCollidableFloraFile(const char *i_filename) const;
bool writeOldStaticCollidableFloraHeightFile(const char *i_filename) const;
void commitStaticCollidableFloraSamples(int *tileBounds); // commit current sample data to base appearance template
const FloraGroup::Info *getStaticCollidableFloraSamples() const { return m_staticCollidableFloraSamples; }
const PackedIntegerMap *getStaticCollidableFloraMap() const { return m_staticCollidableFloraMap; }
const PackedFixedPointMap *getStaticCollidableFloraHeightMap() const { return m_staticCollidableFloraHeightMap; }
private:
SamplerProceduralTerrainAppearanceTemplate ();
SamplerProceduralTerrainAppearanceTemplate (const SamplerProceduralTerrainAppearanceTemplate&);
SamplerProceduralTerrainAppearanceTemplate& operator= (const SamplerProceduralTerrainAppearanceTemplate&);
// ----------------------------------
float m_staticCollidableFloraHeightMin;
float m_staticCollidableFloraHeightMax;
float *m_staticCollidableFloraHeightSamples;
FloraGroup::Info *m_staticCollidableFloraSamples;
int m_numberOfSampledFlora;
// ----------------------------------
};
//===================================================================
#endif
@@ -0,0 +1,392 @@
//==================================================================
//
// SamplerProceduralTerrainAppearance_Cache.cpp
// asommers
//
// copyright 2002, sony online entertainment
//
//==================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/SamplerProceduralTerrainAppearance_Cache.h"
#include "sharedDebug/DebugFlags.h"
#include "sharedFoundation/PointerDeleter.h"
#include "sharedMath/Plane.h"
#include "sharedTerrain/ConfigSharedTerrain.h"
#include <algorithm>
#include <vector>
//==================================================================
namespace SamplerProceduralTerrainAppearanceCacheNamespace
{
typedef std::vector<ArrayList<Vector>*> VertexListList;
typedef std::vector<ArrayList<Plane>*> PlaneListList;
typedef std::vector<Array2d<ShaderGroup::Info>*> ShaderGroupList;
typedef std::vector<Array2d<FloraGroup::Info>*> FloraGroupList;
typedef std::vector<Array2d<bool>*> PassableMapList;
bool ms_installed;
uint ms_preloadSize = 2048;
VertexListList* ms_vertexListList;
PlaneListList* ms_planeListList;
ShaderGroupList* ms_shaderMapList;
FloraGroupList* ms_floraMapList;
PassableMapList* ms_passableMapList;
#ifdef _DEBUG
bool ms_debugReport;
#endif
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void debugDump ();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ArrayList<Vector>* localCreateVertexList (const int size)
{
ArrayList<Vector>* const vertexList = new ArrayList<Vector>;
vertexList->preallocate (size, true);
return vertexList;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ArrayList<Plane>* localCreatePlaneList (const int size)
{
ArrayList<Plane>* const planeList = new ArrayList<Plane>;
planeList->preallocate (size, true);
return planeList;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Array2d<ShaderGroup::Info>* localCreateShaderMap (const int width, const int height)
{
Array2d<ShaderGroup::Info>* const map = new Array2d<ShaderGroup::Info>;
map->allocate (width, height);
return map;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Array2d<FloraGroup::Info>* localCreateFloraMap (const int width, const int height)
{
Array2d<FloraGroup::Info>* const map = new Array2d<FloraGroup::Info>;
map->allocate (width, height);
return map;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Array2d<bool>* localCreatePassableMap (const int width, const int height)
{
Array2d<bool>* const map = new Array2d<bool>;
map->allocate (width, height);
return map;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}
using namespace SamplerProceduralTerrainAppearanceCacheNamespace;
//==================================================================
void SamplerProceduralTerrainAppearance::Cache::install ()
{
DEBUG_REPORT_LOG_PRINT (ConfigSharedTerrain::getDebugReportInstall (), ("SamplerProceduralTerrainAppearance::Cache::install\n"));
DEBUG_FATAL (ms_installed, ("already installed"));
ms_installed = true;
ms_preloadSize = static_cast<uint> (ConfigSharedTerrain::getMaximumNumberOfChunksAllowed ());
//-- can't precreate maps because we don't know what size they will be
ms_vertexListList = new VertexListList;
ms_planeListList = new PlaneListList;
ms_shaderMapList = new ShaderGroupList;
ms_floraMapList = new FloraGroupList;
ms_passableMapList = new PassableMapList;
#ifdef _DEBUG
DebugFlags::registerFlag (SamplerProceduralTerrainAppearanceCacheNamespace::ms_debugReport, "SharedTerrain", "reportSamplerProceduralTerrainAppearanceCache", SamplerProceduralTerrainAppearanceCacheNamespace::debugDump);
#endif
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::remove ()
{
DEBUG_FATAL (!ms_installed, ("not installed"));
ms_installed = false;
//-- delete non-array lists
#define DELETE_SPECIFIC_LIST(a) { \
DEBUG_REPORT_LOG_PRINT (ConfigSharedTerrain::getDebugReportLogPrint (), ("Terrain Cache %sList = %i\n", #a, ms_ ## a ## List->size ())); \
std::for_each (ms_ ## a ## List->begin (), ms_ ## a ## List->end (), PointerDeleter ()); \
delete ms_ ## a ## List; \
ms_ ## a ## List = 0; \
}
DELETE_SPECIFIC_LIST (vertexList);
DELETE_SPECIFIC_LIST (planeList);
DELETE_SPECIFIC_LIST (shaderMap);
DELETE_SPECIFIC_LIST (floraMap);
DELETE_SPECIFIC_LIST (passableMap);
#ifdef _DEBUG
DebugFlags::unregisterFlag (SamplerProceduralTerrainAppearanceCacheNamespace::ms_debugReport);
#endif
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::warm (const int vertexListSize, const int planeListSize, const int mapSize)
{
NOT_NULL (ms_vertexListList);
ms_vertexListList->reserve (ms_preloadSize);
NOT_NULL (ms_planeListList);
ms_planeListList->reserve (ms_preloadSize);
NOT_NULL (ms_shaderMapList);
ms_shaderMapList->reserve (ms_preloadSize);
NOT_NULL (ms_floraMapList);
ms_floraMapList->reserve (ms_preloadSize);
NOT_NULL (ms_passableMapList);
ms_passableMapList->reserve (ms_preloadSize);
uint i;
for (i = 0; i < ms_preloadSize; ++i)
{
ms_vertexListList->push_back (localCreateVertexList (vertexListSize));
ms_planeListList->push_back (localCreatePlaneList (planeListSize));
ms_shaderMapList->push_back (localCreateShaderMap (mapSize, mapSize));
ms_floraMapList->push_back (localCreateFloraMap (mapSize, mapSize));
ms_passableMapList->push_back (localCreatePassableMap (mapSize, mapSize));
}
}
//-------------------------------------------------------------------
ArrayList<Vector>* SamplerProceduralTerrainAppearance::Cache::createVertexList (const int size)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_vertexListList);
ArrayList<Vector>* vertexList = 0;
//-- just take one off the list
if (!ms_vertexListList->empty ())
{
vertexList = ms_vertexListList->back ();
ms_vertexListList->pop_back ();
}
else
{
//-- create one
vertexList = localCreateVertexList (size);
}
NOT_NULL (vertexList);
return vertexList;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::destroyVertexList (ArrayList<Vector>* const vertexList)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_vertexListList);
if (vertexList)
ms_vertexListList->push_back (vertexList);
}
//-------------------------------------------------------------------
ArrayList<Plane>* SamplerProceduralTerrainAppearance::Cache::createPlaneList (const int size)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_planeListList);
ArrayList<Plane>* planeList = 0;
//-- just take one off the list
if (!ms_planeListList->empty ())
{
planeList = ms_planeListList->back ();
ms_planeListList->pop_back ();
}
else
{
//-- create one
planeList = localCreatePlaneList (size);
}
NOT_NULL (planeList);
return planeList;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::destroyPlaneList (ArrayList<Plane>* const planeList)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_planeListList);
if (planeList)
ms_planeListList->push_back (planeList);
}
//-------------------------------------------------------------------
Array2d<ShaderGroup::Info>* SamplerProceduralTerrainAppearance::Cache::createShaderMap (int width, int height)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_shaderMapList);
Array2d<ShaderGroup::Info>* map = 0;
//-- just take one off the list
if (!ms_shaderMapList->empty ())
{
map = ms_shaderMapList->back ();
ms_shaderMapList->pop_back ();
}
else
{
//-- create one
map = localCreateShaderMap (width, height);
}
NOT_NULL (map);
DEBUG_FATAL (width != map->getWidth () && height != map->getHeight (), ("SamplerProceduralTerrainAppearance::Cache - cached map of wrong size"));
return map;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::destroyShaderMap (Array2d<ShaderGroup::Info>* map)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_shaderMapList);
if (map)
ms_shaderMapList->push_back (map);
}
//-------------------------------------------------------------------
Array2d<FloraGroup::Info>* SamplerProceduralTerrainAppearance::Cache::createFloraMap (int width, int height)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_floraMapList);
Array2d<FloraGroup::Info>* map = 0;
//-- just take one off the list
if (!ms_floraMapList->empty ())
{
map = ms_floraMapList->back ();
ms_floraMapList->pop_back ();
}
else
{
//-- create one
map = localCreateFloraMap (width, height);
}
NOT_NULL (map);
DEBUG_FATAL (width != map->getWidth () && height != map->getHeight (), ("SamplerProceduralTerrainAppearance::Cache - cached map of wrong size"));
return map;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::destroyFloraMap (Array2d<FloraGroup::Info>* map)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_floraMapList);
if (map)
ms_floraMapList->push_back (map);
}
//----------------------------------------------------------------------
Array2d<bool>* SamplerProceduralTerrainAppearance::Cache::createPassableMap (int width, int height)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_passableMapList);
Array2d<bool>* map = 0;
//-- just take one off the list
if (!ms_passableMapList->empty ())
{
map = ms_passableMapList->back ();
ms_passableMapList->pop_back ();
}
else
{
//-- create one
map = localCreatePassableMap (width, height);
}
NOT_NULL (map);
DEBUG_FATAL (width != map->getWidth () && height != map->getHeight (), ("SamplerProceduralTerrainAppearance::Cache - cached map of wrong size"));
return map;
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearance::Cache::destroyPassableMap (Array2d<bool>* map)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_passableMapList);
if (map)
ms_passableMapList->push_back (map);
}
//-------------------------------------------------------------------
void SamplerProceduralTerrainAppearanceCacheNamespace::debugDump ()
{
#ifdef _DEBUG
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_vertexListList);
NOT_NULL (ms_planeListList);
NOT_NULL (ms_shaderMapList);
NOT_NULL (ms_floraMapList);
NOT_NULL (ms_passableMapList);
DEBUG_REPORT_PRINT (ms_debugReport, ("vertexListList size = %i\n", ms_vertexListList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("planeListList size = %i\n", ms_planeListList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("shaderMapList size = %i\n", ms_shaderMapList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("floraMapList size = %i\n", ms_floraMapList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("passableMapList size = %i\n", ms_passableMapList->size ()));
#endif
}
//==================================================================
@@ -0,0 +1,53 @@
//==================================================================
//
// SamplerProceduralTerrainAppearance_Cache.h
// asommers
//
// copyright 2002, sony online entertainment
//
//==================================================================
#ifndef INCLUDED_SamplerProceduralTerrainAppearance_Cache_H
#define INCLUDED_SamplerProceduralTerrainAppearance_Cache_H
//==================================================================
#include "SamplerProceduralTerrainAppearance.h"
//==================================================================
class SamplerProceduralTerrainAppearance::Cache
{
public:
static void install ();
static void remove ();
static void warm (int vertexListSize, int planeListSize, int mapSize);
static ArrayList<Vector>* createVertexList (int size);
static void destroyVertexList (ArrayList<Vector>* vertexList);
static ArrayList<Plane>* createPlaneList (int size);
static void destroyPlaneList (ArrayList<Plane>* planeList);
static Array2d<ShaderGroup::Info>* createShaderMap (int width, int height);
static void destroyShaderMap (Array2d<ShaderGroup::Info>* map);
static Array2d<FloraGroup::Info>* createFloraMap (int width, int height);
static void destroyFloraMap (Array2d<FloraGroup::Info>* map);
static Array2d<bool>* createPassableMap (int width, int height);
static void destroyPassableMap (Array2d<bool>* map);
private:
Cache ();
~Cache ();
Cache (const Cache&);
Cache& operator= (const Cache&);
};
//==================================================================
#endif
@@ -0,0 +1,161 @@
//===================================================================
//
// ServerProceduralTerrainAppearance.h
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_ServerProceduralTerrainAppearance_h
#define INCLUDED_ServerProceduralTerrainAppearance_h
//===================================================================
#include "sharedFoundation/MemoryBlockManagerMacros.h"
#include "sharedMath/SphereTree.h"
#include "sharedTerrain/ProceduralTerrainAppearance.h"
class Plane;
class MemoryBlockManager;
//===================================================================
class ServerProceduralTerrainAppearance : public ProceduralTerrainAppearance
{
public:
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Chunk defines a chunk of terrain in the terrain system
//
class ServerChunk : public ProceduralTerrainAppearance::Chunk
{
MEMORY_BLOCK_MANAGER_INTERFACE_WITHOUT_INSTALL;
protected:
// indexList is a list of triplets indexing the vertex positions used in each triangle of the chunk.
static ArrayList<int>* ms_indexList;
protected:
// vertexList is a list of 3D positions for the chunk's height poles. size is (numberOfHeightPoles-2)^2
ArrayList<Vector>* m_vertexList;
// planeList is a list of planes corresponding to the above triangles
ArrayList<Plane>* m_planeList;
time_t m_timeStamp;
private:
static void createIndexList (int numberOfTilesPerChunk, int actualNumberOfPoles);
private:
ServerChunk ();
ServerChunk (const ServerChunk& rhs);
ServerChunk& operator= (const ServerChunk& rhs);
public:
static void install ();
static void remove ();
static bool compareTimestampsGreater(ServerChunk const * lhs, ServerChunk const * rhs);
public:
explicit ServerChunk (ProceduralTerrainAppearance& proceduralTerrainAppearance);
virtual ~ServerChunk ();
virtual bool getHeightAt (const Vector& worldPos, float* height) const;
virtual bool getHeightAt (const Vector& worldPos, float* height, Vector* normal) const;
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParameters, CollisionInfo & result) const;
virtual int getChunkMemorySize () const;
void create (const ProceduralTerrainAppearance::CreateChunkData& newCreateChunkData);
void writeChunkData (const char* filename) const;
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Cache;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public:
ServerProceduralTerrainAppearance (const ProceduralTerrainAppearanceTemplate* appearanceTemplate);
virtual ~ServerProceduralTerrainAppearance ();
virtual float alter (float time);
virtual void render () const;
virtual void writeChunkData (int chunkX, int chunkZ) const;
virtual int getTerrainType (const Vector& position_o) const;
virtual void invalidateRegion (const Rectangle2d& extent2d);
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParameters, CollisionInfo & result) const;
virtual bool collideForceChunkCreation (Vector const & start_o, Vector const & end_o, CollisionInfo & result);
virtual int getNumberOfChunks () const;
virtual bool hasHighLevelOfDetailTerrain (const Vector& position_o) const;
virtual void purgeChunks();
protected:
typedef stdmap<uint32, Chunk const *>::fwd ChunkMap;
typedef stdvector<Chunk const *>::fwd ChunkList;
typedef stdvector<ServerChunk const *>::fwd ServerChunkList;
typedef stdset<uint32>::fwd ChunkSet;
protected:
virtual void createChunk (int x, int z, int chunkSize, unsigned hasLargerNeighborFlags);
virtual void removeUnnecessaryChunk ();
virtual void addChunk (Chunk* chunk, int chunkSize);
virtual const Chunk* findChunk (int x, int z, int chunkSize) const;
virtual const Chunk* findFirstRenderableChunk (int x, int z) const;
virtual const Chunk* findAnyChunk () const;
virtual uint32 computeChunkMapKey (int x, int z) const;
virtual void prepareForDelete (Chunk const * chunk);
void generateBetween(Vector const & start_o, Vector const & end_o, ChunkList & chunkList);
bool collideChunkList(ChunkList const & chunkList, Vector const & start_o, Vector const & end_o, CollisionInfo & result) const;
protected:
ChunkMap* const m_chunkMap;
private:
class ChunkSphereExtentAccessor: public BaseSphereTreeAccessor<Chunk const *, ChunkSphereExtentAccessor>
{
public:
static Sphere const getExtent (Chunk const * chunk);
static char const * getDebugName (Chunk const * chunk);
};
class CollisionChunkSorter;
private:
ServerProceduralTerrainAppearance ();
ServerProceduralTerrainAppearance (const ServerProceduralTerrainAppearance&);
ServerProceduralTerrainAppearance& operator= (const ServerProceduralTerrainAppearance&);
private:
int m_chunkMapKeyOffset;
ServerChunkList* const m_highUsedChunkList;
ServerChunkList* const m_lowUsedChunkList;
ServerChunkList* const m_unusedChunkList;
ChunkList* const m_invalidateChunkList;
ChunkSet* const m_chunksCreatedThisFrame;
SphereTree<Chunk const *, ChunkSphereExtentAccessor> m_sphereTree;
};
//===================================================================
#endif
@@ -0,0 +1,78 @@
//===================================================================
//
// ServerProceduralTerrainAppearanceTemplate.cpp
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/ServerProceduralTerrainAppearanceTemplate.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedObject/AppearanceTemplateList.h"
#include "sharedTerrain/ConfigSharedTerrain.h"
#include "sharedTerrain/ServerProceduralTerrainAppearance.h"
//===================================================================
void ServerProceduralTerrainAppearanceTemplate::install ()
{
DEBUG_REPORT_LOG_PRINT (ConfigSharedTerrain::getDebugReportInstall (), ("ServerProceduralTerrainAppearanceTemplate::install\n"));
AppearanceTemplateList::assignBinding (TAG (M,P,T,A), ServerProceduralTerrainAppearanceTemplate::create);
AppearanceTemplateList::assignBinding (TAG (P,T,A,T), ServerProceduralTerrainAppearanceTemplate::create);
ExitChain::add (remove, "ServerProceduralTerrainAppearanceTemplate::remove");
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearanceTemplate::remove ()
{
AppearanceTemplateList::removeBinding (TAG (M,P,T,A));
AppearanceTemplateList::removeBinding (TAG (P,T,A,T));
}
//-------------------------------------------------------------------
AppearanceTemplate* ServerProceduralTerrainAppearanceTemplate::create (const char* filename, Iff* iff)
{
return new ServerProceduralTerrainAppearanceTemplate (filename, iff);
}
//===================================================================
ServerProceduralTerrainAppearanceTemplate::ServerProceduralTerrainAppearanceTemplate (const char* filename, Iff* iff) :
ProceduralTerrainAppearanceTemplate (filename, iff, false, 0, 2)
{
unsigned mapsToSample =
TGM_vertexPosition
| TGM_shader
| TGM_passable
| TGM_exclude
;
if (getLegacyMode())
{
mapsToSample|=TGM_floraStaticCollidable;
}
m_terrainGenerator->setMapsToSample(mapsToSample);
}
//-------------------------------------------------------------------
ServerProceduralTerrainAppearanceTemplate::~ServerProceduralTerrainAppearanceTemplate ()
{
}
//-------------------------------------------------------------------
Appearance* ServerProceduralTerrainAppearanceTemplate::createAppearance () const
{
return new ServerProceduralTerrainAppearance (this);
}
//===================================================================
@@ -0,0 +1,50 @@
//===================================================================
//
// ServerProceduralTerrainAppearanceTemplate.h
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_ServerProceduralTerrainAppearanceTemplate_h
#define INCLUDED_ServerProceduralTerrainAppearanceTemplate_h
//===================================================================
#include "sharedTerrain/ProceduralTerrainAppearanceTemplate.h"
class Iff;
//===================================================================
class ServerProceduralTerrainAppearanceTemplate : public ProceduralTerrainAppearanceTemplate
{
public:
static void install ();
static AppearanceTemplate* create (const char* filename, Iff* iff);
public:
ServerProceduralTerrainAppearanceTemplate (const char* filename, Iff* iff);
virtual ~ServerProceduralTerrainAppearanceTemplate ();
virtual Appearance* createAppearance () const;
private:
static void remove ();
private:
ServerProceduralTerrainAppearanceTemplate ();
ServerProceduralTerrainAppearanceTemplate (const ServerProceduralTerrainAppearanceTemplate&);
ServerProceduralTerrainAppearanceTemplate& operator= (const ServerProceduralTerrainAppearanceTemplate&);
};
//===================================================================
#endif
@@ -0,0 +1,334 @@
//==================================================================
//
// ServerProceduralTerrainAppearance_Cache.cpp
// asommers
//
// copyright 2002, sony online entertainment
//
//==================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/ServerProceduralTerrainAppearance_Cache.h"
#include "sharedDebug/DebugFlags.h"
#include "sharedFoundation/PointerDeleter.h"
#include "sharedMath/Plane.h"
#include "sharedTerrain/ConfigSharedTerrain.h"
#include <algorithm>
#include <vector>
//==================================================================
namespace ServerProceduralTerrainAppearanceCacheNamespace
{
typedef std::vector<ArrayList<Vector>*> VertexListList;
typedef std::vector<ArrayList<Plane>*> PlaneListList;
typedef std::vector<Array2d<ShaderGroup::Info>*> ShaderGroupList;
typedef std::vector<Array2d<FloraGroup::Info>*> FloraGroupList;
bool ms_installed;
uint ms_preloadSize = 2048;
VertexListList* ms_vertexListList;
PlaneListList* ms_planeListList;
ShaderGroupList* ms_shaderMapList;
FloraGroupList* ms_floraMapList;
#ifdef _DEBUG
bool ms_debugReport;
#endif
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void debugDump ();
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ArrayList<Vector>* localCreateVertexList (const int size)
{
ArrayList<Vector>* const vertexList = new ArrayList<Vector>;
vertexList->preallocate (size, true);
return vertexList;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ArrayList<Plane>* localCreatePlaneList (const int size)
{
ArrayList<Plane>* const planeList = new ArrayList<Plane>;
planeList->preallocate (size, true);
return planeList;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Array2d<ShaderGroup::Info>* localCreateShaderMap (const int width, const int height)
{
Array2d<ShaderGroup::Info>* const map = new Array2d<ShaderGroup::Info>;
map->allocate (width, height);
return map;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Array2d<FloraGroup::Info>* localCreateFloraMap (const int width, const int height)
{
Array2d<FloraGroup::Info>* const map = new Array2d<FloraGroup::Info>;
map->allocate (width, height);
return map;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}
using namespace ServerProceduralTerrainAppearanceCacheNamespace;
//==================================================================
void ServerProceduralTerrainAppearance::Cache::install ()
{
DEBUG_REPORT_LOG_PRINT (ConfigSharedTerrain::getDebugReportInstall (), ("ServerProceduralTerrainAppearance::Cache::install\n"));
DEBUG_FATAL (ms_installed, ("already installed"));
ms_installed = true;
ms_preloadSize = static_cast<uint> (ConfigSharedTerrain::getMaximumNumberOfChunksAllowed ());
//-- can't precreate maps because we don't know what size they will be
ms_vertexListList = new VertexListList;
ms_planeListList = new PlaneListList;
ms_shaderMapList = new ShaderGroupList;
ms_floraMapList = new FloraGroupList;
#ifdef _DEBUG
DebugFlags::registerFlag (ServerProceduralTerrainAppearanceCacheNamespace::ms_debugReport, "SharedTerrain", "reportServerProceduralTerrainAppearanceCache", ServerProceduralTerrainAppearanceCacheNamespace::debugDump);
#endif
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearance::Cache::remove ()
{
DEBUG_FATAL (!ms_installed, ("not installed"));
ms_installed = false;
//-- delete non-array lists
#define DELETE_SPECIFIC_LIST(a) { \
DEBUG_REPORT_LOG_PRINT (ConfigSharedTerrain::getDebugReportLogPrint (), ("Terrain Cache %sList = %i\n", #a, ms_ ## a ## List->size ())); \
std::for_each (ms_ ## a ## List->begin (), ms_ ## a ## List->end (), PointerDeleter ()); \
delete ms_ ## a ## List; \
ms_ ## a ## List = 0; \
}
DELETE_SPECIFIC_LIST (vertexList);
DELETE_SPECIFIC_LIST (planeList);
DELETE_SPECIFIC_LIST (shaderMap);
DELETE_SPECIFIC_LIST (floraMap);
#ifdef _DEBUG
DebugFlags::unregisterFlag (ServerProceduralTerrainAppearanceCacheNamespace::ms_debugReport);
#endif
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearance::Cache::warm (const int vertexListSize, const int planeListSize, const int mapSize)
{
NOT_NULL (ms_vertexListList);
ms_vertexListList->reserve (ms_preloadSize);
NOT_NULL (ms_planeListList);
ms_planeListList->reserve (ms_preloadSize);
NOT_NULL (ms_shaderMapList);
ms_shaderMapList->reserve (ms_preloadSize);
NOT_NULL (ms_floraMapList);
ms_floraMapList->reserve (ms_preloadSize);
uint i;
for (i = 0; i < ms_preloadSize; ++i)
{
ms_vertexListList->push_back (localCreateVertexList (vertexListSize));
ms_planeListList->push_back (localCreatePlaneList (planeListSize));
ms_shaderMapList->push_back (localCreateShaderMap (mapSize, mapSize));
ms_floraMapList->push_back (localCreateFloraMap (mapSize, mapSize));
}
}
//-------------------------------------------------------------------
ArrayList<Vector>* ServerProceduralTerrainAppearance::Cache::createVertexList (const int size)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_vertexListList);
ArrayList<Vector>* vertexList = 0;
//-- just take one off the list
if (!ms_vertexListList->empty ())
{
vertexList = ms_vertexListList->back ();
ms_vertexListList->pop_back ();
}
else
{
//-- create one
vertexList = localCreateVertexList (size);
}
NOT_NULL (vertexList);
return vertexList;
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearance::Cache::destroyVertexList (ArrayList<Vector>* const vertexList)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_vertexListList);
if (vertexList)
ms_vertexListList->push_back (vertexList);
}
//-------------------------------------------------------------------
ArrayList<Plane>* ServerProceduralTerrainAppearance::Cache::createPlaneList (const int size)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_planeListList);
ArrayList<Plane>* planeList = 0;
//-- just take one off the list
if (!ms_planeListList->empty ())
{
planeList = ms_planeListList->back ();
ms_planeListList->pop_back ();
}
else
{
//-- create one
planeList = localCreatePlaneList (size);
}
NOT_NULL (planeList);
return planeList;
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearance::Cache::destroyPlaneList (ArrayList<Plane>* const planeList)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_planeListList);
if (planeList)
ms_planeListList->push_back (planeList);
}
//-------------------------------------------------------------------
Array2d<ShaderGroup::Info>* ServerProceduralTerrainAppearance::Cache::createShaderMap (int width, int height)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_shaderMapList);
Array2d<ShaderGroup::Info>* map = 0;
//-- just take one off the list
if (!ms_shaderMapList->empty ())
{
map = ms_shaderMapList->back ();
ms_shaderMapList->pop_back ();
}
else
{
//-- create one
map = localCreateShaderMap (width, height);
}
NOT_NULL (map);
DEBUG_FATAL (width != map->getWidth () && height != map->getHeight (), ("ServerProceduralTerrainAppearance::Cache - cached map of wrong size"));
return map;
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearance::Cache::destroyShaderMap (Array2d<ShaderGroup::Info>* map)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_shaderMapList);
if (map)
ms_shaderMapList->push_back (map);
}
//-------------------------------------------------------------------
Array2d<FloraGroup::Info>* ServerProceduralTerrainAppearance::Cache::createFloraMap (int width, int height)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_floraMapList);
Array2d<FloraGroup::Info>* map = 0;
//-- just take one off the list
if (!ms_floraMapList->empty ())
{
map = ms_floraMapList->back ();
ms_floraMapList->pop_back ();
}
else
{
//-- create one
map = localCreateFloraMap (width, height);
}
NOT_NULL (map);
DEBUG_FATAL (width != map->getWidth () && height != map->getHeight (), ("ServerProceduralTerrainAppearance::Cache - cached map of wrong size"));
return map;
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearance::Cache::destroyFloraMap (Array2d<FloraGroup::Info>* map)
{
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_floraMapList);
if (map)
ms_floraMapList->push_back (map);
}
//-------------------------------------------------------------------
void ServerProceduralTerrainAppearanceCacheNamespace::debugDump ()
{
#ifdef _DEBUG
DEBUG_FATAL (!ms_installed, ("not installed"));
NOT_NULL (ms_vertexListList);
NOT_NULL (ms_planeListList);
NOT_NULL (ms_shaderMapList);
NOT_NULL (ms_floraMapList);
DEBUG_REPORT_PRINT (ms_debugReport, ("vertexListList size = %i\n", ms_vertexListList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("planeListList size = %i\n", ms_planeListList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("shaderMapList size = %i\n", ms_shaderMapList->size ()));
DEBUG_REPORT_PRINT (ms_debugReport, ("floraMapList size = %i\n", ms_floraMapList->size ()));
#endif
}
//==================================================================
@@ -0,0 +1,50 @@
//==================================================================
//
// ServerProceduralTerrainAppearance_Cache.h
// asommers
//
// copyright 2002, sony online entertainment
//
//==================================================================
#ifndef INCLUDED_ServerProceduralTerrainAppearance_Cache_H
#define INCLUDED_ServerProceduralTerrainAppearance_Cache_H
//==================================================================
#include "sharedTerrain/ServerProceduralTerrainAppearance.h"
//==================================================================
class ServerProceduralTerrainAppearance::Cache
{
public:
static void install ();
static void remove ();
static void warm (int vertexListSize, int planeListSize, int mapSize);
static ArrayList<Vector>* createVertexList (int size);
static void destroyVertexList (ArrayList<Vector>* vertexList);
static ArrayList<Plane>* createPlaneList (int size);
static void destroyPlaneList (ArrayList<Plane>* planeList);
static Array2d<ShaderGroup::Info>* createShaderMap (int width, int height);
static void destroyShaderMap (Array2d<ShaderGroup::Info>* map);
static Array2d<FloraGroup::Info>* createFloraMap (int width, int height);
static void destroyFloraMap (Array2d<FloraGroup::Info>* map);
private:
Cache ();
~Cache ();
Cache (const Cache&);
Cache& operator= (const Cache&);
};
//==================================================================
#endif
@@ -0,0 +1,30 @@
// ======================================================================
//
// ServerSpaceTerrainAppearance.cpp
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/ServerSpaceTerrainAppearance.h"
#include "sharedTerrain/ServerSpaceTerrainAppearanceTemplate.h"
// ======================================================================
// PUBLIC ServerSpaceTerrainAppearance
// ======================================================================
ServerSpaceTerrainAppearance::ServerSpaceTerrainAppearance(ServerSpaceTerrainAppearanceTemplate const * const serverSpaceTerrainAppearanceTemplate) :
SpaceTerrainAppearance(serverSpaceTerrainAppearanceTemplate)
{
}
// ----------------------------------------------------------------------
ServerSpaceTerrainAppearance::~ServerSpaceTerrainAppearance()
{
}
// ======================================================================
@@ -0,0 +1,37 @@
// ======================================================================
//
// ServerSpaceTerrainAppearance.h
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#ifndef INCLUDED_ServerSpaceTerrainAppearance_H
#define INCLUDED_ServerSpaceTerrainAppearance_H
// ======================================================================
#include "sharedTerrain/SpaceTerrainAppearance.h"
class ServerSpaceTerrainAppearanceTemplate;
// ======================================================================
class ServerSpaceTerrainAppearance : public SpaceTerrainAppearance
{
public:
explicit ServerSpaceTerrainAppearance(ServerSpaceTerrainAppearanceTemplate const * serverSpaceTerrainAppearanceTemplate);
virtual ~ServerSpaceTerrainAppearance();
private:
ServerSpaceTerrainAppearance();
ServerSpaceTerrainAppearance(ServerSpaceTerrainAppearance const &);
ServerSpaceTerrainAppearance & operator=(ServerSpaceTerrainAppearance const &);
};
// ======================================================================
#endif
@@ -0,0 +1,67 @@
// ======================================================================
//
// ServerSpaceTerrainAppearanceTemplate.cpp
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/ServerSpaceTerrainAppearanceTemplate.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedObject/AppearanceTemplateList.h"
#include "sharedTerrain/ServerSpaceTerrainAppearance.h"
// ======================================================================
// STATIC PUBLIC ServerSpaceTerrainAppearanceTemplate
// ======================================================================
void ServerSpaceTerrainAppearanceTemplate::install()
{
AppearanceTemplateList::assignBinding(cms_spaceTerrainAppearanceTemplateTag, ServerSpaceTerrainAppearanceTemplate::create);
ExitChain::add(ServerSpaceTerrainAppearanceTemplate::remove, "ServerSpaceTerrainAppearanceTemplate::remove");
}
// ----------------------------------------------------------------------
AppearanceTemplate * ServerSpaceTerrainAppearanceTemplate::create(char const * const filename, Iff * const iff)
{
return new ServerSpaceTerrainAppearanceTemplate(filename, iff);
}
// ======================================================================
// PUBLIC ServerSpaceTerrainAppearanceTemplate
// ======================================================================
ServerSpaceTerrainAppearanceTemplate::ServerSpaceTerrainAppearanceTemplate(char const * const filename, Iff * const iff) :
SpaceTerrainAppearanceTemplate(filename, iff)
{
}
// ----------------------------------------------------------------------
ServerSpaceTerrainAppearanceTemplate::~ServerSpaceTerrainAppearanceTemplate()
{
}
// ----------------------------------------------------------------------
Appearance * ServerSpaceTerrainAppearanceTemplate::createAppearance() const
{
return new ServerSpaceTerrainAppearance(this);
}
// ======================================================================
// STATIC PRIVATE ServerSpaceTerrainAppearanceTemplate
// ======================================================================
void ServerSpaceTerrainAppearanceTemplate::remove()
{
AppearanceTemplateList::removeBinding(cms_spaceTerrainAppearanceTemplateTag);
}
// ======================================================================
@@ -0,0 +1,50 @@
// ======================================================================
//
// ServerSpaceTerrainAppearanceTemplate.h
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#ifndef INCLUDED_ServerSpaceTerrainAppearanceTemplate_H
#define INCLUDED_ServerSpaceTerrainAppearanceTemplate_H
// ======================================================================
#include "sharedTerrain/SpaceTerrainAppearanceTemplate.h"
class Iff;
// ======================================================================
class ServerSpaceTerrainAppearanceTemplate : public SpaceTerrainAppearanceTemplate
{
public:
static void install();
static AppearanceTemplate * create(char const * filename, Iff * iff);
public:
ServerSpaceTerrainAppearanceTemplate(char const * filename, Iff * iff);
virtual ~ServerSpaceTerrainAppearanceTemplate();
virtual Appearance * createAppearance() const;
private:
static void remove();
private:
ServerSpaceTerrainAppearanceTemplate();
ServerSpaceTerrainAppearanceTemplate(ServerSpaceTerrainAppearanceTemplate const &);
ServerSpaceTerrainAppearanceTemplate & operator=(ServerSpaceTerrainAppearanceTemplate const &);
};
// ======================================================================
#endif
@@ -0,0 +1,38 @@
// ======================================================================
//
// SpaceTerrainAppearance.cpp
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/SpaceTerrainAppearance.h"
#include "sharedTerrain/SpaceTerrainAppearanceTemplate.h"
// ======================================================================
// PUBLIC SpaceTerrainAppearance
// ======================================================================
SpaceTerrainAppearance::SpaceTerrainAppearance(SpaceTerrainAppearanceTemplate const * const spaceTerrainAppearanceTemplate) :
TerrainAppearance(spaceTerrainAppearanceTemplate)
{
}
// ----------------------------------------------------------------------
SpaceTerrainAppearance::~SpaceTerrainAppearance()
{
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearance::getMapWidthInMeters() const
{
SpaceTerrainAppearanceTemplate const * const stat = safe_cast<SpaceTerrainAppearanceTemplate const *>(getAppearanceTemplate());
return stat->getMapWidthInMeters();
}
// ======================================================================
@@ -0,0 +1,39 @@
// ======================================================================
//
// SpaceTerrainAppearance.h
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#ifndef INCLUDED_SpaceTerrainAppearance_H
#define INCLUDED_SpaceTerrainAppearance_H
// ======================================================================
#include "sharedTerrain/TerrainAppearance.h"
class SpaceTerrainAppearanceTemplate;
// ======================================================================
class SpaceTerrainAppearance : public TerrainAppearance
{
public:
SpaceTerrainAppearance(SpaceTerrainAppearanceTemplate const * spaceTerrainAppearanceTemplate);
virtual ~SpaceTerrainAppearance();
virtual float getMapWidthInMeters() const;
private:
SpaceTerrainAppearance();
SpaceTerrainAppearance(SpaceTerrainAppearance const &);
SpaceTerrainAppearance & operator=(SpaceTerrainAppearance const &);
};
// ======================================================================
#endif
@@ -0,0 +1,565 @@
// ======================================================================
//
// SpaceTerrainAppearanceTemplate.cpp
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/SpaceTerrainAppearanceTemplate.h"
#include "sharedFile/Iff.h"
#include <string>
#include <vector>
// ======================================================================
namespace SpaceTerrainAppearanceTemplateNamespace
{
Tag const TAG_AMBI = TAG(A,M,B,I);
Tag const TAG_CELE = TAG(C,E,L,E);
Tag const TAG_CLEA = TAG(C,L,E,A);
Tag const TAG_DIST = TAG(D,I,S,T);
Tag const TAG_DUST = TAG(D,U,S,T);
Tag const TAG_ENVI = TAG(E,N,V,I);
Tag const TAG_FOG = TAG3(F,O,G);
Tag const TAG_PARA = TAG(P,A,R,A);
Tag const TAG_PLAN = TAG(P,L,A,N);
Tag const TAG_STAR = TAG(S,T,A,R);
Tag const TAG_SKYB = TAG(S,K,Y,B);
}
using namespace SpaceTerrainAppearanceTemplateNamespace;
// ======================================================================
// PUBLIC SpaceTerrainAppearanceTemplate
// ======================================================================
SpaceTerrainAppearanceTemplate::SpaceTerrainAppearanceTemplate(char const * const filename, Iff * const iff) :
AppearanceTemplate(filename),
m_clearColor(),
m_ambientColor(),
m_lightDataList(new LightDataList),
m_environmentTextureName(),
m_fogEnabled(false),
m_fogColor(),
m_fogDensity(0.f),
m_numberOfStars(0),
m_starColorRampName(),
m_numberOfDust(0),
m_dustRadius(0.f),
m_skyBoxCubeMap(false),
m_skyBoxTextureNameMask(),
m_celestialDataList(new CelestialDataList),
m_distantAppearanceDataList(new DistantAppearanceDataList),
m_mapWidthInMeters(16384.0f)
{
NOT_NULL(iff);
load(*iff);
}
// ----------------------------------------------------------------------
SpaceTerrainAppearanceTemplate::~SpaceTerrainAppearanceTemplate()
{
delete m_lightDataList;
delete m_celestialDataList;
delete m_distantAppearanceDataList;
}
// ----------------------------------------------------------------------
PackedRgb const & SpaceTerrainAppearanceTemplate::getClearColor() const
{
return m_clearColor;
}
// ----------------------------------------------------------------------
VectorArgb const & SpaceTerrainAppearanceTemplate::getAmbientColor() const
{
return m_ambientColor;
}
// ----------------------------------------------------------------------
int SpaceTerrainAppearanceTemplate::getNumberOfParallelLights() const
{
NOT_NULL(m_lightDataList);
return static_cast<int>(m_lightDataList->size());
}
// ----------------------------------------------------------------------
VectorArgb const & SpaceTerrainAppearanceTemplate::getParallelLightDiffuseColor(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfParallelLights());
return (*m_lightDataList)[static_cast<size_t>(index)].m_diffuseColor;
}
// ----------------------------------------------------------------------
VectorArgb const & SpaceTerrainAppearanceTemplate::getParallelLightSpecularColor(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfParallelLights());
return (*m_lightDataList)[static_cast<size_t>(index)].m_specularColor;
}
// ----------------------------------------------------------------------
Vector const & SpaceTerrainAppearanceTemplate::getParallelLightDirection_w(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfParallelLights());
return (*m_lightDataList)[static_cast<size_t>(index)].m_direction_w;
}
// ----------------------------------------------------------------------
CrcString const & SpaceTerrainAppearanceTemplate::getEnvironmentTextureName() const
{
return m_environmentTextureName;
}
// ----------------------------------------------------------------------
bool SpaceTerrainAppearanceTemplate::getFogEnabled() const
{
return m_fogEnabled;
}
// ----------------------------------------------------------------------
PackedArgb const & SpaceTerrainAppearanceTemplate::getFogColor() const
{
return m_fogColor;
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getFogDensity() const
{
return m_fogDensity;
}
// ----------------------------------------------------------------------
int SpaceTerrainAppearanceTemplate::getNumberOfStars() const
{
return m_numberOfStars;
}
// ----------------------------------------------------------------------
CrcString const & SpaceTerrainAppearanceTemplate::getStarColorRampName() const
{
return m_starColorRampName;
}
// ----------------------------------------------------------------------
int SpaceTerrainAppearanceTemplate::getNumberOfDust() const
{
return m_numberOfDust;
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getDustRadius() const
{
return m_dustRadius;
}
// ----------------------------------------------------------------------
bool SpaceTerrainAppearanceTemplate::getSkyBoxCubeMap() const
{
return m_skyBoxCubeMap;
}
// ----------------------------------------------------------------------
CrcString const & SpaceTerrainAppearanceTemplate::getSkyBoxTextureNameMask() const
{
return m_skyBoxTextureNameMask;
}
// ----------------------------------------------------------------------
int SpaceTerrainAppearanceTemplate::getNumberOfDistantAppearances() const
{
NOT_NULL(m_distantAppearanceDataList);
return static_cast<int>(m_distantAppearanceDataList->size());
}
// ----------------------------------------------------------------------
CrcString const & SpaceTerrainAppearanceTemplate::getDistantAppearanceTemplateName(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfDistantAppearances());
return (*m_distantAppearanceDataList)[static_cast<size_t>(index)].m_appearanceTemplateName;
}
// ----------------------------------------------------------------------
Vector const & SpaceTerrainAppearanceTemplate::getDistantAppearanceDirection_w(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfDistantAppearances());
return (*m_distantAppearanceDataList)[static_cast<size_t>(index)].m_direction_w;
}
// ----------------------------------------------------------------------
Vector const & SpaceTerrainAppearanceTemplate::getDistantAppearanceOrientation_w(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfDistantAppearances());
return (*m_distantAppearanceDataList)[static_cast<size_t>(index)].m_orientation_w;
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getPlanetHaloRoll(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfDistantAppearances());
return (*m_distantAppearanceDataList)[static_cast<size_t>(index)].m_haloRoll;
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getPlanetHaloScale(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfDistantAppearances());
return (*m_distantAppearanceDataList)[static_cast<size_t>(index)].m_haloScale;
}
//----------------------------------------------------------------------
bool SpaceTerrainAppearanceTemplate::isDistantAppearanceInfiniteDistance(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfDistantAppearances());
return (*m_distantAppearanceDataList)[static_cast<size_t>(index)].m_infiniteDistance;
}
// ----------------------------------------------------------------------
int SpaceTerrainAppearanceTemplate::getNumberOfCelestials() const
{
NOT_NULL(m_celestialDataList);
return static_cast<int>(m_celestialDataList->size());
}
// ----------------------------------------------------------------------
CrcString const & SpaceTerrainAppearanceTemplate::getCelestialBackShaderTemplateName(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfCelestials());
return (*m_celestialDataList)[static_cast<size_t>(index)].m_backShaderTemplateName;
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getCelestialBackSize(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfCelestials());
return (*m_celestialDataList)[static_cast<size_t>(index)].m_backSize;
}
// ----------------------------------------------------------------------
CrcString const & SpaceTerrainAppearanceTemplate::getCelestialFrontShaderTemplateName(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfCelestials());
return (*m_celestialDataList)[static_cast<size_t>(index)].m_frontShaderTemplateName;
}
// ----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getCelestialFrontSize(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfCelestials());
return (*m_celestialDataList)[static_cast<size_t>(index)].m_frontSize;
}
// ----------------------------------------------------------------------
Vector const & SpaceTerrainAppearanceTemplate::getCelestialDirection_w(int const index) const
{
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfCelestials());
return (*m_celestialDataList)[static_cast<size_t>(index)].m_direction_w;
}
// ======================================================================
// PROTECTED SpaceTerrainAppearanceTemplate
// ======================================================================
Tag const SpaceTerrainAppearanceTemplate::cms_spaceTerrainAppearanceTemplateTag = TAG(S,T,A,T);
// ======================================================================
// PRIVATE SpaceTerrainAppearanceTemplate
// ======================================================================
void SpaceTerrainAppearanceTemplate::load(Iff & iff)
{
iff.enterForm(cms_spaceTerrainAppearanceTemplateTag);
switch(iff.getCurrentName())
{
case TAG_0000:
load_0000(iff);
break;
default:
{
char tagBuffer[5];
ConvertTagToString(iff.getCurrentName(), tagBuffer);
char buffer[128];
iff.formatLocation(buffer, sizeof(buffer));
FATAL(true, ("SpaceTerrainAppearanceTemplate::load: unsupported version tag %s/%s", buffer, tagBuffer));
}
break;
}
iff.exitForm(cms_spaceTerrainAppearanceTemplateTag);
}
// ----------------------------------------------------------------------
void SpaceTerrainAppearanceTemplate::load_0000(Iff & iff)
{
iff.enterForm(TAG_0000);
while (iff.getNumberOfBlocksLeft())
{
switch (iff.getCurrentName())
{
case TAG_INFO:
{
iff.enterForm(TAG_INFO);
{
iff.enterChunk(TAG_0000);
{
m_mapWidthInMeters = iff.read_float();
}
iff.exitChunk(TAG_0000);
}
iff.exitForm(TAG_INFO);
}
break;
case TAG_CLEA:
{
iff.enterForm(TAG_CLEA);
iff.enterChunk(TAG_0000);
m_clearColor.r = static_cast<uint8>(clamp(0.f, iff.read_float(), 1.f) * 255.f);
m_clearColor.g = static_cast<uint8>(clamp(0.f, iff.read_float(), 1.f) * 255.f);
m_clearColor.b = static_cast<uint8>(clamp(0.f, iff.read_float(), 1.f) * 255.f);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_CLEA);
}
break;
case TAG_AMBI:
{
iff.enterForm(TAG_AMBI);
iff.enterChunk(TAG_0000);
m_ambientColor = iff.read_floatVectorArgb();
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_AMBI);
}
break;
case TAG_PARA:
{
iff.enterForm(TAG_PARA);
iff.enterChunk(TAG_0000);
LightData lightData;
lightData.m_dot3 = iff.read_bool8();
lightData.m_diffuseColor = iff.read_floatVectorArgb();
lightData.m_specularColor = iff.read_floatVectorArgb();
lightData.m_direction_w = iff.read_floatVector();
m_lightDataList->push_back(lightData);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_PARA);
}
break;
case TAG_ENVI:
{
iff.enterForm(TAG_ENVI);
iff.enterChunk(TAG_0000);
std::string environmentTextureName;
iff.read_string(environmentTextureName);
m_environmentTextureName.set(environmentTextureName.c_str(), true);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_ENVI);
}
break;
case TAG_FOG:
{
iff.enterForm(TAG_FOG);
iff.enterChunk(TAG_0000);
m_fogEnabled = true;
VectorArgb const fogColor = iff.read_floatVectorArgb();
m_fogColor.setArgb(fogColor);
m_fogDensity = fogColor.a;
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_FOG);
}
break;
case TAG_STAR:
{
iff.enterForm(TAG_STAR);
iff.enterChunk(TAG_0000);
std::string starColorRampName;
iff.read_string(starColorRampName);
m_starColorRampName.set(starColorRampName.c_str(), true);
m_numberOfStars = iff.read_int32();
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_STAR);
}
break;
case TAG_DUST:
{
iff.enterForm(TAG_DUST);
iff.enterChunk(TAG_0000);
m_numberOfDust = iff.read_int32();
m_dustRadius = iff.read_float();
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_DUST);
}
break;
case TAG_SKYB:
{
iff.enterForm(TAG_SKYB);
iff.enterChunk(TAG_0000);
m_skyBoxCubeMap = iff.read_bool8();
std::string textureNameMask;
iff.read_string(textureNameMask);
m_skyBoxTextureNameMask.set(textureNameMask.c_str(), true);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_SKYB);
}
break;
case TAG_DIST:
{
iff.enterForm(TAG_DIST);
iff.enterChunk(TAG_0000);
DistantAppearanceData distantAppearanceData;
std::string appearanceTemplateName;
iff.read_string(appearanceTemplateName);
distantAppearanceData.m_appearanceTemplateName.set(appearanceTemplateName.c_str(), true);
distantAppearanceData.m_direction_w = iff.read_floatVector();
distantAppearanceData.m_orientation_w.x = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_orientation_w.y = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_orientation_w.z = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_haloRoll = 0.f;
distantAppearanceData.m_haloScale = 1.f;
distantAppearanceData.m_infiniteDistance = (iff.read_int8() != 0);
m_distantAppearanceDataList->push_back(distantAppearanceData);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_DIST);
}
break;
case TAG_PLAN:
{
iff.enterForm(TAG_PLAN);
iff.enterChunk(TAG_0000);
DistantAppearanceData distantAppearanceData;
std::string appearanceTemplateName;
iff.read_string(appearanceTemplateName);
distantAppearanceData.m_appearanceTemplateName.set(appearanceTemplateName.c_str(), true);
distantAppearanceData.m_direction_w = iff.read_floatVector();
distantAppearanceData.m_orientation_w.x = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_orientation_w.y = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_orientation_w.z = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_haloRoll = convertDegreesToRadians(iff.read_float());
distantAppearanceData.m_haloScale = iff.read_float();
distantAppearanceData.m_infiniteDistance = (iff.read_int8() != 0);
m_distantAppearanceDataList->push_back(distantAppearanceData);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_PLAN);
}
break;
case TAG_CELE:
{
iff.enterForm(TAG_CELE);
iff.enterChunk(TAG_0000);
CelestialData celestialData;
std::string shaderTemplateName;
iff.read_string(shaderTemplateName);
celestialData.m_backShaderTemplateName.set(shaderTemplateName.c_str(), true);
celestialData.m_backSize = iff.read_float();
iff.read_string(shaderTemplateName);
celestialData.m_frontShaderTemplateName.set(shaderTemplateName.c_str(), true);
celestialData.m_frontSize = iff.read_float();
celestialData.m_direction_w = iff.read_floatVector();
m_celestialDataList->push_back(celestialData);
iff.exitChunk(TAG_0000);
iff.exitForm(TAG_CELE);
}
break;
default:
{
#ifdef _DEBUG
char tagBuffer[5];
ConvertTagToString(iff.getCurrentName(), tagBuffer);
char buffer[128];
iff.formatLocation(buffer, sizeof(buffer));
DEBUG_WARNING(true, ("SpaceTerrainAppearanceTemplate::load: skipping unknown chunk type %s/%s", buffer, tagBuffer));
#endif
IGNORE_RETURN(iff.goForward());
}
break;
}
}
iff.exitForm(TAG_0000);
}
//----------------------------------------------------------------------
float SpaceTerrainAppearanceTemplate::getMapWidthInMeters() const
{
return m_mapWidthInMeters;
}
// ======================================================================
@@ -0,0 +1,160 @@
// ======================================================================
//
// SpaceTerrainAppearanceTemplate.h
// asommers
//
// copyright 2004, sony online entertainment
//
// ======================================================================
#ifndef INCLUDED_SpaceTerrainAppearanceTemplate_H
#define INCLUDED_SpaceTerrainAppearanceTemplate_H
// ======================================================================
#include "sharedFoundation/PersistentCrcString.h"
#include "sharedFoundation/Tag.h"
#include "sharedObject/AppearanceTemplate.h"
#include "sharedMath/PackedArgb.h"
#include "sharedMath/PackedRgb.h"
#include "sharedMath/Vector.h"
#include "sharedMath/VectorArgb.h"
class Iff;
// ======================================================================
class SpaceTerrainAppearanceTemplate : public AppearanceTemplate
{
public:
SpaceTerrainAppearanceTemplate(char const * filename, Iff * iff);
virtual ~SpaceTerrainAppearanceTemplate() = 0;
PackedRgb const & getClearColor() const;
VectorArgb const & getAmbientColor() const;
int getNumberOfParallelLights() const;
VectorArgb const & getParallelLightDiffuseColor(int index) const;
VectorArgb const & getParallelLightSpecularColor(int index) const;
Vector const & getParallelLightDirection_w(int index) const;
CrcString const & getEnvironmentTextureName() const;
bool getFogEnabled() const;
PackedArgb const & getFogColor() const;
float getFogDensity() const;
int getNumberOfStars() const;
CrcString const & getStarColorRampName() const;
int getNumberOfDust() const;
float getDustRadius() const;
bool getSkyBoxCubeMap() const;
CrcString const & getSkyBoxTextureNameMask() const;
int getNumberOfDistantAppearances() const;
CrcString const & getDistantAppearanceTemplateName(int index) const;
Vector const & getDistantAppearanceDirection_w(int index) const;
Vector const & getDistantAppearanceOrientation_w(int index) const;
float getPlanetHaloRoll(int index) const;
float getPlanetHaloScale(int index) const;
bool isDistantAppearanceInfiniteDistance(int index) const;
int getNumberOfCelestials() const;
CrcString const & getCelestialBackShaderTemplateName(int index) const;
float getCelestialBackSize(int index) const;
CrcString const & getCelestialFrontShaderTemplateName(int index) const;
float getCelestialFrontSize(int index) const;
Vector const & getCelestialDirection_w(int index) const;
float getMapWidthInMeters() const;
protected:
static Tag const cms_spaceTerrainAppearanceTemplateTag;
private:
struct LightData
{
bool m_dot3;
VectorArgb m_diffuseColor;
VectorArgb m_specularColor;
Vector m_direction_w;
};
struct DistantAppearanceData
{
PersistentCrcString m_appearanceTemplateName;
Vector m_direction_w;
Vector m_orientation_w;
float m_haloRoll;
float m_haloScale;
bool m_infiniteDistance;
private:
DistantAppearanceData operator=(DistantAppearanceData const & rhs);
};
struct CelestialData
{
PersistentCrcString m_backShaderTemplateName;
float m_backSize;
PersistentCrcString m_frontShaderTemplateName;
float m_frontSize;
Vector m_direction_w;
private:
CelestialData operator=(CelestialData const & rhs);
};
private:
SpaceTerrainAppearanceTemplate();
SpaceTerrainAppearanceTemplate(SpaceTerrainAppearanceTemplate const &);
SpaceTerrainAppearanceTemplate & operator=(SpaceTerrainAppearanceTemplate const &);
void load(Iff & iff);
void load_0000(Iff & iff);
private:
PackedRgb m_clearColor;
VectorArgb m_ambientColor;
typedef stdvector<LightData>::fwd LightDataList;
LightDataList * const m_lightDataList;
PersistentCrcString m_environmentTextureName;
bool m_fogEnabled;
PackedArgb m_fogColor;
float m_fogDensity;
int m_numberOfStars;
PersistentCrcString m_starColorRampName;
int m_numberOfDust;
float m_dustRadius;
bool m_skyBoxCubeMap;
PersistentCrcString m_skyBoxTextureNameMask;
typedef stdvector<CelestialData>::fwd CelestialDataList;
CelestialDataList * const m_celestialDataList;
typedef stdvector<DistantAppearanceData>::fwd DistantAppearanceDataList;
DistantAppearanceDataList * const m_distantAppearanceDataList;
float m_mapWidthInMeters;
};
// ======================================================================
#endif
@@ -0,0 +1,457 @@
//===================================================================
//
// TerrainAppearance.cpp
// asommers 7-6-99
//
// copyright 1999, bootprint entertainment
// copyright 2001, sony online entertainment
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/TerrainAppearance.h"
#include "sharedCollision/CollisionInfo.h"
#include "sharedMath/Sphere.h"
#include "sharedObject/Object.h"
#include "sharedObject/ObjectList.h"
//===================================================================
// PUBLIC TerrainAppearance
//===================================================================
TerrainAppearance::TerrainAppearance (const AppearanceTemplate* newAppearanceTemplate) :
Appearance (newAppearanceTemplate),
m_referenceObjectList (NON_NULL (new ObjectList (10)))
{
}
//-------------------------------------------------------------------
TerrainAppearance::~TerrainAppearance ()
{
delete m_referenceObjectList;
}
//-------------------------------------------------------------------
bool TerrainAppearance::collide(Vector const & /*start_o*/, Vector const & /*end_o*/, CollideParameters const & /*collideParameters*/, CollisionInfo & /*result*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::collideObjects (const Vector& /*start_o*/, const Vector& /*end_o*/, CollisionInfo& /*result*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::approximateCollideObjects (const Vector& /*start_o*/, const Vector& /*end_o*/, CollisionInfo& /*result*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getPauseEnvironment () const
{
return false;
}
//-------------------------------------------------------------------
void TerrainAppearance::setPauseEnvironment (bool const /*pauseEnvironment*/)
{
}
//-------------------------------------------------------------------
float TerrainAppearance::getEnvironmentCycleTime () const
{
return 0.f;
}
//-------------------------------------------------------------------
const PackedRgb TerrainAppearance::getClearColor () const
{
return PackedRgb::solidBlack;
}
//-------------------------------------------------------------------
const PackedRgb TerrainAppearance::getFogColor () const
{
return PackedRgb::solidBlack;
}
//-------------------------------------------------------------------
float TerrainAppearance::getFogDensity () const
{
return 0.f;
}
//-------------------------------------------------------------------
void TerrainAppearance::getTime (int& /*hour*/, int& /*minute*/) const
{
}
//-------------------------------------------------------------------
float TerrainAppearance::getTime () const
{
return 0.f;
}
//-------------------------------------------------------------------
void TerrainAppearance::setTime (float /*time*/, bool /*force*/)
{
}
//-------------------------------------------------------------------
bool TerrainAppearance::isDay () const
{
return true;
}
//----------------------------------------------------------------------
bool TerrainAppearance::isTimeLocked() const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getHeight (const Vector& /*position_o*/, float& /*height*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getHeight (const Vector& /*position_o*/, float& /*height*/, Vector& /*normal*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getHeightForceChunkCreation (const Vector& /*position_o*/, float& /*height*/) const
{
return false;
}
//-------------------------------------------------------------------
const ObjectTemplate* TerrainAppearance::getSurfaceProperties (const Vector& /*position_o*/) const
{
return 0;
}
//-------------------------------------------------------------------
int TerrainAppearance::getTerrainType (const Vector& /*position_o*/) const
{
return 0;
}
//-----------------------------------------------------------------
bool TerrainAppearance::getWaterHeight (const Vector& /*position_o*/, float& /*height*/) const
{
return false;
}
//-----------------------------------------------------------------
bool TerrainAppearance::getWaterHeight (const Vector& /*position_o*/, float& /*height*/, TerrainGeneratorWaterType& /*waterType*/, bool /*ignoreNonTransparentWater*/) const
{
return false;
}
//-----------------------------------------------------------------
TerrainGeneratorWaterType TerrainAppearance::getWaterType (const Vector& /*position_w*/) const
{
return TGWT_invalid;
}
//-----------------------------------------------------------------
bool TerrainAppearance::getWater (const Rectangle2d& /*rectangle*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getSlope (const Rectangle2d& /*rectangle*/) const
{
return false;
}
//----------------------------------------------------------------------
bool TerrainAppearance::isPassable(Vector const & /*position_w*/) const
{
return true;
}
//----------------------------------------------------------------------
bool TerrainAppearance::isPassableForceChunkCreation(Vector const & /*position_w*/) const
{
return true;
}
//----------------------------------------------------------------------
bool TerrainAppearance::hasPassableAffectors() const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getWater (const int /*chunkX*/, const int /*chunkZ*/) const
{
return false;
}
//-------------------------------------------------------------------
bool TerrainAppearance::getSlope (const int /*chunkX*/, const int /*chunkZ*/) const
{
return false;
}
//-------------------------------------------------------------------
float TerrainAppearance::getMapWidthInMeters () const
{
return 0.f;
}
//-------------------------------------------------------------------
float TerrainAppearance::getChunkWidthInMeters () const
{
return 0.f;
}
//-------------------------------------------------------------------
int TerrainAppearance::getNumberOfChunks () const
{
return 0;
}
//-------------------------------------------------------------------
bool TerrainAppearance::hasHighLevelOfDetailTerrain (const Vector& /*position_o*/) const
{
return true;
}
//-------------------------------------------------------------------
int TerrainAppearance::calculateChunkX (float) const
{
return 0;
}
//-------------------------------------------------------------------
int TerrainAppearance::calculateChunkZ (float) const
{
return 0;
}
//-------------------------------------------------------------------
float TerrainAppearance::getChunkHeight (const int /*chunkX*/, const int /*chunkZ*/) const
{
return 0.f;
}
//-------------------------------------------------------------------
const BoxExtent* TerrainAppearance::getChunkExtent (const Vector& /*position_o*/) const
{
return 0;
}
//-------------------------------------------------------------------
const BoxExtent* TerrainAppearance::getChunkExtentForceChunkCreation (const Vector& /*position_o*/) const
{
return 0;
}
//-------------------------------------------------------------------
bool TerrainAppearance::collideForceChunkCreation(Vector const & /*start_o*/, Vector const & /*end_o*/, CollisionInfo & /*result*/)
{
return false;
}
//-------------------------------------------------------------------
void TerrainAppearance::preRender (const Camera* /*camera*/) const
{
}
//-----------------------------------------------------------------
void TerrainAppearance::postRender () const
{
}
//-----------------------------------------------------------------
void TerrainAppearance::addClearCollidableFloraObject (const Object* const /*object*/, const Vector& /*position_w*/, const float /*radius*/)
{
}
//-------------------------------------------------------------------
void TerrainAppearance::removeClearCollidableFloraObject (const Object* const /*object*/)
{
}
//-------------------------------------------------------------------
void TerrainAppearance::addClearNonCollidableFloraObject (const Object* const /*object*/, const ClearFloraEntryList& /*clearFloraEntryList*/)
{
}
//-------------------------------------------------------------------
void TerrainAppearance::removeClearNonCollidableFloraObject (const Object* const /*object*/)
{
}
//-------------------------------------------------------------------
float TerrainAppearance::getHighLevelOfDetailThreshold () const
{
return 1.f;
}
//-------------------------------------------------------------------
void TerrainAppearance::setHighLevelOfDetailThreshold (const float /*highLevelOfDetailThreshold*/)
{
}
//-------------------------------------------------------------------
float TerrainAppearance::getLevelOfDetailThreshold () const
{
return 1.f;
}
//-------------------------------------------------------------------
void TerrainAppearance::setLevelOfDetailThreshold (const float /*levelOfDetailThreshold*/)
{
}
//-------------------------------------------------------------------
void TerrainAppearance::getPolygonSoup (const Rectangle2d& /*extent2d_o*/, IndexedTriangleList& /*indexedTriangleList*/) const
{
}
//-------------------------------------------------------------------
void TerrainAppearance::invalidateRegion (const Rectangle2d& /*extent2d*/)
{
}
//-------------------------------------------------------------------
void TerrainAppearance::addReferenceObject (const Object* const object)
{
m_referenceObjectList->addObject (const_cast<Object*> (object));
}
//-------------------------------------------------------------------
void TerrainAppearance::removeReferenceObject (const Object* const object)
{
m_referenceObjectList->removeObject (const_cast<Object*> (object));
}
//-------------------------------------------------------------------
void TerrainAppearance::removeAllReferenceObjects ()
{
m_referenceObjectList->removeAll ();
}
//-------------------------------------------------------------------
bool TerrainAppearance::isReferenceObject (const Object* const object) const
{
return m_referenceObjectList->find (object);
}
//-------------------------------------------------------------------
void TerrainAppearance::drawExtents (const Vector& /*position_o*/) const
{
}
//-------------------------------------------------------------------
void TerrainAppearance::debugDump () const
{
#ifdef _DEBUG
DEBUG_REPORT_PRINT (true, ("-- TerrainAppearance\n"));
DEBUG_REPORT_PRINT (true, ("numberOfReferenceObjects = %i\n", getNumberOfReferenceObjects ()));
if (getNumberOfReferenceObjects ())
{
const Object* const object = getReferenceObject (0);
if (object)
{
const Vector position_w = object->getPosition_w ();
DEBUG_REPORT_PRINT (true, ("referenceObject0Position = <%1.2f, %1.2f, %1.2f>\n", position_w.x, position_w.y, position_w.z));
}
}
#endif
}
//-------------------------------------------------------------------
void TerrainAppearance::purgeChunks()
{
}
//===================================================================
// PRIVATE TerrainAppearance
//===================================================================
int TerrainAppearance::getNumberOfReferenceObjects () const
{
return m_referenceObjectList->getNumberOfObjects ();
}
//-------------------------------------------------------------------
const Object* TerrainAppearance::getReferenceObject (const int index) const
{
return m_referenceObjectList->getObject (index);
}
//===================================================================
@@ -0,0 +1,126 @@
//===================================================================
//
// TerrainAppearance.h
// asommers 7-6-99
//
// copyright 1999, bootprint entertainment
// copyright 2001, sony online entertainment
//
//===================================================================
#ifndef INCLUDED_TerrainAppearance_H
#define INCLUDED_TerrainAppearance_H
//===================================================================
#include "sharedMath/PackedRgb.h"
#include "sharedObject/Appearance.h"
#include "sharedTerrain/TerrainGeneratorType.h"
class Camera;
class ObjectList;
class ObjectTemplate;
class Rectangle2d;
//===================================================================
class TerrainAppearance : public Appearance
{
public:
explicit TerrainAppearance (const AppearanceTemplate* newAppearanceTemplate);
virtual ~TerrainAppearance ();
//-- Appearance
virtual bool collide(Vector const & start_o, Vector const & end_o, CollideParameters const & collideParameters, CollisionInfo & result) const;
//-- TerrainAppearance
virtual bool getHeight (const Vector& position_o, float& height) const;
virtual bool getHeight (const Vector& position_o, float& height, Vector& normal) const;
virtual bool getHeightForceChunkCreation (const Vector& position_o, float& height) const;
virtual const ObjectTemplate* getSurfaceProperties (const Vector& position_o) const;
virtual int getTerrainType (const Vector& position_o) const;
virtual bool getWaterHeight (const Vector& position_o, float& height) const;
virtual bool getWaterHeight (const Vector& position_o, float& height, TerrainGeneratorWaterType& waterType, bool ignoreNonTransparentWater=false) const;
virtual TerrainGeneratorWaterType getWaterType (const Vector& position_w) const;
virtual bool getWater (const Rectangle2d& rectangle) const;
virtual bool getSlope (const Rectangle2d& rectangle) const;
virtual bool getWater (int chunkX, int chunkZ) const;
virtual bool getSlope (int chunkX, int chunkZ) const;
virtual bool isPassable(Vector const & position_w) const;
virtual bool isPassableForceChunkCreation(Vector const & position_w) const;
virtual bool hasPassableAffectors() const;
virtual float getMapWidthInMeters () const;
virtual float getChunkWidthInMeters () const;
virtual int getNumberOfChunks () const;
virtual bool hasHighLevelOfDetailTerrain (const Vector& position_o) const;
virtual int calculateChunkX (float positionX_o) const;
virtual int calculateChunkZ (float positionZ_o) const;
virtual float getChunkHeight (int chunkX, int chunkZ) const;
virtual const BoxExtent* getChunkExtent (const Vector& position_o) const;
virtual const BoxExtent* getChunkExtentForceChunkCreation (const Vector& position_o) const;
virtual bool collideForceChunkCreation(Vector const & start_o, Vector const & end_o, CollisionInfo & result);
virtual void preRender (const Camera* camera) const;
virtual void postRender () const;
virtual bool collideObjects (const Vector& start_o, const Vector& end_o, CollisionInfo& result) const;
virtual bool approximateCollideObjects (const Vector& start_o, const Vector& end_o, CollisionInfo& result) const;
virtual bool getPauseEnvironment () const;
virtual void setPauseEnvironment (bool pauseEnvironment);
virtual float getEnvironmentCycleTime () const;
virtual const PackedRgb getClearColor () const;
virtual const PackedRgb getFogColor () const;
virtual float getFogDensity () const;
virtual void getTime (int& hour, int& minute) const;
virtual float getTime () const;
virtual void setTime (float time, bool force);
virtual bool isDay () const;
virtual bool isTimeLocked() const;
typedef stdvector<std::pair<Vector, float> >::fwd ClearFloraEntryList;
virtual void addClearCollidableFloraObject (const Object* object, const Vector& position_o, float radius);
virtual void removeClearCollidableFloraObject (const Object* object);
virtual void addClearNonCollidableFloraObject (const Object* object, const ClearFloraEntryList& clearFloraEntryList);
virtual void removeClearNonCollidableFloraObject (const Object* object);
virtual float getHighLevelOfDetailThreshold () const;
virtual void setHighLevelOfDetailThreshold (float highLevelOfDetailThreshold);
virtual float getLevelOfDetailThreshold () const;
virtual void setLevelOfDetailThreshold (float levelOfDetailThreshold);
virtual void getPolygonSoup (const Rectangle2d& extent2d_o, IndexedTriangleList& indexedTriangleList) const;
virtual void invalidateRegion (const Rectangle2d& extent2d);
void addReferenceObject (const Object* object);
int getNumberOfReferenceObjects () const;
void removeReferenceObject (const Object* object);
void removeAllReferenceObjects ();
bool isReferenceObject (const Object* object) const;
//-- debugging
virtual void drawExtents (const Vector& position_o) const;
virtual void debugDump () const;
virtual void purgeChunks();
protected:
const Object* getReferenceObject (int index) const;
private:
TerrainAppearance ();
TerrainAppearance (const TerrainAppearance&);
TerrainAppearance& operator= (const TerrainAppearance&);
private:
ObjectList* const m_referenceObjectList;
};
//===================================================================
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,741 @@
// ======================================================================
//
// TerrainQuadTree.h
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TerrainQuadTree_H
#define INCLUDED_TerrainQuadTree_H
// ======================================================================
#include "sharedCollision/BoxExtent.h"
#include "sharedFoundation/MemoryBlockManagerMacros.h"
#include "sharedTerrain/ProceduralTerrainAppearance.h"
// ======================================================================
/**
* TerrainQuadTree is a wrapper class for a quadtree of TerrainQuadTree::Nodes
*
* @author jwatson
* @date 2001-01-12
* @see nothing
*/
class TerrainQuadTree
{
public:
/**
* TerrainQuadTree::Node is a node in the Terrain Quad Tree. The interface is pretty fat. (not phat)
*/
class Node
{
MEMORY_BLOCK_MANAGER_INTERFACE_WITHOUT_INSTALL;
public:
static void install ();
static void remove ();
public:
/**
* neighbors
*/
enum
{
NORTH = 0,
WEST = 1,
SOUTH = 2,
EAST = 3,
NUM_NEIGHBORS = 4
};
/**
* neighbor flags
*/
enum
{
NORTH_FLAG = (1<<0)
,WEST_FLAG = (1<<1)
,SOUTH_FLAG = (1<<2)
,EAST_FLAG = (1<<3)
};
static const int REVERSE_DIRECTIONS[4];
/**
* quadrants
*/
enum
{
NORTHEAST = 0,
NORTHWEST = 1,
SOUTHWEST = 2,
SOUTHEAST = 3
};
static const int OPPOSITE_QUADRANTS[4];
/**
* half-quadrants
*/
enum
{
ENE = 0,
NNE = 1,
NNW = 2,
WNW = 3,
WSW = 4,
SSW = 5,
SSE = 6,
ESE = 7
};
static const int OPPOSITE_HALFQUADRANTS[8];
/**
* MAX_SIZE should be the square root of the maximum numeric capacity of 32 bit unsigned int
*/
enum
{
MAX_SIZE = 1 << 14
};
public:
Node (int newX, int newZ, int newSize, float theMinChunkWidthInMeters);
~Node ();
void destroyNode (Node * node);
void removeNode (Node * node);
void addNode (Node * node, int quadrant);
Node * addChunk (ProceduralTerrainAppearance::Chunk * newChunk, const int chunkSize);
int removeSubNodes (bool deleteChunks);
int removeSubNodeChunks (bool deleteChunks, bool recurse=true);
Node * findChunkNode (const ProceduralTerrainAppearance::Chunk * aChunk, int ax, int az, int chunkSize);
const BoxExtent & getBoxExtent () const;
bool isBoxExtentInitialized () const;
bool hasChunk (const ProceduralTerrainAppearance::Chunk * aChunk, int ax, int az, int chunkSize);
bool nodeEncloses (int ax, int az) const;
void pruneTree ();
void removeChunk (ProceduralTerrainAppearance::Chunk * aChunk, bool deleteChunk);
const ProceduralTerrainAppearance::Chunk * getChunk () const;
ProceduralTerrainAppearance::Chunk * getChunk ();
int32 getX () const;
int32 getZ () const;
int32 getSize () const;
int getNumberOfChunks () const;
unsigned getChildIndex () const;
Node * getParent ();
const Node * getParent () const;
Node * getSubNode (const int which) const;
int getQuadrant (const int ax, const int az) const;
int getQuadrant (const Vector & v) const;
int getHalfQuadrant (const int ax, const int az) const;
int getHalfQuadrant (const Vector & v) const;
float getDistanceSquared (const Vector & v) const;
Node * findNode (int ax, int az, int asize);
const Node * findFirstRenderableNode (const Vector& position) const;
Node * findFirstRenderableNode (const Vector& position);
const Node * findFirstRenderableNode (int ax, int az) const;
Node * findFirstRenderableNode (int ax, int az);
Node * findFirstRenderableLowerNeighbor (const Node * otherNode, int dir);
Node * findFirstRenderablePeerNeighbor (const Node * otherNode, int dir);
bool isSelectedForRender () const;
void setSelectedForRender (bool b);
//-- larger neighbor stuff
bool getHasLargerNeighbor (int dir) const;
void setHasLargerNeighbor (int dir, bool b);
void clearHasLargerNeighbors ();
bool getHasAnyLargerNeighbors () const;
unsigned getHasLargerNeighbors () const;
bool isOutsideBuildRange () const;
void setOutsideBuildRange (bool b);
const Node * getNeighbor (int index) const;
Node * getNeighbor (int index);
private:
Node ();
Node (const Node &);
Node & operator= (const Node &);
int internalRemoveSubNodes (bool deleteChunks);
int internalRemoveSubNodeChunks (bool deleteChunks, bool recurse) const;
/**
* find the quadrant given the x and z coordinates relative
* to the center of this node
*/
template<class T> int getQuadrantTemplate (const T ax, const T az) const
{
// left quadrants
if (ax < 0)
{
// bottom left quadrant
if (az < 0)
return SOUTHWEST;
// top left quadrant
else
return NORTHWEST;
}
// bottom right quadrant
else if (az < 0)
return SOUTHEAST;
// top right quadrant
else
return NORTHEAST;
}
/**
* find the half-quadrant given the x and z coordinates relative
* to the center of this node
*/
template<class T> int getHalfQuadrantTemplate (const T ax, const T az) const
{
// left quadrants
if (ax < 0)
{
// bottom left quadrant
if (az < 0)
{
return (ax < az) ? WSW : SSW;
}
// top left quadrant
else
{
return (-ax > az) ? NNW : WNW;
}
}
// bottom right quadrant
else if (az < 0)
{
return (ax < -az) ? SSE : ESE;
}
// top right quadrant
else
{
return (ax > az) ? ENE : NNE;
}
}
private:
/**
* The chunkspace coordinates of the node.
*/
const short m_x;
const short m_z;
/**
* The chunkspace size (width & height) of this node. Size is always a power of 2.
* The maximum number of chunks contained under a node is size*size.
*/
const short m_size;
unsigned short m_childIndex : 2; // The index of this child node as a subnode of its parent.
unsigned short m_worldExtentInitialized : 1;
unsigned short hasLargerNeighborFlags : 4;
unsigned short m_selectedForRender : 1;
unsigned short m_outsideBuildRange : 1;
/**
* This is the width of the smallest chunk on the map. REDUNDANT, store elsewhere?
*/
const float m_minChunkWidthInMeters;
/**
* The chunk which lives at this node. Currently all chunks are assumed
* to live on size 1 leaf nodes.
*/
ProceduralTerrainAppearance::Chunk * m_chunk;
/**
* Subnodes are arranged spatially the same as mathematical quadrants.
*/
Node * m_subNodes[4];
Node * m_parent;
Node * m_neighbors[4];
/**
* Current number of size 1 chunks contained beneath this node.
*/
int m_numberOfChunks;
/**
* The worldspace extents of this node. This extent contains all subnodes.
*/
BoxExtent m_worldExtent;
};
/**
* Constants for Iterator tree traversal
*/
class IteratorConstants
{
public:
static const int ORDER_PRE[4];
// traversal starting with the specified corner, front to back
static const int ORDER_ENE[4];
static const int ORDER_NNE[4];
static const int ORDER_NNW[4];
static const int ORDER_WNW[4];
static const int ORDER_WSW[4];
static const int ORDER_SSW[4];
static const int ORDER_SSE[4];
static const int ORDER_ESE[4];
static const int * const HALF_QUADRANT_ORDERS[8];
};
/**
* TerrainQuadTree::Iterator is a preorder iterator
* To use an iterator, loop while the current node is non-null. If the
* current node's subtree should be processed further, call descend ()
* on the iterator, otherwise call advance () to go to the next node.
* Either advance () or descend () should be called every loop iteration,
* otherwise an infinite loop will result.
*
*
* This template floatly depends on having a pointer type as its template parameter.
* T must be assignable from zero and have a default constructor. A zero sentinel
* is used to improve performance.
*/
template <class T>
class IteratorTemplate
{
public:
explicit IteratorTemplate (T node);
void reset (T node);
T advance ();
bool isEmpty () const;
T getCurNode ();
T descend (const int * theOrder = IteratorConstants::ORDER_PRE);
T descendOneChild (int index);
void push (T node);
private:
IteratorTemplate ();
enum
{
maxDepth = 64 // 16 deep x 4 nodes
};
//* The iterator is a stack of nodes
T s[maxDepth];
int depth;
};
/**
* The ordinary, non-const Iterator
*/
typedef IteratorTemplate<Node *> Iterator;
/**
* The const Iterator
*/
typedef IteratorTemplate<const Node *> ConstIterator;
public:
static void setUseDistance2d (bool useDistance2d);
public:
explicit TerrainQuadTree (int maxsize, float theMinChunkWidthInMeters);
~TerrainQuadTree ();
Node * getTopNode ();
const Node * getTopNode () const;
Iterator getIterator () const;
Node * addChunk (ProceduralTerrainAppearance::Chunk * chunk, const int chunkSize);
void removeChunk (ProceduralTerrainAppearance::Chunk * chunk, bool deleteChunk);
int getNumberOfChunks () const;
void pruneTree ();
ProceduralTerrainAppearance::Chunk * findChunk (int ax, int az, int chunkSize) const;
Node * findChunkNode (int ax, int az, int chunkSize) const;
bool hasChunk (int ax, int az, int chunkSize) const;
private:
Node * m_nodes;
private:
TerrainQuadTree ();
TerrainQuadTree (const TerrainQuadTree&);
TerrainQuadTree& operator= (const TerrainQuadTree&);
};
//-----------------------------------------------------------------
// TerrainQuadTree::Node
//-----------------------------------------------------------------
/**
* Get the BoxExtent which contains this node. This is the enclosing BoxExtent
* of all chunks which are children of this node and its subnodes.
* @return the BoxExtent
*/
inline const BoxExtent & TerrainQuadTree::Node::getBoxExtent () const
{
return m_worldExtent;
}
//-----------------------------------------------------------------
/**
* Have any float-world chunks ever been added to this Node or its' subnodes?
* If not, then the BoxExtent is not yet valid.
*/
inline bool TerrainQuadTree::Node::isBoxExtentInitialized () const
{
return m_worldExtentInitialized;
}
//-----------------------------------------------------------------
/**
* Get the chunk located at this node. Currently chunks are only found on size 1 leaf nodes.
*/
inline const ProceduralTerrainAppearance::Chunk * TerrainQuadTree::Node::getChunk () const
{
return m_chunk;
}
//-----------------------------------------------------------------
inline ProceduralTerrainAppearance::Chunk * TerrainQuadTree::Node::getChunk ()
{
return m_chunk;
}
//-----------------------------------------------------------------
/**
* Get the X position of this node in chunkspace.
*/
inline int32 TerrainQuadTree::Node::getX () const
{
return m_x;
}
//-----------------------------------------------------------------
/**
* Get the z position of this node in chunkspace.
*/
inline int32 TerrainQuadTree::Node::getZ () const
{
return m_z;
}
//-----------------------------------------------------------------
/**
* Get the size of this node in chunkspace.
*/
inline int32 TerrainQuadTree::Node::getSize () const
{
return m_size;
}
//-----------------------------------------------------------------
/**
* Get the number of chunks contained within this entire subtree.
*/
inline int TerrainQuadTree::Node::getNumberOfChunks () const
{
return m_numberOfChunks;
}
//-----------------------------------------------------------------
/**
* Get the childIndex, or the quadrant of this node as related to it's parent node.
*/
inline unsigned TerrainQuadTree::Node::getChildIndex () const
{
return m_childIndex;
}
//-----------------------------------------------------------------
/**
* Get the parent node.
*/
inline TerrainQuadTree::Node * TerrainQuadTree::Node::getParent ()
{
return m_parent;
}
//-----------------------------------------------------------------
/**
* Get the parent node
*/
inline const TerrainQuadTree::Node * TerrainQuadTree::Node::getParent () const
{
return m_parent;
}
//-----------------------------------------------------------------
/**
* Get the child node in the specified quadrant of this node.
*/
inline TerrainQuadTree::Node * TerrainQuadTree::Node::getSubNode (const int childIndex) const
{
return m_subNodes [childIndex];
}
//-----------------------------------------------------------------
/**
* Is this node selected for rendering? If so, then it is rendered, and collision detection occurs with it.
*/
inline bool TerrainQuadTree::Node::isSelectedForRender () const
{
return m_selectedForRender;
}
//-----------------------------------------------------------------
inline void TerrainQuadTree::Node::setSelectedForRender (const bool selectedForRender)
{
m_selectedForRender = selectedForRender;
}
//-----------------------------------------------------------------
/**
* Has this node been flagged as having a larger neighbor in the specified direction?
*/
inline bool TerrainQuadTree::Node::getHasLargerNeighbor (const int direction) const
{
return 0!=(hasLargerNeighborFlags & (1<<direction));
}
//-----------------------------------------------------------------
/**
* Flag this node's larger neighbor status in the specified direction
*/
inline void TerrainQuadTree::Node::setHasLargerNeighbor (const int direction, const bool hasLargerNeighbor)
{
if (hasLargerNeighbor)
{
hasLargerNeighborFlags |= (1<<direction);
}
else
{
hasLargerNeighborFlags &= ~(1<<direction);
}
}
//-----------------------------------------------------------------
inline void TerrainQuadTree::Node::clearHasLargerNeighbors ()
{
hasLargerNeighborFlags=0;
}
//-----------------------------------------------------------------
/**
* Quick check to see if any neighbors are larger.
*/
inline bool TerrainQuadTree::Node::getHasAnyLargerNeighbors () const
{
return hasLargerNeighborFlags!=0;
}
//-----------------------------------------------------------------
/**
* Get 4-element bool array of larger neighbor flags.
*/
inline unsigned TerrainQuadTree::Node::getHasLargerNeighbors() const
{
return hasLargerNeighborFlags;
}
//-----------------------------------------------------------------
inline bool TerrainQuadTree::Node::isOutsideBuildRange () const
{
return m_outsideBuildRange;
}
//-----------------------------------------------------------------
inline void TerrainQuadTree::Node::setOutsideBuildRange (const bool outsideBuildRange)
{
m_outsideBuildRange = outsideBuildRange;
}
//-----------------------------------------------------------------
// TerrainQuadTree::IteratorTemplate
//-----------------------------------------------------------------
/**
* Construct an Iterator starting with the specified node. Initialize
* the sentinel and setup the stack with the selected node.
* @param node The top of the tree to traverse.
*/
template <class T>
inline TerrainQuadTree::IteratorTemplate<T>::IteratorTemplate (T node)
{
NOT_NULL (node);
s[0] = 0;
s[1] = node;
depth = 1;
}
//-----------------------------------------------------------------
/**
* Reset the iterator. The sentinel should be already correct.
*/
template <class T>
inline void TerrainQuadTree::IteratorTemplate<T>::reset (T node)
{
NOT_NULL (node);
DEBUG_FATAL (s[0] != 0, ("Corrupt sentinel")); // verify the sentinel
s[1] = node;
depth = 1;
}
//-----------------------------------------------------------------
template <class T>
inline void TerrainQuadTree::IteratorTemplate<T>::push (T node)
{
NOT_NULL (node);
DEBUG_FATAL (depth >= maxDepth, ("TerrainQuadTree::IteratorTemplate<T>: max depth exceeded"));
s[++depth] = node;
}
//-----------------------------------------------------------------
/**
* advance pops the current node off the stack and returns a pointer to
* the next one, if there is one.
*/
template <class T>
inline T TerrainQuadTree::IteratorTemplate<T>::advance ()
{
DEBUG_FATAL (depth <= 0, ("TerrainQuadTree::IteratorTemplate<T>: advancing past root"));
return s[--depth];
}
//-----------------------------------------------------------------
template <class T>
inline bool TerrainQuadTree::IteratorTemplate<T>::isEmpty () const
{
return depth==0;
}
//-----------------------------------------------------------------
/**
* get the top node of the stack
*/
template <class T>
inline T TerrainQuadTree::IteratorTemplate<T>::getCurNode ()
{
return s[depth];
}
//-----------------------------------------------------------------
/**
* descend pushes the children of the current node onto the stack,
* in the reverse of the order specified. The result is that
* multiple calls to advance () will return the nodes in the order
* specified. The current node is removed from the stack, and the
* resulting top of the stack is returned.
*/
template <class T>
inline T TerrainQuadTree::IteratorTemplate<T>::descend (const int * theOrder)
{
DEBUG_FATAL (isEmpty (), ("descent into empty iterator"));
T node = s[depth--];
// go through the order backwards since our iterator uses a stack rather than a queue
for (int i = 3; i >= 0; --i)
{
const int index = theOrder [i];
if (node->getSubNode (index))
push (node->getSubNode (index));
}
return s[depth];
}
//-----------------------------------------------------------------
template <class T>
inline T TerrainQuadTree::IteratorTemplate<T>::descendOneChild (const int index)
{
DEBUG_FATAL (isEmpty (), ("descent into empty iterator"));
T node = s[depth--];
if (node->getSubNode (index))
push (node->getSubNode (index));
return getCurNode ();
}
//-----------------------------------------------------------------
// TerrainQuadTree
//-----------------------------------------------------------------
inline TerrainQuadTree::Node * TerrainQuadTree::getTopNode ()
{
return m_nodes;
}
//-----------------------------------------------------------------
inline const TerrainQuadTree::Node * TerrainQuadTree::getTopNode () const
{
return m_nodes;
}
//-----------------------------------------------------------------
#endif
@@ -0,0 +1,88 @@
//===================================================================
//
// ConfigSharedTerrain.cpp
// copyright 2000, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/ConfigSharedTerrain.h"
#include "sharedFoundation/ConfigFile.h"
//===================================================================
namespace
{
int ms_maximumNumberOfChunksAllowed;
bool ms_disableGetHeight;
bool ms_debugReportInstall;
bool ms_debugReportLogPrint;
bool ms_disableFloraCaching;
float ms_maximumValidHeightInMeters;
}
//===================================================================
int ConfigSharedTerrain::getMaximumNumberOfChunksAllowed ()
{
return ms_maximumNumberOfChunksAllowed;
}
//-------------------------------------------------------------------
bool ConfigSharedTerrain::getDisableGetHeight ()
{
return ms_disableGetHeight;
}
//-------------------------------------------------------------------
bool ConfigSharedTerrain::getDebugReportInstall ()
{
return ms_debugReportInstall;
}
//-------------------------------------------------------------------
bool ConfigSharedTerrain::getDebugReportLogPrint ()
{
return ms_debugReportLogPrint;
}
//-------------------------------------------------------------------
bool ConfigSharedTerrain::getDisableFloraCaching ()
{
return ms_disableFloraCaching;
}
//-------------------------------------------------------------------
float ConfigSharedTerrain::getMaximumValidHeightInMeters ()
{
return ms_maximumValidHeightInMeters;
}
//===================================================================
#define KEY_BOOL(a,b) (ms_ ## a = ConfigFile::getKeyBool ("SharedTerrain", #a, b))
#define KEY_INT(a,b) (ms_ ## a = ConfigFile::getKeyInt ("SharedTerrain", #a, b))
#define KEY_FLOAT(a,b) (ms_ ## a = ConfigFile::getKeyFloat ("SharedTerrain", #a, b))
//#define KEY_STRING (a,b) (ms_ ## a = ConfigFile::getKeyString ("SharedTerrain", #a, b))
//===================================================================
void ConfigSharedTerrain::install ()
{
KEY_INT (maximumNumberOfChunksAllowed, 40 * 1024);
KEY_BOOL (disableGetHeight, false);
KEY_BOOL (debugReportInstall, false);
KEY_BOOL (debugReportLogPrint, false);
KEY_BOOL (disableFloraCaching, false);
KEY_FLOAT (maximumValidHeightInMeters, 16000.0f);
DEBUG_REPORT_LOG_PRINT (ms_debugReportInstall, ("ConfigSharedTerrain::install\n"));
}
//===================================================================
@@ -0,0 +1,36 @@
//===================================================================
//
// ConfigSharedTerrain.h
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_ConfigSharedTerrain_H
#define INCLUDED_ConfigSharedTerrain_H
//===================================================================
class ConfigSharedTerrain
{
public:
static void install ();
static int getMaximumNumberOfChunksAllowed ();
static bool getDisableGetHeight ();
static bool getDebugReportInstall ();
static bool getDebugReportLogPrint ();
static bool getDisableFloraCaching ();
static float getMaximumValidHeightInMeters ();
private:
ConfigSharedTerrain ();
ConfigSharedTerrain (const ConfigSharedTerrain&);
ConfigSharedTerrain& operator= (const ConfigSharedTerrain&);
};
//===================================================================
#endif
@@ -0,0 +1,18 @@
// ======================================================================
//
// FirstTerrain.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_FirstTerrain_H
#define INCLUDED_FirstTerrain_H
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
// ======================================================================
#endif
@@ -0,0 +1,93 @@
//===================================================================
//
// SetupSharedTerrain.cpp
// asommers 9-10-2000
//
// copyright 2000, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/SetupSharedTerrain.h"
#include "sharedDebug/InstallTimer.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedFractal/MultiFractal.h"
#include "sharedTerrain/ConfigSharedTerrain.h"
#include "sharedTerrain/ServerProceduralTerrainAppearance.h"
#include "sharedTerrain/ServerProceduralTerrainAppearanceTemplate.h"
#include "sharedTerrain/ServerSpaceTerrainAppearanceTemplate.h"
#include "sharedTerrain/TerrainObject.h"
#include "sharedTerrain/WaterTypeManager.h"
//===================================================================
namespace
{
bool ms_installed;
}
//===================================================================
SetupSharedTerrain::Data::Data () :
m_allowInactiveLayerItems (false)
{
}
//===================================================================
void SetupSharedTerrain::install (const SetupSharedTerrain::Data& /*data*/)
{
InstallTimer const installTimer("SetupSharedTerrain::install");
DEBUG_FATAL (ms_installed, ("SetupSharedTerrain::install already installed"));
ms_installed = true;
DEBUG_REPORT_LOG_PRINT (ConfigSharedTerrain::getDebugReportInstall (), ("SetupSharedTerrain::install\n"));
ConfigSharedTerrain::install ();
TerrainObject::install ();
ProceduralTerrainAppearance::install ();
ServerProceduralTerrainAppearanceTemplate::install ();
ServerSpaceTerrainAppearanceTemplate::install();
WaterTypeManager::install();
ExitChain::add (SetupSharedTerrain::remove, "SetupSharedTerrain");
}
//-------------------------------------------------------------------
void SetupSharedTerrain::remove ()
{
DEBUG_FATAL (!ms_installed, ("SetupSharedTerrain::remove not installed"));
ms_installed = false;
/*
#ifdef _DEBUG
MultiFractal::debugDump ();
#endif
*/
}
//-------------------------------------------------------------------
bool SetupSharedTerrain::isInstalled ()
{
return ms_installed;
}
//-------------------------------------------------------------------
void SetupSharedTerrain::setupGameData (Data& data)
{
data.m_allowInactiveLayerItems = false;
}
//-------------------------------------------------------------------
void SetupSharedTerrain::setupToolData (Data& data)
{
data.m_allowInactiveLayerItems = true;
}
//===================================================================
@@ -0,0 +1,53 @@
//===================================================================
//
// SetupSharedTerrain.h
// asommers 9-11-2000
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_SetupSharedTerrain_H
#define INCLUDED_SetupSharedTerrain_H
//===================================================================
class SetupSharedTerrain
{
public:
class Data
{
public:
Data ();
private:
bool m_allowInactiveLayerItems;
private:
friend class SetupSharedTerrain;
};
public:
static void install (const Data& data);
static void remove ();
static bool isInstalled ();
static void setupGameData (Data& data);
static void setupToolData (Data& data);
private:
SetupSharedTerrain ();
SetupSharedTerrain (const SetupSharedTerrain&);
SetupSharedTerrain& operator= (const SetupSharedTerrain&);
};
//===================================================================
#endif
@@ -0,0 +1,248 @@
// ======================================================================
//
// WaterTypeManager.cpp
//
// copyright 2005, Sony Online Entertainment
//
// ======================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/WaterTypeManager.h"
#include "sharedDebug/InstallTimer.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedUtility/DataTable.h"
#include "sharedUtility/DataTableManager.h"
#include <map>
// ======================================================================
bool WaterTypeManager::ms_installed = false;
WaterTypeManager::WaterTypeDataType * WaterTypeManager::ms_waterTypeData=NULL;
WaterTypeManager::CreatureWaterTypeDataType* WaterTypeManager::ms_creatureWaterTypeData=NULL;
// ======================================================================
WaterTypeManager::WaterTypeDataRecord::WaterTypeDataRecord() :
m_typeId(0),
m_name(),
m_causesDamage(false),
m_damageKills(false),
m_damageInterval(0),
m_damagePerInterval(0),
m_transparent(false)
{
}
// ======================================================================
WaterTypeManager::CreatureWaterTypeDataRecord::CreatureWaterTypeDataRecord() :
m_objectTemplateName(),
m_lavaResistance(0.0f)
{
}
// ======================================================================
void WaterTypeManager::install()
{
InstallTimer const installTimer("WaterTypeManager::install");
DEBUG_FATAL(ms_installed,("WaterTypeManager::install was called more than once."));
ms_waterTypeData = new WaterTypeDataType;
ms_creatureWaterTypeData = new CreatureWaterTypeDataType;
ms_installed = true;
ExitChain::add(&remove,"WaterTypeManager::remove");
{
DataTable const * const waterTypeDataTable = DataTableManager::getTable("datatables/terrain/water_values.iff", true);
FATAL(!waterTypeDataTable,("water_values data table could not be opened."));
int const numRows = waterTypeDataTable->getNumRows();
for (int row=0; row<numRows; ++row)
{
WaterTypeDataRecord data;
data.m_typeId = row;
data.m_name = waterTypeDataTable->getStringValue("water_type",row);
data.m_causesDamage = (waterTypeDataTable->getIntValue("causes_damage",row) != 0);
data.m_damageKills = (waterTypeDataTable->getIntValue("damage_kills",row) != 0);
data.m_damageInterval = waterTypeDataTable->getIntValue("damage_interval_secs", row);
data.m_damagePerInterval = waterTypeDataTable->getFloatValue("damage_per_interval_percentage",row);
data.m_transparent = (waterTypeDataTable->getIntValue("transparent",row) != 0);
(*ms_waterTypeData)[data.m_typeId] = data;
}
DataTableManager::close("datatables/terrain/water_values.iff");
}
{
DataTable const* const creatureWaterTypeDataTable = DataTableManager::getTable("datatables/terrain/creature_water_values.iff",true);
FATAL(!creatureWaterTypeDataTable,("creature_water_values data table could not be opened."));
int const numRows = creatureWaterTypeDataTable->getNumRows();
for(int row=0; row < numRows; ++row)
{
CreatureWaterTypeDataRecord data;
data.m_objectTemplateName = creatureWaterTypeDataTable->getStringValue("object_template_name",row);
data.m_lavaResistance = creatureWaterTypeDataTable->getFloatValue("lava_resistance",row);
if(data.m_lavaResistance > 100.0f)
{
data.m_lavaResistance = 100.0f;
}
else if(data.m_lavaResistance < 0.0f)
{
data.m_lavaResistance = 0.0f;
}
(*ms_creatureWaterTypeData)[data.m_objectTemplateName] = data;
}
DataTableManager::close("datatables/terrain/creature_water_values.iff");
}
}
// ----------------------------------------------------------------------
void WaterTypeManager::remove()
{
DEBUG_FATAL(!ms_installed,("WaterTypeManager not installed"));
{
/*
// JU_TODO: temp - reference if we need to preload the character or vehicle effects here
for (WaterTypeManager::WaterTypeDataType::iterator it = ms_waterTypeData->begin(); it != ms_waterTypeData->end(); ++it)
{
WaterTypeDataRecord & waterTypeDataRecord = (*it).second;
waterTypeDataRecord.releaseResources();
}
*/
}
delete ms_waterTypeData;
ms_waterTypeData=NULL;
delete ms_creatureWaterTypeData;
ms_creatureWaterTypeData=NULL;
ms_installed = false;
}
// ----------------------------------------------------------------------
bool WaterTypeManager::getCausesDamage(TerrainGeneratorWaterType type)
{
bool ret = false;
WaterTypeDataType::const_iterator const i = ms_waterTypeData->find(type);
if (i == ms_waterTypeData->end())
{
WARNING(true,("WaterTypeManager::getCausesDamage: Received request with type id %i, which isn't in the data table.", type));
}
else
{
WaterTypeDataRecord const & data = i->second;
ret = data.m_causesDamage;
}
return ret;
}
// ----------------------------------------------------------------------
bool WaterTypeManager::getDamageKills(TerrainGeneratorWaterType type)
{
bool ret = false;
WaterTypeDataType::const_iterator const i = ms_waterTypeData->find(type);
if (i == ms_waterTypeData->end())
{
WARNING(true,("WaterTypeManager::getDamageKills: Received request with type id %i, which isn't in the data table.", type));
}
else
{
WaterTypeDataRecord const & data = i->second;
ret = data.m_damageKills;
}
return ret;
}
// ----------------------------------------------------------------------
int WaterTypeManager::getDamageInterval(TerrainGeneratorWaterType type)
{
int ret = 0;
WaterTypeDataType::const_iterator const i = ms_waterTypeData->find(type);
if (i == ms_waterTypeData->end())
{
WARNING(true,("WaterTypeManager::getDamageInterval: Received request with type id %i, which isn't in the data table.", type));
}
else
{
WaterTypeDataRecord const & data = i->second;
ret = data.m_damageInterval;
}
return ret;
}
// ----------------------------------------------------------------------
float WaterTypeManager::getDamagePerInterval(TerrainGeneratorWaterType type)
{
float ret = 0.0f;
WaterTypeDataType::const_iterator const i = ms_waterTypeData->find(type);
if (i == ms_waterTypeData->end())
{
WARNING(true,("WaterTypeManager::getDamagePerInterval: Received request with type id %i, which isn't in the data table.", type));
}
else
{
WaterTypeDataRecord const & data = i->second;
ret = data.m_damagePerInterval;
}
return ret;
}
// ----------------------------------------------------------------------
bool WaterTypeManager::getTransparent(TerrainGeneratorWaterType type)
{
bool ret = false;
WaterTypeDataType::const_iterator const i = ms_waterTypeData->find(type);
if (i == ms_waterTypeData->end())
{
WARNING(true,("WaterTypeManager::getTransparent: Received request with type id %i, which isn't in the data table.", type));
}
else
{
WaterTypeDataRecord const & data = i->second;
ret = data.m_transparent;
}
return ret;
}
// ----------------------------------------------------------------------
float WaterTypeManager::getLavaResistance(const std::string& objectTemplateName)
{
float ret = 0.0f;
CreatureWaterTypeDataType::const_iterator const i = ms_creatureWaterTypeData->find(objectTemplateName);
if(i != ms_creatureWaterTypeData->end())
{
CreatureWaterTypeDataRecord const &data = i->second;
ret = data.m_lavaResistance;
}
return ret;
}
// ======================================================================
@@ -0,0 +1,71 @@
//===================================================================
//
// WaterTypeManager.h
//
// copyright 2005, Sony Online Entertainment
//
//===================================================================
#ifndef INCLUDED_WaterTypeManager_H
#define INCLUDED_WaterTypeManager_H
#include <string>
#include "sharedTerrain/TerrainGeneratorType.def"
//===================================================================
class WaterTypeManager
{
public:
static void install ();
static void remove ();
public:
static bool getCausesDamage(TerrainGeneratorWaterType type);
static bool getDamageKills(TerrainGeneratorWaterType type);
static int getDamageInterval(TerrainGeneratorWaterType type);
static float getDamagePerInterval(TerrainGeneratorWaterType type);
static bool getTransparent(TerrainGeneratorWaterType type);
static float getLavaResistance(const std::string& objectTemplateName);
private:
struct WaterTypeDataRecord
{
public:
WaterTypeDataRecord();
public:
int m_typeId;
std::string m_name;
bool m_causesDamage;
bool m_damageKills;
int m_damageInterval;
float m_damagePerInterval;
bool m_transparent;
};
struct CreatureWaterTypeDataRecord
{
public:
CreatureWaterTypeDataRecord();
public:
std::string m_objectTemplateName;
float m_lavaResistance;
};
typedef stdmap<int, WaterTypeDataRecord>::fwd WaterTypeDataType;
typedef stdmap<std::string, CreatureWaterTypeDataRecord>::fwd CreatureWaterTypeDataType;
static bool ms_installed;
static WaterTypeDataType * ms_waterTypeData;
static CreatureWaterTypeDataType* ms_creatureWaterTypeData;
};
//===================================================================
#endif
@@ -0,0 +1,48 @@
//===================================================================
//
// FloraManager.cpp
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/FloraManager.h"
//===================================================================
namespace FloraManagerNamespace
{
const Object* ms_referenceObject;
}
using namespace FloraManagerNamespace;
//===================================================================
const Object* FloraManager::getReferenceObject ()
{
return ms_referenceObject;
}
//-------------------------------------------------------------------
void FloraManager::setReferenceObject (const Object* const referenceObject)
{
ms_referenceObject = referenceObject;
}
//===================================================================
FloraManager::FloraManager ()
{
}
//-------------------------------------------------------------------
FloraManager::~FloraManager ()
{
}
//===================================================================
@@ -0,0 +1,34 @@
//===================================================================
//
// FloraManager.h
// asommers
//
// copyright 2001, sony online entertainment
//
//===================================================================
#ifndef INCLUDED_FloraManager_H
#define INCLUDED_FloraManager_H
//===================================================================
class Object;
//===================================================================
class FloraManager
{
public:
static const Object* getReferenceObject ();
static void setReferenceObject (const Object* referenceObject);
public:
FloraManager ();
virtual ~FloraManager ()=0;
};
//===================================================================
#endif
@@ -0,0 +1,25 @@
//===================================================================
//
// ServerFloraManager.cpp
// asommers
//
// copyright 2000, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/ServerFloraManager.h"
//===================================================================
ServerFloraManager::ServerFloraManager ()
{
}
//-------------------------------------------------------------------
ServerFloraManager::~ServerFloraManager ()
{
}
//===================================================================
@@ -0,0 +1,26 @@
//===================================================================
//
// ServerFloraManager.h
// asommers
//
// copyright 2001, sony online entertainment
//
//===================================================================
#ifndef INCLUDED_ServerFloraManager_H
#define INCLUDED_ServerFloraManager_H
//===================================================================
class ServerFloraManager
{
public:
ServerFloraManager ();
virtual ~ServerFloraManager ()=0;
};
//===================================================================
#endif
@@ -0,0 +1,454 @@
//===================================================================
//
// Affector.cpp
// asommers 2001-01-17
//
// copyright 2001, verant interactive
//
//===================================================================
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/Affector.h"
#include "sharedMath/Line2d.h"
#include <algorithm>
//===================================================================
namespace
{
inline const float computeT (const Vector2d& start, const Vector2d& end, const Vector2d& point)
{
return ((point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y)) / (sqr (end.x - start.x) + sqr (end.y - start.y));
}
template<class T>
inline const T min (const T& a, const T& b)
{
return a < b ? a : b;
}
}
//===================================================================
void AffectorBoundaryPoly::FindData::reset ()
{
height = 0.f;
distanceToCenter = 0.f;
t = 0.f;
length = 0.f;
}
//===================================================================
bool AffectorBoundaryPoly::ms_enabled = true;
//===================================================================
AffectorBoundaryPoly::AffectorBoundaryPoly (const Tag newTag, const TerrainGeneratorAffectorType newType) :
TerrainGenerator::Affector (newTag, newType),
m_featherFunction (TGFF_linear),
m_featherDistance (0.5f),
m_pointList (),
m_lengths (),
m_lengthTotals (),
m_width (4.f),
m_extent (),
m_heightData ()
{
}
//-------------------------------------------------------------------
AffectorBoundaryPoly::~AffectorBoundaryPoly ()
{
}
//-------------------------------------------------------------------
float AffectorBoundaryPoly::isWithin (const float worldX, const float worldZ) const
{
if (!m_extent.isWithin (worldX, worldZ))
return 0.f;
const float widthSquared = sqr (m_width);
float distanceSquared = widthSquared;
//-- first, scan how far we are from the points
{
const int n = m_pointList.getNumberOfElements ();
int i;
for (i = 0; i < n; ++i)
{
const float x = m_pointList [i].x;
const float y = m_pointList [i].y;
const float thisDistanceSquared = sqr (worldX - x) + sqr (worldZ - y);
if (thisDistanceSquared < distanceSquared)
distanceSquared = thisDistanceSquared;
}
}
//-- next, scan each line
{
const int n = m_pointList.getNumberOfElements () - 1;
int i;
for (i = 0; i < n; ++i)
{
const float x1 = m_pointList [i].x;
const float y1 = m_pointList [i].y; //lint !e578 //-- hides y1 (double)
const float x2 = m_pointList [i + 1].x;
const float y2 = m_pointList [i + 1].y;
const float u = ((worldX - x1) * (x2 - x1) + (worldZ - y1) * (y2 - y1)) / (sqr (x2 - x1) + sqr (y2 - y1));
if (u >= 0 && u <= 1)
{
const float x = x1 + u * (x2 - x1);
const float y = y1 + u * (y2 - y1);
const float thisDistanceSquared = sqr (worldX - x) + sqr (worldZ - y);
if (thisDistanceSquared < distanceSquared)
distanceSquared = thisDistanceSquared;
}
}
}
if (distanceSquared < widthSquared)
{
const float newFeatherDistance = m_width * (1.f - getFeatherDistance ());
const float newFeatherDistanceSquared = sqr (newFeatherDistance);
if (distanceSquared < newFeatherDistanceSquared)
return 1.f;
return 1.f - (sqrt (distanceSquared) - newFeatherDistance) / (m_width - newFeatherDistance);
}
return 0.f;
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::addPoint (const Vector2d& point)
{
m_pointList.add (point);
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::replacePoint (const int index, const Vector2d& newPoint)
{
m_pointList [index] = newPoint;
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::removePoint (const int index)
{
m_pointList.removeIndexAndCompactList (index);
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::clearPointList ()
{
m_pointList.clear ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::copyPointList (const ArrayList<Vector2d>& newPointList)
{
m_pointList = newPointList;
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::recalculate ()
{
//
// recalculate extent
//
{
m_extent.x0 = FLT_MAX;
m_extent.y0 = FLT_MAX;
m_extent.x1 = -FLT_MAX;
m_extent.y1 = -FLT_MAX;
int i;
for (i = 0; i < m_pointList.getNumberOfElements (); ++i)
m_extent.expand (m_pointList [i].x, m_pointList [i].y);
m_extent.x0 -= m_width;
m_extent.y0 -= m_width;
m_extent.x1 += m_width;
m_extent.y1 += m_width;
}
//
// recalculate lengths
//
{
m_lengths.clear ();
m_lengthTotals.clear ();
m_lengths.push_back (0.f);
m_lengthTotals.push_back (0.f);
int i;
for (i = 1; i < m_pointList.getNumberOfElements (); ++i)
{
m_lengths.push_back (m_pointList [i].magnitudeBetween (m_pointList [i - 1]));
m_lengthTotals.push_back (m_lengths [i] + m_lengthTotals [i - 1]);
}
}
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::rotate (const float angle)
{
if (m_pointList.getNumberOfElements () == 0)
return;
Vector2d center;
int i;
for (i = 0; i < m_pointList.getNumberOfElements (); i++)
center += m_pointList [i];
center.x /= static_cast<float> (m_pointList.getNumberOfElements ());
center.y /= static_cast<float> (m_pointList.getNumberOfElements ());
rotate (angle, center);
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::rotate (const float angle, const Vector2d& center)
{
if (m_pointList.getNumberOfElements () == 0)
return;
const float cosAngle = cos (angle);
const float sinAngle = sin (angle);
int i;
for (i = 0; i < m_pointList.getNumberOfElements (); i++)
{
Vector2d point;
point.x = m_pointList [i].x - center.x;
point.y = m_pointList [i].y - center.y;
Vector2d newPoint;
newPoint.x = center.x + point.x * cosAngle - point.y * sinAngle;
newPoint.y = center.y + point.x * sinAngle + point.y * cosAngle;
m_pointList [i] = newPoint;
}
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::translate (const Vector2d& translation)
{
int i;
for (i = 0; i < m_pointList.getNumberOfElements (); i++)
m_pointList [i] += translation;
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::scale (const float scalar)
{
if (m_pointList.getNumberOfElements () == 0)
return;
Vector2d center;
int i;
for (i = 0; i < m_pointList.getNumberOfElements (); i++)
center += m_pointList [i];
center.x /= static_cast<float> (m_pointList.getNumberOfElements ());
center.y /= static_cast<float> (m_pointList.getNumberOfElements ());
for (i = 0; i < m_pointList.getNumberOfElements (); i++)
{
m_pointList [i].x = (m_pointList [i].x - center.x) * scalar + center.x;
m_pointList [i].y = (m_pointList [i].y - center.y) * scalar + center.y;
}
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::expand (Rectangle2d& parentExtent) const
{
parentExtent.expand (m_extent.x0, m_extent.y0);
parentExtent.expand (m_extent.x1, m_extent.y1);
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::setWidth (const float newWidth)
{
m_width = newWidth;
recalculate ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::setFeatherFunction (TerrainGeneratorFeatherFunction newFeatherFunction)
{
m_featherFunction = newFeatherFunction;
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::setFeatherDistance (const float newFeatherDistance)
{
m_featherDistance = newFeatherDistance;
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::enable ()
{
ms_enabled = true;
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::disable ()
{
ms_enabled = false;
}
//-------------------------------------------------------------------
bool AffectorBoundaryPoly::isEnabled ()
{
return ms_enabled;
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::clearHeightData ()
{
m_heightData.clear ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::addSegmentHeightData ()
{
m_heightData.addSegment ();
}
//-------------------------------------------------------------------
void AffectorBoundaryPoly::addPointHeightData (const Vector& point)
{
m_heightData.addPoint (point);
}
//-------------------------------------------------------------------
bool AffectorBoundaryPoly::find (const Vector2d& point, const float width, FindData& result, bool ignoreHeight) const
{
if (m_pointList.empty ())
return false;
const float widthSquared = sqr (width);
float distanceSquared = widthSquared;
//-- first, scan how far we are from the points
{
int i;
for (i = 0; i < m_pointList.size (); ++i)
{
const float thisDistanceSquared = point.magnitudeBetweenSquared (m_pointList [i]);
if (thisDistanceSquared < distanceSquared)
{
distanceSquared = thisDistanceSquared;
result.t = m_lengthTotals [i];
result.height = (i != m_pointList.size () - 1) ? m_heightData.getPoint (i, 0).y : m_heightData.getPoint (i - 1, m_heightData.getNumberOfPoints (i - 1) - 1).y;
}
}
}
int segmentIndex = 0;
Vector2d resultPoint;
bool searchHeightData = false;
//-- next, scan each line
{
int i;
for (i = 0; i < m_pointList.size () - 1; ++i)
{
const Vector2d start = m_pointList [i];
const Vector2d end = m_pointList [i + 1];
const float t = computeT (start, end, point);
if (t >= 0 && t <= 1)
{
const Vector2d lerpedPoint = Vector2d::linearInterpolate (start, end, t);
const float thisDistanceSquared = point.magnitudeBetweenSquared (lerpedPoint);
if (thisDistanceSquared < distanceSquared)
{
distanceSquared = thisDistanceSquared;
segmentIndex = i;
resultPoint = lerpedPoint;
if(!ignoreHeight) // some affectors don't have height data (ribbon)
{
searchHeightData = true;
}
result.t = m_lengthTotals [i] + (t * m_lengths [i + 1]);
}
}
}
}
if (distanceSquared < widthSquared)
{
result.distanceToCenter = static_cast<float> (sqrt (distanceSquared));
result.length = m_lengthTotals.back ();
if (searchHeightData && !m_heightData.find (segmentIndex, resultPoint, result.height))
{
static bool s_warnedMissingHeightData = false;
if (!s_warnedMissingHeightData)
{
s_warnedMissingHeightData = true;
DEBUG_WARNING (true, ("AffectorBoundaryPoly::find - couldn't find height data for %s. Did you not bake the river/road data?", getName ()));
}
result.height = 0.f;
}
return true;
}
return false;
}
//===================================================================
@@ -0,0 +1,200 @@
//===================================================================
//
// Affector.h
// asommers 9-30-2000
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_Affector_H
#define INCLUDED_Affector_H
//===================================================================
#include "sharedMath/Vector2d.h"
#include "sharedTerrain/TerrainGenerator.h"
#include "sharedTerrain/HeightData.h"
//===================================================================
class AffectorExclude : public TerrainGenerator::Affector
{
public:
AffectorExclude ();
virtual ~AffectorExclude ();
virtual void affect (float worldX, float worldZ, int x, int z, float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const;
virtual void load (Iff& iff);
virtual void save (Iff& iff) const;
virtual unsigned getAffectedMaps() const;
private:
void load_0000 (Iff& iff);
private:
AffectorExclude (const AffectorExclude& rhs);
AffectorExclude& operator= (const AffectorExclude& rhs);
};
//===================================================================
class AffectorBoundaryPoly : public TerrainGenerator::Affector
{
public:
AffectorBoundaryPoly (Tag newTag, TerrainGeneratorAffectorType newType);
virtual ~AffectorBoundaryPoly ()=0;
virtual float isWithin (float worldX, float worldZ) const;
TerrainGeneratorFeatherFunction getFeatherFunction () const;
void setFeatherFunction (TerrainGeneratorFeatherFunction newFeatherFunction);
float getFeatherDistance () const;
void setFeatherDistance (float newFeatherDistance);
void rotate (float angle);
void rotate (float angle, const Vector2d& center);
void translate (const Vector2d& translation);
void scale (float scalar);
void expand (Rectangle2d& extent) const;
const Vector2d getCenter () const;
const ArrayList<Vector2d>& getPointList () const;
int getNumberOfPoints () const;
const Vector2d& getPoint (int index) const;
void addPoint (const Vector2d& point);
void replacePoint (int index, const Vector2d& point);
void removePoint (int index);
void clearPointList ();
void copyPointList (const ArrayList<Vector2d>& newPointList);
void setWidth (float newWidth);
float getWidth () const;
const Rectangle2d& getExtent () const;
const HeightData& getHeightData () const;
void clearHeightData ();
void addSegmentHeightData ();
void addPointHeightData (const Vector& point);
virtual void createHeightData ()=0;
//--
static bool isEnabled ();
static void enable ();
static void disable ();
protected:
struct FindData
{
public:
float height;
float distanceToCenter;
float t;
float length;
public:
void reset ();
};
protected:
virtual void recalculate ();
//-- find the closest height along the list of points to position (returns t along entire list of segments)
bool find (const Vector2d& point, const float width, FindData& result,bool ignoreHeight = false) const;
protected:
TerrainGeneratorFeatherFunction m_featherFunction;
float m_featherDistance;
ArrayList<Vector2d> m_pointList;
ArrayList<float> m_lengths;
ArrayList<float> m_lengthTotals;
float m_width;
Rectangle2d m_extent;
HeightData m_heightData;
private:
AffectorBoundaryPoly (const AffectorBoundaryPoly& rhs);
AffectorBoundaryPoly& operator= (const AffectorBoundaryPoly& rhs);
private:
static bool ms_enabled;
};
//===================================================================
inline const ArrayList<Vector2d>& AffectorBoundaryPoly::getPointList () const
{
return m_pointList;
}
//-------------------------------------------------------------------
inline int AffectorBoundaryPoly::getNumberOfPoints () const
{
return m_pointList.getNumberOfElements ();
}
//-------------------------------------------------------------------
inline const Vector2d& AffectorBoundaryPoly::getPoint (int index) const
{
return m_pointList [index];
}
//-------------------------------------------------------------------
inline const Vector2d AffectorBoundaryPoly::getCenter () const
{
return m_extent.getCenter ();
}
//-------------------------------------------------------------------
inline float AffectorBoundaryPoly::getWidth () const
{
return m_width;
}
//-------------------------------------------------------------------
inline TerrainGeneratorFeatherFunction AffectorBoundaryPoly::getFeatherFunction () const
{
return m_featherFunction;
}
//-------------------------------------------------------------------
inline float AffectorBoundaryPoly::getFeatherDistance () const
{
return m_featherDistance;
}
//-------------------------------------------------------------------
inline const Rectangle2d& AffectorBoundaryPoly::getExtent () const
{
return m_extent;
}
//-------------------------------------------------------------------
inline const HeightData& AffectorBoundaryPoly::getHeightData () const
{
return m_heightData;
}
//===================================================================
#endif
@@ -0,0 +1,616 @@
//
// AffectorColor.cpp
// asommers 9-30-2000
//
// copyright 2000, verant interactive
//
//-------------------------------------------------------------------
#include "sharedTerrain/FirstSharedTerrain.h"
#include "sharedTerrain/AffectorColor.h"
#include "sharedFile/Iff.h"
#include "sharedFractal/MultiFractal.h"
#include "sharedFractal/MultiFractalReaderWriter.h"
#include "sharedImage/Image.h"
#include "sharedImage/ImageFormatList.h"
#include "sharedTerrain/Affector.h"
#include "sharedSynchronization/Mutex.h"
#include <algorithm>
#include <string>
//-------------------------------------------------------------------
static const PackedRgb computeColor (const PackedRgb& oldColor, const PackedRgb& desiredColor, const TerrainGeneratorOperation operation, const float amount)
{
PackedRgb newColor = desiredColor;
if (amount < 1.f)
{
newColor.r = static_cast<uint8> (desiredColor.r * amount);
newColor.g = static_cast<uint8> (desiredColor.g * amount);
newColor.b = static_cast<uint8> (desiredColor.b * amount);
}
switch (operation)
{
case TGO_add:
{
newColor.r = static_cast<uint8> (std::min (oldColor.r + newColor.r, 255));
newColor.g = static_cast<uint8> (std::min (oldColor.g + newColor.g, 255));
newColor.b = static_cast<uint8> (std::min (oldColor.b + newColor.b, 255));
}
break;
case TGO_subtract:
{
newColor.r = static_cast<uint8> (std::max (oldColor.r - newColor.r, 0));
newColor.g = static_cast<uint8> (std::max (oldColor.g - newColor.g, 0));
newColor.b = static_cast<uint8> (std::max (oldColor.b - newColor.b, 0));
}
break;
case TGO_multiply:
{
newColor.r = static_cast<uint8> (amount * (0.5f * desiredColor.r + 0.5f * oldColor.r) + (1.f - amount) * oldColor.r);
newColor.g = static_cast<uint8> (amount * (0.5f * desiredColor.g + 0.5f * oldColor.g) + (1.f - amount) * oldColor.g);
newColor.b = static_cast<uint8> (amount * (0.5f * desiredColor.b + 0.5f * oldColor.b) + (1.f - amount) * oldColor.b);
}
break;
case TGO_replace:
default:
{
newColor.r = static_cast<uint8> (amount * desiredColor.r + (1.f - amount) * oldColor.r);
newColor.g = static_cast<uint8> (amount * desiredColor.g + (1.f - amount) * oldColor.g);
newColor.b = static_cast<uint8> (amount * desiredColor.b + (1.f - amount) * oldColor.b);
}
break;
case TGO_COUNT:
FATAL (true, ("invalid operation"));
break;
}
return newColor;
}
//-------------------------------------------------------------------
//
// AffectorColorConstant
//
AffectorColorConstant::AffectorColorConstant () :
TerrainGenerator::Affector (TAG_ACCN, TGAT_colorConstant),
operation (TGO_replace),
color ()
{
}
//-------------------------------------------------------------------
AffectorColorConstant::~AffectorColorConstant ()
{
}
//-------------------------------------------------------------------
void AffectorColorConstant::setOperation (const TerrainGeneratorOperation newOperation)
{
operation = newOperation;
}
//-------------------------------------------------------------------
void AffectorColorConstant::setColor (const PackedRgb& newColor)
{
color = newColor;
}
//-------------------------------------------------------------------
unsigned AffectorColorConstant::getAffectedMaps() const
{
return TGM_color;
}
//-------------------------------------------------------------------
void AffectorColorConstant::affect (const float /*worldX*/, const float /*worldZ*/, const int x, const int z, const float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const
{
if (amount > 0.f)
{
const PackedRgb oldColor = generatorChunkData.colorMap->getData (x, z);
const PackedRgb newColor = computeColor (oldColor, color, operation, amount);
generatorChunkData.colorMap->setData (x, z, newColor);
}
}
//-------------------------------------------------------------------
void AffectorColorConstant::load (Iff& iff)
{
switch (iff.getCurrentName ())
{
case TAG_0000:
load_0000 (iff);
break;
default:
{
char tagBuffer [5];
ConvertTagToString (iff.getCurrentName (), tagBuffer);
char buffer [128];
iff.formatLocation (buffer, sizeof (buffer));
DEBUG_FATAL (true, ("invalid AffectorColorConstant version %s/%s", buffer, tagBuffer));
}
break;
}
}
//-------------------------------------------------------------------
void AffectorColorConstant::load_0000 (Iff& iff)
{
iff.enterForm (TAG_0000);
//-- load the base data
LayerItem::load (iff);
//-- load specific data
iff.enterChunk (TAG_DATA);
int newOperation = iff.read_int32 ();
DEBUG_FATAL (newOperation < 0 || newOperation >= TGO_COUNT, ("operation out of bounds for %s (%i)", getName (), newOperation));
operation = static_cast<TerrainGeneratorOperation> (newOperation);
color.r = iff.read_uint8 ();
color.g = iff.read_uint8 ();
color.b = iff.read_uint8 ();
iff.exitChunk (TAG_DATA);
iff.exitForm (TAG_0000);
}
//-------------------------------------------------------------------
void AffectorColorConstant::save (Iff& iff) const
{
iff.insertForm (TAG_0000);
//-- save the base
LayerItem::save (iff);
//-- save specific data
iff.insertChunk (TAG_DATA);
iff.insertChunkData (static_cast<int32> (operation));
iff.insertChunkData (color.r);
iff.insertChunkData (color.g);
iff.insertChunkData (color.b);
iff.exitChunk (TAG_DATA);
iff.exitForm (TAG_0000);
}
//-------------------------------------------------------------------
//
// AffectorColorRampHeight
//
AffectorColorRampHeight::AffectorColorRampHeight () :
TerrainGenerator::Affector (TAG_ACRH, TGAT_colorRampHeight),
image (0),
operation (TGO_replace),
lowHeight (0),
highHeight (0),
imageName (NON_NULL (new std::string))
{
}
//-------------------------------------------------------------------
AffectorColorRampHeight::~AffectorColorRampHeight ()
{
if (image)
{
delete image;
image = 0;
}
delete imageName;
imageName = 0;
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::setOperation (const TerrainGeneratorOperation newOperation)
{
operation = newOperation;
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::setLowHeight (const float newLowHeight)
{
lowHeight = newLowHeight;
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::setHighHeight (const float newHighHeight)
{
highHeight = newHighHeight;
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::setImage (const std::string& newImageName)
{
*imageName = newImageName;
if (image)
delete image;
image = ImageFormatList::loadImage (imageName->c_str ());
if (image)
{
DEBUG_WARNING (image->getHeight () != 1, ("height != 1"));
DEBUG_WARNING (! (image->getPixelFormat () == Image::PF_bgr_888 || image->getPixelFormat () == Image::PF_rgb_888), ("image is not in rgb or bgr format"));
}
}
//-------------------------------------------------------------------
static const PackedRgb getPixel (const Image* image, const int x, const int y)
{
PackedRgb result = PackedRgb::solidBlack;
if (x >= 0 && x < image->getWidth () &&
y >= 0 && y < image->getHeight ())
{
static Mutex mutex;
mutex.enter ();
const uint8* data = image->lockReadOnly ();
data += y * image->getStride () + x * image->getBytesPerPixel ();
if (image->getPixelFormat () == Image::PF_bgr_888)
{
result.b = *data++;
result.g = *data++;
result.r = *data++;
}
else
{
result.r = *data++;
result.g = *data++;
result.b = *data++;
}
image->unlock ();
mutex.leave ();
}
return result;
}
//-------------------------------------------------------------------
unsigned AffectorColorRampHeight::getAffectedMaps() const
{
return TGM_color;
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::affect (const float /*worldX*/, const float /*worldZ*/, const int x, const int z, const float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const
{
if (image && amount > 0.f)
{
const float height = generatorChunkData.heightMap->getData (x, z);
if (WithinRangeInclusiveInclusive (lowHeight, height, highHeight))
{
const PackedRgb oldColor = generatorChunkData.colorMap->getData (x, z);
const float t = (height - lowHeight) / (highHeight - lowHeight);
const PackedRgb color = getPixel (image, static_cast<int> (t * (image->getWidth () - 1)), 0);
const PackedRgb newColor = computeColor (oldColor, color, operation, amount);
generatorChunkData.colorMap->setData (x, z, newColor);
}
}
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::load (Iff& iff)
{
switch (iff.getCurrentName ())
{
case TAG_0000:
load_0000 (iff);
break;
default:
{
char tagBuffer [5];
ConvertTagToString (iff.getCurrentName (), tagBuffer);
char buffer [128];
iff.formatLocation (buffer, sizeof (buffer));
DEBUG_FATAL (true, ("invalid AffectorColorRampHeight version %s/%s", buffer, tagBuffer));
}
break;
}
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::load_0000 (Iff& iff)
{
iff.enterForm (TAG_0000);
//-- load the base data
LayerItem::load (iff);
//-- load specific data
iff.enterChunk (TAG_DATA);
int newOperation = iff.read_int32 ();
DEBUG_FATAL (newOperation < 0 || newOperation >= TGO_COUNT, ("operation out of bounds for %s (%i)", getName (), newOperation));
operation = static_cast<TerrainGeneratorOperation> (newOperation);
lowHeight = iff.read_float ();
highHeight = iff.read_float ();
char* newImageName = iff.read_string ();
setImage (newImageName);
delete [] newImageName;
iff.exitChunk (TAG_DATA);
iff.exitForm (TAG_0000);
}
//-------------------------------------------------------------------
void AffectorColorRampHeight::save (Iff& iff) const
{
iff.insertForm (TAG_0000);
//-- save the base
LayerItem::save (iff);
//-- save specific data
iff.insertChunk (TAG_DATA);
iff.insertChunkData (static_cast<int32> (operation));
iff.insertChunkData (lowHeight);
iff.insertChunkData (highHeight);
iff.insertChunkString (imageName->c_str ());
iff.exitChunk (TAG_DATA);
iff.exitForm (TAG_0000);
}
//-------------------------------------------------------------------
//
// AffectorColorRampFractal
//
AffectorColorRampFractal::AffectorColorRampFractal () :
TerrainGenerator::Affector (TAG_ACRF, TGAT_colorRampFractal),
m_multiFractal (0),
m_cachedFamilyId (-1),
image (0),
m_familyId (0),
operation (TGO_replace),
imageName (NON_NULL (new std::string))
{
}
//-------------------------------------------------------------------
AffectorColorRampFractal::~AffectorColorRampFractal ()
{
if (image)
{
delete image;
image = 0;
}
delete imageName;
imageName = 0;
m_multiFractal = 0;
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::setFamilyId (const int newFamilyId)
{
m_familyId = newFamilyId;
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::setOperation (const TerrainGeneratorOperation newOperation)
{
operation = newOperation;
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::setImage (const std::string& newImageName)
{
*imageName = newImageName;
if (image)
delete image;
image = ImageFormatList::loadImage (imageName->c_str ());
if (image)
{
DEBUG_WARNING (image->getHeight () != 1, ("height != 1"));
DEBUG_WARNING (! (image->getPixelFormat () == Image::PF_bgr_888 || image->getPixelFormat () == Image::PF_rgb_888), ("image is not in rgb or bgr format"));
}
}
//-------------------------------------------------------------------
unsigned AffectorColorRampFractal::getAffectedMaps() const
{
return TGM_color;
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::affect (const float worldX, const float worldZ, const int x, const int z, const float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const
{
if (image && amount > 0.f)
{
if (m_cachedFamilyId != m_familyId)
{
m_cachedFamilyId = m_familyId;
m_multiFractal = generatorChunkData.fractalGroup->getFamilyMultiFractal (m_familyId);
}
NOT_NULL (m_multiFractal);
const PackedRgb oldColor = generatorChunkData.colorMap->getData (x, z);
const float t = m_multiFractal->getValueCache (worldX, worldZ, x, z);
const PackedRgb color = getPixel (image, static_cast<int> (t * (image->getWidth () - 1)), 0);
const PackedRgb newColor = computeColor (oldColor, color, operation, amount);
generatorChunkData.colorMap->setData (x, z, newColor);
}
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::load (Iff& iff, FractalGroup& fractalGroup)
{
switch (iff.getCurrentName ())
{
case TAG_0000:
load_0000 (iff, fractalGroup);
break;
case TAG_0001:
load_0001 (iff);
break;
default:
{
char tagBuffer [5];
ConvertTagToString (iff.getCurrentName (), tagBuffer);
char buffer [128];
iff.formatLocation (buffer, sizeof (buffer));
DEBUG_FATAL (true, ("invalid AffectorColorRampFractal version %s/%s", buffer, tagBuffer));
}
break;
}
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::load_0000 (Iff& iff, FractalGroup& fractalGroup)
{
iff.enterForm (TAG_0000);
//-- load the base data
LayerItem::load (iff);
//-- load specific data
iff.enterForm (TAG_DATA);
//-- load the fractal settings
MultiFractal multiFractal;
MultiFractalReaderWriter::load (iff, multiFractal);
setFamilyId (fractalGroup.createFamily (&multiFractal, getName ()));
//-- load parameters
iff.enterChunk (TAG_PARM);
int newOperation = iff.read_int32 ();
DEBUG_FATAL (newOperation < 0 || newOperation >= TGO_COUNT, ("operation out of bounds for %s (%i)", getName (), newOperation));
operation = static_cast<TerrainGeneratorOperation> (newOperation);
char* newImageName = iff.read_string ();
setImage (newImageName);
delete [] newImageName;
iff.exitChunk ();
iff.exitForm (TAG_DATA);
iff.exitForm (TAG_0000);
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::load_0001 (Iff& iff)
{
iff.enterForm (TAG_0001);
//-- load the base data
LayerItem::load (iff);
//-- load specific data
iff.enterForm (TAG_DATA);
//-- load parameters
iff.enterChunk (TAG_PARM);
setFamilyId (iff.read_int32 ());
int newOperation = iff.read_int32 ();
DEBUG_FATAL (newOperation < 0 || newOperation >= TGO_COUNT, ("operation out of bounds for %s (%i)", getName (), newOperation));
setOperation (static_cast<TerrainGeneratorOperation> (newOperation));
char* newImageName = iff.read_string ();
setImage (newImageName);
delete [] newImageName;
iff.exitChunk ();
iff.exitForm (TAG_DATA);
iff.exitForm (TAG_0001);
}
//-------------------------------------------------------------------
void AffectorColorRampFractal::save (Iff& iff) const
{
iff.insertForm (TAG_0001);
//-- save the base
LayerItem::save (iff);
//-- save specific data
iff.insertForm (TAG_DATA);
iff.insertChunk (TAG (P,A,R,M));
iff.insertChunkData (getFamilyId ());
iff.insertChunkData (static_cast<int32> (getOperation ()));
iff.insertChunkString (getImageName ().c_str ());
iff.exitChunk ();
iff.exitForm ();
iff.exitForm ();
}
//-------------------------------------------------------------------
@@ -0,0 +1,213 @@
//===================================================================
//
// AffectorColor.h
// asommers 9-30-2000
//
// copyright 2000, verant interactive
//
//===================================================================
#ifndef INCLUDED_AffectorColor_H
#define INCLUDED_AffectorColor_H
//===================================================================
#include "sharedTerrain/TerrainGenerator.h"
class Image;
//===================================================================
class AffectorColorConstant : public TerrainGenerator::Affector
{
private:
//-- accessible
TerrainGeneratorOperation operation;
PackedRgb color;
private:
void load_0000 (Iff& iff);
private:
AffectorColorConstant (const AffectorColorConstant& rhs);
AffectorColorConstant& operator= (const AffectorColorConstant& rhs);
public:
AffectorColorConstant ();
virtual ~AffectorColorConstant ();
virtual void affect (float worldX, float worldZ, int x, int z, float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const;
virtual void load (Iff& iff);
virtual void save (Iff& iff) const;
virtual unsigned getAffectedMaps() const;
TerrainGeneratorOperation getOperation () const;
void setOperation (TerrainGeneratorOperation newOperation);
const PackedRgb& getColor () const;
void setColor (const PackedRgb& newColor);
};
//-------------------------------------------------------------------
inline TerrainGeneratorOperation AffectorColorConstant::getOperation () const
{
return operation;
}
//-------------------------------------------------------------------
inline const PackedRgb& AffectorColorConstant::getColor () const
{
return color;
}
//-------------------------------------------------------------------
class AffectorColorRampHeight : public TerrainGenerator::Affector
{
private:
//-- not accessible
Image* image;
//-- accessible
TerrainGeneratorOperation operation;
float lowHeight;
float highHeight;
std::string* imageName;
private:
void load_0000 (Iff& iff);
private:
AffectorColorRampHeight (const AffectorColorRampHeight& rhs);
AffectorColorRampHeight& operator= (const AffectorColorRampHeight& rhs);
public:
AffectorColorRampHeight ();
virtual ~AffectorColorRampHeight ();
virtual void affect (float worldX, float worldZ, int x, int z, float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const;
virtual void load (Iff& iff);
virtual void save (Iff& iff) const;
virtual unsigned getAffectedMaps() const;
TerrainGeneratorOperation getOperation () const;
void setOperation (TerrainGeneratorOperation newOperation);
float getLowHeight () const;
void setLowHeight (float newLowHeight);
float getHighHeight () const;
void setHighHeight (float newHighHeight);
const std::string& getImageName () const;
void setImage (const std::string& newImageName);
};
//-------------------------------------------------------------------
inline TerrainGeneratorOperation AffectorColorRampHeight::getOperation () const
{
return operation;
}
//-------------------------------------------------------------------
inline float AffectorColorRampHeight::getLowHeight () const
{
return lowHeight;
}
//-------------------------------------------------------------------
inline float AffectorColorRampHeight::getHighHeight () const
{
return highHeight;
}
//-------------------------------------------------------------------
inline const std::string& AffectorColorRampHeight::getImageName () const
{
return *imageName;
}
//-------------------------------------------------------------------
class AffectorColorRampFractal : public TerrainGenerator::Affector
{
private:
//-- not accessible
mutable const MultiFractal* m_multiFractal;
mutable int m_cachedFamilyId;
Image* image;
//-- accessible
int m_familyId;
TerrainGeneratorOperation operation;
std::string* imageName;
private:
void load_0000 (Iff& iff, FractalGroup& fractalGroup);
void load_0001 (Iff& iff);
private:
AffectorColorRampFractal (const AffectorColorRampFractal& rhs);
AffectorColorRampFractal& operator= (const AffectorColorRampFractal& rhs);
public:
AffectorColorRampFractal ();
virtual ~AffectorColorRampFractal ();
virtual void affect (float worldX, float worldZ, int x, int z, float amount, const TerrainGenerator::GeneratorChunkData& generatorChunkData) const;
virtual void load (Iff& iff, FractalGroup& fractalGroup);
virtual void save (Iff& iff) const;
virtual unsigned getAffectedMaps() const;
TerrainGeneratorOperation getOperation () const;
void setOperation (TerrainGeneratorOperation newOperation);
const std::string& getImageName () const;
void setImage (const std::string& newImageName);
int getFamilyId () const;
void setFamilyId (int id);
};
//-------------------------------------------------------------------
inline int AffectorColorRampFractal::getFamilyId () const
{
return m_familyId;
}
//-------------------------------------------------------------------
inline TerrainGeneratorOperation AffectorColorRampFractal::getOperation () const
{
return operation;
}
//-------------------------------------------------------------------
inline const std::string& AffectorColorRampFractal::getImageName () const
{
return *imageName;
}
//===================================================================
#endif

Some files were not shown because too many files have changed in this diff Show More