Skip to content

Commit

Permalink
Refactoring for audio, input and resource core systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Avopeac committed Nov 28, 2017
1 parent 4f2e0f4 commit a635493
Show file tree
Hide file tree
Showing 31 changed files with 370 additions and 310 deletions.
Binary file modified project/.vs/project/v15/.suo
Binary file not shown.
6 changes: 2 additions & 4 deletions project/project.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<ClCompile Include="..\src\core.cpp" />
<ClCompile Include="..\src\entity_core_system.cpp" />
<ClCompile Include="..\src\entity_manager.cpp" />
<ClCompile Include="..\src\file.cpp" />
<ClCompile Include="..\src\text.cpp" />
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\font_renderer.cpp" />
<ClCompile Include="..\src\frame_buffer.cpp" />
Expand All @@ -146,7 +146,6 @@
<ClCompile Include="..\src\gui_tree.cpp" />
<ClCompile Include="..\src\gui_container.cpp" />
<ClCompile Include="..\src\input_core_system.cpp" />
<ClCompile Include="..\src\keymap.cpp" />
<ClCompile Include="..\src\main.cpp" />
<ClCompile Include="..\src\map_parser.cpp" />
<ClCompile Include="..\src\map_view.cpp" />
Expand Down Expand Up @@ -198,9 +197,8 @@
<ClInclude Include="..\src\disposable.h" />
<ClInclude Include="..\src\frame_buffer.h" />
<ClInclude Include="..\src\graphics.h" />
<ClInclude Include="..\src\keymap.h" />
<ClInclude Include="..\src\logger.h" />
<ClInclude Include="..\src\file.h" />
<ClInclude Include="..\src\text.h" />
<ClInclude Include="..\src\orthographic_camera.h" />
<ClInclude Include="..\src\post_effect.h" />
<ClInclude Include="..\src\post_processing.h" />
Expand Down
42 changes: 15 additions & 27 deletions project/project.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
<ClCompile Include="..\src\graphics.cpp">
<Filter>Source\Graphics</Filter>
</ClCompile>
<ClCompile Include="..\src\file.cpp">
<Filter>Source\Input</Filter>
</ClCompile>
<ClCompile Include="..\src\post_processing.cpp">
<Filter>Source\Graphics</Filter>
</ClCompile>
<ClCompile Include="..\src\renderer.cpp">
<Filter>Source\Graphics</Filter>
</ClCompile>
<ClCompile Include="..\src\keymap.cpp">
<Filter>Source\Input</Filter>
</ClCompile>
<ClCompile Include="..\src\entity_manager.cpp">
<Filter>Source\Entity</Filter>
</ClCompile>
Expand Down Expand Up @@ -107,29 +101,20 @@
<ClCompile Include="..\src\config.cpp">
<Filter>Source\Core.Util</Filter>
</ClCompile>
<ClCompile Include="..\src\text.cpp">
<Filter>Source\Core.Resource</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\graphics.h">
<Filter>Source\Graphics</Filter>
</ClInclude>
<ClInclude Include="..\src\logger.h">
<Filter>Source\Debug</Filter>
</ClInclude>
<ClInclude Include="..\src\disposable.h">
<Filter>Source\Base</Filter>
</ClInclude>
<ClInclude Include="..\src\file.h">
<Filter>Source\Input</Filter>
</ClInclude>
<ClInclude Include="..\src\post_processing.h">
<Filter>Source\Graphics</Filter>
</ClInclude>
<ClInclude Include="..\src\renderer.h">
<Filter>Source\Graphics</Filter>
</ClInclude>
<ClInclude Include="..\src\keymap.h">
<Filter>Source\Input</Filter>
</ClInclude>
<ClInclude Include="..\src\abstract_camera.h">
<Filter>Source\Graphics.Camera</Filter>
</ClInclude>
Expand Down Expand Up @@ -271,6 +256,15 @@
<ClInclude Include="..\src\config.h">
<Filter>Source\Core.Util</Filter>
</ClInclude>
<ClInclude Include="..\src\disposable.h">
<Filter>Source\Core</Filter>
</ClInclude>
<ClInclude Include="..\src\logger.h">
<Filter>Source\Core.Debug</Filter>
</ClInclude>
<ClInclude Include="..\src\text.h">
<Filter>Source\Core.Resource</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Source">
Expand All @@ -279,15 +273,6 @@
<Filter Include="Source\Graphics">
<UniqueIdentifier>{b02f3524-5cd6-4c4e-a37d-5e89feb964a8}</UniqueIdentifier>
</Filter>
<Filter Include="Source\Debug">
<UniqueIdentifier>{f8eb5e70-9dee-40d7-abb4-06a676a546b6}</UniqueIdentifier>
</Filter>
<Filter Include="Source\Base">
<UniqueIdentifier>{4d25895c-3069-4c3e-bf0a-ad2a52ff45d4}</UniqueIdentifier>
</Filter>
<Filter Include="Source\Input">
<UniqueIdentifier>{b385a5bc-9f10-4f1c-919b-04931e0fc178}</UniqueIdentifier>
</Filter>
<Filter Include="Source\Graphics.Camera">
<UniqueIdentifier>{9efc4032-0f25-43b0-ab35-812b272626f4}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -327,5 +312,8 @@
<Filter Include="Source\Core.System">
<UniqueIdentifier>{7c1a0a79-7c10-450f-bc4b-8c0e3405c7fb}</UniqueIdentifier>
</Filter>
<Filter Include="Source\Core.Debug">
<UniqueIdentifier>{933adc10-b439-460f-88c1-c6d8ff8d9b56}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AudioBase::AudioBase(const core::Config & config) :

