Skip to content

Commit 3e11586

Browse files
committed
feat: initial basic implementation #2
0 parents  commit 3e11586

File tree

14 files changed

+894
-0
lines changed

14 files changed

+894
-0
lines changed

.clang-format

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
AccessModifierOffset: -2
2+
AlignAfterOpenBracket: BlockIndent
3+
AlignConsecutiveAssignments: false
4+
AlignConsecutiveDeclarations: true
5+
AlignEscapedNewlines: Left
6+
AlignOperands: DontAlign
7+
AlignTrailingComments: false
8+
AllowAllArgumentsOnNextLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: WithoutElse
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: true
18+
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BraceWrapping:
22+
AfterClass: false
23+
AfterControlStatement: false
24+
AfterEnum: false
25+
AfterFunction: false
26+
AfterNamespace: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
AfterExternBlock: false
30+
BeforeCatch: false
31+
BeforeElse: false
32+
IndentBraces: false
33+
SplitEmptyFunction: false
34+
SplitEmptyRecord: false
35+
SplitEmptyNamespace: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakBeforeBinaryOperators: None
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializers: BeforeComma
42+
BreakConstructorInitializersBeforeComma: false
43+
BreakStringLiterals: true
44+
ColumnLimit: 80
45+
CompactNamespaces: false
46+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
47+
ConstructorInitializerIndentWidth: 2
48+
ContinuationIndentWidth: 2
49+
Cpp11BracedListStyle: true
50+
DerivePointerAlignment: false
51+
DisableFormat: false
52+
ExperimentalAutoDetectBinPacking: false
53+
FixNamespaceComments: true
54+
IncludeBlocks: Preserve
55+
IncludeIsMainRegex: "(Test)?$"
56+
IndentCaseLabels: true
57+
IndentPPDirectives: AfterHash
58+
IndentWidth: 2
59+
IndentWrappedFunctionNames: false
60+
InsertBraces: true
61+
JavaScriptQuotes: Leave
62+
JavaScriptWrapImports: true
63+
KeepEmptyLinesAtTheStartOfBlocks: false
64+
MacroBlockBegin: ""
65+
MacroBlockEnd: ""
66+
MaxEmptyLinesToKeep: 1
67+
NamespaceIndentation: None
68+
PackConstructorInitializers: NextLine
69+
PenaltyBreakAssignment: 10
70+
PenaltyBreakBeforeFirstCallParameter: 30
71+
PenaltyBreakComment: 10
72+
PenaltyBreakFirstLessLess: 0
73+
PenaltyBreakString: 10
74+
PenaltyExcessCharacter: 400
75+
PenaltyReturnTypeOnItsOwnLine: 350
76+
PointerAlignment: Left
77+
ReflowComments: true
78+
RequiresClausePosition: OwnLine
79+
SortIncludes: false
80+
SortUsingDeclarations: true
81+
SpaceAfterCStyleCast: false
82+
SpaceAfterLogicalNot: false
83+
SpaceAfterTemplateKeyword: false
84+
SpaceBeforeAssignmentOperators: true
85+
SpaceBeforeCtorInitializerColon: true
86+
SpaceBeforeInheritanceColon: true
87+
SpaceBeforeParens: Never
88+
SpaceBeforeRangeBasedForLoopColon: true
89+
SpaceInEmptyParentheses: false
90+
SpacesBeforeTrailingComments: 1
91+
SpacesInAngles: Never
92+
SpacesInContainerLiterals: false
93+
SpacesInCStyleCastParentheses: false
94+
SpacesInParentheses: false
95+
SpacesInSquareBrackets: false
96+
SeparateDefinitionBlocks: Always
97+
Standard: Latest
98+
TabWidth: 2
99+
UseTab: ForContinuationAndIndentation

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
indent_size = 4
7+
indent_style = tab
8+

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.png filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Visual Studio 2015 user specific files
2+
.vs/
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
22+
# Compiled Static libraries
23+
*.lai
24+
*.la
25+
*.a
26+
*.lib
27+
28+
# Executables
29+
*.exe
30+
*.out
31+
*.app
32+
*.ipa
33+
34+
# These project files can be generated by the engine
35+
*.xcodeproj
36+
*.xcworkspace
37+
*.sln
38+
*.suo
39+
*.opensdf
40+
*.sdf
41+
*.VC.db
42+
*.VC.opendb
43+
44+
# Precompiled Assets
45+
SourceArt/**/*.png
46+
SourceArt/**/*.tga
47+
48+
# Binary Files
49+
Binaries/*
50+
Plugins/**/Binaries/*
51+
52+
# Builds
53+
Build/*
54+
55+
# Whitelist PakBlacklist-<BuildConfiguration>.txt files
56+
!Build/*/
57+
Build/*/**
58+
!Build/*/PakBlacklist*.txt
59+
60+
# Don't ignore icon files in Build
61+
!Build/**/*.ico
62+
63+
# Built data for maps
64+
*_BuiltData.uasset
65+
66+
# Configuration files generated by the Editor
67+
Saved/*
68+
69+
# Compiled source files for the engine to use
70+
Intermediate/*
71+
Plugins/**/Intermediate/*
72+
73+
# Cache files for the editor to use
74+
DerivedDataCache/*
75+
76+
# Clangd
77+
.cache
78+
compile_commands.json
79+
80+
# Generated Ecsact files
81+
82+
Source/**/*.ecsact.*

