Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "W3DDevice/GameClient/WorldHeightMap.h"

#define MAX_ENABLED_DYNAMIC_LIGHTS 20
typedef UnsignedByte HeightSampleType; //type of data to store in heightmap
class W3DTreeBuffer;
class W3DBibBuffer;
class W3DRoadBuffer;
Expand Down Expand Up @@ -133,7 +132,7 @@ class BaseHeightMapRenderObjClass : public RenderObjClass, public DX8_CleanupHoo
}


UnsignedByte getClipHeight(Int x, Int y) const
HeightSampleType getClipHeight(Int x, Int y) const
{
Int xextent = m_map->getXExtent() - 1;
Int yextent = m_map->getYExtent() - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include "Common/STLTypedefs.h"
typedef std::vector<ICoord2D> VecICoord2D;

typedef UnsignedShort HeightSampleType; //type of data to store in heightmap, changed to short (2bytes) to allow more height difference

/** MapObject class
Not ref counted. Do not store pointers to this class. */
Expand Down Expand Up @@ -117,7 +117,7 @@ class WorldHeightMap : public RefCountClass,
Int m_borderSize; ///< Non-playable border area.
VecICoord2D m_boundaries; ///< the in-game boundaries
Int m_dataSize; ///< size of m_data.
UnsignedByte *m_data; ///< array of z(height) values in the height map.
HeightSampleType *m_data; ///< array of z(height) values in the height map.

UnsignedByte *m_seismicUpdateFlag; ///< array of bits to prevent ovelapping physics-update regions from doubling effects on shared cells
UnsignedInt m_seismicUpdateWidth; ///< width of the array holding SeismicUpdateFlags
Expand Down Expand Up @@ -223,7 +223,7 @@ class WorldHeightMap : public RefCountClass,
static Int getMinHeightValue(void) {return K_MIN_HEIGHT;}
static Int getMaxHeightValue(void) {return K_MAX_HEIGHT;}

UnsignedByte *getDataPtr(void) {return m_data;}
HeightSampleType *getDataPtr(void) {return m_data;}


Int getXExtent(void) {return m_width;} ///<number of vertices in x
Expand All @@ -239,10 +239,10 @@ class WorldHeightMap : public RefCountClass,
virtual Int getBorderSize(void) {return m_borderSize;}
Int getBorderSizeInline(void) const { return m_borderSize; }
/// Get height with the offset that HeightMapRenderObjClass uses built in.
UnsignedByte getDisplayHeight(Int x, Int y) { return m_data[x+m_drawOriginX+m_width*(y+m_drawOriginY)];}
HeightSampleType getDisplayHeight(Int x, Int y) { return m_data[x+m_drawOriginX+m_width*(y+m_drawOriginY)];}

/// Get height in normal coordinates.
UnsignedByte getHeight(Int xIndex, Int yIndex)
HeightSampleType getHeight(Int xIndex, Int yIndex)
{
Int ndx = (yIndex*m_width)+xIndex;
if ((ndx>=0) && (ndx<m_dataSize) && m_data)
Expand Down Expand Up @@ -305,7 +305,7 @@ class WorldHeightMap : public RefCountClass,
UnsignedByte *getRGBAlphaDataForWidth(Int width, TBlendTileInfo *pBlend);

public: // modify height value
void setRawHeight(Int xIndex, Int yIndex, UnsignedByte height) {
void setRawHeight(Int xIndex, Int yIndex, HeightSampleType height) {
Int ndx = (yIndex*m_width)+xIndex;
if ((ndx>=0) && (ndx<m_dataSize) && m_data) m_data[ndx]=height;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ Real BaseHeightMapRenderObjClass::getHeightMapHeight(Real x, Real y, Coord3D* no
return getClipHeight(ix, iy) * MAP_HEIGHT_SCALE;
}

const UnsignedByte* data = logicHeightMap->getDataPtr();
const HeightSampleType* data = logicHeightMap->getDataPtr();
int idx = ix + iy*xExtent;
float p0 = data[idx];
float p2 = data[idx + xExtent + 1];
Expand Down Expand Up @@ -1074,7 +1074,7 @@ Bool BaseHeightMapRenderObjClass::isClearLineOfSight(const Coord3D& pos, const C
Real zinc = dz * nsInv;

Bool result = true;
const UnsignedByte* data = logicHeightMap->getDataPtr();
const HeightSampleType* data = logicHeightMap->getDataPtr();
Int xExtent = logicHeightMap->getXExtent();
Int yExtent = logicHeightMap->getYExtent();
for (Int curpixel = 0; curpixel < numpixels; curpixel++)
Expand Down Expand Up @@ -1221,7 +1221,7 @@ Real BaseHeightMapRenderObjClass::getMaxCellHeight(Real x, Real y) const
if (iY >= (logicHeightMap->getYExtent()-1)) {
iY = logicHeightMap->getYExtent()-2;
}
UnsignedByte *data = logicHeightMap->getDataPtr();
HeightSampleType *data = logicHeightMap->getDataPtr();
p0=data[iX+iY*logicHeightMap->getXExtent()]*MAP_HEIGHT_SCALE;
p1=data[(iX+offset)+iY*logicHeightMap->getXExtent()]*MAP_HEIGHT_SCALE;
p2=data[(iX+offset)+(iY+offset)*logicHeightMap->getXExtent()]*MAP_HEIGHT_SCALE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ void HeightMapRenderObjClass::renderExtraBlendTiles(void)

if (!vb || !ib) return;

const UnsignedByte* data = m_map->getDataPtr();
const HeightSampleType* data = m_map->getDataPtr();

//Loop over visible terrain and extract all the tiles that need extra blend
Int drawEdgeY=m_map->getDrawOrgY()+m_map->getDrawHeight()-1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ void W3DTerrainVisual::xfer( Xfer *xfer )

// Write out the terrain height data.
if (version >= 2) {
UnsignedByte *data = m_logicHeightMap->getDataPtr();
Int len = m_logicHeightMap->getXExtent()*m_logicHeightMap->getYExtent();
HeightSampleType *data = m_logicHeightMap->getDataPtr();
Int len = m_logicHeightMap->getXExtent()*m_logicHeightMap->getYExtent() * sizeof(HeightSampleType);
Int xferLen = len;
xfer->xferInt(&xferLen);
if (len!=xferLen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "Common/WellKnownKeys.h"
#include "Common/MapData.h"

#include "GameLogic/PolygonTrigger.h"
#include "GameLogic/SidesList.h"
Expand Down Expand Up @@ -878,7 +879,7 @@ Bool WorldHeightMap::ParseHeightMapData(DataChunkInput &file, DataChunkInfo *inf
}

m_dataSize = file.readInt();
m_data = MSGNEW("WorldHeightMap_ParseHeightMapData") UnsignedByte[m_dataSize];
m_data = MSGNEW("WorldHeightMap_ParseHeightMapData") HeightSampleType[m_dataSize];
if (m_dataSize <= 0 || (m_dataSize != (m_width*m_height))) {
throw ERROR_CORRUPT_FILE_FORMAT ;
}
Expand All @@ -891,8 +892,14 @@ Bool WorldHeightMap::ParseHeightMapData(DataChunkInput &file, DataChunkInfo *inf
m_seismicZVelocities = MSGNEW("WorldHeightMap_ParseHeightMapData _ zvelocities allocated") Real[m_dataSize];
fillSeismicZVelocities( 0 );

//load as bytes first
std::vector<UnsignedByte> loaded_data(m_dataSize);

file.readArrayOfBytes((char *)&loaded_data.at(0), m_dataSize);
for (size_t i = 0; i < loaded_data.size(); i++) {
m_data[i] = static_cast<HeightSampleType>(std::round(loaded_data[i]* TheMapData->m_HeightmapScale));
}

file.readArrayOfBytes((char *)m_data, m_dataSize);
// Resize me.
if (info->version == K_HEIGHT_MAP_VERSION_1) {
Int newWidth = (m_width+1)/2;
Expand Down Expand Up @@ -952,11 +959,18 @@ Bool WorldHeightMap::ParseSizeOnly(DataChunkInput &file, DataChunkInfo *info, vo
}

m_dataSize = file.readInt();
m_data = MSGNEW("WorldHeightMap_ParseSizeOnly") UnsignedByte[m_dataSize];
m_data = MSGNEW("WorldHeightMap_ParseSizeOnly") HeightSampleType[m_dataSize];
if (m_dataSize <= 0 || (m_dataSize != (m_width*m_height))) {
throw ERROR_CORRUPT_FILE_FORMAT ;
}
file.readArrayOfBytes((char *)m_data, m_dataSize);

//load as bytes first
std::vector<UnsignedByte> loaded_data(m_dataSize);
file.readArrayOfBytes((char*)&loaded_data.at(0), m_dataSize);
for (size_t i = 0; i < loaded_data.size(); i++) {
m_data[i] = static_cast<HeightSampleType>(std::round(loaded_data[i] * TheMapData->m_HeightmapScale));
}

// Resize me.
if (info->version == K_HEIGHT_MAP_VERSION_1) {
Int newWidth = (m_width+1)/2;
Expand Down
8 changes: 4 additions & 4 deletions Generals/Code/Tools/WorldBuilder/src/FeatherTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void FeatherTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorl
m_htMapFeatherCopy = pDoc->GetHeightMap()->duplicate();
m_htMapRateCopy = pDoc->GetHeightMap()->duplicate();
Int size = m_htMapRateCopy->getXExtent() * m_htMapRateCopy->getYExtent();
UnsignedByte *pData = m_htMapRateCopy->getDataPtr();
HeightSampleType *pData = m_htMapRateCopy->getDataPtr();
Int i;
for (i=0; i<size; i++) {
*pData++ = 0;
Expand Down Expand Up @@ -234,9 +234,9 @@ void FeatherTool::mouseMoved(TTrackingMode m, CPoint viewPt, WbView* pView, CWor
pDoc->updateHeightMap(m_htMapEditCopy, true, partialRange);
if (redoRate) {
Int size = m_htMapRateCopy->getXExtent() * m_htMapRateCopy->getYExtent();
UnsignedByte *pData = m_htMapRateCopy->getDataPtr();
UnsignedByte *pFeather = m_htMapFeatherCopy->getDataPtr();
UnsignedByte *pEdit = m_htMapEditCopy->getDataPtr();
HeightSampleType *pData = m_htMapRateCopy->getDataPtr();
HeightSampleType *pFeather = m_htMapFeatherCopy->getDataPtr();
HeightSampleType *pEdit = m_htMapEditCopy->getDataPtr();
Int i;
for (i=0; i<size; i++) {
*pData++ = 0;
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ set(GAMEENGINE_SRC
Include/Common/UserPreferences.h
Include/Common/version.h
Include/Common/WellKnownKeys.h
Include/Common/MapData.h
# Include/Common/WorkerProcess.h
# Include/Common/Xfer.h
# Include/Common/XferCRC.h
Expand Down Expand Up @@ -602,6 +603,7 @@ set(GAMEENGINE_SRC
Source/Common/GameLOD.cpp
Source/Common/GameMain.cpp
Source/Common/GlobalData.cpp
Source/Common/MapData.cpp
Source/Common/INI/INI.cpp
Source/Common/INI/INIAiData.cpp
Source/Common/INI/INIAnimation.cpp
Expand Down
3 changes: 2 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/INI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ enum INILoadType CPP_11(: Int)
INI_LOAD_INVALID, ///< invalid load type
INI_LOAD_OVERWRITE, ///< create new or load *over* existing data instance
INI_LOAD_CREATE_OVERRIDES, ///< create new or load into *new* override data instance
INI_LOAD_MULTIFILE ///< create new or continue loading into existing data instance.
INI_LOAD_MULTIFILE, ///< create new or continue loading into existing data instance.
INI_LOAD_MAPDATA_ONLY ///< used by WorldBuilder to only load MapData from map.ini
};

//-------------------------------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/MapData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// FILE: MapData.h /////////////////////////////////////////////////////////////////////////////
// used to store extra map metadata via map.ini, is reset before loading a map
///////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once


class MapData : public SubsystemInterface
{

public:

MapData();
virtual ~MapData() = default;

virtual void init();
virtual void reset();
virtual void update() {};



static void parseMapDataDefinition( INI* ini );
static MapData* createMapDataSystem(void);

Real m_HeightmapScale;
Bool m_enableShips;

private:
static const FieldParse s_MapDataFieldParseTable[];
};

// singleton
extern MapData* TheWriteableMapData;

inline const MapData* const& TheMapData = TheWriteableMapData;

inline MapData* MapData::createMapDataSystem(void) { return NEW MapData; }
4 changes: 3 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ class ThingTemplate : public Overridable

const WeaponTemplateSetVector& getWeaponTemplateSets(void) const {return m_weaponTemplateSets;}

Int getMaxPathFindingCellRadius(void) const { return static_cast<Int>(m_maxPathfindingCellRadius); };

protected:

//
Expand Down Expand Up @@ -823,7 +825,7 @@ class ThingTemplate : public Overridable
UnsignedByte m_crusherLevel; ///< crusher > crushable level to actually crush
UnsignedByte m_crushableLevel; ///< Specifies the level of crushability (must be hit by a crusher greater than this to crush me).
Byte m_ammoPipsStyle; ///< How ammo pips are displayed for this thing

UnsignedByte m_maxPathfindingCellRadius; ///< Limit cells radius for pathfinding, defaults to 2, can be increased for large units
};

//-----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/Locomotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ enum LocomotorBehaviorZ CPP_11(: Int)
Z_FIXED_ABSOLUTE_HEIGHT, // stays fixed at absolute height, regardless of physics
Z_RELATIVE_TO_GROUND_AND_BUILDINGS, // stays fixed at surface-rel height including buildings, regardless of physics
Z_SMOOTH_RELATIVE_TO_HIGHEST_LAYER, // try to follow a height relative to the highest layer.
Z_SEA_SURFACE_RELATIVE_HEIGHT, //try to follow a specific height relative to terrain / water height, optimized for submarines

LOCOMOTOR_BEHAVIOR_Z_COUNT
};
Expand All @@ -116,6 +117,7 @@ static const char *const TheLocomotorBehaviorZNames[] =
"FIXED_ABSOLUTE_HEIGHT",
"FIXED_RELATIVE_TO_GROUND_AND_BUILDINGS",
"RELATIVE_TO_HIGHEST_LAYER",
"SEA_SURFACE_RELATIVE_HEIGHT",

NULL
};
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "Common/GameLOD.h"
#include "Common/Registry.h"
#include "Common/GameCommon.h" // FOR THE ALLOW_DEBUG_CHEATS_IN_RELEASE #define
#include "Common/MapData.h"

#include "GameLogic/Armor.h"
#include "GameLogic/AI.h"
Expand Down Expand Up @@ -451,6 +452,7 @@ void GameEngine::init()
initSubsystem(TheWritableGlobalData, "TheWritableGlobalData", TheWritableGlobalData, &xferCRC, "Data\\INI\\Default\\GameData", "Data\\INI\\GameData");
TheWritableGlobalData->parseCustomDefinition();

initSubsystem(TheWriteableMapData, "TheWriteableMapData", MapData::createMapDataSystem(), &xferCRC);

#ifdef DUMP_PERF_STATS///////////////////////////////////////////////////////////////////////////
GetPrecisionTimer(&endTime64);//////////////////////////////////////////////////////////////////
Expand Down
6 changes: 5 additions & 1 deletion GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ UnsignedInt INI::load( AsciiString filename, INILoadType loadType, Xfer *pXfer,

// the first word is the type of data we're processing
const char *token = strtok( m_buffer, m_seps );
if( token )

// skip non MapData blocks if loading
bool skip = (loadType == INI_LOAD_MAPDATA_ONLY) && (strcmp(token, "MapData") != 0);

if( token && !skip)
{
INIBlockParse parse = findBlockParse(token);
if (parse)
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/INI/INIMapData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine

#include "Common/INI.h"
#include "Common/MapData.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
Expand All @@ -45,6 +46,7 @@
//-------------------------------------------------------------------------------------------------
void INI::parseMapDataDefinition( INI* ini )
{
MapData::parseMapDataDefinition(ini);
}


43 changes: 43 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/MapData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//////////////////////////////////////////
// FILE: MapData.cpp
// Store some extra metadata about the current map
///////////////////////////////////////////////////////////////////////////////////////////////////

// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine

#include "Common/MapData.h"

// PUBLIC DATA ////////////////////////////////////////////////////////////////////////////////////
MapData* TheWriteableMapData = NULL; ///< The current map data singleton

///////////////////////////////////////////////////////////////////////////////////////////////////
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/*static*/ const FieldParse MapData::s_MapDataFieldParseTable[] =
{
{ "HeightMapScale", INI::parseReal, NULL, offsetof( MapData, m_HeightmapScale) },
{ "EnableShips", INI::parseBool, NULL, offsetof( MapData, m_enableShips) },
{ NULL, NULL, NULL, 0 } // keep this last

};

MapData::MapData() : SubsystemInterface()
{
m_HeightmapScale = 1.0f;
m_enableShips = false;
}

void MapData::init() {
m_HeightmapScale = 1.0f;
m_enableShips = false;
}

void MapData::reset() {
m_HeightmapScale = 1.0f;
m_enableShips = false;
}

void MapData::parseMapDataDefinition(INI* ini) {
ini->initFromINI(TheWriteableMapData, s_MapDataFieldParseTable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,9 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
Short totalSamples = sampleData.waterSamples + sampleData.landSamples;
Real threshold_water = totalSamples * 0.6f;
Real threshold_land = 1.0f;
Real max_land = totalSamples * 0.2f;

if (static_cast<Real>(sampleData.waterSamples) < threshold_water || static_cast<Real>(sampleData.landSamples) < threshold_land) {
if (static_cast<Real>(sampleData.waterSamples) < threshold_water || static_cast<Real>(sampleData.landSamples) < threshold_land || static_cast<Real>(sampleData.landSamples) > max_land) {
return LBC_RESTRICTED_TERRAIN;
}

Expand Down
Loading