#include "stdafx.h" #include "Swaypoint.h" #include "EnvironmentInfo.h" #include #include #include #include #include "TerrainSeamlessWorldInfo.h" #include "SDebug_Util.h" SWayPoint::SWayPoint() { } SWayPoint::~SWayPoint() { RemoveAllWayPointList(); } void SWayPoint::Init( const CTerrainSeamlessWorldInfo* pSeamlessWorldInfo ) { const KSize sMapSize = pSeamlessWorldInfo->GetMapCount(); for( int x = 0; x < sMapSize.cx; x++ ) { for( int y = 0; y < sMapSize.cy; y++ ) { std::string strMapFileName = pSeamlessWorldInfo->GetMapFileName( x, y ); strMapFileName = strMapFileName.substr( 0, strMapFileName .find( '.' ) ); strMapFileName += ".nfp"; KStream* pStream = KFileManager::Instance().CreateStreamFromResource( strMapFileName.c_str() ); if( pStream ) { int nWayPointList = 0; pStream->Read( &nWayPointList, sizeof( nWayPointList ) ); for( int nCount = 0; nCount < nWayPointList; nCount++ ) { //헤더 건너뛰기 pStream->Seek( sizeof(MOVEMENT_PATH_HEADER), KStream::seekCur ); //설명 건너뛰기 int nSize = 0; pStream->Read( &nSize, sizeof( nSize ) ); if(nSize > 1) pStream->Seek( nSize, KStream::seekCur ); //웨이포인트 건너뛰기 pStream->Read( &nSize, sizeof( nSize ) ); if(nSize > 0) pStream->Seek( sizeof(K3DVector)*nSize, KStream::seekCur ); //연결된 맵이름 저장해야 한다 pStream->Read( &nSize, sizeof( nSize ) ); if( nSize > 1 ) { char* pLinkMapFileName = new char[ nSize ]; pStream->Read( pLinkMapFileName, nSize ); SAFE_DELETE_ARRAY( pLinkMapFileName ); } } } SAFE_DELETE(pStream); } } } void SWayPoint::RemoveAllWayPointList() { std::vector< WAYPOINT_LIST* >::iterator iter = m_WayPointList.begin(); for( ; iter != m_WayPointList.end() ; ) { SAFE_DELETE( (*iter) ); iter = m_WayPointList.erase( iter ); } m_WayPointList.clear(); } void SWayPoint::LoadWayPoint( std::string strMapFileName, int nPosX, int nPosY, float fMapLen ) { RemoveAllWayPointList(); strMapFileName = strMapFileName.substr( 0, strMapFileName .find( '.' ) ); strMapFileName += ".nfp"; KStream* pStream = KFileManager::Instance().CreateStreamFromResource( strMapFileName.c_str() ); if( pStream == NULL ) { SAFE_DELETE( pStream ); // assert( 0 && "이동경로 파일로드 실패" ); return; } int nWayPointList = 0; pStream->Read( &nWayPointList, sizeof( nWayPointList ) ); for( int nCount = 0; nCount < nWayPointList; nCount++ ) { //WayPoint나 MovementPath나 똑같다 ㅡ,.ㅡ MOVEMENT_PATH_HEADER sMovementPathHeader; pStream->Read( &sMovementPathHeader, sizeof( sMovementPathHeader ) ); WAYPOINT_LIST* pNewWayPoint = new WAYPOINT_LIST; //아이디 및 속성 저장 pNewWayPoint->nWayPointID = sMovementPathHeader.nMovementPathID; //설명 저장 int nCharSize = 0; pStream->Read( &nCharSize, sizeof( int ) ); if( nCharSize > 1 ) { char* pDesCription = new char[ nCharSize ]; pStream->Read( pDesCription, nCharSize ); pNewWayPoint->strDescription = pDesCription; SAFE_DELETE_ARRAY( pDesCription ); } pStream->Read( &pNewWayPoint->nPointSize, sizeof( int ) ); if( pNewWayPoint->nPointSize > 0 ) pNewWayPoint->pPointList = new K3DVector[pNewWayPoint->nPointSize]; //한번에 읽어들일지 하나씩 읽어들일지는 나중에 고치자 for( int nWayPointCount = 0; nWayPointCount < pNewWayPoint->nPointSize; nWayPointCount++ ) { K3DVector vPos = K3DVector( 0.0f, 0.0f, 0.0f ); pStream->Read( &vPos, sizeof( K3DVector ) ); vPos.x += (int)( (float)nPosX * fMapLen ); vPos.y += (int)( (float)nPosY * fMapLen ); pNewWayPoint->pPointList[nWayPointCount] = vPos; pNewWayPoint->pPointList[nWayPointCount].z = 0.0f; } //연결된 맵이름 건너뛴다 pStream->Read( &nCharSize, sizeof( int ) ); if( nCharSize > 1 ) { pStream->Seek( sizeof(char)*nCharSize, KStream::seekCur ); } m_WayPointList.push_back( pNewWayPoint ); } SAFE_DELETE( pStream ); } K3DVector* SWayPoint::GetWayPoint( int& nWayPointID ) { std::vector< WAYPOINT_LIST* >::iterator iter = m_WayPointList.begin(); for( ; iter != m_WayPointList.end(); iter++ ) { if( (*iter)->nWayPointID == nWayPointID ) { nWayPointID = (*iter)->nPointSize; return (*iter)->pPointList; } } return NULL; }