SlideShare a Scribd company logo
Adding Love to an API
(or How I Learned to Stop Worrying and Expose C++ to Unity)
Shawn Laptiste
Software Developer - Game Integrations, Audiokinetic
1
GenerativeArt–MadewithUnity
Adding <3 to an APIHow I Learned to Stop Worrying and Expose C++ to Unity
Shawn Laptiste
Software Developer - Game Integrations, Audiokinetic
@lazerfalcon, slaptiste@audiokinetic.com
2
Wwise Sound Engine
Wwise supports most of the platforms that Unity deploys
to.
3
Legend
4
C# C/C++
Calling Functions
5
Calling Functions
Pseudo-code
6
// Unity C# - Pseudo Code!!!
public class NormalUnityComponent :
UnityEngine.MonoBehaviour
{
private void Start()
{
AmazingCppFunctionality();
}
}
// C/C++ - Pseudo code!!!
void AmazingCppFunctionality()
{
do
{
AmazingStuff();
}
while (!finished);
}
// Generic Function declaration
DLL_EXPORT ReturnType CALL_CONV GenericFunction(ArgType1 arg1, ArgType2, arg2);
#if IS_A_MICROSOFT_PLATFORM
#else
#endif
DLL_EXPORT void CALL_CONV AmazingCppFunctionality();
#define DLL_EXPORT extern "C" __declspec(dllexport)
#define CALL_CONV __stdcall
#define DLL_EXPORT extern "C"
#define CALL_CONV
Exporting C/C++ Functions
Interoperability
7
Exposing the Library Code
Dynamically Linked Library (DLL)
8
Native Plug-ins Are NEVER Unloaded
Gotchas
9
This can present problems while developing and iterating
on your native code.
Consider testing your native code natively!
public class NormalUnityComponent : UnityEngine.MonoBehaviour
{
private void Start() { Functionality(); }
}
#if STATIC_LINKING_WITH_PLUGIN
public const string PluginName = "__Internal";
#else
public const string PluginName = "NativePlugin";
#endif
[DllImport(PluginName, EntryPoint = "AmazingCppFunctionality")]
private static extern void Functionality();
using System.Runtime.InteropServices;
Calling C/C++ Functions From C#
Platform Invocation Services (P/Invoke)
10
Exceptions
Gotchas
11
Exceptions must not cross the managed/unmanaged
boundary.
Under most circumstances, this will lead to a crash!
Passing Data
12
Passing Data
Pseudo-code
13
// Unity C#
public class NormalUnityComponent : UnityEngine.MonoBehaviour
{
private void Start()
{
var data = GetCppData();
DoStuffWithTheData(data);
DoMoarStuffWithTheData(ref data);
}
}
Marshalling is the process of
transferring data between
managed and unmanaged
memory and performing the
required copying or data
conversion.
14
byte (System.SByte) char
ubyte (System.Byte) unsigned char
short (System.Int16) short
ushort (System.UInt16) unsigned short
int (System.Int32) int
uint (System.UInt32) unsigned int
long (System.Int64) long long
ulong (System.UInt64) unsigned long long
System.IntPtr std::intptr_t (void*)
System.UIntPtr std::uintptr_t
float (System.Single) float
double (System.Double) double
Primitive Data Types
Blittable Types
15
● One-Dimensional Arrays of Blittable Types
● Structs Containing Blittable Types
Complex Blittable Types
Blittable Types
16
● All Other Types!!!
● String
Non-Blittable Types
Blittable Types
17
Marshalling Primitive Data Types
Actual code!
18
using System.Runtime.InteropServices;
public partial class NativePlugin
{
[DllImport(PluginName)]
public static extern
float GetDataByReturnValue();
[DllImport(PluginName)]
public static extern
void GetDataByReference(ref float data);
[DllImport(PluginName)]
public static extern
void SetData(float data);
}
static float Data = 90000.0f;
DLL_EXPORT
float CALL_CONV GetDataByReturnValue()
{ return Data; }
DLL_EXPORT
void CALL_CONV GetDataByReference(float& data)
{ data = Data; }
DLL_EXPORT
void CALL_CONV SetData(float data)
{ Data = data; }
public class MarshallingPrimitiveDataTypesTest :
UnityEngine.MonoBehaviour
{
private void Start()
{
float d = 0;
NativePlugin.GetDataByReference(ref d);
print("Data = " + d); // Data = ???
NativePlugin.SetData(90);
NativePlugin.GetDataByReference(ref d);
print("Data = " + d); // Data = 90
}
}
Accessing Primitive Data Types in Unity
M04R C0D3!!!
19
Static Initialization
Gotchas
20
Static initialization of C/C++ variables occurs only once,
when the plug-in is loaded.
Prepare for this or it can lead to unexpected behaviour!
Marshalling One-Dimensional Arrays
Pseudo-code
21
public class NormalUnityComponent :
UnityEngine.MonoBehaviour
{
public int[] Integers = new int[40];
private void Start()
{
FillArray(Integers, 125);
}
}
using System.Runtime.InteropServices;
public partial class NativePlugin
{
[DllImport(PluginName, EntryPoint = "FillArray"))]
private static extern int FillArrayPrivate(int[] integers, int size, int v);
}
public static int FillArray(int[] integers, int v)
{ return FillArrayPrivate(integers, integers.Length, v); }
Marshalling One-Dimensional Arrays
Interoperability
22
DLL_EXPORT int CALL_CONV FillArray(int* integers, int size, int v)
{
if (!integers || size < 1)
return 0;
// ...
}
Access Violations
Gotchas
23
Buffer overruns and dereferenced null-pointers can lead
to serious problems.
Exceptions that could have been caught in C# may
cause Unity and your application to crash.
Bounds checks and null-pointer checks are your friends!
In general, don’t hold onto pointers received from
managed land!
// Valid C/C++ code
enum WeekDay
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
WeekDay GetDayOfTheWeek();
Marshalling Enums
Pseudo-code
24
// C# Pseudo-code
public class NormalUnityComponent :
UnityEngine.MonoBehaviour
{
private void Start()
{
print(GetDayOfTheWeek());
}
}
// Production ready C/C++ code
enum WeekDay : int
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
DLL_EXPORT WeekDay CALL_CONV GetDayOfTheWeek();
Marshalling Enums
Bit representation
25
// Production ready Unity C# code
public enum WeekDay : int
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
public partial class NativePlugin
{
[System.Runtime.InteropServices.DllImport(PluginName)]
public static extern WeekDay GetDayOfTheWeek();
}
using System.Runtime.InteropServices;
public class MarshallingEnumsTest : UnityEngine.MonoBehaviour
{
[DllImport(NativePlugin.PluginName)]
private static extern WeekDay GetDayOfTheWeek();
private void Start()
{
WeekDay day = GetDayOfTheWeek();
print(day);
}
}
DLL_EXPORT WeekDay CALL_CONV GetDayOfTheWeek()
{ return Wednesday; }
Marshalling Enums
Example code
26
using UnityEngine;
public class NormalUnityComponent : MonoBehaviour
{
private void Start()
{
Vector3 vec = GetVectorFromCppLand();
// ...
DoSomethingWithAVectorInCppLand(vec);
}
}
Marshalling Structs
Pseudo-code
27
// C/C++
struct V3
{
float X;
float Y;
float Z;
};
Marshalling Structs
Structure Layout
28
// Unity C#
namespace UnityEngine
{
public struct Vector3 /* ... */
{
// ...
public float x;
public float y;
public float z;
// ...
}
}
Struct Layout
Gotchas
29
When marshalling structs, special attention should be
placed on the struct layout.
Member alignment and struct packing must match
between managed and unmanaged representations!
class CppClass
{
public:
float Value = 0.0f;
int Function()
{ return ++InternalCounter; }
private:
int InternalCounter = 0;
};
“Marshalling” C++ Classes
Exposing similar syntax
30
“Marshalling” C++ Classes
Allocation/Deallocation
31
public partial class CppClassProxy
{
private System.IntPtr CppPtr = System.IntPtr.Zero;
public CppClassProxy()
{ CppPtr = NativePlugin.CreateCppClass(); }
~CppClassProxy()
{ NativePlugin.DestroyCppClass(CppPtr); CppPtr = System.IntPtr.Zero; }
}
DLL_EXPORT CppClass* CALL_CONV CreateCppClass()
{ return new CppClass(); }
DLL_EXPORT void CALL_CONV DestroyCppClass(CppClass* c)
{ delete c; }
“Marshalling” C++ Classes
Accessors
32
public partial class CppClassProxy
{
public float Value
{
get { return NativePlugin.CppClass_Value_get(CppPtr); }
set { NativePlugin.CppClass_Value_set(CppPtr, value); }
}
}
DLL_EXPORT float CALL_CONV CppClass_Value_get(CppClass* c)
{ return c ? c->Value : 0.0f; }
DLL_EXPORT void CALL_CONV CppClass_Value_set(CppClass* c, float v)
{ if (c) c->Value = v; }
“Marshalling” C++ Classes
Member Functions
33
public partial class CppClassProxy
{
public int Function()
{
return NativePlugin.CppClass_Function(CppPtr);
}
}
DLL_EXPORT int CALL_CONV CppClass_Function(CppClass* c)
{ return c ? c->Function() : 0; }
public class MarshallingStructuresTest02 :
UnityEngine.MonoBehaviour
{
private void Start()
{
var c = new CppClassProxy();
print(c.Value + " " + c.Function());
c.Value = 80.5f;
print(c.Value + " " + c.Function());
}
}
Accessing C++ Classes in Unity
Sample use and output
34
struct CppClass
{
float Value = 0.0f;
int InternalCounter = 0;
int Function()
{ return ++InternalCounter; }
};
Null Pointers, Memory Leaks, and Referencing Deallocated Data
Gotchas
35
Null checks are important.
It is also important to ensure that allocated data is
appropriately deallocated.
Memory management is now in your hands!
Get dirty, but remember to clean yourself up!
Advanced Topics
0NLy 4 3L337 H4X0RZ
36
/ C# Pseudo-code
public class MagicalTextComponent :
UnityEngine.MonoBehaviour
{
private void Start()
{
print(MakeTextMagical("TEXT"));
}
}
Marshalling Strings
Pseudo-code
37
using System.Runtime.InteropServices;
public partial class NativePlugin
{
[DllImport(PluginName, EntryPoint = "ModifyText")]
private static extern System.IntPtr ModifyTextImpl([MarshalAs(UnmanagedType.LPStr)] string text);
}
System.IntPtr [MarshalAs(UnmanagedType.LPStr)]
public static string ModifyText(string text)
{ return Marshal.PtrToStringAnsi(ModifyTextImpl(text)); }
Marshalling Single-Byte Character Strings (char* in C/C++)
Interoperability
38
DLL_EXPORT const char* CALL_CONV ModifyText(const char* text)
{
return DoTextMagic(text);
}
Marshalling Multi-Byte Character Strings (wchar_t* in C/C++)
Interoperability
39
using System.Runtime.InteropServices;
public partial class NativePlugin
{
[DllImport(PluginName, EntryPoint = "GetName")]
private static extern System.IntPtr GetNameImpl();
public static string GetName(string text)
{ return Marshal.PtrToStringUni(GetNameImpl()); }
[DllImport(PluginName)]
private static extern void SetName([MarshalAs(UnmanagedType.LPWStr)] string name);
}
DLL_EXPORT const wchar_t* CALL_CONV GetName();
DLL_EXPORT void CALL_CONV SetName(const wchar_t* n);
Strings
Gotchas
40
String marshalling requires special care.
Prepare for performance penalties when using strings
extensively.
Strings should be avoided as part of your API.
using System.Runtime.InteropServices;
public partial class CallbackMarshallingTest : MonoBehaviour
{
[DllImport(NativePlugin.PluginName)]
private static extern void DoExtensiveWork(LoggerInteropDelegate logger, int steps);
}
DLL_EXPORT void CALL_CONV DoExtensiveWork(Logger logger, int steps)
{
logger("Starting initialization work...");
if (TestFailure(steps))
logger("Initialization failed.");
}
typedef void(CALL_CONV * Logger)(const char*);
Marshalling Delegates
Interoperability
41
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void LoggerInteropDelegate([MarshalAs(UnmanagedType.LPStr)] string message);
public partial class CallbackMarshallingTest : MonoBehaviour
{
private LoggerInteropDelegate Logger = new LoggerInteropDelegate(LogFunction);
[AOT.MonoPInvokeCallback(typeof(LoggerInteropDelegate))]
private static void LogFunction(string message)
{
print("Native Message: " + message);
}
}
private void Start()
{
DoExtensiveWork(Logger, 0);
}
Delegates as C/C++ Callbacks
Example
42
Delegated Callback Problem Solver
Gotchas
43
● Unity’s multithreading restrictions
● Garbage Collection
Devs should avoid passing managed delegates as
native callbacks when they are uncertain of the
ramifications!
● CppSharp
● SWIG
(Simplified Wrapper and Interface Generator)
Automation
44
Automation is No Panacea
Gotchas
45
Hours can be wasted fighting
against your automation tool to
consistently produce the required
output when it might be expedient to
simply handcraft a solution for
specific edge cases.
https://xkcd.com/1319/
Conclusion
● Marshalling
○ Primitive Types
○ One-Dimensional Arrays
○ Enums
○ Structures
○ Strings
○ Delegates as Callbacks
46
● Gotchas
○ Native Plug-ins are not unloaded
○ Exceptions
○ Static Initialization
○ Use Strings sparingly
○ Memory Management
○ Access Violations
○ ...
GenerativeArt–MadewithUnity
47
Thank you.

