1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef API_CORE_ECS_ENTITY_H 17 #define API_CORE_ECS_ENTITY_H 18 19 #include <cstdint> 20 21 #include <base/namespace.h> 22 #include <core/namespace.h> 23 24 CORE_BEGIN_NAMESPACE() 25 /** \addtogroup group_ecs_entity 26 * @{ 27 */ 28 /** Invalid entity value */ 29 constexpr const uint32_t INVALID_ENTITY = ~0u; 30 31 /** Entity struct which holds the id 32 high 32 bits is generation. 33 low 32 bits is id. 34 */ 35 struct Entity { 36 /** ID */ 37 uint64_t id { INVALID_ENTITY }; 38 }; 39 40 inline bool operator==(Entity const& lhs, Entity const& rhs) 41 { 42 return lhs.id == rhs.id; 43 } 44 45 inline bool operator!=(Entity const& lhs, Entity const& rhs) 46 { 47 return lhs.id != rhs.id; 48 } 49 50 /** Entity util for checking entities validity */ 51 namespace EntityUtil { 52 /** Returns true if entity is valid */ IsValid(const Entity entity)53inline bool IsValid(const Entity entity) 54 { 55 return entity != Entity {}; 56 } 57 } // namespace EntityUtil 58 /** @} */ 59 60 CORE_END_NAMESPACE() 61 62 BASE_BEGIN_NAMESPACE() 63 template<typename T> 64 uint64_t hash(const T& b); 65 66 template<> hash(const CORE_NS::Entity & b)67inline uint64_t hash(const CORE_NS::Entity& b) 68 { 69 return b.id; 70 } 71 BASE_END_NAMESPACE() 72 73 #endif // API_CORE_ECS_ENTITY_H 74