Compare commits
	
		
			16 Commits
		
	
	
		
			escalade_d
			...
			sqc7_serve
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | e685396589 | ||
|  | 15d3864e4a | ||
|  | 47d7fbfc27 | ||
|  | 1a215c823b | ||
|  | 9a0f162f33 | ||
|  | 2bb55e5bf6 | ||
|  | 51b0795c62 | ||
|  | 703b432fb7 | ||
|  | b7ca0253ca | ||
|  | 9aa426b804 | ||
|  | c3058070e5 | ||
|  | cf75843117 | ||
|  | e546de57c9 | ||
|  | 54ae0b087a | ||
|  | 8faa67596e | ||
|  | f8ad857666 | 
							
								
								
									
										154
									
								
								SQCSim-common/SQCSim-common.vcxproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,154 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project DefaultTargets="Build" 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"> | ||||||
|  |     <VCProjectVersion>17.0</VCProjectVersion> | ||||||
|  |     <Keyword>Win32Proj</Keyword> | ||||||
|  |     <ProjectGuid>{ee91ab12-4225-4a4d-931d-69d72f6d91fb}</ProjectGuid> | ||||||
|  |     <RootNamespace>SQCSimcommon</RootNamespace> | ||||||
|  |     <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>StaticLibrary</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>StaticLibrary</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>StaticLibrary</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>StaticLibrary</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</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" /> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |       <LanguageStandard>stdcpp17</LanguageStandard> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClInclude Include="array2d.h" /> | ||||||
|  |     <ClInclude Include="array3d.h" /> | ||||||
|  |     <ClInclude Include="blockinfo.h" /> | ||||||
|  |     <ClInclude Include="bullet.h" /> | ||||||
|  |     <ClInclude Include="chunk.h" /> | ||||||
|  |     <ClInclude Include="define.h" /> | ||||||
|  |     <ClInclude Include="matrix4.h" /> | ||||||
|  |     <ClInclude Include="opensimplex.h" /> | ||||||
|  |     <ClInclude Include="player.h" /> | ||||||
|  |     <ClInclude Include="vector3.h" /> | ||||||
|  |     <ClInclude Include="world.h" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="blockinfo.cpp" /> | ||||||
|  |     <ClCompile Include="bullet.cpp" /> | ||||||
|  |     <ClCompile Include="chunk.cpp" /> | ||||||
|  |     <ClCompile Include="opensimplex.cpp" /> | ||||||
|  |     <ClCompile Include="player.cpp" /> | ||||||
|  |     <ClCompile Include="world.cpp" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||||
|  |   <ImportGroup Label="ExtensionTargets"> | ||||||
|  |   </ImportGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										72
									
								
								SQCSim-common/SQCSim-common.vcxproj.filters
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,72 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Filter Include="Fichiers sources"> | ||||||
|  |       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||||||
|  |       <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Fichiers d%27en-tête"> | ||||||
|  |       <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||||||
|  |       <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Fichiers de ressources"> | ||||||
|  |       <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> | ||||||
|  |     <ClInclude Include="world.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="player.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="opensimplex.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="array2d.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="array3d.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="blockinfo.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="bullet.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="chunk.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="define.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="matrix4.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="vector3.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="world.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="blockinfo.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="bullet.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="chunk.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="opensimplex.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="player.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |   </ItemGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										61
									
								
								SQCSim-common/array2d.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,61 @@ | |||||||