std::string message = "Loaded audio device with name ";
message.append(device_name_);
debug::Log(SDL_LOG_PRIORITY_INFO, SDL_LOG_CATEGORY_AUDIO, message.c_str());
core::Log(SDL_LOG_PRIORITY_INFO, SDL_LOG_CATEGORY_AUDIO, message.c_str());


context_ = alcCreateContext(device_, nullptr);
Expand All @@ -24,7 +24,7 @@ AudioBase::AudioBase(const core::Config & config) :
{
std::string message = "Failed to load audio device with name";
message.append(device_name_);
debug::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_AUDIO, message.c_str());
core::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_AUDIO, message.c_str());
}

// Clear error messages
Expand Down
54 changes: 53 additions & 1 deletion src/audio_core_system.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "audio_core_system.h"

#include <string>

#include "logger.h"

using namespace core;

AudioCoreSystem::AudioCoreSystem()
AudioCoreSystem::AudioCoreSystem() :
position_(0), velocity_(0), forward_(0, 0, -1), up_(0, 1, 0)
{
}

Expand All @@ -12,8 +17,55 @@ AudioCoreSystem::~AudioCoreSystem()

void AudioCoreSystem::StartUp()
{
device_name_ = std::string(alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));

if (device_ = alcOpenDevice(device_name_.c_str()))
{

std::string message = "Loaded audio device with name ";
message.append(device_name_);
Log(SDL_LOG_PRIORITY_INFO, SDL_LOG_CATEGORY_AUDIO, message.c_str());


context_ = alcCreateContext(device_, nullptr);
alcMakeContextCurrent(context_);
}
else
{
std::string message = "Failed to load audio device with name";
message.append(device_name_);
Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_AUDIO, message.c_str());
}

// Clear error messages
alGetError();
}

void AudioCoreSystem::CleanUp()
{
alcMakeContextCurrent(nullptr);
alcDestroyContext(context_);
alcCloseDevice(device_);
}

void AudioCoreSystem::SetListenerPosition(const glm::vec3 & position)
{
alListener3f(AL_POSITION, position_.x, position_.y, position_.z);
}

void AudioCoreSystem::SetListenerVelocity(const glm::vec3 & velocity)
{
alListener3f(AL_VELOCITY, velocity_.x, velocity_.y, velocity_.z);
}

void AudioCoreSystem::SetListenerOrientation(const glm::vec3 & forward, const glm::vec3 &up)
{

forward_ = forward;

up_ = up;

float values[6]{ forward_.x, forward_.y, forward_.z, up_.x, up_.y, up_.z };

alListenerfv(AL_ORIENTATION, &values[0]);
}
28 changes: 28 additions & 0 deletions src/audio_core_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@

