Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
Alairion committed Oct 28, 2021
1 parent d270e31 commit 258bbb4
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 96 deletions.
2 changes: 1 addition & 1 deletion apyre/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace apr::enum_operations;
int main()
{
//Initialize Apyre.
apr::application application{apr::application_extension::extended_client_area};
apr::application application{};

//Create a window.
//The parameters are pretty simple, the app, the window's title, it's size (width then height), and some additionnal options.
Expand Down
6 changes: 5 additions & 1 deletion captal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ set(CAPTAL_SOURCES
src/captal/components/attachment.hpp
src/captal/components/drawable.hpp
src/captal/components/camera.hpp
src/captal/components/audio_emiter.hpp
src/captal/components/audio_emitter.hpp

src/captal/systems/frame.hpp
src/captal/systems/sorting.hpp
Expand Down Expand Up @@ -166,6 +166,10 @@ if(CAPTAL_BUILD_CAPTAL_EXAMPLES)
target_link_libraries(captal_example PRIVATE captal captal_sansation)
target_include_directories(captal_example PRIVATE ${GLOBAL_INCLUDES})

add_executable(captal_example_easy example_easy.cpp)
target_link_libraries(captal_example_easy PRIVATE captal captal_sansation)
target_include_directories(captal_example_easy PRIVATE ${GLOBAL_INCLUDES})

add_executable(captal_text text.cpp)
target_link_libraries(captal_text PRIVATE captal captal_sansation)
target_include_directories(captal_text PRIVATE ${GLOBAL_INCLUDES})
Expand Down
74 changes: 74 additions & 0 deletions captal/example_easy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <captal/engine.hpp>
#include <captal/view.hpp>
#include <captal/renderable.hpp>

int main()
{
//Initialize the engine
cpt::engine engine{"captal_test", cpt::version{0, 1, 0}};

//Create the window
cpt::window_ptr window{cpt::make_window("Example", 640, 480)};

//Create the render window that targets our window.
//The default video mode is basically double buffering + VSync.
cpt::render_window_ptr target{cpt::make_render_window(window, cpt::video_mode{})};

//Create a view on our render window.
//It will use the default engine render layout,
//and it will create the default render technique that uses the default engine's shaders
//It is basically all defaults :)
cpt::view view{target};

//"fit" is an helper functions that set the view size, viewport and scissor
//to the dimension of the window or texture.
view.fit(window);

//A 40x40px sprite, could have been any renderable
cpt::sprite sprite{40, 40, cpt::colors::dodgerblue};
//Center the sprite
sprite.move_to(cpt::vec3f{300.0f, 220.0f, 0.0f});

//We need to ensure that our object are up to date on the GPU
cpt::memory_transfer_info transfer_info{cpt::engine::instance().begin_transfer()};

//cpt::view and cpt::basic_renderable have an helper function "upload"
//that record everything that is needed for you.
view.upload(transfer_info);
sprite.upload(transfer_info);

//Perform the transfer for real.
cpt::engine::instance().submit_transfers();

//We need to close the window manually, the close event just tell us that
//the user want to close it, not that the window has been actually closed.
window->on_close().connect([](cpt::window& window, const apr::window_event&)
{
window.close();
});

//The main loop, once the window will be closed a quit event will be generated
//so the engine will return false
while(cpt::engine::instance().run())
{
//Tell the window to poll all events and send them through signals
window->dispatch_events();

//Here we do our rendering, since we never change anything in our scene,
//we never use `cpt::begin_render_options::reset`
auto render_info{target->begin_render(cpt::begin_render_options::none)};
if(render_info)
{
//Bind the view, only one view can be bound at a time for each render target.
view.bind(*render_info);

//Bind and draw the sprite, the view must be specified again because
//the renderable needs
sprite.draw(*render_info, view);
}

//Actually send the work to the GPU
//Since it is a window, it also actually present the next swapchain image to the screen.
target->present();
}
}
8 changes: 4 additions & 4 deletions captal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <captal/components/node.hpp>
#include <captal/components/camera.hpp>
#include <captal/components/drawable.hpp>
#include <captal/components/audio_emiter.hpp>
#include <captal/components/audio_emitter.hpp>
#include <captal/components/listener.hpp>
#include <captal/components/rigid_body.hpp>
#include <captal/components/controller.hpp>
Expand Down Expand Up @@ -98,7 +98,7 @@ static entt::entity add_player(entt::registry& world, cpt::physical_world& physi
world.emplace<cpt::components::node>(player, cpt::vec3f{320.0f, 240.0f, 0.5f});

//The player will emit sounds when a wall is hit
world.emplace<cpt::components::audio_emiter>(player, std::make_unique<sinewave_generator>(44100, 2, 100.0f))->set_volume(0.5f);
world.emplace<cpt::components::audio_emitter>(player, std::make_unique<sinewave_generator>(44100, 2, 100.0f))->set_volume(0.5f);

//The player sprite, we use an ellipse. Why ? Because why not !
const auto points{cpt::ellipse(48.0f, 32.0f)};
Expand Down Expand Up @@ -274,7 +274,7 @@ static void add_logic(cpt::render_window_ptr target, entt::registry& world, cpt:
//Start the sawtooth when we first collide.
if(*current_collisions == 1)
{
world.get<cpt::components::audio_emiter>(player)->start();
world.get<cpt::components::audio_emitter>(player)->start();
}

return true;
Expand All @@ -287,7 +287,7 @@ static void add_logic(cpt::render_window_ptr target, entt::registry& world, cpt:
//Stop the sawtooth when we no longer collide with any wall.
if(*current_collisions == 0)
{
world.get<cpt::components::audio_emiter>(player)->stop();
world.get<cpt::components::audio_emitter>(player)->stop();
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

#ifndef CAPTAL_COMPONENTS_AUDIO_EMITER_HPP_INCLUDED
#define CAPTAL_COMPONENTS_AUDIO_EMITER_HPP_INCLUDED
#ifndef CAPTAL_COMPONENTS_AUDIO_EMITTER_HPP_INCLUDED
#define CAPTAL_COMPONENTS_AUDIO_EMITTER_HPP_INCLUDED

#include "../config.hpp"

Expand All @@ -32,23 +32,23 @@
namespace cpt::components
{

class audio_emiter
class audio_emitter
{
public:
audio_emiter() = default;
audio_emitter() = default;

template<typename... Args>
explicit audio_emiter(Args&&... args) noexcept(std::is_nothrow_constructible_v<sound, Args...>)
explicit audio_emitter(Args&&... args) noexcept(std::is_nothrow_constructible_v<sound, Args...>)
:m_attachment{std::in_place, std::forward<Args>(args)...}
{

}

~audio_emiter() = default;
audio_emiter(const audio_emiter&) = delete;
audio_emiter& operator=(const audio_emiter&) = delete;
audio_emiter(audio_emiter&&) noexcept = default;
audio_emiter& operator=(audio_emiter&&) noexcept = default;
~audio_emitter() = default;
audio_emitter(const audio_emitter&) = delete;
audio_emitter& operator=(const audio_emitter&) = delete;
audio_emitter(audio_emitter&&) noexcept = default;
audio_emitter& operator=(audio_emitter&&) noexcept = default;

template<typename... Args>
sound& attach(Args&&... args) noexcept(std::is_nothrow_constructible_v<sound, Args...>)
Expand Down Expand Up @@ -76,7 +76,7 @@ class audio_emiter
return m_attachment.has_value();
}

void swap(audio_emiter& other) noexcept
void swap(audio_emitter& other) noexcept
{
m_attachment.swap(other.m_attachment);
}
Expand Down
2 changes: 0 additions & 2 deletions captal/src/captal/render_technique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ render_layout::render_layout(const render_layout_info& view_info, const render_l

descriptor_set_ptr render_layout::make_set(std::uint32_t layout_index)
{
assert(layout_index < 2 && "cpt::render_layout does not support custom descriptor set layouts yet.");

std::lock_guard lock{m_mutex};

auto& data{m_layout_data[layout_index]};
Expand Down
28 changes: 14 additions & 14 deletions captal/src/captal/sound.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
#include "sound.hpp"

#include "engine.hpp"

#include <swell/sound_file.hpp>

namespace cpt
{

sound::sound(const std::filesystem::path& file, swl::sound_reader_options options)
:sound{swl::open_file(file, options)}
{

}//MIT License
//MIT License
//
//Copyright (c) 2021 Alexy Pellegrini
//
Expand All @@ -33,7 +20,20 @@ sound::sound(const std::filesystem::path& file, swl::sound_reader_options option
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

#include "sound.hpp"

#include "engine.hpp"

#include <swell/sound_file.hpp>

namespace cpt
{

sound::sound(const std::filesystem::path& file, swl::sound_reader_options options)
:sound{swl::open_file(file, options)}
{

}

sound::sound(std::span<const std::uint8_t> data, swl::sound_reader_options options)
:sound{swl::open_file(data, options)}
Expand Down
10 changes: 5 additions & 5 deletions captal/src/captal/systems/audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include "../components/node.hpp"
#include "../components/listener.hpp"
#include "../components/audio_emiter.hpp"
#include "../components/audio_emitter.hpp"

namespace cpt::systems
{
Expand All @@ -46,16 +46,16 @@ inline void audio(entt::registry& world)
}
};

const auto update_emiters = [](components::audio_emiter& emiter, const components::node& node)
const auto update_emitters = [](components::audio_emitter& emitter, const components::node& node)
{
if(node.is_updated() && emiter.has_attachment())
if(node.is_updated() && emitter.has_attachment())
{
emiter->move_to(node.position());
emitter->move_to(node.position());
}
};

world.view<components::listener, const components::node>().each(update_listener);
world.view<components::audio_emiter, const components::node>().each(update_emiters);
world.view<components::audio_emitter, const components::node>().each(update_emitters);
}

}
Expand Down
2 changes: 1 addition & 1 deletion captal/src/captal/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ const text_drawer::glyph_info& text_drawer::load(cpt::font& font, std::uint64_t
//Load the fallback in case the requested codepoint does not have a glyph inside the font
if(codepoint != m_fallback)
{
return load(font, make_key(m_fallback, font.info().size, outline, adjust, bold, italic));
return load(font, make_key(m_fallback, font.info().size, outline, adjust, bold, italic), deferred);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions captal/src/captal/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ class CAPTAL_API text_drawer
m_options = options;
}

void set_adjustement(subpixel_adjustment adjustment) noexcept
void set_adjustment(subpixel_adjustment adjustment) noexcept
{
m_adjustment = adjustment;
}

void set_line_adjustement(subpixel_adjustment adjustment) noexcept
void set_line_adjustment(subpixel_adjustment adjustment) noexcept
{
m_line_adjustment = adjustment;
}
Expand Down
44 changes: 22 additions & 22 deletions captal/src/captal/translation.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
//MIT License
//
//Copyright (c) 2021 Alexy Pellegrini
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

#ifndef CAPTAL_TRANSLATION_HPP_INCLUDED
#define CAPTAL_TRANSLATION_HPP_INCLUDED

Expand Down Expand Up @@ -776,28 +798,6 @@ class CAPTAL_API translation_editor
return std::hash<std::string_view>{}(std::string_view{reinterpret_cast<const char*>(std::data(value)), std::size(value)});
}
};
//MIT License
//
//Copyright (c) 2021 Alexy Pellegrini
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.


public:
using translation_set_type = std::unordered_map<std::string, std::string>;
Expand Down
7 changes: 7 additions & 0 deletions captal/src/captal/uniform_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
namespace cpt
{

uniform_buffer::uniform_buffer(const buffer_part& part)
:m_parts{buffer_part_info{0, part.size}}
,m_buffer{engine::instance().uniform_pool().allocate(part.size, engine::instance().graphics_device().limits().min_uniform_buffer_alignment)}
{

}

uniform_buffer::uniform_buffer(std::span<const buffer_part> parts)
:m_parts{compute_part_info(parts)}
,m_buffer{engine::instance().uniform_pool().allocate(m_parts.back().offset + m_parts.back().size, engine::instance().graphics_device().limits().min_uniform_buffer_alignment)}
Expand Down
1 change: 1 addition & 0 deletions captal/src/captal/uniform_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CAPTAL_API uniform_buffer final : public asynchronous_resource

public:
uniform_buffer() = default;
explicit uniform_buffer(const buffer_part& part);
explicit uniform_buffer(std::span<const buffer_part> parts);

~uniform_buffer() = default;
Expand Down
11 changes: 6 additions & 5 deletions swell/src/swell/sound_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ static constexpr std::array<std::uint8_t, 4> flac_header{0x66, 0x4c, 0x61, 0x43}

audio_file_format file_format(std::span<const std::uint8_t> data) noexcept
{
if(std::size(data) < 4)
{
return audio_file_format::unknown;
}

const auto header_data{data.subspan(0, 4)};

if(std::equal(std::begin(header_data), std::end(header_data), std::begin(wave_header), std::end(wave_header)))
Expand All @@ -61,11 +66,7 @@ audio_file_format file_format(std::istream& stream)
if(!stream.read(reinterpret_cast<char*>(std::data(header_data)), std::size(header_data)))
throw std::runtime_error{"Can not detect audio file format from stream."};

stream.seekg(0, std::ios_base::beg);
const auto output{file_format(header_data)};
stream.seekg(0, std::ios_base::beg);

return output;
return file_format(header_data);
}

audio_file_format file_format(const std::filesystem::path& file)
Expand Down
Loading

0 comments on commit 258bbb4

Please sign in to comment.