Skip to content

Commit 62515f1

Browse files
committed
(core) add type aliases for array, vector and string types
1 parent f1c5736 commit 62515f1

168 files changed

Lines changed: 1953 additions & 1883 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/entities/gameoflife/src/App.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ App::~App() {
2525
ilog("Cleaning");
2626
}
2727

28-
auto App::run([[maybe_unused]] const int argc, [[maybe_unused]] CZString argv[]) -> i32 {
28+
auto App::run([[maybe_unused]] const int argc, [[maybe_unused]] czstring argv[]) -> i32 {
2929
using Clock = std::chrono::high_resolution_clock;
3030

3131
using namespace stormkit::literals;

examples/entities/gameoflife/src/App.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export {
3131
App();
3232
~App() override;
3333

34-
auto run(const int argc, CZString argv[]) -> stormkit::i32 override;
34+
auto run(const int argc, czstring argv[]) -> stormkit::i32 override;
3535

3636
private:
3737
auto do_initWindow() -> void;

examples/entities/gameoflife/src/Constants.cppm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export {
2424
= sizeof(stormkit::math::fvec2) + sizeof(stormkit::fvec3);
2525
inline constexpr auto WINDOW_TITLE = "StormKit GameOfLife Example";
2626
inline constexpr auto MESH_VERTEX_BUFFER_SIZE = VERTEX_SIZE * 3;
27-
inline constexpr auto MESH_VERTEX_BINDING_DESCRIPTIONS = std::array {
27+
inline constexpr auto MESH_VERTEX_BINDING_DESCRIPTIONS = array {
2828
stormkit::gpu::VertexBindingDescription { .binding = 0, .stride = VERTEX_SIZE }
2929
};
30-
inline constexpr auto MESH_VERTEX_ATTRIBUTE_DESCRIPTIONS = std::array {
30+
inline constexpr auto MESH_VERTEX_ATTRIBUTE_DESCRIPTIONS = array {
3131
stormkit::gpu::VertexInputAttributeDescription { .location = 0,
3232
.binding = 0,
3333
.format = stormkit::gpu::format::f322,

examples/entities/gameoflife/src/Renderer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ auto Renderer::renderFrame() -> void {
3636
}
3737

3838
const auto viewports = [&] {
39-
auto v = std::vector<gpu::Viewport> {};
39+
auto v = dyn_array<gpu::Viewport> {};
4040
v.emplace_back(gpu::Viewport {
4141
.extent = surface_extentf,
4242
.depth = { 0, 1 }
@@ -46,7 +46,7 @@ auto Renderer::renderFrame() -> void {
4646
}();
4747

4848
const auto scissors = [&] {
49-
auto s = std::vector<gpu::Scissor> {};
49+
auto s = dyn_array<gpu::Scissor> {};
5050
s.emplace_back(gpu::Scissor { .extent = surface_extent });
5151

5252
return s;
@@ -150,7 +150,7 @@ auto Renderer::do_initMeshRenderObjects() -> void {
150150
.descriptor_count = 1 });
151151
m_descriptor_set_layout->bake();
152152
m_descriptor_pool = m_device->allocateDescriptorPool(
153-
std::array {
153+
array {
154154
gpu::DescriptorPool::Size { gpu::DescriptorType::Combined_Image_Sampler, 1 }
155155
},
156156
1);

examples/entities/gameoflife/src/Renderer.cppm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ export {
4646
stormkit::gpu::Fence* m_current_fence = nullptr;
4747

4848
const stormkit::gpu::Queue* m_queue = nullptr;
49-
std::vector<stormkit::gpu::ImageView> m_surface_views;
49+
dyn_array<stormkit::gpu::ImageView> m_surface_views;
5050

5151
std::unique_ptr<stormkit::gpu::DescriptorSetLayout> m_descriptor_set_layout;
5252
std::unique_ptr<stormkit::gpu::DescriptorPool> m_descriptor_pool;
5353

5454
std::unique_ptr<stormkit::gpu::RenderPass> m_render_pass;
5555

5656
struct Board {
57-
std::vector<stormkit::gpu::Image> images;
58-
std::vector<stormkit::gpu::ImageView> image_views;
57+
dyn_array<stormkit::gpu::Image> images;
58+
dyn_array<stormkit::gpu::ImageView> image_views;
5959
std::unique_ptr<stormkit::gpu::Sampler> sampler;
6060

6161
stormkit::u32 current_image = 0;
@@ -68,8 +68,8 @@ export {
6868
std::unique_ptr<stormkit::gpu::DescriptorSet> descriptor_set;
6969
} m_board;
7070

71-
std::vector<stormkit::gpu::CommandBuffer> m_command_buffers;
72-
std::vector<stormkit::gpu::Framebuffer> m_framebuffers;
71+
dyn_array<stormkit::gpu::CommandBuffer> m_command_buffers;
72+
dyn_array<stormkit::gpu::Framebuffer> m_framebuffers;
7373
};
7474

7575
#ifdef STORMKIT_BUILD_MODULES

examples/entities/gameoflife/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import App;
1414
#include "App.mpp"
1515
#endif
1616

17-
auto main([[maybe_unused]] std::span<const std::string_view> args) -> int {
17+
auto main([[maybe_unused]] array_view<const string_view> args) -> int {
1818
using namespace stormkit;
1919

2020
setup_signal_handler();

examples/gpu/common/app.cppm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern "C" auto debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
4646
export namespace base {
4747
class Application {
4848
public:
49-
auto run(this auto& self, std::span<const std::string_view> args) {
49+
auto run(this auto& self, array_view<const string_view> args) {
5050
wsi::parse_args(args);
5151
log::parse_args(args);
5252

@@ -79,7 +79,7 @@ export namespace base {
7979
DeferInit<gpu::CommandPool> m_command_pool;
8080

8181
private:
82-
auto init_window(std::string_view example_name) noexcept -> void {
82+
auto init_window(string_view example_name) noexcept -> void {
8383
m_window = wsi::Window::open(std::format("Stormkit GPU {} example", example_name),
8484
{ 800_u32, 600_u32 },
8585
wsi::WindowFlag::DEFAULT | wsi::WindowFlag::EXTERNAL_CONTEXT);
@@ -88,13 +88,12 @@ export namespace base {
8888
});
8989
}
9090

91-
auto init_gpu(std::string_view example_name) noexcept -> void {
91+
auto init_gpu(string_view example_name) noexcept -> void {
9292
// initialize gpu backend (vulkan or webgpu depending the platform)
9393
TryDiscardAssert(gpu::initialize_backend(), "Failed to initialize gpu backend");
9494

9595
// create gpu instance and attach surface to window
96-
m_instance = TryAssert(gpu::Instance::create(std::string { example_name }, true),
97-
"Failed to initialize gpu instance");
96+
m_instance = TryAssert(gpu::Instance::create(string { example_name }, true), "Failed to initialize gpu instance");
9897

9998
m_debug_callback = TryAssert(gpu::DebugCallback::create(m_instance, debug_callback),
10099
"Failed to initialize gpu instance");

examples/gpu/imgui/src/main.cpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct SwapchainImageResource {
3737

3838
namespace {
3939
constexpr auto BUFFERING_COUNT = 2_u32;
40-
constexpr auto POOL_SIZES = std::array {
40+
constexpr auto POOL_SIZES = array {
4141
gpu::DescriptorPool::Size { .type = gpu::DescriptorType::COMBINED_IMAGE_SAMPLER, .descriptor_count = BUFFERING_COUNT }
4242
};
4343
} // namespace
@@ -55,7 +55,7 @@ class Application: public base::Application {
5555
"Failed to create descriptor pool!");
5656

5757
// create present engine resources
58-
m_submission_resources = init_by<std::vector<SubmissionResource>>([&](auto& out) noexcept {
58+
m_submission_resources = init_by<dyn_array<SubmissionResource>>([&](auto& out) noexcept {
5959
out.reserve(BUFFERING_COUNT);
6060
for (auto _ : range(BUFFERING_COUNT)) {
6161
out.push_back({
@@ -84,12 +84,11 @@ class Application: public base::Application {
8484
for (const auto& swap_image : images) {
8585
auto view = TryAssert(gpu::ImageView::create(m_device, swap_image), "Failed to create swapchain image view!");
8686

87-
m_image_resources
88-
.push_back({ .image = swap_image,
89-
.view = std::move(view),
90-
.render_finished = TryAssert(gpu::Semaphore::create(m_device),
91-
"Failed to create render "
92-
"signal semaphore!") });
87+
m_image_resources.push_back({ .image = swap_image,
88+
.view = std::move(view),
89+
.render_finished = TryAssert(gpu::Semaphore::create(m_device),
90+
"Failed to create render "
91+
"signal semaphore!") });
9392

9493
auto& transition_cmb = transition_cmbs[image_index];
9594
TryDiscardAssert((transition_cmb.record([&](auto cmb) noexcept {
@@ -163,39 +162,40 @@ class Application: public base::Application {
163162
ImGui_ImplVulkan_LoadFunctions(VK_API_VERSION_1_1, gpu::vk::imgui_vk_loader, &*m_device);
164163
ImGui_ImplVulkan_Init(&init_info);
165164

166-
m_window
167-
->on(wsi::KeyDownEventFunc { [this, &io](u8 /*id*/, wsi::Key key, char c) mutable noexcept {
168-
if (key == wsi::Key::ESCAPE) m_window->close();
169-
io.AddInputCharactersUTF8(&c);
170-
} },
171-
wsi::MouseMovedEventFunc { [&io](u8 /*id*/, const math::ivec2& position) mutable noexcept {
172-
const auto _position = position.to<f32>();
173-
174-
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
175-
io.AddMousePosEvent(_position.x, _position.y);
176-
} },
177-
wsi::MouseButtonDownEventFunc { [&io](u8 /*id*/, wsi::MouseButton button, const math::ivec2&) mutable noexcept {
178-
auto mouse_button = -1;
179-
if (button == wsi::MouseButton::LEFT) mouse_button = 0;
180-
if (button == wsi::MouseButton::RIGHT) mouse_button = 1;
181-
if (button == wsi::MouseButton::MIDDLE) mouse_button = 2;
182-
if (button == wsi::MouseButton::BUTTON_1) mouse_button = 3;
183-
if (button == wsi::MouseButton::BUTTON_2) mouse_button = 4;
184-
if (mouse_button == -1) return;
185-
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
186-
io.AddMouseButtonEvent(mouse_button, true);
187-
} },
188-
wsi::MouseButtonUpEventFunc { [&io](u8 /*id*/, wsi::MouseButton button, const math::ivec2&) mutable noexcept {
189-
auto mouse_button = -1;
190-
if (button == wsi::MouseButton::LEFT) mouse_button = 0;
191-
if (button == wsi::MouseButton::RIGHT) mouse_button = 1;
192-
if (button == wsi::MouseButton::MIDDLE) mouse_button = 2;
193-
if (button == wsi::MouseButton::BUTTON_1) mouse_button = 3;
194-
if (button == wsi::MouseButton::BUTTON_2) mouse_button = 4;
195-
if (mouse_button == -1) return;
196-
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
197-
io.AddMouseButtonEvent(mouse_button, false);
198-
} });
165+
m_window->on(wsi::KeyDownEventFunc { [this, &io](u8 /*id*/, wsi::Key key, char c) mutable noexcept {
166+
if (key == wsi::Key::ESCAPE) m_window->close();
167+
io.AddInputCharactersUTF8(&c);
168+
} },
169+
wsi::MouseMovedEventFunc { [&io](u8 /*id*/, const math::ivec2& position) mutable noexcept {
170+
const auto _position = position.to<f32>();
171+
172+
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
173+
io.AddMousePosEvent(_position.x, _position.y);
174+
} },
175+
wsi::MouseButtonDownEventFunc {
176+
[&io](u8 /*id*/, wsi::MouseButton button, const math::ivec2&) mutable noexcept {
177+
auto mouse_button = -1;
178+
if (button == wsi::MouseButton::LEFT) mouse_button = 0;
179+
if (button == wsi::MouseButton::RIGHT) mouse_button = 1;
180+
if (button == wsi::MouseButton::MIDDLE) mouse_button = 2;
181+
if (button == wsi::MouseButton::BUTTON_1) mouse_button = 3;
182+
if (button == wsi::MouseButton::BUTTON_2) mouse_button = 4;
183+
if (mouse_button == -1) return;
184+
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
185+
io.AddMouseButtonEvent(mouse_button, true);
186+
} },
187+
wsi::MouseButtonUpEventFunc {
188+
[&io](u8 /*id*/, wsi::MouseButton button, const math::ivec2&) mutable noexcept {
189+
auto mouse_button = -1;
190+
if (button == wsi::MouseButton::LEFT) mouse_button = 0;
191+
if (button == wsi::MouseButton::RIGHT) mouse_button = 1;
192+
if (button == wsi::MouseButton::MIDDLE) mouse_button = 2;
193+
if (button == wsi::MouseButton::BUTTON_1) mouse_button = 3;
194+
if (button == wsi::MouseButton::BUTTON_2) mouse_button = 4;
195+
if (mouse_button == -1) return;
196+
io.AddMouseSourceEvent(ImGuiMouseSource_Mouse);
197+
io.AddMouseButtonEvent(mouse_button, false);
198+
} });
199199
}
200200

201201
auto run_example() {
@@ -221,7 +221,7 @@ class Application: public base::Application {
221221
const auto& swapchain_image_resource = m_image_resources[image_index];
222222
const auto& signal = swapchain_image_resource.render_finished;
223223

224-
static constexpr auto PIPELINE_FLAGS = std::array { gpu::PipelineStageFlag::COLOR_ATTACHMENT_OUTPUT };
224+
static constexpr auto PIPELINE_FLAGS = array { gpu::PipelineStageFlag::COLOR_ATTACHMENT_OUTPUT };
225225

226226
const auto window_extent = m_window->extent().to<i32>();
227227
const auto rendering_info = gpu::RenderingInfo {
@@ -268,16 +268,16 @@ class Application: public base::Application {
268268
ImGui::DestroyContext();
269269
}
270270

271-
constexpr auto example_name() const noexcept -> std::string_view { return "Imgui"; }
271+
constexpr auto example_name() const noexcept -> string_view { return "Imgui"; }
272272

273273
private:
274-
DeferInit<gpu::DescriptorPool> m_descriptor_pool;
275-
std::vector<SubmissionResource> m_submission_resources;
276-
std::vector<SwapchainImageResource> m_image_resources;
277-
usize m_current_frame = 0_usize;
274+
DeferInit<gpu::DescriptorPool> m_descriptor_pool;
275+
dyn_array<SubmissionResource> m_submission_resources;
276+
dyn_array<SwapchainImageResource> m_image_resources;
277+
usize m_current_frame = 0_usize;
278278
};
279279

280-
auto main(std::span<const std::string_view> args) -> int {
280+
auto main(array_view<const string_view> args) -> int {
281281
auto app = Application {};
282282
app.run(args);
283283
return 0;

0 commit comments

Comments
 (0)