Skip to content

Commit

Permalink
Merge pull request #1 from WillisMedwell/removing-two-phase-initializ…
Browse files Browse the repository at this point in the history
…ation

Removing two phase initialization
  • Loading branch information
WillisMedwell authored Mar 13, 2024
2 parents 801bd5b + 4e061b3 commit e9aafaa
Show file tree
Hide file tree
Showing 35 changed files with 873 additions and 1,092 deletions.
8 changes: 6 additions & 2 deletions code/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ CheckOptions:
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.MemberVariableCase, value: snake_case }
- { key: readability-identifier-naming.ConstantMemberCase, value: snake_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.MethodCase, value: lower_case }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: _ }
- { key: readability-identifier-naming.StaticMemberPrefix, value: _ }
- { key: readability-identifier-naming.ConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.LocalConstantCase, value: lower_case }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.GlobalConstantCase, value: snake_case }
- { key: readability-identifier-naming.ConstexprVariableCase, value: snake_case }
- { key: readability-identifier-naming.ConstexprMethodCase, value: snake_case }
- { key: readability-identifier-naming.ConstexprFunctionCase, value: snake_case }
- { key: readability-identifier-naming.EnumConstantCase, value: lower_case }


93 changes: 71 additions & 22 deletions code/Demos/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,56 @@ struct IsoData {

Renderer::ResourceManager resource_manager;
Renderer::InstanceRenderer instance_renderer;

std::optional<Renderer::FontBatchRenderer> font_batch_renderer;

Cameras::StationaryPerspective camera { glm::vec3(0, 1, -1), glm::normalize(glm::vec3(0, -0.25f, 0.5f)) };
};
struct IsoLogic {
void init(AppRenderer& renderer, Core::AudioManager& audio, IsoData& data) {

Media::Sound sound {};
Media::Sound sound = Media::Sound::create("assets/background_sound.wav").on_error_panic().value_move();

auto scheduler = std::move(Core::Scheduler::create(2).value());

scheduler.add_task([]() {
Media::FontAtlas::create("assets/RobotoMono.ttf", 500).on_error_panic().value().atlas_image().save_to_disk("RobotoMonoAtlas.png");
});

std::mutex sound_mutex;
std::optional<Media::Sound> sound_2;
scheduler.add_task([&]() {
auto create_sound_result = Media::Sound::create("assets/background_sound.wav");

sound_mutex.lock();
sound_2.emplace(create_sound_result.on_error_panic().value_move());
sound_mutex.unlock();
});



std::mutex model_mutex;
std::optional<Model::Static> model_data_2;
scheduler.add_task([&]() {
auto model_data = Utily::FileReader::load_entire_file("assets/teapot.obj").on_error_panic().value_move();
auto model_decode_result = Model::decode_as_static_model(model_data, ".obj");

model_mutex.lock();
model_data_2.emplace(model_decode_result.on_error_panic().value_move());
model_mutex.unlock();
});

std::mutex image_mutex;
std::optional<Media::Image> image_2;
scheduler.add_task([&]() {
auto image_result = Media::Image::create("assets/texture.png");

auto wav_file_data = Utily::FileReader::load_entire_file("assets/background_sound.wav");
wav_file_data.on_error(print_then_quit);
sound.init_from_wav(wav_file_data.value()).on_error(print_then_quit);
image_mutex.lock();
image_2.emplace(image_result.on_error_panic().value_move());
image_mutex.unlock();
});

scheduler.launch_threads();

auto res = audio.load_sound_into_buffer(sound).on_error(print_then_quit);

Expand All @@ -428,27 +469,20 @@ struct IsoLogic {
data.spinning.angle = 0;
data.spinning.rotations_per_second = 1;

data.source_handle = audio.play_sound(data.sound_buffer).on_error(print_then_quit).value();
data.start_time = std::chrono::high_resolution_clock::now();
auto model_data = Utily::FileReader::load_entire_file("assets/teapot.obj").on_error_panic().value_move();
auto model = Model::decode_as_static_model(model_data, ".obj").on_error_panic().value_move();
auto image = Media::Image::create("assets/texture.png").on_error_panic().value_move();

auto model_data = std::move(
Utily::FileReader::load_entire_file("assets/teapot.obj")
.on_error(print_then_quit)
.value());
auto model = std::move(
Model::decode_as_static_model(model_data, ".obj")
.on_error(print_then_quit)
.value());

auto image_png = std::move(
Utily::FileReader::load_entire_file("assets/texture.png")
.on_error(print_then_quit)
.value());
auto image = Media::Image {};
image.init(image_png, true, false)
.on_error(print_then_quit);
data.font_batch_renderer.emplace(Renderer::FontBatchRenderer::create(data.resource_manager, "assets/RobotoMono.ttf")
.on_error_panic()
.value_move());

data.instance_renderer.init(data.resource_manager, model, image);
data.source_handle = audio.play_sound(data.sound_buffer, { 5, 0, 0 }).on_error(print_then_quit).value();

scheduler.wait_for_threads();

data.start_time = std::chrono::high_resolution_clock::now();
}

void update(float dt, const Core::InputManager& input, Core::AudioManager& audio, AppState& state, IsoData& data) {
Expand All @@ -470,12 +504,27 @@ struct IsoLogic {
lp.dir = { 0, 0, 1 };
lp.vel = { 0, 0, 0 };
audio.set_listener_properties(lp);

auto t = Components::Transform {};
t.position = glm::vec3(0, -1, 1);
t.scale = glm::vec3(0.5f);

auto model = t.calc_transform_mat();
data.instance_renderer.push_instance(model);

t.position = glm::vec3(0, -1, 2);
model = t.calc_transform_mat();
data.instance_renderer.push_instance(model);
}

void draw(AppRenderer& renderer, IsoData& data) {
renderer.screen_frame_buffer.bind();
renderer.screen_frame_buffer.clear(data.background_colour);
renderer.screen_frame_buffer.resize(renderer.window_width, renderer.window_height);

auto v = data.camera.view_matrix();
auto p = data.camera.projection_matrix(renderer.window_width, renderer.window_height);
data.instance_renderer.draw_instances(data.resource_manager, v, p);
}
void stop(IsoData& data) {
}
Expand Down
4 changes: 3 additions & 1 deletion code/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ if(DEFINED EMSCRIPTEN)
"$<$<CONFIG:Debug>:-O2;-g3;-sDEMANGLE_SUPPORT=1;-sFORCE_FILESYSTEM=1;-sASSERTIONS=1;-sSAFE_HEAP=1;-sSTACK_OVERFLOW_CHECK=2;-sNO_DISABLE_EXCEPTION_CATCHING;-Wno-unused-command-line-argument;-fno-inline-functions;-sEXIT_RUNTIME=1>"
"$<$<CONFIG:Release>:-Oz;-sGL_FFP_ONLY;-msimd128;-mrelaxed-simd;-msse;-msse2;-msse3;-msse4.1;-Wno-unused-command-line-argument;-sFORCE_FILESYSTEM=1>"
)
target_link_options(Engine PUBLIC -sUSE_WEBGL2=1 -sUSE_GLFW=3 -sFULL_ES3=1 -sFULL_ES2=1 -Wno-unused-command-line-argument -sALLOW_MEMORY_GROWTH)
#target_compile_options(Engine PUBLIC -sUSE_PTHREADS=1)
target_link_options(Engine PUBLIC -sUSE_WEBGL2=1 -sUSE_GLFW=3 -sFULL_ES3=1 -sFULL_ES2=1 -Wno-unused-command-line-argument -sALLOW_MEMORY_GROWTH) #-sUSE_PTHREADS=1)

else()
find_package(OpenGL REQUIRED)
find_package(OpenAL CONFIG REQUIRED)
Expand Down
3 changes: 0 additions & 3 deletions code/Engine/include/App/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class App
}
auto stop() -> void {
if (!_has_stopped) {
Profiler::Timer timer("App::stop()", { "App" });
_logic.stop(_data);
_renderer.stop();
_audio.stop();
Expand Down Expand Up @@ -113,15 +112,13 @@ class App
}
_context.swap_buffers();
}

auto poll_events() -> void {
Profiler::Timer timer("App::poll_events()", { "App" });
this->_context.poll_events();
}
auto is_running() -> bool {
return _has_init && !_context.should_close() && !_state.should_close;
}

~App() {
stop();
}
Expand Down
3 changes: 3 additions & 0 deletions code/Engine/include/Core/AudioManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace Core {
};
struct Source {
uint32_t id = std::numeric_limits<uint32_t>::max();
glm::vec3 pos = { 0, 0, 0 };
glm::vec3 vel = { 0, 0, 0 };
std::optional<BufferHandle> attached_buffer = std::nullopt;
std::optional<std::chrono::steady_clock::time_point> expected_finish = std::nullopt;
};
Expand All @@ -75,4 +77,5 @@ namespace Core {
void stop_buffers();
void stop_sources();
};

}
6 changes: 3 additions & 3 deletions code/Engine/include/Core/Core.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

namespace Core {
class Fence;
class IndexBuffer;
class InputManager;
class OpenglContext;
Expand All @@ -12,9 +11,9 @@ namespace Core {
class FrameBuffer;
class ScreenFrameBuffer;
class AudioManager;
class Scheduler;
}

#include "Fence.hpp"
#include "IndexBuffer.hpp"
#include "Input.hpp"
#include "OpenglContext.hpp"
Expand All @@ -24,4 +23,5 @@ namespace Core {
#include "VertexBuffer.hpp"
#include "VertexBufferLayout.hpp"
#include "FrameBuffer.hpp"
#include "AudioManager.hpp"
#include "AudioManager.hpp"
#include "Scheduler.hpp"
53 changes: 0 additions & 53 deletions code/Engine/include/Core/Fence.hpp

This file was deleted.

Loading

0 comments on commit e9aafaa

Please sign in to comment.