Panagiotis Christopoulos Charitos 13 lat temu
rodzic
commit
5220f1c573

+ 4 - 4
include/anki/scene/Movable.h

@@ -14,7 +14,7 @@ class PropertyMap;
 /// @{
 
 /// Interface for movable scene nodes
-class Movable: public Object<Movable>, public Flags<uint32_t>
+class Movable: public Object<Movable>, public Flags<U32>
 {
 public:
 	typedef Object<Movable> Base;
@@ -32,7 +32,7 @@ public:
 	/// @param flags The flags
 	/// @param parent The parent. It can be nullptr
 	/// @param pmap Property map to add a few variables
-	Movable(uint32_t flags, Movable* parent, PropertyMap& pmap);
+	Movable(U32 flags, Movable* parent, PropertyMap& pmap);
 
 	~Movable();
 	/// @}
@@ -74,7 +74,7 @@ public:
 		return prevWTrf;
 	}
 
-	uint32_t getMovableTimestamp() const
+	U32 getMovableTimestamp() const
 	{
 		return timestamp;
 	}
@@ -146,7 +146,7 @@ protected:
 	Transform prevWTrf = Transform::getIdentity();
 
 	/// The frame where it was last moved
-	uint32_t timestamp = Timestamp::getTimestamp();
+	U32 timestamp = Timestamp::getTimestamp();
 
 	/// Called for every frame. It updates the @a wTrf if @a shouldUpdateWTrf
 	/// is true. Then it moves to the children.

+ 2 - 2
src/scene/Movable.cpp

