Skip to content

Commit

Permalink
unreal integration (#163)
Browse files Browse the repository at this point in the history
Co-authored-by: Mateusz Dahlke <[email protected]>
Co-authored-by: Mateusz Wiktor <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2023
1 parent 70cf891 commit 2fd4975
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 9 deletions.
21 changes: 13 additions & 8 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: c-core
schema: 1
version: "4.3.0"
version: "4.4.0"
scm: github.com/pubnub/c-core
changelog:
- date: 2023-09-28
version: v4.4.0
changes:
- type: feature
text: "Provide module files to integrate SDK with Unreal Enigne."
- date: 2023-07-24
version: v4.3.0
changes:
Expand Down Expand Up @@ -727,7 +732,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -793,7 +798,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -859,7 +864,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -921,7 +926,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -982,7 +987,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1038,7 +1043,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1091,7 +1096,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.3.0
location: https://github.com/pubnub/c-core/releases/tag/v4.4.0
requires:
-
name: "miniz"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v4.4.0
September 28 2023

#### Added
- Provide module files to integrate SDK with Unreal Enigne.

## v4.3.0
July 24 2023

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The directories of the library repository are:

- `microchip_harmony` : Modules and project for Microchip MPLAB Harmony

- `unreal` : Unreal Engine integration module


## Files

Expand Down
2 changes: 1 addition & 1 deletion core/pubnub_version_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define INC_PUBNUB_VERSION_INTERNAL


#define PUBNUB_SDK_VERSION "4.3.0"
#define PUBNUB_SDK_VERSION "4.4.0"


#endif /* !defined INC_PUBNUB_VERSION_INTERNAL */
6 changes: 6 additions & 0 deletions unreal/PubNubModule/Private/PubNubModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "PubNubModule.h"
#include "Modules/ModuleManager.h"

IMPLEMENT_MODULE(FDefaultModuleImpl, PubNubModule);
55 changes: 55 additions & 0 deletions unreal/PubNubModule/PubNubModule.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright Epic Games, Inc. All Rights Reserved.

using System.IO;
using UnrealBuildTool;



public class PubNubModule : ModuleRules
{
// select desired module type

// `posix`, `openssl`, `windows`
private readonly string Option = "posix";

// `posix`, `windows`
private readonly string Architecture = "posix";

// `sync`, `callback`
private readonly string Implementation = "sync";

public PubNubModule(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });

if (Option == "openssl") {
PublicDependencyModuleNames.AddRange(new string[] { "OpenSSL" });
}

var path = Path.Combine(new string[] { ModuleDirectory, "..", ".." });
var extention = Architecture == "posix" ? "a" : "lib";

PublicAdditionalLibraries.Add(Path.Combine(path, Option, $"pubnub_{Implementation}.{extention}"));
PublicIncludePaths.AddRange(
new string[] {
path,
Path.Combine(path, "core"),
Path.Combine(path, "lib"),
Path.Combine(path, Option)
}
);

PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));

// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");

// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}
3 changes: 3 additions & 0 deletions unreal/PubNubModule/Public/PubNub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
THIRD_PARTY_INCLUDES_START
#include "../../ThirdParty/c-core/unreal/pubnub_core.hpp"
THIRD_PARTY_INCLUDES_END
6 changes: 6 additions & 0 deletions unreal/PubNubModule/Public/PubNubModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

109 changes: 109 additions & 0 deletions unreal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Unreal Engine integration