More Related Content

What's hot

REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...
REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...
REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...
Sangwoo Mo
 
【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...
【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...
【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...
Deep Learning JP
 
Mascara1
Mascara1Mascara1
Mascara1
Maria Amora
 
2SAT(充足可能性問題)の解き方
2SAT(充足可能性問題)の解き方2SAT(充足可能性問題)の解き方
2SAT(充足可能性問題)の解き方
Tsuneo Yoshioka
 
Usage of Generative Adversarial Networks (GANs) in Healthcare
Usage of Generative Adversarial Networks (GANs) in HealthcareUsage of Generative Adversarial Networks (GANs) in Healthcare
Usage of Generative Adversarial Networks (GANs) in Healthcare
GlobalLogic Ukraine
 
第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて
第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて
第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて
The Whole Brain Architecture Initiative
 
Kabsch Fit on PyMOL
Kabsch Fit on PyMOLKabsch Fit on PyMOL
Kabsch Fit on PyMOL
Masahito Ohue
 
文献紹介:YOLO series:v1-v5, X, F, and YOWO
文献紹介:YOLO series:v1-v5, X, F, and YOWO文献紹介:YOLO series:v1-v5, X, F, and YOWO
文献紹介:YOLO series:v1-v5, X, F, and YOWO
Toru Tamaki
 
