diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /APEX_1.4/module/loader | |
| download | physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip | |
Initial commit:
PhysX 3.4.0 Update @ 21294896
APEX 1.4.0 Update @ 21275617
[CL 21300167]
Diffstat (limited to 'APEX_1.4/module/loader')
| -rw-r--r-- | APEX_1.4/module/loader/include/ModuleLoaderImpl.h | 128 | ||||
| -rw-r--r-- | APEX_1.4/module/loader/include/ModuleXmacro.h | 41 | ||||
| -rw-r--r-- | APEX_1.4/module/loader/include/Modules.h | 39 | ||||
| -rw-r--r-- | APEX_1.4/module/loader/src/ModuleLoaderImpl.cpp | 285 |
4 files changed, 493 insertions, 0 deletions
diff --git a/APEX_1.4/module/loader/include/ModuleLoaderImpl.h b/APEX_1.4/module/loader/include/ModuleLoaderImpl.h new file mode 100644 index 00000000..8b39e890 --- /dev/null +++ b/APEX_1.4/module/loader/include/ModuleLoaderImpl.h @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#ifndef MODULELEGACY_H_ +#define MODULELEGACY_H_ + +#include "Apex.h" +#include "ApexSDKIntl.h" +#include "ModuleIntl.h" +#include "ModuleBase.h" +#include "ModuleLoader.h" +#include "PsArray.h" +#include "ApexRWLockable.h" + +namespace nvidia +{ +namespace apex +{ + +class ModuleLoaderImpl : public ModuleLoader, public ModuleIntl, public ModuleBase, public ApexRWLockable +{ + physx::Array<Module*> mModules; // Loaded modules + ModuleLoader::ModuleNameErrorMap mCreateModuleError; // Modules error during it creating + + uint32_t getIdx(const char* name) const; + + uint32_t getIdx(Module* module) const; + +public: + APEX_RW_LOCKABLE_BOILERPLATE + + ModuleLoaderImpl(ApexSDKIntl* inSdk) + { + mName = "Loader"; + mSdk = inSdk; + mApiProxy = this; + } + + Module* loadModule(const char* name); + + void loadModules(const char** names, uint32_t size, Module** modules); + + void loadAllModules(); + + const ModuleNameErrorMap& getLoadedModulesErrors() const; + + void loadAllLegacyModules(); + + uint32_t getLoadedModuleCount() const; + + Module* getLoadedModule(uint32_t idx) const; + + Module* getLoadedModule(const char* name) const; + + void releaseModule(uint32_t idx); + + void releaseModule(const char* name); + + void releaseModule(Module* module); + + void releaseModules(const char** modules, uint32_t size); + + void releaseModules(Module** modules, uint32_t size); + + void releaseLoadedModules(); + +protected: + + virtual ~ModuleLoaderImpl() {} + + // ModuleBase's stuff + + void init(NvParameterized::Interface&) {} + + NvParameterized::Interface* getDefaultModuleDesc() + { + return 0; + } + + void release() + { + ModuleBase::release(); + } + void destroy() + { + ModuleBase::destroy(); + delete this; + } + + const char* getName() const + { + return ModuleBase::getName(); + } + + AuthObjTypeID getModuleID() const + { + return UINT32_MAX; + } + RenderableIterator* createRenderableIterator(const Scene&) + { + return NULL; + } + + // ModuleIntl's stuff + + ModuleSceneIntl* createInternalModuleScene(SceneIntl&, RenderDebugInterface*) + { + return NULL; + } + void releaseModuleSceneIntl(ModuleSceneIntl&) {} + uint32_t forceLoadAssets() + { + return 0; + } +}; + +} +} // physx::apex + +#endif diff --git a/APEX_1.4/module/loader/include/ModuleXmacro.h b/APEX_1.4/module/loader/include/ModuleXmacro.h new file mode 100644 index 00000000..60fd2604 --- /dev/null +++ b/APEX_1.4/module/loader/include/ModuleXmacro.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +// Run X-macro over all modules +// #define MODULE(moduleName, instFunc, hasInit) + +#include <PhysXSDKVersion.h> + +#pragma warning(push) +#pragma warning(disable:4127) + +#ifndef MODULE_LEGACY +#define MODULE_LEGACY(moduleName, instFunc, hasInit) MODULE(moduleName, instFunc, hasInit) +#endif + + +MODULE("Clothing", instantiateModuleClothing, true) +MODULE("Destructible", instantiateModuleDestructible, true) +MODULE("Legacy", instantiateModuleLegacy, false); + + +#if APEX_USE_PARTICLES +MODULE("Particles", instantiateModuleParticles, true) +// No correct init method yet... +MODULE("TurbulenceFS", instantiateModuleTurbulenceFS, false) +#endif // APEX_USE_PARTICLES + + +// Clear inputs +#undef MODULE +#undef MODULE_LEGACY + +#pragma warning(pop) diff --git a/APEX_1.4/module/loader/include/Modules.h b/APEX_1.4/module/loader/include/Modules.h new file mode 100644 index 00000000..1d142ab9 --- /dev/null +++ b/APEX_1.4/module/loader/include/Modules.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#ifndef MODULES_H_ +#define MODULES_H_ + +#include <ApexDefs.h> + +#include <ModuleLegacy.h> +#include <ModuleClothing.h> + +#if PX_PHYSICS_VERSION_MAJOR == 3 +#include <ModuleDestructible.h> + +#if APEX_USE_PARTICLES + +#include <ModuleBasicFS.h> +#include <ModuleBasicIos.h> +#include <ModuleEmitter.h> +#include <ModuleFieldSampler.h> +#include <ModuleForceField.h> +#include <ModuleIofx.h> +#include <ModuleParticleIos.h> +#include <ModuleParticles.h> +#include <ModuleTurbulenceFS.h> + +#endif + +#endif + +#endif diff --git a/APEX_1.4/module/loader/src/ModuleLoaderImpl.cpp b/APEX_1.4/module/loader/src/ModuleLoaderImpl.cpp new file mode 100644 index 00000000..b102a001 --- /dev/null +++ b/APEX_1.4/module/loader/src/ModuleLoaderImpl.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#include "ApexUsingNamespace.h" +#include <PsHashMap.h> +#include <PsHash.h> + +#include "ModuleLoaderImpl.h" +#include "Modules.h" + +#include "ReadCheck.h" +#include "WriteCheck.h" + +namespace nvidia +{ +namespace apex +{ + +#if !defined(_USRDLL) && !PX_OSX +# define INSTANTIATE_MODULE(instFunc) do { instFunc(); } while(0) +#else +# define INSTANTIATE_MODULE(instFunc) +#endif + +#if defined(_USRDLL) || PX_OSX + +ApexSDKIntl* gApexSdk = 0; +ApexSDK* GetApexSDK() +{ + return gApexSdk; +} +ApexSDKIntl* GetInternalApexSDK() +{ + return gApexSdk; +} + +APEX_API Module* CALL_CONV createModule( + ApexSDKIntl* inSdk, + ModuleIntl** niRef, + uint32_t APEXsdkVersion, + uint32_t PhysXsdkVersion, + ApexCreateError* errorCode) +{ + if (APEXsdkVersion != APEX_SDK_VERSION) + { + if (errorCode) + { + *errorCode = APEX_CE_WRONG_VERSION; + } + return NULL; + } + + if (PhysXsdkVersion != PX_PHYSICS_VERSION) + { + if (errorCode) + { + *errorCode = APEX_CE_WRONG_VERSION; + } + return NULL; + } + + gApexSdk = inSdk; + + ModuleLoaderImpl* impl = PX_NEW(ModuleLoaderImpl)(inSdk); + *niRef = (ModuleIntl*) impl; + return (Module*) impl; +} + +#else + +void instantiateModuleLoader() +{ + ApexSDKIntl* sdk = GetInternalApexSDK(); + ModuleLoaderImpl* impl = PX_NEW(ModuleLoaderImpl)(sdk); + sdk->registerExternalModule((Module*) impl, (ModuleIntl*) impl); +} + +#endif + +void ModuleLoaderImpl::loadModules(const char** names, uint32_t size, Module** modules) +{ + WRITE_ZONE(); + typedef HashMap<const char*, uint32_t, nvidia::Hash<const char*> > MapName2Idx; + MapName2Idx mapName2Idx; + + if (modules) + { + for (uint32_t i = 0; i < size; ++i) + { + mapName2Idx[names[i]] = i; + } + } + + // TODO: check that module is not yet loaded +# define MODULE(name, instFunc, hasInit) { \ + if (mapName2Idx.find(name)) { \ + INSTANTIATE_MODULE(instFunc); \ + mCreateModuleError[name] = APEX_CE_NO_ERROR; \ + Module *module = mSdk->createModule(name, &mCreateModuleError[name]); \ + PX_ASSERT(module && name); \ + if (module) \ + { \ + mModules.pushBack(module); \ + if( modules ) modules[mapName2Idx[name]] = module; \ + if( hasInit && module ) { \ + NvParameterized::Interface* params = module->getDefaultModuleDesc(); \ + module->init(*params); \ + } \ + } \ + } \ + } +# include "ModuleXmacro.h" +} + +// TODO: check that module is not yet loaded in all ModuleLoaderImpl::load*-methods + +Module* ModuleLoaderImpl::loadModule(const char* name_) +{ + WRITE_ZONE(); +# define MODULE(name, instFunc, hasInit) { \ + if( 0 == ::strcmp(name, name_) ) { \ + INSTANTIATE_MODULE(instFunc); \ + mCreateModuleError[name] = APEX_CE_NO_ERROR; \ + Module *module = mSdk->createModule(name, &mCreateModuleError[name]); \ + PX_ASSERT(module && name); \ + if (module) \ + { \ + mModules.pushBack(module); \ + if( hasInit && module ) { \ + NvParameterized::Interface* params = module->getDefaultModuleDesc(); \ + module->init(*params); \ + } \ + } \ + return module; \ + } \ + } +# include "ModuleXmacro.h" + + return 0; +} + +void ModuleLoaderImpl::loadAllModules() +{ + WRITE_ZONE(); + // TODO: check that module is not yet loaded +# define MODULE(name, instFunc, hasInit) { \ + INSTANTIATE_MODULE(instFunc); \ + mCreateModuleError[name] = APEX_CE_NO_ERROR; \ + Module *module = mSdk->createModule(name, &mCreateModuleError[name]); \ + PX_ASSERT(module && name); \ + if (module) \ + { \ + mModules.pushBack(module); \ + if( hasInit && module ) { \ + NvParameterized::Interface* params = module->getDefaultModuleDesc(); \ + module->init(*params); \ + } \ + } \ + } +# include "ModuleXmacro.h" +} + +const ModuleLoader::ModuleNameErrorMap& ModuleLoaderImpl::getLoadedModulesErrors() const +{ + return mCreateModuleError; +} + +void ModuleLoaderImpl::loadAllLegacyModules() +{ + WRITE_ZONE(); + // TODO: check that module is not yet loaded +# define MODULE(name, instFunc, hasInit) +# define MODULE_LEGACY(name, instFunc, hasInit) { \ + INSTANTIATE_MODULE(instFunc); \ + mCreateModuleError[name] = APEX_CE_NO_ERROR; \ + Module *module = mSdk->createModule(name, &mCreateModuleError[name]); \ + PX_ASSERT(module && name); \ + if (module) \ + { \ + mModules.pushBack(module); \ + } \ + } +# include "ModuleXmacro.h" +} + +uint32_t ModuleLoaderImpl::getIdx(const char* name) const +{ + for (uint32_t i = 0; i < mModules.size(); ++i) + if (0 == ::strcmp(name, mModules[i]->getName())) + { + return i; + } + + return UINT32_MAX; +} + +uint32_t ModuleLoaderImpl::getIdx(Module* module) const +{ + for (uint32_t i = 0; i < mModules.size(); ++i) + if (module == mModules[i]) + { + return i; + } + + return UINT32_MAX; +} + +uint32_t ModuleLoaderImpl::getLoadedModuleCount() const +{ + READ_ZONE(); + return mModules.size(); +} + +Module* ModuleLoaderImpl::getLoadedModule(uint32_t idx) const +{ + READ_ZONE(); + return mModules[idx]; +} + +Module* ModuleLoaderImpl::getLoadedModule(const char* name) const +{ + READ_ZONE(); + uint32_t idx = getIdx(name); + return UINT32_MAX == idx ? 0 : mModules[idx]; +} + +void ModuleLoaderImpl::releaseModule(uint32_t idx) +{ + WRITE_ZONE(); + if (UINT32_MAX != idx) + { + mCreateModuleError.erase(mModules[idx]->getName()); + mSdk->releaseModule(mModules[idx]); + mModules.remove(idx); + } +} + +void ModuleLoaderImpl::releaseModule(const char* name) +{ + WRITE_ZONE(); + releaseModule(getIdx(name)); +} + +void ModuleLoaderImpl::releaseModule(Module* module) +{ + WRITE_ZONE(); + releaseModule(getIdx(module)); +} + +void ModuleLoaderImpl::releaseModules(Module** modules, uint32_t size) +{ + for (uint32_t i = 0; i < size; ++i) + { + releaseModule(modules[i]); + } +} + +void ModuleLoaderImpl::releaseModules(const char** names, uint32_t size) +{ + WRITE_ZONE(); + for (uint32_t i = 0; i < size; ++i) + { + releaseModule(names[i]); + } +} + +void ModuleLoaderImpl::releaseLoadedModules() +{ + WRITE_ZONE(); + while (!mModules.empty()) + { + releaseModule(uint32_t(0)); + } +} + +} +} // physx::apex |