mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
audio subsystem replacement: openal audio renderer and buffer class, removed deprecated files
This commit is contained in:
8
EU07.cpp
8
EU07.cpp
@@ -25,12 +25,14 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
#include "Globals.h"
|
||||
#include "timer.h"
|
||||
#include "Logs.h"
|
||||
#include "renderer.h"
|
||||
#include "uilayer.h"
|
||||
#include "audiorenderer.h"
|
||||
#include "keyboardinput.h"
|
||||
#include "mouseinput.h"
|
||||
#include "gamepadinput.h"
|
||||
#include "Console.h"
|
||||
#include "PyInt.h"
|
||||
#include "uilayer.h"
|
||||
|
||||
#ifdef EU07_BUILD_STATIC
|
||||
#pragma comment( lib, "glfw3.lib" )
|
||||
@@ -46,6 +48,7 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
#pragma comment( lib, "opengl32.lib" )
|
||||
#pragma comment( lib, "glu32.lib" )
|
||||
#pragma comment( lib, "dsound.lib" )
|
||||
#pragma comment( lib, "openal32.lib")
|
||||
#pragma comment( lib, "winmm.lib" )
|
||||
#pragma comment( lib, "setupapi.lib" )
|
||||
#pragma comment( lib, "python27.lib" )
|
||||
@@ -405,6 +408,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
audio::renderer.init();
|
||||
|
||||
input::Keyboard.init();
|
||||
input::Mouse.init();
|
||||
input::Gamepad.init();
|
||||
|
||||
@@ -2375,44 +2375,52 @@ bool TMoverParameters::MainSwitch( bool const State, int const Notify )
|
||||
{
|
||||
bool MS = false; // Ra: przeniesione z końca
|
||||
|
||||
if ((Mains != State) && (MainCtrlPosNo > 0))
|
||||
{
|
||||
if ((State == false) ||
|
||||
(((ScndCtrlPos == 0)||(EngineType == ElectricInductionMotor)) && ((ConvOvldFlag == false) || (TrainType == dt_EZT)) &&
|
||||
(LastSwitchingTime > CtrlDelay) && !TestFlag(DamageFlag, dtrain_out) &&
|
||||
!TestFlag(EngDmgFlag, 1)))
|
||||
{
|
||||
if( Mains ) {
|
||||
if( ( Mains != State )
|
||||
&& ( MainCtrlPosNo > 0 ) ) {
|
||||
|
||||
if( ( false == State )
|
||||
|| ( ( ( ScndCtrlPos == 0 ) || ( EngineType == ElectricInductionMotor ) )
|
||||
&& ( ( ConvOvldFlag == false ) || ( TrainType == dt_EZT ) )
|
||||
&& ( LastSwitchingTime > CtrlDelay )
|
||||
&& ( false == TestFlag( DamageFlag, dtrain_out ) )
|
||||
&& ( false == TestFlag( EngDmgFlag, 1 ) ) ) ) {
|
||||
|
||||
if( true == Mains ) {
|
||||
// jeśli był załączony
|
||||
if( Notify != range::local ) {
|
||||
// wysłanie wyłączenia do pozostałych?
|
||||
SendCtrlToNext(
|
||||
"MainSwitch", int( State ), CabNo,
|
||||
( Notify == range::unit ?
|
||||
ctrain_controll | ctrain_depot :
|
||||
ctrain_controll ) );
|
||||
coupling::control | coupling::permanent :
|
||||
coupling::control ) );
|
||||
}
|
||||
}
|
||||
Mains = State;
|
||||
if( Mains ) {
|
||||
MS = true; // wartość zwrotna
|
||||
LastSwitchingTime = 0;
|
||||
|
||||
if( true == Mains ) {
|
||||
// jeśli został załączony
|
||||
if( Notify != range::local ) {
|
||||
// wysłanie wyłączenia do pozostałych?
|
||||
SendCtrlToNext(
|
||||
"MainSwitch", int( State ), CabNo,
|
||||
( Notify == range::unit ?
|
||||
ctrain_controll | ctrain_depot :
|
||||
ctrain_controll ) );
|
||||
coupling::control | coupling::permanent :
|
||||
coupling::control ) );
|
||||
}
|
||||
}
|
||||
MS = true; // wartość zwrotna
|
||||
LastSwitchingTime = 0;
|
||||
if ((EngineType == DieselEngine) && Mains)
|
||||
{
|
||||
if( ( EngineType == DieselEngine )
|
||||
&& ( true == Mains ) ) {
|
||||
|
||||
dizel_enginestart = State;
|
||||
}
|
||||
if (((TrainType == dt_EZT) && (!State)))
|
||||
ConvOvldFlag = true;
|
||||
if( ( TrainType == dt_EZT )
|
||||
&& ( false == State ) ) {
|
||||
|
||||
ConvOvldFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// else MainSwitch:=false;
|
||||
|
||||
13
Model3d.h
13
Model3d.h
@@ -13,7 +13,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "Parser.h"
|
||||
#include "dumb3d.h"
|
||||
#include "Float3d.h"
|
||||
#include "VBO.h"
|
||||
#include "openglgeometrybank.h"
|
||||
#include "material.h"
|
||||
|
||||
using namespace Math3D;
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
// places contained geometry in provided ground node
|
||||
};
|
||||
|
||||
class TModel3d : public CMesh
|
||||
class TModel3d
|
||||
{
|
||||
friend class opengl_renderer;
|
||||
|
||||
@@ -221,7 +221,9 @@ private:
|
||||
TSubModel *Root; // drzewo submodeli
|
||||
int iFlags; // Ra: czy submodele mają przezroczyste tekstury
|
||||
public: // Ra: tymczasowo
|
||||
int iNumVerts; // ilość wierzchołków (gdy nie ma VBO, to m_nVertexCount=0)
|
||||
int iNumVerts; // ilość wierzchołków (gdy nie ma VBO, to m_nVertexCount=0)
|
||||
geometrybank_handle m_geometrybank;
|
||||
bool m_geometrycreated { false };
|
||||
private:
|
||||
std::vector<std::string> Textures; // nazwy tekstur
|
||||
std::vector<std::string> Names; // nazwy submodeli
|
||||
@@ -229,15 +231,16 @@ private:
|
||||
int iSubModelsCount; // Ra: używane do tworzenia binarnych
|
||||
std::string asBinary; // nazwa pod którą zapisać model binarny
|
||||
std::string m_filename;
|
||||
|
||||
public:
|
||||
TModel3d();
|
||||
~TModel3d();
|
||||
float bounding_radius() const {
|
||||
return (
|
||||
Root ?
|
||||
Root->m_boundingradius :
|
||||
0.f ); }
|
||||
inline TSubModel * GetSMRoot() { return (Root); };
|
||||
TModel3d();
|
||||
~TModel3d();
|
||||
TSubModel * GetFromName(std::string const &Name);
|
||||
TSubModel * AddToNamed(const char *Name, TSubModel *SubModel);
|
||||
void AddTo(TSubModel *tmp, TSubModel *SubModel);
|
||||
|
||||
4
Names.h
4
Names.h
@@ -50,10 +50,10 @@ public:
|
||||
protected:
|
||||
// types
|
||||
using type_sequence = std::deque<Type_ *>;
|
||||
using type_map = std::unordered_map<std::string, std::size_t>;
|
||||
using index_map = std::unordered_map<std::string, std::size_t>;
|
||||
// members
|
||||
type_sequence m_items;
|
||||
type_map m_itemmap;
|
||||
index_map m_itemmap;
|
||||
|
||||
public:
|
||||
// data access
|
||||
|
||||
@@ -8,6 +8,14 @@ http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
enum class resource_state {
|
||||
none,
|
||||
loading,
|
||||
good,
|
||||
failed
|
||||
};
|
||||
|
||||
/*
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
12
Texture.h
12
Texture.h
@@ -15,13 +15,6 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "GL/glew.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
enum class resource_state {
|
||||
none,
|
||||
loading,
|
||||
good,
|
||||
failed
|
||||
};
|
||||
|
||||
struct opengl_texture {
|
||||
static DDSURFACEDESC2 deserialize_ddsd(std::istream&);
|
||||
static DDCOLORKEY deserialize_ddck(std::istream&);
|
||||
@@ -88,13 +81,16 @@ public:
|
||||
|
||||
void
|
||||
assign_units( GLint const Helper, GLint const Shadows, GLint const Normals, GLint const Diffuse );
|
||||
// activates specified texture unit
|
||||
void
|
||||
unit( GLint const Textureunit );
|
||||
// creates texture object out of data stored in specified file
|
||||
texture_handle
|
||||
create( std::string Filename, bool const Loadnow = true );
|
||||
// binds specified texture to specified texture unit
|
||||
void
|
||||
bind( std::size_t const Unit, texture_handle const Texture );
|
||||
// provides direct access to specified texture object
|
||||
opengl_texture &
|
||||
texture( texture_handle const Texture ) const { return *(m_textures[ Texture ].first); }
|
||||
// performs a resource sweep
|
||||
@@ -186,7 +182,7 @@ downsample( std::size_t const Width, std::size_t const Height, char *Imagedata )
|
||||
(*sampler)[idx]
|
||||
+ ( *( sampler + 1 ) )[idx]
|
||||
+ ( *( sampler + Width ) )[idx]
|
||||
+ (*( sampler + Width + 1 ))[idx] );
|
||||
+ ( *( sampler + Width + 1 ))[idx] );
|
||||
color[ idx ] = component /= 4;
|
||||
}
|
||||
*destination++ = color;
|
||||
|
||||
16
Train.cpp
16
Train.cpp
@@ -589,9 +589,9 @@ void TTrain::OnCommand_secondcontrollerincrease( TTrain *Train, command_data con
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
// on press or hold
|
||||
if( Train->mvControlled->ShuntMode ) {
|
||||
Train->mvControlled->AnPos += ( Command.time_delta * 0.75f );
|
||||
if( Train->mvControlled->AnPos > 1 )
|
||||
Train->mvControlled->AnPos = 1;
|
||||
Train->mvControlled->AnPos = clamp(
|
||||
Train->mvControlled->AnPos + ( Command.time_delta * 1.0f ),
|
||||
0.0, 1.0 );
|
||||
}
|
||||
else {
|
||||
Train->mvControlled->IncScndCtrl( 1 );
|
||||
@@ -650,9 +650,9 @@ void TTrain::OnCommand_secondcontrollerdecrease( TTrain *Train, command_data con
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
// on press or hold
|
||||
if( Train->mvControlled->ShuntMode ) {
|
||||
Train->mvControlled->AnPos -= ( Command.time_delta * 0.75f );
|
||||
if( Train->mvControlled->AnPos > 1 )
|
||||
Train->mvControlled->AnPos = 1;
|
||||
Train->mvControlled->AnPos = clamp(
|
||||
Train->mvControlled->AnPos - ( Command.time_delta * 1.0f ),
|
||||
0.0, 1.0 );
|
||||
}
|
||||
Train->mvControlled->DecScndCtrl( 1 );
|
||||
}
|
||||
@@ -2030,7 +2030,9 @@ void TTrain::OnCommand_motoroverloadrelaythresholdtoggle( TTrain *Train, command
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
||||
if( Train->mvControlled->Imax < Train->mvControlled->ImaxHi ) {
|
||||
if( ( true == Train->mvControlled->ShuntModeAllow ?
|
||||
( false == Train->mvControlled->ShuntMode ) :
|
||||
( Train->mvControlled->Imax < Train->mvControlled->ImaxHi ) ) ) {
|
||||
// turn on
|
||||
if( true == Train->mvControlled->CurrentSwitch( true ) ) {
|
||||
// visual feedback
|
||||
|
||||
10
World.cpp
10
World.cpp
@@ -1422,7 +1422,11 @@ TWorld::Update_UI() {
|
||||
+ ( vehicle->MoverParameters->bPantKurek3 ? "-ZG" : "|ZG" );
|
||||
|
||||
uitextline2 +=
|
||||
"; Ft: " + to_string( vehicle->MoverParameters->Ft * 0.001f * vehicle->MoverParameters->ActiveCab, 1 )
|
||||
"; Ft: " + to_string(
|
||||
vehicle->MoverParameters->Ft * 0.001f * (
|
||||
vehicle->MoverParameters->ActiveCab ? vehicle->MoverParameters->ActiveCab :
|
||||
vehicle->ctOwner ? vehicle->ctOwner->Controlling()->ActiveCab :
|
||||
1 ), 1 )
|
||||
+ ", Fb: " + to_string( vehicle->MoverParameters->Fb * 0.001f, 1 )
|
||||
+ ", Fr: " + to_string( vehicle->MoverParameters->Adhesive( vehicle->MoverParameters->RunningTrack.friction ), 2 )
|
||||
+ ( vehicle->MoverParameters->SlippingWheels ? " (!)" : "" );
|
||||
@@ -1640,7 +1644,9 @@ TWorld::Update_UI() {
|
||||
"HamZ=" + to_string( vehicle->MoverParameters->fBrakeCtrlPos, 2 )
|
||||
+ "; HamP=" + std::to_string( vehicle->MoverParameters->LocalBrakePos ) + "/" + to_string( vehicle->MoverParameters->LocalBrakePosA, 2 )
|
||||
+ "; NasJ=" + std::to_string( vehicle->MoverParameters->MainCtrlPos ) + "(" + std::to_string( vehicle->MoverParameters->MainCtrlActualPos ) + ")"
|
||||
+ "; NasB=" + std::to_string( vehicle->MoverParameters->ScndCtrlPos ) + "(" + std::to_string( vehicle->MoverParameters->ScndCtrlActualPos ) + ")"
|
||||
+ ( vehicle->MoverParameters->ShuntMode ?
|
||||
"; NasB=" + to_string( vehicle->MoverParameters->AnPos, 2 ) :
|
||||
"; NasB=" + std::to_string( vehicle->MoverParameters->ScndCtrlPos ) + "(" + std::to_string( vehicle->MoverParameters->ScndCtrlActualPos ) + ")" )
|
||||
+ "; I=" +
|
||||
( vehicle->MoverParameters->TrainType == dt_EZT ?
|
||||
std::to_string( int( vehicle->MoverParameters->ShowCurrent( 0 ) ) ) :
|
||||
|
||||
181
audio.cpp
Normal file
181
audio.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "audio.h"
|
||||
#include "globals.h"
|
||||
#include "mczapkie/mctools.h"
|
||||
|
||||
#define DR_WAV_IMPLEMENTATION
|
||||
#include "dr_wav.h"
|
||||
#define DR_FLAC_IMPLEMENTATION
|
||||
#include "dr_flac.h"
|
||||
|
||||
namespace audio {
|
||||
|
||||
openal_buffer::openal_buffer( std::string const &Filename ) :
|
||||
name( Filename ) {
|
||||
|
||||
::alGenBuffers( 1, &id );
|
||||
// fetch audio data
|
||||
if( Filename.substr( Filename.rfind( '.' ) ) == ".wav" ) {
|
||||
// .wav file
|
||||
auto *file { drwav_open_file( Filename.c_str() ) };
|
||||
rate = file->sampleRate;
|
||||
auto const samplecount { static_cast<std::size_t>( file->totalSampleCount ) };
|
||||
data.resize( samplecount );
|
||||
drwav_read_s16(
|
||||
file,
|
||||
samplecount,
|
||||
&data[ 0 ] );
|
||||
if( file->channels > 1 ) {
|
||||
narrow_to_mono( file->channels );
|
||||
data.resize( samplecount / file->channels );
|
||||
}
|
||||
// we're done with the disk data
|
||||
drwav_close( file );
|
||||
}
|
||||
else {
|
||||
// .flac or .ogg file
|
||||
auto *file { drflac_open_file( Filename.c_str() ) };
|
||||
rate = file->sampleRate;
|
||||
auto const samplecount{ static_cast<std::size_t>( file->totalSampleCount ) };
|
||||
data.resize( samplecount );
|
||||
drflac_read_s16(
|
||||
file,
|
||||
samplecount,
|
||||
&data[ 0 ] );
|
||||
if( file->channels > 1 ) {
|
||||
narrow_to_mono( file->channels );
|
||||
data.resize( samplecount / file->channels );
|
||||
}
|
||||
// we're done with the disk data
|
||||
drflac_close( file );
|
||||
}
|
||||
// send the data to openal side
|
||||
::alBufferData( id, AL_FORMAT_MONO16, data.data(), data.size() * sizeof( std::int16_t ), rate );
|
||||
// and get rid of the source, we shouldn't need it anymore
|
||||
// TBD, TODO: delay data fetching and transfers until the buffer is actually used?
|
||||
std::vector<std::int16_t>().swap( data );
|
||||
}
|
||||
|
||||
// mix specified number of interleaved multi-channel data, down to mono
|
||||
void
|
||||
openal_buffer::narrow_to_mono( std::uint16_t const Channelcount ) {
|
||||
|
||||
std::size_t monodataindex { 0 };
|
||||
std::int32_t accumulator { 0 };
|
||||
auto channelcount { Channelcount };
|
||||
|
||||
for( auto const channeldata : data ) {
|
||||
|
||||
accumulator += channeldata;
|
||||
if( --channelcount == 0 ) {
|
||||
|
||||
data[ monodataindex++ ] = accumulator / Channelcount;
|
||||
accumulator = 0;
|
||||
channelcount = Channelcount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
buffer_manager::~buffer_manager() {
|
||||
|
||||
for( auto &buffer : m_buffers ) {
|
||||
if( buffer.id != null_resource ) {
|
||||
::alDeleteBuffers( 1, &( buffer.id ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// creates buffer object out of data stored in specified file. returns: handle to the buffer or null_handle if creation failed
|
||||
buffer_handle
|
||||
buffer_manager::create( std::string const &Filename ) {
|
||||
|
||||
auto filename { ToLower( Filename ) };
|
||||
|
||||
auto const dotpos { filename.rfind( '.' ) };
|
||||
if( ( dotpos != std::string::npos )
|
||||
&& ( dotpos != filename.rfind( ".." ) + 1 ) ) {
|
||||
// trim extension if there's one, but don't mistake folder traverse for extension
|
||||
filename.erase( dotpos );
|
||||
}
|
||||
// convert slashes
|
||||
std::replace(
|
||||
std::begin( filename ), std::end( filename ),
|
||||
'\\', '/' );
|
||||
|
||||
// try dynamic-specific sounds first
|
||||
auto lookup { find_buffer( Global::asCurrentDynamicPath + filename ) };
|
||||
if( lookup != null_handle ) {
|
||||
return lookup;
|
||||
}
|
||||
std::string filelookup { find_file( Global::asCurrentDynamicPath + filename ) };
|
||||
if( false == filelookup.empty() ) {
|
||||
return emplace( filelookup );
|
||||
}
|
||||
// if dynamic-specific lookup finds nothing, try the default sound folder
|
||||
lookup = find_buffer( szSoundPath + filename );
|
||||
if( lookup != null_handle ) {
|
||||
return lookup;
|
||||
}
|
||||
filelookup = find_file( szSoundPath + filename );
|
||||
if( false == filelookup.empty() ) {
|
||||
return emplace( filelookup );
|
||||
}
|
||||
// if we still didn't find anything, give up
|
||||
return null_handle;
|
||||
}
|
||||
|
||||
// places in the bank a buffer containing data stored in specified file. returns: handle to the buffer
|
||||
buffer_handle
|
||||
buffer_manager::emplace( std::string Filename ) {
|
||||
|
||||
buffer_handle const handle { m_buffers.size() };
|
||||
m_buffers.emplace_back( Filename );
|
||||
|
||||
// NOTE: we store mapping without file type extension, to simplify lookups
|
||||
m_buffermappings.emplace(
|
||||
Filename.erase( Filename.rfind( '.' ) ),
|
||||
handle );
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
buffer_handle
|
||||
buffer_manager::find_buffer( std::string const &Buffername ) const {
|
||||
|
||||
auto lookup = m_buffermappings.find( Buffername );
|
||||
if( lookup != m_buffermappings.end() )
|
||||
return lookup->second;
|
||||
else
|
||||
return null_handle;
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
buffer_manager::find_file( std::string const &Filename ) const {
|
||||
|
||||
std::vector<std::string> const extensions { ".wav", ".flac", ".ogg" };
|
||||
|
||||
for( auto const &extension : extensions ) {
|
||||
if( FileExists( Filename + extension ) ) {
|
||||
// valid name on success
|
||||
return Filename + extension;
|
||||
}
|
||||
}
|
||||
return {}; // empty string on failure
|
||||
}
|
||||
|
||||
} // audio
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
72
audio.h
Normal file
72
audio.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "al.h"
|
||||
#include "alc.h"
|
||||
|
||||
namespace audio {
|
||||
|
||||
ALuint const null_resource { ~ALuint{ 0 } };
|
||||
|
||||
struct openal_buffer {
|
||||
// members
|
||||
ALuint id { null_resource }; // associated AL resource
|
||||
unsigned int rate { 0 }; // sample rate of the data
|
||||
std::string name;
|
||||
// constructors
|
||||
openal_buffer() = default;
|
||||
explicit openal_buffer( std::string const &Filename );
|
||||
|
||||
private:
|
||||
// methods
|
||||
// mix specified number of interleaved multi-channel data, down to mono
|
||||
void
|
||||
narrow_to_mono( std::uint16_t const Channelcount );
|
||||
// members
|
||||
std::vector<std::int16_t> data; // audio data
|
||||
};
|
||||
|
||||
using buffer_handle = std::size_t;
|
||||
|
||||
class buffer_manager {
|
||||
|
||||
public:
|
||||
// constructors
|
||||
buffer_manager() { m_buffers.emplace_back( openal_buffer() ); } // empty bindings for null buffer
|
||||
// destructor
|
||||
~buffer_manager();
|
||||
// methods
|
||||
// creates buffer object out of data stored in specified file. returns: handle to the buffer or null_handle if creation failed
|
||||
buffer_handle
|
||||
create( std::string const &Filename );
|
||||
|
||||
private:
|
||||
// types
|
||||
using buffer_sequence = std::vector<openal_buffer>;
|
||||
using index_map = std::unordered_map<std::string, std::size_t>;
|
||||
// methods
|
||||
// places in the bank a buffer containing data stored in specified file. returns: handle to the buffer
|
||||
buffer_handle
|
||||
emplace( std::string Filename );
|
||||
// checks whether specified buffer is in the buffer bank. returns: buffer handle, or null_handle.
|
||||
buffer_handle
|
||||
find_buffer( std::string const &Buffername ) const;
|
||||
// checks whether specified file exists. returns: name of the located file, or empty string.
|
||||
std::string
|
||||
find_file( std::string const &Filename ) const;
|
||||
// members
|
||||
buffer_sequence m_buffers;
|
||||
index_map m_buffermappings;
|
||||
};
|
||||
|
||||
} // audio
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
83
audiorenderer.cpp
Normal file
83
audiorenderer.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "audiorenderer.h"
|
||||
#include "logs.h"
|
||||
|
||||
namespace audio {
|
||||
|
||||
openal_renderer renderer;
|
||||
|
||||
openal_renderer::~openal_renderer() {
|
||||
|
||||
::alcMakeContextCurrent( nullptr );
|
||||
|
||||
if( m_context != nullptr ) { ::alcDestroyContext( m_context ); }
|
||||
if( m_device != nullptr ) { ::alcCloseDevice( m_device ); }
|
||||
}
|
||||
|
||||
buffer_handle
|
||||
openal_renderer::fetch_buffer( std::string const &Filename ) {
|
||||
|
||||
return m_buffers.create( Filename );
|
||||
}
|
||||
|
||||
// initializes the service
|
||||
bool
|
||||
openal_renderer::init() {
|
||||
|
||||
if( true == m_ready ) {
|
||||
// already initialized and enabled
|
||||
return true;
|
||||
}
|
||||
if( false == init_caps() ) {
|
||||
// basic initialization failed
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ready = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
openal_renderer::init_caps() {
|
||||
|
||||
// select the "preferred device"
|
||||
// TODO: support for opening config-specified device
|
||||
m_device = ::alcOpenDevice( nullptr );
|
||||
if( m_device == nullptr ) {
|
||||
ErrorLog( "Failed to obtain audio device" );
|
||||
return false;
|
||||
}
|
||||
|
||||
ALCint versionmajor, versionminor;
|
||||
::alcGetIntegerv( m_device, ALC_MAJOR_VERSION, 1, &versionmajor );
|
||||
::alcGetIntegerv( m_device, ALC_MINOR_VERSION, 1, &versionminor );
|
||||
auto const oalversion { std::to_string( versionmajor ) + "." + std::to_string( versionminor ) };
|
||||
|
||||
WriteLog(
|
||||
"Audio Renderer: " + std::string { (char *)::alcGetString( m_device, ALC_DEVICE_SPECIFIER ) }
|
||||
+ " OpenAL Version: " + oalversion );
|
||||
|
||||
WriteLog( "Supported extensions: " + std::string{ (char *)::alcGetString( m_device, ALC_EXTENSIONS ) } );
|
||||
|
||||
m_context = ::alcCreateContext( m_device, nullptr );
|
||||
if( m_context == nullptr ) {
|
||||
ErrorLog( "Failed to create audio context" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( ::alcMakeContextCurrent( m_context ) == AL_TRUE );
|
||||
}
|
||||
|
||||
} // audio
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
47
audiorenderer.h
Normal file
47
audiorenderer.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "audio.h"
|
||||
|
||||
namespace audio {
|
||||
|
||||
class openal_renderer {
|
||||
|
||||
public:
|
||||
// destructor
|
||||
~openal_renderer();
|
||||
// methods
|
||||
// buffer methods
|
||||
// returns handle to a buffer containing audio data from specified file
|
||||
buffer_handle
|
||||
fetch_buffer( std::string const &Filename );
|
||||
// core methods
|
||||
// initializes the service
|
||||
bool
|
||||
init();
|
||||
|
||||
private:
|
||||
// methods
|
||||
bool
|
||||
init_caps();
|
||||
// members
|
||||
ALCdevice * m_device { nullptr };
|
||||
ALCcontext * m_context { nullptr };
|
||||
bool m_ready { false }; // renderer is initialized and functional
|
||||
|
||||
buffer_manager m_buffers;
|
||||
};
|
||||
|
||||
extern openal_renderer renderer;
|
||||
|
||||
} // audio
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -27,9 +27,6 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AdvSound.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AirCoupler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -93,9 +90,6 @@
|
||||
<ClCompile Include="PyInt.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RealSound.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ResourceManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -105,9 +99,6 @@
|
||||
<ClCompile Include="sky.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Sound.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Spring.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -132,12 +123,6 @@
|
||||
<ClCompile Include="TrkFoll.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="VBO.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="wavread.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="World.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -240,6 +225,12 @@
|
||||
<ClCompile Include="messaging.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="audiorenderer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="audio.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Globals.h">
|
||||
@@ -287,9 +278,6 @@
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="VBO.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Float3d.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -320,9 +308,6 @@
|
||||
<ClInclude Include="Console\LPT.h">
|
||||
<Filter>Header Files\input</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RealSound.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Segment.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -347,12 +332,6 @@
|
||||
<ClInclude Include="Names.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Sound.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AdvSound.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Model3d.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -362,9 +341,6 @@
|
||||
<ClInclude Include="AnimModel.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="wavread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Track.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -470,6 +446,12 @@
|
||||
<ClInclude Include="messaging.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="audiorenderer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="audio.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="maszyna.rc">
|
||||
|
||||
@@ -105,7 +105,7 @@ material_manager::create( std::string const &Filename, bool const Loadnow ) {
|
||||
|
||||
// try to locate requested material in the databank
|
||||
auto const databanklookup = find_in_databank( filename );
|
||||
if( databanklookup != npos ) {
|
||||
if( databanklookup != null_handle ) {
|
||||
return databanklookup;
|
||||
}
|
||||
// if this fails, try to look for it on disk
|
||||
@@ -149,7 +149,7 @@ material_manager::find_in_databank( std::string const &Materialname ) const {
|
||||
return (
|
||||
lookup != m_materialmappings.end() ?
|
||||
lookup->second :
|
||||
npos );
|
||||
null_handle );
|
||||
}
|
||||
|
||||
// checks whether specified file exists.
|
||||
|
||||
@@ -55,7 +55,6 @@ private:
|
||||
std::string
|
||||
find_on_disk( std::string const &Materialname ) const;
|
||||
// members:
|
||||
material_handle const npos { -1 };
|
||||
material_sequence m_materials;
|
||||
index_map m_materialmappings;
|
||||
|
||||
|
||||
42
renderer.cpp
42
renderer.cpp
@@ -108,7 +108,7 @@ opengl_renderer::Init( GLFWwindow *Window ) {
|
||||
std::vector<GLint>{ m_normaltextureunit, m_diffusetextureunit } );
|
||||
m_textures.assign_units( m_helpertextureunit, m_shadowtextureunit, m_normaltextureunit, m_diffusetextureunit ); // TODO: add reflections unit
|
||||
UILayer.set_unit( m_diffusetextureunit );
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
|
||||
::glDepthFunc( GL_LEQUAL );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
@@ -452,10 +452,10 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
|
||||
|
||||
if( m_environmentcubetexturesupport ) {
|
||||
// restore default texture matrix for reflections cube map
|
||||
Active_Texture( m_helpertextureunit );
|
||||
select_unit( m_helpertextureunit );
|
||||
::glMatrixMode( GL_TEXTURE );
|
||||
::glPopMatrix();
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
::glMatrixMode( GL_MODELVIEW );
|
||||
}
|
||||
}
|
||||
@@ -765,11 +765,11 @@ opengl_renderer::setup_matrices() {
|
||||
if( ( m_renderpass.draw_mode == rendermode::color )
|
||||
&& ( m_environmentcubetexturesupport ) ) {
|
||||
// special case, for colour render pass setup texture matrix for reflections cube map
|
||||
Active_Texture( m_helpertextureunit );
|
||||
select_unit( m_helpertextureunit );
|
||||
::glMatrixMode( GL_TEXTURE );
|
||||
::glPushMatrix();
|
||||
::glMultMatrixf( glm::value_ptr( glm::inverse( glm::mat4{ glm::mat3{ m_renderpass.camera.modelview() } } ) ) );
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
}
|
||||
|
||||
// trim modelview matrix just to rotation, since rendering is done in camera-centric world space
|
||||
@@ -835,7 +835,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
|
||||
// darkens previous stage, preparing data for the shadow texture unit to select from
|
||||
if( m_helpertextureunit >= 0 ) {
|
||||
|
||||
Active_Texture( m_helpertextureunit );
|
||||
select_unit( m_helpertextureunit );
|
||||
|
||||
if( ( true == Reflections )
|
||||
|| ( ( true == Global::RenderShadows ) && ( true == Shadows ) && ( false == Global::bWireFrame ) ) ) {
|
||||
@@ -922,7 +922,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
|
||||
&& ( false == Global::bWireFrame )
|
||||
&& ( m_shadowcolor != colors::white ) ) {
|
||||
|
||||
Active_Texture( m_shadowtextureunit );
|
||||
select_unit( m_shadowtextureunit );
|
||||
// NOTE: shadowmap isn't part of regular texture system, so we use direct bind call here
|
||||
::glBindTexture( GL_TEXTURE_2D, m_shadowtexture );
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
@@ -953,7 +953,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
|
||||
}
|
||||
else {
|
||||
// turn off shadow map tests
|
||||
Active_Texture( m_shadowtextureunit );
|
||||
select_unit( m_shadowtextureunit );
|
||||
|
||||
::glDisable( GL_TEXTURE_2D );
|
||||
::glDisable( GL_TEXTURE_GEN_S );
|
||||
@@ -966,7 +966,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
|
||||
// NOTE: comes after diffuse stage in the operation chain
|
||||
if( m_normaltextureunit >= 0 ) {
|
||||
|
||||
Active_Texture( m_normaltextureunit );
|
||||
select_unit( m_normaltextureunit );
|
||||
|
||||
if( true == Reflections ) {
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
@@ -989,7 +989,7 @@ opengl_renderer::setup_units( bool const Diffuse, bool const Shadows, bool const
|
||||
}
|
||||
// diffuse texture unit.
|
||||
// NOTE: diffuse texture mapping is never fully disabled, alpha channel information is always included
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
if( true == Diffuse ) {
|
||||
// default behaviour, modulate with previous stage
|
||||
@@ -1027,7 +1027,7 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
|
||||
// helper texture unit.
|
||||
if( m_helpertextureunit >= 0 ) {
|
||||
|
||||
Active_Texture( m_helpertextureunit );
|
||||
select_unit( m_helpertextureunit );
|
||||
if( ( true == Reflections )
|
||||
|| ( ( true == Global::RenderShadows )
|
||||
&& ( true == Shadows )
|
||||
@@ -1053,12 +1053,12 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
|
||||
if( m_shadowtextureunit >= 0 ) {
|
||||
if( ( true == Global::RenderShadows ) && ( true == Shadows ) && ( false == Global::bWireFrame ) ) {
|
||||
|
||||
Active_Texture( m_shadowtextureunit );
|
||||
select_unit( m_shadowtextureunit );
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
}
|
||||
else {
|
||||
|
||||
Active_Texture( m_shadowtextureunit );
|
||||
select_unit( m_shadowtextureunit );
|
||||
::glDisable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
@@ -1066,11 +1066,11 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
|
||||
if( m_normaltextureunit >= 0 ) {
|
||||
if( true == Reflections ) {
|
||||
|
||||
Active_Texture( m_normaltextureunit );
|
||||
select_unit( m_normaltextureunit );
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
}
|
||||
else {
|
||||
Active_Texture( m_normaltextureunit );
|
||||
select_unit( m_normaltextureunit );
|
||||
::glDisable( GL_TEXTURE_2D );
|
||||
}
|
||||
}
|
||||
@@ -1078,12 +1078,12 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
|
||||
// NOTE: toggle actually disables diffuse texture mapping, unlike setup counterpart
|
||||
if( true == Diffuse ) {
|
||||
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
::glEnable( GL_TEXTURE_2D );
|
||||
}
|
||||
else {
|
||||
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
::glDisable( GL_TEXTURE_2D );
|
||||
}
|
||||
// update unit state
|
||||
@@ -1095,9 +1095,9 @@ opengl_renderer::switch_units( bool const Diffuse, bool const Shadows, bool cons
|
||||
void
|
||||
opengl_renderer::setup_shadow_color( glm::vec4 const &Shadowcolor ) {
|
||||
|
||||
Active_Texture( m_helpertextureunit );
|
||||
select_unit( m_helpertextureunit );
|
||||
::glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, glm::value_ptr( Shadowcolor ) ); // in-shadow colour multiplier
|
||||
Active_Texture( m_diffusetextureunit );
|
||||
select_unit( m_diffusetextureunit );
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1322,7 +1322,7 @@ opengl_renderer::Material( material_handle const Material ) const {
|
||||
|
||||
// texture methods
|
||||
void
|
||||
opengl_renderer::Active_Texture( GLint const Textureunit ) {
|
||||
opengl_renderer::select_unit( GLint const Textureunit ) {
|
||||
|
||||
return m_textures.unit( Textureunit );
|
||||
}
|
||||
@@ -3327,7 +3327,7 @@ opengl_renderer::Init_caps() {
|
||||
return false;
|
||||
}
|
||||
|
||||
WriteLog( "Supported extensions:" + std::string((char *)glGetString( GL_EXTENSIONS )) );
|
||||
WriteLog( "Supported extensions: " + std::string((char *)glGetString( GL_EXTENSIONS )) );
|
||||
|
||||
WriteLog( std::string("Render path: ") + ( Global::bUseVBO ? "VBO" : "Display lists" ) );
|
||||
if( GLEW_EXT_framebuffer_object ) {
|
||||
|
||||
@@ -178,8 +178,6 @@ public:
|
||||
opengl_material const &
|
||||
Material( material_handle const Material ) const;
|
||||
// texture methods
|
||||
void
|
||||
Active_Texture( GLint const Textureunit );
|
||||
texture_handle
|
||||
Fetch_Texture( std::string const &Filename, bool const Loadnow = true );
|
||||
void
|
||||
@@ -194,14 +192,14 @@ public:
|
||||
Pick_Control() const { return m_pickcontrolitem; }
|
||||
editor::basic_node const *
|
||||
Pick_Node() const { return m_picksceneryitem; }
|
||||
// maintenance jobs
|
||||
// maintenance methods
|
||||
void
|
||||
Update( double const Deltatime );
|
||||
TSubModel const *
|
||||
Update_Pick_Control();
|
||||
editor::basic_node const *
|
||||
Update_Pick_Node();
|
||||
// debug performance string
|
||||
// debug methods
|
||||
std::string const &
|
||||
info_times() const;
|
||||
std::string const &
|
||||
@@ -275,6 +273,9 @@ private:
|
||||
setup_shadow_color( glm::vec4 const &Shadowcolor );
|
||||
void
|
||||
switch_units( bool const Diffuse, bool const Shadows, bool const Reflections );
|
||||
// helper, texture manager method; activates specified texture unit
|
||||
void
|
||||
select_unit( GLint const Textureunit );
|
||||
// runs jobs needed to generate graphics for specified render pass
|
||||
void
|
||||
Render_pass( rendermode const Mode );
|
||||
|
||||
@@ -873,7 +873,7 @@ void
|
||||
basic_region::serialize( std::string const &Scenariofile ) const {
|
||||
|
||||
auto filename { Scenariofile };
|
||||
if( filename[ 0 ] == '$' ) {
|
||||
while( filename[ 0 ] == '$' ) {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
@@ -916,7 +916,7 @@ bool
|
||||
basic_region::deserialize( std::string const &Scenariofile ) {
|
||||
|
||||
auto filename { Scenariofile };
|
||||
if( filename[ 0 ] == '$' ) {
|
||||
while( filename[ 0 ] == '$' ) {
|
||||
// trim leading $ char rainsted utility may add to the base name for modified .scn files
|
||||
filename.erase( 0, 1 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user