Explorar el Código

Handled threading includes

Marko Pintera hace 13 años
padre
commit
b7f0044aca

+ 10 - 6
CamelotRenderer/HighLevelTODO.txt

@@ -1,5 +1,5 @@
 Camelot use case:
 Camelot use case:
- Application::startUp("RenderSystem", "RenderManager") <- Initializes all modules. Provide Reference render system and render manager
+ Application::startUp("RenderSystem", "RenderManager") <- Initializes all modules. Provide Reference render system and render manager (Maybe directly provide .dll name here)
  RenderWindow* window = new RenderWindow(width, height, /*etc*/); <- Automatically registers with Application
  RenderWindow* window = new RenderWindow(width, height, /*etc*/); <- Automatically registers with Application
  
  
 
 
@@ -13,13 +13,15 @@ Camelot use case:
 
 
 ------------------------------------------
 ------------------------------------------
 
 
- Application::renderLoop INTERNALS: // TODO - Most of this should be a part of a RenderManager, so we can employ better rendering 

+ Application::renderLoop INTERNALS: // TODO - Most of this should be a part of a RenderManager, so we can employ better rendering 
+
 techniques like deferred and forward rendering, transparently
 techniques like deferred and forward rendering, transparently
   Query scene manager and get all cameras
   Query scene manager and get all cameras
   Sort cameras based on render targets
   Sort cameras based on render targets
   For each render target
   For each render target
   Render cameras one by one
   Render cameras one by one
-    - Each camera queries scene manager for all visible entities // Scene manager employs spatial partitioning and frustum culling to 

+    - Each camera queries scene manager for all visible entities // Scene manager employs spatial partitioning and frustum culling to 
+
 speed up the search
 speed up the search
     - Objects are sorted according to a render queue
     - Objects are sorted according to a render queue
     - And sent to the render system one by one
     - And sent to the render system one by one
@@ -34,10 +36,12 @@ speed up the search
 
 
 --------------------------------------------
 --------------------------------------------
 
 
- Loading of mesh/texture/material should be a simple Resource.Load. Returns a ResourcePtr which is a managed ptr to resource. Resource 

-holds a pointer to its source, and it can be in a loaded or unloaded state. If we try to use an unloaded resource, a dummy resource is 

+ Loading of mesh/texture/material should be a simple Resource.Load. Returns a ResourcePtr which is a managed ptr to resource. Resource 
+
+holds a pointer to its source, and it can be in a loaded or unloaded state. If we try to use an unloaded resource, a dummy resource is 
+
 provided.
 provided.
 
 
 --------------------------------------------
 --------------------------------------------
 
 
- IMPORTANT: Develop scene manager and rest of things mentioned here in CamelotRenderer project, and then port it all together to 
+ IMPORTANT: Develop scene manager and rest of things mentioned here in CamelotRenderer project, and then port it all together to 

+ 10 - 1
CamelotRenderer/TODO.txt

@@ -49,6 +49,14 @@ IMPORTANT: I think I should strive to make the renderer one unique CmRenderSyste
    - Later separate out OpenGL and D3D9 dlls as well, since I want to support D3D11. And I want to keep the framework separate from implementation
    - Later separate out OpenGL and D3D9 dlls as well, since I want to support D3D11. And I want to keep the framework separate from implementation
      - AND because I need to have it separated since I can't expect DirectX to compile on OSX or Linux
      - AND because I need to have it separated since I can't expect DirectX to compile on OSX or Linux
 
 
+TOMORROW:
+ - Incorporate CamelotUtility library into CamelotRenderer
+   - First make sure to remove all Ogre namespaces and replace them with CamelotEngine
+   - Then remove all files included in CamelotUtility and add CamelotUtility include and library files
+   - Fix any errors due to missing defines (especially memory related)
+   - Move remaining Utility files to CamelotUtility (files like StringUtil, PixelUtil and similar)
+   - Remove Utility forward declarations from OgrePrerequisites. Make sure to include OgrePrerequisitesUtil in OgrePrerequisites
+
 Other notes:
 Other notes:
  - Search for all remaining "TODO PORT" comments and fix them
  - Search for all remaining "TODO PORT" comments and fix them
  - Make sure to remove all ogre memory allocators and memory category bullshit (Possibly replace with Camelot versions?)
  - Make sure to remove all ogre memory allocators and memory category bullshit (Possibly replace with Camelot versions?)
@@ -68,4 +76,5 @@ After everything is polished:
  - Get 64bit version working
  - Get 64bit version working
  - Add Unified shader so I can easily switch between HLSL and GLSL shaders (they need same parameters usually, just different code)
  - Add Unified shader so I can easily switch between HLSL and GLSL shaders (they need same parameters usually, just different code)
     - Maybe just add support for Cg and force everyone to use that? - I'd like to be able to just switch out renderer in a single location and that everything keeps on working without 
     - Maybe just add support for Cg and force everyone to use that? - I'd like to be able to just switch out renderer in a single location and that everything keeps on working without 
