Skip to content

Commit cb09d27

Browse files
committed
move function definitions to cpp files
1 parent 071a9f1 commit cb09d27

30 files changed

+241
-130
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
22

3-
project(UECS VERSION 0.16.1)
3+
project(UECS VERSION 0.16.2)
44
message(STATUS "[Project] ${PROJECT_NAME}")
55

66
include(cmake/InitUCMake.cmake)

include/UECS/Chunk.hpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace Ubpa::UECS {
1818
bool DidOrderChange(std::size_t version) const noexcept;
1919

2020
std::uint64_t GetComponentVersion(TypeID cmptType) const noexcept;
21-
std::uint64_t GetOrderVersion() const noexcept { return GetHead()->order_version; }
21+
std::uint64_t GetOrderVersion() const noexcept;
2222

23-
std::size_t EntityNum() const noexcept { return GetHead()->num_entity; }
24-
std::size_t ComponentNum() const noexcept { return GetHead()->num_component; }
23+
std::size_t EntityNum() const noexcept;
24+
std::size_t ComponentNum() const noexcept;
2525

2626
// if not contains the component, return nullptr
2727
void* GetCmptArray(TypeID cmptType) const noexcept;
@@ -34,10 +34,10 @@ namespace Ubpa::UECS {
3434
else return {};
3535
}
3636

37-
std::span<Entity> GetEntityArray() const noexcept { return GetCmptArray<Entity>(); }
37+
std::span<Entity> GetEntityArray() const noexcept;
3838

39-
bool Full() const noexcept { return GetHead()->capacity == GetHead()->num_entity; }
40-
bool Empty() const noexcept { return GetHead()->num_entity == 0; }
39+
bool Full() const noexcept;
40+
bool Empty() const noexcept;
4141

4242
bool HasAnyChange(std::span<const TypeID> types, std::uint64_t version) const noexcept;
4343

@@ -46,10 +46,11 @@ namespace Ubpa::UECS {
4646
// ApplyChanges
4747
std::tuple<Entity*, small_vector<CmptAccessPtr>, small_vector<std::size_t>> Locate(std::span<const AccessTypeID> types);
4848

49-
std::pmr::unsynchronized_pool_resource* GetChunkUnsyncResource() noexcept { return &GetHead()->chunk_unsync_rsrc; }
50-
std::pmr::monotonic_buffer_resource* GetChunkUnsyncFrameResource() noexcept { return (std::pmr::monotonic_buffer_resource*)&GetHead()->chunk_unsync_frame_rsrc; }
49+
std::pmr::unsynchronized_pool_resource* GetChunkUnsyncResource() noexcept;
50+
std::pmr::monotonic_buffer_resource* GetChunkUnsyncFrameResource() noexcept;
5151

52-
template<typename T, typename... Args> T* ChunkUnsyncNewFrameObject(Args&&... args) {
52+
template<typename T, typename... Args>
53+
T* ChunkUnsyncNewFrameObject(Args&&... args) {
5354
auto rsrc = GetChunkUnsyncFrameResource();
5455
auto obj = (T*)rsrc->allocate(sizeof(T), alignof(T));
5556
std::pmr::polymorphic_allocator{ rsrc }.construct(obj, std::forward<Args>(args)...);
@@ -79,20 +80,20 @@ namespace Ubpa::UECS {
7980
static_assert(sizeof(CmptInfo) == 24);
8081

8182
// sorted by ID
82-
std::span<CmptInfo> GetCmptInfos() noexcept { return { (CmptInfo*)(this + 1), num_component }; }
83-
std::span<const CmptInfo> GetCmptInfos() const noexcept { return const_cast<Head*>(this)->GetCmptInfos(); }
84-
85-
void ForceUpdateVersion(std::uint64_t version);
83+
std::span<CmptInfo> GetCmptInfos() noexcept;
84+
std::span<const CmptInfo> GetCmptInfos() const noexcept;
8685
};
8786

8887
Chunk() noexcept = default;
89-
~Chunk() { GetHead()->~Head(); }
88+
~Chunk();
9089

91-
Head* GetHead() noexcept { return reinterpret_cast<Head*>(data); }
92-
const Head* GetHead() const noexcept { return reinterpret_cast<const Head*>(data); }
90+
Head* GetHead() noexcept;
91+
const Head* GetHead() const noexcept;
9392

9493
std::size_t Erase(std::size_t idx);
9594

95+
void ForceUpdateVersion(std::uint64_t version);
96+
9697
static_assert(ChunkSize > sizeof(Head));
9798
std::uint8_t data[ChunkSize];
9899
};

include/UECS/CmptLocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ namespace Ubpa::UECS {
2121
template<typename Func>
2222
CmptLocator& Combine();
2323

24-
std::size_t GetValue() const noexcept { return hashCode; }
24+
std::size_t GetValue() const noexcept;
2525

26-
const AccessTypeIDSet& AccessTypeIDs() const noexcept { return cmptTypes; }
26+
const AccessTypeIDSet& AccessTypeIDs() const noexcept;
2727

2828
bool operator==(const CmptLocator& rhs) const noexcept;
2929

include/UECS/CmptsView.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
namespace Ubpa::UECS {
88
class CmptsView {
99
public:
10-
CmptsView() noexcept = default;
11-
CmptsView(std::span<const CmptAccessPtr> cmpts) noexcept : cmpts{ cmpts } {}
10+
CmptsView() noexcept;
11+
CmptsView(std::span<const CmptAccessPtr> cmpts) noexcept;
1212

1313
CmptAccessPtr GetCmpt(AccessTypeID) const noexcept;
14-
std::span<const CmptAccessPtr> Components() const noexcept { return cmpts; }
14+
std::span<const CmptAccessPtr> AccessComponents() const noexcept;
1515
private:
1616
std::span<const CmptAccessPtr> cmpts;
1717
};

include/UECS/CommandBuffer.hpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,24 @@
66
namespace Ubpa::UECS {
77
class CommandBuffer {
88
public:
9-
void AddCommand(std::function<void()> command) { commands.push_back(std::move(command)); }
10-
void AddCommandBuffer(CommandBuffer cb) {
11-
commands.reserve(commands.size() + cb.commands.size());
12-
for (auto& cmd : cb.commands)
13-
commands.push_back(std::move(cmd));
14-
}
15-
bool Empty() const noexcept { return commands.empty(); }
16-
void Clear() { commands.clear(); }
9+
void AddCommand(std::function<void()> command);
10+
void AddCommandBuffer(CommandBuffer cb);
11+
bool Empty() const noexcept;
12+
void Clear() noexcept;
1713

18-
auto& GetCommands() noexcept { return commands; }
19-
const auto& GetCommands() const noexcept { return commands; }
14+
std::span<std::function<void()>> GetCommands() noexcept;
15+
std::span<const std::function<void()>> GetCommands() const noexcept;
2016

21-
void Run() {
22-
for (const auto& cmd : commands)
23-
cmd();
24-
commands.clear();
25-
}
17+
void Run();
2618
private:
2719
std::vector<std::function<void()>> commands;
2820
};
2921

30-
class CommandBufferView {
22+
class CommandBufferPtr {
3123
public:
32-
CommandBufferView(CommandBuffer* cb = nullptr) : commandBuffer{ cb } {}
33-
CommandBuffer* GetCommandBuffer() const noexcept { return commandBuffer; }
34-
CommandBuffer* operator->()const noexcept { return commandBuffer; }
24+
CommandBufferPtr(CommandBuffer* cb = nullptr);
25+
CommandBuffer* Get() const noexcept;
26+
CommandBuffer* operator->()const noexcept;
3527
private:
3628
CommandBuffer* commandBuffer;
3729
};

include/UECS/Entity.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace Ubpa::UECS {
1111
std::uint64_t index;
1212
std::uint64_t version;
1313

14-
static constexpr Entity Invalid() noexcept { return { .index = static_cast<std::uint64_t>(-1), .version = static_cast<std::uint64_t>(-1) }; }
14+
static constexpr Entity Invalid() noexcept
15+
{ return { .index = static_cast<std::uint64_t>(-1), .version = static_cast<std::uint64_t>(-1) }; }
16+
1517
constexpr bool Valid() const noexcept { return index != static_cast<std::uint64_t>(-1); }
1618
constexpr auto operator<=>(const Entity&) const = default;
1719
};

include/UECS/EntityMngr.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace Ubpa::UECS {
2121
// auto maintain Component's lifecycle ({default|copy|move} constructor, destructor)
2222
// [API]
2323
// - Entity: Create, Instantiate, Destroy, Exist
24-
// - Component: Attach, Emplace, Detach, Have, Get, Components
25-
// - Singleton: IsSingleton, GetSingletonEntity, GetSingleton
24+
// - Component: Attach, Emplace, Detach, Have, Get, AccessComponents
25+
// - Singleton: IsSingleton, GetSingletonEntity, AccessSingleton
2626
// - other: EntityNum, AddCommand
2727
// [important]
2828
// - some API with TypeID need CmptTraits to get {size|alignment|lifecycle function} (throw std::logic_error)
@@ -44,17 +44,17 @@ namespace Ubpa::UECS {
4444
bool Have(Entity, TypeID) const;
4545

4646
// nullptr if not containts TypeID
47-
CmptAccessPtr GetComponent(Entity, AccessTypeID) const;
48-
CmptAccessPtr WriteComponent(Entity e, TypeID t) const { return GetComponent(e, { t, AccessMode::WRITE }); }
49-
CmptAccessPtr ReadComponent(Entity e, TypeID t) const { return GetComponent(e, { t, AccessMode::LATEST }); }
47+
CmptAccessPtr AccessComponent(Entity, AccessTypeID) const;
48+
CmptAccessPtr WriteComponent(Entity e, TypeID t) const;
49+
CmptAccessPtr ReadComponent(Entity e, TypeID t) const;
5050
template<typename Cmpt>
5151
Cmpt* WriteComponent(Entity e) const { return WriteComponent(e, TypeID_of<Cmpt>).template As<Cmpt, AccessMode::WRITE>(); }
5252
template<typename Cmpt>
5353
const Cmpt* ReadComponent(Entity e) const { return ReadComponent(e, TypeID_of<Cmpt>).template As<Cmpt, AccessMode::LATEST>(); }
5454

55-
std::vector<CmptAccessPtr> Components(Entity, AccessMode) const;
56-
std::vector<CmptAccessPtr> WriteComponents(Entity e) const { return Components(e, AccessMode::WRITE); }
57-
std::vector<CmptAccessPtr> ReadComponents(Entity e) const { return Components(e, AccessMode::LATEST); }
55+
std::vector<CmptAccessPtr> AccessComponents(Entity, AccessMode) const;
56+
std::vector<CmptAccessPtr> WriteComponents(Entity e) const;
57+
std::vector<CmptAccessPtr> ReadComponents(Entity e) const;
5858

5959
// chunk + index in chunk
6060
std::tuple<Chunk*, std::size_t> GetChunk(Entity e) const;
@@ -63,17 +63,17 @@ namespace Ubpa::UECS {
6363

6464
void Destroy(Entity);
6565

66-
std::size_t TotalEntityNum() const noexcept { return entityTable.size() - entityTableFreeEntry.size(); }
66+
std::size_t TotalEntityNum() const noexcept;
6767
std::size_t EntityNum(const EntityQuery&) const;
6868
// use entry in reverse
69-
std::span<const std::size_t> GetEntityFreeEntries() const noexcept { return { entityTableFreeEntry.data(), entityTableFreeEntry.size() }; }
70-
std::size_t GetEntityVersion(std::size_t idx) const noexcept { return entityTable[idx].version; }
69+
std::span<const std::size_t> GetEntityFreeEntries() const noexcept;
70+
std::size_t GetEntityVersion(std::size_t idx) const noexcept;
7171

7272
bool IsSingleton(TypeID) const;
7373
Entity GetSingletonEntity(TypeID) const;
74-
CmptAccessPtr GetSingleton(AccessTypeID) const;
75-
CmptAccessPtr WriteSingleton(TypeID type) const { return GetSingleton({ type, AccessMode::WRITE }); }
76-
CmptAccessPtr ReadSingleton(TypeID type) const { return GetSingleton({ type, AccessMode::LATEST }); }
74+
CmptAccessPtr AccessSingleton(AccessTypeID) const;
75+
CmptAccessPtr WriteSingleton(TypeID type) const;
76+
CmptAccessPtr ReadSingleton(TypeID type) const;
7777
template<typename Cmpt>
7878
Cmpt* WriteSingleton() const { return WriteSingleton(TypeID_of<Cmpt>).template As<Cmpt, AccessMode::WRITE>(); }
7979
template<typename Cmpt>

include/UECS/EntityQuery.hpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,12 @@ namespace Ubpa::UECS {
1010
ArchetypeFilter filter;
1111
CmptLocator locator;
1212

13-
std::size_t GetValue() const noexcept { return hash_combine(filter.GetValue(), locator.GetValue()); }
13+
std::size_t GetValue() const noexcept;
1414

15-
bool IsMatch(const small_flat_set<TypeID>& types) const noexcept{
16-
return std::find_if_not(filter.all.begin(), filter.all.end(),
17-
[&](const auto& type) { return types.contains(type); }) == filter.all.end()
18-
&& (filter.any.empty()
19-
|| std::find_if(filter.any.begin(), filter.any.end(),
20-
[&](const auto& type) { return types.contains(type); }) != filter.any.end())
21-
&& std::find_if(filter.none.begin(), filter.none.end(),
22-
[&](const auto& type) { return types.contains(type); }) == filter.none.end()
23-
&& std::find_if_not(locator.AccessTypeIDs().begin(), locator.AccessTypeIDs().end(),
24-
[&](const auto& type) { return types.contains(type); }) == locator.AccessTypeIDs().end();
25-
}
26-
27-
friend bool operator==(const EntityQuery& lhs, const EntityQuery& rhs) noexcept {
28-
return lhs.filter == rhs.filter && lhs.locator == rhs.locator;
29-
}
15+
bool IsMatch(const small_flat_set<TypeID>& types) const noexcept;
3016
};
17+
18+
bool operator==(const EntityQuery& lhs, const EntityQuery& rhs) noexcept;
3119
}
3220

3321
template<>

include/UECS/Schedule.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace Ubpa::UECS {
118118
Schedule& AddNone(std::string_view sys, TypeID, int layer = 0);
119119
Schedule& Disable(std::string_view sys, int layer = 0);
120120

121-
World* GetWorld() const noexcept { return world; }
121+
World* GetWorld() const noexcept;
122122

123123
std::string_view RegisterFrameString(std::string_view str);
124124

include/UECS/SingletonLocator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
namespace Ubpa::UECS {
99
class SingletonLocator {
1010
public:
11-
SingletonLocator(std::set<AccessTypeID> types) : singletonTypes{ std::move(types) } {}
11+
SingletonLocator(std::set<AccessTypeID> types);
1212
SingletonLocator(std::span<const AccessTypeID> types);
13-
SingletonLocator() = default;
13+
SingletonLocator();
1414

1515
template<typename Func>
1616
static SingletonLocator Generate();
1717

1818
template<typename Func>
1919
SingletonLocator& Combine();
2020

21-
const std::set<AccessTypeID>& SingletonTypes() const noexcept { return singletonTypes; }
21+
const std::set<AccessTypeID>& SingletonTypes() const noexcept;
2222

2323
bool HasWriteSingletonType() const noexcept;
2424

include/UECS/SingletonsView.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Ubpa::UECS {
1010
SingletonsView(std::span<const CmptAccessPtr> singletons) noexcept
1111
: singletons{ singletons } {}
1212

13-
CmptAccessPtr GetSingleton(AccessTypeID) const noexcept;
13+
CmptAccessPtr AccessSingleton(AccessTypeID) const noexcept;
1414
std::span<const CmptAccessPtr> Singletons() const noexcept { return singletons; }
1515
private:
1616
std::span<const CmptAccessPtr> singletons;

include/UECS/SystemFunc.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ namespace Ubpa::UECS {
2828
// * <tagged-components>: {LastFrame|Write|Latest}<Cmpt>...
2929
// * CmptsView
3030
// * ChunkView
31-
// * CommandBufferView
31+
// * CommandBufferPtr
3232
// 2. Mode::Chunk
3333
// * std::size_t entityBeginIndexInQuery
3434
// * ChunkView (necessary)
35-
// * CommandBufferView
35+
// * CommandBufferPtr
3636
// 3. Mode::Job
3737
// * Write<Singleton<Cmpt>> (only job can write singletons)
3838
class SystemFunc {
@@ -62,27 +62,27 @@ namespace Ubpa::UECS {
6262
template<typename Func>
6363
SystemFunc(Func&&, std::string_view name, SingletonLocator, RandomAccessor);
6464

65-
std::string_view Name() const noexcept { return name; }
65+
std::string_view Name() const noexcept;
6666

6767
static constexpr std::size_t GetValue(std::string_view name) noexcept { return string_hash(name); }
6868

69-
std::size_t GetValue() const noexcept { return hashCode; }
69+
std::size_t GetValue() const noexcept;
7070

71-
void operator()(World*, SingletonsView, Entity, std::size_t entityIndexInQuery, CmptsView, CommandBufferView) const;
72-
void operator()(World*, SingletonsView, std::size_t entityBeginIndexInQuery, ChunkView, CommandBufferView) const;
71+
void operator()(World*, SingletonsView, Entity, std::size_t entityIndexInQuery, CmptsView, CommandBufferPtr) const;
72+
void operator()(World*, SingletonsView, std::size_t entityBeginIndexInQuery, ChunkView, CommandBufferPtr) const;
7373
void operator()(World*, SingletonsView) const;
7474

75-
Mode GetMode() const noexcept { return mode; }
76-
bool IsParallel() const noexcept { return isParallel; }
75+
Mode GetMode() const noexcept;
76+
bool IsParallel() const noexcept;
7777

78-
bool operator==(const SystemFunc& sysFunc) const noexcept { return name == sysFunc.name; }
78+
bool operator==(const SystemFunc& sysFunc) const noexcept;
7979
private:
8080
friend class Schedule;
8181
Mode mode;
8282
std::string_view name;
8383
std::size_t hashCode; // after name
8484
bool isParallel;
85-
std::function<void(World*, SingletonsView, Entity, std::size_t, CmptsView, ChunkView, CommandBufferView)> func;
85+
std::function<void(World*, SingletonsView, Entity, std::size_t, CmptsView, ChunkView, CommandBufferPtr)> func;
8686
};
8787
}
8888

include/UECS/World.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ namespace Ubpa::UECS {
147147
SingletonLocator = {}
148148
) const;
149149

150-
synchronized_monotonic_buffer_resource* GetSyncFrameResource() { return sync_frame_rsrc.get(); }
151-
std::pmr::monotonic_buffer_resource* GetUnsyncFrameResource() { return unsync_frame_rsrc.get(); }
152-
std::pmr::synchronized_pool_resource* GetSyncResource() { return sync_rsrc.get(); }
153-
std::pmr::unsynchronized_pool_resource* GetUnsyncResource() { return unsync_rsrc.get(); }
150+
synchronized_monotonic_buffer_resource* GetSyncFrameResource();
151+
std::pmr::monotonic_buffer_resource* GetUnsyncFrameResource();
152+
std::pmr::synchronized_pool_resource* GetSyncResource();
153+
std::pmr::unsynchronized_pool_resource* GetUnsyncResource();
154154

155155
template<typename T, typename... Args> T* SyncNewFrameObject(Args&&... args);
156156
template<typename T, typename... Args> T* UnsyncNewFrameObject(Args&&... args);
157157

158-
std::uint64_t Version() const noexcept { return version; }
158+
std::uint64_t Version() const noexcept;
159159
private:
160160
bool inRunningJobGraph{ false };
161161

include/UECS/details/SystemFunc.inl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ namespace Ubpa::UECS {
104104
&& !Contain_v<ArgList, std::size_t>
105105
&& !Contain_v<ArgList, CmptsView>
106106
&& !Contain_v<ArgList, ChunkView>
107-
&& !Contain_v<ArgList, CommandBufferView>,
108-
"(Mode::Job) SystemFunc's argument list cann't have Entity, indexInQuery CmptsView, ChunkView or CommandBufferView"
107+
&& !Contain_v<ArgList, CommandBufferPtr>,
108+
"(Mode::Job) SystemFunc's argument list cann't have Entity, indexInQuery CmptsView, ChunkView or CommandBufferPtr"
109109
);
110110
}
111111
}
@@ -127,7 +127,7 @@ namespace Ubpa::UECS::details {
127127
std::size_t entityIndexInQuery,
128128
CmptsView cmpts,
129129
ChunkView chunkView,
130-
CommandBufferView cbv)
130+
CommandBufferPtr cb)
131131
{
132132
auto args = std::tuple{
133133
w,
@@ -136,9 +136,9 @@ namespace Ubpa::UECS::details {
136136
e,
137137
entityIndexInQuery,
138138
cmpts,
139-
reinterpret_cast<NonSingletons*>(cmpts.Components()[Find_v<NonSingletonList, NonSingletons>].Ptr())...,
139+
reinterpret_cast<NonSingletons*>(cmpts.AccessComponents()[Find_v<NonSingletonList, NonSingletons>].Ptr())...,
140140
chunkView,
141-
cbv
141+
cb
142142
};
143143
func(std::get<DecayedArgs>(args)...);
144144
};

0 commit comments

Comments
 (0)