Skip to content

Commit

Permalink
Merge pull request #80 from fallahn/golf-1.13
Browse files Browse the repository at this point in the history
Golf 1.13
  • Loading branch information
fallahn authored Aug 5, 2023
2 parents 9bf497f + 3ceac52 commit dcb801a
Show file tree
Hide file tree
Showing 287 changed files with 40,399 additions and 7,636 deletions.
2 changes: 1 addition & 1 deletion crogine/include/crogine/audio/AudioBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace cro
/*!
\brief Attempts to load a file from the given path.
Currently supported formats are PCM wav files (mono or stereo)
or *.ogg vorbis files (mono or stereo).
or *.ogg vorbis files (mono or stereo) or *.mp3 files (mono or stereo)
\returns true on success, else false
*/
bool loadFromFile(const std::string&) override;
Expand Down
6 changes: 6 additions & 0 deletions crogine/include/crogine/audio/AudioMixer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ namespace cro
*/
static bool hasAudioRenderer();

/*!
\brief Prints the debug output of the active audio renderer, if it has
been implemented. Call this between the begin/end of your own ImGui window
*/
static void printDebug();


static constexpr std::size_t MaxChannels = 16;

Expand Down
4 changes: 2 additions & 2 deletions crogine/include/crogine/audio/AudioStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace cro
\brief An AudioSource which streams data from storage.
When playing longer audio files such as music it is recommended
that an AudioEmitter component use an AudioStream as its data
source rather than a buffer. Streams will stream either *.wav
source rather than a buffer. Streams will stream either *.wav, *mp3
or *.ogg data from disk, as opposed to attempting to load the
entire file into memory.
As with AudioBuffers, AudioStreams must live at least as long as
Expand All @@ -59,7 +59,7 @@ namespace cro
AudioStream& operator = (AudioStream&&) noexcept;

/*!
\brief Attempts to open the *.ogg or *.wav file from the given path.
\brief Attempts to open the *.ogg, *.mp3 or *.wav file from the given path.
\returns true on success else false.
*/
bool loadFromFile(const std::string& path) override;
Expand Down
77 changes: 77 additions & 0 deletions crogine/include/crogine/audio/sound_system/MusicPlayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*-----------------------------------------------------------------------
Matt Marchant 2023
http://trederia.blogspot.com
crogine application - Zlib license.
This software is provided 'as-is', without any express or
implied warranty.In no event will the authors be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions :
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but
is not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any
source distribution.
-----------------------------------------------------------------------*/

#pragma once

#include <crogine/audio/sound_system/SoundStream.hpp>

#include <memory>

namespace cro
{
namespace Detail
{
class AudioFile;
}

/*!
\brief Streaming music player.
Supports playing audio from mono or stereo *ogg, *.mp3 and wav files.
Requires the OpenAL AudioRenderer to be available.
*/
class CRO_EXPORT_API MusicPlayer final : public SoundStream
{
public:
MusicPlayer();
~MusicPlayer();

MusicPlayer(const MusicPlayer&) = delete;
MusicPlayer(MusicPlayer&&) = delete;
const MusicPlayer& operator = (const MusicPlayer&) = delete;
MusicPlayer& operator = (MusicPlayer&&) = delete;

/*!
\brief Attempts to load the file at the given path.
Supported types are *.wav, *.mp3 and *.ogg
\param path A string containing the path to the file to open
\returns true on success, else false.
*/
bool loadFromFile(const std::string& path);

Time getDuration() const;

private:
std::unique_ptr<Detail::AudioFile> m_audioFile;
std::int32_t m_bytesPerSample;

bool onGetData(cro::SoundStream::Chunk&) override;
void onSeek(std::int32_t) override;

};
}
44 changes: 41 additions & 3 deletions crogine/include/crogine/audio/sound_system/SoundStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source distribution.
#pragma once

#include <crogine/audio/sound_system/SoundSource.hpp>
#include <crogine/core/Clock.hpp>

