bool keyboard::is_pressed(KEYCODE keycode) { NYX_ASSERT(pimpl_ != nullptr); NYX_ASSERT(pimpl_->isInitialized); uint8_t key = static_cast<uint8_t>(keycode); return pimpl_->is_pressed(key); }
//----------------------------------------------------------------------------------------- // joystick::joystick(const input_device_desc& desc) :pimpl_(std::make_shared<PImpl>()) { NYX_ASSERT(pimpl_ != nullptr); initialize(desc); NYX_ASSERT(pimpl_!= nullptr); }
keyboard::keyboard(const input_device_desc& desc) : pimpl_(std::make_shared<PImpl>()) { initialize(desc); NYX_ASSERT(pimpl_!= nullptr); NYX_ASSERT(pimpl_->isInitialized); }
const float& Kernel2D::at(int x, int y) const { NYX_ASSERT(abs(x) <= static_cast<int>(_spread)); NYX_ASSERT(abs(y) <= static_cast<int>(_spread)); size_t adj_x = x + _spread; size_t adj_y = y + _spread; return _data[width() * adj_y + adj_x]; }
//---------------------------------------------------------------- void check_box::set_position(const point2i& p) { NYX_ASSERT(hwnd_ != NULL); rect2i r; get_size(r); ::SetWindowPos(hwnd_, NULL, p.x, p.y, r.width, r.height, SWP_SHOWWINDOW); }
int InputLayout::init(InputLayout& obj, const VertexFormat& vf, const void* code, size_t length) { NYX_ASSERT(obj._input_layout == nullptr); ID3D11Device* device = RenderDevice::device(); D3D11_INPUT_ELEMENT_DESC descs[VertexFormat::MAX_ELEMENT_COUNT]; size_t element_count = vf.element_count(); for (size_t i = 0; i < element_count; ++i) { const VertexFormat::Element& elem = vf.element(i); descs[i].SemanticName = vertex_semantic_to_string(elem.semantic); descs[i].SemanticIndex = elem.semantic_index; descs[i].Format = to_dxgi(elem.format); descs[i].InputSlot = elem.input_slot; descs[i].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; descs[i].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; descs[i].InstanceDataStepRate = 0; } HRESULT hr = device->CreateInputLayout(descs, element_count, code, length, &obj._input_layout); if (FAILED(hr)) { term(obj); return 1; } return 0; }
int VertexBuffer::init(VertexBuffer& obj, size_t vertex_count, size_t vertex_size, const void* data) { NYX_ASSERT(obj._buffer == nullptr); ID3D11Device* device = RenderDevice::device(); D3D11_BUFFER_DESC desc; desc.ByteWidth = vertex_count * vertex_size; desc.Usage = D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; desc.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA init; init.pSysMem = data; init.SysMemPitch = 0; init.SysMemSlicePitch = 0; HRESULT hr = device->CreateBuffer(&desc, &init, &obj._buffer); if (FAILED(hr)) { term(obj); return 1; } obj._vertex_count = vertex_count; obj._vertex_size = vertex_size; return 0; }
//----------------------------------------------------------------------------------------- // bool joystick::update() { NYX_ASSERT(pimpl_!= nullptr); if (pimpl_->isInitialized == false) { return false; } return pimpl_->update(); }
//------------------------------------------------------------------------------------------------------- // void dsound_3d_audio_buffer::set_velocity(const vector3f& velocity) { NYX_ASSERT(buffer_ != nullptr); HRESULT hr = buffer_->SetVelocity(velocity.x, velocity.y, velocity.z, NULL); if (FAILED(hr)) { debug_out::trace("音源の速度の設定に失敗しました。[%s, %n]", __FILE__, __LINE__); throw com_exception("音源の速度の設定に失敗しました。", hr); } }
//------------------------------------------------------------------------------------------------------- // void dsound_3d_audio_buffer::set_position(const vector3f& pos) { NYX_ASSERT(buffer_ != nullptr); HRESULT hr = buffer_->SetPosition(pos.x, pos.y, pos.z, NULL); if (FAILED(hr)) { debug_out::trace("音源の位置の設定に失敗しました。[%s, %n]", __FILE__, __LINE__); throw com_exception("音源の位置の設定に失敗しました。", hr); } }
//---------------------------------------------------------------- void check_box::get_position(point2i& p) const { NYX_ASSERT(hwnd_ != NULL); RECT _r; ::GetWindowRect(hwnd_, &_r); p.x = _r.left; p.y = _r.top; }
//------------------------------------------------------------------------------------------------------- // void dsound_3d_audio_buffer::set_min_distance(float minDistance) { NYX_ASSERT(buffer_ != nullptr); HRESULT hr = buffer_->SetMinDistance(minDistance, NULL); if (FAILED(hr)) { debug_out::trace("音源の最小距離の設定に失敗しました。[%s,%d]",__FILE__, __LINE__); throw com_exception("音源の最小距離の設定に失敗しました。", hr); } }
//------------------------------------------------------------------------------------------------------- // void dsound_audio_buffer::stop() { NYX_ASSERT(soundBuffer_ != nullptr); HRESULT hr = soundBuffer_->Stop(); if (FAILED(hr)) { debug_out::trace("DirectSoundオーディオバッファを停止出来ませんでした。[%s:%d]", __FILE__, __LINE__); throw com_exception("DirectSoundオーディオバッファを停止出来ませんでした。", hr); } }
//------------------------------------------------------------------------------------------------------- // void dsound_audio_buffer::set_volume(long volume) { NYX_ASSERT(soundBuffer_ != nullptr); long decibel = volume_to_decibel(volume); HRESULT hr = soundBuffer_->SetVolume(decibel); if (FAILED(hr)) { debug_out::trace("DirectSoundオーディオバッファのデシベル値の設定に失敗しました。[%s:%d]", __FILE__, __LINE__); throw com_exception("DirectSoundオーディオバッファのデシベル値の設定に失敗しました。", hr); } }
//----------------------------------------------------------------------------------------- // uint8_t* joystick::get_key_buffer() { NYX_ASSERT(pimpl_ != nullptr); if (pimpl_->isInitialized == false) { return nullptr; } return pimpl_->get_key_buffer(); }
//----------------------------------------------------------------------------------------- // axis3f joystick::get_axis() { NYX_ASSERT(pimpl_ != nullptr); if (pimpl_->isInitialized == false) { return axis3f(-1.f, -1.f, -1.f); } return pimpl_->get_axis(); }
//------------------------------------------------------------------------------------------------------- // void dsound_audio_buffer::play(bool isLoop) { NYX_ASSERT(soundBuffer_ != nullptr); isLoop_ = isLoop; HRESULT hr = soundBuffer_->Play(0, 0, isLoop_); if (FAILED(hr)) { debug_out::trace("DirectSoundオーディオバッファを再生出来ませんでした。[%s:%d]", __FILE__, __LINE__); throw com_exception("DirectSoundオーディオバッファを再生出来ませんでした。", hr); } }
//------------------------------------------------------------------------------------------------------- // float dsound_3d_audio_buffer::get_max_distance() const { float distance; NYX_ASSERT(buffer_ != nullptr); HRESULT hr = buffer_->GetMaxDistance(&distance); if (FAILED(hr)) { debug_out::trace("音源の最大距離の取得に失敗しました。[%s, %d]",__FILE__, __LINE__); throw com_exception("音源の最大距離の取得に失敗しました。", hr); } return distance; }
//------------------------------------------------------------------------------------------------------- // vector3f dsound_3d_audio_buffer::get_velocity() const { NYX_ASSERT(buffer_ != nullptr); D3DXVECTOR3 velocity; HRESULT hr = buffer_->GetVelocity(&velocity); if (FAILED(hr)) { debug_out::trace("音源の速度の取得に失敗しました。[%s, %n]", __FILE__, __LINE__); throw com_exception("音源の速度の取得に失敗しました。", hr); } return vector3f(velocity.x, velocity.y, velocity.z); }
//------------------------------------------------------------------------------------------------------- // vector3f dsound_3d_audio_buffer::get_position() const { NYX_ASSERT(buffer_ != nullptr); D3DXVECTOR3 pos; HRESULT hr = buffer_->GetPosition(&pos); if (FAILED(hr)) { debug_out::trace("音源の位置の取得に失敗しました。[%s,%n]", __FILE__, __LINE__); throw com_exception("音源の位置の取得に失敗しました。", hr); } return vector3f(pos.x, pos.y, pos.z); }
//------------------------------------------------------------------------------------------------------- // void dsound_audio_buffer::reset() { NYX_ASSERT(soundBuffer_ != nullptr); HRESULT hr = soundBuffer_->SetCurrentPosition(0); if (FAILED(hr)) { debug_out::trace("DirectSoundオーディオバッファの再生位置をリセット出来ませんでした。[%s:%d]", __FILE__, __LINE__); throw com_exception("DirectSoundオーディオバッファの再生位置をリセット出来ませんでした。", hr); } }
bool keyboard::initialize(const input_device_desc& desc) { NYX_ASSERT(pimpl_ != nullptr); if (is_initialized()) { return is_initialized(); } pimpl_->initialize((HWND)desc.handle); return pimpl_->isInitialized; }
//------------------------------------------------------------------------------------------------------- // uint64_t dsound_audio_buffer::get_status() const { NYX_ASSERT(soundBuffer_ != nullptr); uint64_t status; HRESULT hr = soundBuffer_->GetStatus(&status); if (FAILED(hr)) { debug_out::trace("DirectSoundオーディオバッファのステータスコードを取得出来ませんでした。[%s:%d]", __FILE__, __LINE__); throw com_exception("DirectSoundオーディオバッファのステータスコードを取得出来ませんでした。", hr); } return status; }
//----------------------------------------------------------------------------------------- // bool joystick::is_pressed(JOYSTICK_BUTTON keycode) { NYX_ASSERT(pimpl_ != nullptr); if (pimpl_->isInitialized == false) { return false; } uint8_t key = static_cast<uint8_t>(keycode); return pimpl_->is_pressed(key); }
//----------------------------------------------------------------------------------------- // bool joystick::initialize(const input_device_desc& desc) { NYX_ASSERT(pimpl_ != nullptr); if (is_initialized()) { return is_initialized(); } pimpl_->initialize((HWND)desc.handle, desc.range, desc.button); return pimpl_->isInitialized; }
void Kernel2D::set(const Kernel2D& rhs) { NYX_ASSERT(_spread == rhs._spread); size_t len = length(); for (size_t i = 0; i < len; ++i) { _data[i] = rhs._data[i]; } }
//------------------------------------------------------------------------------------------------------- // long dsound_audio_buffer::get_volume() const { NYX_ASSERT(soundBuffer_ != nullptr); long decibel; HRESULT hr = soundBuffer_->GetVolume(&decibel); if (FAILED(hr)) { debug_out::trace("DirectSoundオーディオバッファのデシベル値の取得に失敗しました。[%s:%d]", __FILE__, __LINE__); throw com_exception("DirectSoundオーディオバッファのデシベル値の取得に失敗しました。", hr); } return decibel_to_volume(decibel); }
//------------------------------------------------------------------------------------------------------- // audio_state dsound_audio_buffer::get_audio_state() const { NYX_ASSERT(soundBuffer_ != nullptr); uint64_t status = get_status(); audio_state state; state.isBufferLost = (status & DSBSTATUS_BUFFERLOST) != 0; state.isLooping = (status & DSBSTATUS_LOOPING) != 0; state.isPlaying = (status & DSBSTATUS_PLAYING) != 0; return state; }
//---------------------------------------------------------------- void check_box::get_size(rect2i& rect) const { NYX_ASSERT(hwnd_ != NULL); RECT r; ::GetWindowRect(hwnd_, &r); // rect.x = r.left; rect.y = r.top; rect.width = r.right - r.left; rect.height = r.bottom - r.top; }
//------------------------------------------------------------------------------------------------------- // void dsound_3d_audio_buffer::create_3d_buffer() { auto handle = get_handle(); NYX_ASSERT(handle != nullptr); IDirectSound3DBuffer8* buffer; HRESULT hr = handle->QueryInterface(IID_IDirectSound3DBuffer8, reinterpret_cast<void**>(&buffer)); if (FAILED(hr)) { debug_out::trace("IDirectSound3DBuffer8の取得に失敗しました。[%s,%d]",__FILE__, __LINE__); throw com_exception("IDirectSound3DBuffer8の取得に失敗しました。", hr); } //スマートポインタの管理下に置く buffer_ = buffer; }