-	  further modifications.
+	  further modifications.
+ - Port boost threads to std threads (CmThreadDefines.h)

+ 1 - 1
CamelotUtility/CamelotUtility.vcxproj

@@ -67,6 +67,7 @@
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmMathAsm.h" />
     <ClInclude Include="Include\CmMathAsm.h" />
+    <ClInclude Include="Include\CmThreadDefines.h" />
     <ClInclude Include="Include\CmTypes.h" />
     <ClInclude Include="Include\CmTypes.h" />
     <ClInclude Include="Include\CmFwdDeclUtil.h" />
     <ClInclude Include="Include\CmFwdDeclUtil.h" />
     <ClInclude Include="Include\CmAxisAlignedBox.h" />
     <ClInclude Include="Include\CmAxisAlignedBox.h" />
@@ -80,7 +81,6 @@
     <ClInclude Include="Include\CmRay.h" />
     <ClInclude Include="Include\CmRay.h" />
     <ClInclude Include="Include\CmSphere.h" />
     <ClInclude Include="Include\CmSphere.h" />
     <ClInclude Include="Include\CmStdHeaders.h" />
     <ClInclude Include="Include\CmStdHeaders.h" />
-    <ClInclude Include="Include\CmThreadDefines.h" />
     <ClInclude Include="Include\CmVector2.h" />
     <ClInclude Include="Include\CmVector2.h" />
     <ClInclude Include="Include\CmVector3.h" />
     <ClInclude Include="Include\CmVector3.h" />
     <ClInclude Include="Include\CmVector4.h" />
     <ClInclude Include="Include\CmVector4.h" />

+ 6 - 3
CamelotUtility/CamelotUtility.vcxproj.filters

@@ -22,6 +22,9 @@
     <Filter Include="Source Files\Math">
     <Filter Include="Source Files\Math">
       <UniqueIdentifier>{6f183461-d042-41e0-9c81-aa8bc8462641}</UniqueIdentifier>
       <UniqueIdentifier>{6f183461-d042-41e0-9c81-aa8bc8462641}</UniqueIdentifier>
     </Filter>
     </Filter>
+    <Filter Include="Header Files\Threading">
+      <UniqueIdentifier>{b65008fc-0109-4b6d-b82b-7c30abdbeacf}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\CmTypes.h">
     <ClInclude Include="Include\CmTypes.h">
@@ -33,9 +36,6 @@
     <ClInclude Include="Include\CmStdHeaders.h">
     <ClInclude Include="Include\CmStdHeaders.h">
       <Filter>Header Files\Prerequisites</Filter>
       <Filter>Header Files\Prerequisites</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\CmThreadDefines.h">
-      <Filter>Header Files\Prerequisites</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmPrerequisitesUtil.h">
     <ClInclude Include="Include\CmPrerequisitesUtil.h">
       <Filter>Header Files\Prerequisites</Filter>
       <Filter>Header Files\Prerequisites</Filter>
     </ClInclude>
     </ClInclude>
@@ -78,6 +78,9 @@
     <ClInclude Include="Include\CmVector4.h">
     <ClInclude Include="Include\CmVector4.h">
       <Filter>Header Files\Math</Filter>
       <Filter>Header Files\Math</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmThreadDefines.h">
+      <Filter>Header Files\Threading</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Include\CmAxisAlignedBox.cpp">
     <ClCompile Include="Include\CmAxisAlignedBox.cpp">

+ 0 - 2
CamelotUtility/Include/CmPrerequisitesUtil.h

@@ -27,8 +27,6 @@ THE SOFTWARE
 
 
 #include <assert.h>
 #include <assert.h>
 
 
-#define CM_THREAD_SUPPORT 0 // No thread support for now
-
 // Platform-specific stuff
 // Platform-specific stuff
 #include "CmPlatform.h"
 #include "CmPlatform.h"
 
 

+ 7 - 0
CamelotUtility/Include/CmStdHeaders.h

@@ -111,6 +111,13 @@ extern "C" {
 }
 }
 #endif
 #endif
 
 
+#if CM_THREAD_SUPPORT
+#	if !defined(NOMINMAX) && defined(_MSC_VER)
+#		define NOMINMAX // required to stop windows.h messing up std::min
+#	endif
+#	include "CmThreadHeaders.h"
+#endif
+
 #if defined ( CM_GCC_VISIBILITY ) && (CM_PLATFORM != CM_PLATFORM_APPLE)
 #if defined ( CM_GCC_VISIBILITY ) && (CM_PLATFORM != CM_PLATFORM_APPLE)
 #   pragma GCC visibility pop
 #   pragma GCC visibility pop
 #endif
 #endif

+ 57 - 0
CamelotUtility/Include/CmThreadDefines.h

@@ -26,6 +26,60 @@ THE SOFTWARE
 #pragma once
 #pragma once
 
 
 #define CM_AUTO_MUTEX_NAME mutex
 #define CM_AUTO_MUTEX_NAME mutex
