Skip to content

Commit

Permalink
World::Run*Job const
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Oct 5, 2020
1 parent 05eab28 commit be99291
Show file tree
Hide file tree
Showing 20 changed files with 335 additions and 149 deletions.
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(UECS VERSION 0.13.1)
project(UECS VERSION 0.13.2)
message(STATUS "[Project] ${PROJECT_NAME}")

include(cmake/InitUCMake.cmake)
Ubpa_InitUCMake()

Ubpa_InitProject()

Ubpa_AddDep(UContainer 0.0.6)
Ubpa_AddDep(UTemplate 0.4.7)
Ubpa_AddDep(UGraphviz 0.1.4)
Ubpa_AddDep(UContainer 0.0.7)
Ubpa_AddDep(UTemplate 0.4.8)
Ubpa_AddDep(UGraphviz 0.1.5)

Ubpa_AddSubDirsRec(include)
Ubpa_AddSubDirsRec(src)

Ubpa_Export(DIRECTORIES "include")
Ubpa_Export(
TARGET
DIRECTORIES
"include"
)
4 changes: 2 additions & 2 deletions cmake/InitUCMake.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
macro(Ubpa_InitUCMake)
include(FetchContent)
set(UCMake_VERSION 0.6.1)
set(UCMake_VERSION 0.6.2)
message(STATUS "find package: UCMake ${UCMake_VERSION}")
find_package(UCMake ${UCMake_VERSION} QUIET)
find_package(UCMake ${UCMake_VERSION} EXACT QUIET)
if(NOT UCMake_FOUND)
message(STATUS "UCMake ${UCMake_VERSION} not found")
set(_address "https://github.com/Ubpa/UCMake")
Expand Down
4 changes: 2 additions & 2 deletions include/UECS/ArchetypeFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "CmptType.h"

#include <UTemplate/TypeList.h>

#include <set>