#include <array>
#include <thread>
Expand All @@ -56,9 +57,9 @@ namespace cro
};

SoundStream(const SoundStream&) = delete;
SoundStream(SoundStream&&) = delete;
SoundStream(SoundStream&&) noexcept = delete;
SoundStream& operator = (const SoundStream&) = delete;
SoundStream& operator = (SoundStream&&) = delete;
SoundStream& operator = (SoundStream&&) noexcept = delete;

virtual ~SoundStream() noexcept;

Expand Down Expand Up @@ -95,6 +96,34 @@ namespace cro
*/
std::uint32_t getSampleRate() const;

/*!
\brief Returns the total number of samples in the stream
This may be zero if the total length is unknown
*/
std::uint64_t getSampleCount() const { return m_sampleCount; }

/*!
\brief Sets the stream to loop to the beginning once it has played
or to stop.
*/
void setLooped(bool loop) { m_loop = loop; }

/*!
\brief Returns whether or not this stream is set to loop when playback
reaches the end
*/
bool isLooped() const { return m_loop; }

/*!
\brief Sets the playing position based on the given time offset
*/
void setPlayingPosition(Time);

/*!
\brief Returns the current time offset
*/
Time getPlayingPosition() const;

protected:

static constexpr std::int32_t NoLoop = -1;
Expand All @@ -113,8 +142,9 @@ namespace cro
\param channelCount - The number of audio channels in the stream
\param sampleRate - The stream sample rate.
\param sampleCountn - Total number of samples, if known (can be 0)
*/
void initialise(std::uint32_t channelCount, std::uint32_t sampleRate);
void initialise(std::uint32_t channelCount, std::uint32_t sampleRate, std::uint64_t sampleCount);


/*!
Expand Down Expand Up @@ -148,6 +178,13 @@ namespace cro
void setProcessingInterval(std::int32_t interval);


/*!
\brief Returns the current processing interval in milliseconds
This can be used to calculate the chunk size required from the
source buffers when onGetData() is called
*/
std::int32_t getProcessingInterval() const { return m_processingInterval; }

/*!
\brief Returns loop position if looped or -1 if no loop
*/
Expand All @@ -165,6 +202,7 @@ namespace cro
std::array<std::uint32_t, BufferCount> m_buffers = {};
std::uint32_t m_channelCount;
std::uint32_t m_sampleRate;
std::uint64_t m_sampleCount;
std::int32_t m_format;
bool m_loop;
std::uint64_t m_samplesProcessed;
Expand Down
5 changes: 3 additions & 2 deletions crogine/include/crogine/core/GameController.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2022
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -105,7 +105,8 @@ namespace cro
DPadUp = SDL_CONTROLLER_BUTTON_DPAD_UP,
DPadDown = SDL_CONTROLLER_BUTTON_DPAD_DOWN,
DPadLeft = SDL_CONTROLLER_BUTTON_DPAD_LEFT,
DPadRight = SDL_CONTROLLER_BUTTON_DPAD_RIGHT
DPadRight = SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
ButtonTrackpad = SDL_CONTROLLER_BUTTON_TOUCHPAD
};

static constexpr std::int16_t AxisMax = 32767;
Expand Down
2 changes: 1 addition & 1 deletion crogine/include/crogine/ecs/components/Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace cro

/*!
\brief Returns the normalised texture rect based on the current
texture, or and empty rectangle if not texture exists
texture, or and empty rectangle if no texture exists
*/
FloatRect getTextureRectNormalised() const;

Expand Down
40 changes: 39 additions & 1 deletion crogine/include/crogine/ecs/components/UIInput.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2022
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -100,12 +100,50 @@ namespace cro
*/
std::size_t getSelectionIndex() const { return m_selectionIndex; }

