aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/.vs/libjin/v14/.suobin116224 -> 127488 bytes
-rw-r--r--build/02Audio/02Audio.vcxproj133
-rw-r--r--build/02Audio/02Audio.vcxproj.filters22
-rw-r--r--build/02Audio/02Audio.vcxproj.user11
-rw-r--r--build/03Thread/03Thread.vcxproj134
-rw-r--r--build/03Thread/03Thread.vcxproj.filters25
-rw-r--r--build/03Thread/03Thread.vcxproj.user11
-rw-r--r--build/03Thread/main.cpp154
-rw-r--r--build/libjin.sln10
-rw-r--r--libjin/Math/Math.h4
-rw-r--r--libjin/Thread/Thread.cpp246
-rw-r--r--libjin/Thread/Thread.h71
-rw-r--r--libjin/Time/Timer.cpp84
-rw-r--r--libjin/Time/Timer.h52
-rw-r--r--libjin/modules.h3
-rw-r--r--test/02Audio/audiotest.cpp2
-rw-r--r--test/03Thread/threadtest.cpp86
17 files changed, 991 insertions, 57 deletions
diff --git a/build/.vs/libjin/v14/.suo b/build/.vs/libjin/v14/.suo
index 50ddad7..ad5ef85 100644
--- a/build/.vs/libjin/v14/.suo
+++ b/build/.vs/libjin/v14/.suo
Binary files differ
diff --git a/build/02Audio/02Audio.vcxproj b/build/02Audio/02Audio.vcxproj
new file mode 100644
index 0000000..a06df79
--- /dev/null
+++ b/build/02Audio/02Audio.vcxproj
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{A2D75980-B0AC-498C-B507-4727B4A38E83}</ProjectGuid>
+ <RootNamespace>My02Audio</RootNamespace>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <AdditionalLibraryDirectories>$(SolutionDir)\lib\SDL2-2.0.5\lib\x86\</AdditionalLibraryDirectories>
+ <AdditionalDependencies>SDL2main.lib;SDL2.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(SolutionDir)\lib\SDL2-2.0.5\lib\x86\</AdditionalLibraryDirectories>
+ <AdditionalDependencies>SDL2main.lib;SDL2.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\test\02Audio\audiotest.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\libjin\libjin.vcxproj">
+ <Project>{407e9199-d39c-4460-b218-0c29ab42483b}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/build/02Audio/02Audio.vcxproj.filters b/build/02Audio/02Audio.vcxproj.filters
new file mode 100644
index 0000000..30ce2ab
--- /dev/null
+++ b/build/02Audio/02Audio.vcxproj.filters
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="源文件">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="头文件">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="资源文件">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\test\02Audio\audiotest.cpp">
+ <Filter>源文件</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/build/02Audio/02Audio.vcxproj.user b/build/02Audio/02Audio.vcxproj.user
new file mode 100644
index 0000000..1b06f4b
--- /dev/null
+++ b/build/02Audio/02Audio.vcxproj.user
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LocalDebuggerWorkingDirectory>$(SolutionDir)$(Configuration)\</LocalDebuggerWorkingDirectory>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LocalDebuggerWorkingDirectory>$(SolutionDir)$(Configuration)\</LocalDebuggerWorkingDirectory>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/build/03Thread/03Thread.vcxproj b/build/03Thread/03Thread.vcxproj
new file mode 100644
index 0000000..ddd8193
--- /dev/null
+++ b/build/03Thread/03Thread.vcxproj
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{0E49D105-2032-4825-9FA1-54B1B94E3655}</ProjectGuid>
+ <RootNamespace>My03Thread</RootNamespace>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <AdditionalLibraryDirectories>$(SolutionDir)\lib\SDL2-2.0.5\lib\x86\</AdditionalLibraryDirectories>
+ <AdditionalDependencies>SDL2main.lib;SDL2.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalLibraryDirectories>$(SolutionDir)\lib\SDL2-2.0.5\lib\x86\</AdditionalLibraryDirectories>
+ <AdditionalDependencies>SDL2main.lib;SDL2.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\libjin\libjin.vcxproj">
+ <Project>{407e9199-d39c-4460-b218-0c29ab42483b}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\test\03Thread\threadtest.cpp" />
+ <ClCompile Include="main.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/build/03Thread/03Thread.vcxproj.filters b/build/03Thread/03Thread.vcxproj.filters
new file mode 100644
index 0000000..d0d38cf
--- /dev/null
+++ b/build/03Thread/03Thread.vcxproj.filters
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="源文件">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="头文件">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="资源文件">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\test\03Thread\threadtest.cpp">
+ <Filter>源文件</Filter>
+ </ClCompile>
+ <ClCompile Include="main.cpp">
+ <Filter>源文件</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/build/03Thread/03Thread.vcxproj.user b/build/03Thread/03Thread.vcxproj.user
new file mode 100644
index 0000000..1b06f4b
--- /dev/null
+++ b/build/03Thread/03Thread.vcxproj.user
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LocalDebuggerWorkingDirectory>$(SolutionDir)$(Configuration)\</LocalDebuggerWorkingDirectory>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LocalDebuggerWorkingDirectory>$(SolutionDir)$(Configuration)\</LocalDebuggerWorkingDirectory>
+ <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/build/03Thread/main.cpp b/build/03Thread/main.cpp
new file mode 100644
index 0000000..ed12172
--- /dev/null
+++ b/build/03Thread/main.cpp
@@ -0,0 +1,154 @@
+//#include <SDL2/SDL.h>
+//#include <SDL2/SDL_thread.h>
+//#include <iostream>
+//#include <sstream>
+//#include <stdexcept>
+//
+//class SdlMutex
+//{
+//public:
+// SdlMutex()
+// {
+// mutex = SDL_CreateMutex();
+// if (!mutex) throw std::runtime_error("SDL_CreateMutex == NULL");
+// }
+//
+// ~SdlMutex()
+// {
+// SDL_DestroyMutex(mutex);
+// }
+//
+// void lock()
+// {
+// if (SDL_mutexP(mutex) == -1) throw std::runtime_error("SDL_mutexP == -1");
+// // Note:
+// // -1 does not mean it was already locked - it means there was an error in locking -
+// // if it was locked it will just block - see SDL_mutexP(3)
+// }
+//
+// void unlock()
+// {
+// if (SDL_mutexV(mutex) == -1) throw std::runtime_error("SDL_mutexV == -1");
+// }
+//
+// SDL_mutex* underlying()
+// {
+// return mutex;
+// }
+//private:
+// SDL_mutex* mutex;
+//};
+//
+//class SdlScopedLock
+//{
+//public:
+// SdlScopedLock(SdlMutex& mutex)
+// :
+// mutex(mutex)
+// {
+// mutex.lock();
+// }
+// ~SdlScopedLock()
+// {
+// try
+// {
+// this->unlock();
+// }
+// catch (const std::exception& e)
+// {
+// // Destructors should never throw ...
+// std::cerr << "SdlScopedLock::~SdlScopedLock - caught : " << e.what() << std::endl;
+// }
+// }
+// void unlock()
+// {
+// mutex.unlock();
+// }
+//private:
+// SdlMutex& mutex;
+//};
+//
+//class ThreadData
+//{
+//public:
+// ThreadData()
+// :
+// dataReady(false),
+// done(false)
+// {
+// condition = SDL_CreateCond();
+// }
+//
+// ~ThreadData()
+// {
+// SDL_DestroyCond(condition);
+// }
+//
+// // Using stringstream so I can just shift on integers...
+// std::stringstream data;
+// bool dataReady;
+// bool done;
+// SdlMutex mutex;
+// SDL_cond* condition;
+//};
+//
+//int threadFunction(void* data)
+//{
+// try
+// {
+// ThreadData* threadData = static_cast< ThreadData* >(data);
+//
+// for (size_t i = 0; i < 100; i++)
+// {
+// {
+// SdlScopedLock lock(threadData->mutex);
+// // Everything in this scope is now syncronized with the mutex
+// if (i != 0) threadData->data << ", ";
+// threadData->data << i;
+// threadData->dataReady = true;
+// } // threadData->mutex is automatically unlocked here
+// // Its important to note that condition should be signaled after mutex is unlocked
+// if (SDL_CondSignal(threadData->condition) == -1) throw std::runtime_error("Failed to signal");
+// }
+// {
+// SdlScopedLock lock(threadData->mutex);
+// threadData->done = true;
+// }
+// if (SDL_CondSignal(threadData->condition) == -1) throw std::runtime_error("Failed to signal");
+// return 0;
+// }
+// catch (const std::exception& e)
+// {
+// std::cerr << "Caught : " << e.what() << std::endl;
+// return 1;
+// }
+//}
+//
+//int main(int argc, char* argv[])
+//{
+// ThreadData threadData;
+// SDL_Thread* thread = SDL_CreateThread(threadFunction, "", &threadData);
+//
+// while (true)
+// {
+// SdlScopedLock lock(threadData.mutex);
+// while (threadData.dataReady == false && threadData.done == false)
+// {
+// // NOTE: must call condition wait with mutex already locked
+// if (SDL_CondWait(threadData.condition, threadData.mutex.underlying()) == -1) throw std::runtime_error("Failed to wait");
+// }
+// // once dataReady == true or threadData.done == true we get here
+// std::cout << "Got data = " << threadData.data.str() << std::endl;
+// threadData.data.str("");
+// threadData.dataReady = false;
+// if (threadData.done)
+// {
+// std::cout << "child done - ending" << std::endl;
+// break;
+// }
+// }
+//
+// int status = 99;
+// SDL_WaitThread(thread, &status);
+// std::cerr << "Thread completed with : " << status << std::endl;
+//} \ No newline at end of file
diff --git a/build/libjin.sln b/build/libjin.sln
index 8f9bfae..eb11a5f 100644
--- a/build/libjin.sln
+++ b/build/libjin.sln
@@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "01HelloWorld", "01HelloWorl
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "02Audio", "02Audio\02Audio.vcxproj", "{A2D75980-B0AC-498C-B507-4727B4A38E83}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "03Thread", "03Thread\03Thread.vcxproj", "{0E49D105-2032-4825-9FA1-54B1B94E3655}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -41,6 +43,14 @@ Global
{A2D75980-B0AC-498C-B507-4727B4A38E83}.Release|x64.Build.0 = Release|x64
{A2D75980-B0AC-498C-B507-4727B4A38E83}.Release|x86.ActiveCfg = Release|Win32
{A2D75980-B0AC-498C-B507-4727B4A38E83}.Release|x86.Build.0 = Release|Win32
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Debug|x64.ActiveCfg = Debug|x64
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Debug|x64.Build.0 = Debug|x64
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Debug|x86.ActiveCfg = Debug|Win32
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Debug|x86.Build.0 = Debug|Win32
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x64.ActiveCfg = Release|x64
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x64.Build.0 = Release|x64
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x86.ActiveCfg = Release|Win32
+ {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/libjin/Math/Math.h b/libjin/Math/Math.h
index d4bd202..2bc8ed9 100644
--- a/libjin/Math/Math.h
+++ b/libjin/Math/Math.h
@@ -11,10 +11,10 @@ namespace math
{
#ifdef min
-#undef min
+# undef min
#endif // min
#ifdef max
-#undef max
+# undef max
#endif // max
template<typename T>
diff --git a/libjin/Thread/Thread.cpp b/libjin/Thread/Thread.cpp
index f7a4fb4..e77daa3 100644
--- a/libjin/Thread/Thread.cpp
+++ b/libjin/Thread/Thread.cpp
@@ -8,62 +8,264 @@ namespace jin
namespace thread
{
- Thread::Thread(const std::string name, ThreadFunc threadFunc)
- : paramters(nullptr)
+ class Mutex
{
- #if JIN_THREAD_SDL
- mutex = SDL_CreateMutex();
- condition = SDL_CreateCond();
+ public:
+ Mutex();
+ ~Mutex();
+
+ void lock();
+ void unlock();
+ private:
+ #if JIN_THREAD_SDL
+ SDL_mutex* mutex;
+ #endif
+ friend class Conditional;
+ };
+
+ // ̼߳signal wait
+ class Conditional
+ {
+ public:
+ Conditional();
+ ~Conditional();
+ void signal();
+ void broadcast();
+ bool wait(Mutex* mutex, int timeout = -1);
+ private:
+ #if JIN_THREAD_SDL
+ SDL_cond* cond;
#endif
- this->threadFunc = threadFunc;
- }
+ };
- void Thread::start()
+ class Lock
{
- if (handle == nullptr)
- {
- #if JIN_THREAD_SDL
- handle = SDL_CreateThread(threadFunc, name.c_str(), (void*)paramters);
- #elif JIN_THREAD_CPP
- handle = new std::thread();
- #endif
+ public:
+ Lock(Mutex* m) : mutex(m) {
+ mutex->lock();
}
- }
- void Thread::kill()
+ Lock(Mutex& m) : mutex(&m) {
+ mutex->lock();
+ }
+
+ ~Lock() {
+ mutex->unlock();
+ }
+ private:
+ Mutex* mutex;
+
+ Lock(Lock&) {}
+
+ };
+
+ //////////////////////////////////////////////////////////////////////
+
+ Mutex::Mutex()
{
#if JIN_THREAD_SDL
+ mutex = SDL_CreateMutex();
+ #endif
+ }
+ Mutex::~Mutex()
+ {
+ #if JIN_THREAD_SDL
+ SDL_DestroyMutex(mutex);
#endif
}
- void Thread::lock()
+ void Mutex::lock()
{
#if JIN_THREAD_SDL
SDL_LockMutex(mutex);
#endif
}
- void Thread::unlock()
+ void Mutex::unlock()
{
#if JIN_THREAD_SDL
SDL_UnlockMutex(mutex);
#endif
}
- void Thread::send()
+ //////////////////////////////////////////////////////////////////////
+
+ Conditional::Conditional()
+ {
+ #if JIN_THREAD_SDL
+ cond = SDL_CreateCond();
+ #endif
+ }
+
+ Conditional::~Conditional()
+ {
+ #if JIN_THREAD_SDL
+ SDL_DestroyCond(cond);
+ #endif
+ }
+
+ void Conditional::signal()
+ {
+ #if JIN_THREAD_SDL
+ SDL_CondSignal(cond);
+ #endif
+ }
+
+ void Conditional::broadcast()
+ {
+ #if JIN_THREAD_SDL
+ SDL_CondBroadcast(cond);
+ #endif
+ }
+
+ bool Conditional::wait(Mutex* mutex, int timeout)
+ {
+ #if JIN_THREAD_SDL
+ if (timeout < 0)
+ return !SDL_CondWait(cond, mutex->mutex);
+ else
+ return (SDL_CondWaitTimeout(cond, mutex->mutex, timeout) == 0);
+ #endif
+ }
+
+ //////////////////////////////////////////////////////////////////////
+
+ Thread::ThreadData::ThreadData(Mutex* m, Conditional* c)
+ : mutex(m)
+ , condition(c)
+ , share()
+ {
+ }
+
+ Thread::ThreadData::~ThreadData()
+ {
+ }
+
+ void Thread::ThreadData::set(std::string name, Value* value)
+ {
+ if (share.count(name) != 0);
+ share[name] = value;
+ }
+
+ Thread::Value* Thread::ThreadData::get(std::string name)
{
+ if (share.count(name) != 0)
+ return nullptr;
+ return share[name];
+ }
+
+ void Thread::ThreadData::remove(std::string name)
+ {
+ if (share.count(name) == 0)
+ {
+ share.erase(name);
+ }
+ }
+ //////////////////////////////////////////////////////////////////////
+
+ Thread::Thread(const std::string tname, ThreadRunner runner)
+ : name(tname)
+ , running(false)
+ , threadRunner(runner)
+ {
+ mutex = new Mutex();
+ condition = new Conditional();
+ common = new Thread::ThreadData(mutex, condition);
}
Thread::~Thread()
{
#if JIN_THREAD_SDL
- SDL_DestroyMutex(mutex);
- SDL_DestroyCond(condition);
#endif
}
+ const char* Thread::getName()
+ {
+ Lock l(mutex);
+ return name.c_str();
+ };
+
+ bool Thread::isRunning()
+ {
+ Lock l(mutex);
+ return running;
+ };
+
+ bool Thread::start(void* p)
+ {
+ Lock l(mutex);
+ if (running)
+ return false;
+ if (handle)
+ {
+ #if JIN_THREAD_SDL
+ SDL_WaitThread(handle, nullptr);
+ #endif
+ }
+ #if JIN_THREAD_SDL
+ handle = SDL_CreateThread(threadRunner, name.c_str(), (void*)p);
+ #elif JIN_THREAD_CPP
+ handle = new std::thread();
+ #endif
+ return (running = (handle != nullptr));
+ }
+
+ void Thread::wait()
+ {
+ {
+ Lock l(mutex);
+ if (!handle)
+ return;
+ }
+ #if JIN_THREAD_SDL
+ SDL_WaitThread(handle, nullptr);
+ #endif
+ Lock l(mutex);
+ running = false;
+ handle = nullptr;
+ }
+
+ void Thread::lock()
+ {
+ if (mutex != nullptr)
+ mutex->lock();
+ }
+
+ void Thread::unlock()
+ {
+ if (mutex != nullptr)
+ mutex->unlock();
+ }
+
+ void Thread::set(std::string name, Value* value)
+ {
+ lock();
+ common->set(name, value);
+ unlock();
+ condition->broadcast();
+ }
+
+ Thread::Value* Thread::get(std::string name)
+ {
+ Thread::Value* v = common->get(name);
+ return v;
+ }
+
+ Thread::Value* Thread::demand(std::string name)
+ {
+ Thread::Value* v = common->get(name);
+ while (!v)
+ {
+ if (common->get("error"))
+ return 0;
+ condition->wait(mutex);
+ v = common->get(name);
+ }
+ return v;
+ }
+
} // thread
} // jin
diff --git a/libjin/Thread/Thread.h b/libjin/Thread/Thread.h
index fe5bf56..2e86d73 100644
--- a/libjin/Thread/Thread.h
+++ b/libjin/Thread/Thread.h
@@ -4,6 +4,7 @@
#if JIN_MODULES_THREAD
#include <string>
+#include <map>
#if JIN_THREAD_SDL
# include "SDL2/SDL_thread.h"
#elif JIN_THREAD_CPP
@@ -17,44 +18,64 @@ namespace jin
namespace thread
{
- class ThreadData
- {
-
- };
+ class Mutex;
+ class Conditional;
class Thread
{
- public:
- typedef int(ThreadFunc)(void*);
+ public:
+ union Value
+ {
+ int integer;
+ bool boolean;
+ char character;
+ void* pointer;
+ };
- Thread(const std::string name, ThreadFunc threadfuncs);
- ~Thread();
+ private:
+ class ThreadData
+ {
+ public:
+ ThreadData(Mutex*, Conditional*);
+ ~ThreadData();
+ void set(std::string name, Value* value);
+ Value* get(std::string name);
+ void remove(std::string name);
+ Conditional* condition;
+ Mutex* mutex;
- void start();
- void kill();
- void wait();
- const char* getName() const;
- void recerive();
- void demand();
- void peek();
- void send();
+ private:
+ std::map<std::string, Value*> share; // threads shared value
+ };
- void lock();
- void unlock();
+ public:
+ typedef int(ThreadRunner)(void* /*ThreadData*/);
+ Thread(const std::string name, ThreadRunner threadfuncs);
+ ~Thread();
+ bool start(void* paramters);
+ void wait();
+ void set(std::string name, Value* value);
+ Value* get(std::string name);
+ Value* demand(std::string name);
+ const char* getName();
+ bool isRunning();
- private:
+ void lock();
+ void unlock();
+
+ private:
#if JIN_THREAD_SDL
SDL_Thread* handle; // SDL thread
- SDL_mutex* mutex; // mutex variable
- SDL_cond* condition; // condition variable
#elif JIN_THREAD_CPP
std::thread* handle; // cpp thread
- std::mutex* mutex; // mutex
- std::condition_variable condition; // condition
#endif
- ThreadData* paramters; // thread paramters
- ThreadFunc* threadFunc; // thread function
+ Mutex* mutex; // mutex variable
+ Conditional* condition; // condition variable
+ ThreadRunner* threadRunner; // thread function
+ ThreadData* common; // threads common data
std::string name; // thread name
+ bool running;
+
};
} // thread
diff --git a/libjin/Time/Timer.cpp b/libjin/Time/Timer.cpp
index fe72a90..1520828 100644
--- a/libjin/Time/Timer.cpp
+++ b/libjin/Time/Timer.cpp
@@ -1,12 +1,96 @@
#include "../modules.h"
#if JIN_MODULES_TIME
+#include "Timer.h"
+
namespace jin
{
namespace time
{
+ Timers::Timers()
+ : timers()
+ {
+ }
+
+ Timers::~Timers()
+ {
+ for (int i = 0; i < timers.size(); ++i)
+ delete timers[i];
+ }
+
+ void Timers::update(int ms)
+ {
+ std::vector<Timer*>::iterator it = timers.begin();
+ for (; it != timers.end(); ++it)
+ {
+ if (!(*it)->process(ms))
+ {
+ Timer* t = *it;
+ timers.erase(it);
+ delete t;
+ }
+ }
+ }
+
+ void Timers::every(int ms, timer_callback callback, void* p)
+ {
+ Timer* t = new Timer(Timer::EVERY, ms, 0, callback, p);
+ timers.push_back(t);
+ }
+
+ void Timers::after(int ms, timer_callback callback, void* p)
+ {
+ Timer* t = new Timer(Timer::AFTER, ms, 0, callback, p);
+ timers.push_back(t);
+ }
+
+ void Timers::repeat(int ms, int count, timer_callback callback, void* p)
+ {
+ Timer* t = new Timer(Timer::REPEAT, ms, count, callback, p);
+ timers.push_back(t);
+ }
+
+ Timers::Timer::Timer(Type t, int d, int c, timer_callback f, void* p)
+ : type(t)
+ , duration(d)
+ , count(c)
+ , tickdown(0)
+ , countdown(0)
+ , callback(f)
+ , paramters(p)
+ {
+ }
+
+ Timers::Timer::~Timer()
+ {
+ }
+
+ bool Timers::Timer::process(int ms)
+ {
+ tickdown -= ms;
+ if (tickdown <= 0)
+ {
+ tickdown = duration;
+ if (callback != nullptr)
+ callback(paramters);
+ if (type == EVERY)
+ {
+ }
+ else if (type == AFTER)
+ {
+ return false;
+ }
+ else if (type == REPEAT)
+ {
+ --countdown;
+ if (countdown <= 0)
+ return false;
+ }
+ }
+ return true;
+ }
}
}
diff --git a/libjin/Time/Timer.h b/libjin/Time/Timer.h
index 9458215..173cd95 100644
--- a/libjin/Time/Timer.h
+++ b/libjin/Time/Timer.h
@@ -4,31 +4,71 @@
#if JIN_MODULES_TIME
#include "SDL2/SDL.h"
+#include <vector>
namespace jin
{
namespace time
{
+
+ class Timers
+ {
+ public:
+ typedef void(*timer_callback)(void* prameters);
+
+ Timers();
+ ~Timers();
+
+ void update(int ms);
+
+ void every(int ms, timer_callback callback, void* paramters);
+ void after(int ms, timer_callback callback, void* paramters);
+ void repeat(int ms, int count, timer_callback callback, void* paramters);
+ private:
+ class Timer
+ {
+ public:
+ enum Type
+ {
+ EVERY,
+ AFTER,
+ REPEAT,
+ };
+ Timer(Type type, int duration, int count = 0, timer_callback callback = nullptr, void* paramters = nullptr);
+ virtual ~Timer();
+ bool process(int ms);
+ private:
+ int duration;
+ int count;
+ int tickdown;
+ int countdown;
+ Type type;
+ timer_callback callback;
+ void* paramters;
+ };
+ std::vector<Timer*> timers;
+ };
+
inline void sleep(int ms)
{
-#if JIN_TIME_SDL
+ #if JIN_TIME_SDL
SDL_Delay(ms);
-#endif
+ #endif
}
inline double getSecond()
{
-#if JIN_TIME_SDL
+ #if JIN_TIME_SDL
return SDL_GetTicks() / 1000.f;
-#endif
+ #endif
}
inline double getMilliSecond()
{
-#if JIN_TIME_SDL
+ #if JIN_TIME_SDL
return SDL_GetTicks();
-#endif
+ #endif
}
} // time
diff --git a/libjin/modules.h b/libjin/modules.h
index 4ec5e78..06c14df 100644
--- a/libjin/modules.h
+++ b/libjin/modules.h
@@ -39,7 +39,8 @@
#define JIN_MODULES_THREAD 1
#define JIN_THREAD_SDL 1
#define JIN_THREAD_CPP 0
-
+#define JIN_THREAD_PTHREAD 0
+
#define JIN_MODULES_TIME 1
#define JIN_TIME_SDL 1
diff --git a/test/02Audio/audiotest.cpp b/test/02Audio/audiotest.cpp
index d4b8975..4576cfa 100644
--- a/test/02Audio/audiotest.cpp
+++ b/test/02Audio/audiotest.cpp
@@ -13,7 +13,7 @@ void onEvent(jin::input::Event* e)
game->stop();
}
-void onUpdate(float dt)
+void onUpdate(int ms)
{
}
diff --git a/test/03Thread/threadtest.cpp b/test/03Thread/threadtest.cpp
new file mode 100644
index 0000000..d5d75e4
--- /dev/null
+++ b/test/03Thread/threadtest.cpp
@@ -0,0 +1,86 @@
+#include <iostream>
+#include "jin.h"
+
+using namespace std;
+using namespace jin::core;
+using namespace jin::graphics;
+using namespace jin::input;
+using namespace jin::audio;
+using namespace jin::time;
+using namespace jin::thread;
+
+Timers timers;
+
+void onEvent(jin::input::Event* e)
+{
+ static Game* game = Game::get();
+ if (e->type == EventType::QUIT)
+ game->stop();
+}
+
+void onUpdate(int ms)
+{
+ timers.update(ms);
+}
+
+void onDraw()
+{
+
+}
+
+int thread2Runner(void* p)
+{
+ char* s = (char*)p;
+ int i = 0;
+ while (true)
+ {
+ if (i++ == 1000000000)
+ {
+ i = 0;
+ cout << s;
+ }
+ }
+ return 0;
+}
+
+int thread3Runner(void* p)
+{
+
+}
+
+int main(int argc, char* argv[])
+{
+ Game* game = Game::get();
+ Game::Setting setting;
+ setting.eventHandler = onEvent;
+ setting.updater = onUpdate;
+ setting.drawer = onDraw;
+ setting.loader = nullptr;
+ game->init(&setting);
+
+ Window* wnd = Window::get();
+ Window::Setting wndSetting;
+ wndSetting.width = 600;
+ wndSetting.height = 512;
+ wndSetting.title = "test";
+ wndSetting.fps = 60;
+ wndSetting.vsync = false;
+ wndSetting.fullscreen = false;
+ wndSetting.resizable = false;
+ wnd->init(&wndSetting);
+
+ timers.every(1000, [](void* p)-> void{
+ cout << 1;
+ }, nullptr);
+
+ Thread t("Thread 2", thread2Runner);
+ char* str = "_OK";
+ t.start(str);
+
+ game->run();
+
+ game->quit();
+ wnd->quit();
+
+ return 0;
+} \ No newline at end of file