+
+#if CM_THREAD_SUPPORT
+
+// TODO - Port this to std threads so we aren't dependent on boost
+
+#include <boost/thread/tss.hpp>
+#include <boost/thread/recursive_mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/locks.hpp>
+
+#define CM_AUTO_MUTEX mutable boost::recursive_mutex CM_AUTO_MUTEX_NAME;
+#define CM_LOCK_AUTO_MUTEX boost::recursive_mutex::scoped_lock cmAutoMutexLock(CM_AUTO_MUTEX_NAME);
+#define CM_MUTEX(name) mutable boost::recursive_mutex name;
+#define CM_STATIC_MUTEX(name) static boost::recursive_mutex name;
+#define CM_STATIC_MUTEX_INSTANCE(name) boost::recursive_mutex name;
+#define CM_LOCK_MUTEX(name) boost::recursive_mutex::scoped_lock cmnameLock(name);
+#define CM_LOCK_MUTEX_NAMED(mutexName, lockName) boost::recursive_mutex::scoped_lock lockName(mutexName);
+// like CM_AUTO_MUTEX but mutex held by pointer
+#define CM_AUTO_SHARED_MUTEX mutable boost::recursive_mutex *CM_AUTO_MUTEX_NAME;
+#define CM_LOCK_AUTO_SHARED_MUTEX assert(CM_AUTO_MUTEX_NAME); boost::recursive_mutex::scoped_lock cmAutoMutexLock(*CM_AUTO_MUTEX_NAME);
+#define CM_NEW_AUTO_SHARED_MUTEX assert(!CM_AUTO_MUTEX_NAME); CM_AUTO_MUTEX_NAME = new boost::recursive_mutex();
+#define CM_DELETE_AUTO_SHARED_MUTEX assert(CM_AUTO_MUTEX_NAME); delete CM_AUTO_MUTEX_NAME;
+#define CM_COPY_AUTO_SHARED_MUTEX(from) assert(!CM_AUTO_MUTEX_NAME); CM_AUTO_MUTEX_NAME = from;
+#define CM_SET_AUTO_SHARED_MUTEX_NULL CM_AUTO_MUTEX_NAME = 0;
+#define CM_MUTEX_CONDITIONAL(mutex) if (mutex)
+#define CM_THREAD_SYNCHRONISER(sync) boost::condition sync;
+#define CM_THREAD_WAIT(sync, mutex, lock) sync.wait(lock);
+#define CM_THREAD_NOTIFY_ONE(sync) sync.notify_one(); 
+#define CM_THREAD_NOTIFY_ALL(sync) sync.notify_all(); 
+// Read-write mutex
+#define CM_RW_MUTEX(name) mutable boost::shared_mutex name
+#define CM_LOCK_RW_MUTEX_READ(name) boost::shared_lock<boost::shared_mutex> cmnameLock(name)
+#define CM_LOCK_RW_MUTEX_WRITE(name) boost::unique_lock<boost::shared_mutex> cmnameLock(name)
+// Thread-local pointer
+#define CM_THREAD_POINTER(T, var) boost::thread_specific_ptr<T> var
+#define CM_THREAD_POINTER_INIT(var) var(&deletePtr)
+#define CM_THREAD_POINTER_VAR(T, var) boost::thread_specific_ptr<T> var (&deletePtr<T>)
+#define CM_THREAD_POINTER_SET(var, expr) var.reset(expr)
+#define CM_THREAD_POINTER_GET(var) var.get()
+#define CM_THREAD_POINTER_DELETE(var) var.reset(0)
+// Thread objects and related functions
+#define CM_THREAD_TYPE boost::thread
+#define CM_THREAD_CREATE(name, worker) boost::thread* name = new boost::thread(worker);
+#define CM_THREAD_DESTROY(name) delete name;
+#define CM_THREAD_HARDWARE_CONCURRENCY boost::thread::hardware_concurrency()
+#define CM_THREAD_CURRENT_ID boost::this_thread::get_id()
+#define CM_THREAD_WORKER_INHERIT
+// Utility
+#define CM_THREAD_SLEEP(ms) boost::this_thread::sleep(boost::posix_time::millisec(ms));
+
+#else
+
 #define CM_AUTO_MUTEX
 #define CM_AUTO_MUTEX
 #define CM_LOCK_AUTO_MUTEX
 #define CM_LOCK_AUTO_MUTEX
 #define CM_MUTEX(name)
 #define CM_MUTEX(name)
@@ -55,3 +109,6 @@ THE SOFTWARE
 #define CM_THREAD_POINTER_DELETE(var) { delete var; var = 0; }
 #define CM_THREAD_POINTER_DELETE(var) { delete var; var = 0; }
 #define CM_THREAD_SLEEP(ms)
 #define CM_THREAD_SLEEP(ms)
 #define CM_THREAD_WORKER_INHERIT
 #define CM_THREAD_WORKER_INHERIT
+
+#endif
+