/**************************************************************************/1/* variant_pools.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "core/variant/variant_pools.h"3132#include "core/math/aabb.h"33#include "core/math/projection.h"34#include "core/math/transform_2d.h"35#include "core/math/transform_3d.h"36#include "core/templates/paged_allocator.h"3738namespace VariantPools {39union BucketSmall {40BucketSmall() {}41~BucketSmall() {}42Transform2D _transform2d;43::AABB _aabb;44};45static_assert(sizeof(BucketSmall) == VariantPools::BUCKET_SMALL);46static_assert(alignof(BucketSmall) == alignof(real_t));4748union BucketMedium {49BucketMedium() {}50~BucketMedium() {}51Basis _basis;52Transform3D _transform3d;53};54static_assert(sizeof(BucketMedium) == VariantPools::BUCKET_MEDIUM);55static_assert(alignof(BucketMedium) == alignof(real_t));5657union BucketLarge {58BucketLarge() {}59~BucketLarge() {}60Projection _projection;61};62static_assert(sizeof(BucketLarge) == VariantPools::BUCKET_LARGE);63static_assert(alignof(BucketLarge) == alignof(real_t));64} //namespace VariantPools6566static PagedAllocator<VariantPools::BucketSmall, true> _bucket_small;67static PagedAllocator<VariantPools::BucketMedium, true> _bucket_medium;68static PagedAllocator<VariantPools::BucketLarge, true> _bucket_large;6970void *VariantPools::alloc_small() {71return _bucket_small.alloc();72}7374void *VariantPools::alloc_medium() {75return _bucket_medium.alloc();76}7778void *VariantPools::alloc_large() {79return _bucket_large.alloc();80}8182void VariantPools::free_small(void *p_ptr) {83_bucket_small.free(static_cast<BucketSmall *>(p_ptr));84}8586void VariantPools::free_medium(void *p_ptr) {87_bucket_medium.free(static_cast<BucketMedium *>(p_ptr));88}8990void VariantPools::free_large(void *p_ptr) {91_bucket_large.free(static_cast<BucketLarge *>(p_ptr));92}939495