⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terrdata.h

📁 五行MMORPG引擎系统V1.0
💻 H
📖 第 1 页 / 共 2 页
字号:
	void setSelfBlockAt(S32 x, S32 y,bool bSet=true);
	void setBlockAt(S32 x, S32 y,const U32 uFlags);
	U32  getBlockAt(S32 x, S32 y);
	bool canWalkAt(S32 x, S32 y);

#endif

   TextureHandle getDetailTextureHandle();
   TextureHandle getBumpTextureHandle();
   TextureHandle getInvertedBumpTextureHandle();

   Material *getMaterial(U32 x, U32 y);
   GridSquare *findSquare(U32 level, Point2I pos);
   GridSquare *findSquare(U32 level, S32 x, S32 y);
   GridChunk *findChunk(Point2I pos);

   void setHeight(const Point2I & pos, float height);
   void updateGrid(Point2I min, Point2I max);
   void updateGridMaterials(Point2I min, Point2I max);

   U16 getHeight(U32 x, U32 y) { return heightMap[(x & BlockMask) + ((y & BlockMask) << BlockShift)]; }
   U16 *getHeightAddress(U32 x, U32 y) { return &heightMap[(x & BlockMask) + ((y & BlockMask) << BlockShift)]; }
   void setBaseMaterial(U32 x, U32 y, U8 matGroup);

   S32 getTerrainMapIndex(Point3F& pt);
   U8 *getMaterialAlphaMap(U32 matIndex);
   U8* getBaseMaterialAddress(U32 x, U32 y);
   U8  getBaseMaterial(U32 x, U32 y);
   U16 *getFlagMapPtr(S32 x, S32 y);

   void getMaterialAlpha(Point2I pos, U8 alphas[MaterialGroups]);
   void setMaterialAlpha(Point2I pos, const U8 alphas[MaterialGroups]);

   // a more useful getHeight for the public...
   bool getHeights(const Point2F & pos, F32 * heights);/// TGE_Collision
   bool getHeight(const Point2F & pos, F32 * height);
   bool getNormal(const Point2F & pos, Point3F * normal, bool normalize = true);
   bool getNormalAndHeight(const Point2F & pos, Point3F * normal, F32 * height, bool normalize = true);

   // only the editor currently uses this method - should always be using a ray to collide with
   bool collideBox(const Point3F &start, const Point3F &end, RayInfo* info){return(castRay(start,end,info));}
   S32 getMaterialAlphaIndex(const char *materialName);

  private:
   S32 squareSize;

  public:
   void setFile(Resource<TerrainFile> file);
#ifdef TGE_RPG /// TGE_TerrainScene
	void setScene(Resource<TerrainScene> scene);
#endif
   bool save(const char* filename);

   static void flushCache();
   void relight(const ColorF &lightColor, const ColorF &ambient, const Point3F &lightDir);

   S32 getSquareSize();

   //--------------------------------------
   // SceneGraph functions...

  protected:
   void setTransform     (const MatrixF &mat);
   bool prepRenderImage  ( SceneState *state, const U32 stateKey, const U32 startZone, const bool modifyBaseZoneState=false);
   void renderObject     ( SceneState *state, SceneRenderImage *image);

   //--------------------------------------
   // collision info
  private:
   BSPTree *mTree;
   S32 mHeightMin;
   S32 mHeightMax;
  public:
   void buildConvex(const Box3F& box,Convex* convex);
   bool buildPolyList(AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere);
   BSPNode *buildCollisionBSP(BSPTree *tree, const Box3F &box, const SphereF &sphere);
   bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
   bool castRayI(const Point3F &start, const Point3F &end, RayInfo* info, bool emptyCollide);
   bool castRayBlock(const Point3F &pStart, const Point3F &pEnd, Point2I blockPos, U32 level, F32 invDeltaX, F32 invDeltaY, F32 startT, F32 endT, RayInfo *info, bool);
  private:
   BSPNode *buildSquareTree(S32 y, S32 x);
   BSPNode *buildXTree(S32 y, S32 xStart, S32 xEnd);

  public:
   bool buildMaterialMap();
   void buildMipMap();

   void setBaseMaterials(S32 argc, const char *argv[]);
   bool initMMXBlender();

   // private helper
  private:
   bool        mCollideEmpty;

  public:
   DECLARE_CONOBJECT(TerrainBlock);
   static void initPersistFields();
   void inspectPostApply();
   U32 packUpdate   (NetConnection *conn, U32 mask, BitStream *stream);
   void unpackUpdate(NetConnection *conn,           BitStream *stream);
};



//--------------------------------------
class TerrainFile : public ResourceInstance
{
  public:
   enum Constants {
      FILE_VERSION = 3,
      MATERIAL_GROUP_MASK = 0x7
   };

   TerrainFile();
   ~TerrainFile();

   U16 mHeightMap[TerrainBlock::BlockSize * TerrainBlock::BlockSize];
   U8  mBaseMaterialMap[TerrainBlock::BlockSize * TerrainBlock::BlockSize];

   GridSquare mGridMapBase[TerrainBlock::GridMapSize];
   GridSquare *mGridMap[TerrainBlock::BlockShift+1];
   GridChunk mChunkMap[TerrainBlock::ChunkSquareWidth * TerrainBlock::ChunkSquareWidth];
   U16 mFlagMap[TerrainBlock::FlagMapWidth * TerrainBlock::FlagMapWidth];
   char *mTextureScript;
   char *mHeightfieldScript;

