Browse Source

minor improves

Denis Muratshin 12 years ago
parent
commit
2f67f07145

+ 2 - 2
.hg_archival.txt

@@ -1,5 +1,5 @@
 repo: b6d71054df5712e643a0685bc3ba54b123db5729
-node: 3673bb51c9f0896ca43b2551a2f628971d9c63a1
+node: 56ca01b3ef126d80e4db098c6a192a1bbb303f39
 branch: default
 latesttag: oldrender
-latesttagdistance: 54
+latesttagdistance: 59

BIN
doc.zip


+ 7 - 1
examples/Demo/src/entry_point.cpp

@@ -1,5 +1,10 @@
+/**
+Attention!
+This file has Oxygine initialization stuff.
+If you just started you don't need to understand it exactly you could check it later. 
+You could start from example.cpp and example.h it has main functions being called from there
+*/
 #include <stdio.h>
-
 #include "core/Renderer.h"
 #include "RootActor.h"
 #include "DebugActor.h"
@@ -35,6 +40,7 @@ public:
 	}
 };
 
+//called each frame
 int mainloop()
 {
 	example_update();

+ 4 - 4
examples/Demo/win32/HelloWorld_vs2010.vcxproj

@@ -51,12 +51,12 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;OXYGINE_SDL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>../../../oxygine/src;../../../oxygine/third_party/win32/glew;../../../../SDL/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../../oxygine/src;../../../oxygine/third_party/win32/glew;../../../../SDL/include;../../../oxygine/third_party/win32/pthreads/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>glew32.lib;libjpeg.lib;libpng.lib;libzlib.lib;opengl32.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>glew32.lib;libjpeg.lib;libpng.lib;libzlib.lib;opengl32.lib;SDL2.lib;SDL2main.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>../../../oxygine/third_party/win32/libraries;../../../libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     </Link>
   </ItemDefinitionGroup>
@@ -69,7 +69,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;OXYGINE_SDL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>../../../oxygine/src;../../../oxygine/third_party/win32/glew;../../../../SDL2/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>../../../oxygine/src;../../../oxygine/third_party/win32/glew;../../../../SDL/include;../../../oxygine/third_party/win32/pthreads/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
@@ -77,7 +77,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <AdditionalLibraryDirectories>../../../oxygine/third_party/win32/libraries;../../../libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-      <AdditionalDependencies>glew32.lib;libjpeg.lib;libpng.lib;libzlib.lib;opengl32.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>glew32.lib;libjpeg.lib;libpng.lib;libzlib.lib;opengl32.lib;SDL2.lib;SDL2main.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>

+ 4 - 2
oxygine/SDL/win32/oxygine_vs2010.vcxproj

@@ -55,7 +55,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>..\..\src\;..\..\third_party\win32\zlib;..\..\third_party\win32\libjpeg;..\..\third_party\win32\libpng;..\..\greenlets\src\;..\..\..\..\SDL\include\;..\..\third_party\win32\OGLES;..\..\third_party\win32\glew;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\..\src\;..\..\third_party\win32\zlib;..\..\third_party\win32\libjpeg;..\..\third_party\win32\libpng;..\..\greenlets\src\;..\..\..\..\SDL\include\;..\..\third_party\win32\OGLES;..\..\third_party\win32\glew;../../third_party/win32/pthreads/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;OXYGINE_SDL;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <MinimalRebuild>true</MinimalRebuild>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -77,7 +77,7 @@
     <ClCompile>
       <Optimization>MaxSpeed</Optimization>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>..\..\src\;..\..\third_party\win32\zlib;..\..\third_party\win32\libjpeg;..\..\third_party\win32\libpng;..\..\greenlets\src\;..\..\..\..\SDL\include\;..\..\third_party\win32\OGLES;..\..\third_party\win32\glew;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\..\src\;..\..\third_party\win32\zlib;..\..\third_party\win32\libjpeg;..\..\third_party\win32\libpng;..\..\greenlets\src\;..\..\..\..\SDL\include\;..\..\third_party\win32\OGLES;..\..\third_party\win32\glew;../../third_party/win32/pthreads/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;OXYGINE_SDL;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <FunctionLevelLinking>true</FunctionLevelLinking>
@@ -124,6 +124,7 @@
     <ClCompile Include="..\..\src\core\STDFileSystem.cpp" />
     <ClCompile Include="..\..\src\core\system_data.cpp" />
     <ClCompile Include="..\..\src\core\Texture.cpp" />
+    <ClCompile Include="..\..\src\core\ThreadMessages.cpp" />
     <ClCompile Include="..\..\src\core\UberShaderProgram.cpp" />
     <ClCompile Include="..\..\src\core\VideoDriver.cpp" />
     <ClCompile Include="..\..\src\core\ZipFileSystem.cpp" />
@@ -213,6 +214,7 @@
     <ClInclude Include="..\..\src\core\STDFileSystem.h" />
     <ClInclude Include="..\..\src\core\system_data.h" />
     <ClInclude Include="..\..\src\core\Texture.h" />
+    <ClInclude Include="..\..\src\core\ThreadMessages.h" />
     <ClInclude Include="..\..\src\core\UberShaderProgram.h" />
     <ClInclude Include="..\..\src\core\vertex.h" />
     <ClInclude Include="..\..\src\core\VertexDeclaration.h" />

+ 6 - 0
oxygine/SDL/win32/oxygine_vs2010.vcxproj.filters

@@ -285,6 +285,9 @@
     <ClCompile Include="..\..\src\core\gl\ShaderProgramGL.cpp">
       <Filter>src\gl</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\core\ThreadMessages.cpp">
+      <Filter>src\core</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\closure\closure.h">
@@ -611,6 +614,9 @@
     <ClInclude Include="..\..\src\core\gl\ShaderProgramGL.h">
       <Filter>src\gl</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\core\ThreadMessages.h">
+      <Filter>src\core</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="ReadMe.txt" />

+ 1 - 1
oxygine/src/core/Mem2Native.cpp

@@ -26,7 +26,7 @@ namespace oxygine
 
 		src->addRef();
 		dest->addRef();
-		_messages.post(src.get(), dest.get());
+		_messages.post(0, src.get(), dest.get());
 	}
 	
 	bool Mem2Native::isEmpty()

