add tracy
This commit is contained in:
+160
-129
@@ -5,6 +5,8 @@
|
||||
#include <imgui_internal.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
#include <imgui_impl_sdlgpu3.h>
|
||||
#include <tracy/Tracy.hpp>
|
||||
#include <tracy/TracyC.h>
|
||||
|
||||
#include "smol-atlas.h"
|
||||
#include "defer.h"
|
||||
@@ -1008,6 +1010,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
// MSG Message;
|
||||
while (Running) {
|
||||
ZoneScopedN("Loop");
|
||||
ImGui_ImplSDLGPU3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
@@ -1089,6 +1092,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
TracyCZoneN(tracy_AcquireSwapchainTexture, "AcquireSwapchainTexture", true);
|
||||
Uint32 width = 0, height = 0;
|
||||
SDL_GPUTexture *swapchain_texture = NULL;
|
||||
if (!SDL_WaitAndAcquireGPUSwapchainTexture(command_buffer, window, &swapchain_texture, &width, &height)) {
|
||||
@@ -1096,128 +1100,133 @@ int main(int argc, char **argv) {
|
||||
SDL_CancelGPUCommandBuffer(command_buffer);
|
||||
return 1;
|
||||
}
|
||||
TracyCZoneEnd(tracy_AcquireSwapchainTexture);
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
{
|
||||
ZoneScopedN("Events");
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
ZoneScopedN("Event");
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT: {
|
||||
Running = false;
|
||||
} break;
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT: {
|
||||
Running = false;
|
||||
} break;
|
||||
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: {
|
||||
window_width = event.window.data1;
|
||||
window_height = event.window.data2;
|
||||
} break;
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: {
|
||||
window_width = event.window.data1;
|
||||
window_height = event.window.data2;
|
||||
} break;
|
||||
|
||||
case SDL_EVENT_KEY_DOWN: {
|
||||
if (io.WantCaptureKeyboard)
|
||||
continue;
|
||||
case SDL_EVENT_KEY_DOWN: {
|
||||
if (io.WantCaptureKeyboard)
|
||||
continue;
|
||||
|
||||
if (event.key.key == SDLK_UP || event.key.key == SDLK_W) {
|
||||
player.pos_y = clamp(0, player.pos_y + 1, map_height - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
if (event.key.key == SDLK_UP || event.key.key == SDLK_W) {
|
||||
player.pos_y = clamp(0, player.pos_y + 1, map_height - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
|
||||
if (event.key.key == SDLK_LEFT || event.key.key == SDLK_A) {
|
||||
player.pos_x = clamp(0, player.pos_x - 1, map_width - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
if (event.key.key == SDLK_LEFT || event.key.key == SDLK_A) {
|
||||
player.pos_x = clamp(0, player.pos_x - 1, map_width - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
|
||||
if (event.key.key == SDLK_DOWN || event.key.key == SDLK_S) {
|
||||
player.pos_y = clamp(0, player.pos_y - 1, map_height - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
if (event.key.key == SDLK_DOWN || event.key.key == SDLK_S) {
|
||||
player.pos_y = clamp(0, player.pos_y - 1, map_height - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
|
||||
if (event.key.key == SDLK_RIGHT || event.key.key == SDLK_D) {
|
||||
player.pos_x = clamp(0, player.pos_x + 1, map_width - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
if (event.key.key == SDLK_RIGHT || event.key.key == SDLK_D) {
|
||||
player.pos_x = clamp(0, player.pos_x + 1, map_width - 1 - (per_frame.use_dual_grid ? 1 : 0));
|
||||
}
|
||||
|
||||
if (event.key.key == SDLK_F1) {
|
||||
save_map();
|
||||
}
|
||||
if (event.key.key == SDLK_F1) {
|
||||
save_map();
|
||||
}
|
||||
|
||||
if (event.key.key == SDLK_F4) {
|
||||
load_map();
|
||||
}
|
||||
} break;
|
||||
if (event.key.key == SDLK_F4) {
|
||||
load_map();
|
||||
}
|
||||
} break;
|
||||
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
||||
if (io.WantCaptureMouse)
|
||||
continue;
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
||||
if (io.WantCaptureMouse)
|
||||
continue;
|
||||
|
||||
V2 floor_intersection = get_floor_intersection_of_mouse(V2_(event.button.x, event.button.y));
|
||||
|
||||
Sint32 tile_x = roundf(floor_intersection.x);
|
||||
Sint32 tile_y = roundf(floor_intersection.y);
|
||||
|
||||
if(0 <= tile_x && tile_x < map_width && 0 <= tile_y && tile_y < map_height) {
|
||||
dragging_tile_change = true;
|
||||
|
||||
drag_start_pos[0] = tile_x;
|
||||
drag_start_pos[1] = tile_y;
|
||||
}
|
||||
|
||||
SDL_Keymod modifiers = SDL_GetModState();
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_x <= -1) {
|
||||
if(modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('W', -1);
|
||||
else
|
||||
change_map_size('W', 1);
|
||||
}
|
||||
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_x == map_width) {
|
||||
if (modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('E', -1);
|
||||
else
|
||||
change_map_size('E', 1);
|
||||
}
|
||||
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_y <= -1) {
|
||||
if (modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('N', -1);
|
||||
else
|
||||
change_map_size('N', 1);
|
||||
}
|
||||
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_y == map_height) {
|
||||
if (modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('S', -1);
|
||||
else
|
||||
change_map_size('S', 1);
|
||||
}
|
||||
} break;
|
||||
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
||||
if (io.WantCaptureMouse)
|
||||
continue;
|
||||
|
||||
if (selected_tile != -1 && dragging_tile_change) {
|
||||
V2 floor_intersection = get_floor_intersection_of_mouse(V2_(event.button.x, event.button.y));
|
||||
|
||||
Sint32 tile_x = clamp(0, (Sint32)roundf(floor_intersection.x), map_width - 1);
|
||||
Sint32 tile_y = clamp(0, (Sint32)roundf(floor_intersection.y), map_height - 1);
|
||||
|
||||
Sint32 start_x = min(tile_x, drag_start_pos[0]);
|
||||
Sint32 start_y = min(tile_y, drag_start_pos[1]);
|
||||
Sint32 tile_x = roundf(floor_intersection.x);
|
||||
Sint32 tile_y = roundf(floor_intersection.y);
|
||||
|
||||
Sint32 end_x = max(tile_x, drag_start_pos[0]);
|
||||
Sint32 end_y = max(tile_y, drag_start_pos[1]);
|
||||
if(0 <= tile_x && tile_x < map_width && 0 <= tile_y && tile_y < map_height) {
|
||||
dragging_tile_change = true;
|
||||
|
||||
for (Sint32 y = start_y; y <= end_y; y++) {
|
||||
for (Sint32 x = start_x; x <= end_x; x++) {
|
||||
if (selected_rotation == -1) {
|
||||
Sint32 rotation = SDL_rand(4);
|
||||
map_tiles[x + map_width * y] = ((rotation & 3) << 16) | selected_tile;
|
||||
} else {
|
||||
map_tiles[x + map_width * y] = ((selected_rotation & 3) << 16) | selected_tile;
|
||||
drag_start_pos[0] = tile_x;
|
||||
drag_start_pos[1] = tile_y;
|
||||
}
|
||||
|
||||
SDL_Keymod modifiers = SDL_GetModState();
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_x <= -1) {
|
||||
if(modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('W', -1);
|
||||
else
|
||||
change_map_size('W', 1);
|
||||
}
|
||||
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_x == map_width) {
|
||||
if (modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('E', -1);
|
||||
else
|
||||
change_map_size('E', 1);
|
||||
}
|
||||
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_y <= -1) {
|
||||
if (modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('N', -1);
|
||||
else
|
||||
change_map_size('N', 1);
|
||||
}
|
||||
|
||||
if (modifiers & SDL_KMOD_SHIFT && tile_y == map_height) {
|
||||
if (modifiers & SDL_KMOD_CTRL)
|
||||
change_map_size('S', -1);
|
||||
else
|
||||
change_map_size('S', 1);
|
||||
}
|
||||
} break;
|
||||
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
||||
if (io.WantCaptureMouse)
|
||||
continue;
|
||||
|
||||
if (selected_tile != -1 && dragging_tile_change) {
|
||||
V2 floor_intersection = get_floor_intersection_of_mouse(V2_(event.button.x, event.button.y));
|
||||
|
||||
Sint32 tile_x = clamp(0, (Sint32)roundf(floor_intersection.x), map_width - 1);
|
||||
Sint32 tile_y = clamp(0, (Sint32)roundf(floor_intersection.y), map_height - 1);
|
||||
|
||||
Sint32 start_x = min(tile_x, drag_start_pos[0]);
|
||||
Sint32 start_y = min(tile_y, drag_start_pos[1]);
|
||||
|
||||
Sint32 end_x = max(tile_x, drag_start_pos[0]);
|
||||
Sint32 end_y = max(tile_y, drag_start_pos[1]);
|
||||
|
||||
for (Sint32 y = start_y; y <= end_y; y++) {
|
||||
for (Sint32 x = start_x; x <= end_x; x++) {
|
||||
if (selected_rotation == -1) {
|
||||
Sint32 rotation = SDL_rand(4);
|
||||
map_tiles[x + map_width * y] = ((rotation & 3) << 16) | selected_tile;
|
||||
} else {
|
||||
map_tiles[x + map_width * y] = ((selected_rotation & 3) << 16) | selected_tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_buffer(world_buffer, 0, map_width * map_height * sizeof(Uint32), map_tiles);
|
||||
}
|
||||
|
||||
update_buffer(world_buffer, 0, map_width * map_height * sizeof(Uint32), map_tiles);
|
||||
}
|
||||
|
||||
dragging_tile_change = false;
|
||||
} break;;
|
||||
dragging_tile_change = false;
|
||||
} break;;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1228,23 +1237,35 @@ int main(int argc, char **argv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
player_instance.pos.x = player.pos_x;
|
||||
player_instance.pos.y = player.pos_y;
|
||||
{
|
||||
ZoneScopedN("Update");
|
||||
{
|
||||
ZoneScopedN("player_instance_buffer");
|
||||
player_instance.pos.x = player.pos_x;
|
||||
player_instance.pos.y = player.pos_y;
|
||||
|
||||
update_buffer(player_instance_buffer, 0, sizeof(player_instance), &player_instance);
|
||||
update_buffer(player_instance_buffer, 0, sizeof(player_instance), &player_instance);
|
||||
}
|
||||
|
||||
per_frame.aspect_ratio = ((float) window_width / (float) window_height);
|
||||
per_frame.map_width = map_width;
|
||||
per_frame.camera_x = player.pos_x;
|
||||
per_frame.camera_y = player.pos_y;
|
||||
{
|
||||
ZoneScopedN("per_frame");
|
||||
per_frame.aspect_ratio = ((float) window_width / (float) window_height);
|
||||
per_frame.map_width = map_width;
|
||||
per_frame.camera_x = player.pos_x;
|
||||
per_frame.camera_y = player.pos_y;
|
||||
|
||||
SDL_PushGPUVertexUniformData(command_buffer, 0, &per_frame, sizeof(per_frame));
|
||||
SDL_PushGPUVertexUniformData(command_buffer, 0, &per_frame, sizeof(per_frame));
|
||||
}
|
||||
|
||||
view_matrix = view (V3_((float)player.pos_x, (float)player.pos_y, 0), radians(per_frame.camera_tilt), per_frame.camera_distance);
|
||||
inverse_view_matrix = inverse_view(V3_((float)player.pos_x, (float)player.pos_y, 0), radians(per_frame.camera_tilt), per_frame.camera_distance);
|
||||
{
|
||||
ZoneScopedN("matrices");
|
||||
view_matrix = view (V3_((float)player.pos_x, (float)player.pos_y, 0), radians(per_frame.camera_tilt), per_frame.camera_distance);
|
||||
inverse_view_matrix = inverse_view(V3_((float)player.pos_x, (float)player.pos_y, 0), radians(per_frame.camera_tilt), per_frame.camera_distance);
|
||||
|
||||
projection_matrix = projection (radians(per_frame.fovy_degrees), per_frame.aspect_ratio, NEAR_PLANE);
|
||||
inverse_projection_matrix = inverse_projection(radians(per_frame.fovy_degrees), per_frame.aspect_ratio, NEAR_PLANE);
|
||||
projection_matrix = projection (radians(per_frame.fovy_degrees), per_frame.aspect_ratio, NEAR_PLANE);
|
||||
inverse_projection_matrix = inverse_projection(radians(per_frame.fovy_degrees), per_frame.aspect_ratio, NEAR_PLANE);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GPUColorTargetInfo color_target_info = {
|
||||
.texture = swapchain_texture,
|
||||
@@ -1260,6 +1281,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
{ // Draw Map
|
||||
ZoneScopedN("Draw Map");
|
||||
SDL_GPUBufferBinding index_buffer_binding = { .buffer = index_buffer, .offset = 0 };
|
||||
SDL_GPUBufferBinding vertex_buffers[] = {
|
||||
{ .buffer = vertex_buffer, .offset = 0 },
|
||||
@@ -1278,6 +1300,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
{ // Draw Player
|
||||
ZoneScopedN("Draw Player");
|
||||
SDL_GPUBufferBinding vertex_buffers[] = {
|
||||
{ .buffer = vertex_buffer, .offset = 0 },
|
||||
{ .buffer = player_instance_buffer, .offset = 0 },
|
||||
@@ -1285,6 +1308,7 @@ int main(int argc, char **argv) {
|
||||
SDL_GPUTextureSamplerBinding texture_bindings[] = {
|
||||
{ .texture = player_texture, .sampler = point_sampler },
|
||||
};
|
||||
|
||||
SDL_BindGPUGraphicsPipeline(render_pass, basic_graphics_pipeline);
|
||||
SDL_BindGPUVertexBuffers(render_pass, 0, vertex_buffers, SDL_arraysize(vertex_buffers));
|
||||
SDL_BindGPUFragmentSamplers(render_pass, 0, texture_bindings, SDL_arraysize(texture_bindings));
|
||||
@@ -1292,24 +1316,31 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
SDL_EndGPURenderPass(render_pass);
|
||||
|
||||
ImGui::Render();
|
||||
ImDrawData *draw_data = ImGui::GetDrawData();
|
||||
Imgui_ImplSDLGPU3_PrepareDrawData(draw_data, command_buffer);
|
||||
{
|
||||
ZoneScopedN("ImGui Render");
|
||||
ImGui::Render();
|
||||
ImDrawData *draw_data = ImGui::GetDrawData();
|
||||
Imgui_ImplSDLGPU3_PrepareDrawData(draw_data, command_buffer);
|
||||
|
||||
SDL_GPUColorTargetInfo imgui_color_target_info = {
|
||||
.texture = swapchain_texture,
|
||||
.load_op = SDL_GPU_LOADOP_LOAD,
|
||||
.store_op = SDL_GPU_STOREOP_STORE,
|
||||
};
|
||||
SDL_GPUColorTargetInfo imgui_color_target_info = {
|
||||
.texture = swapchain_texture,
|
||||
.load_op = SDL_GPU_LOADOP_LOAD,
|
||||
.store_op = SDL_GPU_STOREOP_STORE,
|
||||
};
|
||||
|
||||
SDL_GPURenderPass *imgui_render_pass = SDL_BeginGPURenderPass(command_buffer, &imgui_color_target_info, 1, NULL);
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(draw_data, command_buffer, imgui_render_pass);
|
||||
SDL_EndGPURenderPass(imgui_render_pass);
|
||||
|
||||
if (!SDL_SubmitGPUCommandBuffer(command_buffer)) {
|
||||
log_error("Failed to submit gpu command buffer (%s). Exiting.", SDL_GetError());
|
||||
return 1;
|
||||
SDL_GPURenderPass *imgui_render_pass = SDL_BeginGPURenderPass(command_buffer, &imgui_color_target_info, 1, NULL);
|
||||
ImGui_ImplSDLGPU3_RenderDrawData(draw_data, command_buffer, imgui_render_pass);
|
||||
SDL_EndGPURenderPass(imgui_render_pass);
|
||||
}
|
||||
|
||||
{
|
||||
ZoneScopedN("SubmitGPUCommandBuffer");
|
||||
if (!SDL_SubmitGPUCommandBuffer(command_buffer)) {
|
||||
log_error("Failed to submit gpu command buffer (%s). Exiting.", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
FrameMark;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user