   TerrainBlock::Material mMaterialMap[TerrainBlock::BlockSquareWidth * TerrainBlock::BlockSquareWidth];

   // DMMNOTE: This loads all the alpha maps, whether or not they are used.  Possible to
   //  restrict to only the used versions?
   StringTableEntry mMaterialFileName[TerrainBlock::MaterialGroups];
   U8*              mMaterialAlphaMap[TerrainBlock::MaterialGroups];

   bool save(const char *filename);
   void buildChunkDeviance(S32 x, S32 y);
   void buildGridMap();
   void heightDevLine(U32 p1x, U32 p1y, U32 p2x, U32 p2y, U32 pmx, U32 pmy, U16 *devPtr);

   inline GridSquare *findSquare(U32 level, Point2I pos)
   {
      return mGridMap[level] + (pos.x >> level) + ((pos.y>>level) << (TerrainBlock::BlockShift - level));
   }

   inline U16 getHeight(U32 x, U32 y)
   {
      return mHeightMap[(x & TerrainBlock::BlockMask) + ((y & TerrainBlock::BlockMask) << TerrainBlock::BlockShift)];
   }

   inline TerrainBlock::Material *getMaterial(U32 x, U32 y)
   {
      return &mMaterialMap[(x & TerrainBlock::BlockMask) + ((y & TerrainBlock::BlockMask) << TerrainBlock::BlockShift)];
   }

   void setTextureScript(const char *script);
   void setHeightfieldScript(const char *script);
   const char *getTextureScript();
   const char *getHeightfieldScript();
};



//--------------------------------------------------------------------------


#ifdef TGE_RPG ///TGE_TerrainScene
inline bool TerrainBlock::isBlockAt(S32 x, S32 y)
{
	return mTerrainScene->isBlockAt(x,y);
}
inline void TerrainBlock::setWalkBlockAt(S32 x, S32 y,bool bSet)
{
	mTerrainScene->setWalkBlockAt(x,y,bSet);
}
inline void TerrainBlock::setSelfBlockAt(S32 x, S32 y,bool bSet)
{
	mTerrainScene->setSelfBlockAt(x,y,bSet);
}
inline void TerrainBlock::setBlockAt(S32 x, S32 y,const U32 uFlags)
{
	mTerrainScene->setBlockAt(x,y,uFlags);
}

inline U32 TerrainBlock::getBlockAt(S32 x, S32 y)
{
	return mTerrainScene->getBlockAt(x,y);
}

inline bool TerrainBlock::canWalkAt(S32 x, S32 y)
{
	return mTerrainScene->canWalkAt(x,y);
}
#endif


inline U16 *TerrainBlock::getFlagMapPtr(S32 x, S32 y)
{
   return flagMap + ((x >> 1) & TerrainBlock::FlagMapMask) +
                  ((y >> 1) & TerrainBlock::FlagMapMask) * TerrainBlock::FlagMapWidth;
}

inline GridSquare *TerrainBlock::findSquare(U32 level, S32 x, S32 y)
{
   return gridMap[level] + ((x  & TerrainBlock::BlockMask) >> level) + (((y & TerrainBlock::BlockMask) >> level) << (TerrainBlock::BlockShift - level));
}

inline GridSquare *TerrainBlock::findSquare(U32 level, Point2I pos)
{
   return gridMap[level] + (pos.x >> level) + ((pos.y>>level) << (BlockShift - level));
}

inline GridChunk *TerrainBlock::findChunk(Point2I pos)
{
   return mChunkMap + (pos.x >> ChunkDownShift) + ((pos.y>>ChunkDownShift) << ChunkShift);
}

inline TerrainBlock::Material *TerrainBlock::getMaterial(U32 x, U32 y)
{
   return materialMap + x + (y << BlockShift);
}

inline TextureHandle TerrainBlock::getDetailTextureHandle()
{
   return mDetailTextureHandle;
}
inline S32 TerrainBlock::getSquareSize()
{
   return squareSize;
}

inline U8 TerrainBlock::getBaseMaterial(U32 x, U32 y)
{
   return mBaseMaterialMap[(x & BlockMask) + ((y & BlockMask) << BlockShift)];
}

inline U8* TerrainBlock::getBaseMaterialAddress(U32 x, U32 y)
{
   return &mBaseMaterialMap[(x & BlockMask) + ((y & BlockMask) << BlockShift)];
}

inline U8* TerrainBlock::getMaterialAlphaMap(U32 matIndex)
{
   if (mFile->mMaterialAlphaMap[matIndex] == NULL) {
      mFile->mMaterialAlphaMap[matIndex] = new U8[TerrainBlock::BlockSize * TerrainBlock::BlockSize];
      dMemset(mFile->mMaterialAlphaMap[matIndex], 0, TerrainBlock::BlockSize * TerrainBlock::BlockSize);
   }

   return mFile->mMaterialAlphaMap[matIndex];
}

// 11.5 fixed point - gives us a height range from 0->2048 in 1/32 inc

inline F32 fixedToFloat(U16 val)
{
   return F32(val) * 0.03125f;
}

inline U16 floatToFixed(F32 val)
{
   return U16(val * 32.0);
}

extern ResourceInstance *constructTerrainFile(Stream &stream);

#ifdef TGE_RPG /// TGE_Collision 地形的全局指针,通常,RPG只有一个地形便可
	extern TerrainBlock*		g_pTerrainBlock;
#endif

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -