LCOV - code coverage report
Current view: top level - xenolith/scene/nodes - XLComponent.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 53 53 100.0 %
Date: 2024-05-12 00:16:13 Functions: 21 21 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2021 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             : #include "XLComponent.h"
      25             : #include "XLScene.h"
      26             : #include "XLScheduler.h"
      27             : 
      28             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      29             : 
      30          42 : uint64_t Component::GetNextComponentId() {
      31             :         static std::atomic<uint64_t> s_value = 1;
      32          42 :         return s_value.fetch_add(1);
      33             : }
      34             : 
      35        5695 : Component::Component()
      36        5695 : : _owner(nullptr), _enabled(true) { }
      37             : 
      38        5821 : Component::~Component() { }
      39             : 
      40        5695 : bool Component::init() {
      41        5695 :         return true;
      42             : }
      43             : 
      44        5695 : void Component::onAdded(Node *owner) {
      45        5695 :         _owner = owner;
      46        5695 : }
      47        1680 : void Component::onRemoved() {
      48        1680 :         _owner = nullptr;
      49        1680 : }
      50             : 
      51        5590 : void Component::onEnter(Scene *sc) {
      52        5590 :         _running = true;
      53        5590 :         if (_scheduled) {
      54          21 :                 sc->getDirector()->getScheduler()->scheduleUpdate(this, 0, false);
      55             :         }
      56        5590 : }
      57             : 
      58        5590 : void Component::onExit() {
      59        5590 :         if (_scheduled) {
      60          21 :                 unscheduleUpdate();
      61          21 :                 _scheduled = true; // -re-enable after restart;
      62             :         }
      63        5590 :         _running = false;
      64        5590 : }
      65             : 
      66      185199 : void Component::visit(FrameInfo &, NodeFlags parentFlags) { }
      67             : 
      68          21 : void Component::update(const UpdateTime &time) { }
      69             : 
      70        9743 : void Component::onContentSizeDirty() { }
      71        9283 : void Component::onTransformDirty(const Mat4 &) { }
      72        4871 : void Component::onReorderChildDirty() { }
      73             : 
      74        1554 : bool Component::isRunning() const {
      75        1554 :         return _running;
      76             : }
      77             : 
      78      370273 : bool Component::isEnabled() const {
      79      370273 :         return _enabled;
      80             : }
      81             : 
      82          21 : void Component::setEnabled(bool b) {
      83          21 :         _enabled = b;
      84          21 : }
      85             : 
      86        1554 : bool Component::isScheduled() const {
      87        1554 :         return _scheduled;
      88             : }
      89             : 
      90         798 : void Component::scheduleUpdate() {
      91         798 :         if (!_scheduled) {
      92         798 :                 _scheduled = true;
      93         798 :                 if (_running) {
      94         777 :                         _owner->getScheduler()->scheduleUpdate(this, 0, false);
      95             :                 }
      96             :         }
      97         798 : }
      98             : 
      99         798 : void Component::unscheduleUpdate() {
     100         798 :         if (_scheduled) {
     101         798 :                 if (_running) {
     102         798 :                         _owner->getScheduler()->unschedule(this);
     103             :                 }
     104         798 :                 _scheduled = false;
     105             :         }
     106         798 : }
     107             : 
     108        1929 : void Component::setFrameTag(uint64_t tag) {
     109        1929 :         _frameTag = tag;
     110        1929 : }
     111             : 
     112             : }

Generated by: LCOV version 1.14