diff --git a/Engine/source/terrain/terrCell.cpp b/Engine/source/terrain/terrCell.cpp index d96811f45..ba1262df1 100644 --- a/Engine/source/terrain/terrCell.cpp +++ b/Engine/source/terrain/terrCell.cpp @@ -20,6 +20,11 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// +// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames +// Copyright (C) 2015 Faust Logic, Inc. +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// + #include "platform/platform.h" #include "terrain/terrCell.h" @@ -56,6 +61,7 @@ TerrCell::TerrCell() mIsInteriorOnly( false ) { dMemset( mChildren, 0, sizeof( mChildren ) ); + zode_vertexBuffer = 0; } TerrCell::~TerrCell() @@ -64,6 +70,7 @@ TerrCell::~TerrCell() for ( U32 i=0; i < 4; i++ ) SAFE_DELETE( mChildren[i] ); + deleteZodiacVertexBuffer(); } void TerrCell::createPrimBuffer( GFXPrimitiveBufferHandle *primBuffer ) @@ -582,6 +589,7 @@ void TerrCell::_updateVertexBuffer() AssertFatal( vbcounter == smVBSize, "bad" ); mVertexBuffer.unlock(); + deleteZodiacVertexBuffer(); } void TerrCell::_updatePrimitiveBuffer() @@ -1089,3 +1097,114 @@ void TerrCell::deleteMaterials() if ( mChildren[i] ) mChildren[i]->deleteMaterials(); } + +const Point3F* TerrCell::getZodiacVertexBuffer() +{ + if (!zode_vertexBuffer) + createZodiacVertexBuffer(); + return zode_vertexBuffer; +} + +void TerrCell::createZodiacPrimBuffer(U16** zode_primBuffer) +{ + if (*zode_primBuffer != 0) + delete [] *zode_primBuffer; + + *zode_primBuffer = new U16[TerrCell::smMinCellSize*TerrCell::smMinCellSize*6]; + + // Lock and fill it up! + U16* idxBuff = *zode_primBuffer; + U32 counter = 0; + U32 maxIndex = 0; + + for ( U32 y = 0; y < smMinCellSize; y++ ) + { + const U32 yTess = y % 2; + + for ( U32 x = 0; x < smMinCellSize; x++ ) + { + U32 index = ( y * smVBStride ) + x; + + const U32 xTess = x % 2; + + if ( ( xTess == 0 && yTess == 0 ) || + ( xTess != 0 && yTess != 0 ) ) + { + idxBuff[0] = index + 0; + idxBuff[1] = index + smVBStride; + idxBuff[2] = index + smVBStride + 1; + + idxBuff[3] = index + 0; + idxBuff[4] = index + smVBStride + 1; + idxBuff[5] = index + 1; + } + else + { + idxBuff[0] = index + 1; + idxBuff[1] = index; + idxBuff[2] = index + smVBStride; + + idxBuff[3] = index + 1; + idxBuff[4] = index + smVBStride; + idxBuff[5] = index + smVBStride + 1; + } + + idxBuff += 6; + maxIndex = index + 1 + smVBStride; + counter += 6; + } + } +} + +void TerrCell::createZodiacVertexBuffer() +{ + const F32 squareSize = mTerrain->getSquareSize(); + const U32 blockSize = mTerrain->getBlockSize(); + const U32 stepSize = mSize / smMinCellSize; + + if (zode_vertexBuffer) + delete [] zode_vertexBuffer; + + zode_vertexBuffer = new Point3F[smVBStride*smVBStride]; + + Point3F* vert = zode_vertexBuffer; + + Point2I gridPt; + Point2F point; + F32 height; + + const TerrainFile *file = mTerrain->getFile(); + + for ( U32 y = 0; y < smVBStride; y++ ) + { + for ( U32 x = 0; x < smVBStride; x++ ) + { + // We clamp here to keep the geometry from reading across + // one side of the height map to the other causing walls + // around the edges of the terrain. + gridPt.x = mClamp( mPoint.x + x * stepSize, 0, blockSize - 1 ); + gridPt.y = mClamp( mPoint.y + y * stepSize, 0, blockSize - 1 ); + + // Setup this point. + point.x = (F32)gridPt.x * squareSize; + point.y = (F32)gridPt.y * squareSize; + height = fixedToFloat( file->getHeight( gridPt.x, gridPt.y ) ); + + vert->x = point.x; + vert->y = point.y; + vert->z = height; + + ++vert; + } + } +} + +void TerrCell::deleteZodiacVertexBuffer() +{ + if (zode_vertexBuffer) + { + delete [] zode_vertexBuffer; + zode_vertexBuffer = 0; + } +} + diff --git a/Engine/source/terrain/terrCell.h b/Engine/source/terrain/terrCell.h index f736c2915..0b948cedd 100644 --- a/Engine/source/terrain/terrCell.h +++ b/Engine/source/terrain/terrCell.h @@ -20,6 +20,11 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// +// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames +// Copyright (C) 2015 Faust Logic, Inc. +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// + #ifndef _TERRCELL_H_ #define _TERRCELL_H_ @@ -226,6 +231,13 @@ public: void renderBounds() const; /// @} +protected: + Point3F* zode_vertexBuffer; + void createZodiacVertexBuffer(); +public: + const Point3F* getZodiacVertexBuffer(); + void deleteZodiacVertexBuffer(); + static void createZodiacPrimBuffer(U16** primBuffer); }; inline F32 TerrCell::getDistanceTo( const Point3F &pt ) const diff --git a/Engine/source/terrain/terrData.cpp b/Engine/source/terrain/terrData.cpp index eff266385..a97ec7e98 100644 --- a/Engine/source/terrain/terrData.cpp +++ b/Engine/source/terrain/terrData.cpp @@ -20,6 +20,11 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// +// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames +// Copyright (C) 2015 Faust Logic, Inc. +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// + #include "platform/platform.h" #include "terrain/terrData.h" @@ -200,6 +205,8 @@ TerrainBlock::TerrainBlock() { mTypeMask = TerrainObjectType | StaticObjectType | StaticShapeObjectType; mNetFlags.set(Ghostable | ScopeAlways); + mIgnoreZodiacs = false; + zode_primBuffer = 0; } @@ -218,6 +225,7 @@ TerrainBlock::~TerrainBlock() if (editor) editor->detachTerrain(this); #endif + deleteZodiacPrimitiveBuffer(); } void TerrainBlock::_onTextureEvent( GFXTexCallbackCode code ) @@ -1006,6 +1014,7 @@ void TerrainBlock::_rebuildQuadtree() // Build the shared PrimitiveBuffer. mCell->createPrimBuffer( &mPrimBuffer ); + deleteZodiacPrimitiveBuffer(); } void TerrainBlock::_updatePhysics() @@ -1148,6 +1157,9 @@ void TerrainBlock::initPersistFields() endGroup( "Misc" ); + addGroup("AFX"); + addField("ignoreZodiacs", TypeBool, Offset(mIgnoreZodiacs, TerrainBlock)); + endGroup("AFX"); Parent::initPersistFields(); removeField( "scale" ); @@ -1198,6 +1210,7 @@ U32 TerrainBlock::packUpdate(NetConnection* con, U32 mask, BitStream *stream) stream->write( mScreenError ); stream->writeInt(mBaseTexFormat, 32); + stream->writeFlag(mIgnoreZodiacs); return retMask; } @@ -1267,6 +1280,7 @@ void TerrainBlock::unpackUpdate(NetConnection* con, BitStream *stream) stream->read( &mScreenError ); mBaseTexFormat = (BaseTexFormat)stream->readInt(32); + mIgnoreZodiacs = stream->readFlag(); } void TerrainBlock::getMinMaxHeight( F32 *minHeight, F32 *maxHeight ) const @@ -1405,3 +1419,19 @@ DefineConsoleFunction( getTerrainHeightBelowPosition, F32, (const char* ptOrX, c return height; } +const U16* TerrainBlock::getZodiacPrimitiveBuffer() +{ + if (!zode_primBuffer && !mIgnoreZodiacs) + TerrCell::createZodiacPrimBuffer(&zode_primBuffer); + return zode_primBuffer; +} + +void TerrainBlock::deleteZodiacPrimitiveBuffer() +{ + if (zode_primBuffer != 0) + { + delete [] zode_primBuffer; + zode_primBuffer = 0; + } +} + diff --git a/Engine/source/terrain/terrData.h b/Engine/source/terrain/terrData.h index f7b3fb179..87f994a03 100644 --- a/Engine/source/terrain/terrData.h +++ b/Engine/source/terrain/terrData.h @@ -20,6 +20,11 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// +// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames +// Copyright (C) 2015 Faust Logic, Inc. +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// + #ifndef _TERRDATA_H_ #define _TERRDATA_H_ @@ -457,6 +462,13 @@ public: U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream); void unpackUpdate(NetConnection *conn, BitStream *stream); void inspectPostApply(); + +protected: + bool mIgnoreZodiacs; + U16* zode_primBuffer; + void deleteZodiacPrimitiveBuffer(); +public: + const U16* getZodiacPrimitiveBuffer(); }; #endif // _TERRDATA_H_ diff --git a/Engine/source/terrain/terrRender.cpp b/Engine/source/terrain/terrRender.cpp index be67d58eb..15c294611 100644 --- a/Engine/source/terrain/terrRender.cpp +++ b/Engine/source/terrain/terrRender.cpp @@ -20,6 +20,11 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// +// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames +// Copyright (C) 2015 Faust Logic, Inc. +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// + #include "platform/platform.h" #include "terrain/terrRender.h" @@ -45,6 +50,8 @@ #include "gfx/gfxDrawUtil.h" +#include "afx/arcaneFX.h" +#include "afx/ce/afxZodiacMgr.h" #include "gfx/gfxTransformSaver.h" #include "gfx/bitmap/gBitmap.h" #include "gfx/bitmap/ddsFile.h" @@ -421,6 +428,7 @@ void TerrainBlock::_renderBlock( SceneRenderState *state ) if ( isColorDrawPass ) lm = LIGHTMGR; + bool has_zodiacs = afxZodiacMgr::doesBlockContainZodiacs(state, this); for ( U32 i=0; i < renderCells.size(); i++ ) { TerrCell *cell = renderCells[i]; @@ -483,6 +491,8 @@ void TerrainBlock::_renderBlock( SceneRenderState *state ) inst->defaultKey = (U32)cell->getMaterials(); + if (has_zodiacs) + afxZodiacMgr::renderTerrainZodiacs(state, this, cell); // Submit it for rendering. renderPass->addInst( inst ); } diff --git a/Engine/source/terrain/terrRender.h b/Engine/source/terrain/terrRender.h index 0f4bfbc9a..ea67c0ca2 100644 --- a/Engine/source/terrain/terrRender.h +++ b/Engine/source/terrain/terrRender.h @@ -20,6 +20,16 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// +// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames +// Copyright (C) 2015 Faust Logic, Inc. +// +// The terrain implementation of zodiacs is largely contained in +// afxZodiac.[h,cpp], however, some changes are required to the terrain +// code. Structures EmitChunk and SquareStackNode now contain an +// afxZodiacBitmask for keeping track of zodiac intersections. +//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// + #ifndef _TERRRENDER_H_ #define _TERRRENDER_H_ @@ -27,6 +37,7 @@ #include "terrain/terrData.h" #endif +#include "afx/ce/afxZodiacDefs.h" enum TerrConstants : U32 { MaxClipPlanes = 8, ///< left, right, top, bottom - don't need far tho...