コード例 #1
0
ファイル: odeinit.cpp プロジェクト: Belxjander/Asuna
int dInitODE2(unsigned int uiInitFlags/*=0*/)
{
	dIASSERT(!g_bODEInitialized); // ODE can not be initialized twice

	bool bResult = false;
	
#if dOU_ENABLED
	bool bOUCustomizationsDone = false;
#endif
#if dATOMICS_ENABLED
	bool bAtomicsInitialized = false;
#endif
#if dTLS_ENABLED
	bool bTlsInitialized = false;
#endif

	do
	{
#if dOU_ENABLED
		if (!COdeOu::DoOUCustomizations())
		{
			break;
		}

		bOUCustomizationsDone = true;
#endif

#if dATOMICS_ENABLED
		if (!COdeOu::InitializeAtomics())
		{
			break;
		}

		bAtomicsInitialized = true;
#endif

#if dTLS_ENABLED
		unsigned int uiTlsFlags = 0;

		if (uiInitFlags & dInitFlagManualThreadCleanup)
		{
			uiTlsFlags |= COdeTls::MANUAL_DATA_CLEANUP;
		}

		if (!COdeTls::Initialize(uiTlsFlags))
		{
			break;
		}

		bTlsInitialized = true;
#endif
		
#if dTRIMESH_ENABLED && dTRIMESH_OPCODE
		Opcode::ThreadLocalDataProviderProc pfnOpcodeDataProviderProc;
#if dTLS_ENABLED
		pfnOpcodeDataProviderProc = &ProvideOpcodeThreadLocalData;
#else // dTLS_ENABLED
		pfnOpcodeDataProviderProc = NULL;
#endif // dTLS_ENABLED
		if (!Opcode::InitOpcode(pfnOpcodeDataProviderProc))
		{
			break;
		}
#endif

#if dTRIMESH_ENABLED && dTRIMESH_GIMPACT
		gimpact_init();
#endif

		dInitColliders();

		g_bODEInitialized = true;
		bResult = true;
	}
	while (false);

	if (!bResult)
	{
#if dTLS_ENABLED
		if (bTlsInitialized)
		{
			COdeTls::Finalize();
		}
#endif

#if dATOMICS_ENABLED
		if (bAtomicsInitialized)
		{
			COdeOu::FinalizeAtomics();
		}
#endif

#if dOU_ENABLED
		if (bOUCustomizationsDone)
		{
			COdeOu::UndoOUCustomizations();
		}
#endif
	}

	return bResult;
}
コード例 #2
0
ファイル: odeinit.cpp プロジェクト: weilandetian/Yoyo
static bool InitODEForMode(EODEINITMODE imInitMode)
{
    bool bResult = false;

#if dOU_ENABLED
    bool bOUCustomizationsDone = false;
#endif
#if dATOMICS_ENABLED
    bool bAtomicsInitialized = false;
#endif
#if dTLS_ENABLED
    EODETLSKIND tkTLSKindToInit = g_atkTLSKindsByInitMode[imInitMode];
    bool bTlsInitialized = false;
#else
    (void)imInitMode; // unused
#endif

    bool bWorldThreadingInitialized = false;

    do
    {
        bool bAnyModeAlreadyInitialized = IsODEAnyModeInitialized();

        if (!bAnyModeAlreadyInitialized)
        {
#if dOU_ENABLED
            if (!COdeOu::DoOUCustomizations())
            {
                break;
            }

            bOUCustomizationsDone = true;
#endif

#if dATOMICS_ENABLED
            if (!COdeOu::InitializeAtomics())
            {
                break;
            }

            bAtomicsInitialized = true;
#endif
        }

#if dTLS_ENABLED
        if (!COdeTls::Initialize(tkTLSKindToInit))
        {
            break;
        }

        bTlsInitialized = true;
#endif

        if (!bAnyModeAlreadyInitialized)
        {
            if (!dxWorld::InitializeDefaultThreading())
            {
                break;
            }

            bWorldThreadingInitialized = true;

#if dTRIMESH_ENABLED && dTRIMESH_OPCODE
            if (!Opcode::InitOpcode(&OPCODEAbort))
            {
                break;
            }
#endif

#if dTRIMESH_ENABLED && dTRIMESH_GIMPACT
            gimpact_init();
#endif

            dInitColliders();
        }

        bResult = true;
    }
    while (false);

    if (!bResult)
    {
        if (bWorldThreadingInitialized)
        {
            dxWorld::FinalizeDefaultThreading();
        }

#if dTLS_ENABLED
        if (bTlsInitialized)
        {
            COdeTls::Finalize(tkTLSKindToInit);
        }
#endif

#if dATOMICS_ENABLED
        if (bAtomicsInitialized)
        {
            COdeOu::FinalizeAtomics();
        }
#endif

#if dOU_ENABLED
        if (bOUCustomizationsDone)
        {
            COdeOu::UndoOUCustomizations();
        }
#endif
    }

    return bResult;
}