这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildsystem/codecompliance/pystyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"""

try:
from pep8 import StyleGuide
except ImportError:
from pycodestyle import StyleGuide
except ImportError:
from pep8 import StyleGuide


# these errors will be ignored by pep8
Expand Down
11 changes: 11 additions & 0 deletions libopenage/assetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ void AssetManager::set_data_dir_string(const std::string& data_dir) {
}
}


void AssetManager::set_engine(Engine *engine) {
this->engine = engine;
}


Engine *AssetManager::get_engine() const {
return this->engine;
}


bool AssetManager::can_load(const std::string &name) const {
return util::file_size(this->root.join(name)) > 0;
}
Expand Down
17 changes: 17 additions & 0 deletions libopenage/assetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GuiItemLink;

namespace openage {

class Engine;
class Texture;

/**
Expand All @@ -31,6 +32,17 @@ class AssetManager final {
std::string get_data_dir_string() const;
void set_data_dir_string(const std::string& data_dir);

/**
* Set the game engine of this asset manager.
* Called from QML.
*/
void set_engine(Engine *engine);

/**
* Return the engine responsible for this asset manager.
*/
Engine *get_engine() const;

/**
* Test whether a requested asset filename can be loaded.
*
Expand Down Expand Up @@ -66,6 +78,11 @@ class AssetManager final {
private:
void clear();

/**
* The engine this asset manager is attached to.
*/
Engine *engine;

/**
* The root directory for the available assets.
*/
Expand Down
20 changes: 13 additions & 7 deletions libopenage/audio/audio_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
namespace openage {
namespace audio {

/**
* Call back that is invoked once SDL needs the next chunk of data.
*/
void global_audio_callback(void *userdata, uint8_t *stream, int len);

AudioManager::AudioManager()
AudioManager::AudioManager(job::JobManager *job_manager)
:
AudioManager{""} {
}
AudioManager{job_manager, ""} {}

AudioManager::AudioManager(const std::string &device_name)
AudioManager::AudioManager(job::JobManager *job_manager, const std::string &device_name)
:
job_manager{job_manager},
device_name{device_name} {

if (SDL_Init(SDL_INIT_AUDIO) < 0) {
Expand Down Expand Up @@ -93,7 +96,7 @@ void AudioManager::load_resources(const util::Dir &asset_dir,
auto loader_policy = from_loader_policy(sound_file.loader_policy);

auto key = std::make_tuple(category, id);
auto resource = Resource::create_resource(category, id, path, format, loader_policy);
auto resource = Resource::create_resource(this, category, id, path, format, loader_policy);

// TODO check resource already existing
resources.insert({key, resource});
Expand Down Expand Up @@ -187,6 +190,10 @@ SDL_AudioSpec AudioManager::get_device_spec() const {
return device_spec;
}

job::JobManager *AudioManager::get_job_manager() const {
return this->job_manager;
}

std::vector<std::string> AudioManager::get_devices() {
std::vector<std::string> device_list;
auto num_devices = SDL_GetNumAudioDevices(0);
Expand Down Expand Up @@ -219,5 +226,4 @@ void global_audio_callback(void *userdata, uint8_t *stream, int len) {
audio_manager->audio_callback(reinterpret_cast<int16_t*>(stream), len / 2);
}

}
}
}} // openage::audio
69 changes: 45 additions & 24 deletions libopenage/audio/audio_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,27 @@
#include "../gamedata/sound_file.gen.h"

namespace openage {
namespace audio {

/*
* This class provides audio functionality.
*/
class AudioManager {
private:
// the used audio device's name
std::string device_name;

// the audio output format
SDL_AudioSpec device_spec;
// the used audio device's id
SDL_AudioDeviceID device_id;
class Engine;

std::unique_ptr<int32_t[]> mix_buffer;
namespace job {
class JobManager;
}

std::unordered_map<std::tuple<category_t,int>,std::shared_ptr<Resource>>
resources;

std::unordered_map<category_t,std::vector<std::shared_ptr<SoundImpl>>>
playing_sounds;
namespace audio {

/**
* This class provides audio functionality for openage.
*/
class AudioManager {
public:
AudioManager();
AudioManager(job::JobManager *job_manager);

// pass empty device name to indicate, that the default device should be
// used
AudioManager(const std::string &device_name);
/**
* Pass empty device name to indicate, that the default device should be used
*/
AudioManager(job::JobManager *job_manager, const std::string &device_name);

~AudioManager();

Expand Down Expand Up @@ -77,6 +69,11 @@ class AudioManager {
*/
SDL_AudioSpec get_device_spec() const;

/**
* Return the game engine the audio manager is attached to.
*/
job::JobManager *get_job_manager() const;

private:
void add_sound(std::shared_ptr<SoundImpl> sound);
void remove_sound(std::shared_ptr<SoundImpl> sound);
Expand All @@ -85,8 +82,33 @@ class AudioManager {
// add and remove sound method's
friend class Sound;

// static functions
/**
* The job manager used in this audio manager for job queuing.
*/
job::JobManager *job_manager;

/**
* the used audio device's name
*/
std::string device_name;

/**
* the audio output format
*/
SDL_AudioSpec device_spec;

/**
* the used audio device's id
*/
SDL_AudioDeviceID device_id;

std::unique_ptr<int32_t[]> mix_buffer;

std::unordered_map<std::tuple<category_t,int>,std::shared_ptr<Resource>> resources;

std::unordered_map<category_t,std::vector<std::shared_ptr<SoundImpl>>> playing_sounds;

// static functions
public:
/**
* Returns a vector of all available device names.
Expand All @@ -102,7 +124,6 @@ class AudioManager {
* Returns the name of the currently used driver.
*/
static std::string get_current_driver();

};

}
Expand Down
26 changes: 14 additions & 12 deletions libopenage/audio/dynamic_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#include "dynamic_resource.h"


#include "audio_manager.h"
#include "../engine.h"
#include "../job/job_manager.h"
#include "../log/log.h"

namespace openage {
Expand All @@ -13,29 +16,29 @@ chunk_info_t::chunk_info_t(chunk_info_t::state_t state,
:
state{state},
actual_size{0},
buffer{new int16_t[buffer_size]} {
}
buffer{std::make_unique<int16_t[]>(buffer_size)} {}

DynamicResource::DynamicResource(category_t category,

DynamicResource::DynamicResource(AudioManager *manager,
category_t category,
int id,
const std::string &path,
format_t format,
int preload_threshold,
size_t chunk_size,
size_t max_chunks)
:
Resource{category, id},
Resource{manager, category, id},
path{path},
format{format},
preload_threshold{preload_threshold},
chunk_size{chunk_size},
max_chunks{max_chunks},
use_count{0} {
}
use_count{0} {}

void DynamicResource::use() {
log::log(MSG(info) << "DYNRES: now in use");
log::log(MSG(info) << "CS=" << chunk_size << ", MX=" << max_chunks);
log::log(DBG << "DYNRES: now in use");
log::log(DBG << "CS=" << chunk_size << ", MX=" << max_chunks);

// if the resource is new in use
if ((this->use_count++) == 0) {
Expand All @@ -50,14 +53,13 @@ void DynamicResource::use() {
);
}

// get loading job group
Engine &e = Engine::get();
this->loading_job_group = e.get_job_manager()->create_job_group();
// create loading job group
this->loading_job_group = this->manager->get_job_manager()->create_job_group();
}
}

void DynamicResource::stop_using() {
log::log(MSG(info) << "DYNRES: no longer in use");
log::log(DBG << "DYNRES: no longer in use");

// if the resource is not used anymore
if ((--this->use_count) == 0) {
Expand Down
55 changes: 34 additions & 21 deletions libopenage/audio/dynamic_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
namespace openage {
namespace audio {

/**
* information storage about a piece of raw audio data.
*/
struct chunk_info_t {
enum class state_t {
/** The chunk is currently unused. */
Expand All @@ -45,6 +48,11 @@ struct chunk_info_t {
~chunk_info_t() = default;
};


/**
* information about the loading position of
* an audio piece in the whole track.
*/
struct loading_info_t {
/** The chunk into which audio data should be loaded. */
std::shared_ptr<chunk_info_t> chunk_info;
Expand All @@ -56,7 +64,31 @@ struct loading_info_t {
size_t resource_chunk_offset;
};


/**
* Audio data that is loaded dynamically when used.
*/
class DynamicResource : public Resource {
public:
DynamicResource(AudioManager *manager,
category_t category, int id, const std::string &path,
format_t format=format_t::OPUS,
int preload_threshold=DEFAULT_PRELOAD_THRESHOLD,
size_t chunk_size=DEFAULT_CHUNK_SIZE,
size_t max_chunks=DEFAULT_MAX_CHUNKS);
virtual ~DynamicResource() = default;

void use() override;
void stop_using() override;

audio_chunk_t get_data(size_t position, size_t data_length) override;

private:
void start_preloading(size_t resource_chunk_index);

void start_loading(std::shared_ptr<chunk_info_t> chunk_info,
size_t resource_chunk_offset);

public:
/**
* The number of chunks that have to be loaded, before a sound actually
Expand Down Expand Up @@ -93,32 +125,13 @@ class DynamicResource : public Resource {
std::unique_ptr<DynamicLoader> loader;

/** Queue of audio chunks, that should be used next for loading audio data. */
openage::datastructure::ConcurrentQueue<std::shared_ptr<chunk_info_t>> chunk_infos;
datastructure::ConcurrentQueue<std::shared_ptr<chunk_info_t>> chunk_infos;

/** Resource chunk index to chunk mapping. */
std::unordered_map<size_t,std::shared_ptr<chunk_info_t>> chunk_mapping;

/** The background loading job group. */
openage::job::JobGroup loading_job_group;

public:
DynamicResource(category_t category, int id, const std::string &path,
format_t format=format_t::OPUS,
int preload_threshold=DEFAULT_PRELOAD_THRESHOLD,
size_t chunk_size=DEFAULT_CHUNK_SIZE,
size_t max_chunks=DEFAULT_MAX_CHUNKS);
virtual ~DynamicResource() = default;

void use() override;
void stop_using() override;

audio_chunk_t get_data(size_t position, size_t data_length) override;

private:
void start_preloading(size_t resource_chunk_index);

void start_loading(std::shared_ptr<chunk_info_t> chunk_info,
size_t resource_chunk_offset);
job::JobGroup loading_job_group;
};

}
Expand Down
Loading