OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
spaceindex.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <cstdint>
5#include <algorithm>
6#include <array>
7#include <memory>
8#include <Tempest/Point>
9
10#include "utils/workers.h"
11
12class Vob;
13
15 public:
16 void clear();
17 size_t size() const { return arr.size(); }
18 void invalidate();
19
20 protected:
21 BaseSpaceIndex() = default;
22 void add(Vob* v);
23 void del(Vob* v);
24 bool hasObject(const Vob* v) const;
25
26 void find(const Tempest::Vec3& p, float R, const void* ctx, void (*func)(const void*, Vob*));
27 template<class Func>
28 void parallelFor(Func f);
29 Vob** data() { return arr.data(); }
30 Vob*const* data() const { return arr.data(); }
31
32 private:
33 std::vector<Vob*> arr;
34 std::vector<Vob*> index;
35 std::vector<Vob*> dynamic;
36
37 void buildIndex();
38 void buildIndex(Vob** v, size_t cnt, uint8_t depth);
39 void sort(Vob** v, size_t cnt, uint8_t component);
40 void implFind(Vob** v, size_t cnt, uint8_t depth, const Tempest::Vec3& p, float R, const void* ctx, void(*func)(const void*, Vob*));
41 };
42
43template<class Func>
45 Workers::parallelTasks(arr,func);
46 }
47
48
49template<class T>
50class SpaceIndex final : public BaseSpaceIndex {
51 public:
52 SpaceIndex()=default;
53
54 void add(T* v) {
56 }
57
58 void del(T* v) {
60 }
61
62 bool hasObject(const T* v) const {
64 }
65
66 T** begin() { return reinterpret_cast<T**>(data()); }
67 T** end() { return begin()+size(); }
68
69 T*const* begin() const { return reinterpret_cast<T*const*>(data()); }
70 T*const* end() const { return begin()+size(); }
71
72 template<class Func>
73 void find(const Tempest::Vec3& p, float R, const Func& f) {
74 return BaseSpaceIndex::find(p,R,&f,[](const void* ctx, Vob* v){
75 auto& f = *reinterpret_cast<const Func*>(ctx);
76 f(*reinterpret_cast<T*>(v));
77 });
78 }
79
80 template<class F>
81 void parallelFor(F func) {
82 BaseSpaceIndex::parallelFor([&func](Vob* v){ func(*reinterpret_cast<T*>(v)); });
83 }
84 };
85
void del(Vob *v)
void find(const Tempest::Vec3 &p, float R, const void *ctx, void(*func)(const void *, Vob *))
size_t size() const
Definition spaceindex.h:17
Vob *const * data() const
Definition spaceindex.h:30
Vob ** data()
Definition spaceindex.h:29
void parallelFor(Func f)
Definition spaceindex.h:44
bool hasObject(const Vob *v) const
void add(Vob *v)
BaseSpaceIndex()=default
void del(T *v)
Definition spaceindex.h:58
T *const * end() const
Definition spaceindex.h:70
SpaceIndex()=default
bool hasObject(const T *v) const
Definition spaceindex.h:62
void add(T *v)
Definition spaceindex.h:54
void find(const Tempest::Vec3 &p, float R, const Func &f)
Definition spaceindex.h:73
void parallelFor(F func)
Definition spaceindex.h:81
T ** end()
Definition spaceindex.h:67
T ** begin()
Definition spaceindex.h:66
T *const * begin() const
Definition spaceindex.h:69
Definition vob.h:11
static void parallelTasks(std::vector< T > &data, const F &func)
Definition workers.h:30