#include "abstract_core_system.h"

#include "AL/al.h"

#include "AL/alc.h"

#include "glm/glm.hpp"

namespace core {

class AudioCoreSystem : public AbstractCoreSystem
{

ALCdevice * device_ = nullptr;

ALCcontext * context_ = nullptr;

std::string device_name_;

glm::vec3 position_;

glm::vec3 velocity_;

glm::vec3 forward_;

glm::vec3 up_;

public:

AudioCoreSystem();
Expand All @@ -15,5 +36,12 @@ namespace core {
void StartUp() override;

void CleanUp() override;

void SetListenerPosition(const glm::vec3 &position);

void SetListenerVelocity(const glm::vec3 &velocity);

void SetListenerOrientation(const glm::vec3 &forward, const glm::vec3 &up);

};
}
2 changes: 1 addition & 1 deletion src/blend_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ Blend * BlendCache::GetFromHash(size_t hash)
return &blends_[hash];
}

debug::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_RENDER, "Blend state is null.");
Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_RENDER, "Blend state is null.");
return nullptr;
}
15 changes: 7 additions & 8 deletions src/controller_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "entity_manager.h"
#include "core.h"
#include "data_pipe_hub.h"
#include "keymap.h"
#include "timing.h"

using namespace entity;
Expand All @@ -30,15 +29,15 @@ void ControllerSystem::Update(Entity * entity, float delta_time)

if (controller_component)
{
auto &keymap = input::Keymap::Get();
auto * input = core::Core::GetInputSystem();

glm::vec2 velocity(0.0f);
float rotation = 0.0f;

if (keymap.KeyPressed(input::Key::KeyA)) { velocity.x -= 1.0f; }
if (keymap.KeyPressed(input::Key::KeyD)) { velocity.x += 1.0f; }
if (keymap.KeyPressed(input::Key::KeyW)) { velocity.y += 1.0f; }
if (keymap.KeyPressed(input::Key::KeyS)) { velocity.y -= 1.0f; }
if (input->KeyPressed(core::Key::KeyA)) { velocity.x -= 1.0f; }
if (input->KeyPressed(core::Key::KeyD)) { velocity.x += 1.0f; }
if (input->KeyPressed(core::Key::KeyW)) { velocity.y += 1.0f; }
if (input->KeyPressed(core::Key::KeyS)) { velocity.y -= 1.0f; }

float length = glm::length(velocity);
if (length > 0.0f)
Expand All @@ -50,8 +49,8 @@ void ControllerSystem::Update(Entity * entity, float delta_time)
controller_component->SetVelocity(glm::vec2(0.0f));
}

if (keymap.KeyPressed(input::Key::KeyQ)) { rotation -= 1.0f; }
if (keymap.KeyPressed(input::Key::KeyE)) { rotation += 1.0f; }
if (input->KeyPressed(core::Key::KeyQ)) { rotation -= 1.0f; }
if (input->KeyPressed(core::Key::KeyE)) { rotation += 1.0f; }

controller_component->SetRotation(rotation);

Expand Down
30 changes: 0 additions & 30 deletions src/file.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions src/file.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Font::Create(const std::string &path, uint32_t pt_size)

if (!font_)
{
debug::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_INPUT,
core::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_INPUT,
"Could not load the requested font.");
}

Expand All @@ -41,7 +41,7 @@ void Font::Create(const std::string &path, uint32_t pt_size)
SDL_Surface * surface = TTF_RenderGlyph_Shaded(font_, CHAR_MAP[i], fg_color, bg_color);
if (!surface)
{
debug::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_INPUT,
core::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_INPUT,
"Could not load the requested glyph from font.");
continue;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ FontCache::FontCache()
{
if (TTF_Init() < 0)
{
debug::Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_RENDER,
Log(SDL_LOG_PRIORITY_CRITICAL, SDL_LOG_CATEGORY_RENDER,
"Could not initialize SDL TTF library.");
}
}
Expand Down
Loading

0 comments on commit a635493

Please sign in to comment.