+ 51 - 34
oxygine/src/core/ThreadMessages.cpp

@@ -17,7 +17,7 @@ namespace oxygine
 		pthread_mutex_t& _mutex;
 	};
 
-	ThreadMessages::ThreadMessages():_reply(0), _id(0), _waitReplyID(0), _lastGetID(0), _replied(false)
+	ThreadMessages::ThreadMessages():_id(0), _waitReplyID(0)
 	{			
 		pthread_cond_init(&_cond, 0);
 		pthread_mutex_init(&_mutex, 0);	
@@ -32,6 +32,7 @@ namespace oxygine
 	void ThreadMessages::wait()
 	{
 		MutexPthreadLock lock(_mutex);
+		_replyLast(0);
 		while (_events.empty())		
 			pthread_cond_wait(&_cond, &_mutex);			
 	}
@@ -39,18 +40,15 @@ namespace oxygine
 	void ThreadMessages::get(message &ev)
 	{
 		MutexPthreadLock lock(_mutex);
-		if (_lastGetID && _lastGetID == _waitReplyID)
-		{
-			_replied = true;
-			pthread_cond_signal(&_cond);
-		}
+
+		_replyLast(0);
 
 		while (_events.empty())
 			pthread_cond_wait(&_cond, &_mutex);			
 
 		ev = _events.front();
 		_events.erase(_events.begin());
-		_lastGetID = ev.id;	
+		_last = ev;
 	}
 
 	bool ThreadMessages::empty()
@@ -64,12 +62,7 @@ namespace oxygine
 		bool has = false;
 
 		MutexPthreadLock lock(_mutex);
-		
-		if (_lastGetID && _lastGetID == _waitReplyID)
-		{
-			_replied = true;
-			pthread_cond_signal(&_cond);
-		}
+		_replyLast(0);
 
 		if (!_events.empty())
 		{
@@ -77,57 +70,81 @@ namespace oxygine
 			if (del)
 				_events.erase(_events.begin());
 			has = true;
+			_last = ev;
 		}		
-		_lastGetID = ev.id;
 
 		return has;
 	}
 
+	void ThreadMessages::_replyLast(void *val)
+	{
+		if (!_last._replied)
+		{
+			_last._replied = true;
+			_last._result = val;
+
+			if (_last.cb)			
+				_last.cb(_last);
+
+			if (_waitReplyID && _last._id == _waitReplyID)
+			{
+				pthread_cond_signal(&_cond);
+			}
+		}
+	}
+
 	void ThreadMessages::reply(void *val)
 	{		
 		MutexPthreadLock lock(_mutex);
-
-		if (_lastGetID == _waitReplyID)
-		{
-			_replied = true;
-			_reply = val;
-			pthread_cond_signal(&_cond);
-		}		
+		_replyLast(val);		
 	}
 
 
