LCOV - code coverage report
Current view: top level - xenolith/core - XLCore.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 30 100.0 %
Date: 2024-05-12 00:16:13 Functions: 17 20 85.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_CORE_XLCORE_H_
      24             : #define XENOLITH_CORE_XLCORE_H_
      25             : 
      26             : #include "SPCommon.h"
      27             : #include "SPMemory.h"
      28             : #include "SPFilesystem.h"
      29             : #include "SPThreadTask.h"
      30             : #include "SPSpanView.h"
      31             : #include "SPLog.h"
      32             : #include "SPHashTable.h"
      33             : 
      34             : #include "SPVec2.h"
      35             : #include "SPVec3.h"
      36             : #include "SPVec4.h"
      37             : #include "SPGeometry.h"
      38             : #include "SPQuaternion.h"
      39             : #include "SPMat4.h"
      40             : #include "SPPadding.h"
      41             : #include "SPColor.h"
      42             : #include "SPColorHCT.h"
      43             : #include "SPFontStyle.h"
      44             : 
      45             : #include <typeindex>
      46             : #include <forward_list>
      47             : #include <optional>
      48             : 
      49             : #include "XLCoreConfig.h"
      50             : 
      51             : #define XL_ASSERT(cond, msg)  do { if (!(cond)) { stappler::log::text(stappler::log::LogType::Fatal, "Assert", msg); } assert((cond)); } while (0)
      52             : 
      53             : #ifndef XLASSERT
      54             : #if DEBUG
      55             : #define XLASSERT(cond, msg) XL_ASSERT(cond, msg)
      56             : #else
      57             : #define XLASSERT(cond, msg)
      58             : #endif
      59             : #endif
      60             : 
      61             : #if __CDT_PARSER__
      62             : // IDE-specific definition
      63             : 
      64             : // enable all modules
      65             : 
      66             : #define MODULE_XENOLITH_CORE 1
      67             : #define MODULE_XENOLITH_APPLICATION 1
      68             : #define MODULE_XENOLITH_FONT 1
      69             : #define MODULE_XENOLITH_PLATFORM 1
      70             : #define MODULE_XENOLITH_SCENE 1
      71             : #define MODULE_XENOLITH_BACKEND_VK 1
      72             : #define MODULE_XENOLITH_BACKEND_VKGUI 1
      73             : #define MODULE_XENOLITH_RENDERER_BASIC2D 1
      74             : #define MODULE_XENOLITH_RESOURCES_NETWORK 1
      75             : #define MODULE_XENOLITH_RESOURCES_ASSETS 1
      76             : #define MODULE_XENOLITH_RESOURCES_STORAGE 1
      77             : 
      78             : #endif
      79             : 
      80             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      81             : 
      82             : // Import std memory model as default
      83             : using namespace mem_std;
      84             : 
      85             : using geom::Vec2;
      86             : using geom::Vec3;
      87             : using geom::Vec4;
      88             : using geom::Mat4;
      89             : using geom::Size2;
      90             : using geom::Size3;
      91             : using geom::Extent2;
      92             : using geom::Extent3;
      93             : using geom::Rect;
      94             : using geom::URect;
      95             : using geom::UVec2;
      96             : using geom::UVec3;
      97             : using geom::UVec4;
      98             : using geom::Quaternion;
      99             : using geom::Color;
     100             : using geom::Color3B;
     101             : using geom::Color4B;
     102             : using geom::Color4F;
     103             : using geom::ColorHCT;
     104             : using geom::ColorMask;
     105             : using geom::Padding;
     106             : namespace Anchor = geom::Anchor;
     107             : 
     108         110 : inline uint32_t XL_MAKE_API_VERSION(uint32_t variant, uint32_t major, uint32_t minor, uint32_t patch) {
     109         110 :    return (uint32_t(variant) << 29) | (uint32_t(major) << 22) | (uint32_t(minor) << 12) | uint32_t(patch);
     110             : }
     111             : 
     112             : // based on VK_MAKE_API_VERSION
     113          90 : inline uint32_t XL_MAKE_API_VERSION(StringView version) {
     114             :         uint32_t ver[4];
     115          90 :         uint32_t i = 0;
     116          90 :         version.split<StringView::Chars<'.'>>([&] (StringView str) {
     117         220 :                 if (i < 4) {
     118         220 :                         ver[i++] = str.readInteger(10).get(0);
     119             :                 }
     120         220 :         });
     121             : 
     122          90 :         uint32_t verCode = 0;
     123          90 :         switch (i) {
     124          10 :         case 0: verCode = XL_MAKE_API_VERSION(0, 0, 1, 0); break;
     125          10 :         case 1: verCode = XL_MAKE_API_VERSION(0, ver[0], 0, 0); break;
     126          10 :         case 2: verCode = XL_MAKE_API_VERSION(0, ver[0], ver[1], 0); break;
     127          50 :         case 3: verCode = XL_MAKE_API_VERSION(0, ver[0], ver[1], ver[2]); break;
     128          10 :         case 4: verCode = XL_MAKE_API_VERSION(ver[0], ver[1], ver[2], ver[3]); break;
     129             :         }
     130          90 :         return verCode;
     131             : }
     132             : 
     133        1974 : inline String getVersionDescription(uint32_t version) {
     134        3948 :         return toString(version >> 29, ".", version >> 22, ".", (version >> 12) & 0b1111111111, ".", version & 0b111111111111);
     135             : }
     136             : 
     137             : class PoolRef : public Ref {
     138             : public:
     139       35760 :         virtual ~PoolRef() {
     140       17895 :                 memory::pool::destroy(_pool);
     141       35760 :         }
     142             : 
     143       17895 :         PoolRef(memory::pool_t *root = nullptr) {
     144       17895 :                 _pool = memory::pool::create(root);
     145       17895 :         }
     146             : 
     147          63 :         PoolRef(PoolRef *p) : PoolRef(p->_pool) { }
     148             : 
     149      333862 :         memory::pool_t *getPool() const { return _pool; }
     150             : 
     151             :         void *palloc(size_t size) {
     152             :                 return memory::pool::palloc(_pool, size);
     153             :         }
     154             : 
     155             :         template <typename Callable>
     156      177641 :         auto perform(const Callable &cb) {
     157      177641 :                 memory::pool::context<memory::pool_t *> ctx(_pool);
     158      355282 :                 return cb();
     159      177641 :         }
     160             : 
     161             : protected:
     162             :         memory::pool_t *_pool = nullptr;
     163             : };
     164             : 
     165             : }
     166             : 
     167             : namespace STAPPLER_VERSIONIZED stappler::xenolith::profiling {
     168             : 
     169             : struct ProfileData {
     170             :         uint64_t timestamp;
     171             :         StringView tag;
     172             :         StringView variant;
     173             :         uint64_t limit;
     174             : };
     175             : 
     176             : ProfileData begin(StringView tag, StringView variant, uint64_t limit);
     177             : 
     178             : void end(ProfileData &);
     179             : void store(ProfileData &);
     180             : 
     181             : #define XL_PROFILE_DEBUG 0
     182             : 
     183             : #if XL_PROFILE_DEBUG
     184             : #define XL_PROFILE_BEGIN(name, tag, variant, limit) \
     185             :         auto __xl_profile__ ## name = stappler::xenolith::profiling::begin(tag, variant, limit);
     186             : 
     187             : #define XL_PROFILE_END(name) \
     188             :         stappler::xenolith::profiling::end(__xl_profile__ ## name);
     189             : #else
     190             : #define XL_PROFILE_BEGIN(name, tag, variant, limit)
     191             : #define XL_PROFILE_END(name)
     192             : #endif
     193             : 
     194             : }
     195             : 
     196             : #include "XLCoreEnum.h"
     197             : #include "XLCorePipelineInfo.h"
     198             : 
     199             : #endif /* XENOLITH_CORE_XLCORE_H_ */

Generated by: LCOV version 1.14