boost::shared_ptr<ResourceInfo> Resource::LoadResource(const std::string& name) { boost::shared_ptr<ResourceInfo> resource_info = m_resources.LoadResource(name); if (resource_info.get() == NULL) { const char* name_cstr = name.c_str(); // Check if resource exists if (PHYSFS_exists(name_cstr) && !PHYSFS_isDirectory(name_cstr)) { // Load the resource PHYSFS_File* fp = PHYSFS_openRead(name_cstr); // Load file data into ResourceInfo class Sint64 length = (Sint64)PHYSFS_fileLength(fp); char* data = new char[length]; PHYSFS_read(fp, (void*)data, (PHYSFS_uint32)length, 1); resource_info = m_resources.Construct(name, data, length); // Close PHYSFS_File PHYSFS_close(fp); fp = NULL; } else { BOOST_THROW_EXCEPTION(ResourceNotFoundException() << StringErrorInfo("The requested resource could not be found: " + name)); } } return resource_info; }
void Joystick::ReleaseButton(Uint8& button) { try { m_button_states.at(button).Release(); } catch (std::out_of_range) { BOOST_THROW_EXCEPTION(InputException() << StringErrorInfo("Joystick button is out of range")); } }
ButtonState& Joystick::GetButton(Uint8& button) { try { return m_button_states.at(button); } catch (std::out_of_range) { BOOST_THROW_EXCEPTION(InputException() << StringErrorInfo("Joystick button is out of range")); } }
void Joystick::SetAxisPosition(Uint8 axis_num, float position) { try { m_axis_updates.at(axis_num) = true; m_axis_states.at(axis_num).Update(position); } catch (std::out_of_range) { BOOST_THROW_EXCEPTION(InputException() << StringErrorInfo("Joystick axis is out of range")); } }