-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
954 additions
and
1,525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "Pomdog/Utility/Assert.hpp" | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace Pomdog::ECS::Detail { | ||
|
||
class ComponentBufferBase { | ||
public: | ||
virtual ~ComponentBufferBase() = default; | ||
|
||
[[nodiscard]] virtual std::size_t GetSize() const noexcept = 0; | ||
|
||
virtual void Resize(std::size_t size) = 0; | ||
|
||
virtual void Reset(std::uint32_t index) = 0; | ||
}; | ||
|
||
template <typename TComponent> | ||
class ComponentBuffer final : public ComponentBufferBase { | ||
public: | ||
std::size_t GetSize() const noexcept override | ||
{ | ||
return components.size(); | ||
} | ||
|
||
void Resize(std::size_t size) override | ||
{ | ||
components.resize(size); | ||
} | ||
|
||
void Reset(std::uint32_t index) override | ||
{ | ||
POMDOG_ASSERT(index < components.size()); | ||
components[index] = TComponent{}; | ||
} | ||
|
||
[[nodiscard]] TComponent* GetComponent(std::uint32_t index) | ||
{ | ||
POMDOG_ASSERT(index < components.size()); | ||
return &components[index]; | ||
} | ||
|
||
private: | ||
std::vector<TComponent> components; | ||
}; | ||
|
||
} // namespace Pomdog::ECS::Detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2013-2019 mogemimi. Distributed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "Pomdog/Experimental/ECS/ComponentBuffer.hpp" | ||
#include "Pomdog/Experimental/ECS/ComponentTypeIndex.hpp" | ||
#include <cstdint> | ||
#include <memory> | ||
#include <string> | ||
|
||
namespace Pomdog::ECS { | ||
|
||
class ComponentTypeBase { | ||
public: | ||
virtual ~ComponentTypeBase() = default; | ||
|
||
[[nodiscard]] virtual std::uint8_t | ||
GetTypeIndex() const noexcept = 0; | ||
|
||
[[nodiscard]] virtual std::unique_ptr<Detail::ComponentBufferBase> | ||
CreateComponentBuffer() const = 0; | ||
}; | ||
|
||
template <typename TComponent> | ||
struct ComponentTypeDeclaration final { | ||
static std::uint8_t GetTypeIndex() | ||
{ | ||
return Detail::ComponentTypeIndex::Index<TComponent>(); | ||
} | ||
}; | ||
|
||
template <typename T> | ||
class ComponentType final : public ComponentTypeBase { | ||
public: | ||
std::uint8_t GetTypeIndex() const noexcept override | ||
{ | ||
return ComponentTypeDeclaration<T>::GetTypeIndex(); | ||
} | ||
|
||
std::unique_ptr<Detail::ComponentBufferBase> CreateComponentBuffer() const override | ||
{ | ||
return std::make_unique<Detail::ComponentBuffer<T>>(); | ||
} | ||
}; | ||
|
||
template <class TComponent, typename... Args> | ||
inline std::shared_ptr<ComponentTypeBase> AddComponent(Args &&... args) | ||
{ | ||
return std::make_shared<ComponentType<TComponent>>(std::forward<Args>(args)...); | ||
} | ||
|
||
} // namespace Pomdog::ECS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.