Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SortReverseAndStore.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
15JPH_INLINE int SortReverseAndStore(Vec4Arg inValues, float inMaxValue, UVec4 &ioIdentifiers, float *outValues)
16{
17 // Sort so that highest values are first (we want to first process closer hits and we process stack top to bottom)
18 Vec4::sSort4Reverse(inValues, ioIdentifiers);
19
20 // Count how many results are less than the max value
21 UVec4 closer = Vec4::sLess(inValues, Vec4::sReplicate(inMaxValue));
22 int num_results = closer.CountTrues();
23
24 // Shift the values so that only the ones that are less than max are kept
25 inValues = inValues.ReinterpretAsInt().ShiftComponents4Minus(num_results).ReinterpretAsFloat();
26 ioIdentifiers = ioIdentifiers.ShiftComponents4Minus(num_results);
27
28 // Store the values
29 inValues.StoreFloat4(reinterpret_cast<Float4 *>(outValues));
30
31 return num_results;
32}
33
38JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers)
39{
40 // Sort the hits
41 ioIdentifiers = UVec4::sSort4True(inValue, ioIdentifiers);
42
43 // Return the amount of hits
44 return inValue.CountTrues();
45}
46
#define JPH_NAMESPACE_END
Definition: Core.h:354
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:348
JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers)
Definition: SortReverseAndStore.h:38
JPH_NAMESPACE_BEGIN JPH_INLINE int SortReverseAndStore(Vec4Arg inValues, float inMaxValue, UVec4 &ioIdentifiers, float *outValues)
Definition: SortReverseAndStore.h:15
Class that holds 4 float values. Convert to Vec4 to perform calculations.
Definition: Float4.h:11
Definition: UVec4.h:12
JPH_INLINE int CountTrues() const
Count the number of components that are true (true is when highest bit of component is set)
Definition: UVec4.inl:367
static JPH_INLINE UVec4 sSort4True(UVec4Arg inValue, UVec4Arg inIndex)
Definition: UVec4.inl:222
JPH_INLINE UVec4 ShiftComponents4Minus(int inCount) const
Shift vector components by 4 - Count floats to the left, so if Count = 1 the resulting vector is (W,...
Definition: UVec4.inl:547
JPH_INLINE Vec4 ReinterpretAsFloat() const
Reinterpret UVec4 as a Vec4 (doesn't change the bits)
Definition: UVec4.inl:332
Definition: Vec4.h:14
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2)
Less than (component wise)
Definition: Vec4.inl:180
static JPH_INLINE void sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
Definition: Vec4.inl:325
JPH_INLINE UVec4 ReinterpretAsInt() const
Reinterpret Vec4 as a UVec4 (doesn't change the bits)
Definition: Vec4.inl:730
static JPH_INLINE Vec4 sReplicate(float inV)
Replicate inV across all components.
Definition: Vec4.inl:74
JPH_INLINE void StoreFloat4(Float4 *outV) const
Store 4 floats to memory.
Definition: Vec4.inl:707