Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
dcd91dc180 | |||
ef5545f5bd |
11
README.md
11
README.md
@ -1,4 +1,4 @@
|
|||||||
# UnrealFixedPoint
|
# UnrealFixedMath
|
||||||
|
|
||||||
A fixed point math library for Unreal Engine.
|
A fixed point math library for Unreal Engine.
|
||||||
|
|
||||||
@ -18,6 +18,15 @@ This library aims to closely match the interface and functionality of the existi
|
|||||||
- [ ] Fixed point version of FRotator
|
- [ ] Fixed point version of FRotator
|
||||||
- [ ] FFixedRotator class implementation
|
- [ ] FFixedRotator class implementation
|
||||||
- [ ] Corresponding FMath and UKismetMathLibrary utility functions
|
- [ ] Corresponding FMath and UKismetMathLibrary utility functions
|
||||||
|
- [ ] Blueprints
|
||||||
|
- [ ] Expose fixed arithmatic as pure Blueprint nodes
|
||||||
|
- [ ] Ability to edit fixed nums with float sliders/input fields
|
||||||
|
- [ ] Automatically do float <> fixed conversion when tweaking fixed point numbers in the editor
|
||||||
|
- [ ] Plugin config
|
||||||
|
- [ ] Configure how fixed nums are shown in editor when exposed as UPROPERTY (as floats only, as float and underlying int, as underlying int only)
|
||||||
|
- [ ] Handling errors and edge cases
|
||||||
|
- [ ] Overflow
|
||||||
|
- [ ] Infinity
|
||||||
|
|
||||||
### What is fixed point math?
|
### What is fixed point math?
|
||||||
|
|
||||||
|
3
Source/UnrealFixedMath/Private/Fixed.cpp
Normal file
3
Source/UnrealFixedMath/Private/Fixed.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// UnrealFixedPoint Copyright Kevin Poretti
|
||||||
|
|
||||||
|
#include "Fixed.h"
|
@ -1,16 +1,16 @@
|
|||||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
#include "UnrealFixedPoint.h"
|
#include "UnrealFixedMath.h"
|
||||||
|
|
||||||
#define LOCTEXT_NAMESPACE "FUnrealFixedPointModule"
|
#define LOCTEXT_NAMESPACE "FUnrealFixedMathModule"
|
||||||
|
|
||||||
void FUnrealFixedPointModule::StartupModule()
|
void FUnrealFixedMathModule::StartupModule()
|
||||||
{
|
{
|
||||||
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
|
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FUnrealFixedPointModule::ShutdownModule()
|
void FUnrealFixedMathModule::ShutdownModule()
|
||||||
{
|
{
|
||||||
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
|
// 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.
|
// we call this function before unloading the module.
|
||||||
@ -19,4 +19,4 @@ void FUnrealFixedPointModule::ShutdownModule()
|
|||||||
|
|
||||||
#undef LOCTEXT_NAMESPACE
|
#undef LOCTEXT_NAMESPACE
|
||||||
|
|
||||||
IMPLEMENT_MODULE(FUnrealFixedPointModule, UnrealFixedPoint)
|
IMPLEMENT_MODULE(FUnrealFixedMathModule, UnrealFixedMath)
|
16
Source/UnrealFixedMath/Private/UnrealFixedMathBPLibrary.cpp
Normal file
16
Source/UnrealFixedMath/Private/UnrealFixedMathBPLibrary.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
#include "UnrealFixedMathBPLibrary.h"
|
||||||
|
#include "UnrealFixedMath.h"
|
||||||
|
|
||||||
|
UUnrealFixedMathBPLibrary::UUnrealFixedMathBPLibrary(const FObjectInitializer& ObjectInitializer)
|
||||||
|
: Super(ObjectInitializer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float UUnrealFixedMathBPLibrary::UnrealFixedMathSampleFunction(float Param)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
57
Source/UnrealFixedMath/Public/Fixed.h
Normal file
57
Source/UnrealFixedMath/Public/Fixed.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// UnrealFixedMath Copyright Kevin Poretti
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Fixed.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct UNREALFIXEDMATH_API FFixed
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
// 48 bits for the whole portion, 16 bits for the fractional portion
|
||||||
|
static constexpr uint8 DecimalBitPosition = 16;
|
||||||
|
|
||||||
|
FFixed() : Data(0) { }
|
||||||
|
|
||||||
|
// int types <> FFixed conversions
|
||||||
|
FORCEINLINE FFixed(int64 A) { Data = A << DecimalBitPosition; }
|
||||||
|
FORCEINLINE operator int64() const { return Data >> DecimalBitPosition; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
int8
|
||||||
|
int16
|
||||||
|
FORCEINLINE operator uint8()
|
||||||
|
*/
|
||||||
|
|
||||||
|
// floating point types <> FFixed conversions
|
||||||
|
FORCEINLINE FFixed(float A) { Data = static_cast<int64>(A * (1 << DecimalBitPosition) + (A >= 0 ? 0.5 : -0.5)); }
|
||||||
|
FORCEINLINE operator float() const { return static_cast<float>(Data) / (1 << DecimalBitPosition); }
|
||||||
|
|
||||||
|
FORCEINLINE FFixed(double A) { Data = static_cast<int64>(A * (1 << DecimalBitPosition) + (A >= 0 ? 0.5 : -0.5)); }
|
||||||
|
FORCEINLINE operator double() const { return static_cast<double>(Data) / (1 << DecimalBitPosition); }
|
||||||
|
|
||||||
|
// Arithmetic
|
||||||
|
FFixed operator+(const FFixed& Other) const { return Data + Other.Data; }
|
||||||
|
FFixed operator+=(const FFixed& Other) { Data += Other.Data; return Data; }
|
||||||
|
|
||||||
|
FFixed operator-(const FFixed& Other) const { return Data - Other.Data; }
|
||||||
|
FFixed operator-=(const FFixed& Other) { Data -= Other.Data; return Data; }
|
||||||
|
|
||||||
|
// Other overloads
|
||||||
|
FFixed operator=(const FFixed& Other) { Data = Other.Data; return Data; }
|
||||||
|
FFixed operator-() const { return -Data; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int64 Data;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace FFixedMath
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "Modules/ModuleManager.h"
|
#include "Modules/ModuleManager.h"
|
||||||
|
|
||||||
class FUnrealFixedPointModule : public IModuleInterface
|
class FUnrealFixedMathModule : public IModuleInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||||
#include "UnrealFixedPointBPLibrary.generated.h"
|
#include "UnrealFixedMathBPLibrary.generated.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function library class.
|
* Function library class.
|
||||||
@ -23,10 +23,10 @@
|
|||||||
* https://wiki.unrealengine.com/Custom_Blueprint_Node_Creation
|
* https://wiki.unrealengine.com/Custom_Blueprint_Node_Creation
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class UUnrealFixedPointBPLibrary : public UBlueprintFunctionLibrary
|
class UUnrealFixedMathBPLibrary : public UBlueprintFunctionLibrary
|
||||||
{
|
{
|
||||||
GENERATED_UCLASS_BODY()
|
GENERATED_UCLASS_BODY()
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Execute Sample function", Keywords = "UnrealFixedPoint sample test testing"), Category = "UnrealFixedPointTesting")
|
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Execute Sample function", Keywords = "UnrealFixedMath sample test testing"), Category = "UnrealFixedMathTesting")
|
||||||
static float UnrealFixedPointSampleFunction(float Param);
|
static float UnrealFixedMathSampleFunction(float Param);
|
||||||
};
|
};
|
@ -1,10 +1,10 @@
|
|||||||
// Some copyright should be here...
|
// UnrealFixedMath Copyright Kevin Poretti
|
||||||
|
|
||||||
using UnrealBuildTool;
|
using UnrealBuildTool;
|
||||||
|
|
||||||
public class UnrealFixedPoint : ModuleRules
|
public class UnrealFixedMath : ModuleRules
|
||||||
{
|
{
|
||||||
public UnrealFixedPoint(ReadOnlyTargetRules Target) : base(Target)
|
public UnrealFixedMath(ReadOnlyTargetRules Target) : base(Target)
|
||||||
{
|
{
|
||||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
#include "UnrealFixedPointBPLibrary.h"
|
|
||||||
#include "UnrealFixedPoint.h"
|
|
||||||
|
|
||||||
UUnrealFixedPointBPLibrary::UUnrealFixedPointBPLibrary(const FObjectInitializer& ObjectInitializer)
|
|
||||||
: Super(ObjectInitializer)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
float UUnrealFixedPointBPLibrary::UnrealFixedPointSampleFunction(float Param)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
"FileVersion": 3,
|
"FileVersion": 3,
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"VersionName": "1.0",
|
"VersionName": "1.0",
|
||||||
"FriendlyName": "UnrealFixedPoint",
|
"FriendlyName": "Unreal Fixed Math",
|
||||||
"Description": "This library provides a fixed point number primitive with corresponding data types that are useful for game development (i.e. vector, rotator, transform).",
|
"Description": "This library provides a fixed point number primitive with corresponding data types that are useful for game development (i.e. vector, rotator, transform).",
|
||||||
"Category": "Math",
|
"Category": "Math",
|
||||||
"CreatedBy": "Kevin Poretti",
|
"CreatedBy": "Kevin Poretti",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"Installed": false,
|
"Installed": false,
|
||||||
"Modules": [
|
"Modules": [
|
||||||
{
|
{
|
||||||
"Name": "UnrealFixedPoint",
|
"Name": "UnrealFixedMath",
|
||||||
"Type": "Runtime",
|
"Type": "Runtime",
|
||||||
"LoadingPhase": "PreLoadingScreen"
|
"LoadingPhase": "PreLoadingScreen"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user