Skip to content

Commit

Permalink
remove newton background threads. alsoe remove the
Browse files Browse the repository at this point in the history
also remove use define thread, the bug is no in newton it is with unreal checking that no unreal code run on a thread that is no own but unreal core.
the newton worker thread are children that run concurrent with the main but unreal just crash them
  • Loading branch information
JulioJerez committed Oct 29, 2024
1 parent bac8c1f commit 5a402ac
Show file tree
Hide file tree
Showing 24 changed files with 589 additions and 190 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) <2014-2017> <Newton Game Dynamics>
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely.

cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR)

set (projectName "ndCollision")
message (${projectName})

#source and header files
file(GLOB CPP_SOURCE *.h *.cpp)
file(GLOB HEADERS *.h)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE})

include_directories(../dCore/)
include_directories(../dTinyxml/)
include_directories(../dProfiler/)

if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /fp:fast")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /fp:fast")
endif(MSVC)

if(NEWTON_BUILD_SHARED_LIBS)
add_definitions(-D_D_COLLISION_EXPORT_DLL)
add_library(${projectName} SHARED ${CPP_SOURCE})

if(MSVC OR MINGW)
target_link_options(${projectName} PUBLIC "/DEBUG")
endif()
else()
add_library(${projectName} STATIC ${CPP_SOURCE})
endif()

if (MSVC)
if(CMAKE_VS_MSBUILD_COMMAND OR CMAKE_VS_DEVENV_COMMAND)
set_target_properties(${projectName} PROPERTIES COMPILE_FLAGS "/YundCollisionStdafx.h")
set_source_files_properties(ndCollisionStdafx.cpp PROPERTIES COMPILE_FLAGS "/YcndCollisionStdafx.h")
endif()

if (NEWTON_BUILD_TEST AND NEWTON_BUILD_SHARED_LIBS)
add_custom_command(
TARGET ${projectName} POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy $<TARGET_FILE:${projectName}> ${PROJECT_BINARY_DIR}/applications/ndTest/${CMAKE_CFG_INTDIR}/$<TARGET_FILE_NAME:${projectName}>)
endif ()

if (NEWTON_BUILD_SANDBOX_DEMOS AND NEWTON_BUILD_SHARED_LIBS)
add_custom_command(
TARGET ${projectName} POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy $<TARGET_FILE:${projectName}> ${PROJECT_BINARY_DIR}/applications/ndSandbox/${CMAKE_CFG_INTDIR}/$<TARGET_FILE_NAME:${projectName}>)
endif ()

endif(MSVC)

target_link_libraries(${projectName} ndCore ndTinyxml)

install(TARGETS ${projectName}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)

install(FILES ${HEADERS} DESTINATION include/${projectName})

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ ndVector ndScene::m_angularContactError2(D_CONTACT_ANGULAR_ERROR * D_CONTACT_ANG
ndVector ndScene::m_linearContactError2(D_CONTACT_TRANSLATION_ERROR * D_CONTACT_TRANSLATION_ERROR);

ndScene::ndScene()
:ndClassAlloc()
,ndThreadPool("newtonWorker")
:ndThreadPool("newtonWorker")
,m_bodyList()
,m_particleSetList()
,m_contactArray()
Expand All @@ -56,12 +55,12 @@ ndScene::ndScene()
,m_sceneBodyArray(1024)
,m_activeConstraintArray(1024)
,m_specialUpdateList()
,m_backgroundThread()
,m_newPairs(1024)
,m_lock()
,m_rootNode(nullptr)
,m_sentinelBody(nullptr)
,m_contactNotifyCallback(new ndContactNotify(nullptr))
,m_backgroundThread(nullptr)
,m_timestep(ndFloat32 (0.0f))
,m_lru(D_CONTACT_DELAY_FRAMES)
,m_frameNumber(0)
Expand All @@ -78,8 +77,7 @@ ndScene::ndScene()
}

