Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Simulated.h
1// trax track library
2// AD 2025
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "Units.h"
30
31
32namespace trax{
33
34 struct Scene;
35
38 struct Simulated
39 {
44 virtual bool Start( Scene& scene ) = 0;
45
46
55 virtual void Idle() = 0;
56
57
61 virtual void Update( Time dt = fixed_timestep ) = 0;
62
63
65 virtual void Pause() noexcept = 0;
66
67
70 virtual void Resume() noexcept = 0;
71
72
74 virtual void Stop() noexcept = 0;
75
76
77 virtual ~Simulated() = default;
78 };
79
80
81 template<class BaseDecorator>
82 class SimulatedDecorator : public BaseDecorator{
83 protected:
84 using BaseDecorator::m_pComponent;
85 public:
87 typedef typename BaseDecorator::InterfaceType InterfaceType;
88
91 SimulatedDecorator( std::shared_ptr<InterfaceType> pComponent )
92 : BaseDecorator{ pComponent }
93 {}
94
95 bool Start( Scene& scene ) override{
96 return m_pComponent->Start( scene );
97 }
98
99 void Idle() override{
100 return m_pComponent->Idle();
101 }
102
103 void Update( Time dt ) override{
104 m_pComponent->Update( dt );
105 }
106
107 void Pause() noexcept override{
108 m_pComponent->Pause();
109 }
110
111 void Resume() noexcept override{
112 m_pComponent->Resume();
113 }
114
115 void Stop() noexcept override{
116 m_pComponent->Stop();
117 }
118 };
119}
SimulatedDecorator(std::shared_ptr< InterfaceType > pComponent)
Decorator constructor.
Definition Simulated.h:91
BaseDecorator::InterfaceType InterfaceType
Type of the interface the decorator is decorating.
Definition Simulated.h:87
Value< Dimension< 0, 0, 1 > > Time
Time.
Definition DimensionedValues.h:329
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
constexpr Time fixed_timestep
The fixed timestep to use with the simulation.
Definition Units.h:136
A physical simulation scene for running a simulation and creating physical objects in the scene.
Definition Scene.h:72
A simulated object. Register the object with a scene to get called back for Update,...
Definition Simulated.h:39
virtual void Update(Time dt=fixed_timestep)=0
Called to update the simulated object after the simuation step finishes.
virtual bool Start(Scene &scene)=0
Called if the simulation is started.
virtual void Resume() noexcept=0
Called if the simulation is resumed after pause.
virtual void Stop() noexcept=0
Called if the simulation is stopped.
virtual void Idle()=0
Called during the simulation calculations, to perform tasks foreign to the physical simulation.
virtual void Pause() noexcept=0
Called if the simulation is paused.