Skip to content

Commit d8f64f5

Browse files
committed
Add ToolUpdate support for editor/toolmode updates for physics merged colliders debug display
1 parent 965ee32 commit d8f64f5

26 files changed

Lines changed: 352 additions & 100 deletions

File tree

‎projects/game/src/Game.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ void Game::FixedUpdate(float _dt)
206206
}
207207
}
208208

209+
//--------------------------------------------------------------------------------------
210+
void Game::Update(float _dt)
211+
{
212+
213+
}
214+
215+
//--------------------------------------------------------------------------------------
216+
void Game::LateUpdate(float _dt)
217+
{
218+
219+
}
220+
221+
//--------------------------------------------------------------------------------------
222+
void Game::ToolUpdate(float _dt)
223+
{
224+
225+
}
226+
209227
//--------------------------------------------------------------------------------------
210228
vg::engine::IEngine & Game::Engine()
211229
{

‎projects/game/src/Game.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Game : public vg::IGame, public vg::core::Singleton<Game>
4242
void OnStop () final override;
4343

4444
void FixedUpdate (float _dt) final override;
45+
void Update (float _dt) final override;
46+
void LateUpdate (float _dt) final override;
47+
void ToolUpdate (float _dt) final override;
4548

4649
static vg::engine::IEngine & Engine ();
4750
static vg::core::IInput & Input ();

‎src/core/Component/Component.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ namespace vg::core
7373
VG_ASSERT(false, "Component \"%s\" from GameObject \"%s\" should implement 'LateUpdate'", GetClassName(), _context.m_gameObject->GetName().c_str());
7474
}
7575

76+
//--------------------------------------------------------------------------------------
77+
void Component::ToolUpdate(const Context & _context)
78+
{
79+
80+
}
81+
7682
//--------------------------------------------------------------------------------------
7783
const IGameObject * Component::GetGameObject() const
7884
{

‎src/core/Component/Component.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace vg::core
2323
void FixedUpdate (const Context & _context) override;
2424
void Update (const Context & _context) override;
2525
void LateUpdate (const Context & _context) override;
26+
void ToolUpdate (const Context & _context) override;
2627

2728
const IGameObject * GetGameObject () const final override;
2829
IGameObject * GetGameObject () final override;

‎src/core/GameObject/GameObject.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,36 @@ namespace vg::core
447447
}
448448
}
449449

450+
//--------------------------------------------------------------------------------------
451+
void GameObject::ToolUpdate(const Context & _context)
452+
{
453+
if (asBool(InstanceFlags::Enabled & getInstanceFlags()))
454+
{
455+
VG_PROFILE_CPU(GetName().c_str());
456+
VG_ASSERT(asBool(UpdateFlags::ToolUpdate & getUpdateFlags()), "[ToolUpdate] GameObject \"%s\" does not have the '%s' flag", GetName().c_str(), asString(UpdateFlags::LateUpdate).c_str());
457+
458+
ComponentUpdateContext componentUpdateContext(_context, this);
459+
460+
for (uint i = 0; i < m_components.size(); ++i)
461+
{
462+
Component * component = m_components[i];
463+
if (asBool(ComponentFlags::Enabled & component->getComponentFlags()) && asBool(UpdateFlags::ToolUpdate & component->getUpdateFlags()))
464+
{
465+
VG_PROFILE_CPU(component->GetClassName());
466+
component->ToolUpdate(componentUpdateContext);
467+
}
468+
}
469+
470+
const auto & children = getChildren();
471+
for (uint e = 0; e < children.size(); ++e)
472+
{
473+
auto * child = children[e];
474+
if (asBool(InstanceFlags::Enabled & child->getInstanceFlags()) && asBool(UpdateFlags::ToolUpdate & child->getUpdateFlags()))
475+
child->ToolUpdate(componentUpdateContext);
476+
}
477+
}
478+
}
479+
450480
//--------------------------------------------------------------------------------------
451481
void GameObject::AddComponent(IComponent * _component, core::uint _index)
452482
{

‎src/core/GameObject/GameObject.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace vg::core
6161
void FixedUpdate (const Context & _context);
6262
void Update (const Context & _context);
6363
void LateUpdate (const Context & _context);
64+
void ToolUpdate (const Context & _context);
6465

6566
const core::vector<IBehaviour*> /*&*/ getBehaviours () const;
6667

‎src/core/IComponent.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace vg::core
2424
virtual void FixedUpdate (const Context & _context) = 0;
2525
virtual void Update (const Context & _context) = 0;
2626
virtual void LateUpdate (const Context & _context) = 0;
27+
virtual void ToolUpdate (const Context & _context) = 0;
2728

2829
virtual const IGameObject * GetGameObject () const = 0;
2930
virtual IGameObject * GetGameObject () = 0;

‎src/core/IPlugin.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace vg::core
2121
virtual void FixedUpdate (float _dt) {}
2222
virtual void Update (float _dt) {}
2323
virtual void LateUpdate (float _dt) {}
24+
virtual void ToolUpdate (float _dt) {}
2425

2526
virtual void CreateResources () {};
2627
virtual void ReleaseResources () {};

‎src/core/Object/Update.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace vg::core
88
vg_enum_class(vg::core, UpdateFlags, u8,
99
FixedUpdate = 0x01, // 'FixedUpdate' should be used for physics-based calculations such as applying forces to Rigidbodies or any other calculations needing to be framerate independent
1010
Update = 0x02, // 'Update' will be called once per frame
11-
LateUpdate = 0x04 // 'LateUpdate' will also be called once per frame, after all other 'Updates' and should be used to e.g., animate model bones for lookup
11+
LateUpdate = 0x04, // 'LateUpdate' will also be called once per frame, after all other 'Updates' and should be used to e.g., animate model bones for lookup
12+
ToolUpdate = 0x08 // 'ToolUpdate' is used for editor/toolmode debug display and is only executed when the world has at least one toolmode view visible
1213
);
1314

1415
class IWorld;

‎src/engine/Component/Physics/Object/Body/PhysicsBodyComponent.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace vg::engine
2323
~PhysicsBodyComponent();
2424

2525
void Update (const Context & _context) final override;
26+
void ToolUpdate (const Context & _context) final override;
27+
2628
void OnEnable () final override;
2729
void OnDisable () final override;
2830
void OnLoad () final override;
@@ -45,6 +47,8 @@ namespace vg::engine
4547

4648
void SetAngularVelocity (const core::float3 & _velocity) final override;
4749
const core::float3 & GetAngularVelocity () const final override;
50+
51+
bool CanStaticMerge () const final override;
4852

4953
void onShapeUpdated ();
5054
void updateShapesColor ();

0 commit comments

Comments
 (0)