void Window::paint() { if( !m_silent ) { if( !m_renderer_display_paint( m_display ) ) { throw StrException( "%s", utils::cbase::geterror() ); } m_fpscounter += 1; clock_t time = clock(); if( time > m_fpstime ) { m_fps = m_fpscounter; m_fpscounter = 0; m_fpstime = time + CLOCKS_PER_SEC; } #if defined( _WIN32 ) || defined( _WIN64 ) char buffer[ 256 ]; snprintf( buffer, sizeof( buffer ), "FPS=%.3i", m_fps ); SetWindowText( m_hwnd, buffer ); #endif } }
void PngReader::feed( size_t length, void const* buffer ) { if( setjmp( m_jmpbuf ) ) { throw StrException( m_error ); } png_process_data( m_png, m_info, png_bytep( buffer ), length ); }
Sound::Stream *Sound::Stream::Load(unsigned char *Data,size_t Length,const Vector <Sound::Synth::Instrument> &Instruments) { for (Link <Sound::Stream::Format> *it = Formats.Front;it;it = it->Next) { if (Sound::Stream *Result = it->Value(Data,Length,Instruments)) { return Result; } } throw StrException("Unknown audio format."); }
Sound::Stream *Sound::MIDIStream::Load(unsigned char *Data,size_t Length,const Vector <Sound::Synth::Instrument> &Instruments) { if (Length < 14) return 0; if (Data[0] != 'M') return 0; if (Data[1] != 'T') return 0; if (Data[2] != 'h') return 0; if (Data[3] != 'd') return 0; if (Data[4] != 0) StrException("Invalid MIDI file."); if (Data[5] != 0) StrException("Invalid MIDI file."); if (Data[6] != 0) StrException("Invalid MIDI file."); if (Data[7] != 6) StrException("Invalid MIDI file."); unsigned short TimeDivision; TimeDivision = Data[12] << 8; TimeDivision |= Data[13]; if (TimeDivision & 0x8000) { unsigned char FPS = (TimeDivision & 0x7F00) >> 8; unsigned char TPF = TimeDivision & 0xFF; return new Sound::MIDIStream(0,Data + 14,Length - 14,Instruments,TPF,FPS); }
void Video::SDLSystem::SetPalette(unsigned char *Palette) { SDL_Color Colors[256]; for (int i = 0;i < 256;i++) { Colors[i].r = Palette[i * 3 + 0]; Colors[i].g = Palette[i * 3 + 1]; Colors[i].b = Palette[i * 3 + 2]; } if (!SDL_SetColors(Screen,Colors,0,256)) { throw StrException("SDL palette change failed."); } }
Video::SDLSystem::SDLSystem(int Width,int Height,bool Fullscreen) : Width(Width), Height(Height) { if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { throw StrException("SDL video initialization failed."); } try { Screen = SDL_SetVideoMode(Width,Height,8,Fullscreen ? (SDL_HWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE); if (!Screen) { throw StrException("SDL video mode setting failed."); } SDL_ShowCursor(false); } catch (...) { SDL_QuitSubSystem(SDL_INIT_VIDEO); throw; } }
void Video::SDLSystem::Write(unsigned char *Buffer) { if (SDL_LockSurface(Screen) == -1) { throw StrException("SDL surface lock failed."); } unsigned char *Pixels = (unsigned char *)Screen->pixels; short Pitch = Screen->pitch; for (int y = 0;y < Height;y++) { Memory::Copy(Pixels + y * Pitch,Buffer + y * Width,Width); } SDL_UnlockSurface(Screen); SDL_Flip(Screen); }
FlacReader::FlacReader( MemoryIo* source ) : m_bitdepth( 0 ) , m_channels( 0 ) , m_samplerate( 0 ) , m_decoder( 0 ) , m_source( source ) , m_sourcepos( 0 ) , m_totalsamples( 0 ) { m_decoder = FLAC__stream_decoder_new(); if( !m_decoder ) { throw std::runtime_error( "failed to create the flac decoder" ); } FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream( m_decoder, &FlacReader::read_callback, &FlacReader::seek_callback, &FlacReader::tell_callback, &FlacReader::length_callback, &FlacReader::eof_callback, &FlacReader::write_callback, 0, &FlacReader::error_callback, this ); if( status != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { FLAC__stream_decoder_delete( m_decoder ); throw std::runtime_error( FLAC__StreamDecoderInitStatusString[ status ] ); } if( !FLAC__stream_decoder_process_until_end_of_stream( m_decoder ) ) { FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state( m_decoder ); FLAC__stream_decoder_delete( m_decoder ); if( m_error ) { throw StrException( m_error ); } else { throw std::runtime_error( FLAC__StreamDecoderStateString[ state ] ); } } }
void checkerror_pos( char const* filename, char const* function, int line, HRESULT hr ) { if( hr ) { char buffer[ 1024 ]; auto it = errmap.find( hr ); if( it != errmap.end() ) { snprintf( buffer, sizeof( buffer ), "Direct3D error: %s", it->second ); } else { snprintf( buffer, sizeof( buffer ), "Direct3D error: %#x", uint32_t( hr ) ); } throw StrException( "[%48s:%24s@%4i]\t%s", filename, function, line, buffer ); } }
void Window::initialize() { m_info.window = this; m_info.silent = m_silent; m_info.client_methodlist = &client_main_methodlist; if( !m_silent ) { #if defined( _WIN32 ) || defined( _WIN64 ) String rpath = utils::MainConf->string( "renderer", nullptr ); Ref< DataBuffer > wrpath = utf8toutf16( rpath ); m_renderermodule = LoadLibraryW( ( wchar_t* )wrpath->m_data ); if( !m_renderermodule ) { throw StrException( "cannot load renderer %s", rpath.getchars() ); } m_renderer_connect = renderer_connect_t( GetProcAddress( m_renderermodule, "renderer_connect" ) ); m_renderer_display_create = renderer_display_create_t( GetProcAddress( m_renderermodule, "renderer_display_create" ) ); m_renderer_display_destroy = renderer_display_destroy_t( GetProcAddress( m_renderermodule, "renderer_display_destroy" ) ); m_renderer_display_paint = renderer_display_paint_t( GetProcAddress( m_renderermodule, "renderer_display_paint" ) ); m_renderer_display_setshape = renderer_display_setshape_t( GetProcAddress( m_renderermodule, "renderer_display_setshape" ) ); if( !m_renderer_connect || !m_renderer_display_create || !m_renderer_display_destroy || !m_renderer_display_paint || !m_renderer_display_setshape ) { FreeLibrary( m_renderermodule ); throw StrException( "%s is not a valid Mist renderer", rpath.getchars() ); } m_renderer_connect( &m_info ); if( !m_renderer_display_create( m_hwnd, &m_display ) ) { throw StrException( "%s", utils::cbase::geterror() ); } m_info.acceleratorinput = false; m_info.pointinput = true; m_info.keyboardinput = true; #elif defined( __ANDROID__ ) m_info.acceleratorinput = false; m_info.pointinput = true; m_info.keyboardinput = false; #endif } else { m_info.width = 0; m_info.height = 0; m_info.texelsoffset = 0; m_info.texeltoffset = 0; m_info.renderer_methodlist = 0; m_info.renderer_module = 0; m_info.acceleratorinput = false; m_info.pointinput = false; m_info.keyboardinput = false; } m_fpstime = clock() + CLOCKS_PER_SEC; initlstate(); }