Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unreal integration #163

Merged
merged 29 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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"

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

Our can use the PubNub C-Core SDK with [Unreal Engine](https://www.unrealengine.com/en-US). It's **not** a fully functional plugin yet, but you can easily integrate it into your project as an Unreal module.

## Setup

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:

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

For example:

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

> :warning: If you choose the `openssl` option, 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 out build system needs some love.

For example:

```csharp
private readonly string Option = "openssl";
private readonly string Architecture = "posix";
private readonly string string Implementation = "sync";
```

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`

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

Now, generate the project files using your IDE and you're 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"
```

> :warning: 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
Loading