ELFの動的リンク
ELFの動的リンクELFの動的リンク
ELFの動的リンク
7shi
 
CookWhat - 食材画像からのレシピ提案-
CookWhat  - 食材画像からのレシピ提案-CookWhat  - 食材画像からのレシピ提案-
CookWhat - 食材画像からのレシピ提案-
Shizuma Kubo
 
StoryboardでUIを使いまわす
StoryboardでUIを使いまわすStoryboardでUIを使いまわす
StoryboardでUIを使いまわす
Masaki Fuke
 
Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...
Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...
Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...
Sungchul Kim
 
[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization
[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization
[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization
Deep Learning JP
 
ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)
ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)
ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)
Masakazu Iwamura
 
12 分くらいで知るLuaVM
12 分くらいで知るLuaVM12 分くらいで知るLuaVM
12 分くらいで知るLuaVM
Yuki Tamura
 
モデル高速化百選
モデル高速化百選モデル高速化百選
モデル高速化百選
Yusuke Uchida
 
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組みTokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組みYohei Sato
 
期末專題報告書
期末專題報告書期末專題報告書
期末專題報告書
HsuChi Chen
 
CH551/2/8/9を炙ってみた
CH551/2/8/9を炙ってみたCH551/2/8/9を炙ってみた
CH551/2/8/9を炙ってみた
Junichi Akita
 
