Skip to content

EmbeddingNPLRuntime

Li, Xizhi edited this page Oct 4, 2017 · 6 revisions

Embedding NPLRuntime

NPLRuntime comes with a general purpose executable for launching NPL based applications. This is the standard usage of NPLRuntime. However, some client application may prefer embedding NPLRuntime in their own executable file, or even as child window of their own application. This is possible via NPLRuntime dll (paraengineclient.dll or static lib).

Dynamically linking to NPLRuntime Example

Please see https://github.com/LiXizhi/ParaCraftSDK/blob/master/samples/MyAppExe/MyApp.cpp for details.

#include "PEtypes.h"
#include "IParaEngineApp.h"
#include "IParaEngineCore.h"
#include "INPL.h"
#include "INPLRuntime.h"
#include "INPLRuntimeState.h"
#include "INPLAcitvationFile.h"
#include "NPLInterface.hpp"
#include "PluginLoader.hpp"

#include "MyApp.h"

using namespace ParaEngine;
using namespace NPL;
using namespace MyCompany;

// some lines omitted here ....

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmdLine, INT)
{
	std::string sAppCmdLine;
	if (lpCmdLine)
		sAppCmdLine = lpCmdLine;

	// TODO: add your custom command line here
	sAppCmdLine += " mc=true noupdate=true";

	CMyApp myApp(hInst);
	return myApp.Run(0, sAppCmdLine.c_str());
}

Building Custom Executable Application

To build your custom application, you must download NPLRuntime source code (for header files) and set CMAKE include directory properly.

Build NPLRuntime as Libraries

In most cases, you do not need to build these libraries, simply copy ParaEngineClient.dll and other related dll files from the ParacraftSDK's ./redist folder to your host application's executable directory. Make sure they are up to date.

However, one can also build NPL Runtime as Libraries manually. See CMake options when building NPLRuntime from source code.

Statically linking to NPLRuntime Example

If you want to embed the entire NPLRuntime inside a single executable, we also give the option to statically link to it.

You can put NPLRuntime in a subdirectory and use following CMAKE options to build your app and NPLRuntime together.

# main NPL runtime and override default options to generate only static libs and skip some unused library
option(NPLRUNTIME_STATIC_LIB "static lib or not" ON)
option(NPLRUNTIME_LUAJIT21 "build luajit21 support GC64" OFF)
option(NPLRUNTIME_LUAJIT20   "build luajit2.0.4" OFF)
option(NPLRUNTIME_LUA51   "build lua5.1.5 with coco" ON)
option(NPLRUNTIME_SUPPORT_FBX "support FBX files (assimp)" OFF)
option(NPLRUNTIME_PHYSICS "include physics" OFF)
add_subdirectory (${PROJECT_SOURCE_DIR}/NPLRuntime/Client)

add_subdirectory (${PROJECT_SOURCE_DIR}/src)

For a complete example, please see AppLauncher. It generates a single executable without any external dll dependencies.

Clone this wiki locally