Ecsact.uplugin

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"FileVersion": 3,
3+
"Version": 1,
4+
"VersionName": "0.1.0",
5+
"FriendlyName": "Ecsact",
6+
"Description": "Ecsact integration for Unreal Engine",
7+
"Category": "Other",
8+
"CreatedBy": "Seaube",
9+
"CreatedByURL": "https://seaube.com",
10+
"DocsURL": "https://ecsact.dev/start/unreal",
11+
"MarketplaceURL": "",
12+
"SupportURL": "https://discord.gg/vKxQztg7gB",
13+
"CanContainContent": true,
14+
"IsBetaVersion": true,
15+
"IsExperimentalVersion": false,
16+
"Installed": false,
17+
"Modules": [
18+
{
19+
"Name": "Ecsact",
20+
"Type": "Runtime",
21+
"LoadingPhase": "Default"
22+
},
23+
{
24+
"Name": "EcsactEditor",
25+
"Type": "Editor",
26+
"LoadingPhase": "Default"
27+
}
28+
]
29+
}

Resources/Icon128.png

Lines changed: 3 additions & 0 deletions
Loading

Source/Ecsact/Ecsact.Build.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using UnrealBuildTool;
2+
using System.IO;
3+
using System.Diagnostics;
4+
using System;
5+
6+
[Serializable]
7+
public class EcsactSdkNotFound : Exception {
8+
public EcsactSdkNotFound(Exception inner)
9+
: base(
10+
"Ecsact CLI not found in PATH. Please make sure you have the Ecsact " +
11+
"SDK installed. https://ecsact.dev/start",
12+
inner
13+
) {
14+
}
15+
}
16+
17+
public class Ecsact : ModuleRules {
18+
public Ecsact(ReadOnlyTargetRules Target) : base(Target) {
19+
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
20+
21+
PublicDependencyModuleNames.AddRange(new string[] {
22+
"Core",
23+
});
24+
25+
PrivateDependencyModuleNames.AddRange(new string[] {
26+
"CoreUObject",
27+
"Engine",
28+
"Slate",
29+
"SlateCore",
30+
});
31+
32+
if(Target.bBuildEditor) {
33+
PrivateDependencyModuleNames.Add("UnrealEd");
34+
}
35+
36+
var ecsactSdkIncludeDir = GetEcsactSdkIncludeDir();
37+
PublicIncludePaths.Add(ecsactSdkIncludeDir);
38+
39+
// NOTE: For now these APIs are loaded on module startup
40+
PublicDefinitions.AddRange(new string[] {
41+
"ECSACT_CORE_API_LOAD_AT_RUNTIME",
42+
"ECSACT_DYNAMIC_API_LOAD_AT_RUNTIME",
43+
"ECSACT_ASYNC_API_LOAD_AT_RUNTIME",
44+
"ECSACT_META_API_LOAD_AT_RUNTIME",
45+
"ECSACT_SERIALIZE_API_LOAD_AT_RUNTIME",
46+
"ECSACT_STATIC_API_LOAD_AT_RUNTIME",
47+
});
48+
}
49+
50+
private string GetEcsactSdkIncludeDir() {
51+
var includePath = "";
52+
53+
try {
54+
ProcessStartInfo startInfo = new ProcessStartInfo();
55+
startInfo.FileName = "ecsact";
56+
startInfo.Arguments = "config include_dir";
57+
startInfo.RedirectStandardOutput = true;
58+
startInfo.UseShellExecute = false;
59+
startInfo.CreateNoWindow = true;
60+
61+
using(Process process = Process.Start(startInfo)) {
62+
using(StreamReader reader = process.StandardOutput) {
63+
includePath = reader.ReadToEnd().Trim();
64+
}
65+
}
66+
} catch(Exception err) {
67+
throw new EcsactSdkNotFound(err);
68+
}
69+
70+
return includePath;
71+
}
72+
}