-	void *ThreadMessages::send(void *arg1, void *arg2)
+	void *ThreadMessages::send(int msgid, void *arg1, void *arg2)
 	{
 		message ev;
+		ev.msgid = msgid;
 		ev.arg1 = arg1;
 		ev.arg2 = arg2;
-		ev.id = ++_id;
+		ev._id = ++_id;
 
 		MutexPthreadLock lock(_mutex);
 
-		_waitReplyID = ev.id;
+		_waitReplyID = ev._id;
 		_events.push_back(ev);
 		pthread_cond_signal(&_cond);
 
-		void *r = 0;
-		while (!_replied)
-		{
+		while (!_last._replied)		
 			pthread_cond_wait(&_cond, &_mutex);
-		}
+
 		_waitReplyID = 0;
-		_replied = false;
-		r = _reply;
-		_reply = 0;
+		_last._replied = false;
+
+		return _last._result;
+	}
+
+	void ThreadMessages::sendCallback(int msgid, void *arg1, void *arg2, callback cb, void *cbData)
+	{
+		message ev;
+		ev.msgid = msgid;
+		ev.arg1 = arg1;
+		ev.arg2 = arg2;
+		ev.cb = cb;
+		ev.cbData = cbData;
+		ev._id = ++_id;
 
-		return r;
+		MutexPthreadLock lock(_mutex);
+		_events.push_back(ev);
+		pthread_cond_signal(&_cond);
 	}
 
