Made Faster
This commit is contained in:
parent
8e5655abb3
commit
a5fd89168b
34
imgui.ini
34
imgui.ini
@ -10,24 +10,24 @@ Collapsed=1
|
||||
|
||||
[Window][WindowOverViewport_11111111]
|
||||
Pos=0,19
|
||||
Size=1920,1158
|
||||
Size=1280,701
|
||||
Collapsed=0
|
||||
|
||||
[Window][Inspector]
|
||||
Pos=0,683
|
||||
Size=342,494
|
||||
Pos=0,421
|
||||
Size=342,299
|
||||
Collapsed=0
|
||||
DockId=0x0000000A,0
|
||||
|
||||
[Window][Scene Tree]
|
||||
Pos=0,19
|
||||
Size=342,662
|
||||
Size=342,400
|
||||
Collapsed=0
|
||||
DockId=0x00000009,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=344,19
|
||||
Size=1576,535
|
||||
Size=936,78
|
||||
Collapsed=0
|
||||
DockId=0x0000000B,0
|
||||
|
||||
@ -36,14 +36,14 @@ Size=1280,19
|
||||
Collapsed=0
|
||||
|
||||
[Window][Performance Info]
|
||||
Pos=1588,840
|
||||
Size=332,118
|
||||
Pos=1083,383
|
||||
Size=197,118
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Console]
|
||||
Pos=344,840
|
||||
Size=612,337
|
||||
Pos=344,383
|
||||
Size=363,337
|
||||
Collapsed=0
|
||||
DockId=0x0000000D,0
|
||||
|
||||
@ -54,8 +54,8 @@ Collapsed=0
|
||||
DockId=0x0000000B,1
|
||||
|
||||
[Window][Profiler]
|
||||
Pos=344,556
|
||||
Size=1576,282
|
||||
Pos=344,99
|
||||
Size=936,282
|
||||
Collapsed=0
|
||||
DockId=0x0000000C,0
|
||||
|
||||
@ -78,26 +78,26 @@ Collapsed=0
|
||||
DockId=0x00000005,1
|
||||
|
||||
[Window][Color Correction]
|
||||
Pos=1588,960
|
||||
Size=332,217
|
||||
Pos=1083,503
|
||||
Size=197,217
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Window][Asset Browser]
|
||||
Pos=958,840
|
||||
Size=628,337
|
||||
Pos=709,383
|
||||
Size=372,337
|
||||
Collapsed=0
|
||||
DockId=0x0000000E,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=X
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x11111111 SizeRef=342,701 Split=Y Selected=0x12EF0F59
|
||||
DockNode ID=0x00000009 Parent=0x00000001 SizeRef=385,662 HiddenTabBar=1 Selected=0x12EF0F59
|
||||
DockNode ID=0x0000000A Parent=0x00000001 SizeRef=385,494 HiddenTabBar=1 Selected=0x36DC96AB
|
||||
DockNode ID=0x00000002 Parent=0x11111111 SizeRef=1576,701 Split=Y Selected=0xC450F867
|
||||
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,819 Split=Y Selected=0xC450F867
|
||||
DockNode ID=0x0000000B Parent=0x00000007 SizeRef=1576,535 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867
|
||||
DockNode ID=0x0000000C Parent=0x00000007 SizeRef=1576,282 Selected=0x9B5D3198
|
||||
DockNode ID=0x0000000C Parent=0x00000007 SizeRef=1576,282 HiddenTabBar=1 Selected=0x9B5D3198
|
||||
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,337 Split=X Selected=0x9B5D3198
|
||||
DockNode ID=0x00000005 Parent=0x00000008 SizeRef=737,481 Split=X Selected=0x9B5D3198
|
||||
DockNode ID=0x0000000D Parent=0x00000005 SizeRef=363,248 HiddenTabBar=1 Selected=0xEA83D666
|
||||
|
36445
profile_export.json
36445
profile_export.json
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,3 @@
|
||||
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -Isrc\vendor\imgui -IC:\msys64\mingw64\lib\libyaml-cpp.a -MMD -MP -c src\src\Engine.cpp -o src\build\Engine.o
|
||||
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -Isrc\vendor\imgui -IC:\msys64\mingw64\lib\libyaml-cpp.a -MMD -MP -c src\src\core\utils\Profiler.cpp -o src\build\core\utils\Profiler.o
|
||||
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\utils\AssetLoader.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\Logging.o src\build\core\utils\Profiler.o src\build\core\utils\utils.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\Inspector.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto
|
||||
[RUN] Executed app.exe successfully.
|
||||
|
@ -1,50 +1,49 @@
|
||||
Engine.DebugLua(true)
|
||||
|
||||
local Objects = {}
|
||||
local Velocities = {}
|
||||
local CameraObj -- will hold our camera
|
||||
local CamSpeed = 800 -- camera speed in world units/sec
|
||||
local Objects = {}
|
||||
local Velocities = {}
|
||||
local CachedVecs = {}
|
||||
local CachedPoses = {}
|
||||
local CameraObj
|
||||
local CachedCamPos = nil
|
||||
|
||||
-- new border extents
|
||||
local CamSpeed = 800
|
||||
local MinX, MinY = 0, 0
|
||||
local MaxX, MaxY = 5096, 5096
|
||||
local Speed = 1000 -- light speed in units per second
|
||||
local Speed = 1000
|
||||
|
||||
-- simple clamp
|
||||
local function clamp(v, lo, hi)
|
||||
if v < lo then return lo end
|
||||
if v > hi then return hi end
|
||||
return v
|
||||
return (v < lo and lo) or (v > hi and hi) or v
|
||||
end
|
||||
|
||||
function OnInit()
|
||||
math.randomseed(os.time())
|
||||
Engine.LogInfo("Initial Speed: " .. Speed)
|
||||
|
||||
-- cache lights
|
||||
for i = 0, 99 do
|
||||
local tag = "Light_" .. i
|
||||
local obj = Engine.GetObjectByTag(tag)
|
||||
if obj then
|
||||
table.insert(Objects, obj)
|
||||
local ang = math.random() * 2 * math.pi
|
||||
local vx = math.cos(ang) * Speed
|
||||
local vy = math.sin(ang) * Speed
|
||||
Velocities[obj] = { x = vx, y = vy }
|
||||
|
||||
local ang = math.random() * 2 * math.pi
|
||||
Velocities[obj] = { x = math.cos(ang) * Speed, y = math.sin(ang) * Speed }
|
||||
CachedVecs[obj] = Vector2(0, 0) -- reused Vector2 for SetPosition
|
||||
CachedPoses[obj] = obj:GetPosition() -- only once at init
|
||||
else
|
||||
Engine.LogError("Object '" .. tag .. "' not found!")
|
||||
end
|
||||
end
|
||||
|
||||
-- grab the camera
|
||||
CameraObj = Engine.GetObjectByTag("Camera")
|
||||
if not CameraObj then
|
||||
if CameraObj then
|
||||
CachedCamPos = CameraObj:GetPosition()
|
||||
else
|
||||
Engine.LogError("Camera object not found!")
|
||||
end
|
||||
end
|
||||
|
||||
function OnUpdate(dt)
|
||||
-- light speed tweaks (same as before)
|
||||
if Engine.KeyDown(Keycode.Equal) or Engine.KeyDown(Keycode.KPAdd) then
|
||||
Speed = Speed + 100 * dt
|
||||
Engine.LogInfo(string.format("Speed increased to %.1f", Speed))
|
||||
@ -54,16 +53,10 @@ function OnUpdate(dt)
|
||||
Engine.LogInfo(string.format("Speed decreased to %.1f", Speed))
|
||||
end
|
||||
|
||||
|
||||
if not CameraObj then
|
||||
Engine.LogError("Camera object not found!")
|
||||
CameraObj = Engine.GetObjectByTag("Camera")
|
||||
end
|
||||
|
||||
-- move lights
|
||||
-- update light positions
|
||||
for _, obj in ipairs(Objects) do
|
||||
local vel = Velocities[obj]
|
||||
local pos = obj:GetPosition()
|
||||
local pos = CachedPoses[obj]
|
||||
|
||||
local ang = math.atan(vel.y, vel.x)
|
||||
vel.x = math.cos(ang) * Speed
|
||||
@ -74,29 +67,37 @@ function OnUpdate(dt)
|
||||
|
||||
if nx < MinX or nx > MaxX then
|
||||
vel.x = -vel.x
|
||||
nx = clamp(nx, MinX, MaxX)
|
||||
nx = clamp(nx, MinX, MaxX)
|
||||
end
|
||||
if ny < MinY or ny > MaxY then
|
||||
vel.y = -vel.y
|
||||
ny = clamp(ny, MinY, MaxY)
|
||||
ny = clamp(ny, MinY, MaxY)
|
||||
end
|
||||
|
||||
Velocities[obj] = vel
|
||||
obj:SetPosition(Vector2(nx, ny))
|
||||
pos.x = nx
|
||||
pos.y = ny
|
||||
|
||||
local cachedVec = CachedVecs[obj]
|
||||
cachedVec.x = nx
|
||||
cachedVec.y = ny
|
||||
obj:SetPosition(cachedVec)
|
||||
end
|
||||
|
||||
if CameraObj then
|
||||
local camPos = CameraObj:GetPosition()
|
||||
if Engine.KeyDown(Keycode.W) then
|
||||
camPos.y = camPos.y - CamSpeed * dt
|
||||
elseif Engine.KeyDown(Keycode.S) then
|
||||
camPos.y = camPos.y + CamSpeed * dt
|
||||
-- camera movement
|
||||
if not CameraObj then
|
||||
CameraObj = Engine.GetObjectByTag("Camera")
|
||||
if CameraObj then
|
||||
CachedCamPos = CameraObj:GetPosition()
|
||||
else
|
||||
Engine.LogError("Camera object not found!")
|
||||
return
|
||||
end
|
||||
if Engine.KeyDown(Keycode.A) then
|
||||
camPos.x = camPos.x - CamSpeed * dt
|
||||
elseif Engine.KeyDown(Keycode.D) then
|
||||
camPos.x = camPos.x + CamSpeed * dt
|
||||
end
|
||||
CameraObj:SetPosition(Vector2(camPos.x, camPos.y))
|
||||
end
|
||||
|
||||
local moved = false
|
||||
if Engine.KeyDown(Keycode.W) then CachedCamPos.y = CachedCamPos.y - CamSpeed * dt moved = true end
|
||||
if Engine.KeyDown(Keycode.S) then CachedCamPos.y = CachedCamPos.y + CamSpeed * dt moved = true end
|
||||
if Engine.KeyDown(Keycode.A) then CachedCamPos.x = CachedCamPos.x - CamSpeed * dt moved = true end
|
||||
if Engine.KeyDown(Keycode.D) then CachedCamPos.x = CachedCamPos.x + CamSpeed * dt moved = true end
|
||||
if moved then CameraObj:SetPosition(CachedCamPos) end
|
||||
end
|
||||
|
@ -1,27 +1,30 @@
|
||||
#include "Profiler.h"
|
||||
#include <cmath>
|
||||
|
||||
#include "Logging.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
|
||||
extern float g_fps;
|
||||
extern EngineConfig g_engineConfig;
|
||||
|
||||
inline double Lerp(double a, double b, double t) {
|
||||
inline double Lerp(double a, double b, double t)
|
||||
{
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
static void SmoothVisualDurations(ProfileNode& node, double blendFactor) {
|
||||
static void SmoothVisualDurations(ProfileNode &node, double blendFactor)
|
||||
{
|
||||
node.visualStartMs = Lerp(node.visualStartMs, node.startMs, blendFactor);
|
||||
node.visualDurationMs = Lerp(node.visualDurationMs, node.durationMs, blendFactor);
|
||||
for (auto& child : node.children)
|
||||
for (auto &child : node.children)
|
||||
SmoothVisualDurations(child, blendFactor);
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::BeginFrame() {
|
||||
void HierarchicalProfiler::BeginFrame()
|
||||
{
|
||||
if (!g_engineConfig.settings.profile_enabled)
|
||||
return;
|
||||
|
||||
@ -43,22 +46,40 @@ void HierarchicalProfiler::BeginFrame() {
|
||||
ProfilesLastFrame = 0;
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::BeginSection(const std::string& name) {
|
||||
if (!g_engineConfig.settings.profile_enabled)
|
||||
void HierarchicalProfiler::BeginSection(const std::string& name)
|
||||
{
|
||||
if (__builtin_expect(!g_engineConfig.settings.profile_enabled, 0))
|
||||
return;
|
||||
|
||||
auto now = Clock::now();
|
||||
double timeSinceStart = std::chrono::duration<double, std::milli>(now - startTime).count();
|
||||
if (__builtin_expect(currentStack.size() == 0, 0))
|
||||
{
|
||||
static bool warned = false;
|
||||
if (!warned) {
|
||||
Logger::LogWarning("[Profiler] BeginSection called with no active frame (name: %s)", name.c_str());
|
||||
warned = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ProfileNode& parent = *currentStack.back();
|
||||
parent.children.emplace_back(name, timeSinceStart);
|
||||
currentStack.push_back(&parent.children.back());
|
||||
const auto now = Clock::now();
|
||||
const double startMs = std::chrono::duration<double, std::milli>(now - startTime).count();
|
||||
|
||||
ProfileNode* parent = currentStack.back();
|
||||
parent->children.emplace_back(); // Use default ctor, fill manually
|
||||
ProfileNode& child = parent->children.back();
|
||||
|
||||
child.name = name;
|
||||
child.startMs = startMs;
|
||||
|
||||
currentStack.push_back(&child);
|
||||
sectionStartTimes.push_back(now);
|
||||
ProfilesLastFrame++;
|
||||
++ProfilesLastFrame;
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::EndSection() {
|
||||
|
||||
|
||||
void HierarchicalProfiler::EndSection()
|
||||
{
|
||||
if (!g_engineConfig.settings.profile_enabled)
|
||||
return;
|
||||
|
||||
@ -66,7 +87,7 @@ void HierarchicalProfiler::EndSection() {
|
||||
return;
|
||||
|
||||
auto now = Clock::now();
|
||||
ProfileNode& node = *currentStack.back();
|
||||
ProfileNode &node = *currentStack.back();
|
||||
double duration = std::chrono::duration<double, std::milli>(now - sectionStartTimes.back()).count();
|
||||
|
||||
node.durationMs = duration;
|
||||
@ -75,28 +96,32 @@ void HierarchicalProfiler::EndSection() {
|
||||
sectionStartTimes.pop_back();
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::BeginEngineSection(const std::string& name) {
|
||||
void HierarchicalProfiler::BeginEngineSection(const std::string &name)
|
||||
{
|
||||
if (g_engineConfig.settings.profile_enabled && g_engineConfig.settings.profile_editor)
|
||||
BeginSection(name);
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::EndEngineSection() {
|
||||
void HierarchicalProfiler::EndEngineSection()
|
||||
{
|
||||
if (g_engineConfig.settings.profile_enabled && g_engineConfig.settings.profile_editor)
|
||||
EndSection();
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::BeginDeepSection(const std::string& name) {
|
||||
void HierarchicalProfiler::BeginDeepSection(const std::string &name)
|
||||
{
|
||||
if (g_engineConfig.settings.profile_deep)
|
||||
BeginSection(name);
|
||||
}
|
||||
|
||||
void HierarchicalProfiler::EndDeepSection() {
|
||||
void HierarchicalProfiler::EndDeepSection()
|
||||
{
|
||||
if (g_engineConfig.settings.profile_deep)
|
||||
EndSection();
|
||||
}
|
||||
|
||||
|
||||
void HierarchicalProfiler::EndFrame() {
|
||||
void HierarchicalProfiler::EndFrame()
|
||||
{
|
||||
if (!g_engineConfig.settings.profile_enabled)
|
||||
return;
|
||||
|
||||
@ -113,15 +138,18 @@ void HierarchicalProfiler::EndFrame() {
|
||||
frameHistory.erase(frameHistory.begin());
|
||||
}
|
||||
|
||||
const std::vector<ProfileNode>& HierarchicalProfiler::GetFrames() const {
|
||||
const std::vector<ProfileNode> &HierarchicalProfiler::GetFrames() const
|
||||
{
|
||||
return frameHistory;
|
||||
}
|
||||
|
||||
const ProfileNode* HierarchicalProfiler::GetLatestFrame() const {
|
||||
const ProfileNode *HierarchicalProfiler::GetLatestFrame() const
|
||||
{
|
||||
return frameHistory.empty() ? nullptr : &frameHistory.back();
|
||||
}
|
||||
|
||||
json SerializeProfileNode(const ProfileNode& node) {
|
||||
json SerializeProfileNode(const ProfileNode &node)
|
||||
{
|
||||
json j;
|
||||
j["name"] = node.name;
|
||||
j["startMs"] = node.startMs;
|
||||
@ -129,13 +157,11 @@ json SerializeProfileNode(const ProfileNode& node) {
|
||||
j["visualStartMs"] = node.visualStartMs;
|
||||
j["visualDurationMs"] = node.visualDurationMs;
|
||||
|
||||
for (const auto& child : node.children) {
|
||||
for (const auto &child : node.children)
|
||||
{
|
||||
j["children"].push_back(SerializeProfileNode(child));
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HierarchicalProfiler profiler;
|
||||
|
Loading…
Reference in New Issue
Block a user