Source/Ecsact/Private/Ecsact.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include "Ecsact.h"
2+
#include "CoreGlobals.h"
3+
#include "HAL/PlatformProcess.h"
4+
#include "Misc/Paths.h"
5+
#include "ecsact/runtime.h"
6+
7+
#define LOCTEXT_NAMESPACE "FEcsactModule"
8+
9+
DEFINE_LOG_CATEGORY(Ecsact);
10+
11+
#define INIT_ECSACT_API_FN(fn, UNUSED_PARAM) decltype(fn) fn = nullptr
12+
FOR_EACH_ECSACT_API_FN(INIT_ECSACT_API_FN, UNUSED_PARAM);
13+
#undef INIT_ECSACT_API_FN
14+
15+
auto FEcsactModule::Abort() -> void {
16+
#ifdef WITH_EDITOR
17+
if(GEditor) {
18+
GEditor->EndPlayMap();
19+
return;
20+
}
21+
#endif
22+
}
23+
24+
auto FEcsactModule::LoadEcsactRuntime() -> void {
25+
auto ecsact_runtime_path = FPaths::Combine(
26+
FPaths::ProjectDir(),
27+
TEXT("Binaries/Win64/EcsactRuntime.dll")
28+
);
29+
30+
EcsactRuntimeHandle = FPlatformProcess::GetDllHandle(*ecsact_runtime_path);
31+
32+
if(!EcsactRuntimeHandle) {
33+
UE_LOG(
34+
Ecsact,
35+
Error,
36+
TEXT("Failed to load ecsact runtime: %s"),
37+
*ecsact_runtime_path
38+
);
39+
Abort();
40+
return;
41+
}
42+
43+
#define LOAD_ECSACT_FN(fn, UNUSED_PARAM) \
44+
fn = reinterpret_cast<decltype(fn)>( \
45+
FPlatformProcess::GetDllExport(EcsactRuntimeHandle, TEXT(#fn)) \
46+
)
47+
FOR_EACH_ECSACT_API_FN(LOAD_ECSACT_FN);
48+
#undef LOAD_ECSACT_FN
49+
}
50+
51+
auto FEcsactModule::UnloadEcsactRuntime() -> void {
52+
if(EcsactRuntimeHandle) {
53+
FPlatformProcess::FreeDllHandle(EcsactRuntimeHandle);
54+
EcsactRuntimeHandle = nullptr;
55+
}
56+
57+
#define RESET_ECSACT_FN(fn, UNUSED_PARAM) fn = nullptr
58+
FOR_EACH_ECSACT_API_FN(RESET_ECSACT_FN);
59+
#undef RESET_ECSACT_FN
60+
}
61+
62+
auto FEcsactModule::StartupModule() -> void {
63+
if(!GIsEditor) {
64+
LoadEcsactRuntime();
65+
}
66+
#if WITH_EDITOR
67+
FEditorDelegates::PreBeginPIE.AddRaw(this, &FEcsactModule::OnPreBeginPIE);
68+
FEditorDelegates::EndPIE.AddRaw(this, &FEcsactModule::OnEndPIE);
69+
#endif
70+
}
71+
72+
auto FEcsactModule::ShutdownModule() -> void {
73+
if(!GIsEditor) {
74+
UnloadEcsactRuntime();
75+
}
76+
77+
#if WITH_EDITOR
78+
FEditorDelegates::PreBeginPIE.RemoveAll(this);
79+
FEditorDelegates::EndPIE.RemoveAll(this);
80+
#endif
81+
}
82+
83+
auto FEcsactModule::OnPreBeginPIE(bool _) -> void {
84+
LoadEcsactRuntime();
85+
}
86+
87+
auto FEcsactModule::OnEndPIE(bool _) -> void {
88+
UnloadEcsactRuntime();
89+
}
90+
91+
#undef LOCTEXT_NAMESPACE
92+
93+
IMPLEMENT_MODULE(FEcsactModule, Ecsact)

0 commit comments

Comments
 (0)