Merge remote-tracking branch 'origin/master' into 1.7
This commit is contained in:
@@ -357,8 +357,8 @@ public:
|
||||
{
|
||||
for (Iterator i = Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
if (i->Value)
|
||||
::Delete(i->Value);
|
||||
if (i->Item)
|
||||
::Delete(i->Item);
|
||||
}
|
||||
Clear();
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
#include "Enums.h"
|
||||
|
||||
DECLARE_ENUM_3(Encoding, ANSI, Unicode, UnicodeBigEndian);
|
||||
DECLARE_ENUM_4(Encoding, ANSI, Unicode, UnicodeBigEndian, UTF8);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
/// </summary>
|
||||
API_STRUCT(InBuild) struct FLAXENGINE_API BoundingFrustum
|
||||
{
|
||||
friend CollisionsHelper;
|
||||
private:
|
||||
Matrix _matrix;
|
||||
|
||||
|
||||
@@ -939,7 +939,6 @@ bool CollisionsHelper::RayIntersectsSphere(const Ray& ray, const BoundingSphere&
|
||||
normal = Vector3::Up;
|
||||
return false;
|
||||
}
|
||||
|
||||
const Vector3 point = ray.Position + ray.Direction * distance;
|
||||
normal = Vector3::Normalize(point - sphere.Center);
|
||||
return true;
|
||||
@@ -953,22 +952,17 @@ bool CollisionsHelper::RayIntersectsSphere(const Ray& ray, const BoundingSphere&
|
||||
point = Vector3::Zero;
|
||||
return false;
|
||||
}
|
||||
|
||||
point = ray.Position + ray.Direction * distance;
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaneIntersectionType CollisionsHelper::PlaneIntersectsPoint(const Plane& plane, const Vector3& point)
|
||||
{
|
||||
Real distance = Vector3::Dot(plane.Normal, point);
|
||||
distance += plane.D;
|
||||
|
||||
const Real distance = Vector3::Dot(plane.Normal, point) + plane.D;
|
||||
if (distance > Plane::DistanceEpsilon)
|
||||
return PlaneIntersectionType::Front;
|
||||
|
||||
if (distance < Plane::DistanceEpsilon)
|
||||
return PlaneIntersectionType::Back;
|
||||
|
||||
return PlaneIntersectionType::Intersecting;
|
||||
}
|
||||
|
||||
@@ -1169,7 +1163,6 @@ ContainmentType CollisionsHelper::SphereContainsPoint(const BoundingSphere& sphe
|
||||
{
|
||||
if (Vector3::DistanceSquared(point, sphere.Center) <= sphere.Radius * sphere.Radius)
|
||||
return ContainmentType::Contains;
|
||||
|
||||
return ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
@@ -1254,13 +1247,10 @@ ContainmentType CollisionsHelper::SphereContainsBox(const BoundingSphere& sphere
|
||||
ContainmentType CollisionsHelper::SphereContainsSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2)
|
||||
{
|
||||
const Real distance = Vector3::Distance(sphere1.Center, sphere2.Center);
|
||||
|
||||
if (sphere1.Radius + sphere2.Radius < distance)
|
||||
return ContainmentType::Disjoint;
|
||||
|
||||
if (sphere1.Radius - sphere2.Radius < distance)
|
||||
return ContainmentType::Intersects;
|
||||
|
||||
return ContainmentType::Contains;
|
||||
}
|
||||
|
||||
@@ -1274,7 +1264,8 @@ ContainmentType CollisionsHelper::FrustumContainsBox(const BoundingFrustum& frus
|
||||
auto result = ContainmentType::Contains;
|
||||
for (int32 i = 0; i < 6; i++)
|
||||
{
|
||||
Plane plane = frustum.GetPlane(i);
|
||||
Plane plane = frustum._planes[i];
|
||||
|
||||
Vector3 p = box.Minimum;
|
||||
if (plane.Normal.X >= 0)
|
||||
p.X = box.Maximum.X;
|
||||
@@ -1282,7 +1273,7 @@ ContainmentType CollisionsHelper::FrustumContainsBox(const BoundingFrustum& frus
|
||||
p.Y = box.Maximum.Y;
|
||||
if (plane.Normal.Z >= 0)
|
||||
p.Z = box.Maximum.Z;
|
||||
if (PlaneIntersectsPoint(plane, p) == PlaneIntersectionType::Back)
|
||||
if (Vector3::Dot(plane.Normal, p) + plane.D < Plane::DistanceEpsilon)
|
||||
return ContainmentType::Disjoint;
|
||||
|
||||
p = box.Maximum;
|
||||
@@ -1292,7 +1283,7 @@ ContainmentType CollisionsHelper::FrustumContainsBox(const BoundingFrustum& frus
|
||||
p.Y = box.Minimum.Y;
|
||||
if (plane.Normal.Z >= 0)
|
||||
p.Z = box.Minimum.Z;
|
||||
if (PlaneIntersectsPoint(plane, p) == PlaneIntersectionType::Back)
|
||||
if (Vector3::Dot(plane.Normal, p) + plane.D < Plane::DistanceEpsilon)
|
||||
result = ContainmentType::Intersects;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -36,6 +36,32 @@ namespace AllocatorExt
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reallocates block of the memory.
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="ptr">A pointer to the memory block to reallocate.</param>
|
||||
/// <param name="newSize">The size of the new allocation (in bytes).</param>
|
||||
/// <param name="alignment">The memory alignment (in bytes). Must be an integer power of 2.</param>
|
||||
/// <returns>The pointer to the allocated chunk of the memory. The pointer is a multiple of alignment.</returns>
|
||||
inline void* ReallocAligned(void* ptr, uint64 newSize, uint64 alignment)
|
||||
{
|
||||
if (newSize == 0)
|
||||
{
|
||||
Allocator::Free(ptr);
|
||||
return nullptr;
|
||||
}
|
||||
if (!ptr)
|
||||
return Allocator::Allocate(newSize, alignment);
|
||||
void* result = Allocator::Allocate(newSize, alignment);
|
||||
if (result)
|
||||
{
|
||||
Platform::MemoryCopy(result, ptr, newSize);
|
||||
Allocator::Free(ptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reallocates block of the memory.
|
||||
/// </summary>
|
||||
|
||||
@@ -114,3 +114,14 @@ inline Span<T> ToSpan(const T* ptr, int32 length)
|
||||
{
|
||||
return Span<T>(ptr, length);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool SpanContains(const Span<T> span, const T& value)
|
||||
{
|
||||
for (int32 i = 0; i < span.Length(); i++)
|
||||
{
|
||||
if (span.Get()[i] == value)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ void String::Set(const char* chars, int32 length)
|
||||
_length = length;
|
||||
}
|
||||
if (chars)
|
||||
StringUtils::ConvertANSI2UTF16(chars, _data, length);
|
||||
StringUtils::ConvertANSI2UTF16(chars, _data, length, _length);
|
||||
}
|
||||
|
||||
void String::SetUTF8(const char* chars, int32 length)
|
||||
@@ -112,7 +112,7 @@ void String::Append(const char* chars, int32 count)
|
||||
_data = (Char*)Platform::Allocate((_length + 1) * sizeof(Char), 16);
|
||||
|
||||
Platform::MemoryCopy(_data, oldData, oldLength * sizeof(Char));
|
||||
StringUtils::ConvertANSI2UTF16(chars, _data + oldLength, count * sizeof(Char));
|
||||
StringUtils::ConvertANSI2UTF16(chars, _data + oldLength, count, _length);
|
||||
_data[_length] = 0;
|
||||
|
||||
Platform::Free(oldData);
|
||||
|
||||
@@ -125,7 +125,8 @@ public:
|
||||
const int32 length = str && *str ? StringUtils::Length(str) : 0;
|
||||
const int32 prevCnt = _data.Count();
|
||||
_data.AddDefault(length);
|
||||
StringUtils::ConvertANSI2UTF16(str, _data.Get() + prevCnt, length);
|
||||
int32 tmp;
|
||||
StringUtils::ConvertANSI2UTF16(str, _data.Get() + prevCnt, length, tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -660,7 +660,8 @@ Variant::Variant(const StringAnsiView& v)
|
||||
const int32 length = v.Length() * sizeof(Char) + 2;
|
||||
AsBlob.Data = Allocator::Allocate(length);
|
||||
AsBlob.Length = length;
|
||||
StringUtils::ConvertANSI2UTF16(v.Get(), (Char*)AsBlob.Data, v.Length());
|
||||
int32 tmp;
|
||||
StringUtils::ConvertANSI2UTF16(v.Get(), (Char*)AsBlob.Data, v.Length(), tmp);
|
||||
((Char*)AsBlob.Data)[v.Length()] = 0;
|
||||
}
|
||||
else
|
||||
@@ -2578,7 +2579,8 @@ void Variant::SetString(const StringAnsiView& str)
|
||||
AsBlob.Data = Allocator::Allocate(length);
|
||||
AsBlob.Length = length;
|
||||
}
|
||||
StringUtils::ConvertANSI2UTF16(str.Get(), (Char*)AsBlob.Data, str.Length());
|
||||
int32 tmp;
|
||||
StringUtils::ConvertANSI2UTF16(str.Get(), (Char*)AsBlob.Data, str.Length(), tmp);
|
||||
((Char*)AsBlob.Data)[str.Length()] = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user