Skip to content

Modules

Alex Miyamoto edited this page Apr 23, 2018 · 2 revisions

Modules were a last minute addition added to allow open sourcing the project without having to strip out Oculus support (or require the SDK be installed even if you don't want it).

Modules are projects which generate dll's. They should do as little as possible and reference as few other libraries as possible.

A dll should expose the following functions:

DLL_EXPORT 	usg::ModuleInterfaceSet* InitModule(usg::ModuleInitData& initData);
DLL_EXPORT 	void DestroyModule(usg::ModuleInitData& initData, usg::ModuleInterfaceSet* Set);

The very first thing you need to do is initialize the memory with the allocator set contained in the ModuleInitData

usg::mem::InitialiseAllocators(&initData.allocators);

This will allow you to use mem::Alloc and vnew normally.

You will need to create a class which implements the ModuleInterfaceSet - this allows each dll to return a number of seperate unrelated classes (such as the Oculus HMD and Touch Controllers).

You can only return types than inherit from ModuleInterface and implement GetModuleTypeName().

To load a module call

usg::ModuleManager::Inst()->LoadModule("ModuleName.dll");

Currently all the hookup occurs in GameUtil.cpp HookupModules (not the module manager so as to reduce code coupling) but there would be nothing to stop you having project specific modules that only your game knew how to handle.