diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8ebcca --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Binaries +Intermediate \ No newline at end of file diff --git a/LICENSE b/LICENSE index 2071b23..f8cefad 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2023 Kevin Poretti (kevinporetti.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 1e55af2..229bc02 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,72 @@ # UnrealFixedCollision -A collision detection library for Unreal Engine using fixed point math for coordinates and dimensions of collision shapes. \ No newline at end of file +A collision detection library for Unreal Engine using fixed point math for coordinates and dimensions of collision shapes. + +**Please note: this library depends on [the UnrealFixedPoint library](https://git.kevinporetti.com/poret/UnrealFixedPoint).** + +**Please note: this is NOT a physics library. This library aims to only provide collision detection. Any collision resolution must be handled on a project by project basis.** + +This library aims to closely match the interface and functionality of the existing collision library in Unreal Engine. This library tries to closely match the available collision shapes available in Unreal (both 2D and 3D) as well as other functionality involved with collision (collision and trace channels, line/shape traces, etc.). + +### To-Do + +- [ ] 2D Shapes + - [ ] Point + - [ ] Circle + - [ ] Box/Rectangle + - [ ] Line/Ray + - [ ] Arbitrary polygon +- [ ] 3D Shapes + - [ ] Point + - [ ] Sphere + - [ ] Capsule + - [ ] Box + - [ ] Line/Ray + - [ ] Arbitrary polygon +- [ ] Trace + - [ ] LineTrace/Raycast + - [ ] SphereCast + - [ ] BoxCast + - [ ] ShapeCast +- [ ] Collision channel support +- [ ] Trace channel support +- [ ] Broad phase collision detection using spatial partitioning +- [ ] Automatically get Unreal level/world/map collision data in a fixed point format +- [ ] Generate fixed point collision shapes during asset import + +### What is fixed point math? + +Fixed point math is math that uses an INT data type format (i.e. int, long, long long) rather than a floating point format (i.e. float or double). Unlike normal integers, which represent entirely whole numbers, fixed point can represent fractional numbers. The way this works is a portion of the bits of the underlying data type are reserved for the fractional portion of the value, while the rest of the bits are reserved for the whole number portion. + +For more detailed information on how this works see [the Wikipedia article](https://en.wikipedia.org/wiki/Computer_number_format#Fixed-point_numbers). + +### Why use fixed point over floating point? + +In short, some projects require your game simulation to be fully deterministic, meaning given a set of inputs and an initial "world state" of your game, the resulting update will be the same each time. + +Due to the nature of floating point numbers, calculations may result in slight differences between platforms or CPU architecture. This means your game simulation will not be fully deterministic. This can cause desyncs when implementing the lock-step or rollback networking models. + +There are ways to get deterministic behavior for floating point operations between architectures with compilar flags, but this is not guaranteed or particularly easy. This also may not be feasible if you are using precompiled binaries, like would be the case when using the installed version of Unreal Engine. See [this Gaffer On Games article for more information](https://www.gafferongames.com/post/floating_point_determinism/). + +### Setup + +Clone this repository into the Plugins folder of your game project or your Unreal Engine installation. + +Engine - /[UE Root]/Engine/Plugins/ +Game - /[Project Root]/Plugins/ + +### Usage + +Coming soon... + +### Supported Unreal Engine Versions + +- UE 5.1.1 + +### Known Issues + +None so far... + +### Licensing + +This library is available under [The MIT License](https://mit-license.org/). This library is free for commercial and non-commercial use. Attribution is not required, but is greatly appreciated. \ No newline at end of file diff --git a/Resources/Icon128.png b/Resources/Icon128.png new file mode 100644 index 0000000..1231d4a Binary files /dev/null and b/Resources/Icon128.png differ diff --git a/Source/UnrealFixedCollision/Private/UnrealFixedCollision.cpp b/Source/UnrealFixedCollision/Private/UnrealFixedCollision.cpp new file mode 100644 index 0000000..757d7fc --- /dev/null +++ b/Source/UnrealFixedCollision/Private/UnrealFixedCollision.cpp @@ -0,0 +1,22 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "UnrealFixedCollision.h" + +#define LOCTEXT_NAMESPACE "FUnrealFixedCollisionModule" + +void FUnrealFixedCollisionModule::StartupModule() +{ + // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module + +} + +void FUnrealFixedCollisionModule::ShutdownModule() +{ + // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, + // we call this function before unloading the module. + +} + +#undef LOCTEXT_NAMESPACE + +IMPLEMENT_MODULE(FUnrealFixedCollisionModule, UnrealFixedCollision) \ No newline at end of file diff --git a/Source/UnrealFixedCollision/Private/UnrealFixedCollisionBPLibrary.cpp b/Source/UnrealFixedCollision/Private/UnrealFixedCollisionBPLibrary.cpp new file mode 100644 index 0000000..f0197c4 --- /dev/null +++ b/Source/UnrealFixedCollision/Private/UnrealFixedCollisionBPLibrary.cpp @@ -0,0 +1,16 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "UnrealFixedCollisionBPLibrary.h" +#include "UnrealFixedCollision.h" + +UUnrealFixedCollisionBPLibrary::UUnrealFixedCollisionBPLibrary(const FObjectInitializer& ObjectInitializer) +: Super(ObjectInitializer) +{ + +} + +float UUnrealFixedCollisionBPLibrary::UnrealFixedCollisionSampleFunction(float Param) +{ + return -1; +} + diff --git a/Source/UnrealFixedCollision/Public/UnrealFixedCollision.h b/Source/UnrealFixedCollision/Public/UnrealFixedCollision.h new file mode 100644 index 0000000..793bea6 --- /dev/null +++ b/Source/UnrealFixedCollision/Public/UnrealFixedCollision.h @@ -0,0 +1,14 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "Modules/ModuleManager.h" + +class FUnrealFixedCollisionModule : public IModuleInterface +{ +public: + + /** IModuleInterface implementation */ + virtual void StartupModule() override; + virtual void ShutdownModule() override; +}; diff --git a/Source/UnrealFixedCollision/Public/UnrealFixedCollisionBPLibrary.h b/Source/UnrealFixedCollision/Public/UnrealFixedCollisionBPLibrary.h new file mode 100644 index 0000000..5a1d659 --- /dev/null +++ b/Source/UnrealFixedCollision/Public/UnrealFixedCollisionBPLibrary.h @@ -0,0 +1,32 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "Kismet/BlueprintFunctionLibrary.h" +#include "UnrealFixedCollisionBPLibrary.generated.h" + +/* +* Function library class. +* Each function in it is expected to be static and represents blueprint node that can be called in any blueprint. +* +* When declaring function you can define metadata for the node. Key function specifiers will be BlueprintPure and BlueprintCallable. +* BlueprintPure - means the function does not affect the owning object in any way and thus creates a node without Exec pins. +* BlueprintCallable - makes a function which can be executed in Blueprints - Thus it has Exec pins. +* DisplayName - full name of the node, shown when you mouse over the node and in the blueprint drop down menu. +* Its lets you name the node using characters not allowed in C++ function names. +* CompactNodeTitle - the word(s) that appear on the node. +* Keywords - the list of keywords that helps you to find node when you search for it using Blueprint drop-down menu. +* Good example is "Print String" node which you can find also by using keyword "log". +* Category - the category your node will be under in the Blueprint drop-down menu. +* +* For more info on custom blueprint nodes visit documentation: +* https://wiki.unrealengine.com/Custom_Blueprint_Node_Creation +*/ +UCLASS() +class UUnrealFixedCollisionBPLibrary : public UBlueprintFunctionLibrary +{ + GENERATED_UCLASS_BODY() + + UFUNCTION(BlueprintCallable, meta = (DisplayName = "Execute Sample function", Keywords = "UnrealFixedCollision sample test testing"), Category = "UnrealFixedCollisionTesting") + static float UnrealFixedCollisionSampleFunction(float Param); +}; diff --git a/Source/UnrealFixedCollision/UnrealFixedCollision.Build.cs b/Source/UnrealFixedCollision/UnrealFixedCollision.Build.cs new file mode 100644 index 0000000..391f60b --- /dev/null +++ b/Source/UnrealFixedCollision/UnrealFixedCollision.Build.cs @@ -0,0 +1,51 @@ +// UnrealFixedCollision Copyright Kevin Poretti + +using UnrealBuildTool; + +public class UnrealFixedCollision : ModuleRules +{ + public UnrealFixedCollision(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicIncludePaths.AddRange( + new string[] { + "../../UnrealFixedPoint/Source/UnrealFixedPoint/Public/" + } + ); + + + PrivateIncludePaths.AddRange( + new string[] { + // ... add other private include paths required here ... + } + ); + + + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + "UnrealFixedPoint", + } + ); + + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "CoreUObject", + "Engine", + // ... add private dependencies that you statically link with here ... + } + ); + + + DynamicallyLoadedModuleNames.AddRange( + new string[] + { + // ... add any modules that your module loads dynamically here ... + } + ); + } +} diff --git a/UnrealFixedCollision.uplugin b/UnrealFixedCollision.uplugin new file mode 100644 index 0000000..50e307c --- /dev/null +++ b/UnrealFixedCollision.uplugin @@ -0,0 +1,30 @@ +{ + "FileVersion": 3, + "Version": 1, + "VersionName": "1.0", + "FriendlyName": "UnrealFixedCollision", + "Description": "A collision detection library for Unreal Engine using fixed point math for coordinates and dimensions of collision shapes.", + "Category": "Other", + "CreatedBy": "Kevin Poretti", + "CreatedByURL": "https://kevinporetti.com", + "DocsURL": "", + "MarketplaceURL": "", + "SupportURL": "", + "CanContainContent": true, + "IsBetaVersion": true, + "IsExperimentalVersion": false, + "Installed": false, + "Modules": [ + { + "Name": "UnrealFixedCollision", + "Type": "Runtime", + "LoadingPhase": "PreLoadingScreen" + } + ], + "Plugins": [ + { + "Name": "UnrealFixedPoint", + "Enabled": true + } + ] +} \ No newline at end of file