[DL輪読会] off-policyなメタ強化学習
[DL輪読会] off-policyなメタ強化学習[DL輪読会] off-policyなメタ強化学習
[DL輪読会] off-policyなメタ強化学習
Deep Learning JP
 

What's hot (20)

REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...
REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...
REBAR: Low-variance, unbiased gradient estimates for discrete latent variable...
 
【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...
【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...
【DL輪読会】StyleGAN-T: Unlocking the Power of GANs for Fast Large-Scale Text-to-I...
 
Mascara1
Mascara1Mascara1
Mascara1
 
2SAT(充足可能性問題)の解き方
2SAT(充足可能性問題)の解き方2SAT(充足可能性問題)の解き方
2SAT(充足可能性問題)の解き方
 
Usage of Generative Adversarial Networks (GANs) in Healthcare
Usage of Generative Adversarial Networks (GANs) in HealthcareUsage of Generative Adversarial Networks (GANs) in Healthcare
Usage of Generative Adversarial Networks (GANs) in Healthcare
 
第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて
第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて
第7回WBAシンポジウム:全脳確率的生成モデル(WB-PGM)〜世界モデルと推論に基づく汎用人工知能に向けて
 
Kabsch Fit on PyMOL
Kabsch Fit on PyMOLKabsch Fit on PyMOL
Kabsch Fit on PyMOL
 
文献紹介:YOLO series:v1-v5, X, F, and YOWO
文献紹介:YOLO series:v1-v5, X, F, and YOWO文献紹介:YOLO series:v1-v5, X, F, and YOWO
文献紹介:YOLO series:v1-v5, X, F, and YOWO
 
ELFの動的リンク
ELFの動的リンクELFの動的リンク
ELFの動的リンク
 
CookWhat - 食材画像からのレシピ提案-
CookWhat  - 食材画像からのレシピ提案-CookWhat  - 食材画像からのレシピ提案-
CookWhat - 食材画像からのレシピ提案-
 
StoryboardでUIを使いまわす
StoryboardでUIを使いまわすStoryboardでUIを使いまわす
StoryboardでUIを使いまわす
 
Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...
Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...
Generalized Intersection over Union: A Metric and A Loss for Bounding Box Reg...
 
[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization
[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization
[DL輪読会]Model-Based Reinforcement Learning via Meta-Policy Optimization
 
ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)
ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)
ディープラーニングを用いた物体認識とその周辺 ~現状と課題~ (Revised on 18 July, 2018)
 
12 分くらいで知るLuaVM
12 分くらいで知るLuaVM12 分くらいで知るLuaVM
12 分くらいで知るLuaVM
 
モデル高速化百選
モデル高速化百選モデル高速化百選
モデル高速化百選
 
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組みTokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
 
期末專題報告書
期末專題報告書期末專題報告書
期末專題報告書
 
CH551/2/8/9を炙ってみた
CH551/2/8/9を炙ってみたCH551/2/8/9を炙ってみた
CH551/2/8/9を炙ってみた
 
