LCOV - code coverage report
Current view: top level - xenolith/scene/director - XLDirector.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 9 100.0 %
Date: 2024-05-12 00:16:13 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2020-2022 Roman Katuntsev <sbkarr@stappler.org>
       3             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       6             :  of this software and associated documentation files (the "Software"), to deal
       7             :  in the Software without restriction, including without limitation the rights
       8             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             :  copies of the Software, and to permit persons to whom the Software is
      10             :  furnished to do so, subject to the following conditions:
      11             : 
      12             :  The above copyright notice and this permission notice shall be included in
      13             :  all copies or substantial portions of the Software.
      14             : 
      15             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             :  THE SOFTWARE.
      22             :  **/
      23             : 
      24             : #ifndef XENOLITH_SCENE_DIRECTOR_XLDIRECTOR_H_
      25             : #define XENOLITH_SCENE_DIRECTOR_XLDIRECTOR_H_
      26             : 
      27             : #include "XLResourceCache.h"
      28             : #include "XLApplication.h"
      29             : #include "XLCoreFrameEmitter.h"
      30             : #include "XLInput.h"
      31             : #include "SPMovingAverage.h"
      32             : 
      33             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      34             : 
      35             : class Scene;
      36             : class Scheduler;
      37             : class InputDispatcher;
      38             : class TextInputManager;
      39             : class ActionManager;
      40             : class View;
      41             : 
      42             : class Director : public Ref {
      43             : public:
      44             :         using FrameRequest = core::FrameRequest;
      45             : 
      46             :         virtual ~Director();
      47             : 
      48             :         Director();
      49             : 
      50             :         bool init(Application *, const core::FrameContraints &, View *view);
      51             : 
      52             :         void setFrameConstraints(const core::FrameContraints &);
      53             : 
      54             :         void runScene(Rc<Scene> &&);
      55             : 
      56             :         bool acquireFrame(const Rc<FrameRequest> &);
      57             : 
      58             :         void update(uint64_t t);
      59             : 
      60             :         void end();
      61             : 
      62        6595 :         Application *getApplication() const { return _mainLoop; }
      63             :         core::Loop *getGlLoop() const;
      64         332 :         View *getView() const { return _view; }
      65             : 
      66      174866 :         Scheduler *getScheduler() const { return _scheduler; }
      67      172558 :         ActionManager *getActionManager() const { return _actionManager; }
      68       14698 :         InputDispatcher *getInputDispatcher() const { return _inputDispatcher; }
      69             :         TextInputManager *getTextInputManager() const;
      70             : 
      71             :         const Rc<Scene> &getScene() const { return _scene; }
      72             :         const Rc<ResourceCache> &getResourceCache() const;
      73        9538 :         const Mat4 &getGeneralProjection() const { return _generalProjection; }
      74             : 
      75           2 :         const core::FrameContraints & getFrameConstraints() const { return _constraints; }
      76             : 
      77             :         void pushDrawStat(const DrawStat &);
      78             : 
      79        4650 :         const DrawStat &getDrawStat() const { return _drawStat; }
      80             : 
      81             :         float getFps() const;
      82             :         float getAvgFps() const;
      83             :         float getSpf() const; // in milliseconds
      84             :         float getLocalFrameTime() const; // in milliseconds
      85             : 
      86        4650 :         float getDirectorFrameTime() const { return _avgFrameTimeValue / 1000.0f; }
      87             : 
      88             :         void autorelease(Ref *);
      89             : 
      90             : protected:
      91             :         // Vk Swaphain was invalidated, drop all dependent resources;
      92             :         void invalidate();
      93             : 
      94             :         void updateGeneralTransform();
      95             : 
      96             :         bool hasActiveInteractions();
      97             : 
      98             :         Rc<Application> _mainLoop;
      99             :         View *_view = nullptr;
     100             : 
     101             :         core::FrameContraints _constraints;
     102             : 
     103             :         uint64_t _startTime = 0;
     104             :         UpdateTime _time;
     105             :         DrawStat _drawStat;
     106             : 
     107             :         Rc<Scene> _scene;
     108             :         Rc<Scene> _nextScene;
     109             : 
     110             :         Mat4 _generalProjection;
     111             : 
     112             :         Rc<PoolRef> _pool;
     113             :         Rc<Scheduler> _scheduler;
     114             :         Rc<ActionManager> _actionManager;
     115             :         Rc<InputDispatcher> _inputDispatcher;
     116             : 
     117             :         Vector<Rc<Ref>> _autorelease;
     118             : 
     119             :         math::MovingAverage<20, uint64_t> _avgFrameTime;
     120             :         uint64_t _avgFrameTimeValue = 0;
     121             : };
     122             : 
     123             : }
     124             : 
     125             : #endif /* XENOLITH_SCENE_DIRECTOR_XLDIRECTOR_H_ */

Generated by: LCOV version 1.14