/*********************/ /*** Elem Stuph ***/ /*********************/ #include "stdafx.h" #include #include #include #include #include #include "Core.h" #include "TexCache.h" #include "Elem.h" #include "GinTex.h" #include "utils.h" /*****************************************************************************/ const float XFlipMtx[]= { -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }; const float YFlipMtx[]= { 1, 0, 0, 0, 0,-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }; /*****************************************************************************/ CElem::CElem(int Width,int Height) { ElemWidth=Width; ElemHeight=Height; UnitWidth=ElemWidth/UnitSize; UnitHeight=ElemHeight/UnitSize; ElemID=-1; ElemRGB=(u8*)malloc(ElemWidth*ElemHeight*3); memset(ElemRGB,0,ElemWidth*ElemHeight*3); Type=ElemType2d; TexXOfs=0; TexYOfs=0; CreateBlankTileGfx(); } /*****************************************************************************/ // 3d Elem (From Gin File) CElem::CElem(CCore *Core,const char *Filename,CScene &ThisScene,int Node) { CNode &ThisNode=ThisScene.GetNode(Node); CTexCache &TexCache=Core->GetTexCache(); GFName Path=Filename; SetPath=Path.Drive(); SetPath+=Path.Dir(); SetPath.Append('\\'); Type=ElemType3d; TexXOfs=-1; TexYOfs=-1; Build3dElem(TexCache,ThisScene,Node); Calc3dSize(); Ofs.x=+0.5f; Ofs.y=0; Ofs.z=+4.0f; Build3dDrawList(TexCache,DrawList[ElemType3d]); Create2dTexture(TexCache,Path.File(),Node); Build2dDrawList(TexCache,DrawList[ElemType2d]); if (!ValidFlag) CreateInvalidTileGfx(); } /*****************************************************************************/ // 2d Elem (From Bmp File) CElem::CElem(CCore *Core,const char *Filename,int TexID,int XOfs,int YOfs,int Width,int Height) { CTexCache &TexCache=Core->GetTexCache(); GFName Path=Filename; ElemWidth=Width; ElemHeight=Height; UnitWidth=ElemWidth/UnitSize; UnitHeight=ElemHeight/UnitSize; Type=ElemType2d; TexXOfs=XOfs; TexYOfs=YOfs; Build2dElem(Core,Path.File(),TexID); Ofs.Zero(); Build3dDrawList(TexCache,DrawList[ElemType3d]); Create2dTexture(TexCache,Path.File(),TexID); Build2dDrawList(TexCache,DrawList[ElemType2d]); if (!ValidFlag) CreateInvalidTileGfx(); } /*****************************************************************************/ void CElem::CleanUp() { free(ElemRGB); } /*****************************************************************************/ void CElem::Build2dElem(CCore *Core,const char *Filename,int TexID) { const Vector3 P0(0.0f,0.0f,0.0f); const Vector3 P1(1.0f,0.0f,0.0f); const Vector3 P2(0.0f,1.0f,0.0f); const Vector3 P3(1.0f,1.0f,0.0f); int ListSize=TriList.size(); TriList.resize(ListSize+2); sTriFace &Tri0=TriList[ListSize+0]; sTriFace &Tri1=TriList[ListSize+1]; CTexCache &TexCache=Core->GetTexCache(); sTex &ThisTex=TexCache.GetTex(TexID); float u0,u1,v0,v1; u0=(TexXOfs)*ThisTex.dW; u1=u0+ThisTex.dW; v0=(((ThisTex.TexHeight/UnitSize)-(TexYOfs+1))*ThisTex.dH); v1=v0+ThisTex.dH; Tri0.Mat=TexID; Tri0.vtx[0]=P0; Tri0.vtx[1]=P1; Tri0.vtx[2]=P2; Tri0.uvs[0].u=u0; Tri0.uvs[0].v=v0; Tri0.uvs[1].u=u1; Tri0.uvs[1].v=v0; Tri0.uvs[2].u=u0; Tri0.uvs[2].v=v1; Tri1.Mat=TexID; Tri1.vtx[0]=P1; Tri1.vtx[1]=P2; Tri1.vtx[2]=P3; Tri1.uvs[0].u=u1; Tri1.uvs[0].v=v0; Tri1.uvs[1].u=u0; Tri1.uvs[1].v=v1; Tri1.uvs[2].u=u1; Tri1.uvs[2].v=v1; } /*****************************************************************************/ void CElem::Build3dElem(CTexCache &TexCache,CScene &ThisScene,int Node) { CNode &ThisNode=ThisScene.GetNode(Node); int ChildCount=ThisNode.GetChildCount(); std::vector const &NodeTriList=ThisNode.GetTris(); std::vectorconst &NodeVtxList=ThisNode.GetRelPts(); std::vector const &NodeUVList=ThisNode.GetUVTris(); std::vector const &NodeTriMat=ThisNode.GetTriMaterial(); std::vector const &TexList= ThisScene.GetTexNames();//List(); std::vector const &MatList= ThisScene.GetMaterials(); int TriCount=NodeTriList.size(); int ListSize=TriList.size(); TriList.resize(ListSize+TriCount); for (int T=0; TTri.vtx[p].x) XMin=Tri.vtx[p].x; if (XMaxTri.vtx[p].y) YMin=Tri.vtx[p].y; if (YMax> PC_TILE_FLAG_COLLISION_SHIFT; if (ColFlags) { switch (ColFlags) { case PC_TILE_COLLISION_NORMAL: glColor4f(1,1,1,0.5); break; case PC_TILE_COLLISION_DAMAGE: glColor4f(1,0,0,0.5); break; case PC_TILE_COLLISION_SLIPPERY: glColor4f(0,1,0,0.5); break; case PC_TILE_COLLISION_ELECTRIC: glColor4f(1,0,1,0.5); break; case PC_TILE_COLLISION_STICKY: glColor4f(1,1,0,0.5); break; case PC_TILE_COLLISION_WATER: glColor4f(0,0,1,0.5); break; } } glEnable(GL_TEXTURE_2D); if (Render3d) { glEnable(GL_DEPTH_TEST); glCallList(DrawList[ElemType3d]); glDisable(GL_DEPTH_TEST); } else { glCallList(DrawList[ElemType2d]); } glDisable(GL_TEXTURE_2D); glPopMatrix(); } /*****************************************************************************/ void CElem::Purge() { for (int i=0; iGetTexCache(); int TexID=TexCache.ProcessTexture(Filename,0); sTex &ThisTex=TexCache.GetTex(TexID); int Width=ThisTex.TexWidth/DefWidth; int Height=ThisTex.TexHeight/DefHeight; ElemList.push_back(CElem(DefWidth,DefHeight)); // Insert Blank for (int Y=0; YListSize) return(false); return(ElemList[No].IsValid()); } /*****************************************************************************/ /*****************************************************************************/ /*** Elem Bank ***************************************************************/ /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ CElemBank::CElemBank() { LoadFlag=FALSE; } /*****************************************************************************/ CElemBank::~CElemBank() { } /*****************************************************************************/ void CElemBank::CleanUp() { int ListSize=SetList.size(); for (int i=0; iGetFilePath(); GString FilePath; char FixPath[1024]; FilePath=RootPath.Drive(); FilePath+=RootPath.Dir(); FilePath.Append('\\'); FilePath.Upper(); File->Read(&ListSize,sizeof(int)); // New Style rel storage for (int i=0;iRead(&c,1); FullName.Append(c); } FullName.Upper(); GFName::makeabsolute(FilePath,FullName,FixPath); FullName=FixPath; _fullpath( FixPath, FullName, 1024); for (int z=0; zGetFilePath(); GString SavePath; SavePath=RootPath.Drive(); SavePath+=RootPath.Dir(); SavePath.Append('\\'); SavePath.Upper(); File->Write(&ListSize,sizeof(int)); for (int i=0; iWrite(Filename,strlen(Filename)+1); } } /*****************************************************************************/ void CElemBank::AddSet(const char *Filename) { int ListSize=SetList.size(); CElemSet NewSet(Filename,ListSize); SetList.Add(NewSet); if (SetList.size()!=ListSize) LoadFlag=TRUE; } /*****************************************************************************/ void CElemBank::LoadAllSets(CCore *Core) { int ListSize=SetList.size(); if (!LoadFlag) return; for (int i=0;i=0 && Elem>=0); return(SetList[Set].GetElem(Elem)); } /*****************************************************************************/ bool CElemBank::IsValid(int Set,int Elem) { if (Set<0 || Elem<0) return(false); if (Elem==0) return(true); ASSERT(Set