Polymorphic Map and threadpool

This commit is contained in:
2021-11-01 20:25:16 +01:00
parent 9c48c48f8c
commit 1b7ab9b1f1
20 changed files with 1442 additions and 1280 deletions
+2
View File
@@ -21,7 +21,9 @@ set(NSAM_ROOT ${EXTERNAL_ROOT}/aftermath)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)
set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_STATIC_LIBS OFF)
if(WIN32)
set(Boost_LIB_PREFIX lib) set(Boost_LIB_PREFIX lib)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE})
#Workaround for vs, because it places artifacts into an additional subfolder #Workaround for vs, because it places artifacts into an additional subfolder
+1
View File
@@ -34,6 +34,7 @@ void TextureAsset::load()
setStatus(Status::Loading); setStatus(Status::Loading);
ktxTexture2* kTexture; ktxTexture2* kTexture;
// TODO: consider return // TODO: consider return
std::cout << "Loading texture " << getFullPath() << std::endl;
ktxTexture2_CreateFromNamedFile(getFullPath().c_str(), ktxTexture2_CreateFromNamedFile(getFullPath().c_str(),
KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT,
&kTexture); &kTexture);
-1
View File
@@ -28,7 +28,6 @@ void TextureLoader::importAsset(const std::filesystem::path& filePath)
PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string()); PTextureAsset asset = new TextureAsset(assetFileName.replace_extension("asset").filename().generic_string());
asset->setStatus(Asset::Status::Loading); asset->setStatus(Asset::Status::Loading);
asset->setTexture(placeholderAsset->getTexture()); asset->setTexture(placeholderAsset->getTexture());
std::cout << "Loading texture " << asset->getFileName() << std::endl;
AssetRegistry::get().registerTexture(asset); AssetRegistry::get().registerTexture(asset);
futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable { futures.add(std::async(std::launch::async, [this, filePath, asset] () mutable {
using namespace std::chrono_literals; using namespace std::chrono_literals;
+37 -41
View File
@@ -112,7 +112,7 @@ namespace Seele
assert(_data != nullptr); assert(_data != nullptr);
markIteratorDirty(); markIteratorDirty();
} }
constexpr Array(size_type size, const T& value, const allocator_type& alloc = allocator_type()) constexpr Array(size_type size, const value_type& value, const allocator_type& alloc = allocator_type())
: arraySize(size) : arraySize(size)
, allocated(size) , allocated(size)
, allocator(alloc) , allocator(alloc)
@@ -169,21 +169,16 @@ namespace Seele
{ {
if (this != &other) if (this != &other)
{ {
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value )
&& !std::allocator_traits<allocator_type>::is_always_equal::value)
{ {
if(allocator != other.allocator) if (!std::allocator_traits<allocator_type>::is_always_equal::value
&& allocator != other.allocator)
{ {
deallocateArray(_data, allocated); deallocateArray(_data, allocated);
_data = nullptr; _data = nullptr;
} }
}
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value)
{
allocator = other.allocator; allocator = other.allocator;
} }
else
{}
if(other.arraySize > allocated) if(other.arraySize > allocated)
{ {
if(_data != nullptr) if(_data != nullptr)
@@ -203,17 +198,14 @@ namespace Seele
{ {
if (this != &other) if (this != &other)
{ {
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
&& !std::allocator_traits<allocator_type>::is_always_equal::value)
{ {
if(allocator != other.allocator) if (!std::allocator_traits<allocator_type>::is_always_equal::value
&& allocator != other.allocator)
{ {
deallocateArray(_data, allocated); deallocateArray(_data, allocated);
_data = nullptr; _data = nullptr;
} }
}
if constexpr (std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value)
{
allocator = std::move(other.allocator); allocator = std::move(other.allocator);
} }
if (_data != nullptr) if (_data != nullptr)
@@ -248,59 +240,59 @@ namespace Seele
return !(*this == other); return !(*this == other);
} }
constexpr Iterator find(const T &item) constexpr iterator find(const value_type &item)
{ {
for (uint32 i = 0; i < arraySize; ++i) for (uint32 i = 0; i < arraySize; ++i)
{ {
if (_data[i] == item) if (_data[i] == item)
{ {
return Iterator(&_data[i]); return iterator(&_data[i]);
} }
} }
return endIt; return endIt;
} }
constexpr Iterator find(T&& item) constexpr iterator find(value_type&& item)
{ {
for (uint32 i = 0; i < arraySize; ++i) for (uint32 i = 0; i < arraySize; ++i)
{ {
if (_data[i] == item) if (_data[i] == item)
{ {
return Iterator(&_data[i]); return iterator(&_data[i]);
} }
} }
return endIt; return endIt;
} }
constexpr Allocator get_allocator() const constexpr allocator_type get_allocator() const
{ {
return allocator; return allocator;
} }
constexpr Iterator begin() const constexpr iterator begin() const
{ {
return beginIt; return beginIt;
} }
constexpr Iterator end() const constexpr iterator end() const
{ {
return endIt; return endIt;
} }
constexpr ConstIterator cbegin() const constexpr const_iterator cbegin() const
{ {
return beginIt; return beginIt;
} }
constexpr ConstIterator cend() const constexpr const_iterator cend() const
{ {
return endIt; return endIt;
} }
constexpr T &add(const T &item = T()) constexpr reference add(const value_type &item = value_type())
{ {
return addInternal(item); return addInternal(item);
} }
constexpr T &add(T&& item) constexpr reference add(value_type&& item)
{ {
return addInternal(std::forward<T>(item)); return addInternal(std::forward<T>(item));
} }
constexpr T &addUnique(const T &item = T()) constexpr reference addUnique(const value_type &item = value_type())
{ {
Iterator it; iterator it;
if((it = std::move(find(item))) != endIt) if((it = std::move(find(item))) != endIt)
{ {
return *it; return *it;
@@ -308,7 +300,7 @@ namespace Seele
return addInternal(item); return addInternal(item);
} }
template<typename... args> template<typename... args>
constexpr T &emplace(args... arguments) constexpr reference emplace(args... arguments)
{ {
if (arraySize == allocated) if (arraySize == allocated)
{ {
@@ -316,10 +308,8 @@ namespace Seele
allocated = calculateGrowth(newSize); allocated = calculateGrowth(newSize);
T *tempArray = allocateArray(allocated); T *tempArray = allocateArray(allocated);
assert(tempArray != nullptr); assert(tempArray != nullptr);
for (size_type i = 0; i < arraySize; ++i)
{ std::uninitialized_move(begin(), end(), Iterator(tempArray));
tempArray[i] = std::move(_data[i]);
}
deallocateArray(_data, arraySize); deallocateArray(_data, arraySize);
_data = tempArray; _data = tempArray;
} }
@@ -327,7 +317,7 @@ namespace Seele
markIteratorDirty(); markIteratorDirty();
return _data[arraySize - 1]; return _data[arraySize - 1];
} }
constexpr void remove(Iterator it, bool keepOrder = true) constexpr void remove(iterator it, bool keepOrder = true)
{ {
remove(it - beginIt, keepOrder); remove(it - beginIt, keepOrder);
} }
@@ -351,7 +341,7 @@ namespace Seele
{ {
resizeInternal(newSize, std::move(T())); resizeInternal(newSize, std::move(T()));
} }
constexpr void resize(size_type newSize, const T& value) constexpr void resize(size_type newSize, const value_type& value)
{ {
resizeInternal(newSize, value); resizeInternal(newSize, value);
} }
@@ -367,11 +357,11 @@ namespace Seele
allocated = 0; allocated = 0;
markIteratorDirty(); markIteratorDirty();
} }
inline size_type indexOf(Iterator iterator) inline size_type indexOf(iterator iterator)
{ {
return iterator - beginIt; return iterator - beginIt;
} }
inline size_type indexOf(ConstIterator iterator) const inline size_type indexOf(const_iterator iterator) const
{ {
return iterator.p - beginIt.p; return iterator.p - beginIt.p;
} }
@@ -395,12 +385,18 @@ namespace Seele
{ {
return allocated; return allocated;
} }
inline T *data() const inline pointer data() const
{ {
return _data; return _data;
} }
inline T &back() const inline reference front() const
{ {
assert(arraySize > 0);
return _data[0];
}
inline reference back() const
{
assert(arraySize > 0);
return _data[arraySize - 1]; return _data[arraySize - 1];
} }
void pop() void pop()
@@ -408,12 +404,12 @@ namespace Seele
arraySize--; arraySize--;
markIteratorDirty(); markIteratorDirty();
} }
constexpr inline T &operator[](size_type index) constexpr inline reference operator[](size_type index)
{ {
assert(index < arraySize); assert(index < arraySize);
return _data[index]; return _data[index];
} }
constexpr inline const T &operator[](size_type index) const constexpr inline const reference operator[](size_type index) const
{ {
assert(index < arraySize); assert(index < arraySize);
return _data[index]; return _data[index];
+24 -7
View File
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include <xmemory> #include <memory_resource>
namespace Seele namespace Seele
{ {
@@ -187,11 +187,11 @@ public:
return *this; return *this;
} }
T &front() reference front()
{ {
return root->data; return root->data;
} }
T &back() reference back()
{ {
return tail->prev->data; return tail->prev->data;
} }
@@ -218,7 +218,7 @@ public:
root = allocateNode(); root = allocateNode();
tail = root; tail = root;
} }
tail->data = value; initializeNode(tail, value);
Node *newTail = allocateNode(); Node *newTail = allocateNode();
newTail->prev = tail; newTail->prev = tail;
newTail->next = nullptr; newTail->next = nullptr;
@@ -236,7 +236,7 @@ public:
root = allocateNode(); root = allocateNode();
tail = root; tail = root;
} }
tail->data = std::move(value); initializeNode(tail, std::move(value));
Node *newTail = allocateNode(); Node *newTail = allocateNode();
newTail->prev = tail; newTail->prev = tail;
newTail->next = nullptr; newTail->next = nullptr;
@@ -247,6 +247,13 @@ public:
_size++; _size++;
return insertedElement; return insertedElement;
} }
// front + popFront
value_type&& retrieve()
{
auto&& temp = std::move(root->data);
popFront();
return std::move(temp);
}
iterator remove(iterator pos) iterator remove(iterator pos)
{ {
_size--; _size--;
@@ -299,7 +306,7 @@ public:
} }
Node *tmp = pos.node->prev; Node *tmp = pos.node->prev;
Node *newNode = allocateNode(); Node *newNode = allocateNode();
newNode->data = value; initializeNode(newNode, value);
tmp->next = newNode; tmp->next = newNode;
newNode->prev = tmp; newNode->prev = tmp;
newNode->next = pos.node; newNode->next = pos.node;
@@ -346,10 +353,20 @@ private:
Node* allocateNode() Node* allocateNode()
{ {
Node* node = allocator.allocate(1); Node* node = allocator.allocate(1);
std::memset(node, 0, sizeof(Node));
assert(node != nullptr); assert(node != nullptr);
node->prev = nullptr;
node->next = nullptr;
return node; return node;
} }
template<typename Type>
void initializeNode(Node* node, Type&& data)
{
std::allocator_traits<NodeAllocator>::construct(allocator,
node,
node->prev,
node->next,
std::forward<Type>(data));
}
void deallocateNode(Node* node) void deallocateNode(Node* node)
{ {
allocator.deallocate(node, 1); allocator.deallocate(node, 1);
+173 -180
View File
@@ -11,18 +11,26 @@ public:
Pair() Pair()
: key(K()), value(V()) : key(K()), value(V())
{} {}
Pair(const Pair& other) = default;
Pair(Pair&& other) = default;
~Pair(){}
Pair& operator=(const Pair& other) = default;
Pair& operator=(Pair&& other) = default;
template<class KeyType> template<class KeyType>
explicit Pair(KeyType&& key) explicit Pair(KeyType&& key)
: key(key), value(V()) : key(std::forward<KeyType>(key)), value(V())
{} {}
template<class KeyType, class ValueType> template<class KeyType, class ValueType>
explicit Pair(KeyType&& key, ValueType&& value) explicit Pair(KeyType&& key, ValueType&& value)
: key(std::move(key)), value(std::move(value)) : key(std::forward<KeyType>(key)), value(std::forward<ValueType>(value))
{} {}
K key; K key;
V value; V value;
}; };
template <typename K, typename V> template <typename K,
typename V,
typename Compare = std::less<K>,
typename Allocator = std::pmr::polymorphic_allocator<Pair<const K,V>>>
struct Map struct Map
{ {
private: private:
@@ -35,158 +43,49 @@ private:
: leftChild(nullptr), rightChild(nullptr), pair() : leftChild(nullptr), rightChild(nullptr), pair()
{ {
} }
template<class KeyType, class ValueType> Node(const Node& other) = default;
explicit Node(KeyType&& key, ValueType&& value) Node(Node&& other) = default;
: leftChild(nullptr), rightChild(nullptr), pair(key, value) Node& operator=(const Node& other) = default;
{ Node& operator=(Node&& other) = default;
} Node(K key)
Node(const Node& other) : leftChild(nullptr)
: pair(other.pair.key, other.pair.value) , rightChild(nullptr)
{ , pair(std::move(key))
if(other.leftChild != nullptr)
{
leftChild = new Node(*other.leftChild);
}
if(other.rightChild != nullptr)
{
rightChild = new Node(*other.rightChild);
}
}
Node(Node&& other)
: leftChild(std::move(other.leftChild)), rightChild(std::move(other.rightChild))
{ {
} }
~Node() ~Node()
{ {
if (leftChild != nullptr)
{
delete leftChild;
}
if (rightChild != nullptr)
{
delete rightChild;
}
}
Node& operator=(const Node& other)
{
if(this != &other)
{
if(leftChild != nullptr)
{
delete leftChild;
}
if(rightChild != nullptr)
{
delete rightChild;
}
if(other.leftChild != nullptr)
{
leftChild = new Node(*other.leftChild);
}
if(other.rightChild != nullptr)
{
rightChild = new Node(*other.rightChild);
}
}
}
Node& operator=(Node&& other)
{
if(this != &other)
{
if(leftChild != nullptr)
{
delete leftChild;
}
if(rightChild != nullptr)
{
delete rightChild;
}
leftChild = std::move(other.leftChild);
rightChild = std::move(other.rightChild);
}
return *this;
} }
}; };
using NodeAlloc = std::allocator_traits<Allocator>::template rebind_alloc<Node>;
public: public:
Map() template<typename PairType>
: root(nullptr) class IteratorBase
, beginIt(nullptr)
, endIt(nullptr)
, iteratorsDirty(false)
, _size(0)
{
}
Map(const Map& other)
: root(new Node(*other.root))
, _size(other._size)
{
refreshIterators();
}
Map(Map&& other)
: root(std::move(other.root))
, _size(other._size)
{
refreshIterators();
}
~Map()
{
delete root;
}
Map& operator=(const Map& other)
{
if(this != &other)
{
if(root != nullptr)
{
delete root;
}
root = new Node(*other.root);
_size = other.size;
markIteratorDirty();
}
return *this;
}
Map& operator=(Map&& other)
{
if(this != &other)
{
if(root != nullptr)
{
delete root;
}
root = new Node(std::move(*other.root));
_size = std::move(other._size);
markIteratorDirty();
}
return *this;
}
class Iterator
{ {
public: public:
using iterator_category = std::bidirectional_iterator_tag; using iterator_category = std::bidirectional_iterator_tag;
using value_type = Pair<K, V>; using value_type = PairType;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
using reference = Pair<K, V>&; using reference = PairType&;
using pointer = Pair<K, V>*; using pointer = PairType*;
Iterator(Node *x = nullptr) IteratorBase(Node *x = nullptr)
: node(x) : node(x)
{ {
} }
Iterator(Node *x, Array<Node *> &&beginIt) IteratorBase(Node *x, Array<Node *> &&beginIt)
: node(x), traversal(std::move(beginIt)) : node(x), traversal(std::move(beginIt))
{ {
} }
Iterator(const Iterator &i) IteratorBase(const IteratorBase &i)
: node(i.node), traversal(i.traversal) : node(i.node), traversal(i.traversal)
{ {
} }
Iterator(Iterator&& i) IteratorBase(IteratorBase&& i)
: node(std::move(i.node)), traversal(std::move(i.traversal)) : node(std::move(i.node)), traversal(std::move(i.traversal))
{ {
} }
Iterator& operator=(const Iterator& other) IteratorBase& operator=(const IteratorBase& other)
{ {
if(this != &other) if(this != &other)
{ {
@@ -195,7 +94,7 @@ public:
} }
return *this; return *this;
} }
Iterator& operator=(Iterator&& other) IteratorBase& operator=(IteratorBase&& other)
{ {
if(this != &other) if(this != &other)
{ {
@@ -212,15 +111,15 @@ public:
{ {
return &node->pair; return &node->pair;
} }
inline bool operator!=(const Iterator &other) inline bool operator!=(const IteratorBase &other)
{ {
return node != other.node; return node != other.node;
} }
inline bool operator==(const Iterator &other) inline bool operator==(const IteratorBase &other)
{ {
return node == other.node; return node == other.node;
} }
Iterator &operator++() IteratorBase &operator++()
{ {
node = node->rightChild; node = node->rightChild;
while (node != nullptr && node->leftChild != nullptr) while (node != nullptr && node->leftChild != nullptr)
@@ -235,7 +134,7 @@ public:
} }
return *this; return *this;
} }
Iterator &operator--() IteratorBase &operator--()
{ {
node = node->leftChild; node = node->leftChild;
while (node != nullptr && node->rightchild != nullptr) while (node != nullptr && node->rightchild != nullptr)
@@ -250,15 +149,15 @@ public:
} }
return *this; return *this;
} }
Iterator operator--(int) IteratorBase operator--(int)
{ {
Iterator tmp(*this); IteratorBase tmp(*this);
--*this; --*this;
return tmp; return tmp;
} }
Iterator operator++(int) IteratorBase operator++(int)
{ {
Iterator tmp(*this); IteratorBase tmp(*this);
++*this; ++*this;
return tmp; return tmp;
} }
@@ -267,72 +166,164 @@ public:
Node *node; Node *node;
Array<Node *> traversal; Array<Node *> traversal;
}; };
inline V &operator[](const K& key) using Iterator = IteratorBase<Pair<K,V>>;
using ConstIterator = IteratorBase<const Pair<K,V>>;
using key_type = K;
using mapped_type = V;
using value_type = Pair<K,V>;
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 = std::allocator_traits<Allocator>::pointer;
using const_pointer = std::allocator_traits<Allocator>::const_pointer;
using iterator = Iterator;
using const_iterator = ConstIterator;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
Map()
: root(nullptr)
, beginIt(nullptr)
, endIt(nullptr)
, iteratorsDirty(false)
, _size(0)
, comp(Compare())
{
}
explicit Map(const Compare& comp,
const Allocator& alloc = Allocator())
: nodeContainer(alloc)
, root(nullptr)
, beginIt(nullptr)
, endIt(nullptr)
, iteratorsDirty(false)
, _size(0)
, comp(comp)
{
}
explicit Map(const Allocator& alloc)
: nodeContainer(alloc)
, root(nullptr)
, beginIt(nullptr)
, endIt(nullptr)
, iteratorsDirty(false)
, _size(0)
, comp(Compare())
{
}
Map(const Map& other)
: nodeContainer(other.nodeContainer)
, _size(other._size)
, comp(other.comp)
{
root = &nodeContainer[nodeContainer.indexOf(other.root)];
refreshIterators();
}
Map(Map&& other)
: nodeContainer(other.nodeContainer)
, _size(std::move(other._size))
, comp(std::move(other.comp))
{
root = &nodeContainer[nodeContainer.indexOf(other.root)];
refreshIterators();
}
~Map()
{
}
Map& operator=(const Map& other)
{
if(this != &other)
{
nodeContainer = other.nodeContainer;
root = &nodeContainer[nodeContainer.indexOf(other.root)];
_size = other._size;
comp = other.comp;
refreshIterators();
}
return *this;
}
Map& operator=(Map&& other)
{
if(this != &other)
{
nodeContainer = std::move(other.nodeContainer);
root = &nodeContainer[nodeContainer.indexOf(other.root)];
_size = std::move(other._size);
comp = std::move(other.comp);
refreshIterators();
}
return *this;
}
inline mapped_type& operator[](const key_type& key)
{ {
root = splay(root, key); root = splay(root, key);
markIteratorDirty(); refreshIterators();
if (root == nullptr || root->pair.key < key || key < root->pair.key) if (root == nullptr || comp(root->pair.key, key) || comp(key, root->pair.key))
{ {
root = insert(root, key); root = insert(root, key);
_size++; _size++;
} }
return root->pair.value; return root->pair.value;
} }
inline V &operator[](K&& key) inline mapped_type& operator[](key_type&& key)
{ {
root = splay(root, std::move(key)); root = splay(root, std::move(key));
markIteratorDirty(); refreshIterators();
if (root == nullptr || root->pair.key < key || key < root->pair.key) if (root == nullptr || comp(root->pair.key, key) || comp(key, root->pair.key))
{ {
root = insert(root, std::move(key)); root = insert(root, std::move(key));
_size++; _size++;
} }
return root->pair.value; return root->pair.value;
} }
Iterator find(const K& key) iterator find(const key_type& key)
{ {
root = splay(root, key); root = splay(root, key);
markIteratorDirty(); refreshIterators();
if (root == nullptr || root->pair.key != key) if (root == nullptr || comp(root->pair.key, key) || comp(key, root->pair.key))
{ {
return endIt; return endIt;
} }
return Iterator(root); return iterator(root);
} }
Iterator find(K&& key) iterator find(key_type&& key)
{ {
root = splay(root, std::move(key)); root = splay(root, std::move(key));
markIteratorDirty(); refreshIterators();
if (root == nullptr || root->pair.key != key) if (root == nullptr || comp(root->pair.key, key) || comp(key, root->pair.key))
{ {
return endIt; return endIt;
} }
return Iterator(root); return iterator(root);
} }
Iterator erase(const K& key) iterator erase(const key_type& key)
{ {
root = remove(root, key); root = remove(root, key);
markIteratorDirty(); refreshIterators();
return Iterator(root); return iterator(root);
} }
Iterator erase(K&& key) iterator erase(K&& key)
{ {
root = remove(root, std::move(key)); root = remove(root, std::move(key));
markIteratorDirty(); refreshIterators();
return Iterator(root); return iterator(root);
} }
void clear() void clear()
{ {
delete root; nodeContainer.clear();
root = nullptr; root = nullptr;
_size = 0; _size = 0;
markIteratorDirty(); refreshIterators();
} }
bool exists(K&& key) bool exists(key_type&& key)
{ {
return find(std::forward<K>(key)) != endIt; return find(std::forward<K>(key)) != endIt;
} }
Iterator begin() iterator begin()
{ {
if(iteratorsDirty) if(iteratorsDirty)
{ {
@@ -340,7 +331,7 @@ public:
} }
return beginIt; return beginIt;
} }
Iterator end() iterator end()
{ {
if(iteratorsDirty) if(iteratorsDirty)
{ {
@@ -348,7 +339,7 @@ public:
} }
return endIt; return endIt;
} }
Iterator begin() const iterator begin() const
{ {
if(iteratorsDirty) if(iteratorsDirty)
{ {
@@ -356,7 +347,7 @@ public:
} }
return beginIt; return beginIt;
} }
Iterator end() const iterator end() const
{ {
if(iteratorsDirty) if(iteratorsDirty)
{ {
@@ -366,9 +357,9 @@ public:
} }
bool empty() const bool empty() const
{ {
return root == nullptr; return nodeContainer.empty();
} }
uint32 size() const size_type size() const
{ {
return _size; return _size;
} }
@@ -422,11 +413,13 @@ private:
return Iterator(endNode, std::move(endTraversal)); return Iterator(endNode, std::move(endTraversal));
} }
} }
Array<Node, NodeAlloc> nodeContainer;
Node *root; Node *root;
Iterator beginIt; Iterator beginIt;
Iterator endIt; Iterator endIt;
bool iteratorsDirty; bool iteratorsDirty;
uint32 _size; uint32 _size;
Compare comp;
Node *rotateRight(Node *node) Node *rotateRight(Node *node)
{ {
Node *y = node->leftChild; Node *y = node->leftChild;
@@ -446,16 +439,16 @@ private:
{ {
if (r == nullptr) if (r == nullptr)
{ {
return new Node(std::forward<KeyType>(key), V()); return &nodeContainer.emplace(std::forward<KeyType>(key));
} }
r = splay(r, key); r = splay(r, key);
if (!(r->pair.key < key || key < r->pair.key)) if (!(comp(r->pair.key, key) || comp(key, r->pair.key)))
return r; return r;
Node *newNode = new Node(std::forward<KeyType>(key), V()); Node *newNode = &nodeContainer.emplace(std::forward<KeyType>(key));
if (key < r->pair.key) if (comp(key, r->pair.key))
{ {
newNode->rightChild = r; newNode->rightChild = r;
newNode->leftChild = r->leftChild; newNode->leftChild = r->leftChild;
@@ -478,7 +471,7 @@ private:
r = splay(r, key); r = splay(r, key);
if (r->pair.key < key || key < r->pair.key) if (comp(r->pair.key, key) || comp(key, r->pair.key))
return r; return r;
if (!r->leftChild) if (!r->leftChild)
@@ -502,23 +495,23 @@ private:
template<class KeyType> template<class KeyType>
Node *splay(Node *r, KeyType&& key) Node *splay(Node *r, KeyType&& key)
{ {
if (r == nullptr || !(r->pair.key < key || key < r->pair.key)) if (r == nullptr || !(comp(r->pair.key, key) || comp(key, r->pair.key)))
{ {
return r; return r;
} }
if (key < r->pair.key) if (comp(key, r->pair.key))
{ {
if (r->leftChild == nullptr) if (r->leftChild == nullptr)
return r; return r;
if (key < r->leftChild->pair.key) if (comp(key, r->leftChild->pair.key))
{ {
r->leftChild->leftChild = splay(r->leftChild->leftChild, key); r->leftChild->leftChild = splay(r->leftChild->leftChild, key);
r = rotateRight(r); r = rotateRight(r);
} }
else if (r->leftChild->pair.key < key) else if (comp(r->leftChild->pair.key, key))
{ {
r->leftChild->rightChild = splay(r->leftChild->rightChild, key); r->leftChild->rightChild = splay(r->leftChild->rightChild, key);
@@ -534,7 +527,7 @@ private:
if (r->rightChild == nullptr) if (r->rightChild == nullptr)
return r; return r;
if (key < r->rightChild->pair.key) if (comp(key, r->rightChild->pair.key))
{ {
r->rightChild->leftChild = splay(r->rightChild->leftChild, key); r->rightChild->leftChild = splay(r->rightChild->leftChild, key);
@@ -543,7 +536,7 @@ private:
r->rightChild = rotateRight(r->rightChild); r->rightChild = rotateRight(r->rightChild);
} }
} }
else if (r->rightChild->pair.key < key) else if (comp(r->rightChild->pair.key, key))
{ {
r->rightChild->rightChild = splay(r->rightChild->rightChild, key); r->rightChild->rightChild = splay(r->rightChild->rightChild, key);
r = rotateLeft(r); r = rotateLeft(r);
+1
View File
@@ -581,6 +581,7 @@ public:
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0; virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0;
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0; virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0; virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
virtual void setCloseCallback(std::function<void()> callback) = 0;
SeFormat getSwapchainFormat() const SeFormat getSwapchainFormat() const
{ {
return pixelFormat; return pixelFormat;
@@ -370,12 +370,14 @@ public:
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override; virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
virtual void setScrollCallback(std::function<void(double, double)> callback) override; virtual void setScrollCallback(std::function<void(double, double)> callback) override;
virtual void setFileCallback(std::function<void(int, const char**)> callback) override; virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
virtual void setCloseCallback(std::function<void()> callback);
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback; std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
std::function<void(double, double)> mouseMoveCallback; std::function<void(double, double)> mouseMoveCallback;
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback; std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
std::function<void(double, double)> scrollCallback; std::function<void(double, double)> scrollCallback;
std::function<void(int, const char**)> fileCallback; std::function<void(int, const char**)> fileCallback;
std::function<void()> closeCallback;
protected: protected:
void advanceBackBuffer(); void advanceBackBuffer();
void recreateSwapchain(const WindowCreateInfo &createInfo); void recreateSwapchain(const WindowCreateInfo &createInfo);
@@ -38,6 +38,12 @@ void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
window->fileCallback(count, paths); window->fileCallback(count, paths);
} }
void glfwCloseCallback(GLFWwindow* handle)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->closeCallback();
}
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
: Gfx::Window(createInfo) : Gfx::Window(createInfo)
, graphics(graphics) , graphics(graphics)
@@ -56,6 +62,7 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback); glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback);
glfwSetScrollCallback(handle, &glfwScrollCallback); glfwSetScrollCallback(handle, &glfwScrollCallback);
glfwSetDropCallback(handle, &glfwFileCallback); glfwSetDropCallback(handle, &glfwFileCallback);
glfwSetWindowCloseCallback(handle, &glfwCloseCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface); glfwCreateWindowSurface(instance, handle, nullptr, &surface);
@@ -134,6 +141,11 @@ void Window::setFileCallback(std::function<void(int, const char**)> callback)
fileCallback = callback; fileCallback = callback;
} }
void Window::setCloseCallback(std::function<void()> callback)
{
closeCallback = callback;
}
void Window::advanceBackBuffer() void Window::advanceBackBuffer()
{ {
VkResult res = VK_ERROR_OUT_OF_DATE_KHR; VkResult res = VK_ERROR_OUT_OF_DATE_KHR;
+2 -2
View File
@@ -54,9 +54,9 @@ public:
std::unique_lock lock(registeredObjectsLock); std::unique_lock lock(registeredObjectsLock);
registeredObjects.erase(handle); registeredObjects.erase(handle);
} }
#pragma warning( disable: 4150) // #pragma warning( disable: 4150)
delete handle; delete handle;
#pragma warning( default: 4150) // #pragma warning( default: 4150)
} }
RefObject &operator=(const RefObject &rhs) RefObject &operator=(const RefObject &rhs)
{ {
+1 -1
View File
@@ -18,7 +18,7 @@ Scene::Scene(Gfx::PGraphics graphics)
lightEnv.directionalLights[0].color = Vector4(1, 1, 1, 1); lightEnv.directionalLights[0].color = Vector4(1, 1, 1, 1);
lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1); lightEnv.directionalLights[0].direction = Vector4(1, 1, 0, 1);
lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1); lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1);
lightEnv.numDirectionalLights = 0; lightEnv.numDirectionalLights = 1;
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
for(uint32 i = 0; i < 16; ++i) for(uint32 i = 0; i < 16; ++i)
{ {
+80 -5
View File
@@ -2,20 +2,38 @@
using namespace Seele; using namespace Seele;
Event::Event()
: flag(new std::atomic_bool())
{}
void Event::await_suspend(std::coroutine_handle<JobPromise> h) Event::Event(const std::string& name)
: name(name)
, flag(new std::atomic_bool())
{}
void Event::raise()
{ {
getGlobalThreadPool().addJob(Job(h)); flag->store(1);
getGlobalThreadPool().notify(this);
}
void Event::reset()
{
flag->store(0);
} }
Job JobPromise::get_return_object() noexcept { bool Event::await_ready()
return Job { std::coroutine_handle<JobPromise>::from_promise(*this) }; {
return flag->load();
} }
ThreadPool::ThreadPool(uint32 threadCount) ThreadPool::ThreadPool(uint32 threadCount)
: workers(threadCount) : workers(threadCount)
{ {
running.store(true);
for(uint32 i = 0; i < threadCount; ++i)
{
workers[i] = std::thread(&ThreadPool::threadLoop, this, i == 0);
}
} }
ThreadPool::~ThreadPool() ThreadPool::~ThreadPool()
@@ -25,6 +43,63 @@ ThreadPool::~ThreadPool()
thread.join(); thread.join();
} }
} }
void ThreadPool::addJob(Job&& job)
{
std::unique_lock lock(jobQueueLock);
jobQueue.add(job);
}
void ThreadPool::addJob(MainJob&& job)
{
std::unique_lock lock(mainJobLock);
mainJobs.add(job);
}
void ThreadPool::enqueueWaiting(Event* event, Job&& job)
{
std::unique_lock lock(waitingLock);
waitingJobs[event].add(std::move(job));
}
void ThreadPool::enqueueWaiting(Event* event, MainJob&& job)
{
std::unique_lock lock(waitingMainLock);
waitingMainJobs[event].add(std::move(job));
}
void ThreadPool::notify(Event* event)
{
{
std::unique_lock lock(jobQueueLock);
std::unique_lock lock2(waitingLock);
for(auto&& job : waitingJobs[event])
{
jobQueue.add(job);
}
waitingJobs[event].clear();
}
{
std::unique_lock lock(mainJobLock);
std::unique_lock lock2(waitingMainLock);
for(auto&& job : waitingMainJobs[event])
{
mainJobs.add(job);
}
waitingMainJobs[event].clear();
}
event->reset();
}
void ThreadPool::threadLoop(const bool mainThread)
{
while(running.load())
{
if(mainThread)
{
std::unique_lock lock(mainJobLock);
if(!mainJobs.empty())
{
MainJob&& job = mainJobs.retrieve();
job.resume();
}
}
}
}
ThreadPool& Seele::getGlobalThreadPool() ThreadPool& Seele::getGlobalThreadPool()
{ {
+88 -37
View File
@@ -1,35 +1,20 @@
#pragma once #pragma once
#include <thread> #include <thread>
#include <coroutine>
#include "Containers/List.h" #include "Containers/List.h"
namespace Seele namespace Seele
{ {
struct JobPromise; extern class ThreadPool& getGlobalThreadPool();
struct Event
{
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_always initial_suspend() const noexcept { return {}; } template<bool MainJob>
struct JobBase;
template<bool MainJob>
struct JobPromiseBase
{
JobBase<MainJob> get_return_object() noexcept;
inline auto initial_suspend() const noexcept;
std::suspend_never final_suspend() const noexcept { return {}; } std::suspend_never final_suspend() const noexcept { return {}; }
void return_void() noexcept {} void return_void() noexcept {}
@@ -38,23 +23,47 @@ struct JobPromise
exit(1); exit(1);
}; };
}; };
struct [[nodiscard]] Job template<bool MainJob>
struct JobBase
{ {
public: public:
using promise_type = JobPromise; using promise_type = JobPromiseBase<MainJob>;
explicit Job(std::coroutine_handle<JobPromise> handle) explicit JobBase(std::coroutine_handle<promise_type> handle)
: handle(handle) : handle(handle)
{} {}
~Job() ~JobBase()
{ {
if(handle) if(handle)
{ {
handle.destroy(); handle.destroy();
} }
} }
void resume()
{
handle.resume();
}
private: private:
std::coroutine_handle<JobPromise> handle; std::coroutine_handle<promise_type> handle;
};
using MainJob = JobBase<true>;
using Job = JobBase<false>;
struct Event
{
public:
Event();
Event(const std::string& name);
void raise();
void reset();
bool await_ready();
template<bool MainJob>
constexpr void await_suspend(std::coroutine_handle<JobPromiseBase<MainJob>> h);
constexpr void await_resume() {}
private:
std::string name;
RefPtr<std::atomic_bool> flag;
}; };
class ThreadPool class ThreadPool
@@ -62,14 +71,56 @@ class ThreadPool
public: public:
ThreadPool(uint32 threadCount = std::thread::hardware_concurrency()); ThreadPool(uint32 threadCount = std::thread::hardware_concurrency());
virtual ~ThreadPool(); virtual ~ThreadPool();
void addJob(Job&& job) void addJob(Job&& job);
{ void addJob(MainJob&& job);
jobs.add(std::move(job)); void enqueueWaiting(Event* event, Job&& job);
} void enqueueWaiting(Event* event, MainJob&& job);
void notify(Event* event);
private: private:
std::atomic_bool running;
std::thread* mainThread;
std::vector<std::thread> workers; std::vector<std::thread> workers;
List<Job> jobs;
void threadLoop(); List<MainJob> mainJobs;
std::mutex mainJobLock;
List<Job> jobQueue;
std::mutex jobQueueLock;
Map<Event*, List<Job>> waitingJobs;
std::mutex waitingLock;
Map<Event*, List<MainJob>> waitingMainJobs;
std::mutex waitingMainLock;
void threadLoop(const bool isMainThread);
}; };
extern ThreadPool& getGlobalThreadPool();
template<bool MainJob>
inline JobBase<MainJob> JobPromiseBase<MainJob>::get_return_object() noexcept {
return JobBase<MainJob> { std::coroutine_handle<JobPromiseBase<MainJob>>::from_promise(*this) };
}
template<bool MainJob>
inline auto JobPromiseBase<MainJob>::initial_suspend() const noexcept
{
struct JobAwaitable
{
constexpr bool await_ready() { return false; }
constexpr void await_suspend(std::coroutine_handle<JobPromiseBase<MainJob>> h)
{
getGlobalThreadPool().addJob(JobBase<MainJob>(h));
}
constexpr void await_resume() {}
};
return JobAwaitable{};
}
template<bool MainJob>
inline constexpr void Event::await_suspend(std::coroutine_handle<JobPromiseBase<MainJob>> h)
{
getGlobalThreadPool().enqueueWaiting(this, JobBase<MainJob>(h));
}
} // namespace Seele } // namespace Seele
+6 -6
View File
@@ -16,7 +16,7 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
{ {
scene = new Scene(graphics); scene = new Scene(graphics);
scene->addActor(activeCamera); scene->addActor(activeCamera);
/*AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
@@ -24,11 +24,11 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx");
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka")); PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
ayaka->addWorldTranslation(Vector(0, 0, 100)); ayaka->addWorldTranslation(Vector(0, 0, 0));
ayaka->setWorldScale(Vector(0.1f, 0.1f, 0.1f)); ayaka->setWorldScale(Vector(10, 10, 10));
scene->addPrimitiveComponent(ayaka);*/ scene->addPrimitiveComponent(ayaka);
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx"); /*AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj"); AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx"); AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane")); PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
@@ -37,7 +37,7 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
arissa->addWorldTranslation(Vector(0, 0, 100)); arissa->addWorldTranslation(Vector(0, 0, 100));
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f)); arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
scene->addPrimitiveComponent(plane); scene->addPrimitiveComponent(plane);
scene->addPrimitiveComponent(arissa); scene->addPrimitiveComponent(arissa);*/
PRenderGraphResources resources = new RenderGraphResources(); PRenderGraphResources resources = new RenderGraphResources();
depthPrepass.setResources(resources); depthPrepass.setResources(resources);
+18 -12
View File
@@ -1,10 +1,12 @@
#include "Window.h" #include "Window.h"
#include "WindowManager.h"
#include <functional> #include <functional>
using namespace Seele; using namespace Seele;
Window::Window(Gfx::PWindow handle) Window::Window(PWindowManager owner, Gfx::PWindow handle)
: gfxHandle(handle) : owner(owner)
, gfxHandle(handle)
{ {
} }
@@ -20,23 +22,17 @@ void Window::addView(PView view)
views.add(windowView); views.add(windowView);
} }
void Window::render() MainJob Window::render()
{ {
gfxHandle->beginFrame(); gfxHandle->beginFrame();
for(auto& windowView : views) for(auto& windowView : views)
{ {
windowView->view->beginUpdate(); viewWorker(windowView);
windowView->view->update(); co_await windowView->updateFinished;
{
std::unique_lock lock(windowView->workerMutex);
windowView->view->commitUpdate();
}
windowView->updateFinished.raise();
{ {
std::unique_lock lock(windowView->workerMutex); std::unique_lock lock(windowView->workerMutex);
windowView->view->prepareRender(); windowView->view->prepareRender();
} }
windowView->updateFinished.reset();
windowView->view->render(); windowView->view->render();
} }
gfxHandle->endFrame(); gfxHandle->endFrame();
@@ -59,12 +55,22 @@ void Window::setFocused(PView view)
gfxHandle->setMouseButtonCallback(mouseButtonFunction); gfxHandle->setMouseButtonCallback(mouseButtonFunction);
gfxHandle->setScrollCallback(scrollFunction); gfxHandle->setScrollCallback(scrollFunction);
gfxHandle->setFileCallback(fileFunction); gfxHandle->setFileCallback(fileFunction);
gfxHandle->setCloseCallback([this](){
owner->notifyWindowClosed(this);
});
} }
void Window::viewWorker(WindowView* windowView) Job Window::viewWorker(WindowView* windowView)
{ {
while(true) while(true)
{ {
windowView->view->beginUpdate();
windowView->view->update();
{
std::unique_lock lock(windowView->workerMutex);
windowView->view->commitUpdate();
}
windowView->updateFinished.raise();
} }
} }
+5 -4
View File
@@ -9,26 +9,27 @@ struct WindowView
{ {
PView view; PView view;
Event updateFinished; Event updateFinished;
std::thread worker;
std::mutex workerMutex; std::mutex workerMutex;
}; };
DEFINE_REF(WindowView) DEFINE_REF(WindowView)
DECLARE_REF(WindowManager)
// The logical window, with the graphics proxy // The logical window, with the graphics proxy
class Window class Window
{ {
public: public:
Window(Gfx::PWindow handle); Window(PWindowManager owner, Gfx::PWindow handle);
~Window(); ~Window();
void addView(PView view); void addView(PView view);
void render(); MainJob render();
Gfx::PWindow getGfxHandle(); Gfx::PWindow getGfxHandle();
void setFocused(PView view); void setFocused(PView view);
protected: protected:
PWindowManager owner;
Array<WindowView*> views; Array<WindowView*> views;
Gfx::PWindow gfxHandle; Gfx::PWindow gfxHandle;
void viewWorker(WindowView* view); Job viewWorker(WindowView* view);
}; };
DEFINE_REF(Window) DEFINE_REF(Window)
} // namespace Seele } // namespace Seele
+6 -1
View File
@@ -31,7 +31,12 @@ WindowManager::~WindowManager()
PWindow WindowManager::addWindow(const WindowCreateInfo &createInfo) PWindow WindowManager::addWindow(const WindowCreateInfo &createInfo)
{ {
Gfx::PWindow handle = graphics->createWindow(createInfo); Gfx::PWindow handle = graphics->createWindow(createInfo);
PWindow window = new Window(handle); PWindow window = new Window(this, handle);
windows.add(window); windows.add(window);
return window; return window;
} }
void WindowManager::notifyWindowClosed(PWindow window)
{
windows.remove(windows.find(window));
}
+1
View File
@@ -12,6 +12,7 @@ public:
WindowManager(); WindowManager();
~WindowManager(); ~WindowManager();
PWindow addWindow(const WindowCreateInfo &createInfo); PWindow addWindow(const WindowCreateInfo &createInfo);
void notifyWindowClosed(PWindow window);
static Gfx::PGraphics getGraphics() static Gfx::PGraphics getGraphics()
{ {
return graphics; return graphics;
+2 -2
View File
@@ -9,7 +9,7 @@ using namespace Seele;
int main() int main()
{ {
PWindowManager windowManager = new WindowManager(); PWindowManager windowManager = new WindowManager();
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject\\"); AssetRegistry::init("/home/dynamitos/TestSeeleProject");
WindowCreateInfo mainWindowInfo; WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine"; mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280; mainWindowInfo.width = 1280;
@@ -34,7 +34,7 @@ int main()
PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo); PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
window->addView(inspectorView); window->addView(inspectorView);
sceneView->setFocused(); sceneView->setFocused();
while(true) while(windowManager->isActive())
{ {
window->render(); window->render();
} }