/****************************************************************************** libx42pp - skinned vertex animation library (C++ API) Copyright (C) 2007 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #include "local.h" namespace x42 { model::model( const x42header_t &h, persist_flags pers_flags ) { size_t cb = x42_GetLoadedSize( &h, pers_flags ); if( !cb ) throw std::exception(); buf.alloc( cb ); _x42 = x42_SetupBufferPointers( buf.ptr(), &h, pers_flags ); if( !_x42 ) throw std::exception(); } model::model( InStream &stream, persist_flags pers_flags ) { initialize( stream, pers_flags ); } model::model( const char *path, persist_flags pers_flags ) { std::fstream file( path, std::ios_base::in | std::ios_base::binary ); InStream stream( file ); initialize( stream, pers_flags ); } model::model( const model &src, persist_flags pers_flags ) { size_t cb = x42_GetLoadedSize( &src._x42->header, pers_flags ); if( !cb ) throw std::exception(); buf.alloc( cb ); _x42 = x42_CopyRuntimeData( buf.ptr(), src._x42 ); if( !_x42 ) throw std::exception(); } model::~model() { } void model::initialize( InStream &stream, persist_flags pers_flags ) { x42header_t hbuf, *h; h = x42_LoadHeaderFromStream( &hbuf, &stream ); if( !h ) throw std::exception(); size_t cb = x42_GetLoadedSize( h, pers_flags ); if( !cb ) throw std::exception(); buf.alloc( cb ); _x42 = x42_LoadDataFromStream( buf.ptr(), h, pers_flags, &stream ); if( !_x42 ) throw std::exception(); } void model::swap( model &other ) { buf.swap( other.buf ); std::swap( _x42, other._x42 ); } model& model::operator = ( const model &src ) { model( src ).swap( *this ); return *this; } void model::write_data( OutStream &stream, persist_flags pers_flags ) { bool stat; stat = x42_WriteToStream( &stream, pers_flags, _x42 ); if( !stat ) throw std::exception(); } };