Projet server.
This commit is contained in:
parent
cf75843117
commit
c3058070e5
154
SQCSim-common/SQCSim-common.vcxproj
Normal file
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
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
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
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
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
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
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
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
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
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__
|
49
SQCSim-common/define.h
Normal file
49
SQCSim-common/define.h
Normal file
@ -0,0 +1,49 @@
|
||||
#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
|
||||
|
||||
#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
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
2542
SQCSim-common/opensimplex.cpp
Normal file
File diff suppressed because it is too large
Load Diff
51
SQCSim-common/opensimplex.h
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__
|
160
SQCSim-common/player.cpp
Normal file
160
SQCSim-common/player.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
#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) {
|
||||
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) {
|
||||
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
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
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
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
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__
|
||||
|
138
SQCSim-srv/SQCSim-srv.vcxproj
Normal file
138
SQCSim-srv/SQCSim-srv.vcxproj
Normal file
@ -0,0 +1,138 @@
|
||||
<?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>
|
||||
</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></ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
17
SQCSim-srv/SQCSim-srv.vcxproj.filters
Normal file
17
SQCSim-srv/SQCSim-srv.vcxproj.filters
Normal file
@ -0,0 +1,17 @@
|
||||
<?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>
|
||||
</Project>
|
@ -112,8 +112,8 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>external\irrKlang-1.6.0\include;external\glew170\include;external\devil178\include;external\sfml23\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>external\glew170\lib;external\devil178\lib;external\sfml23\lib;$(LibraryPath);external\irrKlang-1.6.0\lib\Win32-visualStudio</LibraryPath>
|
||||
<IncludePath>external\irrKlang-1.6.0\include;external\glew210\include;external\devil178\include;external\sfml251\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>external\glew210\lib;external\sfml251\lib;external\devil178\lib;external\irrKlang-1.6.0\lib\Win32-visualStudio;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
@ -122,8 +122,8 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>external\irrKlang-1.6.0\include;external\sfml23\include;external\devil178\include;external\glew170\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>external\sfml23\lib;external\devil178\lib;external\glew170\lib;$(LibraryPath);external\irrKlang-1.6.0\lib\Win32-visualStudio</LibraryPath>
|
||||
<IncludePath>external\devil180\include;external\irrKlang-1.6.0\include;external\sfml251\include;external\glew210\include;$(IncludePath)</IncludePath>
|
||||
<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 Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include <gl/GLU.h>
|
||||
#endif
|
||||
|
||||
#define CHUNK_SIZE_X 16
|
||||
#define CHUNK_SIZE_Y 128
|
||||
#define CHUNK_SIZE_Z 16
|
||||
#define CHUNK_SIZE_X 4
|
||||
#define CHUNK_SIZE_Y 64
|
||||
#define CHUNK_SIZE_Z 4
|
||||
#define MAX_SELECTION_DISTANCE 5
|
||||
#define SEED 12345
|
||||
|
||||
@ -36,18 +36,18 @@
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define WORLD_SIZE_X 16
|
||||
#define WORLD_SIZE_Y 16
|
||||
#define WORLD_SIZE_X 64
|
||||
#define WORLD_SIZE_Y 64
|
||||
|
||||
#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_GENERATE_CHUNKS 6
|
||||
#define THREADS_UPDATE_CHUNKS 3
|
||||
#define THREADS_DELETE_CHUNKS 2
|
||||
|
||||
#define VIEW_DISTANCE 1024
|
||||
#define VIEW_DISTANCE 512
|
||||
#define TEXTURE_SIZE 512
|
||||
#define MAX_BULLETS 512
|
||||
#endif
|
||||
@ -56,11 +56,6 @@
|
||||
typedef uint8_t BlockType;
|
||||
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 SHADER_PATH "./media/shaders/"
|
||||
#define AUDIO_PATH "./media/audio/"
|
||||
|
@ -223,7 +223,7 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
direct.Normalize();
|
||||
pos.y = 1;
|
||||
|
||||
static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 4]; // Nombre de Chunks maximal à être rendus.
|
||||
static Vector3<unsigned int> renderManifest[VIEW_DISTANCE * 8]; // Nombre de Chunks maximal à être rendus.
|
||||
|
||||
//for (int dist = VIEW_DISTANCE; dist >= 0; dist -= CHUNK_SIZE_X) {
|
||||
for (int dist = 0; dist <= VIEW_DISTANCE; dist += CHUNK_SIZE_X) {
|
||||
@ -231,26 +231,26 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
float sinus, cosinus;
|
||||
int echantillons;
|
||||
|
||||
if (dist > VIEW_DISTANCE * .5f) {
|
||||
if (dist > VIEW_DISTANCE * .1f) {
|
||||
sinus = .00872653549f; // sin(1/2 degré)
|
||||
cosinus = .99996192306; // cos(1/2 degré)
|
||||
echantillons = 180;
|
||||
}
|
||||
else if (dist > VIEW_DISTANCE * .4f) {
|
||||
sinus = .01151891831f; // sin(2/3 degré)
|
||||
cosinus = .99993365506; // cos(2/3 degré)
|
||||
echantillons = 120;
|
||||
}
|
||||
else if (dist > VIEW_DISTANCE * .3f) {
|
||||
sinus = .01745240643; // sin(1 degré)
|
||||
cosinus = .99984769515; // cos(1 degré)
|
||||
echantillons = 90;
|
||||
}
|
||||
else if (dist > VIEW_DISTANCE * .2f) {
|
||||
sinus = .0261769483;
|
||||
cosinus = .99965732497;
|
||||
echantillons = 60;
|
||||
}
|
||||
//else if (dist > VIEW_DISTANCE * .3f) {
|
||||
// sinus = .01151891831f; // sin(2/3 degré)
|
||||
// cosinus = .99993365506; // cos(2/3 degré)
|
||||
// echantillons = 120;
|
||||
//}
|
||||
//else if (dist > VIEW_DISTANCE * .2f) {
|
||||
// sinus = .01745240643; // sin(1 degré)
|
||||
// cosinus = .99984769515; // cos(1 degré)
|
||||
// echantillons = 90;
|
||||
//}
|
||||
//else if (dist > VIEW_DISTANCE * .1f) {
|
||||
// sinus = .0261769483;
|
||||
// cosinus = .99965732497;
|
||||
// echantillons = 60;
|
||||
//}
|
||||
else {
|
||||
sinus = .0348994967;
|
||||
cosinus = .99939082701;
|
||||
@ -293,7 +293,7 @@ void World::RenderWorld(int& rendercount, Player& player, Transformation& world,
|
||||
|
||||
world.ApplyTranslation(chx, 0, chy);
|
||||
world.Use();
|
||||
float blcolor = renderManifest[index].y / (VIEW_DISTANCE * 1000.f);
|
||||
float blcolor = renderManifest[index].y / (VIEW_DISTANCE / 50.f);
|
||||
glBlendColor(blcolor, blcolor, blcolor, 1.f);
|
||||
ChunkAt(chx, 1, chy)->Render();
|
||||
world.ApplyTranslation(-chx, 0, -chy);
|
||||
|
@ -1,10 +1,14 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31702.278
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34031.279
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQCSim2021", "SQCSim2021\SQCSim2021.vcxproj", "{A21FD938-1FEA-4687-AB86-0EABAC30877B}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQCSim-common", "SQCSim-common\SQCSim-common.vcxproj", "{EE91AB12-4225-4A4D-931D-69D72F6D91FB}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQCSim-srv", "SQCSim-srv\SQCSim-srv.vcxproj", "{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -21,6 +25,22 @@ Global
|
||||
{A21FD938-1FEA-4687-AB86-0EABAC30877B}.Release|x64.Build.0 = Release|x64
|
||||
{A21FD938-1FEA-4687-AB86-0EABAC30877B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{A21FD938-1FEA-4687-AB86-0EABAC30877B}.Release|x86.Build.0 = Release|Win32
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Debug|x64.Build.0 = Debug|x64
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Debug|x86.Build.0 = Debug|Win32
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Release|x64.ActiveCfg = Release|x64
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Release|x64.Build.0 = Release|x64
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Release|x86.ActiveCfg = Release|Win32
|
||||
{EE91AB12-4225-4A4D-931D-69D72F6D91FB}.Release|x86.Build.0 = Release|Win32
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Debug|x64.Build.0 = Debug|x64
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Debug|x86.Build.0 = Debug|Win32
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Release|x64.ActiveCfg = Release|x64
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Release|x64.Build.0 = Release|x64
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Release|x86.ActiveCfg = Release|Win32
|
||||
{D3BB3300-25F0-42BF-A934-FAC33B5C7D25}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user