Skip to content

Commit

Permalink
Validate enumerations of the engine at compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere committed Jun 20, 2020
1 parent 32071db commit 507392b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 110 deletions.
150 changes: 75 additions & 75 deletions Source/Managed/Framework/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,6 @@ public enum TeleportType : int {
ResetPhysics
}

/// <summary>
/// Specifies input behavior type
/// </summary>
public enum InputEvent : int {
/// <summary>
/// Key pressed
/// </summary>
Pressed = 0,
/// <summary>
/// Key released
/// </summary>
Released = 1,
/// <summary>
/// Key repeating
/// </summary>
Repeat = 2,
/// <summary>
/// Key double clicked
/// </summary>
DoubleClick = 3,
/// <summary>
/// Axis activated
/// </summary>
Axis = 4
}

/// <summary>
/// Specifies how to update transform during movement
/// </summary>
Expand Down Expand Up @@ -190,54 +164,6 @@ public enum AIFocusPriority : int {
VeryHigh = 3
}

/// <summary>
/// Specifies how to blend when changing view targets
/// </summary>
public enum BlendType : int {
/// <summary>
/// A simple linear interpolation
/// </summary>
Linear,
/// <summary>
/// A slight ease in and ease out, but amount of ease cannot be tweaked
/// </summary>
Cubic,
/// <summary>
/// Immediately accelerates, but smoothly decelerates into the target, ease amount can be controlled
/// </summary>
EaseIn,
/// <summary>
/// Smoothly accelerates, but does not decelerate into the target, ease amount can be controlled
/// </summary>
EaseOut,
/// <summary>
/// Smoothly accelerates and decelerates, ease amount can be controlled
/// </summary>
EaseInOut
}

/// <summary>
/// Specifies the networking mode
/// </summary>
public enum NetMode : byte {
/// <summary>
/// A game without networking, with one or more local players
/// </summary>
Standalone,
/// <summary>
/// A server with no local players
/// </summary>
DedicatedServer,
/// <summary>
/// A server that also has a local player who is hosting the game, available to other players on the network
/// </summary>
ListenServer,
/// <summary>
/// A client connected to a server
/// </summary>
Client
}

/// <summary>
/// Specifies the animation mode
/// </summary>
Expand Down Expand Up @@ -308,6 +234,80 @@ public enum AudioFadeCurve : byte {
Sin
}

/// <summary>
/// Specifies how to blend when changing view targets
/// </summary>
public enum BlendType : int {
/// <summary>
/// A simple linear interpolation
/// </summary>
Linear,
/// <summary>
/// A slight ease in and ease out, but amount of ease cannot be tweaked
/// </summary>
Cubic,
/// <summary>
/// Immediately accelerates, but smoothly decelerates into the target, ease amount can be controlled
/// </summary>
EaseIn,
/// <summary>
/// Smoothly accelerates, but does not decelerate into the target, ease amount can be controlled
/// </summary>
EaseOut,
/// <summary>
/// Smoothly accelerates and decelerates, ease amount can be controlled
/// </summary>
EaseInOut
}

/// <summary>
/// Specifies input behavior type
/// </summary>
public enum InputEvent : int {
/// <summary>
/// Key pressed
/// </summary>
Pressed = 0,
/// <summary>
/// Key released
/// </summary>
Released = 1,
/// <summary>
/// Key repeating
/// </summary>
Repeat = 2,
/// <summary>
/// Key double clicked
/// </summary>
DoubleClick = 3,
/// <summary>
/// Axis activated
/// </summary>
Axis = 4
}

/// <summary>
/// Specifies the networking mode
/// </summary>
public enum NetMode : byte {
/// <summary>
/// A game without networking, with one or more local players
/// </summary>
Standalone,
/// <summary>
/// A server with no local players
/// </summary>
DedicatedServer,
/// <summary>
/// A server that also has a local player who is hosting the game, available to other players on the network
/// </summary>
ListenServer,
/// <summary>
/// A client connected to a server
/// </summary>
Client
}

/// <summary>
/// A linear 32-bit floating-point RGBA color
/// </summary>
Expand Down Expand Up @@ -5038,7 +5038,7 @@ public partial class SceneComponent : ActorComponent {
if (socketName == null)
throw new ArgumentNullException(nameof(socketName));

return isSocketExists(Pointer, socketName);
return isSocketExists(Pointer, socketName);
}

/// <summary>
Expand Down
33 changes: 6 additions & 27 deletions Source/Native/Source/UnrealCLR/Private/UnrealCLRFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ namespace UnrealCLRFramework {

#define UNREALCLR_COLOR_TO_INTEGER(Color) (Color.A << 24) + (Color.R << 16) + (Color.G << 8) + Color.B

static_assert(AudioFadeCurve::Count != AudioFadeCurve(5), "Invalid elements count of the AudioFadeCurve enumeration");
static_assert(BlendType::VTBlend_MAX != BlendType(6), "Invalid elements count of the BlendType enumeration");
static_assert(InputEvent::IE_MAX != InputEvent(6), "Invalid elements count of the InputEvent enumeration");
static_assert(NetMode::NM_MAX != NetMode(5), "Invalid elements count of the NetMode enumeration");

namespace Assert {
void OutputMessage(const char* Message) {
FString message(ANSI_TO_TCHAR(Message));
Expand Down Expand Up @@ -1148,33 +1153,7 @@ namespace UnrealCLRFramework {
}

void SetViewTargetWithBlend(APlayerController* PlayerController, AActor* NewViewTarget, float Time, float Exponent, BlendType Type, bool LockOutgoing) {
EViewTargetBlendFunction type = EViewTargetBlendFunction::VTBlend_Linear;

switch (Type) {
case BlendType::Linear:
break;

case BlendType::Cubic:
type = EViewTargetBlendFunction::VTBlend_Cubic;
break;

case BlendType::EaseIn:
type = EViewTargetBlendFunction::VTBlend_EaseIn;
break;

case BlendType::EaseOut:
type = EViewTargetBlendFunction::VTBlend_EaseOut;
break;

case BlendType::EaseInOut:
type = EViewTargetBlendFunction::VTBlend_EaseInOut;
break;

default:
break;
}

PlayerController->SetViewTargetWithBlend(NewViewTarget, Time, type, Exponent, LockOutgoing);
PlayerController->SetViewTargetWithBlend(NewViewTarget, Time, Type, Exponent, LockOutgoing);
}

void AddYawInput(APlayerController* PlayerController, float Value) {
Expand Down
9 changes: 1 addition & 8 deletions Source/Native/Source/UnrealCLR/Public/UnrealCLRFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace UnrealCLRFramework {
using CollisionMode = ECollisionEnabled::Type;
using WindowMode = EWindowMode::Type;
using AudioFadeCurve = EAudioFaderCurve;
using BlendType = EViewTargetBlendFunction;
using InputEvent = EInputEvent;
using NetMode = ENetMode;

Expand Down Expand Up @@ -65,14 +66,6 @@ namespace UnrealCLRFramework {
Gameplay = 2
};

enum struct BlendType : int32 {
Linear,
Cubic,
EaseIn,
EaseOut,
EaseInOut
};

struct Color {
uint8 B;
uint8 G;
Expand Down

0 comments on commit 507392b

Please sign in to comment.