|  | #ifndef ARRAY2D_H__ | ||||||
|  | #define ARRAY2D_H__ | ||||||
|  |  | ||||||
|  | #include "define.h" | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | class Array2d { | ||||||
|  |     public: | ||||||
|  |         Array2d(int x, int y); | ||||||
|  |         ~Array2d(); | ||||||
|  |         Array2d(const Array2d& array); | ||||||
|  |  | ||||||
|  |         void Set(int x, int y, T type); | ||||||
|  |         T Get(int x, int y) const; | ||||||
|  |         T Remove(int x, int y); | ||||||
|  |  | ||||||
|  |         void Reset(T type); | ||||||
|  |  | ||||||
|  |     private: | ||||||
|  |         int m_x, m_y; | ||||||
|  |         T* m_array; | ||||||
|  |  | ||||||
|  |         int To1dIndex(int x, int y) const; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Array2d<T>::Array2d(int x, int y) : m_x(x), m_y(y) { m_array = new T[m_x * m_y]; } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Array2d<T>::~Array2d() { delete[] m_array; } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Array2d<T>::Array2d(const Array2d<T>& array) : m_x(array.m_x), m_y(array.m_y) { | ||||||
|  |     m_array = new T[m_x * m_y]; | ||||||
|  |     for (int i = 0; i < m_x * m_y; ++i) | ||||||
|  |         m_array[i] = array.m_array[i]; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Array2d<T>::Set(int x, int y, T type) { m_array[To1dIndex(x, y)] = type; } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | T Array2d<T>::Get(int x, int y) const { return m_array[To1dIndex(x, y)]; } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | T Array2d<T>::Remove(int x, int y) {  | ||||||
|  |     T thing = std::move(m_array[To1dIndex(x, y)]); | ||||||
|  |     m_array[To1dIndex(x, y)] = nullptr; | ||||||
|  |     return thing; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Array2d<T>::Reset(T type) { | ||||||
|  |     for (int i = 0; i < m_x * m_y; ++i) | ||||||
|  |         m_array[i] = type; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int Array2d<T>::To1dIndex(int x, int y) const { return x + (y * m_x); } | ||||||
|  |  | ||||||
|  | #endif // ARRAY2D_H__ | ||||||
							
								
								
									
										55
									
								
								SQCSim-common/array3d.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,55 @@ | |||||||
|  | #ifndef ARRAY3D_H__ | ||||||
|  | #define ARRAY3D_H__ | ||||||
|  |  | ||||||
|  | #include "define.h" | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | class Array3d { | ||||||
|  |     public: | ||||||
|  |         Array3d(int x, int y, int z); | ||||||
|  |         ~Array3d(); | ||||||
|  |         Array3d(const Array3d& array); | ||||||
|  |  | ||||||
|  |         void Set(int x, int y, int z, T type); | ||||||
|  |         T Get(int x, int y, int z) const; | ||||||
|  |  | ||||||
|  |         void Reset(T type); | ||||||
|  |  | ||||||
|  |     private: | ||||||
|  |         int m_x, m_y, m_z; | ||||||
|  |         T* m_array; | ||||||
|  |  | ||||||
|  |         int To1dIndex(int x, int y, int z) const; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Array3d<T>::Array3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z) { m_array = new T[m_x * m_y * m_z]; } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Array3d<T>::~Array3d() { delete[] m_array; } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Array3d<T>::Array3d(const Array3d<T>& array) : m_x(array.m_x), m_y(array.m_y), m_z(array.m_z) { | ||||||
|  |     m_array = new T[m_x * m_y * m_z]; | ||||||
|  |     for (int i = 0; i < m_x * m_y * m_z; ++i) | ||||||
|  |         m_array[i] = array.m_array[i]; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Array3d<T>::Set(int x, int y, int z, T type) {  | ||||||
|  |     m_array[To1dIndex(x, y, z)] = type;  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | T Array3d<T>::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; } | ||||||
|  |         | ||||||
|  | template <class T> | ||||||
|  | void Array3d<T>::Reset(T type) { | ||||||
|  |     for (int i = 0; i < m_x * m_y * m_z; ++i) | ||||||
|  |         m_array[i] = type; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | int Array3d<T>::To1dIndex(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); } | ||||||
|  |  | ||||||
|  | #endif // ARRAY3D_H__ | ||||||
							
								
								
									
										42
									
								
								SQCSim-common/blockinfo.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,42 @@ | |||||||
|  | #include "blockinfo.h" | ||||||
|  | #include <iostream> | ||||||
|  |  | ||||||
|  | BlockInfo::BlockInfo(BlockType type, const std::string& name, float u, float v, float s, int dur) : m_type(type), m_name(name), m_u(u), m_v(v), m_s(s), m_durability(dur) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BlockInfo::~BlockInfo() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BlockType BlockInfo::GetType() const | ||||||
|  | { | ||||||
|  |     return m_type; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void BlockInfo::SetDurability(int durability) | ||||||
|  | { | ||||||
|  |     m_durability = durability; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int BlockInfo::GetDurability() const | ||||||
|  | { | ||||||
|  |     return m_durability; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void BlockInfo::GetTexture(float& u, float& v, float& s) | ||||||
|  | { | ||||||
|  |     u = m_u; | ||||||
|  |     v = m_v; | ||||||
|  |     s = m_s; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void BlockInfo::Show() const | ||||||
|  | { | ||||||
|  |     std::cout << "Type: " << m_type << std::endl; | ||||||
|  |     std::cout << "Nom: " << m_name << std::endl; | ||||||
|  |     std::cout << "Durabilite: " << m_durability << std::endl; | ||||||
|  |     std::cout << "Coordonnees Texture: " << m_u << ", " << m_v << ", " << m_s << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										32
									
								
								SQCSim-common/blockinfo.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,32 @@ | |||||||
|  | #ifndef BLOCKINFO_H__ | ||||||
|  | #define BLOCKINFO_H__ | ||||||
|  |  | ||||||
|  | #include <string> | ||||||
|  | #include "define.h" | ||||||
|  |  | ||||||
|  | class BlockInfo | ||||||
|  | { | ||||||
|  |     public: | ||||||
|  |     BlockInfo(BlockType type, const std::string& name, float u, float v, float s, int dur); | ||||||
|  |     ~BlockInfo(); | ||||||
|  |  | ||||||
|  |     BlockType GetType() const; | ||||||
|  |  | ||||||
|  |     void SetDurability(int durability); | ||||||
|  |     int GetDurability() const; | ||||||
|  |  | ||||||
|  |     void GetTexture(float& u, float& v, float& s); | ||||||
|  |  | ||||||
|  |     void Show() const; | ||||||
|  |  | ||||||
|  |     private: | ||||||
|  |     BlockType m_type; | ||||||
|  |     float m_u; | ||||||
|  |     float m_v; | ||||||
|  |     float m_s; | ||||||
|  |     std::string m_name; | ||||||
|  |     int m_durability; | ||||||
|  |  | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // BLOCKINFO_H__ | ||||||
							
								
								
									
										32
									
								
								SQCSim-common/bullet.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,32 @@ | |||||||
|  | #include "bullet.h" | ||||||
|  | #include "world.h" | ||||||
|  |  | ||||||
|  | Bullet::Bullet(Player& player) { | ||||||
|  | 	m_startpos = m_currentpos = player.GetPOV() + player.GetDirection(); | ||||||
|  | 	m_velocity = player.GetDirection(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Bullet::~Bullet() {} | ||||||
|  |  | ||||||
|  | bool Bullet::Update(World* world, float elapsedtime) { | ||||||
|  | 	for (int x = 0; x < 1000; ++x) { | ||||||
|  | 		m_currentpos += m_velocity * elapsedtime; | ||||||
|  |  | ||||||
|  | 		if (!world->ChunkAt(m_currentpos)) | ||||||
|  | 			return true; | ||||||
|  | 		else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { | ||||||
|  | 			world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Bullet::Transpose(int& x, int& z) { | ||||||
|  | 	m_currentpos.x -= x * CHUNK_SIZE_X; | ||||||
|  | 	m_currentpos.z -= z * CHUNK_SIZE_Z; | ||||||
|  | 	m_startpos.x -= x * CHUNK_SIZE_X; | ||||||
|  | 	m_startpos.z -= z * CHUNK_SIZE_Z; | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								SQCSim-common/bullet.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,23 @@ | |||||||
|  | #ifndef BULLET_H__ | ||||||
|  | #define BULLET_H__ | ||||||
|  |  | ||||||
|  | #include "player.h" | ||||||
|  |  | ||||||
|  | class World; | ||||||
|  |  | ||||||
|  | class Bullet { | ||||||
|  | public: | ||||||
|  | 	Bullet(Player& player); | ||||||
|  | 	~Bullet(); | ||||||
|  |  | ||||||
|  | 	bool Update(World* world, float elapsedtime); | ||||||
|  | 	void Transpose(int& x, int& z); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	Vector3f m_startpos; | ||||||
|  | 	Vector3f m_currentpos; | ||||||
|  | 	Vector3f m_velocity; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // BULLET_H__ | ||||||
|  |  | ||||||
							
								
								
									
										111
									
								
								SQCSim-common/chunk.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,111 @@ | |||||||
|  | #include "chunk.h" | ||||||
|  | #include "world.h" | ||||||
|  |  | ||||||
|  | Chunk::Chunk(unsigned int x, unsigned int y) : m_posX(x), m_posY(y) {  | ||||||
|  |     //std::ostringstream pos; // V<>rifie l'existence d'un fichier .chunk avec sa position. | ||||||
|  |     //pos << CHUNK_PATH << x << '_' << y << ".chunk"; | ||||||
|  |     //std::ifstream input(pos.str(), std::fstream::binary); | ||||||
|  |  | ||||||
|  |     //if (input.fail()) { | ||||||
|  |         OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(SEED); | ||||||
|  |         m_blocks.Reset(BTYPE_AIR); | ||||||
|  |  | ||||||
|  |         for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes | ||||||
|  |             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|  |                 float xnoiz, ynoiz; | ||||||
|  |                 xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 4096.; | ||||||
|  |                 ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 4096.; | ||||||
|  |                 double height = 0; | ||||||
|  |                 for (int x = 0; x < 39; ++x) { | ||||||
|  |                     height += simplex.eval(xnoiz, ynoiz); | ||||||
|  |                     height *= .79; | ||||||
|  |                     xnoiz *= 1.139; | ||||||
|  |                     ynoiz *= 1.139; | ||||||
|  |                 } | ||||||
|  |                 height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.); | ||||||
|  |                 height /= (CHUNK_SIZE_Y / 1.9); | ||||||
|  |                 height += 15.; | ||||||
|  |                 for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) | ||||||
|  |                     SetBlock(ix, iy, iz, BTYPE_METAL, nullptr); | ||||||
|  |             } | ||||||
|  |         for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Collines | ||||||
|  |             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|  |                 float xnoiz, ynoiz; | ||||||
|  |                 xnoiz = (double)(ix + x * CHUNK_SIZE_X) / 512.; | ||||||
|  |                 ynoiz = (double)(iz + y * CHUNK_SIZE_Z) / 512.; | ||||||
|  |                 float height = simplex.eval(xnoiz, ynoiz) * 50.f;// +1.f; | ||||||
|  |                 for (int iy = 0; iy <= (int)height % CHUNK_SIZE_Y; ++iy) { | ||||||
|  |                     if (GetBlock(ix, iy, iz) == BTYPE_AIR) | ||||||
|  |                         SetBlock(ix, iy, iz, BTYPE_GRASS, nullptr); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Lacs" | ||||||
|  |             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|  |                 for (int iy = 0; iy < 13; ++iy) { | ||||||
|  |                     if (GetBlock(ix, iy, iz) == BTYPE_AIR) | ||||||
|  |                         SetBlock(ix, iy, iz, BTYPE_ICE, nullptr); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         //for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // "Arbres" | ||||||
|  |         //    for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { | ||||||
|  |         //        float xnoiz, ynoiz; | ||||||
|  |         //        xnoiz = (double)(iz * CHUNK_SIZE_Y + x * CHUNK_SIZE_X) / 256.; | ||||||
|  |         //        ynoiz = (double)(ix * CHUNK_SIZE_Y + y * CHUNK_SIZE_Z) / 256.; | ||||||
|  |         //        bool tree = (int)(abs(simplex.eval(xnoiz, ynoiz)) * 17933.f) % CHUNK_SIZE_Y > 126 ? true : false; | ||||||
|  |         //        for (int iy = 0; iy < CHUNK_SIZE_Y - 10; ++iy) | ||||||
|  |         //            if (GetBlock(ix, iy, iz) == BTYPE_AIR) | ||||||
|  |         //                if (GetBlock(ix, iy - 1, iz) == BTYPE_GRASS) | ||||||
|  |         //                    if (tree) { | ||||||
|  |         //                        for (int i = 0; i < (int)(abs(simplex.eval(xnoiz, ynoiz) * 4)) % 42 + 1; ++i) | ||||||
|  |         //                            SetBlock(ix, iy + i, iz, BTYPE_DIRT, nullptr); | ||||||
|  |         //                        break; | ||||||
|  |         //                    } | ||||||
|  |         //    } | ||||||
|  |     /* } | ||||||
|  |     else { | ||||||
|  |         input.seekg(0, std::ios_base::end); | ||||||
|  |         int size = input.tellg(); | ||||||
|  |         input.seekg(0, std::ios_base::beg); | ||||||
|  |  | ||||||
|  |         char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; | ||||||
|  |         input.read(data, size); | ||||||
|  |         input.close(); | ||||||
|  |  | ||||||
|  |         for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) | ||||||
|  |             for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) | ||||||
|  |                 for (int iy = 0; iy < CHUNK_SIZE_Y; ++iy) | ||||||
|  |                     m_blocks.Set(ix, iy, iz, data[ix + (iz * CHUNK_SIZE_X) + (iy * CHUNK_SIZE_Z * CHUNK_SIZE_X)]); | ||||||
|  |     }*/ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Chunk::~Chunk() { | ||||||
|  |     /*if (m_isModified) { | ||||||
|  |         char data[CHUNK_SIZE_X * CHUNK_SIZE_Y * CHUNK_SIZE_Z]; | ||||||
|  |  | ||||||
|  |         for (int x = 0; x < CHUNK_SIZE_X; ++x) | ||||||
|  |             for (int z = 0; z < CHUNK_SIZE_Z; ++z) | ||||||
|  |                 for (int y = 0; y < CHUNK_SIZE_Y; ++y) | ||||||
|  |                     data[x + (z * CHUNK_SIZE_X) + (y * CHUNK_SIZE_Z * CHUNK_SIZE_X)] = (char)GetBlock(x, y, z); | ||||||
|  |  | ||||||
|  |         std::ostringstream pos; | ||||||
|  |         pos << CHUNK_PATH << m_posX << '_' << m_posY << ".chunk"; | ||||||
|  |  | ||||||
|  |         std::ofstream output(pos.str(), std::fstream::binary); | ||||||
|  |         output.write(data, sizeof(data)); | ||||||
|  |         output.close(); | ||||||
|  |     }*/ | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Chunk::RemoveBlock(int x, int y, int z, World* world) { | ||||||
|  |     m_blocks.Set(x, y, z, BTYPE_AIR); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Chunk::SetBlock(int x, int y, int z, BlockType type, World* world) { | ||||||
|  |     m_blocks.Set(x, y, z, type); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BlockType Chunk::GetBlock(int x, int y, int z) { return m_blocks.Get(x, y, z); } | ||||||
|  |  | ||||||
|  | void Chunk::GetPosition(unsigned int& x, unsigned int& y) const { x = m_posX; y = m_posY; } | ||||||
|  |  | ||||||
|  | void Chunk::MakeModified() { m_isModified = true; } | ||||||
							
								
								
									
										31
									
								
								SQCSim-common/chunk.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,31 @@ | |||||||
|  | #ifndef CHUNK_H__ | ||||||
|  | #define CHUNK_H__ | ||||||
|  | #include "define.h" | ||||||
|  | #include "array3d.h" | ||||||
|  | #include "array2d.h" | ||||||
|  | #include "blockinfo.h" | ||||||
|  | #include "opensimplex.h" | ||||||
|  |  | ||||||
|  | class World; | ||||||
|  |  | ||||||
|  | class Chunk { | ||||||
|  |     protected: | ||||||
|  |         Array3d<BlockType> m_blocks = Array3d<BlockType>(CHUNK_SIZE_X, CHUNK_SIZE_Y, CHUNK_SIZE_Z); | ||||||
|  |         bool m_isModified = false; | ||||||
|  |  | ||||||
|  |         unsigned int m_posX; // Position du chunk dans l'array constituant le monde. | ||||||
|  |         unsigned int m_posY; | ||||||
|  |  | ||||||
|  |     public: | ||||||
|  |         Chunk(unsigned int x, unsigned int y); | ||||||
|  |         ~Chunk(); | ||||||
|  |  | ||||||
|  |         void RemoveBlock(int x, int y, int z, World* world); | ||||||
|  |         void SetBlock(int x, int y, int z, BlockType type, World* world); | ||||||
|  |         BlockType GetBlock(int x, int y, int z); | ||||||
|  |         void GetPosition(unsigned int& x, unsigned int& y) const; | ||||||
|  |  | ||||||
|  |         void MakeModified(); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // CHUNK_H__ | ||||||
							
								
								
									
										52
									
								
								SQCSim-common/define.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,52 @@ | |||||||
|  | #ifndef DEFINE_H__ | ||||||
|  | #define DEFINE_H__ | ||||||
|  |  | ||||||
|  | #include <iostream> | ||||||
|  |  | ||||||
|  | #define CHUNK_SIZE_X  16 | ||||||
|  | #define CHUNK_SIZE_Y  128 | ||||||
|  | #define CHUNK_SIZE_Z  16 | ||||||
|  | #define MAX_SELECTION_DISTANCE 5 | ||||||
|  | #define SEED 12345 | ||||||
|  |  | ||||||
|  | #define SRV_PORT 1025 | ||||||
|  | #define CLI_PORT 1026 | ||||||
|  |  | ||||||
|  | #ifdef _DEBUG | ||||||
|  | #define WORLD_SIZE_X 64 | ||||||
|  | #define WORLD_SIZE_Y 64 | ||||||
|  |  | ||||||
|  | #define FRAMES_RENDER_CHUNKS 4 | ||||||
|  | #define FRAMES_UPDATE_CHUNKS 4 | ||||||
|  | #define FRAMES_DELETE_CHUNKS 4 | ||||||
|  |  | ||||||
|  | #define THREADS_GENERATE_CHUNKS 1 | ||||||
|  | #define THREADS_UPDATE_CHUNKS 1 | ||||||
|  | #define THREADS_DELETE_CHUNKS 1 | ||||||
|  |  | ||||||
|  | #define VIEW_DISTANCE 256 | ||||||
|  | #define TEXTURE_SIZE 128 | ||||||
|  | #define MAX_BULLETS 64 | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #ifdef NDEBUG | ||||||
|  | #define WORLD_SIZE_X 16 | ||||||
|  | #define WORLD_SIZE_Y 16 | ||||||
|  |  | ||||||
|  | #define FRAMES_RENDER_CHUNKS 1 | ||||||
|  | #define FRAMES_UPDATE_CHUNKS 1 | ||||||
|  | #define FRAMES_DELETE_CHUNKS 1 | ||||||
|  |  | ||||||
|  | #define THREADS_GENERATE_CHUNKS 12 | ||||||
|  | #define THREADS_UPDATE_CHUNKS 5 | ||||||
|  | #define THREADS_DELETE_CHUNKS 2 | ||||||
|  |  | ||||||
|  | #define VIEW_DISTANCE 1024 | ||||||
|  | #define TEXTURE_SIZE 512 | ||||||
|  | #define MAX_BULLETS 512 | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | typedef uint8_t BlockType; | ||||||
|  | enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; | ||||||
|  |  | ||||||
|  | #endif // DEFINE_H__ | ||||||
							
								
								
									
										571
									
								
								SQCSim-common/matrix4.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,571 @@ | |||||||
|  | #ifndef MATRIX4_H__ | ||||||
|  | #define MATRIX4_H__ | ||||||
|  |  | ||||||
|  | #include <ostream> | ||||||
|  | #include <sstream> | ||||||
|  | #include <string> | ||||||
|  |  | ||||||
|  | #include "define.h" | ||||||
|  | #include "vector3.h" | ||||||
|  |  | ||||||
|  | #ifndef M_PI | ||||||
|  | #define M_PI 3.14159265f | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #define DEGTORAD(x) ((x * M_PI) / 180.f) | ||||||
|  | #define RADTODEG(x) ((180.f * x) / M_PI) | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | class Matrix4 | ||||||
|  | { | ||||||
|  |     public: | ||||||
|  |         typedef T Type; | ||||||
|  |  | ||||||
|  |     public: | ||||||
|  |         static const Matrix4<T> ZERO; | ||||||
|  |         static const Matrix4<T> IDENTITY; | ||||||
|  |  | ||||||
|  |     public: | ||||||
|  |         Matrix4(); | ||||||
|  |         Matrix4(const T& v); | ||||||
|  |         Matrix4(const Matrix4<T>& m); | ||||||
|  |         Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14, | ||||||
|  |                 const T& m_21, const T& m_22, const T& m_23, const T& m_24, | ||||||
|  |                 const T& m_31, const T& m_32, const T& m_33, const T& m_34, | ||||||
|  |                 const T& m_41, const T& m_42, const T& m_43, const T& m_44); | ||||||
|  |  | ||||||
|  |         const T& Get11() const; | ||||||
|  |         const T& Get12() const; | ||||||
|  |         const T& Get13() const; | ||||||
|  |         const T& Get14() const; | ||||||
|  |         const T& Get21() const; | ||||||
|  |         const T& Get22() const; | ||||||
|  |         const T& Get23() const; | ||||||
|  |         const T& Get24() const; | ||||||
|  |         const T& Get31() const; | ||||||
|  |         const T& Get32() const; | ||||||
|  |         const T& Get33() const; | ||||||
|  |         const T& Get34() const; | ||||||
|  |         const T& Get41() const; | ||||||
|  |         const T& Get42() const; | ||||||
|  |         const T& Get43() const; | ||||||
|  |         const T& Get44() const; | ||||||
|  |  | ||||||
|  |         Matrix4<T>& operator=(const Matrix4<T>& m); | ||||||
|  |  | ||||||
|  |         Matrix4<T> operator+(const Matrix4<T>& m) const; | ||||||
|  |         const Matrix4<T>& operator+=(const Matrix4<T>& m); | ||||||
|  |  | ||||||
|  |         Matrix4<T> operator-(const Matrix4<T>& m) const; | ||||||
|  |         Matrix4<T> operator-() const; | ||||||
|  |         const Matrix4<T>& operator-=(const Matrix4<T>& m); | ||||||
|  |  | ||||||
|  |         Matrix4<T> operator*(const Matrix4<T>& m) const; | ||||||
|  |         Matrix4<T> operator*(const T& v) const; | ||||||
|  |         const Matrix4<T>& operator*=(const Matrix4<T>& m); | ||||||
|  |         const Matrix4<T>& operator*=(const T& v); | ||||||
|  |  | ||||||
|  |         Matrix4<T> operator/(const T& v) const; | ||||||
|  |         const Matrix4<T>& operator/=(const T& v); | ||||||
|  |  | ||||||
|  |         bool operator==(const Matrix4<T>& m) const; | ||||||
|  |         bool operator!=(const Matrix4<T>& m) const; | ||||||
|  |  | ||||||
|  |         void SetZero(); | ||||||
|  |         void SetIdentity(); | ||||||
|  |         void SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane); | ||||||
|  |         void SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane); | ||||||
|  |  | ||||||
|  |         void SetLookAt(const Vector3<T>& eyePosition, const Vector3<T>& lookAtPosition, Vector3<T> upVector = Vector3<T>(T(0), T(1), T(0))); | ||||||
|  |  | ||||||
|  |         bool IsZero() const; | ||||||
|  |         bool IsIdentity() const; | ||||||
|  |  | ||||||
|  |         void ApplyTranslation(const T& x, const T& y, const T& z); | ||||||
|  |         void ApplyRotation(const T& angle, const T& x, const T& y, const T& z); | ||||||
|  |         void ApplyScale(const T& x, const T& y, const T& z); | ||||||
|  |  | ||||||
|  |         Vector3<T> GetTranslation() const; | ||||||
|  |  | ||||||
|  |         const T* GetInternalValues() const; | ||||||
|  |         T* GetInternalValues(); | ||||||
|  |         std::string ToString(const std::string& lineBegin = "|", const std::string& lineEnd = "|\n") const; | ||||||
|  |  | ||||||
|  |     private: | ||||||
|  |         union { | ||||||
|  |             // column-major matrix | ||||||
|  |             struct | ||||||
|  |             { | ||||||
|  |                 T m_11, m_21, m_31, m_41, m_12, m_22, m_32, m_42, m_13, m_23, m_33, m_43, m_14, m_24, m_34, m_44; | ||||||
|  |             }; | ||||||
|  |             T m_values[16]; | ||||||
|  |         }; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef Matrix4<int> Matrix4i; | ||||||
|  | typedef Matrix4<float> Matrix4f; | ||||||
|  | typedef Matrix4<double> Matrix4d; | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const Matrix4<T> Matrix4<T>::ZERO = Matrix4<T>(0); | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const Matrix4<T> Matrix4<T>::IDENTITY = Matrix4<T>( | ||||||
|  |         1, 0, 0, 0, | ||||||
|  |         0, 1, 0, 0, | ||||||
|  |         0, 0, 1, 0, | ||||||
|  |         0, 0, 0, 1); | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | std::ostream& operator<<(std::ostream& out, const Matrix4<T>& m) | ||||||
|  | { | ||||||
|  |     out << m.ToString(); | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | Matrix4<T>::Matrix4() | ||||||
|  | { | ||||||
|  |     // Leave matrix uninitialized | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | Matrix4<T>::Matrix4(const T& v) | ||||||
|  | { | ||||||
|  |     for(int i = 0; i < 16; ++i) | ||||||
|  |         m_values[i] = v; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | Matrix4<T>::Matrix4(const Matrix4<T>& m) | ||||||
|  | { | ||||||
|  |     for(int i = 0; i < 16; ++i) | ||||||
|  |         m_values[i] = m.m_values[i]; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | Matrix4<T>::Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14, | ||||||
|  |         const T& m_21, const T& m_22, const T& m_23, const T& m_24, | ||||||
|  |         const T& m_31, const T& m_32, const T& m_33, const T& m_34, | ||||||
|  |         const T& m_41, const T& m_42, const T& m_43, const T& m_44) | ||||||
|  | { | ||||||
|  |     this->m_11 = m_11; | ||||||
|  |     this->m_12 = m_12; | ||||||
|  |     this->m_13 = m_13; | ||||||
|  |     this->m_14 = m_14; | ||||||
|  |     this->m_21 = m_21; | ||||||
|  |     this->m_22 = m_22; | ||||||
|  |     this->m_23 = m_23; | ||||||
|  |     this->m_24 = m_24; | ||||||
|  |     this->m_31 = m_31; | ||||||
|  |     this->m_32 = m_32; | ||||||
|  |     this->m_33 = m_33; | ||||||
|  |     this->m_34 = m_34; | ||||||
|  |     this->m_41 = m_41; | ||||||
|  |     this->m_42 = m_42; | ||||||
|  |     this->m_43 = m_43; | ||||||
|  |     this->m_44 = m_44; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get11() const | ||||||
|  | { | ||||||
|  |     return m_11; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get12() const | ||||||
|  | { | ||||||
|  |     return m_12; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get13() const | ||||||
|  | { | ||||||
|  |     return m_13; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get14() const | ||||||
|  | { | ||||||
|  |     return m_14; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get21() const | ||||||
|  | { | ||||||
|  |     return m_21; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get22() const | ||||||
|  | { | ||||||
|  |     return m_22; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get23() const | ||||||
|  | { | ||||||
|  |     return m_23; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get24() const | ||||||
|  | { | ||||||
|  |     return m_24; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get31() const | ||||||
|  | { | ||||||
|  |     return m_31; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get32() const | ||||||
|  | { | ||||||
|  |     return m_32; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get33() const | ||||||
|  | { | ||||||
|  |     return m_33; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get34() const | ||||||
|  | { | ||||||
|  |     return m_34; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get41() const | ||||||
|  | { | ||||||
|  |     return m_41; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get42() const | ||||||
|  | { | ||||||
|  |     return m_42; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get43() const | ||||||
|  | { | ||||||
|  |     return m_43; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T& Matrix4<T>::Get44() const | ||||||
|  | { | ||||||
|  |     return m_44; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | Matrix4<T>& Matrix4<T>::operator=(const Matrix4<T>& m) | ||||||
|  | { | ||||||
|  |     if(this != &m) | ||||||
|  |     { | ||||||
|  |         for(int i = 0; i < 16; ++i) | ||||||
|  |             m_values[i] = m.m_values[i]; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Matrix4<T> Matrix4<T>::operator+(const Matrix4<T>& m) const | ||||||
|  | { | ||||||
|  |     return Matrix4<T>( | ||||||
|  |             m_11 + m.m_11, m_12 + m.m_12, m_13 + m.m_13, m_14 + m.m_14, | ||||||
|  |             m_21 + m.m_21, m_22 + m.m_22, m_23 + m.m_23, m_24 + m.m_24, | ||||||
|  |             m_31 + m.m_31, m_32 + m.m_32, m_33 + m.m_33, m_34 + m.m_34, | ||||||
|  |             m_41 + m.m_41, m_42 + m.m_42, m_43 + m.m_43, m_44 + m.m_44); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | const Matrix4<T>& Matrix4<T>::operator+=(const Matrix4<T>& m) | ||||||
|  | { | ||||||
|  |     *this = *this + m; | ||||||
|  |     return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Matrix4<T> Matrix4<T>::operator-(const Matrix4<T>& m) const | ||||||
|  | { | ||||||
|  |     return Matrix4<T>( | ||||||
|  |             m_11 - m.m_11, m_12 - m.m_12, m_13 - m.m_13, m_14 - m.m_14, | ||||||
|  |             m_21 - m.m_21, m_22 - m.m_22, m_23 - m.m_23, m_24 - m.m_24, | ||||||
|  |             m_31 - m.m_31, m_32 - m.m_32, m_33 - m.m_33, m_34 - m.m_34, | ||||||
|  |             m_41 - m.m_41, m_42 - m.m_42, m_43 - m.m_43, m_44 - m.m_44); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Matrix4<T> Matrix4<T>::operator-() const | ||||||
|  | { | ||||||
|  |     return Matrix4<T>( | ||||||
|  |             -m_11, -m_12, -m_13, -m_14, | ||||||
|  |             -m_21, -m_22, -m_23, -m_24, | ||||||
|  |             -m_31, -m_32, -m_33, -m_34, | ||||||
|  |             -m_41, -m_42, -m_43, -m_44); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | const Matrix4<T>& Matrix4<T>::operator-=(const Matrix4<T>& m) | ||||||
|  | { | ||||||
|  |     *this = *this - m; | ||||||
|  |     return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Matrix4<T> Matrix4<T>::operator*(const Matrix4<T>& m) const | ||||||
|  | { | ||||||
|  |     return Matrix4<T>( | ||||||
|  |             m_11 * m.m_11 + m_12 * m.m_21 + m_13 * m.m_31 + m_14 * m.m_41, | ||||||
|  |             m_11 * m.m_12 + m_12 * m.m_22 + m_13 * m.m_32 + m_14 * m.m_42, | ||||||
|  |             m_11 * m.m_13 + m_12 * m.m_23 + m_13 * m.m_33 + m_14 * m.m_43, | ||||||
|  |             m_11 * m.m_14 + m_12 * m.m_24 + m_13 * m.m_34 + m_14 * m.m_44, | ||||||
|  |  | ||||||
|  |             m_21 * m.m_11 + m_22 * m.m_21 + m_23 * m.m_31 + m_24 * m.m_41, | ||||||
|  |             m_21 * m.m_12 + m_22 * m.m_22 + m_23 * m.m_32 + m_24 * m.m_42, | ||||||
|  |             m_21 * m.m_13 + m_22 * m.m_23 + m_23 * m.m_33 + m_24 * m.m_43, | ||||||
|  |             m_21 * m.m_14 + m_22 * m.m_24 + m_23 * m.m_34 + m_24 * m.m_44, | ||||||
|  |  | ||||||
|  |             m_31 * m.m_11 + m_32 * m.m_21 + m_33 * m.m_31 + m_34 * m.m_41, | ||||||
|  |             m_31 * m.m_12 + m_32 * m.m_22 + m_33 * m.m_32 + m_34 * m.m_42, | ||||||
|  |             m_31 * m.m_13 + m_32 * m.m_23 + m_33 * m.m_33 + m_34 * m.m_43, | ||||||
|  |             m_31 * m.m_14 + m_32 * m.m_24 + m_33 * m.m_34 + m_34 * m.m_44, | ||||||
|  |  | ||||||
|  |             m_41 * m.m_11 + m_42 * m.m_21 + m_43 * m.m_31 + m_44 * m.m_41, | ||||||
|  |             m_41 * m.m_12 + m_42 * m.m_22 + m_43 * m.m_32 + m_44 * m.m_42, | ||||||
|  |             m_41 * m.m_13 + m_42 * m.m_23 + m_43 * m.m_33 + m_44 * m.m_43, | ||||||
|  |             m_41 * m.m_14 + m_42 * m.m_24 + m_43 * m.m_34 + m_44 * m.m_44); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Matrix4<T> Matrix4<T>::operator*(const T& v) const | ||||||
|  | { | ||||||
|  |     return Matrix4<T>( | ||||||
|  |             m_11 * v, m_12 * v, m_13 * v, m_14 * v, | ||||||
|  |             m_21 * v, m_22 * v, m_23 * v, m_24 * v, | ||||||
|  |             m_31 * v, m_32 * v, m_33 * v, m_34 * v, | ||||||
|  |             m_41 * v, m_42 * v, m_43 * v, m_44 * v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | const Matrix4<T>& Matrix4<T>::operator*=(const Matrix4<T>& m) | ||||||
|  | { | ||||||
|  |     *this = *this * m; | ||||||
|  |     return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | const Matrix4<T>& Matrix4<T>::operator*=(const T& v) | ||||||
|  | { | ||||||
|  |     *this = *this * v; | ||||||
|  |     return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Matrix4<T> Matrix4<T>::operator/(const T& v) const | ||||||
|  | { | ||||||
|  |     return Matrix4<T>( | ||||||
|  |             m_11 / v, m_12 / v, m_13 / v, m_14 / v, | ||||||
|  |             m_21 / v, m_22 / v, m_23 / v, m_24 / v, | ||||||
|  |             m_31 / v, m_32 / v, m_33 / v, m_34 / v, | ||||||
|  |             m_41 / v, m_42 / v, m_43 / v, m_44 / v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | const Matrix4<T>& Matrix4<T>::operator/=(const T& v) | ||||||
|  | { | ||||||
|  |     *this = *this / v; | ||||||
|  |     return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | bool Matrix4<T>::operator==(const Matrix4<T>& m) const | ||||||
|  | { | ||||||
|  |     for(int i = 0; i < 16; ++i) | ||||||
|  |         if(m_values[i] != m.m_values[i]) | ||||||
|  |             return false; | ||||||
|  |  | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | bool Matrix4<T>::operator!=(const Matrix4<T>& m) const | ||||||
|  | { | ||||||
|  |     return !(*this == m); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::SetZero() | ||||||
|  | { | ||||||
|  |     *this = ZERO; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::SetIdentity() | ||||||
|  | { | ||||||
|  |     *this = IDENTITY; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane) | ||||||
|  | { | ||||||
|  |     const float h = T(1) / tan(fov * T(M_PI / 360.f)); | ||||||
|  |     T negDepth = nearPlane - farPlane; | ||||||
|  |  | ||||||
|  |     SetZero(); | ||||||
|  |  | ||||||
|  |     m_11 = h / aspect; | ||||||
|  |     m_22 = h; | ||||||
|  |     m_33 = (farPlane + nearPlane) / negDepth; | ||||||
|  |     m_34 = T(2) * (nearPlane * farPlane) / negDepth; | ||||||
|  |     m_43 = -T(1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane) | ||||||
|  | { | ||||||
|  |     m_11 = T(2) / (right - left); | ||||||
|  |     m_12 = T(0); | ||||||
|  |     m_13 = T(0); | ||||||
|  |     m_14 = -(right + left) / (right - left); | ||||||
|  |  | ||||||
|  |     m_21 = T(0); | ||||||
|  |     m_22 = T(2) / (top - bottom); | ||||||
|  |     m_23 = T(0); | ||||||
|  |     m_24 = -(top + bottom) / (top - bottom); | ||||||
|  |  | ||||||
|  |     m_31 = T(0); | ||||||
|  |     m_32 = T(0); | ||||||
|  |     m_33 = -T(2) / (farPlane - nearPlane); | ||||||
|  |     m_34 = -(farPlane + nearPlane) / (farPlane - nearPlane); | ||||||
|  |  | ||||||
|  |     m_41 = T(0); | ||||||
|  |     m_42 = T(0); | ||||||
|  |     m_43 = T(0); | ||||||
|  |     m_44 = T(1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::SetLookAt(const Vector3<T>& eyePosition, const Vector3<T>& lookAtPosition, Vector3<T> upVector) | ||||||
|  | { | ||||||
|  |     Vector3f L = lookAtPosition - eyePosition; | ||||||
|  |     L.Normalize(); | ||||||
|  |  | ||||||
|  |     upVector.Normalize(); | ||||||
|  |     Vector3f S = L.Cross(upVector); | ||||||
|  |     S.Normalize(); | ||||||
|  |  | ||||||
|  |     Vector3f U = S.Cross(L); | ||||||
|  |  | ||||||
|  |     Matrix4<T> M; | ||||||
|  |     M.m_11 = S.x; | ||||||
|  |     M.m_12 = S.y; | ||||||
|  |     M.m_13 = S.z; | ||||||
|  |     M.m_14 = 0; | ||||||
|  |  | ||||||
|  |     M.m_21 = U.x; | ||||||
|  |     M.m_22 = U.y; | ||||||
|  |     M.m_23 = U.z; | ||||||
|  |     M.m_24 = 0; | ||||||
|  |  | ||||||
|  |     M.m_31 = -L.x; | ||||||
|  |     M.m_32 = -L.y; | ||||||
|  |     M.m_33 = -L.z; | ||||||
|  |     M.m_34 = 0; | ||||||
|  |  | ||||||
|  |     M.m_41 = 0; | ||||||
|  |     M.m_42 = 0; | ||||||
|  |     M.m_43 = 0; | ||||||
|  |     M.m_44 = 1.f; | ||||||
|  |  | ||||||
|  |     SetIdentity(); | ||||||
|  |     *this *= M; | ||||||
|  |     ApplyTranslation(-eyePosition.x, -eyePosition.y, -eyePosition.z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::ApplyTranslation(const T& x, const T& y, const T& z) | ||||||
|  | { | ||||||
|  |     Matrix4<T> tmp( | ||||||
|  |             1, 0, 0, x, | ||||||
|  |             0, 1, 0, y, | ||||||
|  |             0, 0, 1, z, | ||||||
|  |             0, 0, 0, 1); | ||||||
|  |  | ||||||
|  |     *this *= tmp; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::ApplyRotation(const T& angle, const T& x, const T& y, const T& z) | ||||||
|  | { | ||||||
|  |     // TODO axis (x, y, z) must be normalized... | ||||||
|  |  | ||||||
|  |     T s = sin(DEGTORAD(angle)); | ||||||
|  |     T c = cos(DEGTORAD(angle)); | ||||||
|  |     T ic = T(1) - c; | ||||||
|  |  | ||||||
|  |     Matrix4<T> tmp( | ||||||
|  |             x * x * ic + c, y * x * ic + (z * s), z * x * ic - (y * s), 0, | ||||||
|  |             x * y * ic - (z * s), y * y * ic + c, z * y * ic + (x * s), 0, | ||||||
|  |             x * z * ic + (y * s), y * z * ic - (x * s), z * z * ic + c, 0, | ||||||
|  |             0, 0, 0, 1); | ||||||
|  |  | ||||||
|  |     *this *= tmp; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | void Matrix4<T>::ApplyScale(const T& x, const T& y, const T& z) | ||||||
|  | { | ||||||
|  |     Matrix4<T> tmp( | ||||||
|  |             x, 0, 0, 0, | ||||||
|  |             0, y, 0, 0, | ||||||
|  |             0, 0, z, 0, | ||||||
|  |             0, 0, 0, 1); | ||||||
|  |  | ||||||
|  |     *this *= tmp; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Matrix4<T>::GetTranslation() const | ||||||
|  | { | ||||||
|  |     // NOTE: Works only if the matrix doesn't contains scale information (only rotation and translation) | ||||||
|  |     // Reference: http://www.gamedev.net/topic/397751-how-to-get-camera-position/ | ||||||
|  |     T x = -(m_11 * m_14 + m_21 * m_24 + m_31 * m_34); | ||||||
|  |     T y = -(m_12 * m_14 + m_22 * m_24 + m_32 * m_34); | ||||||
|  |     T z = -(m_13 * m_14 + m_23 * m_24 + m_33 * m_34); | ||||||
|  |  | ||||||
|  |     return Vector3<T>(x, y, z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |     template <class T> | ||||||
|  | T* Matrix4<T>::GetInternalValues() | ||||||
|  | { | ||||||
|  |     return m_values; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | const T* Matrix4<T>::GetInternalValues() const | ||||||
|  | { | ||||||
|  |     return m_values; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | std::string Matrix4<T>::ToString(const std::string& lineBegin, const std::string& lineEnd) const | ||||||
|  | { | ||||||
|  |     std::ostringstream ss; | ||||||
|  |     ss << lineBegin << m_11 << " " << m_12 << " " << m_13 << " " << m_14 << lineEnd; | ||||||
|  |     ss << lineBegin << m_21 << " " << m_22 << " " << m_23 << " " << m_24 << lineEnd; | ||||||
|  |     ss << lineBegin << m_31 << " " << m_32 << " " << m_33 << " " << m_34 << lineEnd; | ||||||
|  |     ss << lineBegin << m_41 << " " << m_42 << " " << m_43 << " " << m_44 << lineEnd; | ||||||
|  |  | ||||||
|  |     return ss.str(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif // MATRIX4_H__ | ||||||
							
								
								
									
										2542
									
								
								SQCSim-common/opensimplex.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										51
									
								
								SQCSim-common/opensimplex.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,51 @@ | |||||||
|  | /** | ||||||
|  |   Open Simple Noise for C++ | ||||||
|  |  | ||||||
|  |   Port to C++ from https://gist.github.com/KdotJPG/b1270127455a94ac5d19 | ||||||
|  |   by Rickard Lundberg, 2019. | ||||||
|  | */ | ||||||
|  | #ifndef _OPENSIMPLEX_H__ | ||||||
|  | #define _OPENSIMPLEX_H__ | ||||||
|  |  | ||||||
|  | #include <cstdint> | ||||||
|  | #include <array> | ||||||
|  |  | ||||||
|  | namespace OpenSimplexNoise | ||||||
|  | { | ||||||
|  |   class Noise | ||||||
|  |   { | ||||||
|  |   public: | ||||||
|  |     Noise(); | ||||||
|  |     Noise(int64_t seed); | ||||||
|  |     //2D Open Simplex Noise. | ||||||
|  |     double eval(const double x, const double y) const; | ||||||
|  |     //3D Open Simplex Noise. | ||||||
|  |     double eval(double x, double y, double z) const; | ||||||
|  |     //4D Open Simplex Noise. | ||||||
|  |     double eval(double x, double y, double z, double w) const; | ||||||
|  |   private: | ||||||
|  |     const double m_stretch2d; | ||||||
|  |     const double m_squish2d; | ||||||
|  |     const double m_stretch3d; | ||||||
|  |     const double m_squish3d; | ||||||
|  |     const double m_stretch4d; | ||||||
|  |     const double m_squish4d; | ||||||
|  |  | ||||||
|  |     const double m_norm2d; | ||||||
|  |     const double m_norm3d; | ||||||
|  |     const double m_norm4d; | ||||||
|  |  | ||||||
|  |     const long m_defaultSeed; | ||||||
|  |  | ||||||
|  |     std::array<short, 256> m_perm; | ||||||
|  |     std::array<short, 256> m_permGradIndex3d; | ||||||
|  |     std::array<char, 16> m_gradients2d; | ||||||
|  |     std::array<char, 72> m_gradients3d; | ||||||
|  |     std::array<char, 256> m_gradients4d; | ||||||
|  |     double extrapolate(int xsb, int ysb, double dx, double dy) const; | ||||||
|  |     double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) const; | ||||||
|  |     double extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw) const; | ||||||
|  |   }; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif // _OPENSIMPLEX_H__ | ||||||
							
								
								
									
										176
									
								
								SQCSim-common/player.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,176 @@ | |||||||
|  | #include "player.h" | ||||||
|  | #include "world.h" | ||||||
|  |  | ||||||
|  | Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) { | ||||||
|  | 	m_velocity = Vector3f(0, 0, 0); | ||||||
|  | 	m_airborne = true; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Player::TurnLeftRight(float value) { | ||||||
|  | 	m_rotY += value; | ||||||
|  | 	if (m_rotY > 360) m_rotY = 0; | ||||||
|  | 	else if (m_rotY < -360) m_rotY = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Player::TurnTopBottom(float value) { | ||||||
|  | 	m_rotX += value; | ||||||
|  | 	if (m_rotX > 80) m_rotX = 80; | ||||||
|  | 	else if (m_rotX < -80) m_rotX = -80; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) { | ||||||
|  |  | ||||||
|  | 	Vector3f delta = Vector3f(0, 0, 0); | ||||||
|  |  | ||||||
|  | 	float yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295... | ||||||
|  | 	float xrotrad = (m_rotX / 57.2957795056f); | ||||||
|  |  | ||||||
|  | 	m_direction = Vector3f(cos(xrotrad) * sin(yrotrad), | ||||||
|  | 						   -sin(xrotrad), | ||||||
|  | 						   cos(xrotrad) * -cos(yrotrad)); | ||||||
|  |  | ||||||
|  | 	m_direction.Normalize(); | ||||||
|  |  | ||||||
|  | 	if (front) { | ||||||
|  | 		delta.x += float(sin(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 		delta.z += float(-cos(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 	} | ||||||
|  | 	else if (back) { | ||||||
|  | 		delta.x += float(-sin(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 		delta.z += float(cos(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (left) { | ||||||
|  | 		delta.x += float(-cos(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 		delta.z += float(-sin(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 	} | ||||||
|  | 	else if (right) { | ||||||
|  | 		delta.x += float(cos(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 		delta.z += float(sin(yrotrad)) * elapsedTime * 10.f; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	delta.Normalize(); | ||||||
|  | 	delta.x *= .6f; | ||||||
|  | 	delta.z *= .6f; | ||||||
|  |  | ||||||
|  | 	if ((jump || shoot ) && !m_airborne) { | ||||||
|  | 		delta.y += jump? .32f: shoot? .1f : 0.f; | ||||||
|  | 		m_airborne = true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (shoot) // Recoil! | ||||||
|  | 		TurnTopBottom(-1); | ||||||
|  |  | ||||||
|  | 	return delta; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime) { | ||||||
|  | 	static float timing = 0.f; | ||||||
|  | 	/* Gestion de collisions */ | ||||||
|  | 	BlockType bt1, bt2, bt3; | ||||||
|  |  | ||||||
|  | 	bt1 = world->BlockAt(GetPosition().x, GetPosition().y + input.y, GetPosition().z); | ||||||
|  | 	bt2 = world->BlockAt(GetPosition().x, GetPosition().y + input.y - 0.9f, GetPosition().z); | ||||||
|  | 	bt3 = world->BlockAt(GetPosition().x, GetPosition().y + input.y - 1.7f, GetPosition().z); | ||||||
|  | 	if ((bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) && m_position.y < 129.7f) { | ||||||
|  | 		bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z); | ||||||
|  | 		if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f; | ||||||
|  | 		m_velocity.y = input.y = 0; | ||||||
|  | 		m_airborne = false; | ||||||
|  | 	} | ||||||
|  | 	else { | ||||||
|  | 		if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime; | ||||||
|  | 		bt3 = world->BlockAt(GetPosition().x, GetPosition().y + m_velocity.y - 1.7f, GetPosition().z); | ||||||
|  | 		bt1 = world->BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z); | ||||||
|  | 		if (bt3 != BTYPE_AIR) { | ||||||
|  | 			m_velocity.y = 0; | ||||||
|  | 			if (timing == 0.f) { | ||||||
|  | 				timing = .3f; | ||||||
|  | 			} | ||||||
|  | 			m_airborne = false; | ||||||
|  | 		} | ||||||
|  | 		else if (bt1 != BTYPE_AIR) { | ||||||
|  | 			m_velocity.y = -.1f; | ||||||
|  | 		} | ||||||
|  | 		else m_airborne = true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (timing > 0.f) timing -= elapsedTime; | ||||||
|  | 	if (timing < 0.f) timing = 0.f; | ||||||
|  |  | ||||||
|  | 	bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z); | ||||||
|  | 	bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z); | ||||||
|  | 	bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z); | ||||||
|  | 	if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) { | ||||||
|  | 		if (input.x > 0) | ||||||
|  | 			input.x = m_velocity.x = 0.5f; | ||||||
|  | 		else | ||||||
|  | 			input.x = m_velocity.x = -0.5f; | ||||||
|  | 		m_velocity.y = 0.3; | ||||||
|  | 		m_velocity.z *= .5f; | ||||||
|  | 	} | ||||||
|  | 	else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { | ||||||
|  | 		input.x = m_velocity.x = 0; | ||||||
|  | 		m_velocity.z *= .5f; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z); | ||||||
|  | 	bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z); | ||||||
|  | 	bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z); | ||||||
|  | 	if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) { | ||||||
|  | 		if (input.z > 0) | ||||||
|  | 			input.z = m_velocity.z = 0.5f; | ||||||
|  | 		else | ||||||
|  | 			input.z = m_velocity.z = -0.5f; | ||||||
|  | 		m_velocity.y = 0.3; | ||||||
|  | 		m_velocity.x *= .5f; | ||||||
|  | 	} | ||||||
|  | 	else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) { | ||||||
|  | 		input.z = m_velocity.z = 0; | ||||||
|  | 		m_velocity.x *= .5f; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/* Fin gestion de collisions */ | ||||||
|  | 	/* Gestion de la friction */ | ||||||
|  |  | ||||||
|  | 	if (!m_airborne) { | ||||||
|  | 		m_velocity.x += input.x * 2.f * elapsedTime; | ||||||
|  | 		m_velocity.z += input.z * 2.f * elapsedTime; | ||||||
|  |  | ||||||
|  | 		if (input.x == 0.f)  | ||||||
|  | 			m_velocity.x *= .8f; | ||||||
|  | 		 | ||||||
|  | 		if (input.z == 0.f)  | ||||||
|  | 			m_velocity.z *= .8f; | ||||||
|  | 	} | ||||||
|  | 	else { | ||||||
|  | 		m_velocity.x += input.x * .4f * elapsedTime; // Techniquement contre les lois de la physique, mais c'est beaucoup moins chiant pour grimper sur les blocs. | ||||||
|  | 		m_velocity.z += input.z * .4f * elapsedTime; | ||||||
|  | 		m_velocity.x *= .99f; | ||||||
|  | 		m_velocity.z *= .99f; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/* Fin gestion de la friction */ | ||||||
|  |  | ||||||
|  | 	float vy = m_velocity.y; | ||||||
|  | 	m_velocity.y = 1.f; // Padding pour limiter le x et z lors du Normalize(). | ||||||
|  | 	if (m_velocity.Length() >= 1.f) m_velocity.Normalize(); // Limiteur de vitesse en x/z. | ||||||
|  | 	m_velocity.y = 0; | ||||||
|  | 	if (m_velocity.Length() < .005f) m_velocity.Zero(); // Threshold en x/z. | ||||||
|  | 	m_velocity.y = vy; | ||||||
|  |  | ||||||
|  | 	m_position += m_velocity; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Vector3f Player::GetPosition() const { return Vector3f(m_position.x + CHUNK_SIZE_X * WORLD_SIZE_X / 2, m_position.y, m_position.z + CHUNK_SIZE_Z * WORLD_SIZE_Y / 2); } | ||||||
|  |  | ||||||
|  | Vector3f Player::GetVelocity() const { return m_velocity; } | ||||||
|  |  | ||||||
|  | Vector3f Player::GetPOV() const { return Vector3f(GetPosition().x, m_POV, GetPosition().z); } | ||||||
|  |  | ||||||
|  | Vector3f Player::GetDirection() const { return m_direction; } | ||||||
|  |  | ||||||
|  | void Player::Teleport(int& x, int& z) { | ||||||
|  | 	m_position.x -= x * CHUNK_SIZE_X; | ||||||
|  | 	m_position.z -= z * CHUNK_SIZE_Z; | ||||||
|  | } | ||||||
							
								
								
									
										34
									
								
								SQCSim-common/player.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,34 @@ | |||||||
|  | #ifndef _PLAYER_H__ | ||||||
|  | #define _PLAYER_H__ | ||||||
|  | #include "vector3.h" | ||||||
|  | #include <cmath> | ||||||
|  |  | ||||||
|  | class World; | ||||||
|  |  | ||||||
|  | class Player { | ||||||
|  | public: | ||||||
|  | 	Player(const Vector3f& position, float rotX = 0, float rotY = 0); | ||||||
|  | 	void TurnLeftRight(float value); | ||||||
|  | 	void TurnTopBottom(float value); | ||||||
|  | 	Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime); | ||||||
|  | 	void ApplyPhysics(Vector3f input, World* world, float elapsedTime); | ||||||
|  |  | ||||||
|  | 	Vector3f GetPosition() const; | ||||||
|  | 	Vector3f GetDirection() const; | ||||||
|  | 	Vector3f GetVelocity() const; | ||||||
|  | 	Vector3f GetPOV() const; | ||||||
|  | 	void Teleport(int& x, int& z); | ||||||
|  |  | ||||||
|  | protected: | ||||||
|  | 	Vector3f m_position; | ||||||
|  | 	Vector3f m_velocity; | ||||||
|  | 	Vector3f m_direction; | ||||||
|  |  | ||||||
|  | 	float m_rotX = 0;  | ||||||
|  | 	float m_rotY = 0; | ||||||
|  | 	float m_POV; | ||||||
|  |  | ||||||
|  | 	bool m_airborne; | ||||||
|  | }; | ||||||
|  | #endif //_PLAYER_H__ | ||||||
|  |  | ||||||
							
								
								
									
										219
									
								
								SQCSim-common/vector3.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,219 @@ | |||||||
|  | #ifndef VECTOR3_H__ | ||||||
|  | #define VECTOR3_H__ | ||||||
|  |  | ||||||
|  | #include <iostream> | ||||||
|  | #include <cmath> | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | class Vector3 | ||||||
|  | { | ||||||
|  | public: | ||||||
|  | 	Vector3(); | ||||||
|  | 	Vector3(const T& x, const T& y, const T& z); | ||||||
|  | 	~Vector3(); | ||||||
|  |  | ||||||
|  | 	T Length() const; | ||||||
|  | 	void Normalize(); | ||||||
|  | 	void Zero(); | ||||||
|  |  | ||||||
|  | 	T Dot(const Vector3<T>& v) const; | ||||||
|  | 	Vector3<T> Cross(const Vector3<T>& v) const; | ||||||
|  |  | ||||||
|  | 	Vector3<T> operator+(const Vector3<T>& v) const; | ||||||
|  | 	Vector3<T> operator-(const Vector3<T>& v) const; | ||||||
|  | 	Vector3<T> operator-() const; | ||||||
|  | 	Vector3<T> operator+(const T& v) const; | ||||||
|  | 	Vector3<T> operator-(const T& v) const; | ||||||
|  | 	Vector3<T> operator/(const T& v) const; | ||||||
|  | 	Vector3<T> operator*(const T& v) const; | ||||||
|  |  | ||||||
|  | 	Vector3<T>& operator=(const Vector3<T>& v); | ||||||
|  |  | ||||||
|  | 	Vector3<T>& operator+=(const Vector3<T>& v); | ||||||
|  | 	Vector3<T>& operator-=(const Vector3<T>& v); | ||||||
|  | 	Vector3<T>& operator+=(const T& v); | ||||||
|  | 	Vector3<T>& operator-=(const T& v); | ||||||
|  | 	Vector3<T>& operator/=(const T& v); | ||||||
|  | 	Vector3<T>& operator*=(const T& v); | ||||||
|  |  | ||||||
|  | 	bool operator==(const Vector3<T>& v) const; | ||||||
|  | 	bool operator!=(const Vector3<T>& v) const; | ||||||
|  |  | ||||||
|  | 	void Afficher() const; | ||||||
|  |  | ||||||
|  | public: | ||||||
|  | 	T x, y, z; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef Vector3<int> Vector3i; | ||||||
|  | typedef Vector3<float> Vector3f; | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | inline std::ostream& operator<<(std::ostream& out, const Vector3<T>& v) | ||||||
|  | { | ||||||
|  | 	out << "[" << v.x << ", " << v.y << ", " << v.z << "]"; | ||||||
|  |     return out; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>::Vector3() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>::Vector3(const T& x, const T& y, const T& z) : x(x), y(y), z(z) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>::~Vector3() | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | T Vector3<T>::Length() const | ||||||
|  | { | ||||||
|  | 	return sqrt(x*x + y*y + z*z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Vector3<T>::Normalize() | ||||||
|  | { | ||||||
|  | 	T len = Length(); | ||||||
|  | 	if (len != 0) | ||||||
|  | 	{ | ||||||
|  | 		x /= len; | ||||||
|  | 		y /= len; | ||||||
|  | 		z /= len; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Vector3<T>::Zero() | ||||||
|  | { | ||||||
|  | 	x = y = z = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | T Vector3<T>::Dot(const Vector3<T>& v) const | ||||||
|  | { | ||||||
|  | 	return (x * v.x) + (y * v.y) + (z * v.z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::Cross(const Vector3<T>& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>( | ||||||
|  | 		y * v.z - v.y * z, | ||||||
|  | 		z * v.x - v.z * x, | ||||||
|  | 		x * v.y - v.x * y); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator+(const Vector3<T>& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(x + v.x, y + v.y, z + v.z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator-(const Vector3<T>& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(x - v.x, y - v.y, z - v.z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator-() const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(-x, -y, -z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator+(const T& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(x + v, y + v, z + v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator-(const T& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(x - v, y - v, z - v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator/(const T& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(x / v, y / v, z / v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T> Vector3<T>::operator*(const T& v) const | ||||||
|  | { | ||||||
|  | 	return Vector3<T>(x * v, y * v, z * v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator=(const Vector3<T>& v) | ||||||
|  | { | ||||||
|  | 	x = v.x; | ||||||
|  | 	y = v.y; | ||||||
|  | 	z = v.z; | ||||||
|  | 	return *this; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator+=(const Vector3<T>& v) | ||||||
|  | { | ||||||
|  | 	return (*this = *this + v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator-=(const Vector3<T>& v) | ||||||
|  | { | ||||||
|  | 	return (*this = *this - v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator+=(const T& v) | ||||||
|  | { | ||||||
|  | 	return (*this = *this + v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator-=(const T& v) | ||||||
|  | { | ||||||
|  | 	return (*this = *this - v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator/=(const T& v) | ||||||
|  | { | ||||||
|  | 	return (*this = *this / v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | Vector3<T>& Vector3<T>::operator*=(const T& v) | ||||||
|  | { | ||||||
|  | 	return (*this = *this * v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | bool Vector3<T>::operator==(const Vector3<T>& v) const | ||||||
|  | { | ||||||
|  | 	return (x == v.x && y == v.y && z == v.z); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | bool Vector3<T>::operator!=(const Vector3<T>& v) const | ||||||
|  | { | ||||||
|  | 	return !(*this == v); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | void Vector3<T>::Afficher() const | ||||||
|  | { | ||||||
|  | 	std::cout << "[" << x << ", " << y << ", " << z << "]" << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #endif // VECTOR3_H__ | ||||||
							
								
								
									
										109
									
								
								SQCSim-common/world.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,109 @@ | |||||||
|  | #include "world.h" | ||||||
|  |  | ||||||
|  | World::World() {} | ||||||
|  |  | ||||||
|  | World::~World() {} | ||||||
|  |  | ||||||
|  | Array2d<Chunk*>& World::GetChunks() { return m_chunks; } | ||||||
|  |  | ||||||
|  | Chunk* World::ChunkAt(float x, float y, float z) const { | ||||||
|  | 	int cx = (int)x / CHUNK_SIZE_X; | ||||||
|  | 	int cz = (int)z / CHUNK_SIZE_Z; | ||||||
|  |  | ||||||
|  | 	if (x < 0 || y < 0 || z < 0 || | ||||||
|  | 		x >= WORLD_SIZE_X * CHUNK_SIZE_X || | ||||||
|  | 		z >= CHUNK_SIZE_Z * WORLD_SIZE_Y || | ||||||
|  | 		y > CHUNK_SIZE_Y) | ||||||
|  | 		return 0; | ||||||
|  |  | ||||||
|  | 	return m_chunks.Get(cx, cz); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Chunk* World::ChunkAt(const Vector3f& pos) const { return ChunkAt(pos.x, pos.y, pos.z); } | ||||||
|  |  | ||||||
|  | BlockType World::BlockAt(float x, float y, float z, BlockType defaultBlockType) const { | ||||||
|  | 	Chunk* c = ChunkAt(x, y, z); | ||||||
|  |  | ||||||
|  | 	if (!c) | ||||||
|  | 		return defaultBlockType; | ||||||
|  |  | ||||||
|  | 	int bx = (int)x % CHUNK_SIZE_X; | ||||||
|  | 	int by = (int)y % CHUNK_SIZE_Y; | ||||||
|  | 	int bz = (int)z % CHUNK_SIZE_Z; | ||||||
|  |  | ||||||
|  | 	return c->GetBlock(bx, by, bz); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BlockType World::BlockAt(const Vector3f& pos, BlockType defaultBlockType) const { | ||||||
|  | 	return BlockAt(pos.x, pos.y, pos.z, defaultBlockType); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void World::GetScope(unsigned int& x, unsigned int& y) { | ||||||
|  | 	x = m_center[0]; | ||||||
|  | 	y = m_center[1]; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void World::ChangeBlockAtPosition(BlockType blockType, Vector3f pos) { | ||||||
|  | 	int bx = (int)pos.x % CHUNK_SIZE_X; | ||||||
|  | 	int by = (int)pos.y % CHUNK_SIZE_Y; | ||||||
|  | 	int bz = (int)pos.z % CHUNK_SIZE_Z; | ||||||
|  |  | ||||||
|  | 	ChunkAt(pos)->SetBlock(bx, by, bz, blockType, this); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void World::ChangeBlockAtCursor(BlockType blockType, Player& player, bool& block) { | ||||||
|  | 	Vector3f currentPos = player.GetPosition(); | ||||||
|  | 	Vector3f currentBlock = currentPos; | ||||||
|  | 	Vector3f ray = player.GetDirection(); | ||||||
|  | 	bool found = false; | ||||||
|  |  | ||||||
|  | 	if (block) return; | ||||||
|  |  | ||||||
|  | 	while ((currentPos - currentBlock).Length() <= MAX_SELECTION_DISTANCE && !found) { | ||||||
|  | 		currentBlock += ray / 10.f; | ||||||
|  |  | ||||||
|  | 		BlockType bt = BlockAt(currentBlock); | ||||||
|  |  | ||||||
|  | 		if (bt != BTYPE_AIR) | ||||||
|  | 			found = true; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (found) | ||||||
|  | 		if (blockType != BTYPE_AIR) { | ||||||
|  | 			found = false; | ||||||
|  | 			while ((currentPos - currentBlock).Length() >= 1.7f && !found) { | ||||||
|  | 				currentBlock -= ray / 10.f; | ||||||
|  |  | ||||||
|  | 				BlockType bt = BlockAt(currentBlock); | ||||||
|  |  | ||||||
|  | 				if (bt == BTYPE_AIR) { // V?rification pour ?tre s?r que le bloc ? changer n'est pas dans le joueur. | ||||||
|  | 					int Bx = (int)currentBlock.x; | ||||||
|  | 					int By = (int)currentBlock.y; | ||||||
|  | 					int Bz = (int)currentBlock.z; | ||||||
|  |  | ||||||
|  | 					int Px = (int)currentPos.x; | ||||||
|  | 					int PyA = (int)currentPos.y; | ||||||
|  | 					int PyB = (int)(currentPos.y - .9f); | ||||||
|  | 					int PyC = (int)(currentPos.y - 1.7f); | ||||||
|  | 					int Pz = (int)currentPos.z; | ||||||
|  |  | ||||||
|  | 					if (!(Bx == Px && | ||||||
|  | 						(By == PyA || | ||||||
|  | 							By == PyB || | ||||||
|  | 							By == PyC) && | ||||||
|  | 						Bz == Pz)) | ||||||
|  | 						found = true; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 	if (found && (int)currentBlock.y < CHUNK_SIZE_Y) { | ||||||
|  | 		int bx = (int)currentBlock.x % CHUNK_SIZE_X; | ||||||
|  | 		int by = (int)currentBlock.y % CHUNK_SIZE_Y; | ||||||
|  | 		int bz = (int)currentBlock.z % CHUNK_SIZE_Z; | ||||||
|  |  | ||||||
|  | 		ChunkAt(currentBlock)->SetBlock(bx, by, bz, blockType, this); | ||||||
|  | 		ChunkAt(currentBlock)->MakeModified(); | ||||||
|  | 		block = true; | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										45
									
								
								SQCSim-common/world.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,45 @@ | |||||||
|  | #ifndef WORLD_H__ | ||||||
|  | #define WORLD_H__ | ||||||
|  | #include <fstream> | ||||||
|  | #include <string> | ||||||
|  | #include <vector> | ||||||
|  | #include <future> | ||||||
|  | #include <thread> | ||||||
|  | #include "define.h" | ||||||
|  | #include "chunk.h" | ||||||
|  | #include "array2d.h" | ||||||
|  | #include "vector3.h" | ||||||
|  | #include "player.h" | ||||||
|  | #include "bullet.h" | ||||||
|  |  | ||||||
|  | class Chunk; | ||||||
|  | class Player; | ||||||
|  | class Bullet; | ||||||
|  |  | ||||||
|  | class World { | ||||||
|  | public: | ||||||
|  | 	World(); | ||||||
|  | 	~World(); | ||||||
|  |  | ||||||
|  | 	Array2d<Chunk*>& GetChunks(); | ||||||
|  |  | ||||||
|  | 	Chunk* ChunkAt(float x, float y, float z) const; | ||||||
|  | 	Chunk* ChunkAt(const Vector3f& pos) const; | ||||||
|  |  | ||||||
|  | 	BlockType BlockAt(float x, float y, float z, BlockType defaultBlockType = BTYPE_AIR) const; | ||||||
|  | 	BlockType BlockAt(const Vector3f& pos, BlockType defaultBlockType = BTYPE_AIR) const; | ||||||
|  |  | ||||||
|  | 	void GetScope(unsigned int& x, unsigned int& y); | ||||||
|  |  | ||||||
|  | 	void ChangeBlockAtCursor(BlockType blockType, Player& player, bool& block); | ||||||
|  | 	void ChangeBlockAtPosition(BlockType blockType, Vector3f pos); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | 	Array2d<Chunk*> m_chunks = Array2d<Chunk*>(WORLD_SIZE_X, WORLD_SIZE_Y); | ||||||
|  | 	std::vector<Chunk*> m_tbDeleted; | ||||||
|  |  | ||||||
|  | 	unsigned int m_center[2] = { UINT16_MAX / 2 - WORLD_SIZE_X, UINT16_MAX / 2 - WORLD_SIZE_Y }; | ||||||
|  |  | ||||||
|  | }; | ||||||
|  | #endif // WORLD_H__ | ||||||
|  |  | ||||||
							
								
								
									
										148
									
								
								SQCSim-srv/SQCSim-srv.vcxproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,148 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project DefaultTargets="Build" 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"> | ||||||
|  |     <VCProjectVersion>17.0</VCProjectVersion> | ||||||
|  |     <Keyword>Win32Proj</Keyword> | ||||||
|  |     <ProjectGuid>{d3bb3300-25f0-42bf-a934-fac33b5c7d25}</ProjectGuid> | ||||||
|  |     <RootNamespace>SQCSimsrv</RootNamespace> | ||||||
|  |     <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>true</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <CharacterSet>Unicode</CharacterSet> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||||||
|  |     <ConfigurationType>Application</ConfigurationType> | ||||||
|  |     <UseDebugLibraries>false</UseDebugLibraries> | ||||||
|  |     <PlatformToolset>v143</PlatformToolset> | ||||||
|  |     <WholeProgramOptimization>true</WholeProgramOptimization> | ||||||
|  |     <CharacterSet>Unicode</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" /> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |       <LanguageStandard>Default</LanguageStandard> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|  |     <ClCompile> | ||||||
|  |       <WarningLevel>Level3</WarningLevel> | ||||||
|  |       <FunctionLevelLinking>true</FunctionLevelLinking> | ||||||
|  |       <IntrinsicFunctions>true</IntrinsicFunctions> | ||||||
|  |       <SDLCheck>true</SDLCheck> | ||||||
|  |       <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||||
|  |       <ConformanceMode>true</ConformanceMode> | ||||||
|  |     </ClCompile> | ||||||
|  |     <Link> | ||||||
|  |       <SubSystem>Console</SubSystem> | ||||||
|  |       <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||||||
|  |       <OptimizeReferences>true</OptimizeReferences> | ||||||
|  |       <GenerateDebugInformation>true</GenerateDebugInformation> | ||||||
|  |     </Link> | ||||||
|  |   </ItemDefinitionGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClCompile Include="connection.cpp" /> | ||||||
|  |     <ClCompile Include="main.cpp" /> | ||||||
|  |     <ClCompile Include="server.cpp" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClInclude Include="connection.h" /> | ||||||
|  |     <ClInclude Include="define.h" /> | ||||||
|  |     <ClInclude Include="server.h" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ProjectReference Include="..\SQCSim-common\SQCSim-common.vcxproj"> | ||||||
|  |       <Project>{ee91ab12-4225-4a4d-931d-69d72f6d91fb}</Project> | ||||||
|  |     </ProjectReference> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||||
|  |   <ImportGroup Label="ExtensionTargets"> | ||||||
|  |   </ImportGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										39
									
								
								SQCSim-srv/SQCSim-srv.vcxproj.filters
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,39 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Filter Include="Fichiers sources"> | ||||||
|  |       <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||||||
|  |       <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Fichiers d%27en-tête"> | ||||||
|  |       <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||||||
|  |       <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | ||||||
|  |     </Filter> | ||||||
|  |     <Filter Include="Fichiers de ressources"> | ||||||
|  |       <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="main.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="server.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |     <ClCompile Include="connection.cpp"> | ||||||
|  |       <Filter>Fichiers sources</Filter> | ||||||
|  |     </ClCompile> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <ClInclude Include="define.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="server.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |     <ClInclude Include="connection.h"> | ||||||
|  |       <Filter>Fichiers d%27en-tête</Filter> | ||||||
|  |     </ClInclude> | ||||||
|  |   </ItemGroup> | ||||||
|  | </Project> | ||||||
							
								
								
									
										56
									
								
								SQCSim-srv/connection.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,56 @@ | |||||||
|  | #include "connection.h" | ||||||
|  |  | ||||||
|  | Connection::Connection(in_addr addr,  | ||||||
|  | 					   std::string name,  | ||||||
|  | 					   UINT64 id,  | ||||||
|  | 					   UINT64 self_id, | ||||||
|  | 				       UINT64 team_id):  | ||||||
|  | 	m_addr(addr),  | ||||||
|  | 	m_id(id),  | ||||||
|  | 	m_sid(self_id), | ||||||
|  | 	m_tid(team_id),  | ||||||
|  | 	m_name(name) { | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Connection::~Connection() { | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | in_addr Connection::GetAddr() const { return m_addr; } | ||||||
|  |  | ||||||
|  | UINT64 Connection::GetHash(bool self) const { return self? m_sid: m_id; } | ||||||
|  |  | ||||||
|  | UINT64 Connection::GetTeamHash() const { return m_tid; } | ||||||
|  |  | ||||||
|  | std::string Connection::GetName() const { return m_name; } | ||||||
|  |  | ||||||
|  | void Connection::AddInput(Input in) { | ||||||
|  | 	m_input_manifest.insert({in.timestamp, in}); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Output* Connection::getOutput(Timestamp time) { | ||||||
|  | 	auto out = m_output_manifest.find(time); | ||||||
|  | 	if (out != m_output_manifest.end()) | ||||||
|  | 		return &out->second; | ||||||
|  | 	return nullptr; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Sync Connection::getSync(Timestamp time) { | ||||||
|  | 	Sync sync; | ||||||
|  | 	auto out = m_output_manifest.find(time); | ||||||
|  | 	if (out != m_output_manifest.end()) { | ||||||
|  | 		sync.timestamp = out->second.timestamp; | ||||||
|  | 		sync.position = out->second.position; | ||||||
|  | 		sync.sid = m_sid; | ||||||
|  | 	} | ||||||
|  | 	return sync; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Connection::CleanInputManifest(Timestamp time) { | ||||||
|  | 	auto wat = m_input_manifest.find(time); | ||||||
|  |  | ||||||
|  | 	while (wat != m_input_manifest.begin()) | ||||||
|  | 		m_input_manifest.erase(wat--); | ||||||
|  | 	 | ||||||
|  | } | ||||||
							
								
								
									
										60
									
								
								SQCSim-srv/connection.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,60 @@ | |||||||
|  | #ifndef CONNECTION_H__ | ||||||
|  | #define CONNECTION_H__ | ||||||
|  | #include <deque> | ||||||
|  | #include <map> | ||||||
|  | #include "../SQCSim-common/player.h" | ||||||
|  | #include "../SQCSim-common/vector3.h" | ||||||
|  | #include "define.h" | ||||||
|  |  | ||||||
|  | struct Input { | ||||||
|  | 	Timestamp timestamp; | ||||||
|  | 	UINT8 keys; // 0bFBLRJS__ | ||||||
|  | 	Vector3f direction; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | struct Output { | ||||||
|  | 	Timestamp timestamp; | ||||||
|  | 	UINT64 id = 0; | ||||||
|  | 	Vector3f position, direction; | ||||||
|  | 	bool is_shooting, is_jumping; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | struct Sync { | ||||||
|  | 	Timestamp timestamp; | ||||||
|  | 	UINT64 sid = 0; | ||||||
|  | 	Vector3f position; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | class Connection { | ||||||
|  | public: | ||||||
|  | 	Connection( | ||||||
|  | 		in_addr addr,  | ||||||
|  | 		std::string name,  | ||||||
|  | 		UINT64 hash,  | ||||||
|  | 		UINT64 self_hash,  | ||||||
|  | 		UINT64 team_hash); | ||||||
|  | 	~Connection(); | ||||||
|  |  | ||||||
|  | 	Player* player = nullptr; | ||||||
|  |  | ||||||
|  | 	in_addr GetAddr() const; | ||||||
|  | 	UINT64 GetHash(bool self = true) const; | ||||||
|  | 	UINT64 GetTeamHash() const; | ||||||
|  | 	std::string GetName() const; | ||||||
|  |  | ||||||
|  | 	void AddInput(Input in); | ||||||
|  | 	Output* getOutput(Timestamp time); | ||||||
|  | 	Sync getSync(Timestamp time); | ||||||
|  |  | ||||||
|  | 	void CleanInputManifest(Timestamp time); | ||||||
|  | private: | ||||||
|  | 	std::map<Timestamp, Input> m_input_manifest; | ||||||
|  | 	std::map<Timestamp, Output> m_output_manifest; | ||||||
|  | 	in_addr m_addr; | ||||||
|  | 	UINT64 m_id, | ||||||
|  | 		   m_sid, | ||||||
|  | 		   m_tid; | ||||||
|  | 	std::string m_name; | ||||||
|  |  | ||||||
|  | }; | ||||||
|  | #endif | ||||||
							
								
								
									
										43
									
								
								SQCSim-srv/define.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,43 @@ | |||||||
|  | #ifndef SRV_DEFINE_H__ | ||||||
|  | #define SRV_DEFINE_H__ | ||||||
|  |  | ||||||
|  | #include "../SQCSim-common/define.h" | ||||||
|  | #include <iostream> | ||||||
|  | #include <sstream> | ||||||
|  | #include <cctype> | ||||||
|  | #include <string> | ||||||
|  | #include <chrono> | ||||||
|  |  | ||||||
|  | #define MAX_CONNECTIONS 16 | ||||||
|  | typedef unsigned char LogDest; | ||||||
|  | enum LOG_DEST { CONSOLE, LOGFILE, LOG_LAST }; | ||||||
|  | typedef std::chrono::system_clock::time_point Timestamp; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #ifdef _WIN32 | ||||||
|  |  | ||||||
|  | #pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject | ||||||
|  |  | ||||||
|  | #include <Windows.h> | ||||||
|  | #include <cstdio> | ||||||
|  | #include <ctime> | ||||||
|  |  | ||||||
|  | #define popen _popen | ||||||
|  | #define pclose _pclose | ||||||
|  |  | ||||||
|  | #else // Pas _WIN32 | ||||||
|  |  | ||||||
|  | #include <unistd.h> | ||||||
|  | #include <time.h> | ||||||
|  | #include <stdio.h> | ||||||
|  | #include <sys/socket.h> | ||||||
|  | #include <arpa/inet.h> | ||||||
|  | #include <netinet/in.h> | ||||||
|  |  | ||||||
|  | #define SOCKET int | ||||||
|  | #define INVALID_SOCKET -1 | ||||||
|  | #define closesocket close | ||||||
|  |  | ||||||
|  | #endif // _WIN32 | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										10
									
								
								SQCSim-srv/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,10 @@ | |||||||
|  | #include "define.h" | ||||||
|  | #include "server.h" | ||||||
|  |  | ||||||
|  | int main() { | ||||||
|  | 	Server* server = new Server(); | ||||||
|  | 	if (server->Init() == 0) | ||||||
|  | 		if (server->Ready() == 0) | ||||||
|  | 			server->Run(); | ||||||
|  | 	delete server; | ||||||
|  | } | ||||||
							
								
								
									
										242
									
								
								SQCSim-srv/server.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,242 @@ | |||||||
|  | #include "server.h" | ||||||
|  |  | ||||||
|  | Server::Server(LogDest log) { | ||||||
|  | 	m_log = log; | ||||||
|  | 	if (log == LOG_DEST::LOGFILE) { | ||||||
|  | 		m_logfile = std::ofstream("server.log", std::ofstream::out); | ||||||
|  | 		if (!m_logfile.is_open()) { | ||||||
|  | 			m_log = LOG_DEST::CONSOLE; // Fallback console. | ||||||
|  | 			Log("Ouverture fichier log: repli vers console.", true, false); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Server::~Server() { | ||||||
|  | 	if (m_logfile.is_open()) | ||||||
|  | 		m_logfile.close(); | ||||||
|  | 	if (m_sock_udp) | ||||||
|  | 		closesocket(m_sock_udp); | ||||||
|  | 	if (m_sock_tcp) | ||||||
|  | 		closesocket(m_sock_tcp); | ||||||
|  | #ifdef _WIN32 | ||||||
|  | 	WSACleanup(); | ||||||
|  | #endif | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int Server::Init() { | ||||||
|  | 	Log("Initialisation du serveur...", false, false); | ||||||
|  |  | ||||||
|  | #ifdef _WIN32 | ||||||
|  | 	if (WSAStartup(MAKEWORD(2, 2), &m_wsaData) != 0) { /* Initialisation de l'environnement reseau (Windows only) */ | ||||||
|  | 		Log("Initialisation WinSock.", true, true); | ||||||
|  | 		return 1; | ||||||
|  | 	} | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | 	m_sock_udp = socket(AF_INET, SOCK_DGRAM, 0); | ||||||
|  | 	if (m_sock_udp == INVALID_SOCKET) { /* Creation du socket UDP */ | ||||||
|  | 		Log("Creation Socket UDP.", true, true); | ||||||
|  | 		return 2; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	m_sock_tcp = socket(AF_INET, SOCK_STREAM, 0); | ||||||
|  | 	if (m_sock_tcp == INVALID_SOCKET) { /* Creation du socket TCP */ | ||||||
|  | 		Log("Creation Socket TCP.", true, true); | ||||||
|  | 		return 3; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/* Creation structure donnes descripteur du socket serveur */ | ||||||
|  | 	sockaddr_in addr; | ||||||
|  | 	addr.sin_family = AF_INET; | ||||||
|  | 	addr.sin_port = htons(SRV_PORT); | ||||||
|  | 	addr.sin_addr.s_addr = htonl(INADDR_ANY); | ||||||
|  |  | ||||||
|  | 	if (bind(m_sock_udp, (sockaddr*)&addr, sizeof(addr)) != 0) { /* Associer le socket UDP au port */ | ||||||
|  | 		Log("Association Socket UDP.", true, true); | ||||||
|  | 		return 4; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (bind(m_sock_tcp, (sockaddr*)&addr, sizeof(addr)) != 0) { /* Associer le socket TCP au port */ | ||||||
|  | 		Log("Association Socket TCP.", true, true); | ||||||
|  | 		return 5; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	for (auto& conn : m_conn) | ||||||
|  | 		conn = nullptr; | ||||||
|  |  | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int Server::Ready() { | ||||||
|  | 	if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) { | ||||||
|  | 		Log("<EFBFBD>coute sur le port TCP.", true, true); | ||||||
|  | 		return 1; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	char buffer[2048]; | ||||||
|  | 	bool readystart = false; | ||||||
|  |  | ||||||
|  | 	Log("<EFBFBD> l'<27>coute sur le port: " + std::to_string(SRV_PORT), false, false); | ||||||
|  |  | ||||||
|  | 	while (!readystart) { | ||||||
|  | 		 | ||||||
|  | 		Log("trololo", false, false); | ||||||
|  | 		readystart = true; | ||||||
|  | 	} | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Server::Run() { | ||||||
|  | 	Log("Partie en cours...", false, false); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | inline std::string Server::Timestamp() { | ||||||
|  | 	time_t rawtime; | ||||||
|  | 	struct tm timeinfo; | ||||||
|  | 	char buffer[80]; | ||||||
|  |  | ||||||
|  | 	time(&rawtime); | ||||||
|  |  | ||||||
|  | #ifdef _WIN32 | ||||||
|  | 	localtime_s(&timeinfo, &rawtime); | ||||||
|  | #else | ||||||
|  | 	localtime_r(&rawtime, &timeinfo); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | 	strftime(buffer, sizeof(buffer), "%d-%m-%Y %H:%M:%S", &timeinfo); | ||||||
|  | 	std::string str(buffer); | ||||||
|  |  | ||||||
|  | 	return "[" + str + "] "; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) { | ||||||
|  | 	switch (m_log) { | ||||||
|  | 	case LOG_DEST::LOGFILE: | ||||||
|  | 		m_logfile << Timestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	case LOG_DEST::CONSOLE: | ||||||
|  | 	default: | ||||||
|  | 		std::cout << Timestamp() << (is_fatal? "FATAL ": "") << (is_error ? "ERROR ": "") << str << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (is_fatal) { | ||||||
|  | 		if (m_sock_udp) | ||||||
|  | 			closesocket(m_sock_udp); | ||||||
|  | 		if (m_sock_tcp) | ||||||
|  | 			closesocket(m_sock_tcp); | ||||||
|  | #ifdef _WIN32 | ||||||
|  | 		WSACleanup(); | ||||||
|  | #endif | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ///* Recevoir paquet */ | ||||||
|  | //while (true) { | ||||||
|  | //	char buffer[2048]; | ||||||
|  | //	sockaddr_in client; | ||||||
|  | // | ||||||
|  | //#ifdef _WIN32 // Mais pourquoi? | ||||||
|  | //	int clen = sizeof(client); | ||||||
|  | //#else | ||||||
|  | //	unsigned int clen = sizeof(client); | ||||||
|  | //#endif | ||||||
|  | // | ||||||
|  | //	int count = recvfrom(socket_udp, buffer, sizeof(buffer) - 1, 0, (sockaddr*)&client, &clen); | ||||||
|  | // | ||||||
|  | //	if (count < 0) { | ||||||
|  | //		Log("Erreur de reception de paquet.", socket_udp); | ||||||
|  | //		return 4; | ||||||
|  | //	} | ||||||
|  | // | ||||||
|  | //	buffer[count] = '\0'; | ||||||
|  | // | ||||||
|  | //	/* G<>rer le paquet re<72>u */ | ||||||
|  | //	std::string commande(buffer); | ||||||
|  | // | ||||||
|  | //	if (commande.find("echo ") == 0) {													/*		ECHO		*/ | ||||||
|  | //		std::string::size_type pos = commande.find(' '); | ||||||
|  | //		std::string parametres = commande.substr(pos + 1); | ||||||
|  | // | ||||||
|  | //		sendto(socket_udp, parametres.c_str(), parametres.length(), 0, (const sockaddr*)&client, sizeof(client)); | ||||||
|  | //	} | ||||||
|  | //	else if (commande.find("date ") == 0) {												/*		DATE		*/ | ||||||
|  | //		time_t rawtime; | ||||||
|  | //		struct tm* timeinfo = new tm(); | ||||||
|  | //		char tbuffer[80]; | ||||||
|  | // | ||||||
|  | //		time(&rawtime); | ||||||
|  | // | ||||||
|  | //#ifdef _WIN32 | ||||||
|  | //		localtime_s(timeinfo, &rawtime); | ||||||
|  | //#else | ||||||
|  | //		localtime_r(&rawtime, timeinfo); | ||||||
|  | //#endif | ||||||
|  | // | ||||||
|  | //		strftime(tbuffer, 80, "%a %b %e %T %G", timeinfo); | ||||||
|  | // | ||||||
|  | //		sendto(socket_udp, tbuffer, sizeof(tbuffer), 0, (const sockaddr*)&client, sizeof(client)); | ||||||
|  | //		delete timeinfo; | ||||||
|  | //	} | ||||||
|  | //	else if (commande.find("ping ") == 0) {												/*		PING		*/ | ||||||
|  | //		sendto(socket_udp, "pong", sizeof("pong"), 0, (const sockaddr*)&client, sizeof(client)); | ||||||
|  | //	} | ||||||
|  | //	else if (commande.find("usager ") == 0) {											/*		USAGER		*/ | ||||||
|  | //		std::string user; | ||||||
|  | // | ||||||
|  | //#ifdef _WIN32 | ||||||
|  | //		wchar_t userbuf[30]; | ||||||
|  | //		DWORD usersize = 30; | ||||||
|  | // | ||||||
|  | //		GetUserNameW(userbuf, &usersize); | ||||||
|  | // | ||||||
|  | //		std::wstring wuser = userbuf; | ||||||
|  | //		user = std::string(wuser.begin(), wuser.end()); | ||||||
|  | //#else | ||||||
|  | //		char ptr[30]; | ||||||
|  | //		getlogin_r(ptr, sizeof(ptr) - 1); | ||||||
|  | //		user = std::string(ptr); | ||||||
|  | //#endif | ||||||
|  | // | ||||||
|  | //		sendto(socket_udp, user.c_str(), user.length(), 0, (const sockaddr*)&client, sizeof(client)); | ||||||
|  | //	} | ||||||
|  | //	else if (commande.find("exec ") == 0) {												/*		EXEC		*/ | ||||||
|  | //		std::string::size_type pos = commande.find(' '); | ||||||
|  | //		std::string parametres = commande.substr(pos + 1); | ||||||
|  | // | ||||||
|  | //		FILE* pipe = nullptr; | ||||||
|  | //		char buffer[301]; // 300 caract<63>res + '\0' | ||||||
|  | //		std::string reponse; | ||||||
|  | // | ||||||
|  | //		pipe = popen(parametres.c_str(), "r"); | ||||||
|  | // | ||||||
|  | //		if (!pipe) | ||||||
|  | //			reponse = "Erreur de commande!"; | ||||||
|  | //		else while (!feof(pipe)) { | ||||||
|  | //			if (fgets(buffer, sizeof(buffer) - 1, pipe)) | ||||||
|  | //				reponse += buffer; | ||||||
|  | //		} | ||||||
|  | // | ||||||
|  | //		if (pipe) | ||||||
|  | //			pclose(pipe); | ||||||
|  | // | ||||||
|  | //		if (reponse.length() > 300) | ||||||
|  | //			reponse = reponse.substr(0, 300); | ||||||
|  | //		else if (reponse.length() < 1) | ||||||
|  | //			reponse = "OK!"; | ||||||
|  | // | ||||||
|  | //		sendto(socket_udp, reponse.c_str(), reponse.length(), 0, (const sockaddr*)&client, sizeof(client)); | ||||||
|  | //	} | ||||||
|  | //	else if (commande.find("bye ") == 0) {											/*		BYE			*/ | ||||||
|  | //		Log("", 0); // Message d'erreur pas de message d'erreur! | ||||||
|  | //		return 0; | ||||||
|  | //	} | ||||||
|  | //	else sendto(socket_udp, "huh?", sizeof("huh?"), 0, (const sockaddr*)&client, sizeof(client));		/*			DEFAULT			 */ | ||||||
|  | //} | ||||||
|  | // | ||||||
|  | ///* Ce bout de code ne devrait theoriquement jamais etre atteint, mais au cas. */ | ||||||
|  | //Log("", 0); | ||||||
|  | //return 0; | ||||||
|  | //return false; | ||||||
|  | //} | ||||||
|  | // | ||||||
							
								
								
									
										35
									
								
								SQCSim-srv/server.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,35 @@ | |||||||
|  | #ifndef SERVER_H__ | ||||||
|  | #define SERVER_H__ | ||||||
|  |  | ||||||
|  | #include <fstream> | ||||||
|  | #include <vector> | ||||||
|  | #include <string> | ||||||
|  | #include "../SQCSim-common/world.h" | ||||||
|  | #include "define.h" | ||||||
|  | #include "connection.h" | ||||||
|  |  | ||||||
|  | class Server { | ||||||
|  | public: | ||||||
|  | 	Server(LogDest log = LOG_DEST::CONSOLE); | ||||||
|  | 	~Server(); | ||||||
|  |  | ||||||
|  | 	int Init(); | ||||||
|  | 	int Ready(); | ||||||
|  | 	void Run(); | ||||||
|  |  | ||||||
|  | private: | ||||||
|  | #ifdef _WIN32 | ||||||
|  | 	WSADATA m_wsaData; | ||||||
|  | #endif | ||||||
|  | 	SOCKET m_sock_udp = 0, | ||||||
|  | 		   m_sock_tcp = 0; | ||||||
|  | 	LogDest m_log; | ||||||
|  | 	std::ofstream m_logfile; | ||||||
|  |  | ||||||
|  | 	Connection* m_conn[MAX_CONNECTIONS]; | ||||||
|  | 	World* m_world = nullptr; | ||||||
|  |  | ||||||
|  | 	std::string Timestamp(); | ||||||
|  | 	void Log(std::string str, bool is_error, bool is_fatal); | ||||||
|  | }; | ||||||
|  | #endif | ||||||
| @@ -112,8 +112,8 @@ | |||||||
|   <PropertyGroup Label="UserMacros" /> |   <PropertyGroup Label="UserMacros" /> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||||||
|     <LinkIncremental>true</LinkIncremental> |     <LinkIncremental>true</LinkIncremental> | ||||||
|     <IncludePath>external\irrKlang-1.6.0\include;external\glew170\include;external\devil178\include;external\sfml23\include;$(IncludePath)</IncludePath> |     <IncludePath>external\irrKlang-1.6.0\include;external\glew210\include;external\devil178\include;external\sfml251\include;$(IncludePath)</IncludePath> | ||||||
|     <LibraryPath>external\glew170\lib;external\devil178\lib;external\sfml23\lib;$(LibraryPath);external\irrKlang-1.6.0\lib\Win32-visualStudio</LibraryPath> |     <LibraryPath>external\glew210\lib;external\sfml251\lib;external\devil178\lib;external\irrKlang-1.6.0\lib\Win32-visualStudio;$(LibraryPath)</LibraryPath> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||||
|     <LinkIncremental>true</LinkIncremental> |     <LinkIncremental>true</LinkIncremental> | ||||||
| @@ -122,8 +122,8 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||||||
|     <LinkIncremental>false</LinkIncremental> |     <LinkIncremental>false</LinkIncremental> | ||||||
|     <IncludePath>external\irrKlang-1.6.0\include;external\sfml23\include;external\devil178\include;external\glew170\include;$(IncludePath)</IncludePath> |     <IncludePath>external\devil180\include;external\irrKlang-1.6.0\include;external\sfml251\include;external\glew210\include;$(IncludePath)</IncludePath> | ||||||
|     <LibraryPath>external\sfml23\lib;external\devil178\lib;external\glew170\lib;$(LibraryPath);external\irrKlang-1.6.0\lib\Win32-visualStudio</LibraryPath> |     <LibraryPath>external\sfml251\lib;external\devil180\lib\x86\Release;external\glew210\lib\Release\Win32;$(LibraryPath);external\irrKlang-1.6.0\lib\Win32-visualStudio</LibraryPath> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||||||
|     <LinkIncremental>false</LinkIncremental> |     <LinkIncremental>false</LinkIncremental> | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ Audio::Audio(const char * music) { | |||||||
| 	m_engine->setRolloffFactor(1); | 	m_engine->setRolloffFactor(1); | ||||||
| 	m_engine->setDefault3DSoundMinDistance(1); | 	m_engine->setDefault3DSoundMinDistance(1); | ||||||
| 	m_engine->setDefault3DSoundMaxDistance(1000); | 	m_engine->setDefault3DSoundMaxDistance(1000); | ||||||
| 	m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING); | 	m_music = m_engine->play2D(music, false, true, true, irrklang::ESM_STREAMING); | ||||||
| } | } | ||||||
|  |  | ||||||
| Audio::~Audio() {  | Audio::~Audio() {  | ||||||
| @@ -40,9 +40,9 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v | |||||||
| 	sound->setVolume(volume); | 	sound->setVolume(volume); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Audio::PlaySong(const char* music) { | //void Audio::PlaySong(const char* music) { | ||||||
| 	m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING); | //	m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING); | ||||||
| } | //} | ||||||
|  |  | ||||||
| void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); } | void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ public: | |||||||
|  |  | ||||||
| 	void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume); | 	void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume); | ||||||
|  |  | ||||||
| 	void PlaySong(const char* music); | 	//void PlaySong(const char* music); | ||||||
|  |  | ||||||
| 	void ToggleMusicState(); | 	void ToggleMusicState(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ | |||||||
| #include <SFML/Window.hpp> | #include <SFML/Window.hpp> | ||||||
| #include <SFML/Graphics.hpp> | #include <SFML/Graphics.hpp> | ||||||
| #include <iostream> | #include <iostream> | ||||||
|  | #include <iomanip> | ||||||
|  |  | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
| #include <windows.h> | #include <windows.h> | ||||||
| @@ -12,55 +13,33 @@ | |||||||
| #include <gl/GLU.h> | #include <gl/GLU.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #define CHUNK_SIZE_X  16 | #define CHUNK_SIZE_X  4 | ||||||
| #define CHUNK_SIZE_Y  128 | #define CHUNK_SIZE_Y  64 | ||||||
| #define CHUNK_SIZE_Z  16 | #define CHUNK_SIZE_Z  4 | ||||||
| #define MAX_SELECTION_DISTANCE 5 | #define MAX_SELECTION_DISTANCE 5 | ||||||
|  | #define BASE_WIDTH 640 | ||||||
|  | #define BASE_HEIGHT 480 | ||||||
| #define SEED 12345 | #define SEED 12345 | ||||||
|  |  | ||||||
| #ifdef _DEBUG |  | ||||||
| #define WORLD_SIZE_X 64 | #define WORLD_SIZE_X 64 | ||||||
| #define WORLD_SIZE_Y 64 | #define WORLD_SIZE_Y 64 | ||||||
|  |  | ||||||
| #define FRAMES_RENDER_CHUNKS 4 |  | ||||||
| #define FRAMES_UPDATE_CHUNKS 4 |  | ||||||
| #define FRAMES_DELETE_CHUNKS 4 |  | ||||||
|  |  | ||||||
| #define THREADS_GENERATE_CHUNKS 1 |  | ||||||
| #define THREADS_UPDATE_CHUNKS 1 |  | ||||||
| #define THREADS_DELETE_CHUNKS 1 |  | ||||||
|  |  | ||||||
| #define VIEW_DISTANCE 256 |  | ||||||
| #define TEXTURE_SIZE 128 |  | ||||||
| #define MAX_BULLETS 64 |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifdef NDEBUG |  | ||||||
| #define WORLD_SIZE_X 16 |  | ||||||
| #define WORLD_SIZE_Y 16 |  | ||||||
|  |  | ||||||
| #define FRAMES_RENDER_CHUNKS 1 | #define FRAMES_RENDER_CHUNKS 1 | ||||||
| #define FRAMES_UPDATE_CHUNKS 1 | #define FRAMES_UPDATE_CHUNKS 1 | ||||||
| #define FRAMES_DELETE_CHUNKS 1 | #define FRAMES_DELETE_CHUNKS 1 | ||||||
|  |  | ||||||
| #define THREADS_GENERATE_CHUNKS 12 | #define THREADS_GENERATE_CHUNKS 8 | ||||||
| #define THREADS_UPDATE_CHUNKS 5 | #define THREADS_UPDATE_CHUNKS 3 | ||||||
| #define THREADS_DELETE_CHUNKS 2 | #define THREADS_DELETE_CHUNKS 3 | ||||||
|  |  | ||||||
| #define VIEW_DISTANCE 1024 | #define VIEW_DISTANCE 512 | ||||||
| #define TEXTURE_SIZE 512 | #define TEXTURE_SIZE 512 | ||||||
| #define MAX_BULLETS 512 | #define MAX_BULLETS 512 | ||||||
| #endif |  | ||||||
|  |  | ||||||
|  |  | ||||||
| typedef uint8_t BlockType; | typedef uint8_t BlockType; | ||||||
| enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; | enum BLOCK_TYPE { BTYPE_AIR, BTYPE_DIRT, BTYPE_GRASS, BTYPE_METAL, BTYPE_ICE, BTYPE_LAST }; | ||||||
|  |  | ||||||
| //#define TEXTURE_PATH        "../SQCSim2021/media/textures/" |  | ||||||
| //#define SHADER_PATH		    "../SQCSim2021/media/shaders/" |  | ||||||
| //#define AUDIO_PATH			"../SQCSim2021/media/audio/" |  | ||||||
| //#define CHUNK_PATH			"../SQCSim2021/media/chunks/" |  | ||||||
|  |  | ||||||
| #define TEXTURE_PATH        "./media/textures/" | #define TEXTURE_PATH        "./media/textures/" | ||||||
| #define SHADER_PATH		    "./media/shaders/" | #define SHADER_PATH		    "./media/shaders/" | ||||||
| #define AUDIO_PATH			"./media/audio/" | #define AUDIO_PATH			"./media/audio/" | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| #include "transformation.h" | #include "transformation.h" | ||||||
| #include "player.h" | #include "player.h" | ||||||
|  |  | ||||||
| Engine::Engine() { } | Engine::Engine() {} | ||||||
|  |  | ||||||
| Engine::~Engine() { | Engine::~Engine() { | ||||||
| 	m_world.CleanUpWorld(m_renderCount, true); | 	m_world.CleanUpWorld(m_renderCount, true); | ||||||
| @@ -21,24 +21,25 @@ void Engine::Init() { | |||||||
| 		abort(); | 		abort(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	glDisable(GL_FRAMEBUFFER_SRGB); | 	//glDisable(GL_FRAMEBUFFER_SRGB); | ||||||
| 	glClearColor(0.f, 0.f, 0.f, 1.f); | 	//glEnable(GL_DEPTH_TEST); | ||||||
|  | 	//glEnable(GL_STENCIL_TEST); | ||||||
|  | 	//glEnable(GL_POINT_SMOOTH); | ||||||
|  | 	//glEnable(GL_BLEND); | ||||||
|  | 	glEnable(GL_CULL_FACE); | ||||||
| 	glEnable(GL_TEXTURE_2D); | 	glEnable(GL_TEXTURE_2D); | ||||||
|  |  | ||||||
| 	glMatrixMode(GL_PROJECTION); | 	glMatrixMode(GL_PROJECTION); | ||||||
| 	glLoadIdentity(); | 	glLoadIdentity(); | ||||||
|  |  | ||||||
| 	gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE); | 	gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE); | ||||||
| 	glEnable(GL_DEPTH_TEST); |  | ||||||
| 	glEnable(GL_STENCIL_TEST); |  | ||||||
| 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |  | ||||||
| 	glShadeModel(GL_SMOOTH); | 	glShadeModel(GL_SMOOTH); | ||||||
|  |  | ||||||
| 	glEnable(GL_POINT_SMOOTH); | 	//glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | ||||||
| 	glEnable(GL_CULL_FACE); | 	//glDisable(GL_BLEND); | ||||||
|  | 	//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||||
| 	glEnable(GL_BLEND); | 	//glBlendEquation(GL_FUNC_SUBTRACT); | ||||||
| 	glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); | 	//  | ||||||
| 	glBlendEquation(GL_FUNC_SUBTRACT); |  | ||||||
|  |  | ||||||
| 	// Objet de skybox avec sa propre texture et son propre shader! | 	// Objet de skybox avec sa propre texture et son propre shader! | ||||||
| 	m_skybox.Init(0.2f); | 	m_skybox.Init(0.2f); | ||||||
|  |  | ||||||
| @@ -57,12 +58,14 @@ void Engine::Init() { | |||||||
| 	HideCursor(); | 	HideCursor(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Engine::DeInit() { } | void Engine::DeInit() {} | ||||||
|  |  | ||||||
| void Engine::LoadResource() { | void Engine::LoadResource() { | ||||||
| 	LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png"); | 	LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); | ||||||
| 	LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp"); | 	LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); | ||||||
| 	LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp"); | 	LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); | ||||||
|  | 	LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false); | ||||||
|  |  | ||||||
| 	TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); | 	TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); | ||||||
| 	TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); | 	TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); | ||||||
| 	TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); | 	TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); | ||||||
| @@ -97,92 +100,221 @@ void Engine::LoadResource() { | |||||||
|  |  | ||||||
| void Engine::UnloadResource() {} | void Engine::UnloadResource() {} | ||||||
|  |  | ||||||
| void Engine::DrawHud(float elapsedTime, BlockType bloc) { | void Engine::DisplayCrosshair() { | ||||||
| 	// Setter le blend function , tout ce qui sera noir sera transparent |  | ||||||
| 	glDisable(GL_STENCIL_TEST); |  | ||||||
| 	glColor4f(1.f, 1.f, 1.f, 1.f); |  | ||||||
| 	glBlendFunc(GL_SRC_ALPHA, GL_ONE); |  | ||||||
| 	glBlendEquation(GL_FUNC_ADD); |  | ||||||
| 	glDisable(GL_DEPTH_TEST); |  | ||||||
| 	glMatrixMode(GL_PROJECTION); |  | ||||||
| 	glPushMatrix(); |  | ||||||
| 	glLoadIdentity(); |  | ||||||
| 	glOrtho(0, Width(), 0, Height(), -1, 1); |  | ||||||
| 	glMatrixMode(GL_MODELVIEW); |  | ||||||
| 	glPushMatrix(); |  | ||||||
|  |  | ||||||
| 	// Bind de la texture pour le font |  | ||||||
| 	m_textureFont.Bind(); |  | ||||||
| 	std::ostringstream ss; |  | ||||||
| 	ss << " Fps : " << GetFps(elapsedTime); |  | ||||||
| 	PrintText(10, Height() - 25, ss.str()); |  | ||||||
| 	ss.str(""); |  | ||||||
| 	ss << " Rendered Chunks : " << m_renderCount; |  | ||||||
| 	PrintText(10, Height() - 35, ss.str()); |  | ||||||
| 	ss.str(""); |  | ||||||
| 	ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted(); |  | ||||||
| 	PrintText(10, Height() - 45, ss.str()); |  | ||||||
| 	ss.str(""); |  | ||||||
| 	ss << " Velocity  : " << m_player.GetVelocity(); // IMPORTANT : on utilise l <20> operateur << pour afficher la position |  | ||||||
| 	PrintText(10, 10, ss.str()); |  | ||||||
| 	ss.str(""); |  | ||||||
| 	ss << " Direction : " << m_player.GetDirection(); |  | ||||||
| 	PrintText(10, 20, ss.str()); |  | ||||||
| 	ss.str(""); |  | ||||||
| 	ss << " Position  : " << m_player.GetPosition(); |  | ||||||
| 	PrintText(10, 30, ss.str()); |  | ||||||
| 	ss.str(""); |  | ||||||
| 	ss << " Block  : "; |  | ||||||
| 	if (bloc == BTYPE_LAST) |  | ||||||
| 		ss << "Weapon."; |  | ||||||
| 	else ss << (int)bloc; |  | ||||||
| 	PrintText(10, 40, ss.str()); |  | ||||||
| 	m_textureCrosshair.Bind(); | 	m_textureCrosshair.Bind(); | ||||||
| 	static const int crossSize = 32; | 	static const int crossSize = 32; | ||||||
| 	glLoadIdentity(); | 	glLoadIdentity(); | ||||||
| 	glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0); | 	glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0); | ||||||
| 	glBegin(GL_QUADS); | 	glBegin(GL_QUADS); | ||||||
| 	glTexCoord2f(0, 0); | 		glTexCoord2f(0, 0); | ||||||
| 	glVertex2i(0, 0); | 		glVertex2i(0, 0); | ||||||
| 	glTexCoord2f(1, 0); | 		glTexCoord2f(1, 0); | ||||||
| 	glVertex2i(crossSize, 0); | 		glVertex2i(crossSize, 0); | ||||||
| 	glTexCoord2f(1, 1); | 		glTexCoord2f(1, 1); | ||||||
| 	glVertex2i(crossSize, crossSize); | 		glVertex2i(crossSize, crossSize); | ||||||
| 	glTexCoord2f(0, 1); | 		glTexCoord2f(0, 1); | ||||||
| 	glVertex2i(0, crossSize); | 		glVertex2i(0, crossSize); | ||||||
| 	glEnd(); | 	glEnd(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::DisplayCurrentItem() { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::DisplayHud(int timer) { | ||||||
|  | 	glBindTexture(GL_TEXTURE_2D, 0); | ||||||
|  | 	glLoadIdentity(); | ||||||
|  | 	glDisable(GL_BLEND); | ||||||
|  |  | ||||||
|  | 	// Barre HP | ||||||
|  | 	float fBarWidth = Width() / 4; | ||||||
|  | 	float fBarHeight = Height() / 25; | ||||||
|  | 	float fPosX = Width() / 20; | ||||||
|  | 	float fPosY = Height() - (Height() - (fBarHeight * 4)); | ||||||
|  | 	float playerHp = m_player.GetHP(); | ||||||
|  | 	float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f; | ||||||
|  |  | ||||||
|  | 	// Arri<72>re-plan (Barre HP) | ||||||
|  | 	glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); | ||||||
|  | 	glBegin(GL_QUADS); | ||||||
|  | 		glVertex2f(fPosX, fPosY - fBarHeight);				// Bas-Gauche | ||||||
|  | 		glVertex2f(fPosX + fBarWidth, fPosY - fBarHeight);  // Bas-Droite | ||||||
|  | 		glVertex2f(fPosX + fBarWidth, fPosY);				// Haut-Droite | ||||||
|  | 		glVertex2f(fPosX, fPosY);							// Haut-Gauche | ||||||
|  | 	glEnd(); | ||||||
|  |  | ||||||
|  | 	//TODO: Associer avec m<>chanique de vie du joueur | ||||||
|  |  | ||||||
|  | 	// Barre HP | ||||||
|  | 	glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage); | ||||||
|  | 	glBegin(GL_QUADS); | ||||||
|  | 		glVertex2f(fPosX, fPosY - fBarHeight);							// Bas-Gauche | ||||||
|  | 		glVertex2f(fPosX + fBarWidth * playerHp, fPosY - fBarHeight);	// Bas-Droite | ||||||
|  | 		glVertex2f(fPosX + fBarWidth * playerHp, fPosY);				// Haut-Droite | ||||||
|  | 		glVertex2f(fPosX, fPosY);										// Haut-Gauche | ||||||
|  | 	glEnd(); | ||||||
|  |  | ||||||
|  | 	// Barre <20>quip | ||||||
|  | 	glEnable(GL_BLEND); | ||||||
|  | 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||||
|  | 	glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); | ||||||
|  | 	m_textureGun.Bind(); | ||||||
|  |  | ||||||
|  | 	float margin = Width() * 0.05; | ||||||
|  | 	float itemWidth = Width() * 0.33; | ||||||
|  | 	float itemHeight = itemWidth / 2.208; | ||||||
|  | 	float startX = Width() - itemWidth - margin; | ||||||
|  | 	float startY = margin; | ||||||
|  |  | ||||||
|  | 	glTranslated(startX, startY, 0); | ||||||
|  |  | ||||||
|  | 	glBegin(GL_QUADS); | ||||||
|  | 	glTexCoord2f(1, 0); glVertex2i(0, 0); | ||||||
|  | 	glTexCoord2f(0, 0); glVertex2i(itemWidth, 0); | ||||||
|  | 	glTexCoord2f(0, 1); glVertex2i(itemWidth, itemHeight); | ||||||
|  | 	glTexCoord2f(1, 1); glVertex2i(0, itemHeight); | ||||||
|  | 	glEnd(); | ||||||
|  |  | ||||||
|  | 	glDisable(GL_BLEND); | ||||||
|  |  | ||||||
|  | 	// Username | ||||||
|  | 	glEnable(GL_BLEND); | ||||||
|  | 	glBlendFunc(GL_SRC_ALPHA, GL_ONE); | ||||||
|  |  | ||||||
|  | 	glColor3f(1.0f, 1.0f, 1.0f); | ||||||
|  | 	float scale = GetScale(); | ||||||
|  | 	m_textureFont.Bind(); | ||||||
|  | 	std::ostringstream ss; | ||||||
|  | 	ss << m_player.GetUsername(); | ||||||
|  | 	PrintText(fPosX, fPosY, scale, ss.str()); | ||||||
|  |  | ||||||
|  | 	//Countdown | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60; | ||||||
|  | 	PrintText(Width() - Width() * 0.15, Height() - (Height() / 19.2), scale, ss.str()); | ||||||
|  | 	 | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { | ||||||
|  | 	// Bind de la texture pour le font | ||||||
|  | 	m_textureFont.Bind(); | ||||||
|  | 	std::ostringstream ss; | ||||||
|  |  | ||||||
|  | 	float scale = GetScale(); | ||||||
|  | 	unsigned int x = Width() / 25; | ||||||
|  |  | ||||||
|  | 	ss << " Fps : " << GetFps(elapsedTime); | ||||||
|  | 	PrintText(x, Height() - (Height() / 19.2), scale, ss.str()); | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << " Rendered Chunks : " << m_renderCount; | ||||||
|  | 	PrintText(x, Height() - (Height() / 13.7), scale, ss.str()); | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << " To-Be-Deleted Chunks : " << m_world.GettbDeleted(); | ||||||
|  | 	PrintText(x, Height() - (Height() / 10.7), scale, ss.str()); | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << " Velocity  : " << m_player.GetVelocity(); // IMPORTANT : on utilise l <20> operateur << pour afficher la position | ||||||
|  | 	PrintText(x, Height() / 48, scale, ss.str()); | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << " Direction : " << m_player.GetDirection(); | ||||||
|  | 	PrintText(x, Height() / 24, scale, ss.str()); | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << " Position  : " << m_player.GetPosition(); | ||||||
|  | 	PrintText(x, Height() / 16, scale, ss.str()); | ||||||
|  | 	ss.str(""); | ||||||
|  | 	ss << " Block  : "; | ||||||
|  |  | ||||||
|  | 	if (bloc == BTYPE_LAST) | ||||||
|  | 		ss << "Weapon."; | ||||||
|  | 	else ss << (int)bloc; | ||||||
|  |  | ||||||
|  | 	PrintText(x, Height() / 12, scale, ss.str()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void Engine::DrawHud(float elapsedTime, BlockType bloc) { | ||||||
|  | 	// Setter le blend function, tout ce qui sera noir sera transparent | ||||||
|  | 	glDisable(GL_STENCIL_TEST); | ||||||
|  | 	glDisable(GL_DEPTH_TEST); | ||||||
|  |  | ||||||
|  | 	glBlendFunc(GL_SRC_ALPHA, GL_ONE); | ||||||
|  | 	glBlendEquation(GL_FUNC_ADD); | ||||||
|  |  | ||||||
|  | 	glMatrixMode(GL_PROJECTION); | ||||||
|  | 	glPushMatrix(); | ||||||
|  |  | ||||||
|  | 	glLoadIdentity(); | ||||||
|  | 	glOrtho(0, Width(), 0, Height(), -1, 1); | ||||||
|  |  | ||||||
|  | 	glMatrixMode(GL_MODELVIEW); | ||||||
|  | 	glPushMatrix(); | ||||||
|  |  | ||||||
|  | 	int timer = GetCountdown(elapsedTime); | ||||||
|  |  | ||||||
|  | 	if (m_displayInfo) { | ||||||
|  | 		DisplayInfo(elapsedTime, bloc); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (m_displayHud) { | ||||||
|  | 		DisplayHud(timer); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if (m_displayCrosshair) { | ||||||
|  | 		DisplayCrosshair(); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Reset du blend function | ||||||
| 	glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); | 	glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); | ||||||
| 	glBlendEquation(GL_FUNC_SUBTRACT); | 	glBlendEquation(GL_FUNC_SUBTRACT); | ||||||
| 	glEnable(GL_DEPTH_TEST); |  | ||||||
| 	glEnable(GL_STENCIL_TEST); | 	glEnable(GL_STENCIL_TEST); | ||||||
|  | 	glEnable(GL_DEPTH_TEST); | ||||||
|  |  | ||||||
| 	glMatrixMode(GL_PROJECTION); | 	glMatrixMode(GL_PROJECTION); | ||||||
| 	glPopMatrix(); | 	glPopMatrix(); | ||||||
|  |  | ||||||
| 	glMatrixMode(GL_MODELVIEW); | 	glMatrixMode(GL_MODELVIEW); | ||||||
| 	glPopMatrix(); | 	glPopMatrix(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Engine::PrintText(unsigned int x, unsigned int y, const std::string& t) { | void Engine::PrintText(float x, float y, float scale, const std::string& t) { | ||||||
| 	glLoadIdentity(); | 	glLoadIdentity(); | ||||||
| 	glTranslated(x, y, 0); | 	glTranslated(x, y, 0); | ||||||
|  |  | ||||||
| 	for (unsigned int i = 0; i < t.length(); ++i) { | 	for (unsigned int i = 0; i < t.length(); ++i) { | ||||||
| 		float left = (float)((t[i] - 32) % 16) / 16.f; | 		float left = (float)((t[i] - 32) % 16) / 16.f; | ||||||
| 		float top = (float)((t[i] - 32) / 16) / 16.f; | 		float top = (float)((t[i] - 32) / 16) / 16.f; | ||||||
| 		top += .5f; | 		top += .5f; | ||||||
|  |  | ||||||
| 		glBegin(GL_QUADS); | 		glBegin(GL_QUADS); | ||||||
| 		glTexCoord2f(left, 1.f - top - .0625f); | 			glTexCoord2f(left, 1.f - top - .0625f);			 glVertex2f(0, 0); | ||||||
| 		glVertex2f(0, 0); | 			glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(12 * scale, 0); | ||||||
| 		glTexCoord2f(left + .0625f, 1.f - top - .0625f); | 			glTexCoord2f(left + .0625f, 1.f - top);			 glVertex2f(12 * scale, 12 * scale); | ||||||
| 		glVertex2f(12, 0); | 			glTexCoord2f(left, 1.f - top);					 glVertex2f(0, 12 * scale); | ||||||
| 		glTexCoord2f(left + .0625f, 1.f - top); |  | ||||||
| 		glVertex2f(12, 12); |  | ||||||
| 		glTexCoord2f(left, 1.f - top); |  | ||||||
| 		glVertex2f(0, 12); |  | ||||||
| 		glEnd(); | 		glEnd(); | ||||||
| 		glTranslated(8, 0, 0); |  | ||||||
|  | 		glTranslated(8 * scale, 0, 0); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | float Engine::GetScale() const { | ||||||
|  | 	float widthRatio = Width() / BASE_WIDTH; | ||||||
|  | 	float heightRatio = Height() / BASE_HEIGHT; | ||||||
|  |  | ||||||
|  | 	return (widthRatio + heightRatio) / 2.0f; | ||||||
|  | } | ||||||
|  |  | ||||||
| int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } | int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } | ||||||
|  | int Engine::GetCountdown(float elapsedTime) { | ||||||
|  | 	if (m_resetcountdown) | ||||||
|  | 	{ | ||||||
|  | 		m_countdown = m_time + COUNTDOWN; | ||||||
|  | 		m_resetcountdown = false; | ||||||
|  | 	} | ||||||
|  | 	if (m_countdown < m_time) | ||||||
|  | 		Stop(); | ||||||
|  | 	if(!m_stopcountdown) | ||||||
|  | 		m_time += elapsedTime; | ||||||
|  | 	return m_countdown - (int)m_time; | ||||||
|  | } | ||||||
|  |  | ||||||
| void Engine::Render(float elapsedTime) { | void Engine::Render(float elapsedTime) { | ||||||
| 	//static float gameTime = elapsedTime; | 	//static float gameTime = elapsedTime; | ||||||
| @@ -207,16 +339,16 @@ void Engine::Render(float elapsedTime) { | |||||||
| 	if (bulletTime < 0.f) bulletTime = 0.f; | 	if (bulletTime < 0.f) bulletTime = 0.f; | ||||||
|  |  | ||||||
| 	if (pollTime >= .005f) { | 	if (pollTime >= .005f) { | ||||||
| 	m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime, &m_audio); | 		m_player.ApplyPhysics(m_player.GetInput(m_keyW, m_keyS, m_keyA, m_keyD, m_keySpace, (bloc == BTYPE_LAST && bulletTime <= 0.f && m_mouseL), elapsedTime), &m_world, elapsedTime, &m_audio); | ||||||
| 	m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<6E>es du joueur et | 		m_audio.Update3DAudio(m_player.GetPOV(), m_player.GetDirection(), m_player.GetVelocity()); // Ajustement du positionnement 3D avec les coordonn<6E>es du joueur et | ||||||
| 																									// son vecteur de v<>locit<69> (pour l'effet Doppler) | 		// son vecteur de v<>locit<69> (pour l'effet Doppler) | ||||||
| 	pollTime = 0; | 		pollTime = 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	m_player.ApplyTransformation(all); | 	m_player.ApplyTransformation(all); | ||||||
|  |  | ||||||
| 	m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation  | 	m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation  | ||||||
| 												// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!). | 	// (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!). | ||||||
|  |  | ||||||
| 	if (m_mouseWU) bloc++; | 	if (m_mouseWU) bloc++; | ||||||
| 	else if (m_mouseWD) bloc--; | 	else if (m_mouseWD) bloc--; | ||||||
| @@ -238,7 +370,7 @@ void Engine::Render(float elapsedTime) { | |||||||
| 					m_bullets[0] = new Bullet(m_player); | 					m_bullets[0] = new Bullet(m_player); | ||||||
| 				} | 				} | ||||||
| 			bulletTime = .1f; | 			bulletTime = .1f; | ||||||
| 			m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, .5f); | 			m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "windowsaccount.wav", m_player.GetPOV(), m_player.GetDirection() * 10, .5f); | ||||||
| 			if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash. | 			if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash. | ||||||
| 				glClearColor(.8f, .8f, .8f, 1.f); | 				glClearColor(.8f, .8f, .8f, 1.f); | ||||||
| 				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | 				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | ||||||
| @@ -261,11 +393,7 @@ void Engine::Render(float elapsedTime) { | |||||||
|  |  | ||||||
| 	if (m_isSkybox) m_skybox.Render(skybox); | 	if (m_isSkybox) m_skybox.Render(skybox); | ||||||
|  |  | ||||||
| 	if (m_wireframe) |  | ||||||
| 		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |  | ||||||
| 	DrawHud(elapsedTime, bloc); | 	DrawHud(elapsedTime, bloc); | ||||||
| 	if (m_wireframe) |  | ||||||
| 		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); |  | ||||||
| 	 | 	 | ||||||
| 	static bool fell = false; | 	static bool fell = false; | ||||||
| 	if (m_player.GetPosition().y < 1.7f && !fell) { | 	if (m_player.GetPosition().y < 1.7f && !fell) { | ||||||
| @@ -280,54 +408,58 @@ void Engine::Render(float elapsedTime) { | |||||||
|  |  | ||||||
| void Engine::KeyPressEvent(unsigned char key) { | void Engine::KeyPressEvent(unsigned char key) { | ||||||
| 	switch (key) { | 	switch (key) { | ||||||
| 	case 36: // ESC | 	case 0: // A - Gauche | ||||||
| 		Stop(); |  | ||||||
| 		break; |  | ||||||
| 	case 94: // F10 |  | ||||||
| 		SetFullscreen(!IsFullscreen()); |  | ||||||
| 		break; |  | ||||||
| 	case 22: // W |  | ||||||
| 		if (!m_keyW) { |  | ||||||
| 		//	std::cout << "W " << std::endl; |  | ||||||
| 			m_keyW = true; |  | ||||||
| 		} |  | ||||||
| 		break; |  | ||||||
| 	case 0: // A |  | ||||||
| 		if (!m_keyA) { | 		if (!m_keyA) { | ||||||
| 			//std::cout << "A " << std::endl; |  | ||||||
| 			m_keyA = true; | 			m_keyA = true; | ||||||
| 		} | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case 18: // S | 	case 3: // D - Droite | ||||||
| 		if (!m_keyS) { |  | ||||||
| 			//std::cout << "S " << std::endl; |  | ||||||
| 			m_keyS = true; |  | ||||||
| 		} |  | ||||||
| 		break; |  | ||||||
| 	case 3: // D |  | ||||||
| 		if (!m_keyD) { | 		if (!m_keyD) { | ||||||
| 			//std::cout << "D " << std::endl; |  | ||||||
| 			m_keyD = true; | 			m_keyD = true; | ||||||
| 		} | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case 38: // Left Shift | 	case 18: // S - Reculer | ||||||
| 		if (!m_keylshift) { | 		if (!m_keyS) { | ||||||
| 			//std::cout << "Dash!" << std::endl; | 			m_keyS = true; | ||||||
| 			m_keylshift = true; |  | ||||||
| 		} | 		} | ||||||
| 		break; | 		break; | ||||||
| 	case 57: // Space | 	case 22: // W - Avancer | ||||||
|  | 		if (!m_keyW) { | ||||||
|  | 			m_keyW = true; | ||||||
|  | 		} | ||||||
|  | 		break; | ||||||
|  | 	case 36: // ESC - Quitter | ||||||
|  | 		Stop(); | ||||||
|  | 		break; | ||||||
|  | 	case 57: // Space - Sauter | ||||||
| 		if (!m_keySpace) { | 		if (!m_keySpace) { | ||||||
| 			//std::cout << "Jump! " << std::endl; |  | ||||||
| 			m_keySpace = true; | 			m_keySpace = true; | ||||||
| 		} | 		} | ||||||
| 		break; | 		break; | ||||||
|  | 	case 94: // F10 - Plein <20>cran | ||||||
|  | 		IsFullscreen() ? SetFullscreen(false) : SetFullscreen(true); | ||||||
|  | 		//SetFullscreen(!IsFullscreen()); | ||||||
|  | 		break; | ||||||
|  | 	case 2: // C - Ignorer | ||||||
|  | 		break; | ||||||
| 	case 5: // F - Ignorer | 	case 5: // F - Ignorer | ||||||
| 	case 24: // Y - Ignorer | 		break; | ||||||
| 	case 255: // Fn - Ignorer | 	case 6: // G - Ignorer | ||||||
|  | 		break; | ||||||
| 	case 12: // M - Ignorer | 	case 12: // M - Ignorer | ||||||
|  | 		break; | ||||||
|  | 	case 7: // H - Ignorer | ||||||
|  | 		break; | ||||||
|  | 	case 8: // I - Ignorer | ||||||
|  | 		break; | ||||||
| 	case 17: // R - Ignorer | 	case 17: // R - Ignorer | ||||||
| 		break; | 		break; | ||||||
|  | 	case 19: // T - Ignorer | ||||||
|  | 		break;  | ||||||
|  | 	case 24: // Y - Ignorer | ||||||
|  | 		break; | ||||||
|  | 	case 255: // Fn - Ignorer | ||||||
|  | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		std::cout << "Unhandled key: " << (int)key << std::endl; | 		std::cout << "Unhandled key: " << (int)key << std::endl; | ||||||
| 	} | 	} | ||||||
| @@ -335,44 +467,55 @@ void Engine::KeyPressEvent(unsigned char key) { | |||||||
|  |  | ||||||
| void Engine::KeyReleaseEvent(unsigned char key) { | void Engine::KeyReleaseEvent(unsigned char key) { | ||||||
| 	switch (key) { | 	switch (key) { | ||||||
| 	case 5: | 	case 0: // A - Stop gauche | ||||||
|  | 		m_keyA = false; | ||||||
|  | 		break; | ||||||
|  | 	case 2: // C - Toggle crosshair | ||||||
|  | 		m_displayCrosshair = !m_displayCrosshair; | ||||||
|  | 		std::cout << "DISPLAY CROSSHAIR " << (m_displayCrosshair ? "enabled" : "disabled") << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	case 3: // D - Stop droite | ||||||
|  | 		m_keyD = false; | ||||||
|  | 		break; | ||||||
|  | 	case 5: // F - Toggle flash | ||||||
| 		m_flash = !m_flash; | 		m_flash = !m_flash; | ||||||
| 		break; | 		break; | ||||||
| 	case 12: | 	case 6: // G - Toggle Stop Countdown | ||||||
|  | 		m_stopcountdown = !m_stopcountdown; | ||||||
|  | 		std::cout << "STOP COUNTDOWN " << (m_stopcountdown ? "enabled" : "disabled") << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	case 7: // H - Toggle HUD | ||||||
|  | 		m_displayHud = !m_displayHud; | ||||||
|  | 		std::cout << "DISPLAY HUD " << (m_displayHud ? "enabled" : "disabled") << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	case 8: // I - Toggle render data | ||||||
|  | 		m_displayInfo = !m_displayInfo; | ||||||
|  | 		std::cout << "DISPLAY INFO " << (m_displayInfo ? "enabled" : "disabled") << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	case 12: // M - Toggle music | ||||||
| 		m_audio.ToggleMusicState(); | 		m_audio.ToggleMusicState(); | ||||||
| 		break; | 		break; | ||||||
| 	case 17: | 	case 17: // R - Toggle skybox | ||||||
| 		m_isSkybox = !m_isSkybox; | 		m_isSkybox = !m_isSkybox; | ||||||
| 		break; | 		break; | ||||||
| 	case 24: // Y | 	case 18: // S - Stop reculer | ||||||
|  | 		m_keyS = false; | ||||||
|  | 		break; | ||||||
|  | 	case 19: // T -Reset countdown | ||||||
|  | 		m_resetcountdown = true; | ||||||
|  | 		std::cout << "RESET COUNTDOWN" << std::endl; | ||||||
|  | 		break; | ||||||
|  | 	case 22: // W - Stop avancer | ||||||
|  | 		m_keyW = false; | ||||||
|  | 		break; | ||||||
|  | 	case 24: // Y - Wireframe | ||||||
| 		m_wireframe = !m_wireframe; | 		m_wireframe = !m_wireframe; | ||||||
| 		if (m_wireframe) | 		if (m_wireframe) | ||||||
| 			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | 			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | ||||||
| 		else | 		else | ||||||
| 			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | 			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | ||||||
| 		break; | 		break; | ||||||
| 	case 22: // W | 	case 57: // Espace - Stop sauter | ||||||
| 		//std::cout << "rW " << std::endl; |  | ||||||
| 		m_keyW = false; |  | ||||||
| 		break; |  | ||||||
| 	case 0: // A |  | ||||||
| 		//std::cout << "rA " << std::endl; |  | ||||||
| 		m_keyA = false; |  | ||||||
| 		break; |  | ||||||
| 	case 18: // S |  | ||||||
| 		//std::cout << "rS " << std::endl; |  | ||||||
| 		m_keyS = false; |  | ||||||
| 		break; |  | ||||||
| 	case 3: // D |  | ||||||
| 		//std::cout << "rD " << std::endl; |  | ||||||
| 		m_keyD = false; |  | ||||||
| 		break; |  | ||||||
| 	case 38: // Left Shift |  | ||||||
| 		//std::cout << "rLS " << std::endl; |  | ||||||
| 		m_keylshift = false; |  | ||||||
| 		break; |  | ||||||
| 	case 57: // Espace |  | ||||||
| 		//std::cout << "rSpace " << std::endl; |  | ||||||
| 		m_keySpace = false; | 		m_keySpace = false; | ||||||
| 		break; | 		break; | ||||||
| 	} | 	} | ||||||
| @@ -437,10 +580,9 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool stopOnError) { | bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps, bool stopOnError) { | ||||||
| 	texture.Load(filename); | 	texture.Load(filename, useMipmaps); | ||||||
| 	if (!texture.IsValid()) | 	if (!texture.IsValid()) { | ||||||
| 	{ |  | ||||||
| 		std::cerr << "Unable to load texture (" << filename << ")" << std::endl; | 		std::cerr << "Unable to load texture (" << filename << ")" << std::endl; | ||||||
| 		if (stopOnError) | 		if (stopOnError) | ||||||
| 			Stop(); | 			Stop(); | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #ifndef ENGINE_H__ | #ifndef ENGINE_H__ | ||||||
| #define ENGINE_H__ | #define ENGINE_H__ | ||||||
|  |  | ||||||
| #include "define.h" | #include "define.h" | ||||||
| #include "openglcontext.h" | #include "openglcontext.h" | ||||||
| #include "texture.h" | #include "texture.h" | ||||||
| @@ -31,15 +32,19 @@ public: | |||||||
|     virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); |     virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     bool LoadTexture(Texture& texture, const std::string& filename, bool stopOnError = true); |     float GetScale() const; | ||||||
|     void DrawHud(float elapsedTime, BlockType bloc); |  | ||||||
|     void PrintText(unsigned int x, unsigned int y, const std::string& t); |  | ||||||
|     int GetFps(float elapsedTime) const; |     int GetFps(float elapsedTime) const; | ||||||
|  |     int GetCountdown(float elapsedTime); | ||||||
|  |  | ||||||
|     bool m_wireframe = false; |     bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); | ||||||
|     bool m_isSkybox = true; |  | ||||||
|  |  | ||||||
|     int m_renderCount = 0; |     void DisplayCrosshair(); | ||||||
|  |     void DisplayCurrentItem(); | ||||||
|  |     void DisplayHud(int timer); | ||||||
|  |     void DisplayInfo(float elapsedTime, BlockType bloc); | ||||||
|  |     void DrawHud(float elapsedTime, BlockType bloc); | ||||||
|  |     void PrintText(float x, float y, float scale, const std::string& t); | ||||||
|  |  | ||||||
|     Shader m_shader01; |     Shader m_shader01; | ||||||
|     BlockInfo* m_blockinfo[BTYPE_LAST]; |     BlockInfo* m_blockinfo[BTYPE_LAST]; | ||||||
| @@ -50,9 +55,10 @@ private: | |||||||
|     Texture m_textureSkybox; |     Texture m_textureSkybox; | ||||||
|     Texture m_textureFont; |     Texture m_textureFont; | ||||||
|     Texture m_textureCrosshair; |     Texture m_textureCrosshair; | ||||||
|  |     Texture m_textureGun; | ||||||
|  |  | ||||||
|     Skybox m_skybox; |     Skybox m_skybox; | ||||||
|     Audio m_audio = Audio(AUDIO_PATH "music01.wav"); |     Audio m_audio = Audio(AUDIO_PATH "start.wav"); | ||||||
|  |  | ||||||
|     irrklang::ISound* m_powpow; |     irrklang::ISound* m_powpow; | ||||||
|     irrklang::ISound* m_scream; |     irrklang::ISound* m_scream; | ||||||
| @@ -61,21 +67,32 @@ private: | |||||||
|  |  | ||||||
|     Bullet* m_bullets[MAX_BULLETS]; |     Bullet* m_bullets[MAX_BULLETS]; | ||||||
|  |  | ||||||
|  |     float m_scale; | ||||||
|  |     float m_time = 0; | ||||||
|  |  | ||||||
|  |     int m_renderCount = 0; | ||||||
|  |     int m_countdown = COUNTDOWN; | ||||||
|  |  | ||||||
|  |     bool m_wireframe = false; | ||||||
|  |     bool m_isSkybox = true; | ||||||
|  |     bool m_block = false; | ||||||
|  |     bool m_flash = true; | ||||||
|  |     bool m_displayCrosshair = true; | ||||||
|  |     bool m_displayHud = true; | ||||||
|  |     bool m_displayInfo = false; | ||||||
|  |     bool m_resetcountdown = false; | ||||||
|  |     bool m_stopcountdown = false; | ||||||
|  |      | ||||||
|     bool m_keyW = false; |     bool m_keyW = false; | ||||||
|     bool m_keyA = false; |     bool m_keyA = false; | ||||||
|     bool m_keyS = false; |     bool m_keyS = false; | ||||||
|     bool m_keyD = false; |     bool m_keyD = false; | ||||||
|     bool m_keylshift = false; |  | ||||||
|     bool m_keySpace = false; |     bool m_keySpace = false; | ||||||
|     bool m_mouseL = false; |     bool m_mouseL = false; | ||||||
|     bool m_mouseR = false; |     bool m_mouseR = false; | ||||||
|     bool m_mouseC = false; |     bool m_mouseC = false; | ||||||
|     bool m_mouseWU = false; |     bool m_mouseWU = false; | ||||||
|     bool m_mouseWD = false; |     bool m_mouseWD = false; | ||||||
|  |  | ||||||
|     bool m_block = false; |  | ||||||
|     bool m_flash = true; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| #endif // ENGINE_H__ | #endif // ENGINE_H__ | ||||||
|   | |||||||
| @@ -5,5 +5,5 @@ | |||||||
| int main() { | int main() { | ||||||
|     Engine engine; |     Engine engine; | ||||||
|     engine.SetMaxFps(60); |     engine.SetMaxFps(60); | ||||||
|     engine.Start("Syndicat Quebecois de la Construction Simulator 2023", 640, 480, false); |     engine.Start("Syndicat Quebecois de la Construction Simulator 2023", BASE_WIDTH, BASE_HEIGHT, false); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/audio/notify.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/audio/start.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								SQCSim2021/media/audio/windowsaccount.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 262 KiB | 
| After Width: | Height: | Size: 261 KiB | 
| After Width: | Height: | Size: 363 KiB | 
| After Width: | Height: | Size: 363 KiB | 
| After Width: | Height: | Size: 249 KiB | 
| After Width: | Height: | Size: 308 KiB | 
| After Width: | Height: | Size: 370 KiB | 
| After Width: | Height: | Size: 370 KiB | 
| After Width: | Height: | Size: 249 KiB | 
| After Width: | Height: | Size: 308 KiB | 
| After Width: | Height: | Size: 254 KiB | 
| After Width: | Height: | Size: 255 KiB | 
| After Width: | Height: | Size: 270 KiB | 
| After Width: | Height: | Size: 269 KiB | 
| After Width: | Height: | Size: 310 KiB | 
| After Width: | Height: | Size: 310 KiB | 
| After Width: | Height: | Size: 359 KiB | 
| After Width: | Height: | Size: 360 KiB | 
| After Width: | Height: | Size: 367 KiB | 
| After Width: | Height: | Size: 368 KiB | 
| After Width: | Height: | Size: 327 KiB | 
| After Width: | Height: | Size: 348 KiB | 
| After Width: | Height: | Size: 382 KiB | 
| After Width: | Height: | Size: 327 KiB | 
| After Width: | Height: | Size: 329 KiB | 
| After Width: | Height: | Size: 362 KiB | 
| After Width: | Height: | Size: 641 KiB | 
| After Width: | Height: | Size: 654 KiB | 
| After Width: | Height: | Size: 651 KiB | 
| After Width: | Height: | Size: 640 KiB | 
| After Width: | Height: | Size: 654 KiB | 
| After Width: | Height: | Size: 650 KiB | 
| After Width: | Height: | Size: 474 KiB | 
| After Width: | Height: | Size: 501 KiB | 
| After Width: | Height: | Size: 563 KiB | 
| After Width: | Height: | Size: 473 KiB | 
| After Width: | Height: | Size: 500 KiB | 
| After Width: | Height: | Size: 563 KiB | 
| After Width: | Height: | Size: 698 KiB | 
| After Width: | Height: | Size: 719 KiB | 
| After Width: | Height: | Size: 735 KiB | 
| After Width: | Height: | Size: 698 KiB | 
| After Width: | Height: | Size: 719 KiB | 
| After Width: | Height: | Size: 735 KiB | 
| After Width: | Height: | Size: 760 KiB | 
| After Width: | Height: | Size: 783 KiB | 
| After Width: | Height: | Size: 804 KiB | 
| After Width: | Height: | Size: 760 KiB | 
| After Width: | Height: | Size: 783 KiB | 
| After Width: | Height: | Size: 804 KiB | 
| After Width: | Height: | Size: 276 KiB | 
| After Width: | Height: | Size: 276 KiB | 
| After Width: | Height: | Size: 315 KiB | 
| After Width: | Height: | Size: 315 KiB | 
| After Width: | Height: | Size: 338 KiB | 
| After Width: | Height: | Size: 395 KiB | 
| After Width: | Height: | Size: 395 KiB | 
| After Width: | Height: | Size: 338 KiB | 
| After Width: | Height: | Size: 258 KiB | 
| After Width: | Height: | Size: 258 KiB | 
| After Width: | Height: | Size: 655 KiB | 
| After Width: | Height: | Size: 658 KiB | 
| After Width: | Height: | Size: 679 KiB |