Path: blob/master/modules/jolt_physics/jolt_globals.cpp
10277 views
/**************************************************************************/1/* jolt_globals.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 "jolt_globals.h"3132#include "objects/jolt_group_filter.h"33#include "shapes/jolt_custom_double_sided_shape.h"34#include "shapes/jolt_custom_ray_shape.h"35#include "shapes/jolt_custom_user_data_shape.h"3637#include "core/os/memory.h"38#include "core/string/print_string.h"3940#include "Jolt/Jolt.h"4142#include "Jolt/RegisterTypes.h"4344#include <cstdarg>4546void *jolt_alloc(size_t p_size) {47return Memory::alloc_static(p_size);48}4950void *jolt_realloc(void *p_mem, size_t p_old_size, size_t p_new_size) {51return Memory::realloc_static(p_mem, p_new_size);52}5354void jolt_free(void *p_mem) {55Memory::free_static(p_mem);56}5758void *jolt_aligned_alloc(size_t p_size, size_t p_alignment) {59return Memory::alloc_aligned_static(p_size, p_alignment);60}6162void jolt_aligned_free(void *p_mem) {63Memory::free_aligned_static(p_mem);64}6566#ifdef JPH_ENABLE_ASSERTS6768void jolt_trace(const char *p_format, ...) {69va_list args;70va_start(args, p_format);71char buffer[1024] = { '\0' };72vsnprintf(buffer, sizeof(buffer), p_format, args);73va_end(args);74print_verbose(buffer);75}7677bool jolt_assert(const char *p_expr, const char *p_msg, const char *p_file, uint32_t p_line) {78ERR_PRINT(vformat("Jolt Physics assertion '%s' failed with message '%s' at '%s:%d'", p_expr, p_msg != nullptr ? p_msg : "", p_file, p_line));79return false;80}8182#endif8384void jolt_initialize() {85JPH::Allocate = &jolt_alloc;86JPH::Reallocate = &jolt_realloc;87JPH::Free = &jolt_free;88JPH::AlignedAllocate = &jolt_aligned_alloc;89JPH::AlignedFree = &jolt_aligned_free;9091#ifdef JPH_ENABLE_ASSERTS92JPH::Trace = &jolt_trace;93JPH::AssertFailed = &jolt_assert;94#endif9596JPH::Factory::sInstance = new JPH::Factory();9798JPH::RegisterTypes();99100JoltCustomRayShape::register_type();101JoltCustomUserDataShape::register_type();102JoltCustomDoubleSidedShape::register_type();103104JoltGroupFilter::instance = new JoltGroupFilter();105JoltGroupFilter::instance->SetEmbedded();106}107108void jolt_deinitialize() {109if (JoltGroupFilter::instance != nullptr) {110delete JoltGroupFilter::instance;111JoltGroupFilter::instance = nullptr;112}113114JPH::UnregisterTypes();115116if (JPH::Factory::sInstance != nullptr) {117delete JPH::Factory::sInstance;118JPH::Factory::sInstance = nullptr;119}120}121122123