File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,4 +19,10 @@ void Service::InitService() {
1919}
2020
2121void Service::OnRun () {
22+ }
23+
24+ void Service::GameTick () {
25+ }
26+
27+ void Service::RenderTick () {
2228}
Original file line number Diff line number Diff line change @@ -14,5 +14,10 @@ class Service : public Instance {
1414
1515 void OnParentUpdated (nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) override ;
1616
17+ // Called while the game is running
18+ virtual void GameTick ();
19+ // Called every tick always
20+ virtual void RenderTick ();
21+
1722 friend class DataModel ;
1823};
Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ void DataModel::Init(bool runMode) {
5353 if (auto service = FindService<ServerScriptService>()) service->OnRun ();
5454}
5555
56+ void DataModel::TickServices (bool running) {
57+ for (auto && [_, service] : this ->services ) {
58+ service->RenderTick ();
59+ if (running)
60+ service->GameTick ();
61+ }
62+ }
63+
5664void DataModel::SaveToFile (std::optional<std::string> path) {
5765 if (!path.has_value () && !this ->currentFile .has_value ()) {
5866 Logger::fatalError (" Cannot save DataModel because no path was provided." );
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ class DataModel : public Instance {
2727 ~DataModel ();
2828 void Init (bool runMode = false );
2929
30+ void TickServices (bool running);
31+
3032 static inline std::shared_ptr<DataModel> New () { return new_instance<DataModel>(); };
3133
3234 result<std::shared_ptr<Service>, NoSuchService> GetService (std::string className);
Original file line number Diff line number Diff line change 55#include " objectmodel/type.h"
66#include " objects/datamodel.h"
77#include " objects/service/workspace.h"
8+ #include " objects/part/basepart.h"
89
910INSTANCE_IMPL (CameraController)
1011
@@ -17,6 +18,23 @@ void CameraController::InitService() {
1718 initialized = true ;
1819}
1920
21+ // This probably should be handled by Camera itself using a signal listener
22+ // Or should it? I don't know
23+ void CameraController::RenderTick () {
24+ auto cameraw = dataModel ()->GetService <Workspace>()->currentCamera ;
25+ if (cameraw.expired ()) return ;
26+ auto camera = cameraw.lock ();
27+
28+ if (!camera->cameraSubject .expired ()) {
29+ auto subject = camera->cameraSubject .lock ();
30+ if (subject->IsA <BasePart>()) {
31+ camera->focus = std::dynamic_pointer_cast<BasePart>(subject)->cframe ;
32+ }
33+ }
34+
35+ camera->UpdateView ();
36+ }
37+
2038void CameraController::InputMovement (Direction direction, float deltaTime) {
2139 auto workspace = dataModel ()->GetService <Workspace>();
2240 auto camera = workspace->GetCamera ();
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ class CameraController : public Service {
1919protected:
2020 void InitService () override ;
2121 bool initialized = false ;
22+
23+ void RenderTick () override ;
2224public:
2325 static inline std::shared_ptr<Instance> Create () { return new_instance<CameraController>(); };
2426
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ void PlaceDocument::timerEvent(QTimerEvent* evt) {
9595
9696 placeWidget->repaint ();
9797 placeWidget->updateCycle ();
98+ gDataModel ->TickServices (_runState == RUN_RUNNING );
9899 if (_runState != RUN_RUNNING ) return ;
99100 gDataModel ->GetService <ScriptContext>()->RunSleepingThreads ();
100101 gDataModel ->GetService <Workspace>()->PhysicsStep (0.033 );
You can’t perform that action at this time.
0 commit comments