Overte C++ Documentation
Space.h
1 //
2 // Space.h
3 // libraries/workload/src/workload
4 //
5 // Created by Andrew Meadows 2018.01.30
6 // Copyright 2018 High Fidelity, Inc.
7 //
8 // Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
9 // Simple plane class.
10 //
11 // Distributed under the Apache License, Version 2.0.
12 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
13 //
14 
15 #ifndef hifi_workload_Space_h
16 #define hifi_workload_Space_h
17 
18 #include <memory>
19 #include <vector>
20 #include <glm/glm.hpp>
21 
22 #include "Transaction.h"
23 
24 namespace workload {
25 
26 class Space : public Collection {
27 public:
28  using ProxyUpdate = std::pair<int32_t, Sphere>;
29 
30  class Change {
31  public:
32  Change(int32_t i, uint32_t c, uint32_t p) : proxyId(i), region(c), prevRegion(p) {}
33  int32_t proxyId { -1 };
34  uint8_t region { 0 };
35  uint8_t prevRegion { 0 };
36  };
37 
38  Space();
39 
40  void setViews(const Views& views);
41 
42  uint32_t getNumViews() const { return (uint32_t)(_views.size()); }
43  void copyViews(std::vector<View>& copy) const;
44 
45  uint32_t getNumObjects() const { return _IDAllocator.getNumLiveIndices(); }
46  uint32_t getNumAllocatedProxies() const { return (uint32_t)(_IDAllocator.getNumAllocatedIndices()); }
47 
48  void categorizeAndGetChanges(std::vector<Change>& changes);
49  uint32_t copyProxyValues(Proxy* proxies, uint32_t numDestProxies) const;
50  uint32_t copySelectedProxyValues(Proxy::Vector& proxies, const workload::indexed_container::Indices& indices) const;
51 
52  const Owner getOwner(int32_t proxyID) const;
53  uint8_t getRegion(int32_t proxyID) const;
54 
55  void clear() override;
56 private:
57 
58  void processTransactionFrame(const Transaction& transaction) override;
59  void processResets(const Transaction::Resets& transactions);
60  void processRemoves(const Transaction::Removes& transactions);
61  void processUpdates(const Transaction::Updates& transactions);
62 
63  // The database of proxies is protected for editing by a mutex
64  mutable std::mutex _proxiesMutex;
65  Proxy::Vector _proxies;
66  std::vector<Owner> _owners;
67 
68  Views _views;
69 };
70 
71 using SpacePointer = std::shared_ptr<Space>;
72 using Changes = std::vector<Space::Change>;
73 using IndexVectors = std::vector<IndexVector>;
74 using Timing_ns = std::chrono::nanoseconds;
75 using Timings = std::vector<Timing_ns>;
76 
77 } // namespace workload
78 
79 #endif // hifi_workload_Space_h