/*!
\brief Override the default selection index of the next UIInput to be selected
\param next The next index to select when pressing right
\param down The next index to select when pressing down
*/
void setNextIndex(std::size_t next, std::size_t down = std::numeric_limits<std::size_t>::max())
{
m_neighbourIndices[1] = next;
m_neighbourIndices[3] = down;
}

/*!
\brief Override the default selection index of the next UIInput to be selected
\param prev The next index to select when pressing left
\param up The next index to select when pressing up
*/
void setPrevIndex(std::size_t prev, std::size_t up = std::numeric_limits<std::size_t>::max())
{
m_neighbourIndices[0] = prev;
m_neighbourIndices[2] = up;
}

private:
std::size_t m_previousGroup = 0;
std::size_t m_group = 0;
std::size_t m_selectionIndex = 0;
bool m_updateGroup = true; //do order sorting by default

struct Index final
{
enum
{
Left, Right, Up, Down,
Count
};
};
std::array<std::size_t, Index::Count> m_neighbourIndices =
{
std::numeric_limits<std::size_t>::max() ,
std::numeric_limits<std::size_t>::max() ,
std::numeric_limits<std::size_t>::max() ,
std::numeric_limits<std::size_t>::max()
};

cro::FloatRect m_worldArea; //cached by transform callback, ie dirty flag optimised

friend class UISystem;
Expand Down
3 changes: 1 addition & 2 deletions crogine/include/crogine/ecs/systems/AudioPlayerSystem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2021
Matt Marchant 2021 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -54,6 +54,5 @@ namespace cro

private:

void onEntityAdded(Entity) override;
};
}
4 changes: 1 addition & 3 deletions crogine/include/crogine/ecs/systems/RenderSystem2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ namespace cro
Shader m_texturedShader;

DepthAxis m_sortOrder;
bool m_needsSort;
std::vector<std::vector<Entity>> m_drawLists;

Detail::QuadTree m_quadTree;
std::vector<Entity> m_dirtyEnts; //transform callback marks these as needing to be moved in the quad tree

void applyBlendMode(Material::BlendMode);
glm::ivec2 mapCoordsToPixel(glm::vec2, const glm::mat4& viewProjMat, IntRect) const;

Expand Down
18 changes: 15 additions & 3 deletions crogine/include/crogine/ecs/systems/UISystem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2022
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -30,6 +30,7 @@ source distribution.
#pragma once

#include <crogine/ecs/System.hpp>
#include <crogine/ecs/components/UIInput.hpp>
#include <crogine/graphics/Rectangle.hpp>

#include <crogine/detail/glm/mat4x4.hpp>
Expand Down Expand Up @@ -172,6 +173,9 @@ namespace cro
that has a different number of columns, this function should be used to
set the new active value.
Note that this is ignored for any UIInput components which has a specific
previous or next index set on them.
\param count The number of columns in the display (or number of indices to
skip when moving up/down). Must be greater than zero.
*/
Expand Down Expand Up @@ -207,9 +211,17 @@ namespace cro
\param index The index of the input to select
Note that this may not give expected results if multiple inputs
have been manually assigned the same selection index with setSelectionIndex()
or the index is not in range of the group size - in which case prefer
selectByIndex()
*/
void selectAt(std::size_t index);

/*!
\brief Selects at a specific index if a UIInput component has been provided
with one via setSelectionIndex() - otherwise prefer selectAt()
*/
void selectByIndex(std::size_t index);

private:

std::vector<ButtonCallback> m_buttonCallbacks;
Expand Down Expand Up @@ -244,8 +256,8 @@ namespace cro
bool m_scrollNavigation;
std::size_t m_columnCount;
std::size_t m_selectedIndex;
void selectNext(std::size_t);
void selectPrev(std::size_t);
void selectNext(std::size_t, std::int32_t = UIInput::Index::Right);
void selectPrev(std::size_t, std::int32_t = UIInput::Index::Left);

void unselect(std::size_t);
void select(std::size_t);
Expand Down
Loading

0 comments on commit dcb801a

Please sign in to comment.