-	void ThreadMessages::post(void *arg1, void *arg2)
+	void ThreadMessages::post(int msgid, void *arg1, void *arg2)
 	{
 		message ev;
+		ev.msgid = msgid;
 		ev.arg1 = arg1;
 		ev.arg2 = arg2;
-		ev.id = ++_id;
+		ev._id = ++_id;
 
 		MutexPthreadLock lock(_mutex);
 		_events.push_back(ev);

+ 22 - 9
oxygine/src/core/ThreadMessages.h

@@ -6,12 +6,21 @@ namespace oxygine
 {
 	class ThreadMessages
 	{
-	public:
+	public:		
+		struct message;
+		typedef void (*callback)(const message &m);
 		struct message
 		{
+			message():msgid(0), arg1(0), arg2(0), cb(0), cbData(0), _id(0), _result(0), _replied(false){}
+			int msgid;
 			void *arg1;
-			void *arg2;
-			unsigned int id;
+			void *arg2;			
+			callback cb;
+			void *cbData;
+
+			unsigned int _id;
+			void *_result;
+			bool _replied;
 		};
 
 		ThreadMessages();
@@ -21,17 +30,21 @@ namespace oxygine
 		void wait();
 		void get(message &ev);
 		bool peek(message &ev, bool del);
-		void reply(void *val);
-		void *send(void *arg1, void *arg2);
-		void post(void *arg1, void *arg2);
+				
+		void*send(int msgid, void *arg1, void *arg2);
+		void sendCallback(int msgid, void *arg1, void *arg2, callback cb, void *cbData);
+		void post(int msgid, void *arg1, void *arg2);
+
+		void reply(void *val);		
 
 	private:
+		void _replyLast(void *val);
 		std::vector<message> _events;
 		unsigned int _id;
 		unsigned int _waitReplyID;
-		unsigned int _lastGetID;
-		bool _replied;
-		void* _reply;
+		//unsigned int _lastGetID;
+		message _last;
+		//bool _replied;
 		pthread_cond_t _cond;
 		pthread_mutex_t _mutex;
 	};

+ 169 - 0
oxygine/third_party/win32/pthreads/include/semaphore.h

@@ -0,0 +1,169 @@
+/*
+ * Module: semaphore.h
+ *
+ * Purpose:
+ *	Semaphores aren't actually part of the PThreads standard.
+ *	They are defined by the POSIX Standard:
+ *
+ *		POSIX 1003.1b-1993	(POSIX.1b)
+ *
+ * --------------------------------------------------------------------------
+ *
+ *      Pthreads-win32 - POSIX Threads Library for Win32
+ *      Copyright(C) 1998 John E. Bossom
+ *      Copyright(C) 1999,2005 Pthreads-win32 contributors
+ * 
+ *      Contact Email: [email protected]
+ * 
+ *      The current list of contributors is contained
+ *      in the file CONTRIBUTORS included with the source
+ *      code distribution. The list can also be seen at the
+ *      following World Wide Web location:
+ *      http://sources.redhat.com/pthreads-win32/contributors.html
+ * 
+ *      This library is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU Lesser General Public
+ *      License as published by the Free Software Foundation; either
+ *      version 2 of the License, or (at your option) any later version.
+ * 
+ *      This library is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *      Lesser General Public License for more details.
+ * 
+ *      You should have received a copy of the GNU Lesser General Public
+ *      License along with this library in the file COPYING.LIB;
+ *      if not, write to the Free Software Foundation, Inc.,
+ *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#if !defined( SEMAPHORE_H )
+#define SEMAPHORE_H
+
+#undef PTW32_SEMAPHORE_LEVEL
+
+#if defined(_POSIX_SOURCE)
+#define PTW32_SEMAPHORE_LEVEL 0
+/* Early POSIX */
+#endif
+
+#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
+#undef PTW32_SEMAPHORE_LEVEL
+#define PTW32_SEMAPHORE_LEVEL 1
+/* Include 1b, 1c and 1d */
+#endif
+
+#if defined(INCLUDE_NP)
+#undef PTW32_SEMAPHORE_LEVEL
+#define PTW32_SEMAPHORE_LEVEL 2
+/* Include Non-Portable extensions */
+#endif
+
+#define PTW32_SEMAPHORE_LEVEL_MAX 3
+
+#if !defined(PTW32_SEMAPHORE_LEVEL)
+#define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX
+/* Include everything */
+#endif
+
+#if defined(__GNUC__) && ! defined (__declspec)
+# error Please upgrade your GNU compiler to one that supports __declspec.
+#endif
+
+/*
+ * When building the library, you should define PTW32_BUILD so that
+ * the variables/functions are exported correctly. When using the library,
+ * do NOT define PTW32_BUILD, and then the variables/functions will
+ * be imported correctly.
+ */
+#if !defined(PTW32_STATIC_LIB)
+#  if defined(PTW32_BUILD)
+#    define PTW32_DLLPORT __declspec (dllexport)
+#  else
+#    define PTW32_DLLPORT __declspec (dllimport)
+#  endif
+#else
+#  define PTW32_DLLPORT
+#endif
+
+/*
+ * This is a duplicate of what is in the autoconf config.h,
+ * which is only used when building the pthread-win32 libraries.
+ */
+
+#if !defined(PTW32_CONFIG_H)
+#  if defined(WINCE)
+#    define NEED_ERRNO
+#    define NEED_SEM
+#  endif
+#  if defined(__MINGW64__)
+#    define HAVE_STRUCT_TIMESPEC
+#    define HAVE_MODE_T
+#  elif defined(_UWIN) || defined(__MINGW32__)
+#    define HAVE_MODE_T
+#  endif
+#endif
+
+/*
+ *
+ */
+
+#if PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX
+#if defined(NEED_ERRNO)
+#include "need_errno.h"
+#else
+#include <errno.h>
+#endif
+#endif /* PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX */
+
+#define _POSIX_SEMAPHORES
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif				/* __cplusplus */
+
+#if !defined(HAVE_MODE_T)
+typedef unsigned int mode_t;
+#endif
+
+
+typedef struct sem_t_ * sem_t;
+
+PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
+			    int pshared,
+			    unsigned int value);
+
+PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
+
+PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
+
+PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
+
+PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
+				 const struct timespec * abstime);
+
+PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
+
+PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
+				     int count);
+
+PTW32_DLLPORT int __cdecl sem_open (const char * name,
+			    int oflag,
+			    mode_t mode,
+			    unsigned int value);
+
+PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);
+
+PTW32_DLLPORT int __cdecl sem_unlink (const char * name);
+
+PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
+				int * sval);
+
+#if defined(__cplusplus)
+}				/* End of extern "C" */
+#endif				/* __cplusplus */
+
+#undef PTW32_SEMAPHORE_LEVEL
+#undef PTW32_SEMAPHORE_LEVEL_MAX
+
+#endif				/* !SEMAPHORE_H */

+ 1 - 1
readme.SDL2

@@ -1,4 +1,4 @@
-1. Download SDL2 (http://www.libsdl.org/)
+1. Download  latest SDL2 source snapshot http://libsdl.org/hg.php
 2. Put it on the same level with oxygine-framework
 root\
      oxygine-framework