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 : #ifndef XENOLITH_SCENE_DIRECTOR_XLFRAMEINFO_H_ 25 : #define XENOLITH_SCENE_DIRECTOR_XLFRAMEINFO_H_ 26 : 27 : #include "XLFrameContext.h" 28 : #include "XLComponent.h" 29 : 30 : namespace STAPPLER_VERSIONIZED stappler::xenolith { 31 : 32 : class InputListenerStorage; 33 : class Director; 34 : 35 : struct FrameInfo; 36 : struct FrameContextHandle; 37 : 38 : struct FrameInfo { 39 : Rc<PoolRef> pool; 40 : 41 : Rc<core::FrameRequest> request; 42 : Rc<Director> director; 43 : Rc<Scene> scene; 44 : Rc<InputListenerStorage> input; 45 : 46 : memory::vector<ZOrder> zPath; 47 : memory::vector<Mat4> viewProjectionStack; 48 : memory::vector<Mat4> modelTransformStack; 49 : memory::vector<float> depthStack; 50 : memory::vector<Rc<FrameContextHandle>> contextStack; 51 : memory::map<uint64_t, memory::vector<Rc<Component>>> componentsStack; 52 : memory::set<const core::AttachmentData *> resolvedInputs; 53 : 54 : uint32_t focusValue = 0; 55 : 56 : FrameContextHandle *currentContext = nullptr; 57 : 58 112920 : memory::vector<Rc<Component>> * pushComponent(const Rc<Component> &comp) { 59 112920 : auto it = componentsStack.find(comp->getFrameTag()); 60 112920 : if (it == componentsStack.end()) { 61 19076 : it = componentsStack.emplace(comp->getFrameTag()).first; 62 : } 63 112920 : it->second.emplace_back(comp); 64 112920 : return &it->second; 65 : } 66 : 67 112920 : void popComponent(memory::vector<Rc<Component>> *vec) { 68 112920 : vec->pop_back(); 69 112920 : } 70 : 71 : template<typename T = Component> 72 88972 : auto getComponent(uint64_t tag) const -> Rc<T> { 73 88972 : auto it = componentsStack.find(tag); 74 88972 : if (it != componentsStack.end() && !it->second.empty()) { 75 88972 : return it->second.back().cast<T>(); 76 : } 77 0 : return nullptr; 78 : } 79 : 80 9538 : void pushContext(FrameContext *ctx) { 81 9538 : auto h = ctx->makeHandle(*this); 82 : 83 9538 : currentContext = contextStack.emplace_back(move(h)); 84 9538 : } 85 : 86 9538 : void popContext() { 87 9538 : currentContext->context->submitHandle(*this, currentContext); 88 9538 : contextStack.pop_back(); 89 9538 : if (contextStack.empty()) { 90 9538 : currentContext = nullptr; 91 : } else { 92 0 : currentContext = contextStack.back(); 93 : } 94 9538 : } 95 : }; 96 : 97 : } 98 : 99 : #endif /* XENOLITH_SCENE_DIRECTOR_XLFRAMEINFO_H_ */