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