void XmlMapHandler::Load(std::istream& file, Map& map) { wxXmlDocument doc; wxFInputStream fis(file); if (!doc.Load(dynamic_cast<wxInputStream&>(fis))) throw "Could not open XML file"; wxXmlNode* child = doc.GetRoot()->GetChildren(); if (child != NULL && child->GetName() != "Properties") throw "Properties must be the first node in the XML file"; ReadProperties(child, map); while ((child = child->GetNext())) { std::string name = child->GetName().ToStdString(); VerboseLog("%s Got node %s", __func__, name.c_str()); if (name == "Layer") ReadLayer(child, map); else if (name == "Background") ReadBackground(child, map); else if (name == "Collision") ReadCollision(child, map); else if (name == "Animation") ReadAnimation(child, map); else throw "Unknown element found in file " + name; } }
// --[ Method ]--------------------------------------------------------------- // // - Class : CHelper // - prototype : bool ReadNodeData(CInput* pInput) // // - Purpose : Reads the helper data from a source. // // ----------------------------------------------------------------------------- bool CHelper::ReadNodeData(CInput* pInput) { assert(pInput); assert(pInput->Ready()); unsigned uError = 0; if(!ReadAnimation(pInput)) uError++; return uError == 0; }
int CEQUFile::LoadEQUFile( char* filename ) { int ret; m_mode = EQUFILE_LOAD; m_hfile = CreateFile( (LPCTSTR)filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL ); if( m_hfile == INVALID_HANDLE_VALUE ){ DbgOut( "EQUFile : LoadEQUFile : CreateFile : INVALID_HANDLE_VALUE error !!!\n" ); //return D3DAPPERR_MEDIANOTFOUND;//!!!!!!!! return 1; } ret = SetBuffer(); if( ret ){ DbgOut( "EQUFile : LoadEQUFile : SetBuffer error !!!\n" ); _ASSERT( 0 ); return 1; } ret = ReadFileInfo(); if( ret ){ DbgOut( "EQUFile : LoadEQUFile : ReadFileInfo error !!!\n" ); _ASSERT( 0 ); return 1; } ret = Read_Int( &m_equbuf, "<AnimNum>", "</AnimNum>", &m_animnum ); if( ret ){ DbgOut( "EQUFile : LoadEQUFile : Read_Int animnum error !!!\n" ); _ASSERT( 0 ); return 1; } if( m_animnum <= 0 ){ return 0; } m_animdat = (ANIMDAT*)malloc( sizeof( ANIMDAT ) * m_animnum ); if( !m_animdat ){ DbgOut( "EQUFile : LoadEQUFile : animdat alloc error !!!\n" ); _ASSERT( 0 ); return 1; } ZeroMemory( m_animdat, sizeof( ANIMDAT ) * m_animnum ); int animcnt; for( animcnt = 0; animcnt < m_animnum; animcnt++ ){ if( m_equbuf.pos >= m_equbuf.bufleng ){ DbgOut( "EQUFile : LoadEQUFile : pos overflow error !!!\n" ); _ASSERT( 0 ); return 1; } char* startptr = 0; char* endptr = 0; startptr = strstr( m_equbuf.buf + m_equbuf.pos, "<Animation>" ); if( startptr ){ startptr += (int)strlen( "<Animation>" ); } endptr = strstr( m_equbuf.buf + m_equbuf.pos, "</Animation>" ); if( endptr ){ endptr += (int)strlen( "</Animation>" ); } if( !startptr || !endptr ){ DbgOut( "EQUFile : LoadEQUFile : Animation pattern not found skip !!!\n" ); _ASSERT( 0 ); return 1; } int chkendpos; chkendpos = (int)( endptr - m_equbuf.buf ); if( (chkendpos >= (int)m_equbuf.bufleng) || (endptr < startptr) ){ DbgOut( "EQUFile : LoadEQUFile : Animation endmark error !!!\n" ); _ASSERT( 0 ); return 1; } EQUBUF animbuf; ZeroMemory( &animbuf, sizeof( EQUBUF ) ); animbuf.buf = startptr; animbuf.pos = 0; animbuf.bufleng = (int)( endptr - startptr ); animbuf.isend = 0; ret = ReadAnimation( &animbuf, animcnt ); if( ret ){ DbgOut( "EQUFile : LoadEQUFile : ReadAnimation error !!!\n" ); _ASSERT( 0 ); return 1; } m_equbuf.pos = chkendpos; } return 0; }