namespace Ubpa::UECS {
Expand All @@ -15,6 +13,8 @@ namespace Ubpa::UECS {

size_t HashCode() const noexcept;

bool HaveWriteCmptType() const noexcept;

bool operator==(const ArchetypeFilter& rhs) const;
};
}
2 changes: 2 additions & 0 deletions include/UECS/CmptLocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace Ubpa::UECS {
const CmptAccessTypeSet& CmptAccessTypes() const noexcept { return cmptTypes; }

bool operator==(const CmptLocator& rhs) const;

bool HasWriteCmptType() const noexcept;
private:
size_t GenHashCode() const noexcept;

Expand Down
101 changes: 0 additions & 101 deletions include/UECS/CmptTag.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once

#include <UTemplate/Typelist.h>

namespace Ubpa::UECS {

// read/write tag : LastFrame -> Write -> Latest
// singleton tag : Singleton
// ====
Expand Down Expand Up @@ -110,104 +107,6 @@ namespace Ubpa::UECS {
private:
const Cmpt* cmpt;
};

template<typename TaggedCmpt>
void* CastToVoidPointer(TaggedCmpt p) {
return const_cast<void*>(reinterpret_cast<const void*>(p));
}

// <Cmpt> (without read/write and singleton tag)
template<typename TaggedCmpt>
struct RemoveTag;
template<typename TaggedCmpt>
using RemoveTag_t = typename RemoveTag<TaggedCmpt>::type;

// <Cmpt> / Singleton<Cmpt>
template<typename TaggedCmpt>
struct RemoveRWTag;
template<typename TaggedCmpt>
using RemoveRWTag_t = typename RemoveRWTag<TaggedCmpt>::type;

// LastFrame<Cmpt>
// Write<Cmpt> / Cmpt*
// Latest<Cmpt> / const Cmpt*
template<typename TaggedCmpt>
struct RemoveSingletonTag;
template<typename TaggedCmpt>
using RemoveSingletonTag_t = typename RemoveSingletonTag<TaggedCmpt>::type;

// <Cmpt>*
template<typename TaggedCmpt>
struct DecayTag;
template<typename TaggedCmpt>
using DecayTag_t = typename DecayTag<TaggedCmpt>::type;

template<typename TaggedCmpt>
struct IsLastFrame;
template<typename TaggedCmpt>
static constexpr bool IsLastFrame_v = IsLastFrame<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsWrite;
template<typename TaggedCmpt>
static constexpr bool IsWrite_v = IsWrite<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsLatest;
template<typename TaggedCmpt>
static constexpr bool IsLatest_v = IsLatest<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsLastFrameSingleton;
template<typename TaggedCmpt>
static constexpr bool IsLastFrameSingleton_v = IsLastFrameSingleton<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsWriteSingleton;
template<typename TaggedCmpt>
static constexpr bool IsWriteSingleton_v = IsWriteSingleton<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsLatestSingleton;
template<typename TaggedCmpt>
static constexpr bool IsLatestSingleton_v = IsLatestSingleton<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsSingleton : IValue<bool,
IsLastFrameSingleton_v<TaggedCmpt>
|| IsWriteSingleton_v<TaggedCmpt>
|| IsLatestSingleton_v<TaggedCmpt>
> {};
template<typename TaggedCmpt>
static constexpr bool IsSingleton_v = IsSingleton<TaggedCmpt>::value;

template<typename TaggedCmpt>
struct IsNonSingleton : IValue<bool,
IsLastFrame_v<TaggedCmpt>
|| IsWrite_v<TaggedCmpt>
|| IsLatest_v<TaggedCmpt>
> {};
template<typename TaggedCmpt>
static constexpr bool IsNonSingleton_v = IsNonSingleton<TaggedCmpt>::value;

template<typename T>
struct IsTaggedCmpt : IValue<bool, IsNonSingleton_v<T> || IsSingleton_v<T>> {};
template<typename T>
static constexpr bool IsTaggedCmpt_v = IsTaggedCmpt<T>::value;

template<typename T, AccessMode defaultMode>
static constexpr AccessMode AccessModeOf_default =
IsLastFrame_v<T> ? AccessMode::LAST_FRAME : (
IsWrite_v<T> ? AccessMode::WRITE : (
IsLatest_v<T> ? AccessMode::LATEST : (
IsLastFrameSingleton_v<T> ? AccessMode::LAST_FRAME_SINGLETON : (
IsWriteSingleton_v<T> ? AccessMode::WRITE_SINGLETON : (
IsLatestSingleton_v<T> ? AccessMode::LATEST_SINGLETON :
defaultMode
)))));

template<typename T>
static constexpr AccessMode AccessModeOf = AccessModeOf_default<T, AccessMode::LATEST>;
}

#include "detail/CmptTag.inl"
6 changes: 3 additions & 3 deletions include/UECS/Schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Ubpa::UECS {
class Schedule {
public:
// Func's argument list:
// World*
// [const] World*
// {LastFrame|Latest}<Singleton<Cmpt>>
// SingletonsView
// Entity
Expand All @@ -44,7 +44,7 @@ namespace Ubpa::UECS {
);

// Func's argument list:
// World*
// [const] World*
// {LastFrame|Latest}<Singleton<Cmpt>>
// SingletonsView
// ChunkView (necessary)
Expand All @@ -58,7 +58,7 @@ namespace Ubpa::UECS {
);

// Func's argument list:
// World*
// [const] World*
// {LastFrame|Write|Latest}<Singleton<Cmpt>>
// SingletonsView
template<typename Func>
Expand Down
40 changes: 32 additions & 8 deletions include/UECS/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ namespace Ubpa::UECS {
void Accept(IListener*) const;

// you can't run several parallel jobs in parallel because there is only an executor
// you can't run parallel jobs in runing job graph

// Func's argument list:
// World*
// [const] World*
// {LastFrame|Latest}<Singleton<Cmpt>>
// SingletonsView
// Entity
Expand All @@ -61,9 +60,29 @@ namespace Ubpa::UECS {
);

// Func's argument list:
// World*
// const World*
// {LastFrame|Latest}<Singleton<Cmpt>>
// SingletonsView
// Entity
// size_t indexInQuery
// <tagged-components>: const <Cmpt>*...
// CmptsView
// --
// CmptLocator's Cmpt AccessMode can't be WRITE
template<typename Func>
void RunEntityJob(
Func&&,
bool isParallel = true,
ArchetypeFilter = {},
CmptLocator = {},
SingletonLocator = {}
) const;

// Func's argument list:
// [const] World*
// {LastFrame|Latest}<Singleton<Cmpt>>
// SingletonsView
// size_t entityBeginIndexInQuery
// ChunkView (necessary)
template<typename Func>
void RunChunkJob(
Expand All @@ -74,15 +93,20 @@ namespace Ubpa::UECS {
);

// Func's argument list:
// World*
// {LastFrame|Write|Latest}<Singleton<Cmpt>>
// const World*
// {LastFrame|Latest}<Singleton<Cmpt>>
// SingletonsView
// size_t entityBeginIndexInQuery
// ChunkView (necessary)
// --
// ArchetypeFilter's Cmpt AccessMode can't be WRITE
template<typename Func>
void RunJob(
void RunChunkJob(
Func&&,
ArchetypeFilter = {},
bool isParallel = true,
SingletonLocator = {}
);

) const;
private:
bool inRunningJobGraph{ false };

Expand Down
Loading

0 comments on commit be99291

Please sign in to comment.