@@ -4,7 +4,7 @@
 namespace anki {
 
 //==============================================================================
-Movable::Movable(uint32_t flags_, Movable* parent, PropertyMap& pmap)
+Movable::Movable(U32 flags_, Movable* parent, PropertyMap& pmap)
 	: Base(this, parent), Flags(flags_)
 {
 	pmap.addNewProperty(
@@ -31,7 +31,7 @@ void Movable::updateWorldTransform()
 {
 	prevWTrf = wTrf;
 	Movable* parent = getParent();
-	uint32_t crntTimestamp = Timestamp::getTimestamp();
+	U32 crntTimestamp = Timestamp::getTimestamp();
 
 	if(parent)
 	{

+ 47 - 0
src/scene/Scene.cpp

@@ -2,9 +2,41 @@
 #include "anki/scene/Camera.h"
 #include "anki/util/Exception.h"
 #include "anki/scene/VisibilityTester.h"
+#include "anki/core/ThreadPool.h"
 
 namespace anki {
 
+//==============================================================================
+// Misc                                                                        =
+//==============================================================================
+
+//==============================================================================
+struct UpdateMovablesJob: ThreadJob
+{
+	Scene::Types<SceneNode>::Iterator movablesBegin;
+	U32 movablesCount;
+
+	void operator()(U threadId, U threadsCount)
+	{
+		U64 start, end;
+		choseStartEnd(threadId, threadsCount, movablesCount, start, end);
+
+		for(U64 i = start; i < end; i++)
+		{
+			SceneNode* sn = *(movablesBegin + i);
+			Movable* m = sn->getMovable();
+			if(m)
+			{
+				m->update();
+			}
+		}
+	}
+};
+
+//==============================================================================
+// Scene                                                                       =
+//==============================================================================
+
 //==============================================================================
 Scene::Scene()
 {
@@ -34,6 +66,7 @@ void Scene::update(float prevUpdateTime, float crntTime, Renderer& r)
 {
 	physics.update(prevUpdateTime, crntTime);
 
+#if 0
 	// First do the movable updates
 	for(SceneNode* n : nodes)
 	{
@@ -43,6 +76,20 @@ void Scene::update(float prevUpdateTime, float crntTime, Renderer& r)
 			m->update();
 		}
 	}
+#else
+	ThreadPool& threadPool = ThreadPoolSingleton::get();
+	UpdateMovablesJob jobs[ThreadPool::MAX_THREADS];
+
+	for(U i = 0; i < threadPool.getThreadsCount(); i++)
+	{
+		jobs[i].movablesBegin = nodes.begin();
+		jobs[i].movablesCount = nodes.size();
+
+		threadPool.assignNewJob(i, &jobs[i]);
+	}
+
+	threadPool.waitForAllJobsToFinish();
+#endif
 
 	// Then the rest
 	for(SceneNode* n : nodes)

+ 29 - 22
src/util/HighRezTimerPosix.cpp

@@ -42,6 +42,26 @@ struct DummyInitTimer
 
 static DummyInitTimer dummy;
 
+//==============================================================================
+static U32 getMs()
+{
+	U32 ticks;
+
+#if HAVE_CLOCK_GETTIME
+	struct timespec now;
+	clock_gettime(CLOCK_MONOTONIC, &now);
+	ticks = (now.tv_sec - gstart.tv_sec) * 1000 
+		+ (now.tv_nsec - gstart.tv_nsec) / 1000000;
+#else
+	struct timeval now;
+	gettimeofday(&now, NULL);
+	ticks = (now.tv_sec - gstart.tv_sec) * 1000 
+		+ (now.tv_usec - gstart.tv_usec) / 1000;
+#endif
+
+	return ticks;
+}
+
 //==============================================================================
 void HighRezTimer::start()
 {
@@ -62,7 +82,7 @@ void HighRezTimer::stop()
 //==============================================================================
 HighRezTimer::Scalar HighRezTimer::getElapsedTime() const
 {
-	if(stopTime == 0)
+	if(stopTime == 0.0)
 	{
 		return getCurrentTime() - startTime;
 	}
@@ -75,27 +95,14 @@ HighRezTimer::Scalar HighRezTimer::getElapsedTime() const
 //==============================================================================
 HighRezTimer::Scalar HighRezTimer::getCurrentTime()
 {
-	U32 ticks;
-
-#if HAVE_CLOCK_GETTIME
-	struct timespec now;
-	clock_gettime(CLOCK_MONOTONIC, &now);
-	ticks = (now.tv_sec - gstart.tv_sec) * 1000 
-		+ (now.tv_nsec - gstart.tv_nsec) / 1000000;
-#else
-	struct timeval now;
-	gettimeofday(&now, NULL);
-	ticks = (now.tv_sec - gstart.tv_sec) * 1000 
-		+ (now.tv_usec - gstart.tv_usec) / 1000;
-#endif
-
-	return Scalar(ticks) / 1000.0;
+	// Scalar(ticks) / 1000.0
+	return Scalar(getMs()) * 0.001;
 }
 
 //==============================================================================
 void HighRezTimer::sleep(Scalar sec)
 {
-	int was_error;
+	int wasError;
 	U32 ms = U32(sec * 1000.0);
 
 #if HAVE_NANOSLEEP
@@ -110,7 +117,7 @@ void HighRezTimer::sleep(Scalar sec)
 	elapsed.tv_sec = ms / 1000;
 	elapsed.tv_nsec = (ms % 1000) * 1000000;
 #else
-	then = getCurrentTime() * 1000.0;
+	then = getMs();
 #endif
 
 	do 
@@ -120,10 +127,10 @@ void HighRezTimer::sleep(Scalar sec)
 #if HAVE_NANOSLEEP
 		tv.tv_sec = elapsed.tv_sec;
 		tv.tv_nsec = elapsed.tv_nsec;
-		was_error = nanosleep(&tv, &elapsed);
+		wasError = nanosleep(&tv, &elapsed);
 #else
 		// Calculate the time interval left (in case of interrupt)
-		now = getCurrentTime() * 1000.0;
+		now = getMs();
 		elapsed = now - then;
 		then = now;
 		if(elapsed >= ms)
@@ -134,9 +141,9 @@ void HighRezTimer::sleep(Scalar sec)
 		tv.tv_sec = ms / 1000;
 		tv.tv_usec = (ms % 1000) * 1000;
 
-		was_error = select(0, NULL, NULL, NULL, &tv);
+		wasError = select(0, NULL, NULL, NULL, &tv);
 #endif
-	} while(was_error && (errno == EINTR));
+	} while(wasError && (errno == EINTR));
 }
 
 } // end namespace anki

+ 2 - 2
testapp/Main.cpp

@@ -242,7 +242,7 @@ void init()
 
 	(void)sponzaModel;
 
-	initPhysics();
+	/*initPhysics();*/
 }
 
 //==============================================================================
@@ -449,7 +449,7 @@ void initSubsystems(int argc, char* argv[])
 	// Main renderer
 	RendererInitializer initializer;
 	initializer.ms.ez.enabled = true;
-	initializer.dbg.enabled = true;
+	initializer.dbg.enabled = false;
 	initializer.is.sm.bilinearEnabled = true;
 	initializer.is.sm.enabled = true;
 	initializer.is.sm.pcfEnabled = false;