[DL輪読会] off-policyなメタ強化学習
[DL輪読会] off-policyなメタ強化学習[DL輪読会] off-policyなメタ強化学習
[DL輪読会] off-policyなメタ強化学習
 

Similar to Adding Love to an API (or How to Expose C++ in Unity)

Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
Joan Puig Sanz
 
P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#
Rainer Stropek
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
Sunil OS
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
ssuser33f16f
 
C++ via C#
C++ via C#C++ via C#
C++ via C#
Egor Bogatov
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
Fujio Kojima
 
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slidesC# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
Sami Mut
 
C#
C#C#
PyHEP 2018: Tools to bind to Python
PyHEP 2018:  Tools to bind to PythonPyHEP 2018:  Tools to bind to Python
PyHEP 2018: Tools to bind to Python
Henry Schreiner
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Doug Hawkins
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
Microsoft Tech Community
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
Microsoft Tech Community
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
Garth Gilmour
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
Michael Ivanov
 

Similar to Adding Love to an API (or How to Expose C++ in Unity) (20)

Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
 
C++ via C#
C++ via C#C++ via C#
C++ via C#
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
 
Hems
HemsHems
Hems
 
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slidesC# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
 
C#
C#C#
C#
 
PyHEP 2018: Tools to bind to Python
PyHEP 2018:  Tools to bind to PythonPyHEP 2018:  Tools to bind to Python
PyHEP 2018: Tools to bind to Python
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
 

More from Unity Technologies

Build Immersive Worlds in Virtual Reality
Build Immersive Worlds  in Virtual RealityBuild Immersive Worlds  in Virtual Reality
Build Immersive Worlds in Virtual Reality
Unity Technologies
 
Augmenting reality: Bring digital objects into the real world
Augmenting reality: Bring digital objects into the real worldAugmenting reality: Bring digital objects into the real world
Augmenting reality: Bring digital objects into the real world
Unity Technologies
 
Let’s get real: An introduction to AR, VR, MR, XR and more
Let’s get real: An introduction to AR, VR, MR, XR and moreLet’s get real: An introduction to AR, VR, MR, XR and more
Let’s get real: An introduction to AR, VR, MR, XR and more
Unity Technologies
 
Using synthetic data for computer vision model training
Using synthetic data for computer vision model trainingUsing synthetic data for computer vision model training
Using synthetic data for computer vision model training
Unity Technologies
 
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global IndustriesThe Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
Unity Technologies
 
Unity Roadmap 2020: Live games
Unity Roadmap 2020: Live games Unity Roadmap 2020: Live games
Unity Roadmap 2020: Live games
Unity Technologies
 
Unity Roadmap 2020: Core Engine & Creator Tools
Unity Roadmap 2020: Core Engine & Creator ToolsUnity Roadmap 2020: Core Engine & Creator Tools
Unity Roadmap 2020: Core Engine & Creator Tools
Unity Technologies
 
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
Unity Technologies
 
Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity XR platform has a new architecture – Unite Copenhagen 2019Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity Technologies
 
Turn Revit Models into real-time 3D experiences
Turn Revit Models into real-time 3D experiencesTurn Revit Models into real-time 3D experiences
Turn Revit Models into real-time 3D experiences
Unity Technologies
 
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
Unity Technologies
 
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
Unity Technologies
 
QA your code: The new Unity Test Framework – Unite Copenhagen 2019
QA your code: The new Unity Test Framework – Unite Copenhagen 2019QA your code: The new Unity Test Framework – Unite Copenhagen 2019
QA your code: The new Unity Test Framework – Unite Copenhagen 2019
Unity Technologies
 
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Unity Technologies
 
Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Supplying scalable VR training applications with Innoactive - Unite Copenhage...Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Unity Technologies
 
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
Unity Technologies
 
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Unity Technologies
 
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Unity Technologies
 
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
Unity Technologies
 
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
Unity Technologies
 

More from Unity Technologies (20)

Build Immersive Worlds in Virtual Reality
Build Immersive Worlds  in Virtual RealityBuild Immersive Worlds  in Virtual Reality
Build Immersive Worlds in Virtual Reality
 
Augmenting reality: Bring digital objects into the real world
Augmenting reality: Bring digital objects into the real worldAugmenting reality: Bring digital objects into the real world
Augmenting reality: Bring digital objects into the real world
 
Let’s get real: An introduction to AR, VR, MR, XR and more
Let’s get real: An introduction to AR, VR, MR, XR and moreLet’s get real: An introduction to AR, VR, MR, XR and more
Let’s get real: An introduction to AR, VR, MR, XR and more
 
Using synthetic data for computer vision model training
Using synthetic data for computer vision model trainingUsing synthetic data for computer vision model training
Using synthetic data for computer vision model training
 
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global IndustriesThe Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
 
Unity Roadmap 2020: Live games
Unity Roadmap 2020: Live games Unity Roadmap 2020: Live games
Unity Roadmap 2020: Live games
 