Our C-core SDK can be used together with [Unreal Engine](https://www.unrealengine.com/en-US). It's **not** a fully functional plugin yet, but can easily be integrated into your project as a [Unreal Engine Module](https://docs.unrealengine.com/5.3/en-US/unreal-engine-modules/).

## How to setup PubNub C-Core SDK as a Unreal Engine Module

1. Clone this repository to the `<UnrealProject>/Source/` directory. We recommend that you place it inside the `ThirdParty` folder (create it, if necessary).

2. Compile the [desired option](https://www.pubnub.com/docs/sdks/c-core#hello-world) of the SDK. You can do it in the SDK directory like so:

- POSIX:

```sh
make -C <option> -f <architecture>.mk pubnub_<implementation>.a
```

- Windows:

```sh
nmake -f windows.mk
```

- Windows Universal Platform:

```sh
nmake -f windows/uwp.mk
```

Windows builds everything at once. We are aware that our build system needs some love.

For example, to build the OpenSSL option, run the following script:

```sh
make -C openssl -f posix.mk pubnub_sync.a
```

:warning: If you choose `openssl`, ensure that your OpenSSL library headers match the Unreal ones!

3. Adjust `PubNubModule/PubNubModule.Build.cs` with selected options by changing `option`, `architecture` and `implementation` with the same values you used for compilation.

> This is a temporary solution. We are aware that our build system needs some love.

For example:

```csharp
private readonly string Option = "openssl"; // posix, windows, openssl
private readonly string Architecture = "posix"; // posix, windows
private readonly string string Implementation = "sync"; // sync, callback
```

4. Finally, import the module into your project as follows:

- `<UnrealProject>.Target.cs` and `<UnrealProject>Editor.Target.cs`

```csharp
public class <UnrealProject>[Editor]Target : TargetRules
{
public <UnrealProject>[Editor]Target (TargetInfo Target) : base(Target)
{
//...
ExtraModuleNames.Add("PubNubModule");
}
}
```

- `<UnrealProject>.uproject`

```json
{
//...
"Modules": [
//...
{
"Name": "PubNubModule",
"Type": "Runtime",
"LoadingPhase": "Default"
}
],
//...
}
```

Generate the project files using your IDE of choice and you are ready to go!

## Usage

1. Make PubNub discoverable in the module you want to use PubNub in by modifying the `<Module>.Build.cs` file:

```csharp
public class <Module> : ModuleRules
{
public <Module>(ReadOnlyTargetRules Target) : base(Target)
{
//...
PrivateDependencyModuleNames.Add("PubNubModule");
}
}
```

2. Import the `PubNub.h` header into your files as follows:

```cpp
#include "PubNub.h"
```

> Note that you don't have to wrap it with `THIRD_PARTY_INCLUDES_START` and `THIRD_PARTY_INCLUDES_END` because we've done that for you.

Good luck with your project!

58 changes: 58 additions & 0 deletions unreal/pubnub_core.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
#if !defined INC_PUBNUB_CORE
#define INC_PUBNUB_CORE

extern "C" {

#include "../core/pubnub_api_types.h"
#include "../core/pubnub_assert.h"
#include "../core/pubnub_helper.h"
#include "../lib/pb_deprecated.h"
#include "../core/pubnub_alloc.h"
#include "../core/pubnub_pubsubapi.h"
#include "../core/pubnub_coreapi.h"
#include "../core/pubnub_coreapi_ex.h"
#include "../core/pubnub_generate_uuid.h"
#include "../core/pubnub_blocking_io.h"
#include "../core/pubnub_ssl.h"
#include "../core/pubnub_timers.h"
#include "../core/pubnub_helper.h"
#include "../core/pubnub_free_with_timeout.h"
#include "../core/pubnub_ntf_sync.h"
#if defined(PUBNUB_CALLBACK_API)
#include "../core/pubnub_ntf_callback.h"
#endif
#if PUBNUB_PROXY_API
#include "../core/pubnub_proxy.h"
#endif
#if PUBNUB_USE_SUBSCRIBE_V2
#include "../core/pubnub_subscribe_v2.h"
#endif
#if PUBNUB_CRYPTO_API
#include "../core/pubnub_crypto.h"
#endif
#if PUBNUB_USE_ADVANCED_HISTORY
#include "../core/pubnub_advanced_history.h"
#endif
#if PUBNUB_USE_FETCH_HISTORY
#include "../core/pubnub_fetch_history.h"
#endif
#if PUBNUB_USE_OBJECTS_API
#include "../core/pubnub_objects_api.h"
#define MAX_INCLUDE_DIMENSION 100
#define MAX_ELEM_LENGTH 30
#endif
#if PUBNUB_USE_ACTIONS_API
#include "../core/pubnub_actions_api.h"
#endif
#if PUBNUB_USE_GRANT_TOKEN_API
#include "../core/pubnub_grant_token_api.h"
#endif
#if PUBNUB_USE_REVOKE_TOKEN_API
#include "../core/pubnub_revoke_token_api.h"
#endif
#include "../core/pubnub_auto_heartbeat.h"

}

#endif // !defined INC_PUBNUB_CORE

0 comments on commit 2fd4975

Please sign in to comment.