ndScene::ndScene(const ndScene& src)
:ndClassAlloc()
,ndThreadPool("newtonWorker")
:ndThreadPool("newtonWorker")
,m_bodyList(src.m_bodyList)
,m_particleSetList()
,m_contactArray(src.m_contactArray)
Expand All @@ -88,12 +86,12 @@ ndScene::ndScene(const ndScene& src)
,m_sceneBodyArray()
,m_activeConstraintArray()
,m_specialUpdateList()
,m_backgroundThread()
,m_newPairs(1024)
,m_lock()
,m_rootNode(nullptr)
,m_sentinelBody(nullptr)
,m_contactNotifyCallback(nullptr)
,m_backgroundThread(nullptr)
,m_timestep(ndFloat32(0.0f))
,m_lru(src.m_lru)
,m_frameNumber(src.m_frameNumber)
Expand All @@ -103,7 +101,7 @@ ndScene::ndScene(const ndScene& src)
ndScene* const stealData = (ndScene*)&src;

SetThreadCount(src.GetThreadCount());
m_backgroundThread.SetThreadCount(m_backgroundThread.GetThreadCount());
//m_backgroundThread.SetThreadCount(m_backgroundThread.GetThreadCount());

m_scratchBuffer.Swap(stealData->m_scratchBuffer);
m_sceneBodyArray.Swap(stealData->m_sceneBodyArray);
Expand Down Expand Up @@ -1188,7 +1186,10 @@ void ndScene::BodiesInAabb(ndBodiesInAabbNotify& callback, const ndVector& minBo
void ndScene::Cleanup()
{
Sync();
m_backgroundThread.Terminate();
if (m_backgroundThread)
{
m_backgroundThread->Terminate();
}
PrepareCleanup();

m_frameNumber = 0;
Expand Down Expand Up @@ -1268,7 +1269,15 @@ bool ndScene::ConvexCast(ndConvexCastNotify& callback, const ndShapeInstance& co

void ndScene::SendBackgroundTask(ndBackgroundTask* const job)
{
m_backgroundThread.SendTask(job);
if (m_backgroundThread)
{
m_backgroundThread->SendTask(job);
}
else
{
ndAssert(0);
delete job;
}
}

void ndScene::AddPair(ndBodyKinematic* const body0, ndBodyKinematic* const body1, ndInt32 threadId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ndSceneTreeNotiFy : public ndClassAlloc
} D_GCC_NEWTON_ALIGN_32;

D_MSV_NEWTON_ALIGN_32
class ndScene : public ndClassAlloc, public ndThreadPool
class ndScene : public ndThreadPool
{
protected:
class ndContactPairs
Expand Down Expand Up @@ -162,7 +162,6 @@ class ndScene : public ndClassAlloc, public ndThreadPool
ndArray<ndBodyKinematic*> m_sceneBodyArray;
ndArray<ndConstraint*> m_activeConstraintArray;
ndSpecialList<ndBodyKinematic> m_specialUpdateList;
ndThreadBackgroundWorker m_backgroundThread;
ndArray<ndContactPairs> m_newPairs;
ndArray<ndContactPairs> m_partialNewPairs[D_MAX_THREADS_COUNT];
ndPolygonMeshDesc::ndStaticMeshFaceQuery m_staticMeshQuery[D_MAX_THREADS_COUNT];
Expand All @@ -172,6 +171,7 @@ class ndScene : public ndClassAlloc, public ndThreadPool
ndBvhNode* m_rootNode;
ndBodyKinematic* m_sentinelBody;
ndContactNotify* m_contactNotifyCallback;
ndThreadBackgroundWorker* m_backgroundThread;

ndFloat32 m_timestep;
ndUnsigned32 m_lru;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) <2014-2017> <Newton Game Dynamics>
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely.

cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR)

set (projectName "ndCore")
message (${projectName})

# source and header files
file(GLOB CPP_SOURCE *.h *.cpp)
file(GLOB HEADERS *.h)

include_directories(../dTinyxml/)
include_directories(../dProfiler/)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/" FILES ${CPP_SOURCE})

if(NEWTON_BUILD_SHARED_LIBS STREQUAL "ON")
add_definitions(-D_D_CORE_EXPORT_DLL)
add_library(${projectName} SHARED ${CPP_SOURCE})

if(MSVC OR MINGW)
target_link_options(${projectName} PUBLIC "/DEBUG")
endif()

else()
add_library(${projectName} STATIC ${CPP_SOURCE})
endif()

if (MSVC)
if(CMAKE_VS_MSBUILD_COMMAND OR CMAKE_VS_DEVENV_COMMAND)
set_target_properties(${projectName} PROPERTIES COMPILE_FLAGS "/YundCoreStdafx.h")
set_source_files_properties(ndCoreStdAfx.cpp PROPERTIES COMPILE_FLAGS "/YcndCoreStdafx.h")
endif()

if (NEWTON_BUILD_TEST AND NEWTON_BUILD_SHARED_LIBS)
add_custom_command(
TARGET ${projectName} POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy $<TARGET_FILE:${projectName}> ${PROJECT_BINARY_DIR}/applications/ndTest/${CMAKE_CFG_INTDIR}/$<TARGET_FILE_NAME:${projectName}>)
endif ()

if (NEWTON_BUILD_SANDBOX_DEMOS AND NEWTON_BUILD_SHARED_LIBS)
add_custom_command(
TARGET ${projectName} POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy $<TARGET_FILE:${projectName}> ${PROJECT_BINARY_DIR}/applications/ndSandbox/${CMAKE_CFG_INTDIR}/$<TARGET_FILE_NAME:${projectName}>)
endif ()

endif(MSVC)

target_include_directories(${projectName} PUBLIC .)

if (NEWTON_BUILD_PROFILER)
target_link_libraries (${projectName} dProfiler)
endif()

target_link_libraries (${projectName} ndTinyxml)

install(TARGETS ${projectName}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)

install(FILES ${HEADERS} DESTINATION include/${projectName})
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ inline ndMatrix::ndMatrix (const ndVector &front, const ndVector &up, const ndVe
{
}

inline ndVector& ndMatrix::operator[] (ndInt32 i)
inline ndVector& ndMatrix::operator[] (ndInt32 i)
{
ndAssert (i < 4);
ndAssert (i >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ndQuaternion: public ndVector

inline ndQuaternion::ndQuaternion()
//:ndVector(ndVector::m_wOne)
:ndVector(ndFloat32(0.0f), ndFloat32(0.0f), ndFloat32(0.0f), ndFloat32(1.0f))
:ndVector(ndFloat32 (0.0f), ndFloat32(0.0f), ndFloat32(0.0f), ndFloat32(1.0f))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,9 @@
#pragma warning( disable : 4355)
#endif

ndThreadInterface::ndThreadInterface()
ndThread::ndThread()
:ndClassAlloc()
,ndSemaphore()
{
}

ndThreadInterface::~ndThreadInterface()
{
}


ndThread::ndThread()
:ndThreadInterface()
#ifndef D_USE_THREAD_EMULATION
,ndAtomic<bool>(true)
,std::condition_variable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,10 @@ class ndThreadName
char m_name[32];
};

class ndThreadInterface: public ndClassAlloc, public ndSemaphore
{
public:
D_CORE_API ndThreadInterface();
D_CORE_API virtual ~ndThreadInterface();

virtual void Signal() = 0;
virtual void Finish() = 0;
virtual void Release() = 0;
virtual void ThreadFunction() = 0;
virtual void ThreadFunctionCallback() = 0;
virtual void SetName(const char* const name) = 0;

ndThreadName m_name;
};

/// Base class for for all multi thread functionality.
class ndThread
:public ndThreadInterface
class ndThread
:public ndClassAlloc
,public ndSemaphore
#ifndef D_USE_THREAD_EMULATION
,public ndAtomic<bool>
,public std::condition_variable
Expand All @@ -72,25 +57,27 @@ class ndThread

/// Set thread name.
/// Useful for when debugging or profiler and application.
D_CORE_API virtual void SetName(const char* const name) override;
D_CORE_API virtual void SetName(const char* const name);

/// Set the thread, to execute one call to and go back to a wait state
D_CORE_API virtual void Signal() override;
D_CORE_API virtual void Signal();

/// Force the thread loop to terminate.
/// This function must be call explicitly when the application
/// wants to terminate the thread because the destructor does not do it.
D_CORE_API virtual void Finish() override;
D_CORE_API virtual void Finish();

/// Thread function to execute in a perpetual loop until the thread is terminated.
/// Each time the thread owner calls function Signal, the loop execute one call to
/// this function and upon return, the thread goes back to wait for another signal
/// or to exit the loop.
//virtual virtual void ThreadFunction() = 0;
virtual void ThreadFunction() = 0;

protected:
D_CORE_API virtual void Release() override;
D_CORE_API virtual void ThreadFunctionCallback() override;
D_CORE_API virtual void Release();
D_CORE_API virtual void ThreadFunctionCallback();

ndThreadName m_name;
};

#endif
Loading

0 comments on commit 5a402ac

Please sign in to comment.