You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
366 lines
12 KiB
366 lines
12 KiB
#include "MapManager.h" |
|
|
|
MapManager::MapManager() |
|
{ |
|
g_pD3DDevice = NULL; |
|
m_MapFile = NULL; |
|
m_Zone = 0; |
|
pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); |
|
#ifdef USE_FFACE |
|
Instance = NULL; |
|
Instance = CreateInstance(POL_PID); |
|
if(Instance) |
|
{ |
|
ptm = new PARTYMEMBER(); |
|
GetPartyMember(Instance, 0, ptm); |
|
} |
|
#endif |
|
} |
|
MapManager::~MapManager() |
|
{ |
|
#ifdef USE_FFACE |
|
/*if(Instance) |
|
DeleteInstance(Instance);*/ |
|
delete ptm; |
|
#endif |
|
if(m_MapFile) |
|
{ |
|
delete m_MapFile; |
|
m_MapFile = NULL; |
|
} |
|
} |
|
|
|
bool MapManager::LoadMap(int ZoneID) |
|
{ |
|
m_Zone = ZoneID; |
|
if(m_MapFile) |
|
return m_MapFile->LoadMap(ZoneID); |
|
else |
|
{ |
|
m_MapFile = new MapFile(); |
|
return m_MapFile->LoadMap(ZoneID); |
|
} |
|
} |
|
|
|
void MapManager::Render() |
|
{ |
|
#ifdef USE_FFACE |
|
GetPartyMember(Instance, 0, ptm); |
|
if((ptm->Zone + 100) != m_Zone) |
|
LoadMap(ptm->Zone + 100); |
|
#endif |
|
|
|
if(!m_MapFile) |
|
return; |
|
if(!m_MapFile->Ready()) |
|
return; |
|
if(!g_pD3DDevice) |
|
return; |
|
|
|
|
|
/*------------------------------------------------------------------------------ |
|
//Begin Input Ctrl & View Matrix Setup |
|
------------------------------------------------------------------------------*/ |
|
static float angle = 0.0f; |
|
static float view = -240.0f; |
|
D3DXMATRIX matView; |
|
static float mawari = 0.0f; |
|
|
|
#ifdef USE_FFACE |
|
if(ptm->ID) |
|
{ |
|
pos.x = GetNPCPosX(Instance, ptm->ID); |
|
pos.y = GetNPCPosY(Instance, ptm->ID) - 1; |
|
pos.z = GetNPCPosZ(Instance, ptm->ID); |
|
mawari = GetNPCPosH(Instance, ptm->ID); |
|
} |
|
#endif |
|
|
|
//view = -view; |
|
D3DXMATRIX matWorld; |
|
D3DXMATRIX matWorld2; |
|
D3DXMatrixTranslation(&matWorld2,0.0f,0.0f,angle/1500.0f); |
|
//D3DXMatrixRotationX(&matWorld, DEGtoRAD(angle/1.0069)); |
|
//DXMatrixRotationY(&matWorld, DEGtoRAD(angle)); |
|
D3DXMatrixRotationYawPitchRoll(&matWorld,DEGtoRAD(angle/20.0f),DEGtoRAD(angle/15.0f),DEGtoRAD(angle/10.0f)); |
|
matWorld*=matWorld2; |
|
angle += 1.0f; |
|
//g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); |
|
|
|
|
|
float delta; |
|
delta = 0.02f; |
|
if( GetKeyState(VK_CONTROL)&0x8000 ){ delta = 0.1f; }; |
|
if( GetKeyState(VK_RIGHT) & 0x8000 ) mawari-=delta; |
|
if( GetKeyState(VK_LEFT) & 0x8000 ) mawari+=delta; |
|
|
|
delta = 2.0f; |
|
if( GetKeyState(VK_CONTROL)&0x8000 ){ delta = 5.0f; }; |
|
if( GetKeyState(VK_UP) & 0x8000 ){ pos.x+=cos(mawari)*delta; pos.z+=sin(mawari)*delta; } |
|
if( GetKeyState(VK_DOWN) & 0x8000 ){ pos.x+=cos(mawari+3.1415926f)*delta; pos.z+=sin(mawari+3.1415926f)*delta; } |
|
if( GetKeyState(VK_PRIOR) & 0x8000 ){ pos.y+=delta; } |
|
if( GetKeyState(VK_NEXT) & 0x8000 ){ pos.y-=delta; } |
|
if( GetKeyState(VK_HOME) & 0x8000 ){ mawari=pos.x=pos.y=pos.z=0.0f; } |
|
D3DXVECTOR3 pnt(pos.x+cos(mawari), pos.y+0.0f, pos.z+sin(mawari)); |
|
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); |
|
D3DXMatrixLookAtRH(&matView, &pos, &pnt, &up); |
|
g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView); |
|
|
|
D3DXMATRIX matProj; |
|
D3DXMatrixPerspectiveFovRH(&matProj, DEGtoRAD(45.0f), 4.0f / 3.0f, 1.0f, 500.0f); |
|
g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); |
|
/*------------------------------------------------------------------------------ |
|
//End Input Ctrl & View Matrix Setup |
|
------------------------------------------------------------------------------*/ |
|
|
|
/*------------------------------------------------------------------------------ |
|
//Begin RenderState |
|
------------------------------------------------------------------------------*/ |
|
//g_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW/*/D3DCULL_NONE*/ ); |
|
g_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW/*/D3DCULL_NONE*/ ); |
|
g_pD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); |
|
//g_pD3DDevice->SetLight(0,&light); |
|
//g_pD3DDevice->LightEnable(0,TRUE); |
|
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE); |
|
//g_pD3DDevice->SetRenderState(D3DRS_AMBIENT, 0xF0F0F0F0); |
|
g_pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD ); |
|
|
|
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
|
g_pD3DDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE ); |
|
g_pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE , TRUE ); |
|
g_pD3DDevice->SetRenderState( D3DRS_ALPHAREF , 0x80 ); |
|
g_pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC , D3DCMP_GREATER ); |
|
//g_pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS,TRUE); |
|
/*------------------------------------------------------------------------------ |
|
//End RenderState |
|
------------------------------------------------------------------------------*/ |
|
|
|
for( int i=0; i< m_MapFile->nobj; i++ ) |
|
{ |
|
D3DXMATRIX matWorld; |
|
D3DXMATRIX matWorld2; |
|
D3DXMATRIX matWorld3; |
|
D3DXMATRIX matWorld4; |
|
D3DXMATRIX matWorldR4; |
|
D3DXMATRIX matWorldR5; |
|
D3DXMATRIX matWorldR6; |
|
ZeroMemory(&matWorld,sizeof(D3DXMATRIX)); |
|
D3DXMatrixScaling(&matWorld3,m_MapFile->obj[i].fScaleX,m_MapFile->obj[i].fScaleY,m_MapFile->obj[i].fScaleZ); |
|
D3DXMatrixTranslation(&matWorld,m_MapFile->obj[i].fTransX,m_MapFile->obj[i].fTransY,m_MapFile->obj[i].fTransZ); |
|
D3DXMatrixRotationX(&matWorldR4,m_MapFile->obj[i].fRotX); |
|
D3DXMatrixRotationY(&matWorldR5,m_MapFile->obj[i].fRotY); |
|
D3DXMatrixRotationZ(&matWorldR6,m_MapFile->obj[i].fRotZ); |
|
matWorld2 = matWorldR4 * matWorldR5 * matWorldR6; |
|
matWorld=((matWorld3*matWorld2)/**matWorld4*/)*matWorld; |
|
g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); |
|
if( m_MapFile->obj[i].fScaleX*m_MapFile->obj[i].fScaleY*m_MapFile->obj[i].fScaleZ < 0.0f ) |
|
{ |
|
g_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW ); |
|
} |
|
else |
|
{ |
|
g_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); |
|
} |
|
if(0) |
|
{ |
|
float pp[]={-20,0,0,20,0,0, 0,-20,0,0,20,0, 0,0,-20,0,0,20}; |
|
//float pp[]={-10,0,0,10,0,0, 0,-10,0,0,10,0, 0,0,-10,0,0,10}; |
|
g_pD3DDevice->SetFVF(D3DFVF_XYZ); |
|
g_pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST,3,pp,12); |
|
} |
|
|
|
for( int j=0; j< m_MapFile->NumMMB; j++ ) |
|
{ |
|
if( memcmp(m_MapFile->MMBlist[j]+16, m_MapFile->obj[i].id, 16) ) |
|
continue; |
|
DrawMMB(m_MapFile->MMBlist[j]); |
|
}//End For MumMMB |
|
}//End For Noj |
|
} |
|
|
|
void MapManager::DrawMMB(char *pp) |
|
{ |
|
float *ff = (float*)pp; |
|
|
|
char *p = pp; |
|
p+=0x020; |
|
for(;;) |
|
{ |
|
OOO * oo = (OOO*)(p+4); |
|
|
|
D3DXMATRIX mat; |
|
D3DXMATRIX mat1; |
|
g_pD3DDevice->GetTransform(D3DTS_WORLD, &mat1); mat = mat1; |
|
g_pD3DDevice->GetTransform(D3DTS_VIEW, &mat1); mat *= mat1; |
|
g_pD3DDevice->GetTransform(D3DTS_PROJECTION, &mat1); mat *= mat1; |
|
D3DXVECTOR3 Vec; |
|
D3DXVECTOR4 v; |
|
|
|
Vec.x=oo->x1; |
|
Vec.y=oo->y1; |
|
Vec.z=oo->z1; |
|
D3DXVec3Transform(&v,&Vec,&mat); |
|
v.x/=v.w; |
|
v.y/=v.w; |
|
v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) |
|
break; |
|
Vec.x=oo->x1;Vec.y=oo->y1; |
|
Vec.z=oo->z2; |
|
D3DXVec3Transform(&v,&Vec,&mat); |
|
v.x/=v.w; v.y/=v.w; v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) |
|
break; |
|
Vec.x=oo->x1; |
|
Vec.y=oo->y2; |
|
Vec.z=oo->z1; |
|
D3DXVec3Transform(&v,&Vec,&mat); |
|
v.x/=v.w; v.y/=v.w; v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) |
|
break; |
|
Vec.x=oo->x1; |
|
Vec.y=oo->y2; |
|
Vec.z=oo->z2; |
|
D3DXVec3Transform(&v,&Vec,&mat); |
|
v.x/=v.w; |
|
v.y/=v.w; |
|
v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) |
|
break; |
|
Vec.x=oo->x2;Vec.y=oo->y1;Vec.z=oo->z1; D3DXVec3Transform(&v,&Vec,&mat); v.x/=v.w; v.y/=v.w; v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) break; |
|
Vec.x=oo->x2;Vec.y=oo->y1;Vec.z=oo->z2; D3DXVec3Transform(&v,&Vec,&mat); v.x/=v.w; v.y/=v.w; v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) break; |
|
Vec.x=oo->x2;Vec.y=oo->y2;Vec.z=oo->z1; D3DXVec3Transform(&v,&Vec,&mat); v.x/=v.w; v.y/=v.w; v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) break; |
|
Vec.x=oo->x2;Vec.y=oo->y2;Vec.z=oo->z2; D3DXVec3Transform(&v,&Vec,&mat); v.x/=v.w; v.y/=v.w; v.z/=v.w; |
|
if( v.x<=2.2 && v.x>=-2.2 && v.y<=2.2 && v.y>=-2.2 && v.z<=2.2 && v.z>=-1.2 ) break; |
|
return; |
|
|
|
if(1) |
|
{ |
|
//float pp[]={-20,0,0,20,0,0, 0,-20,0,0,20,0, 0,0,-20,0,0,20}; |
|
float pp[]={ |
|
oo->x1,oo->y1,oo->z1, oo->x2,oo->y1,oo->z1, |
|
oo->x1,oo->y2,oo->z1, oo->x2,oo->y2,oo->z1, |
|
oo->x1,oo->y1,oo->z2, oo->x2,oo->y1,oo->z2, |
|
oo->x1,oo->y2,oo->z2, oo->x2,oo->y2,oo->z2, |
|
|
|
oo->x1,oo->y1,oo->z1, oo->x1,oo->y2,oo->z1, |
|
oo->x2,oo->y1,oo->z1, oo->x2,oo->y2,oo->z1, |
|
oo->x1,oo->y1,oo->z2, oo->x1,oo->y2,oo->z2, |
|
oo->x2,oo->y1,oo->z2, oo->x2,oo->y2,oo->z2, |
|
|
|
oo->x1,oo->y1,oo->z1, oo->x1,oo->y1,oo->z2, |
|
oo->x1,oo->y2,oo->z1, oo->x1,oo->y2,oo->z2, |
|
oo->x2,oo->y1,oo->z1, oo->x2,oo->y1,oo->z2, |
|
oo->x2,oo->y2,oo->z1, oo->x2,oo->y2,oo->z2, |
|
}; |
|
g_pD3DDevice->SetFVF(D3DFVF_XYZ); |
|
g_pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST,12,pp,12); |
|
} |
|
} |
|
g_pD3DDevice->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_NORMAL|D3DFVF_TEX1); |
|
int kai = *(int*)p; |
|
if( kai<=0 ) |
|
return; |
|
if( kai==1 ) |
|
p+=32; |
|
if( kai>=2 && kai<=16 ) |
|
{ |
|
p+=16*4; |
|
} |
|
if( kai>16 ) |
|
p+=kai*4; |
|
|
|
if( kai>0xff ) |
|
return; |
|
int i,j; |
|
while(kai) |
|
{ |
|
j = *(int*)p; |
|
if( j > 0xffff || j<0 ) |
|
{ |
|
return; |
|
} |
|
p += 32; |
|
for( i=0; i<j; i++ ) |
|
{ |
|
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); |
|
g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); |
|
|
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); |
|
|
|
//g_pD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR ); |
|
//g_pD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); |
|
//g_pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); |
|
int k; |
|
/*for( k=0; k<NumTexList; k++ ) |
|
{ |
|
if( !memcmp(p,TexList[k].ID,16) ) |
|
{ |
|
|
|
if( flgFirst ) |
|
logprintf("Finded Textur: %s",sstr(TexList[k].ID,16)); |
|
|
|
g_pD3DDevice->SetTexture(0, TexList[k].pTex); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE2X); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE); |
|
D3DSURFACE_DESC Desc; |
|
|
|
TexList[k].pTex->GetLevelDesc( 0, &Desc ); |
|
if( Desc.Format == D3DFMT_DXT1 ) |
|
{ |
|
//g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); |
|
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); |
|
//typedef enum _D3DTEXTUREOP |
|
//g_pD3DDevice->SetRenderState( D3DRS_ALPHAREF,0x7f) ; |
|
//g_pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC,D3DCMP_NOTEQUAL) ; |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE4X ); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); |
|
g_pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); |
|
|
|
g_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); |
|
g_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); |
|
g_pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); |
|
} |
|
|
|
break; |
|
} |
|
}*/ |
|
int nVer = (int)*(short*)(p+16); |
|
int nVerReal = (int)*(int*)(p+16); |
|
if( nVer > 0xffff || nVer<0 ) |
|
{ |
|
return; |
|
} |
|
int nIdx = (*(int*)(p+16+4+nVer*36)); |
|
if( nIdx > 0xffff || nIdx < 0 ) |
|
{ |
|
return; |
|
} |
|
k = 16 + 4+ nVer*36+ 4+ nIdx*2; |
|
k = 4*((k+3)/4); |
|
for( int ii=0; ii<nIdx; ii++ ) |
|
{ |
|
WORD *pidx = (WORD*)(p+16+4+nVer*36+4); |
|
if( (int)(UINT)pidx[ii]>=nVer ) |
|
{ |
|
return; |
|
} |
|
} |
|
|
|
g_pD3DDevice->BeginScene(); |
|
g_pD3DDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP,0,nIdx,nIdx-2,p+16+4+nVer*36+4,D3DFMT_INDEX16, (p+16+4) ,36 ); |
|
g_pD3DDevice->EndScene(); |
|
|
|
g_pD3DDevice->SetTexture(0,NULL); |
|
p += k; |
|
} |
|
kai--; |
|
} |
|
} |