Overte C++ Documentation
Region.h
1 //
2 // Region.h
3 // libraries/workload/src/workload
4 //
5 // Created by Sam Gateau 2018.03.05
6 // Copyright 2018 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 #ifndef hifi_workload_Region_h
12 #define hifi_workload_Region_h
13 
14 namespace workload {
15 
16 class Region {
17 public:
18  using Type = uint8_t;
19 
20  enum Name : uint8_t {
21  R1 = 0, // R1 = in physics simulation and client will bid for simulation ownership
22  R2, // R2 = in physics simulation but client prefers to NOT have simulation ownership
23  R3, // R3 = are NOT in physics simulation but yes kinematically animated when velocities are non-zero
24  R4, // R4 = known to workload but outside R3, not in physics, not animated if moving
25  UNKNOWN, // UNKNOWN = known to workload but unsorted
26  INVALID, // INVALID = not known to workload
27  };
28 
29  static constexpr uint32_t NUM_KNOWN_REGIONS = uint32_t(Region::R4 - Region::R1 + 1); // R1 through R4 inclusive
30  static constexpr uint32_t NUM_TRACKED_REGIONS = uint32_t(Region::R3 - Region::R1 + 1); // R1 through R3 inclusive
31  static const uint8_t NUM_REGION_TRANSITIONS = NUM_KNOWN_REGIONS * (NUM_KNOWN_REGIONS - 1);
32 
33  static uint8_t computeTransitionIndex(uint8_t prevIndex, uint8_t newIndex);
34 
35 };
36 
37 inline uint8_t Region::computeTransitionIndex(uint8_t prevIndex, uint8_t newIndex) {
38  // given prevIndex and newIndex compute an index into the transition list,
39  // where the lists between unchanged indices don't exist (signaled by index = -1).
40  //
41  // Given an NxN array
42  // let p = i + N * j
43  //
44  // then k = -1 when i == j
45  // = p - (1 + p/(N+1)) when i != j
46  //
47  // i 0 1 2 3
48  // j +-------+-------+-------+-------+
49  // |p = 0 | 1 | 2 | 3 |
50  // 0 | | | | |
51  // |k = -1 | 0 | 1 | 2 |
52  // +-------+-------+-------+-------+
53  // | 4 | 5 | 6 | 7 |
54  // 1 | | | | |
55  // | 3 | -1 | 4 | 5 |
56  // +-------+-------+-------+-------+
57  // | 8 | 9 | 10 | 11 |
58  // 2 | | | | |
59  // | 6 | 7 | -1 | 8 |
60  // +-------+-------+-------+-------+
61  // | 12 | 13 | 14 | 15 |
62  // 3 | | | | |
63  // | 9 | 10 | 11 | -1 |
64  // +-------+-------+-------+-------+
65  uint8_t p = prevIndex + Region::NUM_KNOWN_REGIONS * newIndex;
66  if (0 == (p % (Region::NUM_KNOWN_REGIONS + 1))) {
67  return -1;
68  }
69  return p - (1 + p / (Region::NUM_KNOWN_REGIONS + 1));
70 }
71 
72 } // namespace workload
73 
74 #endif // hifi_workload_Region_h