Initial commit

This commit is contained in:
Martin Felis
2021-11-11 21:22:24 +01:00
commit b78045ffe7
812 changed files with 421882 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
add_library(ozz_base STATIC
${PROJECT_SOURCE_DIR}/include/ozz/base/endianness.h
${PROJECT_SOURCE_DIR}/include/ozz/base/gtest_helper.h
${PROJECT_SOURCE_DIR}/include/ozz/base/memory/allocator.h
${PROJECT_SOURCE_DIR}/include/ozz/base/memory/unique_ptr.h
memory/allocator.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/platform.h
${PROJECT_SOURCE_DIR}/include/ozz/base/span.h
platform.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/log.h
log.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/intrusive_list.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/deque.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/list.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/map.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/queue.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/set.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/stack.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/string.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/string_archive.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/unordered_map.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/unordered_set.h
containers/string_archive.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/vector.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/vector_archive.h
${PROJECT_SOURCE_DIR}/include/ozz/base/containers/std_allocator.h
${PROJECT_SOURCE_DIR}/include/ozz/base/io/archive.h
io/archive.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/io/archive_traits.h
${PROJECT_SOURCE_DIR}/include/ozz/base/io/stream.h
io/stream.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/box.h
maths/box.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/gtest_math_helper.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/internal/simd_math_config.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/internal/simd_math_ref-inl.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/internal/simd_math_sse-inl.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/math_ex.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/math_constant.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/quaternion.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/rect.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/simd_math.h
maths/simd_math.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/simd_quaternion.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/soa_float.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/soa_quaternion.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/soa_transform.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/soa_float4x4.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/transform.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/vec_float.h
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/math_archive.h
maths/math_archive.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/soa_math_archive.h
maths/soa_math_archive.cc
${PROJECT_SOURCE_DIR}/include/ozz/base/maths/simd_math_archive.h
maths/simd_math_archive.cc)
target_include_directories(ozz_base PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
set_target_properties(ozz_base PROPERTIES FOLDER "ozz")
install(TARGETS ozz_base DESTINATION lib)
fuse_target("ozz_base")
@@ -0,0 +1,75 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/containers/string_archive.h"
#include "ozz/base/io/archive.h"
#include "ozz/base/maths/math_ex.h"
namespace ozz {
namespace io {
void Extern<string>::Save(OArchive& _archive, const string* _values,
size_t _count) {
for (size_t i = 0; i < _count; i++) {
const ozz::string& string = _values[i];
// Get size excluding null terminating character.
uint32_t size = static_cast<uint32_t>(string.size());
_archive << size;
_archive << ozz::io::MakeArray(string.c_str(), size);
}
}
void Extern<string>::Load(IArchive& _archive, string* _values, size_t _count,
uint32_t _version) {
(void)_version;
for (size_t i = 0; i < _count; i++) {
ozz::string& string = _values[i];
// Ensure an existing string is reseted.
string.clear();
uint32_t size;
_archive >> size;
string.reserve(size);
// Prepares temporary buffer used for reading.
char buffer[128];
for (size_t to_read = size; to_read != 0;) {
// Read from the archive to the local temporary buffer.
const size_t to_read_this_loop =
math::Min(to_read, OZZ_ARRAY_SIZE(buffer));
_archive >> ozz::io::MakeArray(buffer, to_read_this_loop);
to_read -= to_read_this_loop;
// Append to the string.
string.append(buffer, to_read_this_loop);
}
}
}
} // namespace io
} // namespace ozz
+57
View File
@@ -0,0 +1,57 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/io/archive.h"
#include <cassert>
namespace ozz {
namespace io {
// OArchive implementation.
OArchive::OArchive(Stream* _stream, Endianness _endianness)
: stream_(_stream), endian_swap_(_endianness != GetNativeEndianness()) {
assert(stream_ && stream_->opened() &&
"_stream argument must point a valid opened stream.");
// Save as a single byte as it does not need to be swapped.
uint8_t endianness = static_cast<uint8_t>(_endianness);
*this << endianness;
}
// IArchive implementation.
IArchive::IArchive(Stream* _stream) : stream_(_stream), endian_swap_(false) {
assert(stream_ && stream_->opened() &&
"_stream argument must point a valid opened stream.");
// Endianness was saved as a single byte, as it does not need to be swapped.
uint8_t endianness;
*this >> endianness;
endian_swap_ = endianness != GetNativeEndianness();
}
} // namespace io
} // namespace ozz
+217
View File
@@ -0,0 +1,217 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/io/stream.h"
#include <cassert>
#include <cstdio>
#include <cstring>
#include <limits>
#include "ozz/base/maths/math_ex.h"
#include "ozz/base/memory/allocator.h"
namespace ozz {
namespace io {
// Starts File implementation.
bool File::Exist(const char* _filename) {
FILE* file = std::fopen(_filename, "r");
if (file) {
std::fclose(file);
return true;
}
return false;
}
File::File(const char* _filename, const char* _mode)
: file_(std::fopen(_filename, _mode)) {}
File::File(void* _file) : file_(_file) {}
File::~File() { Close(); }
void File::Close() {
if (file_) {
std::FILE* file = reinterpret_cast<std::FILE*>(file_);
std::fclose(file);
file_ = nullptr;
}
}
bool File::opened() const { return file_ != nullptr; }
size_t File::Read(void* _buffer, size_t _size) {
std::FILE* file = reinterpret_cast<std::FILE*>(file_);
return std::fread(_buffer, 1, _size, file);
}
size_t File::Write(const void* _buffer, size_t _size) {
std::FILE* file = reinterpret_cast<std::FILE*>(file_);
return std::fwrite(_buffer, 1, _size, file);
}
int File::Seek(int _offset, Origin _origin) {
int origins[] = {SEEK_CUR, SEEK_END, SEEK_SET};
if (_origin >= static_cast<int>(OZZ_ARRAY_SIZE(origins))) {
return -1;
}
std::FILE* file = reinterpret_cast<std::FILE*>(file_);
return std::fseek(file, _offset, origins[_origin]);
}
int File::Tell() const {
std::FILE* file = reinterpret_cast<std::FILE*>(file_);
const long current = std::ftell(file);
return static_cast<int>(current);
}
size_t File::Size() const {
std::FILE* file = reinterpret_cast<std::FILE*>(file_);
const long current = std::ftell(file);
assert(current >= 0);
int seek = std::fseek(file, 0, SEEK_END);
assert(seek == 0);
(void)seek;
const long end = std::ftell(file);
assert(end >= 0);
seek = std::fseek(file, current, SEEK_SET);
assert(seek == 0);
return static_cast<size_t>(end);
}
// Starts MemoryStream implementation.
const size_t MemoryStream::kBufferSizeIncrement = 16 << 10;
const size_t MemoryStream::kMaxSize = std::numeric_limits<int>::max();
MemoryStream::MemoryStream()
: buffer_(nullptr), alloc_size_(0), end_(0), tell_(0) {}
MemoryStream::~MemoryStream() {
ozz::memory::default_allocator()->Deallocate(buffer_);
buffer_ = nullptr;
}
bool MemoryStream::opened() const { return true; }
size_t MemoryStream::Read(void* _buffer, size_t _size) {
// A read cannot set file position beyond the end of the file.
// A read cannot exceed the maximum Stream size.
if (tell_ > end_ || _size > kMaxSize) {
return 0;
}
const int read_size = math::Min(end_ - tell_, static_cast<int>(_size));
std::memcpy(_buffer, buffer_ + tell_, read_size);
tell_ += read_size;
return read_size;
}
size_t MemoryStream::Write(const void* _buffer, size_t _size) {
if (_size > kMaxSize || tell_ > static_cast<int>(kMaxSize - _size)) {
// A write cannot exceed the maximum Stream size.
return 0;
}
if (tell_ > end_) {
// The fseek() function shall allow the file-position indicator to be set
// beyond the end of existing data in the file. If data is later written at
// this point, subsequent reads of data in the gap shall return bytes with
// the value 0 until data is actually written into the gap.
if (!Resize(tell_)) {
return 0;
}
// Fills the gap with 0's.
const size_t gap = tell_ - end_;
std::memset(buffer_ + end_, 0, gap);
end_ = tell_;
}
const int size = static_cast<int>(_size);
const int tell_end = tell_ + size;
if (Resize(tell_end)) {
end_ = math::Max(tell_end, end_);
std::memcpy(buffer_ + tell_, _buffer, _size);
tell_ += size;
return _size;
}
return 0;
}
int MemoryStream::Seek(int _offset, Origin _origin) {
int origin;
switch (_origin) {
case kCurrent:
origin = tell_;
break;
case kEnd:
origin = end_;
break;
case kSet:
origin = 0;
break;
default:
return -1;
}
// Exit if seeking before file begin or beyond max file size.
if (origin < -_offset ||
(_offset > 0 && origin > static_cast<int>(kMaxSize - _offset))) {
return -1;
}
// So tell_ is moved but end_ pointer is not moved until something is later
// written.
tell_ = origin + _offset;
return 0;
}
int MemoryStream::Tell() const { return tell_; }
size_t MemoryStream::Size() const { return static_cast<size_t>(end_); }
bool MemoryStream::Resize(size_t _size) {
if (_size > alloc_size_) {
// Resize to the next multiple of kBufferSizeIncrement, requires
// kBufferSizeIncrement to be a power of 2.
static_assert(
(MemoryStream::kBufferSizeIncrement & (kBufferSizeIncrement - 1)) == 0,
"kBufferSizeIncrement must be a power of 2");
const size_t new_size = ozz::Align(_size, kBufferSizeIncrement);
char* new_buffer = reinterpret_cast<char*>(
ozz::memory::default_allocator()->Allocate(new_size, 16));
std::memcpy(new_buffer, buffer_, alloc_size_);
ozz::memory::default_allocator()->Deallocate(buffer_);
buffer_ = new_buffer;
alloc_size_ = new_size;
}
return _size == 0 || buffer_ != nullptr;
}
} // namespace io
} // namespace ozz
+79
View File
@@ -0,0 +1,79 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/log.h"
#include <iomanip>
#include <sstream>
#include "ozz/base/memory/allocator.h"
namespace ozz {
namespace log {
// Default log level initialization.
namespace {
Level log_level = kStandard;
}
Level SetLevel(Level _level) {
const Level previous_level = log_level;
log_level = _level;
return previous_level;
}
Level GetLevel() { return log_level; }
LogV::LogV() : Logger(std::clog, kVerbose) {}
Log::Log() : Logger(std::clog, kStandard) {}
Out::Out() : Logger(std::cout, kStandard) {}
Err::Err() : Logger(std::cerr, kStandard) {}
Logger::Logger(std::ostream& _stream, Level _level)
: stream_(_level <= GetLevel() ? _stream : *ozz::New<std::ostringstream>()),
local_stream_(&stream_ != &_stream) {}
Logger::~Logger() {
if (local_stream_) {
ozz::Delete(&stream_);
}
}
FloatPrecision::FloatPrecision(const Logger& _logger, int _precision)
: precision_(_logger.stream().precision(_precision)),
format_(_logger.stream().setf(std::ios_base::fixed,
std::ios_base::floatfield)),
stream_(_logger.stream()) {}
FloatPrecision::~FloatPrecision() {
stream_.precision(precision_);
stream_.setf(format_, std::ios_base::floatfield);
}
} // namespace log
} // namespace ozz
+75
View File
@@ -0,0 +1,75 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/maths/box.h"
#include <limits>
#include "ozz/base/maths/math_ex.h"
#include "ozz/base/maths/simd_math.h"
namespace ozz {
namespace math {
Box::Box()
: min(std::numeric_limits<float>::max()),
max(-std::numeric_limits<float>::max()) {}
Box::Box(const Float3* _points, size_t _stride, size_t _count) {
assert(_stride >= sizeof(Float3) &&
"_stride must be greater or equal to sizeof(Float3)");
Float3 local_min(std::numeric_limits<float>::max());
Float3 local_max(-std::numeric_limits<float>::max());
const Float3* end = PointerStride(_points, _stride * _count);
for (; _points < end; _points = PointerStride(_points, _stride)) {
local_min = Min(local_min, *_points);
local_max = Max(local_max, *_points);
}
min = local_min;
max = local_max;
}
Box TransformBox(const Float4x4& _matrix, const Box& _box) {
const SimdFloat4 min = simd_float4::Load3PtrU(&_box.min.x);
const SimdFloat4 max = simd_float4::Load3PtrU(&_box.max.x);
// Transforms min and max.
const SimdFloat4 ta = TransformPoint(_matrix, min);
const SimdFloat4 tb = TransformPoint(_matrix, max);
// Finds new min and max and store them in box.
Box tbox;
math::Store3PtrU(Min(ta, tb), &tbox.min.x);
math::Store3PtrU(Max(ta, tb), &tbox.max.x);
return tbox;
}
} // namespace math
} // namespace ozz
+125
View File
@@ -0,0 +1,125 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/maths/math_archive.h"
#include <cassert>
#include "ozz/base/io/archive.h"
#include "ozz/base/maths/box.h"
#include "ozz/base/maths/quaternion.h"
#include "ozz/base/maths/rect.h"
#include "ozz/base/maths/transform.h"
#include "ozz/base/maths/vec_float.h"
namespace ozz {
namespace io {
void Extern<math::Float2>::Save(OArchive& _archive, const math::Float2* _values,
size_t _count) {
_archive << MakeArray(&_values->x, 2 * _count);
}
void Extern<math::Float2>::Load(IArchive& _archive, math::Float2* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->x, 2 * _count);
}
void Extern<math::Float3>::Save(OArchive& _archive, const math::Float3* _values,
size_t _count) {
_archive << MakeArray(&_values->x, 3 * _count);
}
void Extern<math::Float3>::Load(IArchive& _archive, math::Float3* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->x, 3 * _count);
}
void Extern<math::Float4>::Save(OArchive& _archive, const math::Float4* _values,
size_t _count) {
_archive << MakeArray(&_values->x, 4 * _count);
}
void Extern<math::Float4>::Load(IArchive& _archive, math::Float4* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->x, 4 * _count);
}
void Extern<math::Quaternion>::Save(OArchive& _archive,
const math::Quaternion* _values,
size_t _count) {
_archive << MakeArray(&_values->x, 4 * _count);
}
void Extern<math::Quaternion>::Load(IArchive& _archive,
math::Quaternion* _values, size_t _count,
uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->x, 4 * _count);
}
void Extern<math::Transform>::Save(OArchive& _archive,
const math::Transform* _values,
size_t _count) {
_archive << MakeArray(&_values->translation.x, 10 * _count);
}
void Extern<math::Transform>::Load(IArchive& _archive, math::Transform* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->translation.x, 10 * _count);
}
void Extern<math::Box>::Save(OArchive& _archive, const math::Box* _values,
size_t _count) {
_archive << MakeArray(&_values->min.x, 6 * _count);
}
void Extern<math::Box>::Load(IArchive& _archive, math::Box* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->min.x, 6 * _count);
}
void Extern<math::RectFloat>::Save(OArchive& _archive,
const math::RectFloat* _values,
size_t _count) {
_archive << MakeArray(&_values->left, 4 * _count);
}
void Extern<math::RectFloat>::Load(IArchive& _archive, math::RectFloat* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->left, 4 * _count);
}
void Extern<math::RectInt>::Save(OArchive& _archive,
const math::RectInt* _values, size_t _count) {
_archive << MakeArray(&_values->left, 4 * _count);
}
void Extern<math::RectInt>::Load(IArchive& _archive, math::RectInt* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(&_values->left, 4 * _count);
}
} // namespace io
} // namespace ozz
+61
View File
@@ -0,0 +1,61 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/maths/simd_math.h"
namespace ozz {
namespace math {
// Select compile time name of the simd implementation
#if defined(OZZ_SIMD_AVX2) && defined(OZZ_SIMD_FMA)
#define _OZZ_SIMD_IMPLEMENTATION "AVX2-FMA"
#elif defined(OZZ_SIMD_AVX2)
#define _OZZ_SIMD_IMPLEMENTATION "AVX2"
#elif defined(OZZ_SIMD_AVX)
#define _OZZ_SIMD_IMPLEMENTATION "AVX"
#elif defined(OZZ_SIMD_SSE4_2)
#define _OZZ_SIMD_IMPLEMENTATION "SSE4.2"
#elif defined(OZZ_SIMD_SSE4_1)
#define _OZZ_SIMD_IMPLEMENTATION "SSE4.1"
#elif defined(OZZ_SIMD_SSSE3)
#define _OZZ_SIMD_IMPLEMENTATION "SSSE3"
#elif defined(OZZ_SIMD_SSE3)
#define _OZZ_SIMD_IMPLEMENTATION "SSE3"
#elif defined(OZZ_SIMD_SSEx)
#define _OZZ_SIMD_IMPLEMENTATION "SSE2"
#elif defined(OZZ_SIMD_REF)
#define _OZZ_SIMD_IMPLEMENTATION "Reference"
#else
// Not defined
#endif
#pragma message("Ozz libraries were built with " _OZZ_SIMD_IMPLEMENTATION \
" SIMD math implementation")
const char* SimdImplementationName() { return _OZZ_SIMD_IMPLEMENTATION; }
} // namespace math
} // namespace ozz
@@ -0,0 +1,70 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/maths/simd_math_archive.h"
#include <cassert>
#include "ozz/base/io/archive.h"
namespace ozz {
namespace io {
void Extern<math::SimdFloat4>::Save(OArchive& _archive,
const math::SimdFloat4* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(_values), 4 * _count);
}
void Extern<math::SimdFloat4>::Load(IArchive& _archive,
math::SimdFloat4* _values, size_t _count,
uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(_values), 4 * _count);
}
void Extern<math::SimdInt4>::Save(OArchive& _archive,
const math::SimdInt4* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const int*>(_values), 4 * _count);
}
void Extern<math::SimdInt4>::Load(IArchive& _archive, math::SimdInt4* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<int*>(_values), 4 * _count);
}
void Extern<math::Float4x4>::Save(OArchive& _archive,
const math::Float4x4* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(_values), 16 * _count);
}
void Extern<math::Float4x4>::Load(IArchive& _archive, math::Float4x4* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(_values), 16 * _count);
}
} // namespace io
} // namespace ozz
@@ -0,0 +1,115 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/maths/soa_math_archive.h"
#include "ozz/base/io/archive.h"
#include "ozz/base/maths/soa_float.h"
#include "ozz/base/maths/soa_float4x4.h"
#include "ozz/base/maths/soa_quaternion.h"
#include "ozz/base/maths/soa_transform.h"
namespace ozz {
namespace io {
void Extern<math::SoaFloat2>::Save(OArchive& _archive,
const math::SoaFloat2* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(&_values->x),
2 * 4 * _count);
}
void Extern<math::SoaFloat2>::Load(IArchive& _archive, math::SoaFloat2* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(&_values->x), 2 * 4 * _count);
}
void Extern<math::SoaFloat3>::Save(OArchive& _archive,
const math::SoaFloat3* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(&_values->x),
3 * 4 * _count);
}
void Extern<math::SoaFloat3>::Load(IArchive& _archive, math::SoaFloat3* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(&_values->x), 3 * 4 * _count);
}
void Extern<math::SoaFloat4>::Save(OArchive& _archive,
const math::SoaFloat4* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(&_values->x),
4 * 4 * _count);
}
void Extern<math::SoaFloat4>::Load(IArchive& _archive, math::SoaFloat4* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(&_values->x), 4 * 4 * _count);
}
void Extern<math::SoaQuaternion>::Save(OArchive& _archive,
const math::SoaQuaternion* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(&_values->x),
4 * 4 * _count);
}
void Extern<math::SoaQuaternion>::Load(IArchive& _archive,
math::SoaQuaternion* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(&_values->x), 4 * 4 * _count);
}
void Extern<math::SoaFloat4x4>::Save(OArchive& _archive,
const math::SoaFloat4x4* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(&_values->cols[0].x),
4 * 4 * 4 * _count);
}
void Extern<math::SoaFloat4x4>::Load(IArchive& _archive,
math::SoaFloat4x4* _values, size_t _count,
uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(&_values->cols[0].x),
4 * 4 * 4 * _count);
}
void Extern<math::SoaTransform>::Save(OArchive& _archive,
const math::SoaTransform* _values,
size_t _count) {
_archive << MakeArray(reinterpret_cast<const float*>(&_values->translation.x),
10 * 4 * _count);
}
void Extern<math::SoaTransform>::Load(IArchive& _archive,
math::SoaTransform* _values,
size_t _count, uint32_t _version) {
(void)_version;
_archive >> MakeArray(reinterpret_cast<float*>(&_values->translation.x),
10 * 4 * _count);
}
} // namespace io
} // namespace ozz
+111
View File
@@ -0,0 +1,111 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/memory/allocator.h"
#include <memory.h>
#include <atomic>
#include <cassert>
#include <cstdlib>
#include "ozz/base/maths/math_ex.h"
namespace ozz {
namespace memory {
namespace {
struct Header {
void* unaligned;
size_t size;
};
} // namespace
// Implements the basic heap allocator.
// Will trace allocation count and assert in case of a memory leak.
class HeapAllocator : public Allocator {
public:
HeapAllocator() { allocation_count_.store(0); }
~HeapAllocator() {
assert(allocation_count_.load() == 0 && "Memory leak detected");
}
protected:
void* Allocate(size_t _size, size_t _alignment) {
// Allocates enough memory to store the header + required alignment space.
const size_t to_allocate = _size + sizeof(Header) + _alignment - 1;
char* unaligned = reinterpret_cast<char*>(malloc(to_allocate));
if (!unaligned) {
return nullptr;
}
char* aligned = ozz::Align(unaligned + sizeof(Header), _alignment);
assert(aligned + _size <= unaligned + to_allocate); // Don't overrun.
// Set the header
Header* header = reinterpret_cast<Header*>(aligned - sizeof(Header));
assert(reinterpret_cast<char*>(header) >= unaligned);
header->unaligned = unaligned;
header->size = _size;
// Allocation's succeeded.
++allocation_count_;
return aligned;
}
void Deallocate(void* _block) {
if (_block) {
Header* header = reinterpret_cast<Header*>(
reinterpret_cast<char*>(_block) - sizeof(Header));
free(header->unaligned);
// Deallocation completed.
--allocation_count_;
}
}
private:
// Internal allocation count used to track memory leaks.
// Should equals 0 at destruction time.
std::atomic_int allocation_count_;
};
namespace {
// Instantiates the default heap allocator->
HeapAllocator g_heap_allocator;
// Instantiates the default heap allocator pointer.
Allocator* g_default_allocator = &g_heap_allocator;
} // namespace
// Implements default allocator accessor.
Allocator* default_allocator() { return g_default_allocator; }
// Implements default allocator setter.
Allocator* SetDefaulAllocator(Allocator* _allocator) {
Allocator* previous = g_default_allocator;
g_default_allocator = _allocator;
return previous;
}
} // namespace memory
} // namespace ozz
+54
View File
@@ -0,0 +1,54 @@
//----------------------------------------------------------------------------//
// //
// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
// and distributed under the MIT License (MIT). //
// //
// Copyright (c) Guillaume Blanc //
// //
// Permission is hereby granted, free of charge, to any person obtaining a //
// copy of this software and associated documentation files (the "Software"), //
// to deal in the Software without restriction, including without limitation //
// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
// and/or sell copies of the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in //
// all copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
// DEALINGS IN THE SOFTWARE. //
// //
//----------------------------------------------------------------------------//
#include "ozz/base/platform.h"
namespace ozz {
bool strmatch(const char* _str, const char* _pattern) {
for (; *_pattern; ++_str, ++_pattern) {
if (*_pattern == '?') {
if (!*_str) {
return false;
}
} else if (*_pattern == '*') {
if (strmatch(_str, _pattern + 1)) {
return true;
}
if (*_str && strmatch(_str + 1, _pattern)) {
return true;
}
return false;
} else {
if (*_str != *_pattern) {
return false;
}
}
}
return !*_str && !*_pattern;
}
} // namespace ozz