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 values = inValues;
19 Vec4::sSort4Reverse(values, ioIdentifiers);
20
21 // Count how many results are less than the max value
22 UVec4 closer = Vec4::sLess(values, Vec4::sReplicate(inMaxValue));
23 int num_results = closer.CountTrues();
24
25 // Shift the values so that only the ones that are less than max are kept
26 values = values.ReinterpretAsInt().ShiftComponents4Minus(num_results).ReinterpretAsFloat();
27 ioIdentifiers = ioIdentifiers.ShiftComponents4Minus(num_results);
28
29 // Store the values
30 values.StoreFloat4(reinterpret_cast<Float4 *>(outValues));
31
32 return num_results;
33}
34
39JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers)
40{
41 // Sort the hits
42 ioIdentifiers = UVec4::sSort4True(inValue, ioIdentifiers);
43
44 // Return the amount of hits
45 return inValue.CountTrues();
46}
47
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
JPH_INLINE int CountAndSortTrues(UVec4Arg inValue, UVec4 &ioIdentifiers)
Definition: SortReverseAndStore.h:39
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