Skip to content

Commit c6906bb

Browse files
authored
feat: Add optional Tracy profiling (#9)
1 parent f5bc458 commit c6906bb

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

noengine-cpp-sdl2/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ecsact_binary(
2020
recipes = [
2121
"@ecsact_rt_entt",
2222
],
23+
# tracy = True,
2324
)
2425

2526
cc_binary(
@@ -52,6 +53,7 @@ cc_binary(
5253
"@ecsact_runtime//:core",
5354
"@ecsact_lang_cpp//:support",
5455
"@ecsact_lang_cpp//:execution_context",
56+
"@tracy",
5557
],
5658
)
5759

noengine-cpp-sdl2/MODULE.bazel

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
88

99
bazel_dep(name = "ecsact_runtime", version = "0.7.0")
1010
bazel_dep(name = "bazel_skylib", version = "1.7.1")
11-
bazel_dep(name = "rules_ecsact", version = "0.5.8")
12-
bazel_dep(name = "ecsact_cli", version = "0.3.19")
11+
bazel_dep(name = "rules_ecsact", version = "0.5.9")
12+
bazel_dep(name = "ecsact_cli", version = "0.3.21")
1313
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.10")
1414
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
1515
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
1616
bazel_dep(name = "platforms", version = "0.0.10")
17-
bazel_dep(name = "ecsact_rt_entt", version = "0.3.13")
17+
bazel_dep(name = "ecsact_rt_entt", version = "0.3.14")
18+
bazel_dep(name = "docopt.cpp", version = "0.6.2")
19+
bazel_dep(name = "boost.regex", version = "1.83.0.bcr.1")
20+
bazel_dep(name = "tracy", version = "0.11.1.edr.2")
1821
bazel_dep(name = "cute_c2")
1922
bazel_dep(name = "imgui")
20-
bazel_dep(name = "tracy", version = "0.11.1")
2123

2224
archive_override(
2325
module_name = "cute_c2",
@@ -37,12 +39,6 @@ git_override(
3739
remote = "https://github.com/zaucy/sdl.git",
3840
)
3941

40-
git_override(
41-
module_name = "tracy",
42-
commit = "cc236c7d1cf57b7065dc2cb3faa6a9573b46481a",
43-
remote = "git@github.com:seaube/tracy.git",
44-
)
45-
4642
ecsact = use_extension("@rules_ecsact//ecsact:extensions.bzl", "ecsact", dev_dependency = True)
4743
ecsact.toolchain(use_ecsact_cli = True)
4844
use_repo(ecsact, "ecsact_toolchain")

noengine-cpp-sdl2/src/collision.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
#include <algorithm>
66
#include "cute_c2.h"
77
#include "simulation_config.hh"
8+
#include "tracy/Tracy.hpp"
89

910
constexpr auto push_pressure_strength = 1000.f;
1011

1112
auto example::AlwaysRemoveColliding::impl(context& ctx) -> void {
13+
ZoneScoped;
1214
}
1315

1416
auto example::CollisionPressurePush::impl(context& ctx) -> void {
17+
ZoneScoped;
1518
auto vel = ctx.get<Velocity>();
1619
auto colliding = ctx.get<Colliding>();
1720

@@ -24,9 +27,11 @@ auto example::CollisionPressurePush::impl(context& ctx) -> void {
2427
}
2528

2629
auto example::CollisionParent::impl(context& ctx) -> void {
30+
ZoneScoped;
2731
}
2832

2933
auto example::CollisionParent::Collision::impl(context& ctx) -> void {
34+
ZoneScoped;
3035
if(ctx._ctx.same(ctx._ctx.parent())) {
3136
return;
3237
}

noengine-cpp-sdl2/src/example.ecsact

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ system ViewportCollision {
7878
readwrite Position;
7979
}
8080

81-
system Render {
81+
system Render(parallel: false) {
8282
readonly Position;
8383
}
8484

85-
system RenderAimer {
85+
system RenderAimer(parallel: false) {
8686
readonly Moving;
8787
readonly Position;
8888
}

noengine-cpp-sdl2/src/main.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <format>
44
#include <SDL.h>
55
#include <SDL_main.h>
6+
#include "tracy/Tracy.hpp"
67
#include "imgui.h"
78
#include "imgui_impl_sdl2.h"
89
#include "imgui_impl_sdlrenderer2.h"
@@ -86,6 +87,10 @@ auto main(int argc, char* argv[]) -> int {
8687
return 1;
8788
}
8889

90+
#ifdef TRACY_MANUAL_LIFETIME
91+
tracy::StartupProfiler();
92+
#endif
93+
8994
// TODO: Create codegen for this
9095
ecsact_set_system_execution_impl(
9196
ecsact_id_cast<ecsact_system_like_id>(example::Move::id),
@@ -271,6 +276,7 @@ auto main(int argc, char* argv[]) -> int {
271276
ImGui::Render();
272277
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
273278
SDL_RenderPresent(renderer);
279+
FrameMark;
274280
} else if(event.type == SDL_WINDOWEVENT) {
275281
if(event.window.type == SDL_WINDOWEVENT_RESIZED) {
276282
SDL_GetWindowSize(win, &viewport_width, &viewport_height);
@@ -283,5 +289,8 @@ auto main(int argc, char* argv[]) -> int {
283289
ImGui_ImplSDL2_Shutdown();
284290
ImGui::DestroyContext();
285291
SDL_Quit();
292+
#ifdef TRACY_MANUAL_LIFETIME
293+
tracy::ShutdownProfiler();
294+
#endif
286295
return 0;
287296
}

noengine-cpp-sdl2/src/render.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <format>
55
#include <SDL.h>
66
#include <SDL_render.h>
7+
#include "tracy/Tracy.hpp"
78

89
extern SDL_Renderer* renderer;
910
extern int viewport_width;
@@ -21,6 +22,7 @@ static auto viewport_relative_pos(const auto& pos, auto& out_pos) -> void {
2122
}
2223

2324
auto example::Render::impl(context& ctx) -> void {
25+
ZoneScoped;
2426
auto pos = ctx.get<Position>();
2527
auto rect = SDL_Rect{};
2628
rect.w = 10.0f;
@@ -32,6 +34,7 @@ auto example::Render::impl(context& ctx) -> void {
3234
}
3335

3436
auto example::RenderAimer::impl(context& ctx) -> void {
37+
ZoneScoped;
3538
constexpr auto aimer_size = 5.f;
3639
SDL_SetRenderDrawColor(renderer, 255, 128, 0, 255);
3740

noengine-cpp-sdl2/src/system_impls.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <iostream>
55
#include <format>
66
#include "simulation_config.hh"
7+
#include "tracy/Tracy.hpp"
78

89
constexpr auto player_speed = 600.f;
910
constexpr auto player_jump_power = 1800.f;
@@ -12,12 +13,14 @@ constexpr auto projectile_speed = 2500.0f;
1213
constexpr auto terminal_velocity = 5000.0f;
1314

1415
auto example::Move::impl(context& ctx) -> void {
16+
ZoneScoped;
1517
auto move_dir_x = std::clamp(ctx.action().dir_x, -1.f, 1.f);
1618
auto move_dir_y = std::clamp(ctx.action().dir_y, -1.f, 1.f);
1719
ctx.update(Moving{move_dir_x, move_dir_y});
1820
}
1921

2022
auto example::Fire::impl(context& ctx) -> void {
23+
ZoneScoped;
2124
auto player_pos = ctx.get<Position>();
2225
auto moving = ctx.get<Moving>();
2326

0 commit comments

Comments
 (0)