📄 terrdata.h
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _TERRDATA_H_
#define _TERRDATA_H_
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
#ifndef _MPOINT_H_
#include "math/mPoint.h"
#endif
#ifndef _SCENEOBJECT_H_
#include "sim/sceneObject.h"
#endif
#ifndef _RESMANAGER_H_
#include "core/resManager.h"
#endif
#ifndef _MATERIALLIST_H_
#include "dgl/materialList.h"
#endif
#ifndef _GTEXMANAGER_H_
#include "dgl/gTexManager.h"
#endif
#ifndef _CONVEX_H_
#include "collision/convex.h"
#endif
#ifdef TGE_RPG /// TGE_TerrainScene
#ifndef _TERRSCENE_H_
#include "terrain/terrScene.h"
#endif
#endif
class GBitmap;
class TerrainFile;
class TerrainBlock;
class ColorF;
class Blender;
#ifdef TGE_RPG /// TGE_TerrainScene
class TerrainScene;
#endif
//--------------------------------------------------------------------------
class TerrainConvex: public Convex
{
friend class TerrainBlock;
TerrainConvex *square; ///< Alternate convex if square is concave
bool halfA; ///< Which half of square
bool split45; ///< Square split pattern
U32 squareId; ///< Used to match squares
U32 material;
Point3F point[4]; ///< 3-4 vertices
VectorF normal[2];
Box3F box; ///< Bounding box
public:
TerrainConvex() { mType = TerrainConvexType; }
TerrainConvex(const TerrainConvex& cv) {
mType = TerrainConvexType;
// Only a partial copy...
mObject = cv.mObject;
split45 = cv.split45;
squareId = cv.squareId;
material = cv.material;
point[0] = cv.point[0];
point[1] = cv.point[1];
point[2] = cv.point[2];
point[3] = cv.point[3];
normal[0] = cv.normal[0];
normal[1] = cv.normal[1];
box = cv.box;
}
Box3F getBoundingBox() const;
Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
Point3F support(const VectorF& v) const;
void getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf);
void getPolyList(AbstractPolyList* list);
};
//--------------------------------------------------------------------------
struct GridSquare
{
U16 minHeight;
U16 maxHeight;
U16 heightDeviance;
U16 flags;
enum
{
Split45 = 1,
Empty = 2,
HasEmpty = 4,
MaterialShift = 3,
MaterialStart = 8,
Material0 = 8,
Material1 = 16,
Material2 = 32,
Material3 = 64,
};
};
struct GridChunk
{
U16 heightDeviance[3]; // levels 0-1, 1-2, 2
U16 emptyFlags;
};
//--------------------------------------------------------------------------
class TerrainBlock : public SceneObject
{
typedef SceneObject Parent;
public:
struct Material
{
enum Flags
{
Plain = 0,
Rotate = 1,
FlipX = 2,
FlipXRotate = 3,
FlipY = 4,
FlipYRotate = 5,
FlipXY = 6,
FlipXYRotate = 7,
RotateMask = 7,
Empty = 8,
Modified = BIT(7),
// must not clobber TerrainFile::MATERIAL_GROUP_MASK bits!
PersistMask = BIT(7)
};
U8 flags;
U8 index;
};
enum
{
#ifndef TGE_RPG /// TGE_Map
BlockShift = 7,
GridMapSize = 0x5555,//1 + 4 + 0x10 + 0x40 + 0x100 + 0x400 + 0x1000 + 0x4000,
ChunkSquareWidth = 32,
#else
BlockShift = 8,
GridMapSize = 0x15555,//1 + 4 + 0x10 + 0x40 + 0x100 + 0x400 + 0x1000 + 0x4000 + 0x10000,
ChunkSquareWidth = 64,
#endif
BlockSize = 1 << BlockShift,//256, 0x100
BlockMask = BlockSize-1,
BlockSizeSquare = BlockSize*BlockSize,
BlockSizeSquareShift = BlockShift*2,
BlockSizeSquareMask = (BlockSize*BlockSize)-1,//如(256*256)-1
BlockSquareWidth = BlockSize,
SquareMaxPoints = BlockSize*4,
ChunkSize = 4,
ChunkDownShift = 2,
ChunkShift = BlockShift - ChunkDownShift,
LightmapSize = 512,
LightmapShift = 9,
FlagMapWidth = 128, ///< Flags that map is for 2x2 squares.
FlagMapMask = 127,
MaxMipLevel = 6,
NumBaseTextures = 16,
MaterialGroups = 8,
MaxEmptyRunPairs = 100
};
enum UpdateMaskBits
{
InitMask = 1,
VisibilityMask = 2,
EmptyMask = 4,
#ifdef TGE_RPG /// TGE_Map
TextureMask = 8, //
#endif
};
Blender* mBlender;
TextureHandle baseTextures[NumBaseTextures];
TextureHandle mBaseMaterials[MaterialGroups];
TextureHandle mAlphaMaterials[MaterialGroups];
GBitmap *lightMap;
StringTableEntry *mMaterialFileName; ///< Array from the file.
TextureHandle mDynLightTexture;
U8 *mBaseMaterialMap;
Material *materialMap;
// fixed point height values
U16 *heightMap;
U16 *flagMap;
StringTableEntry mDetailTextureName;
TextureHandle mDetailTextureHandle;
// Bumpmapping.
StringTableEntry mBumpTextureName;
TextureHandle mBumpTextureHandle;
TextureHandle mInvertedBumpTextureHandle;
F32 mBumpScale;
F32 mBumpOffset;
U32 mZeroBumpScale;
#ifdef TGE_RPG /// TGE_TerrainScene
StringTableEntry mSceneFileName;
#endif
StringTableEntry mTerrFileName;
Vector<S32> mEmptySquareRuns;
U32 mTextureCallbackKey;
void processTextureEvent(const U32 eventCode);
S32 mMPMIndex[TerrainBlock::MaterialGroups];
S32 mVertexBuffer;
/// If true, we tile infinitely.
bool mTile;
private:
#ifdef TGE_RPG /// TGE_TerrainScene
Resource<TerrainScene> mTerrainScene;
#endif
Resource<TerrainFile> mFile;
GridSquare *gridMap[BlockShift+1];
GridChunk *mChunkMap;
U32 mCRC;
public:
TerrainBlock();
~TerrainBlock();
void buildChunkDeviance(S32 x, S32 y);
void buildGridMap();
U32 getCRC() { return(mCRC); }
#ifdef TGE_RPG /// TGE_TerrainScene
Resource<TerrainScene> getTerrainScene() { return mTerrainScene;};
#endif
Resource<TerrainFile> getFile() { return mFile; };
bool onAdd();
void onRemove();
void refreshMaterialLists();
void onEditorEnable();
void onEditorDisable();
void rebuildEmptyFlags();
bool unpackEmptySquares();
void packEmptySquares();
#ifdef TGE_RPG //TGE_Map
void setDetailTextureHandle(StringTableEntry sFileName);
void setBumpTextureHandle(StringTableEntry sFileName);
/// TGE_TerrainScene
bool isBlockAt(S32 x, S32 y);
void setWalkBlockAt(S32 x, S32 y,bool bSet=true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -