Skip to content

Commit

Permalink
Merge branch 'main' into feature/rendering-abstraction-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
FiniteReality authored Jul 2, 2023
2 parents 648ec5d + fdc64ac commit 65aeba4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 104 deletions.
80 changes: 1 addition & 79 deletions include/NovelRT/Atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,7 @@

namespace NovelRT
{
class Atom
{
friend class AtomHashFunction;

private:
uintptr_t _value;

public:
constexpr Atom() noexcept : Atom(0)
{
}

constexpr Atom(uintptr_t value) noexcept : _value(value)
{
}

bool operator==(Atom other) const noexcept
{
return _value == other._value;
}

bool operator==(uintptr_t other) const noexcept
{
return _value == other;
}

bool operator!=(Atom other) const noexcept
{
return _value != other._value;
}

bool operator!=(uintptr_t other) const noexcept
{
return _value != other;
}

bool operator<(Atom other) const noexcept
{
return _value < other._value;
}

bool operator<=(Atom other) const noexcept
{
return _value <= other._value;
}

bool operator>(Atom other) const noexcept
{
return _value > other._value;
}

bool operator>=(Atom other) const noexcept
{
return _value >= other._value;
}

operator uintptr_t() const noexcept
{
return _value;
}

static Atom GetNextEcsPrimitiveInfoConfigurationId() noexcept;
};
using Atom = uintptr_t;

class AtomFactory
{
Expand All @@ -100,22 +38,6 @@ namespace NovelRT
public:
[[nodiscard]] static AtomFactory& GetFactory(const std::string& factoryName) noexcept;
};

class AtomHashFunction
{
public:
size_t operator()(Atom atom) const noexcept
{
return static_cast<size_t>(atom._value);
}
};
}

namespace std
{
template<> class numeric_limits<NovelRT::Atom> : public numeric_limits<uintptr_t>
{
};
}

#endif // NOVELRT_ATOM_H
3 changes: 1 addition & 2 deletions include/NovelRT/Ecs/ComponentCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace NovelRT::Ecs
class ComponentCache
{
private:
std::unordered_map<ComponentTypeId, std::shared_ptr<ComponentBufferMemoryContainer>, AtomHashFunction>
_componentMap;
std::unordered_map<ComponentTypeId, std::shared_ptr<ComponentBufferMemoryContainer>> _componentMap;
size_t _poolSize;
Utilities::Event<const std::vector<EntityId>&> _bufferPrepEvent;

Expand Down
2 changes: 1 addition & 1 deletion include/NovelRT/Ecs/SystemScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace NovelRT::Ecs
static inline const uint32_t DEFAULT_BLIND_THREAD_LIMIT = 8;

std::vector<std::shared_ptr<IEcsSystem>> _typedSystemCache;
std::unordered_map<Atom, std::function<void(Timing::Timestamp, Catalogue)>, AtomHashFunction> _systems;
std::unordered_map<Atom, std::function<void(Timing::Timestamp, Catalogue)>> _systems;

EntityCache _entityCache;
ComponentCache _componentCache;
Expand Down
1 change: 0 additions & 1 deletion include/NovelRT/NovelRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
* It is aimed at designers and developers alike, however many of the designer tools and features we have on our roadmap have yet to be implemented.
*/
namespace NovelRT {
typedef class Atom Atom;
typedef class LoggingService LoggingService;
}

Expand Down
8 changes: 0 additions & 8 deletions src/NovelRT/Atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@

namespace NovelRT
{

Atom Atom::GetNextEcsPrimitiveInfoConfigurationId() noexcept
{
static std::atomic_uintptr_t _nextEcsPrimitiveInfoConfigurationId(0);
auto value = ++_nextEcsPrimitiveInfoConfigurationId;
return Atom(value);
}

AtomFactory::AtomFactory() noexcept : AtomFactory(0)
{
}
Expand Down
3 changes: 1 addition & 2 deletions src/NovelRT/Ecs/ComponentCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace NovelRT::Ecs
{
ComponentCache::ComponentCache(size_t poolSize) noexcept
: _componentMap(
std::unordered_map<ComponentTypeId, std::shared_ptr<ComponentBufferMemoryContainer>, AtomHashFunction>{}),
: _componentMap(std::unordered_map<ComponentTypeId, std::shared_ptr<ComponentBufferMemoryContainer>>{}),
_poolSize(poolSize),
_bufferPrepEvent(Utilities::Event<const std::vector<EntityId>&>())
{
Expand Down
2 changes: 1 addition & 1 deletion src/NovelRT/Ecs/Graphics/DefaultRenderingSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ namespace NovelRT::Ecs::Graphics
size_t currentIndex = 0;
};

std::unordered_map<Atom, std::map<int32_t, GpuSpanCounter>, AtomHashFunction> gpuSpanCounterMap{};
std::unordered_map<Atom, std::map<int32_t, GpuSpanCounter>> gpuSpanCounterMap{};

for (auto reverseIt = transformLayerMap.rbegin(); reverseIt != transformLayerMap.rend(); reverseIt++)
{
Expand Down
25 changes: 15 additions & 10 deletions src/NovelRT/Ecs/SparseSetMemoryContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,29 @@ namespace NovelRT::Ecs

_sparse[key] = 0;

bool canResize = true;
if (!_dense.empty())
{
for (auto it = _sparse.begin() + key; it != _sparse.end(); it++)
std::optional<std::vector<size_t>::iterator> targetStart{};
size_t currentValue = 0;
size_t finalDenseSize = _dense.size();
for (auto it = _sparse.rbegin(); it != _sparse.rend(); it++)
{
if (*it == 0 && _dense[0] != key)
currentValue = *it;
if (currentValue < finalDenseSize && _dense[currentValue] == currentValue)
{
continue;
targetStart = it.base();
break;
}
}

canResize = false;
break;
if (targetStart.has_value() && targetStart.value() != _sparse.end())
{
_sparse.erase(targetStart.value(), _sparse.end());
}
}

if (canResize)
else
{
_sparse.erase(_sparse.begin() + key, _sparse.end());
_sparse.clear();
}

for (auto&& index : _sparse)
Expand Down Expand Up @@ -140,7 +145,7 @@ namespace NovelRT::Ecs

bool SparseSetMemoryContainer::ContainsKey(size_t key) const noexcept
{
if (key >= _sparse.size() || _dense.empty())
if (key >= _sparse.size())
{
return false;
}
Expand Down

0 comments on commit 65aeba4

Please sign in to comment.