Unity Roadmap 2020: Core Engine & Creator Tools
Unity Roadmap 2020: Core Engine & Creator ToolsUnity Roadmap 2020: Core Engine & Creator Tools
Unity Roadmap 2020: Core Engine & Creator Tools
 
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
 
Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity XR platform has a new architecture – Unite Copenhagen 2019Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity XR platform has a new architecture – Unite Copenhagen 2019
 
Turn Revit Models into real-time 3D experiences
Turn Revit Models into real-time 3D experiencesTurn Revit Models into real-time 3D experiences
Turn Revit Models into real-time 3D experiences
 
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
 
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
 
QA your code: The new Unity Test Framework – Unite Copenhagen 2019
QA your code: The new Unity Test Framework – Unite Copenhagen 2019QA your code: The new Unity Test Framework – Unite Copenhagen 2019
QA your code: The new Unity Test Framework – Unite Copenhagen 2019
 
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
 
Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Supplying scalable VR training applications with Innoactive - Unite Copenhage...Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Supplying scalable VR training applications with Innoactive - Unite Copenhage...
 
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
 
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
 
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
 
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
 
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
 

Recently uploaded

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 

Recently uploaded (20)

Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 

Adding Love to an API (or How to Expose C++ in Unity)

  • 1. Adding Love to an API (or How I Learned to Stop Worrying and Expose C++ to Unity) Shawn Laptiste Software Developer - Game Integrations, Audiokinetic 1
  • 2. GenerativeArt–MadewithUnity Adding <3 to an APIHow I Learned to Stop Worrying and Expose C++ to Unity Shawn Laptiste Software Developer - Game Integrations, Audiokinetic @lazerfalcon, slaptiste@audiokinetic.com 2
  • 3. Wwise Sound Engine Wwise supports most of the platforms that Unity deploys to. 3
  • 6. Calling Functions Pseudo-code 6 // Unity C# - Pseudo Code!!! public class NormalUnityComponent : UnityEngine.MonoBehaviour { private void Start() { AmazingCppFunctionality(); } } // C/C++ - Pseudo code!!! void AmazingCppFunctionality() { do { AmazingStuff(); } while (!finished); }
  • 7. // Generic Function declaration DLL_EXPORT ReturnType CALL_CONV GenericFunction(ArgType1 arg1, ArgType2, arg2); #if IS_A_MICROSOFT_PLATFORM #else #endif DLL_EXPORT void CALL_CONV AmazingCppFunctionality(); #define DLL_EXPORT extern "C" __declspec(dllexport) #define CALL_CONV __stdcall #define DLL_EXPORT extern "C" #define CALL_CONV Exporting C/C++ Functions Interoperability 7
  • 8. Exposing the Library Code Dynamically Linked Library (DLL) 8
  • 9. Native Plug-ins Are NEVER Unloaded Gotchas 9 This can present problems while developing and iterating on your native code. Consider testing your native code natively!
  • 10. public class NormalUnityComponent : UnityEngine.MonoBehaviour { private void Start() { Functionality(); } } #if STATIC_LINKING_WITH_PLUGIN public const string PluginName = "__Internal"; #else public const string PluginName = "NativePlugin"; #endif [DllImport(PluginName, EntryPoint = "AmazingCppFunctionality")] private static extern void Functionality(); using System.Runtime.InteropServices; Calling C/C++ Functions From C# Platform Invocation Services (P/Invoke) 10
  • 11. Exceptions Gotchas 11 Exceptions must not cross the managed/unmanaged boundary. Under most circumstances, this will lead to a crash!
  • 13. Passing Data Pseudo-code 13 // Unity C# public class NormalUnityComponent : UnityEngine.MonoBehaviour { private void Start() { var data = GetCppData(); DoStuffWithTheData(data); DoMoarStuffWithTheData(ref data); } }
  • 14. Marshalling is the process of transferring data between managed and unmanaged memory and performing the required copying or data conversion. 14
  • 15. byte (System.SByte) char ubyte (System.Byte) unsigned char short (System.Int16) short ushort (System.UInt16) unsigned short int (System.Int32) int uint (System.UInt32) unsigned int long (System.Int64) long long ulong (System.UInt64) unsigned long long System.IntPtr std::intptr_t (void*) System.UIntPtr std::uintptr_t float (System.Single) float double (System.Double) double Primitive Data Types Blittable Types 15
  • 16. ● One-Dimensional Arrays of Blittable Types ● Structs Containing Blittable Types Complex Blittable Types Blittable Types 16
  • 17. ● All Other Types!!! ● String Non-Blittable Types Blittable Types 17
  • 18. Marshalling Primitive Data Types Actual code! 18 using System.Runtime.InteropServices; public partial class NativePlugin { [DllImport(PluginName)] public static extern float GetDataByReturnValue(); [DllImport(PluginName)] public static extern void GetDataByReference(ref float data); [DllImport(PluginName)] public static extern void SetData(float data); } static float Data = 90000.0f; DLL_EXPORT float CALL_CONV GetDataByReturnValue() { return Data; } DLL_EXPORT void CALL_CONV GetDataByReference(float& data) { data = Data; } DLL_EXPORT void CALL_CONV SetData(float data) { Data = data; }
  • 19. public class MarshallingPrimitiveDataTypesTest : UnityEngine.MonoBehaviour { private void Start() { float d = 0; NativePlugin.GetDataByReference(ref d); print("Data = " + d); // Data = ??? NativePlugin.SetData(90); NativePlugin.GetDataByReference(ref d); print("Data = " + d); // Data = 90 } } Accessing Primitive Data Types in Unity M04R C0D3!!! 19
  • 20. Static Initialization Gotchas 20 Static initialization of C/C++ variables occurs only once, when the plug-in is loaded. Prepare for this or it can lead to unexpected behaviour!
  • 21. Marshalling One-Dimensional Arrays Pseudo-code 21 public class NormalUnityComponent : UnityEngine.MonoBehaviour { public int[] Integers = new int[40]; private void Start() { FillArray(Integers, 125); } }
  • 22. using System.Runtime.InteropServices; public partial class NativePlugin { [DllImport(PluginName, EntryPoint = "FillArray"))] private static extern int FillArrayPrivate(int[] integers, int size, int v); } public static int FillArray(int[] integers, int v) { return FillArrayPrivate(integers, integers.Length, v); } Marshalling One-Dimensional Arrays Interoperability 22 DLL_EXPORT int CALL_CONV FillArray(int* integers, int size, int v) { if (!integers || size < 1) return 0; // ... }
  • 23. Access Violations Gotchas 23 Buffer overruns and dereferenced null-pointers can lead to serious problems. Exceptions that could have been caught in C# may cause Unity and your application to crash. Bounds checks and null-pointer checks are your friends! In general, don’t hold onto pointers received from managed land!
  • 24. // Valid C/C++ code enum WeekDay { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; WeekDay GetDayOfTheWeek(); Marshalling Enums Pseudo-code 24 // C# Pseudo-code public class NormalUnityComponent : UnityEngine.MonoBehaviour { private void Start() { print(GetDayOfTheWeek()); } }
  • 25. // Production ready C/C++ code enum WeekDay : int { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; DLL_EXPORT WeekDay CALL_CONV GetDayOfTheWeek(); Marshalling Enums Bit representation 25 // Production ready Unity C# code public enum WeekDay : int { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } public partial class NativePlugin { [System.Runtime.InteropServices.DllImport(PluginName)] public static extern WeekDay GetDayOfTheWeek(); }
  • 26. using System.Runtime.InteropServices; public class MarshallingEnumsTest : UnityEngine.MonoBehaviour { [DllImport(NativePlugin.PluginName)] private static extern WeekDay GetDayOfTheWeek(); private void Start() { WeekDay day = GetDayOfTheWeek(); print(day); } } DLL_EXPORT WeekDay CALL_CONV GetDayOfTheWeek() { return Wednesday; } Marshalling Enums Example code 26
  • 27. using UnityEngine; public class NormalUnityComponent : MonoBehaviour { private void Start() { Vector3 vec = GetVectorFromCppLand(); // ... DoSomethingWithAVectorInCppLand(vec); } } Marshalling Structs Pseudo-code 27
  • 28. // C/C++ struct V3 { float X; float Y; float Z; }; Marshalling Structs Structure Layout 28 // Unity C# namespace UnityEngine { public struct Vector3 /* ... */ { // ... public float x; public float y; public float z; // ... } }
  • 29. Struct Layout Gotchas 29 When marshalling structs, special attention should be placed on the struct layout. Member alignment and struct packing must match between managed and unmanaged representations!
  • 30. class CppClass { public: float Value = 0.0f; int Function() { return ++InternalCounter; } private: int InternalCounter = 0; }; “Marshalling” C++ Classes Exposing similar syntax 30
  • 31. “Marshalling” C++ Classes Allocation/Deallocation 31 public partial class CppClassProxy { private System.IntPtr CppPtr = System.IntPtr.Zero; public CppClassProxy() { CppPtr = NativePlugin.CreateCppClass(); } ~CppClassProxy() { NativePlugin.DestroyCppClass(CppPtr); CppPtr = System.IntPtr.Zero; } } DLL_EXPORT CppClass* CALL_CONV CreateCppClass() { return new CppClass(); } DLL_EXPORT void CALL_CONV DestroyCppClass(CppClass* c) { delete c; }
  • 32. “Marshalling” C++ Classes Accessors 32 public partial class CppClassProxy { public float Value { get { return NativePlugin.CppClass_Value_get(CppPtr); } set { NativePlugin.CppClass_Value_set(CppPtr, value); } } } DLL_EXPORT float CALL_CONV CppClass_Value_get(CppClass* c) { return c ? c->Value : 0.0f; } DLL_EXPORT void CALL_CONV CppClass_Value_set(CppClass* c, float v) { if (c) c->Value = v; }
  • 33. “Marshalling” C++ Classes Member Functions 33 public partial class CppClassProxy { public int Function() { return NativePlugin.CppClass_Function(CppPtr); } } DLL_EXPORT int CALL_CONV CppClass_Function(CppClass* c) { return c ? c->Function() : 0; }
  • 34. public class MarshallingStructuresTest02 : UnityEngine.MonoBehaviour { private void Start() { var c = new CppClassProxy(); print(c.Value + " " + c.Function()); c.Value = 80.5f; print(c.Value + " " + c.Function()); } } Accessing C++ Classes in Unity Sample use and output 34 struct CppClass { float Value = 0.0f; int InternalCounter = 0; int Function() { return ++InternalCounter; } };
  • 35. Null Pointers, Memory Leaks, and Referencing Deallocated Data Gotchas 35 Null checks are important. It is also important to ensure that allocated data is appropriately deallocated. Memory management is now in your hands! Get dirty, but remember to clean yourself up!
  • 36. Advanced Topics 0NLy 4 3L337 H4X0RZ 36
  • 37. / C# Pseudo-code public class MagicalTextComponent : UnityEngine.MonoBehaviour { private void Start() { print(MakeTextMagical("TEXT")); } } Marshalling Strings Pseudo-code 37
  • 38. using System.Runtime.InteropServices; public partial class NativePlugin { [DllImport(PluginName, EntryPoint = "ModifyText")] private static extern System.IntPtr ModifyTextImpl([MarshalAs(UnmanagedType.LPStr)] string text); } System.IntPtr [MarshalAs(UnmanagedType.LPStr)] public static string ModifyText(string text) { return Marshal.PtrToStringAnsi(ModifyTextImpl(text)); } Marshalling Single-Byte Character Strings (char* in C/C++) Interoperability 38 DLL_EXPORT const char* CALL_CONV ModifyText(const char* text) { return DoTextMagic(text); }
  • 39. Marshalling Multi-Byte Character Strings (wchar_t* in C/C++) Interoperability 39 using System.Runtime.InteropServices; public partial class NativePlugin { [DllImport(PluginName, EntryPoint = "GetName")] private static extern System.IntPtr GetNameImpl(); public static string GetName(string text) { return Marshal.PtrToStringUni(GetNameImpl()); } [DllImport(PluginName)] private static extern void SetName([MarshalAs(UnmanagedType.LPWStr)] string name); } DLL_EXPORT const wchar_t* CALL_CONV GetName(); DLL_EXPORT void CALL_CONV SetName(const wchar_t* n);
  • 40. Strings Gotchas 40 String marshalling requires special care. Prepare for performance penalties when using strings extensively. Strings should be avoided as part of your API.
  • 41. using System.Runtime.InteropServices; public partial class CallbackMarshallingTest : MonoBehaviour { [DllImport(NativePlugin.PluginName)] private static extern void DoExtensiveWork(LoggerInteropDelegate logger, int steps); } DLL_EXPORT void CALL_CONV DoExtensiveWork(Logger logger, int steps) { logger("Starting initialization work..."); if (TestFailure(steps)) logger("Initialization failed."); } typedef void(CALL_CONV * Logger)(const char*); Marshalling Delegates Interoperability 41 [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void LoggerInteropDelegate([MarshalAs(UnmanagedType.LPStr)] string message);
  • 42. public partial class CallbackMarshallingTest : MonoBehaviour { private LoggerInteropDelegate Logger = new LoggerInteropDelegate(LogFunction); [AOT.MonoPInvokeCallback(typeof(LoggerInteropDelegate))] private static void LogFunction(string message) { print("Native Message: " + message); } } private void Start() { DoExtensiveWork(Logger, 0); } Delegates as C/C++ Callbacks Example 42
  • 43. Delegated Callback Problem Solver Gotchas 43 ● Unity’s multithreading restrictions ● Garbage Collection Devs should avoid passing managed delegates as native callbacks when they are uncertain of the ramifications!
  • 44. ● CppSharp ● SWIG (Simplified Wrapper and Interface Generator) Automation 44
  • 45. Automation is No Panacea Gotchas 45 Hours can be wasted fighting against your automation tool to consistently produce the required output when it might be expedient to simply handcraft a solution for specific edge cases. https://xkcd.com/1319/
  • 46. Conclusion ● Marshalling ○ Primitive Types ○ One-Dimensional Arrays ○ Enums ○ Structures ○ Strings ○ Delegates as Callbacks 46 ● Gotchas ○ Native Plug-ins are not unloaded ○ Exceptions ○ Static Initialization ○ Use Strings sparingly ○ Memory Management ○ Access Violations ○ ...