Allocator Aware Array and List
This commit is contained in:
@@ -74,3 +74,4 @@ float4 fragmentMain(
|
||||
}
|
||||
return float4(result, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ target_sources(SeeleEngine
|
||||
EngineTypes.h
|
||||
MinimalEngine.h
|
||||
MinimalEngine.cpp
|
||||
ThreadPool.h
|
||||
ThreadPool.cpp
|
||||
main.cpp)
|
||||
|
||||
add_subdirectory(Asset/)
|
||||
|
||||
+649
-549
File diff suppressed because it is too large
Load Diff
+357
-321
@@ -1,337 +1,373 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include <xmemory>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
template <typename T>
|
||||
template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>>
|
||||
class List
|
||||
{
|
||||
private:
|
||||
struct Node
|
||||
{
|
||||
Node *prev;
|
||||
Node *next;
|
||||
T data;
|
||||
};
|
||||
struct Node
|
||||
{
|
||||
Node *prev;
|
||||
Node *next;
|
||||
T data;
|
||||
};
|
||||
using NodeAllocator = std::allocator_traits<Allocator>::template rebind_alloc<Node>;
|
||||
|
||||
public:
|
||||
List()
|
||||
{
|
||||
root = nullptr;
|
||||
tail = nullptr;
|
||||
beginIt = Iterator(root);
|
||||
endIt = Iterator(tail);
|
||||
_size = 0;
|
||||
}
|
||||
List(const List& other)
|
||||
{
|
||||
//TODO: improve
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
List(List&& other)
|
||||
: root(std::move(other.root))
|
||||
, tail(std::move(other.tail))
|
||||
, beginIt(std::move(other.beginIt))
|
||||
, endIt(std::move(other.endIt))
|
||||
, _size(std::move(other._size))
|
||||
{
|
||||
other._size = 0;
|
||||
}
|
||||
~List()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
List& operator=(const List& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
if(tail != nullptr)
|
||||
{
|
||||
delete tail;
|
||||
}
|
||||
_size = 0;
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
List& operator=(List&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
root = other.root;
|
||||
tail = other.tail;
|
||||
beginIt = other.beginIt;
|
||||
endIt = other.endIt;
|
||||
_size = other._size;
|
||||
other._size = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename X>
|
||||
class IteratorBase
|
||||
{
|
||||
public:
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef X value_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef X &reference;
|
||||
typedef X *pointer;
|
||||
template <typename X>
|
||||
class IteratorBase
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = X;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using reference = X&;
|
||||
using pointer = X*;
|
||||
|
||||
IteratorBase(Node *x = nullptr)
|
||||
: node(x)
|
||||
{
|
||||
}
|
||||
IteratorBase(const IteratorBase &i)
|
||||
: node(i.node)
|
||||
{
|
||||
}
|
||||
IteratorBase(IteratorBase&& i)
|
||||
: node(std::move(i.node))
|
||||
{
|
||||
}
|
||||
~IteratorBase()
|
||||
{
|
||||
}
|
||||
IteratorBase& operator=(const IteratorBase& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = other.node;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
IteratorBase& operator=(IteratorBase&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = std::move(other.node);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
reference operator*() const
|
||||
{
|
||||
return node->data;
|
||||
}
|
||||
pointer operator->() const
|
||||
{
|
||||
return &node->data;
|
||||
}
|
||||
inline bool operator!=(const IteratorBase &other)
|
||||
{
|
||||
return node != other.node;
|
||||
}
|
||||
inline bool operator==(const IteratorBase &other)
|
||||
{
|
||||
return node == other.node;
|
||||
}
|
||||
IteratorBase &operator--()
|
||||
{
|
||||
node = node->prev;
|
||||
return *this;
|
||||
}
|
||||
IteratorBase operator--(int)
|
||||
{
|
||||
IteratorBase tmp(*this);
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
IteratorBase &operator++()
|
||||
{
|
||||
node = node->next;
|
||||
return *this;
|
||||
}
|
||||
IteratorBase operator++(int)
|
||||
{
|
||||
IteratorBase tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
IteratorBase(Node *x = nullptr)
|
||||
: node(x)
|
||||
{
|
||||
}
|
||||
IteratorBase(const IteratorBase &i)
|
||||
: node(i.node)
|
||||
{
|
||||
}
|
||||
IteratorBase(IteratorBase&& i)
|
||||
: node(std::move(i.node))
|
||||
{
|
||||
}
|
||||
~IteratorBase()
|
||||
{
|
||||
}
|
||||
IteratorBase& operator=(const IteratorBase& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = other.node;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
IteratorBase& operator=(IteratorBase&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = std::move(other.node);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
reference operator*() const
|
||||
{
|
||||
return node->data;
|
||||
}
|
||||
pointer operator->() const
|
||||
{
|
||||
return &node->data;
|
||||
}
|
||||
inline bool operator!=(const IteratorBase &other)
|
||||
{
|
||||
return node != other.node;
|
||||
}
|
||||
inline bool operator==(const IteratorBase &other)
|
||||
{
|
||||
return node == other.node;
|
||||
}
|
||||
IteratorBase &operator--()
|
||||
{
|
||||
node = node->prev;
|
||||
return *this;
|
||||
}
|
||||
IteratorBase operator--(int)
|
||||
{
|
||||
IteratorBase tmp(*this);
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
IteratorBase &operator++()
|
||||
{
|
||||
node = node->next;
|
||||
return *this;
|
||||
}
|
||||
IteratorBase operator++(int)
|
||||
{
|
||||
IteratorBase tmp(*this);
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private:
|
||||
Node *node;
|
||||
friend class List<T>;
|
||||
};
|
||||
typedef IteratorBase<T> Iterator;
|
||||
typedef IteratorBase<const T> ConstIterator;
|
||||
private:
|
||||
Node *node;
|
||||
friend class List<T>;
|
||||
};
|
||||
|
||||
T &front()
|
||||
{
|
||||
return root->data;
|
||||
}
|
||||
T &back()
|
||||
{
|
||||
return tail->prev->data;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (Node *tmp = root; tmp != tail;)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
delete tmp->prev;
|
||||
}
|
||||
delete tail;
|
||||
tail = nullptr;
|
||||
root = nullptr;
|
||||
}
|
||||
//Insert at the end
|
||||
Iterator add(const T &value)
|
||||
{
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = new Node();
|
||||
tail = root;
|
||||
}
|
||||
tail->data = value;
|
||||
Node *newTail = new Node();
|
||||
newTail->prev = tail;
|
||||
newTail->next = nullptr;
|
||||
tail->next = newTail;
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
markIteratorDirty();
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
Iterator add(T&& value)
|
||||
{
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = new Node();
|
||||
tail = root;
|
||||
}
|
||||
tail->data = std::move(value);
|
||||
Node *newTail = new Node();
|
||||
newTail->prev = tail;
|
||||
newTail->next = nullptr;
|
||||
tail->next = newTail;
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
markIteratorDirty();
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
Iterator remove(Iterator pos)
|
||||
{
|
||||
_size--;
|
||||
Node *prev = pos.node->prev;
|
||||
Node *next = pos.node->next;
|
||||
if (prev == nullptr)
|
||||
{
|
||||
root = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
if(next == nullptr)
|
||||
{
|
||||
root = prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
delete pos.node;
|
||||
markIteratorDirty();
|
||||
return Iterator(next);
|
||||
}
|
||||
void popBack()
|
||||
{
|
||||
assert(_size > 0);
|
||||
remove(Iterator(tail->prev));
|
||||
}
|
||||
void popFront()
|
||||
{
|
||||
assert(_size > 0);
|
||||
remove(Iterator(root));
|
||||
}
|
||||
Iterator insert(Iterator pos, const T &value)
|
||||
{
|
||||
_size++;
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = new Node();
|
||||
root->data = value;
|
||||
tail = new Node();
|
||||
root->next = tail;
|
||||
root->prev = nullptr;
|
||||
tail->prev = root;
|
||||
tail->next = nullptr;
|
||||
markIteratorDirty();
|
||||
return beginIt;
|
||||
}
|
||||
Node *tmp = pos.node->prev;
|
||||
Node *newNode = new Node();
|
||||
newNode->data = value;
|
||||
tmp->next = newNode;
|
||||
newNode->prev = tmp;
|
||||
newNode->next = pos.node;
|
||||
pos.node->prev = newNode;
|
||||
return Iterator(newNode);
|
||||
}
|
||||
Iterator find(const T &value)
|
||||
{
|
||||
for (Node *i = root; i != tail; i = i->next)
|
||||
{
|
||||
if (!(i->data < value) && !(value < i->data))
|
||||
{
|
||||
return Iterator(i);
|
||||
}
|
||||
}
|
||||
return endIt;
|
||||
}
|
||||
bool empty()
|
||||
{
|
||||
return _size == 0;
|
||||
}
|
||||
uint32 size()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
Iterator begin()
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
const Iterator begin() const
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
Iterator end()
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
const Iterator end() const
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
using Iterator = IteratorBase<T>;
|
||||
using ConstIterator = IteratorBase<const T>;
|
||||
|
||||
using value_type = T;
|
||||
using allocator_type = Allocator;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using reference = value_type&;
|
||||
using const_reference = const value_type&;
|
||||
using pointer = T*;
|
||||
using const_pointer = const T*;
|
||||
|
||||
using iterator = Iterator;
|
||||
using const_iterator = ConstIterator;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
List()
|
||||
: root(nullptr)
|
||||
, tail(nullptr)
|
||||
, beginIt(Iterator(root))
|
||||
, endIt(Iterator(tail))
|
||||
, _size(0)
|
||||
, allocator(NodeAllocator())
|
||||
{
|
||||
}
|
||||
List(const List& other)
|
||||
{
|
||||
//TODO: improve
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
List(List&& other)
|
||||
: root(std::move(other.root))
|
||||
, tail(std::move(other.tail))
|
||||
, beginIt(std::move(other.beginIt))
|
||||
, endIt(std::move(other.endIt))
|
||||
, _size(std::move(other._size))
|
||||
{
|
||||
other._size = 0;
|
||||
}
|
||||
~List()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
List& operator=(const List& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
if(tail != nullptr)
|
||||
{
|
||||
delete tail;
|
||||
}
|
||||
_size = 0;
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
List& operator=(List&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
root = other.root;
|
||||
tail = other.tail;
|
||||
beginIt = other.beginIt;
|
||||
endIt = other.endIt;
|
||||
_size = other._size;
|
||||
other._size = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
T &front()
|
||||
{
|
||||
return root->data;
|
||||
}
|
||||
T &back()
|
||||
{
|
||||
return tail->prev->data;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (Node *tmp = root; tmp != tail;)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
deallocateNode(tmp->prev);
|
||||
}
|
||||
deallocateNode(tail);
|
||||
tail = nullptr;
|
||||
root = nullptr;
|
||||
}
|
||||
//Insert at the end
|
||||
iterator add(const T &value)
|
||||
{
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = allocateNode();
|
||||
tail = root;
|
||||
}
|
||||
tail->data = value;
|
||||
Node *newTail = allocateNode();
|
||||
newTail->prev = tail;
|
||||
newTail->next = nullptr;
|
||||
tail->next = newTail;
|
||||
iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
markIteratorDirty();
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
iterator add(T&& value)
|
||||
{
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = allocateNode();
|
||||
tail = root;
|
||||
}
|
||||
tail->data = std::move(value);
|
||||
Node *newTail = allocateNode();
|
||||
newTail->prev = tail;
|
||||
newTail->next = nullptr;
|
||||
tail->next = newTail;
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
markIteratorDirty();
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
iterator remove(iterator pos)
|
||||
{
|
||||
_size--;
|
||||
Node *prev = pos.node->prev;
|
||||
Node *next = pos.node->next;
|
||||
if (prev == nullptr)
|
||||
{
|
||||
root = next;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
if(next == nullptr)
|
||||
{
|
||||
root = prev;
|
||||
}
|
||||
else
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
delete pos.node;
|
||||
markIteratorDirty();
|
||||
return Iterator(next);
|
||||
}
|
||||
void popBack()
|
||||
{
|
||||
assert(_size > 0);
|
||||
remove(Iterator(tail->prev));
|
||||
}
|
||||
void popFront()
|
||||
{
|
||||
assert(_size > 0);
|
||||
remove(Iterator(root));
|
||||
}
|
||||
iterator insert(iterator pos, const T &value)
|
||||
{
|
||||
_size++;
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = allocateNode();
|
||||
root->data = value;
|
||||
tail = allocateNode();
|
||||
root->next = tail;
|
||||
root->prev = nullptr;
|
||||
tail->prev = root;
|
||||
tail->next = nullptr;
|
||||
markIteratorDirty();
|
||||
return beginIt;
|
||||
}
|
||||
Node *tmp = pos.node->prev;
|
||||
Node *newNode = allocateNode();
|
||||
newNode->data = value;
|
||||
tmp->next = newNode;
|
||||
newNode->prev = tmp;
|
||||
newNode->next = pos.node;
|
||||
pos.node->prev = newNode;
|
||||
return Iterator(newNode);
|
||||
}
|
||||
iterator find(const T &value)
|
||||
{
|
||||
for (Node *i = root; i != tail; i = i->next)
|
||||
{
|
||||
if (!(i->data < value) && !(value < i->data))
|
||||
{
|
||||
return iterator(i);
|
||||
}
|
||||
}
|
||||
return endIt;
|
||||
}
|
||||
bool empty()
|
||||
{
|
||||
return _size == 0;
|
||||
}
|
||||
size_type size()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
iterator begin()
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
const_iterator begin() const
|
||||
{
|
||||
return cbeginIt;
|
||||
}
|
||||
iterator end()
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
const_iterator end() const
|
||||
{
|
||||
return cendIt;
|
||||
}
|
||||
|
||||
private:
|
||||
void markIteratorDirty()
|
||||
{
|
||||
beginIt = Iterator(root);
|
||||
endIt = Iterator(tail);
|
||||
}
|
||||
Node *root;
|
||||
Node *tail;
|
||||
Iterator beginIt;
|
||||
Iterator endIt;
|
||||
uint32 _size;
|
||||
Node* allocateNode()
|
||||
{
|
||||
Node* node = allocator.allocate(1);
|
||||
std::memset(node, 0, sizeof(Node));
|
||||
assert(node != nullptr);
|
||||
return node;
|
||||
}
|
||||
void deallocateNode(Node* node)
|
||||
{
|
||||
allocator.deallocate(node, 1);
|
||||
}
|
||||
void markIteratorDirty()
|
||||
{
|
||||
beginIt = Iterator(root);
|
||||
endIt = Iterator(tail);
|
||||
cbeginIt = ConstIterator(root);
|
||||
cendIt = ConstIterator(tail);
|
||||
}
|
||||
Node *root;
|
||||
Node *tail;
|
||||
Iterator beginIt;
|
||||
Iterator endIt;
|
||||
ConstIterator cbeginIt;
|
||||
ConstIterator cendIt;
|
||||
uint32 _size;
|
||||
NodeAllocator allocator;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
using pointer = Pair<K, V>*;
|
||||
|
||||
Iterator(Node *x = nullptr)
|
||||
: node(x), traversal(Init_t::NO_INIT)
|
||||
: node(x)
|
||||
{
|
||||
}
|
||||
Iterator(Node *x, Array<Node *> &&beginIt)
|
||||
|
||||
@@ -70,13 +70,9 @@ ShaderCollection& ShaderMap::createShaders(
|
||||
modifyRenderPassMacros(renderPass, createInfo.defines);
|
||||
createInfo.name = getShaderNameFromRenderPassType(renderPass) + " Material " + material->getName();
|
||||
|
||||
std::ifstream codeStream("./shaders/" + getShaderNameFromRenderPassType(renderPass), std::ios::ate);
|
||||
auto fileSize = codeStream.tellg();
|
||||
codeStream.seekg(0);
|
||||
Array<char> buffer(static_cast<uint32>(fileSize));
|
||||
codeStream.read(buffer.data(), fileSize);
|
||||
std::ifstream codeStream("./shaders/" + getShaderNameFromRenderPassType(renderPass));
|
||||
|
||||
createInfo.shaderCode.add(std::string(buffer.data(), 0, fileSize));
|
||||
createInfo.shaderCode.add(std::string(std::istreambuf_iterator<char>{codeStream}, {}));
|
||||
|
||||
collection.vertexShader = graphics->createVertexShader(createInfo);
|
||||
|
||||
|
||||
+314
-313
@@ -2,27 +2,28 @@
|
||||
#include "Containers/Map.h"
|
||||
#include "EngineTypes.h"
|
||||
#include "Math/Math.h"
|
||||
//#include "ThreadPool.h"
|
||||
|
||||
#define DEFINE_REF(x) \
|
||||
typedef RefPtr<x> P##x; \
|
||||
typedef UniquePtr<x> UP##x; \
|
||||
typedef WeakPtr<x> W##x;
|
||||
typedef RefPtr<x> P##x; \
|
||||
typedef UniquePtr<x> UP##x; \
|
||||
typedef WeakPtr<x> W##x;
|
||||
|
||||
#define DECLARE_REF(x) \
|
||||
class x; \
|
||||
typedef RefPtr<x> P##x; \
|
||||
typedef UniquePtr<x> UP##x; \
|
||||
typedef WeakPtr<x> W##x;
|
||||
class x; \
|
||||
typedef RefPtr<x> P##x; \
|
||||
typedef UniquePtr<x> UP##x; \
|
||||
typedef WeakPtr<x> W##x;
|
||||
|
||||
|
||||
#define DECLARE_NAME_REF(nmsp, x) \
|
||||
namespace nmsp \
|
||||
{ \
|
||||
class x; \
|
||||
typedef RefPtr<x> P##x; \
|
||||
typedef UniquePtr<x> UP##x; \
|
||||
typedef WeakPtr<x> W##x; \
|
||||
}
|
||||
namespace nmsp \
|
||||
{ \
|
||||
class x; \
|
||||
typedef RefPtr<x> P##x; \
|
||||
typedef UniquePtr<x> UP##x; \
|
||||
typedef WeakPtr<x> W##x; \
|
||||
}
|
||||
|
||||
extern Seele::Map<void *, void *> registeredObjects;
|
||||
extern std::mutex registeredObjectsLock;
|
||||
@@ -34,332 +35,332 @@ template <typename T>
|
||||
class RefObject
|
||||
{
|
||||
public:
|
||||
RefObject(T *ptr)
|
||||
: handle(ptr), refCount(1)
|
||||
{
|
||||
registeredObjects[ptr] = this;
|
||||
}
|
||||
inline RefObject(const RefObject &rhs)
|
||||
: handle(rhs.handle), refCount(rhs.refCount)
|
||||
{
|
||||
}
|
||||
RefObject(RefObject &&rhs)
|
||||
: handle(std::move(rhs.handle)), refCount(std::move(rhs.refCount))
|
||||
{
|
||||
}
|
||||
~RefObject()
|
||||
{
|
||||
{
|
||||
std::unique_lock lock(registeredObjectsLock);
|
||||
registeredObjects.erase(handle);
|
||||
}
|
||||
#pragma warning( disable: 4150)
|
||||
delete handle;
|
||||
#pragma warning( default: 4150)
|
||||
}
|
||||
RefObject &operator=(const RefObject &rhs)
|
||||
{
|
||||
if (*this != rhs)
|
||||
{
|
||||
handle = rhs.handle;
|
||||
refCount = rhs.refCount;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
RefObject &operator=(RefObject &&rhs)
|
||||
{
|
||||
if (*this != rhs)
|
||||
{
|
||||
handle = std::move(rhs.handle);
|
||||
refCount = std::move(rhs.refCount);
|
||||
rhs.handle = nullptr;
|
||||
rhs.refCount = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
inline bool operator==(const RefObject &other) const
|
||||
{
|
||||
return handle == other.handle;
|
||||
}
|
||||
inline bool operator!=(const RefObject &other) const
|
||||
{
|
||||
return handle != other.handle;
|
||||
}
|
||||
inline bool operator<(const RefObject &other) const
|
||||
{
|
||||
return handle < other.handle;
|
||||
}
|
||||
void addRef()
|
||||
{
|
||||
refCount++;
|
||||
}
|
||||
inline void removeRef()
|
||||
{
|
||||
refCount--;
|
||||
if (refCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
T *getHandle() const
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
RefObject(T *ptr)
|
||||
: handle(ptr), refCount(1)
|
||||
{
|
||||
registeredObjects[ptr] = this;
|
||||
}
|
||||
inline RefObject(const RefObject &rhs)
|
||||
: handle(rhs.handle), refCount(rhs.refCount)
|
||||
{
|
||||
}
|
||||
RefObject(RefObject &&rhs)
|
||||
: handle(std::move(rhs.handle)), refCount(std::move(rhs.refCount))
|
||||
{
|
||||
}
|
||||
~RefObject()
|
||||
{
|
||||
{
|
||||
std::unique_lock lock(registeredObjectsLock);
|
||||
registeredObjects.erase(handle);
|
||||
}
|
||||
#pragma warning( disable: 4150)
|
||||
delete handle;
|
||||
#pragma warning( default: 4150)
|
||||
}
|
||||
RefObject &operator=(const RefObject &rhs)
|
||||
{
|
||||
if (*this != rhs)
|
||||
{
|
||||
handle = rhs.handle;
|
||||
refCount = rhs.refCount;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
RefObject &operator=(RefObject &&rhs)
|
||||
{
|
||||
if (*this != rhs)
|
||||
{
|
||||
handle = std::move(rhs.handle);
|
||||
refCount = std::move(rhs.refCount);
|
||||
rhs.handle = nullptr;
|
||||
rhs.refCount = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
inline bool operator==(const RefObject &other) const
|
||||
{
|
||||
return handle == other.handle;
|
||||
}
|
||||
inline bool operator!=(const RefObject &other) const
|
||||
{
|
||||
return handle != other.handle;
|
||||
}
|
||||
inline bool operator<(const RefObject &other) const
|
||||
{
|
||||
return handle < other.handle;
|
||||
}
|
||||
void addRef()
|
||||
{
|
||||
refCount++;
|
||||
}
|
||||
inline void removeRef()
|
||||
{
|
||||
refCount--;
|
||||
if (refCount == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
T *getHandle() const
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
private:
|
||||
T *handle;
|
||||
std::atomic_uint64_t refCount;
|
||||
friend class RefPtr<T>;
|
||||
T *handle;
|
||||
std::atomic_uint64_t refCount;
|
||||
friend class RefPtr<T>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class RefPtr
|
||||
{
|
||||
public:
|
||||
RefPtr()
|
||||
{
|
||||
object = nullptr;
|
||||
}
|
||||
RefPtr(nullptr_t)
|
||||
{
|
||||
object = nullptr;
|
||||
}
|
||||
RefPtr(T *ptr)
|
||||
{
|
||||
std::unique_lock l(registeredObjectsLock);
|
||||
auto registeredObj = registeredObjects.find(ptr);
|
||||
// get here for thread safetly
|
||||
auto registeredEnd = registeredObjects.end();
|
||||
if (registeredObj == registeredEnd)
|
||||
{
|
||||
object = new RefObject<T>(ptr);
|
||||
l.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
l.unlock();
|
||||
object = (RefObject<T> *)registeredObj->value;
|
||||
object->addRef();
|
||||
}
|
||||
}
|
||||
explicit RefPtr(RefObject<T> *other)
|
||||
: object(other)
|
||||
{
|
||||
object->addRef();
|
||||
}
|
||||
inline RefPtr(const RefPtr &other)
|
||||
: object(other.object)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->addRef();
|
||||
}
|
||||
}
|
||||
RefPtr(RefPtr &&rhs)
|
||||
: object(std::move(rhs.object))
|
||||
{
|
||||
rhs.object = nullptr;
|
||||
//Dont change references, they stay the same
|
||||
}
|
||||
template <typename F>
|
||||
RefPtr(const RefPtr<F> &other)
|
||||
{
|
||||
F *f = other.getObject()->getHandle();
|
||||
assert(static_cast<T *>(f));
|
||||
object = (RefObject<T> *)other.getObject();
|
||||
object->addRef();
|
||||
}
|
||||
RefPtr()
|
||||
{
|
||||
object = nullptr;
|
||||
}
|
||||
RefPtr(nullptr_t)
|
||||
{
|
||||
object = nullptr;
|
||||
}
|
||||
RefPtr(T *ptr)
|
||||
{
|
||||
std::unique_lock l(registeredObjectsLock);
|
||||
auto registeredObj = registeredObjects.find(ptr);
|
||||
// get here for thread safetly
|
||||
auto registeredEnd = registeredObjects.end();
|
||||
if (registeredObj == registeredEnd)
|
||||
{
|
||||
object = new RefObject<T>(ptr);
|
||||
l.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
l.unlock();
|
||||
object = (RefObject<T> *)registeredObj->value;
|
||||
object->addRef();
|
||||
}
|
||||
}
|
||||
explicit RefPtr(RefObject<T> *other)
|
||||
: object(other)
|
||||
{
|
||||
object->addRef();
|
||||
}
|
||||
inline RefPtr(const RefPtr &other)
|
||||
: object(other.object)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->addRef();
|
||||
}
|
||||
}
|
||||
RefPtr(RefPtr &&rhs)
|
||||
: object(std::move(rhs.object))
|
||||
{
|
||||
rhs.object = nullptr;
|
||||
//Dont change references, they stay the same
|
||||
}
|
||||
template <typename F>
|
||||
RefPtr(const RefPtr<F> &other)
|
||||
{
|
||||
F *f = other.getObject()->getHandle();
|
||||
assert(static_cast<T *>(f));
|
||||
object = (RefObject<T> *)other.getObject();
|
||||
object->addRef();
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
RefPtr<F> cast()
|
||||
{
|
||||
T *t = object->getHandle();
|
||||
F *f = dynamic_cast<F *>(t);
|
||||
if (f == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
RefObject<F> *newObject = (RefObject<F> *)object;
|
||||
return RefPtr<F>(newObject);
|
||||
}
|
||||
template <typename F>
|
||||
RefPtr<F> cast()
|
||||
{
|
||||
T *t = object->getHandle();
|
||||
F *f = dynamic_cast<F *>(t);
|
||||
if (f == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
RefObject<F> *newObject = (RefObject<F> *)object;
|
||||
return RefPtr<F>(newObject);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
const RefPtr<F> cast() const
|
||||
{
|
||||
T *t = object->getHandle();
|
||||
F *f = dynamic_cast<F *>(t);
|
||||
if (f == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
RefObject<F> *newObject = (RefObject<F> *)object;
|
||||
return RefPtr<F>(newObject);
|
||||
}
|
||||
template <typename F>
|
||||
const RefPtr<F> cast() const
|
||||
{
|
||||
T *t = object->getHandle();
|
||||
F *f = dynamic_cast<F *>(t);
|
||||
if (f == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
RefObject<F> *newObject = (RefObject<F> *)object;
|
||||
return RefPtr<F>(newObject);
|
||||
}
|
||||
|
||||
RefPtr &operator=(const RefPtr &other)
|
||||
{
|
||||
if (*this != other)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->removeRef();
|
||||
}
|
||||
object = other.object;
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->addRef();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
RefPtr &operator=(RefPtr &&rhs)
|
||||
{
|
||||
if (*this != rhs)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->removeRef();
|
||||
}
|
||||
object = std::move(rhs.object);
|
||||
rhs.object = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
~RefPtr()
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->removeRef();
|
||||
}
|
||||
}
|
||||
inline bool operator==(const RefPtr &other) const
|
||||
{
|
||||
return object == other.object;
|
||||
}
|
||||
inline bool operator!=(const RefPtr &other) const
|
||||
{
|
||||
return object != other.object;
|
||||
}
|
||||
bool operator<(const RefPtr &other) const
|
||||
{
|
||||
return object < other.object;
|
||||
}
|
||||
inline T *operator->()
|
||||
{
|
||||
assert(object != nullptr);
|
||||
return object->handle;
|
||||
}
|
||||
inline const T *operator->() const
|
||||
{
|
||||
assert(object != nullptr);
|
||||
return object->handle;
|
||||
}
|
||||
RefObject<T> *getObject() const
|
||||
{
|
||||
return object;
|
||||
}
|
||||
inline T *getHandle()
|
||||
{
|
||||
return object->getHandle();
|
||||
}
|
||||
inline const T *getHandle() const
|
||||
{
|
||||
return object->getHandle();
|
||||
}
|
||||
RefPtr &operator=(const RefPtr &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->removeRef();
|
||||
}
|
||||
object = other.object;
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->addRef();
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
RefPtr &operator=(RefPtr &&rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->removeRef();
|
||||
}
|
||||
object = std::move(rhs.object);
|
||||
rhs.object = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
~RefPtr()
|
||||
{
|
||||
if (object != nullptr)
|
||||
{
|
||||
object->removeRef();
|
||||
}
|
||||
}
|
||||
inline bool operator==(const RefPtr &other) const
|
||||
{
|
||||
return object == other.object;
|
||||
}
|
||||
inline bool operator!=(const RefPtr &other) const
|
||||
{
|
||||
return object != other.object;
|
||||
}
|
||||
bool operator<(const RefPtr &other) const
|
||||
{
|
||||
return object < other.object;
|
||||
}
|
||||
inline T *operator->()
|
||||
{
|
||||
assert(object != nullptr);
|
||||
return object->handle;
|
||||
}
|
||||
inline const T *operator->() const
|
||||
{
|
||||
assert(object != nullptr);
|
||||
return object->handle;
|
||||
}
|
||||
RefObject<T> *getObject() const
|
||||
{
|
||||
return object;
|
||||
}
|
||||
inline T *getHandle()
|
||||
{
|
||||
return object->getHandle();
|
||||
}
|
||||
inline const T *getHandle() const
|
||||
{
|
||||
return object->getHandle();
|
||||
}
|
||||
|
||||
private:
|
||||
RefObject<T> *object;
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar, const unsigned int)
|
||||
{
|
||||
ar & *object->getHandle();
|
||||
}
|
||||
RefObject<T> *object;
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar, const unsigned int)
|
||||
{
|
||||
ar & *object->getHandle();
|
||||
}
|
||||
};
|
||||
template <typename T>
|
||||
class UniquePtr
|
||||
{
|
||||
public:
|
||||
UniquePtr()
|
||||
: handle(nullptr)
|
||||
{
|
||||
}
|
||||
UniquePtr(nullptr_t)
|
||||
: handle(nullptr)
|
||||
{
|
||||
}
|
||||
UniquePtr(T *ptr)
|
||||
: handle(ptr)
|
||||
{
|
||||
}
|
||||
UniquePtr(const UniquePtr &rhs) = delete;
|
||||
UniquePtr(UniquePtr &&rhs) noexcept
|
||||
: handle(rhs.handle)
|
||||
{
|
||||
rhs.handle = nullptr;
|
||||
}
|
||||
UniquePtr &operator=(const UniquePtr &rhs) = delete;
|
||||
UniquePtr &operator=(UniquePtr &&rhs)
|
||||
{
|
||||
handle = rhs.handle;
|
||||
rhs.handle = nullptr;
|
||||
return *this;
|
||||
}
|
||||
~UniquePtr()
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
inline bool operator==(const UniquePtr &other) const
|
||||
{
|
||||
return handle == other.handle;
|
||||
}
|
||||
inline bool operator!=(const UniquePtr &other) const
|
||||
{
|
||||
return handle != other.handle;
|
||||
}
|
||||
inline T *operator->()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
bool isValid()
|
||||
{
|
||||
return handle != nullptr;
|
||||
}
|
||||
UniquePtr()
|
||||
: handle(nullptr)
|
||||
{
|
||||
}
|
||||
UniquePtr(nullptr_t)
|
||||
: handle(nullptr)
|
||||
{
|
||||
}
|
||||
UniquePtr(T *ptr)
|
||||
: handle(ptr)
|
||||
{
|
||||
}
|
||||
UniquePtr(const UniquePtr &rhs) = delete;
|
||||
UniquePtr(UniquePtr &&rhs) noexcept
|
||||
: handle(rhs.handle)
|
||||
{
|
||||
rhs.handle = nullptr;
|
||||
}
|
||||
UniquePtr &operator=(const UniquePtr &rhs) = delete;
|
||||
UniquePtr &operator=(UniquePtr &&rhs)
|
||||
{
|
||||
handle = rhs.handle;
|
||||
rhs.handle = nullptr;
|
||||
return *this;
|
||||
}
|
||||
~UniquePtr()
|
||||
{
|
||||
delete handle;
|
||||
}
|
||||
inline bool operator==(const UniquePtr &other) const
|
||||
{
|
||||
return handle == other.handle;
|
||||
}
|
||||
inline bool operator!=(const UniquePtr &other) const
|
||||
{
|
||||
return handle != other.handle;
|
||||
}
|
||||
inline T *operator->()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
bool isValid()
|
||||
{
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
T *handle;
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar, const unsigned int version)
|
||||
{
|
||||
ar & *handle;
|
||||
}
|
||||
T *handle;
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive& ar, const unsigned int version)
|
||||
{
|
||||
ar & *handle;
|
||||
}
|
||||
};
|
||||
//A weak pointer has no ownership over an object and thus cant delete it
|
||||
template <typename T>
|
||||
class WeakPtr
|
||||
{
|
||||
public:
|
||||
WeakPtr()
|
||||
: pointer(nullptr)
|
||||
{
|
||||
}
|
||||
WeakPtr(RefPtr<T> &sharedPtr)
|
||||
: pointer(sharedPtr)
|
||||
{
|
||||
}
|
||||
WeakPtr &operator=(WeakPtr<T> &weakPtr)
|
||||
{
|
||||
pointer = weakPtr.pointer;
|
||||
return *this;
|
||||
}
|
||||
WeakPtr &operator=(RefPtr<T> &sharedPtr)
|
||||
{
|
||||
pointer = sharedPtr;
|
||||
return *this;
|
||||
}
|
||||
WeakPtr()
|
||||
: pointer(nullptr)
|
||||
{
|
||||
}
|
||||
WeakPtr(RefPtr<T> &sharedPtr)
|
||||
: pointer(sharedPtr)
|
||||
{
|
||||
}
|
||||
WeakPtr &operator=(WeakPtr<T> &weakPtr)
|
||||
{
|
||||
pointer = weakPtr.pointer;
|
||||
return *this;
|
||||
}
|
||||
WeakPtr &operator=(RefPtr<T> &sharedPtr)
|
||||
{
|
||||
pointer = sharedPtr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<T> pointer;
|
||||
RefPtr<T> pointer;
|
||||
};
|
||||
} // namespace Seele
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/List.h"
|
||||
#include <semaphore>
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
static ThreadPool gThreadPool;
|
||||
|
||||
void Event::await_suspend(std::coroutine_handle<JobPromise> h)
|
||||
{
|
||||
getGlobalThreadPool().addJob(Job(h));
|
||||
}
|
||||
|
||||
Job JobPromise::get_return_object() noexcept {
|
||||
return Job { std::coroutine_handle<JobPromise>::from_promise(*this) };
|
||||
@@ -14,7 +18,16 @@ ThreadPool::ThreadPool(uint32 threadCount)
|
||||
|
||||
}
|
||||
|
||||
static ThreadPool& getGlobalThreadPool()
|
||||
ThreadPool::~ThreadPool()
|
||||
{
|
||||
return gThreadPool;
|
||||
for(auto& thread : workers)
|
||||
{
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
ThreadPool& Seele::getGlobalThreadPool()
|
||||
{
|
||||
static ThreadPool threadPool;
|
||||
return threadPool;
|
||||
}
|
||||
+26
-16
@@ -1,23 +1,35 @@
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include <coroutine>
|
||||
#include "MinimalEngine.h"
|
||||
#include "Containers/List.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
enum class JobStage
|
||||
struct JobPromise;
|
||||
struct Event
|
||||
{
|
||||
INPUT,
|
||||
GAMELOGIC,
|
||||
RENDER,
|
||||
DONT_CARE
|
||||
public:
|
||||
void raise()
|
||||
{
|
||||
flag.test_and_set();
|
||||
flag.notify_all();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
flag.clear();
|
||||
}
|
||||
bool await_ready() { return flag.test(); }
|
||||
void await_suspend(std::coroutine_handle<JobPromise> h);
|
||||
void await_resume() {}
|
||||
private:
|
||||
std::atomic_flag flag;
|
||||
};
|
||||
struct [[nodiscard]] Job;
|
||||
struct JobPromise
|
||||
{
|
||||
Job get_return_object() noexcept;
|
||||
|
||||
std::suspend_never initial_suspend() const noexcept { return {}; }
|
||||
std::suspend_always initial_suspend() const noexcept { return {}; }
|
||||
std::suspend_never final_suspend() const noexcept { return {}; }
|
||||
|
||||
void return_void() noexcept {}
|
||||
@@ -31,9 +43,8 @@ struct [[nodiscard]] Job
|
||||
public:
|
||||
using promise_type = JobPromise;
|
||||
|
||||
explicit Job(std::coroutine_handle<task_promise> handle, JobStage stage = JobStage::DONT_CARE)
|
||||
explicit Job(std::coroutine_handle<JobPromise> handle)
|
||||
: handle(handle)
|
||||
, stage(stage)
|
||||
{}
|
||||
~Job()
|
||||
{
|
||||
@@ -44,22 +55,21 @@ public:
|
||||
}
|
||||
private:
|
||||
std::coroutine_handle<JobPromise> handle;
|
||||
JobStage stage;
|
||||
};
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
ThreadPool(uint32 threadCount = std::thread::hardware_concurrency);
|
||||
ThreadPool(uint32 threadCount = std::thread::hardware_concurrency());
|
||||
virtual ~ThreadPool();
|
||||
void schedule(std::function<void()> function)
|
||||
void addJob(Job&& job)
|
||||
{
|
||||
|
||||
jobs.add(std::move(job));
|
||||
}
|
||||
private:
|
||||
Array<std::thread> workers;
|
||||
Map<JobStage, List<Job>> jobs;
|
||||
std::vector<std::thread> workers;
|
||||
List<Job> jobs;
|
||||
void threadLoop();
|
||||
};
|
||||
static ThreadPool& getGlobalThreadPool();
|
||||
extern ThreadPool& getGlobalThreadPool();
|
||||
} // namespace Seele
|
||||
|
||||
@@ -16,7 +16,7 @@ void Window::addView(PView view)
|
||||
{
|
||||
WindowView* windowView = new WindowView();
|
||||
windowView->view = view;
|
||||
windowView->worker = std::thread(&Window::viewWorker, this, windowView);
|
||||
//windowView->worker = std::thread(&Window::viewWorker, this, windowView);
|
||||
views.add(windowView);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,16 @@ void Window::render()
|
||||
{
|
||||
windowView->view->beginUpdate();
|
||||
windowView->view->update();
|
||||
windowView->view->commitUpdate();
|
||||
windowView->view->prepareRender();
|
||||
{
|
||||
std::unique_lock lock(windowView->workerMutex);
|
||||
windowView->view->commitUpdate();
|
||||
}
|
||||
windowView->updateFinished.raise();
|
||||
{
|
||||
std::unique_lock lock(windowView->workerMutex);
|
||||
windowView->view->prepareRender();
|
||||
}
|
||||
windowView->updateFinished.reset();
|
||||
windowView->view->render();
|
||||
}
|
||||
gfxHandle->endFrame();
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "View.h"
|
||||
#include "ThreadPool.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct WindowView
|
||||
{
|
||||
PView view;
|
||||
Event updateFinished;
|
||||
std::thread worker;
|
||||
std::mutex workerMutex;
|
||||
};
|
||||
|
||||
@@ -35,12 +35,3 @@ PWindow WindowManager::addWindow(const WindowCreateInfo &createInfo)
|
||||
windows.add(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
void WindowManager::render()
|
||||
{
|
||||
for(auto window : windows)
|
||||
{
|
||||
window->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ public:
|
||||
WindowManager();
|
||||
~WindowManager();
|
||||
PWindow addWindow(const WindowCreateInfo &createInfo);
|
||||
void render();
|
||||
static Gfx::PGraphics getGraphics()
|
||||
{
|
||||
return graphics;
|
||||
|
||||
+2
-2
@@ -34,9 +34,9 @@ int main()
|
||||
PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
|
||||
window->addView(inspectorView);
|
||||
sceneView->setFocused();
|
||||
while (windowManager->isActive())
|
||||
while(true)
|
||||
{
|
||||
windowManager->render();
|
||||
window->render();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user