Using Haxe with the Unreal Engine 4
https://bit.ly/unrealhx
By Cauê Waneck ( @cwaneck )
[~]$ whoami
C++ can be difficult to integrate with itself let alone other languages
Closed beta this year!
package unreal;
/**
Actor is the base class for an Object that can be placed or spawned in a level.
Actors may contain a collection of ActorComponents, which can be used to control how actors move, how they are rendered, etc.
The other main function of an Actor is the replication of properties and function calls across the network during play.
@see https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/
@see UActorComponent
**/
@:glueCppIncludes("GameFramework/Actor.h")
@:uextern extern class AActor extends unreal.UObject {
/**
Array of ActorComponents that are created by blueprints and serialized per-instance.
**/
public var BlueprintCreatedComponents : unreal.TArray<unreal.UActorComponent>;
#if WITH_EDITORONLY_DATA
/**
Local space pivot offset for the actor
**/
private var PivotOffset : unreal.FVector;
#end // WITH_EDITORONLY_DATA
/**
Returns the point of view of the actor.
Note that this doesn't mean the camera, but the 'eyes' of the actor.
For example, for a Pawn, this would define the eye height location,
and view rotation (which is different from the pawn rotation which has a zeroed pitch component).
A camera first person view will typically use this view point. Most traces (weapon, AI) will be done from this view point.
@param OutLocation - location of view point
@param OutRotation - view rotation of actor.
**/
@:thisConst public function GetActorEyesViewPoint(OutLocation : unreal.PRef<unreal.FVector>, OutRotation : unreal.PRef<unreal.FRotator>) : Void;
/**
Script exposed version of FindComponentByClass
**/
public function GetComponentByClass(ComponentClass : unreal.TSubclassOf<unreal.UActorComponent>) : unreal.UActorComponent;
package unreal;
/**
Actor is the base class for an Object that can be placed or spawned in a level.
Actors may contain a collection of ActorComponents, which can be used to control how actors move, how they are rendered, etc.
The other main function of an Actor is the replication of properties and function calls across the network during play.
@see https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/
@see UActorComponent
**/
@:glueCppIncludes("GameFramework/Actor.h")
@:uextern class AActor extends unreal.UObject {
/**
Array of ActorComponents that are created by blueprints and serialized per-instance.
**/
public var BlueprintCreatedComponents(get,set):unreal.PPtr<unreal.TArray<unreal.UActorComponent>>;
@:glueCppIncludes("GameFramework/Actor.h", "uhx/Wrapper.h")
@:glueHeaderIncludes("IntPtr.h", "VariantPtr.h")
@:glueHeaderCode("static void GetActorEyesViewPoint(unreal::UIntPtr self, unreal::VariantPtr OutLocation, unreal::VariantPtr OutRotation);")
@:glueCppCode("void uhx::glues::AActor_Glue_obj::GetActorEyesViewPoint(unreal::UIntPtr self, unreal::VariantPtr OutLocation, unreal::VariantPtr OutRotation) {\n\t( (AActor *) self )->GetActorEyesViewPoint(*::uhx::StructHelper< FVector >::getPointer(OutLocation), *::uhx::StructHelper< FRotator >::getPointer(OutRotation));\n}")
@:thisConst
public function GetActorEyesViewPoint(OutLocation : unreal.PRef<unreal.FVector>, OutRotation : unreal.PRef<unreal.FRotator>) : Void {
uhx.glues.AActor_Glue.GetActorEyesViewPoint(unreal.helpers.HaxeHelpers.getUObjectWrapped(this), OutLocation, OutRotation);
}
@:glueCppIncludes("GameFramework/Actor.h", "uhx/Wrapper.h", "Containers/Array.h", "Components/ActorComponent.h", "uhx/glues/TArrayImpl_Glue_UE.h")
@:glueHeaderIncludes("IntPtr.h", "VariantPtr.h")
@:glueHeaderCode("static unreal::VariantPtr get_BlueprintCreatedComponents(unreal::UIntPtr self);")
@:glueCppCode("unreal::VariantPtr uhx::glues::AActor_Glue_obj::get_BlueprintCreatedComponents(unreal::UIntPtr self) {\n\treturn ::uhx::TemplateHelper<TArray<UActorComponent *>>::fromPointer( (&(( (AActor *) self )->BlueprintCreatedComponents)) );\n}")
@:final @:nonVirtual
private function get_BlueprintCreatedComponents() : unreal.PPtr<unreal.TArray<unreal.UActorComponent>> {
return ( @:privateAccess unreal.TArrayImpl.fromPointer( uhx.glues.AActor_Glue.get_BlueprintCreatedComponents(unreal.helpers.HaxeHelpers.getUObjectWrapped(this)) ) : unreal.PPtr<unreal.TArray<unreal.UActorComponent>> );
}
/**
Script exposed version of FindComponentByClass
**/
@:glueCppIncludes("GameFramework/Actor.h", "UObject/ObjectBase.h", "Components/ActorComponent.h")
@:glueHeaderIncludes("IntPtr.h")
@:glueHeaderCode("static unreal::UIntPtr GetComponentByClass(unreal::UIntPtr self, unreal::UIntPtr ComponentClass);")
@:glueCppCode("unreal::UIntPtr uhx::glues::AActor_Glue_obj::GetComponentByClass(unreal::UIntPtr self, unreal::UIntPtr ComponentClass) {\n\treturn ( (unreal::UIntPtr) (( (AActor *) self )->GetComponentByClass(( (TSubclassOf<UActorComponent>) (UClass *) ComponentClass ))) );\n}")
public function GetComponentByClass(ComponentClass : unreal.TSubclassOf<unreal.UActorComponent>) : unreal.UActorComponent {
return ( cast unreal.UObject.wrap(uhx.glues.AActor_Glue.GetComponentByClass(unreal.helpers.HaxeHelpers.getUObjectWrapped(this), unreal.helpers.HaxeHelpers.getUObjectWrapped(ComponentClass))) : unreal.UActorComponent );
}
// you define templated functions and types!
@:glueCppIncludes('Templates/SharedPointer.h')
@:uextern extern class TSharedPtr<T> {
@:global
public static function MakeShareable<T>(ptr:PPtr<T>):TSharedPtr<T>;
/**
* Constructs an empty shared pointer
*/
@:uname('.ctor') public static function create<T>():TSharedPtr<T>;
/* snip ... */
}
// you can also define C++ enums!
@:glueCppIncludes("IHttpRequest.h")
@:uname("EHttpRequestStatus.Type")
@:uextern extern enum EHttpRequestStatus {
NotStarted;
Processing;
Failed;
Succeeded;
}
// and delegates! Yes you can bind normal Haxe functions to them
@:glueCppIncludes("IHttpRequest.h")
@:uname('FHttpRequestCompleteDelegate')
typedef FHttpRequestCompleteDelegate = Delegate<FHttpRequestCompleteDelegate, TSharedPtr<IHttpRequest>->TThreadSafeSharedPtr<IHttpResponse>->Bool->Void>;
// also C++ method pointers:
/**
* Binds a delegate function to an Action defined in the project settings.
* Returned reference is only guaranteed to be valid until another action is bound.
*/
public function BindAction(actionName:Const<FName>, keyEvent:EInputEvent, object:UObject, func:MethodPointer<UObject,Void->Void>) : PRef<FInputActionBinding>;
// also some operators are supported
@:glueCppIncludes("Array.h")
@:uextern @:noCopy extern class TIndexedContainerIterator<Ar, El, Ind> {
public function op_Increment() : Void;
public function op_Decrement() : Void;
public function op_Dereference() : PRef<El>;
public function op_Not() : Bool;
}
package platformer;
import unreal.*;
using unreal.CoreAPI;
// define a new delegate
typedef FRoundFinishedDelegate = DynamicMulticastDelegate<FRoundFinishedDelegate, Void->Void>;
// you can define your own UENUMs through Haxe - which can be used by C++!
@:uenum
enum EGameState {
Intro;
Waiting;
Playing;
Finished;
Restarting;
}
@:uclass
// you can use @:uname to define the target name, without having to use that
@:uname("APlatformerGameMode")
class GameMode extends AGameMode {
var someHaxeArray:Array<String>;
var someUnrealArray:TArray<Int8>;
@:uexpose var someExposedUnrealArray:TArray<FString>;
/** delegate to broadcast about finished round */
@:uproperty(BlueprintAssignable)
public var OnRoundFinished:FRoundFinishedDelegate;
public function someHaxeFunction(json:{ name:String, age:Int }):Void { /* ... */ }
@:uexpose public function someUnrealFunction(char:Character, basicType:Bool):Void { /* ... */ }
/* snip .. */
}
@:uclass(Abstract)
@:uname("APlatformerCharacter")
class Character extends ACharacter {
/** player pawn initialization */
override public function PostInitializeComponents():Void {
super.PostInitializeComponents();
SetActorRotation(FRotator.createWithValues(0,0,0));
}
/* snip ... */
}
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "PlatformerClimbMarker.generated.h"
UCLASS(Blueprintable)
class APlatformerClimbMarker : public AActor
{
GENERATED_UCLASS_BODY()
private:
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category=Mesh, meta=(AllowPrivateAccess="true"))
UStaticMeshComponent* Mesh;
public:
/** Returns Mesh subobject **/
FORCEINLINE UStaticMeshComponent* GetMesh() const { return Mesh; }
};
class FPlatformerMessageData
{
/** text to display */
FString Message;
/** how long this FMessageData will be displayed in seconds */
float DisplayDuration;
/** TimeSeconds when this FMessageData was first shown */
float DisplayStartTime;
/** x axis position on screen <0, 1> (0 means left side of the screen) ; text will be centered */
float PosX;
/** y axis position on screen <0, 1> (0 means top of the screen) ; text will be centered */
float PosY;
/** text scale */
float TextScale;
/** if red border should be drawn instead of blue */
bool bRedBorder;
};
C++ | Haxe |
---|---|
FSomeStruct | FSomeStruct |
FSomeStruct& | PRef<FSomeStruct> |
FSomeStruct * | PPtr<FSomeStruct> or POwnedPtr<FSomeStruct> |
const FSomeStruct& | Const<PRef<FSomeStruct>> |
FSomeStruct ** | <not supported... yet> |