Threads
This commit is contained in:
parent
3f2572eaa5
commit
46b7b28b2b
BIN
assets/clean-fabric-texture-4-780x585.jpg
Executable file
BIN
assets/clean-fabric-texture-4-780x585.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
135
game/main_code.cpp
Normal file → Executable file
135
game/main_code.cpp
Normal file → Executable file
@ -54,7 +54,8 @@ void TMyApplication::InnerInit()
|
|||||||
|
|
||||||
#ifdef TARGET_WIN32
|
#ifdef TARGET_WIN32
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
ST::PathToResources = "resources/";
|
//ST::PathToResources = "resources/";
|
||||||
|
ST::PathToResources = "../../../assets/";
|
||||||
#else
|
#else
|
||||||
ST::PathToResources = "../../../assets/";
|
ST::PathToResources = "../../../assets/";
|
||||||
#endif
|
#endif
|
||||||
@ -83,6 +84,9 @@ void TMyApplication::InnerInit()
|
|||||||
ResourceManager->TexList.AddTexture("HeightMap.png");
|
ResourceManager->TexList.AddTexture("HeightMap.png");
|
||||||
ResourceManager->TexList.AddTexture("NormalMap.png");
|
ResourceManager->TexList.AddTexture("NormalMap.png");
|
||||||
ResourceManager->TexList.AddTexture("linesAll.png");
|
ResourceManager->TexList.AddTexture("linesAll.png");
|
||||||
|
ResourceManager->TexList.AddTexture("clean-fabric-texture-4-780x585.jpg");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
|
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
|
||||||
|
|
||||||
@ -137,49 +141,97 @@ void TMyApplication::InnerInit()
|
|||||||
float const step = 12;
|
float const step = 12;
|
||||||
float const thick = 10;
|
float const thick = 10;
|
||||||
|
|
||||||
auto f = [this, texW, texH, thick, W, H] (const Vector3f &p1, const Vector3f &p2) {
|
|
||||||
auto pv = p2 - p1;
|
|
||||||
Vector3f ortho(pv[2], 0, pv[0]);
|
|
||||||
ortho.normalize();
|
|
||||||
auto p3 = p2 + ortho * thick;
|
|
||||||
auto p4 = p1 + ortho * thick;
|
|
||||||
|
|
||||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
|
float const R = 5;
|
||||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p2);
|
float const r = 6;
|
||||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
|
size_t const threadsCount = 3;
|
||||||
|
size_t const verticesCount = 6;
|
||||||
|
float const angle = pi / 18;
|
||||||
|
size_t const iterationsCount = 50;
|
||||||
|
auto g = [this, R, r, threadsCount, verticesCount, angle, iterationsCount, texW, texH, thick, H, W] (const Vector3f &start, const Vector3f &end) {
|
||||||
|
Vector3f direction = end - start;
|
||||||
|
Vector3f translate = direction / iterationsCount;
|
||||||
|
direction.normalize();
|
||||||
|
|
||||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p3);
|
auto e0 = Vector3f(1, 0, -direction.x() / direction.z());
|
||||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p4);
|
auto e1 = Vector3f(0, 1, -direction.y() / direction.z());
|
||||||
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(p1);
|
e1 = e1 - (e1.dot(e0) / e0.dot(e0)) * e0;
|
||||||
|
|
||||||
auto texThick = thick / texW;
|
e0.normalize();
|
||||||
auto m = (p1[0] + p2[0]) / 2 / texW;
|
e1.normalize();
|
||||||
auto y = H / texH;
|
|
||||||
|
|
||||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
|
std::vector<std::vector<Vector4f>> threads;
|
||||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, y));
|
for(auto i = 0; i < threadsCount; i++) {
|
||||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
|
std::vector<Vector4f> vertices;
|
||||||
|
Vector3f threadCenter = R * (e0 * cosf(i * 2 * pi / threadsCount) + e1 * sinf(i * 2 * pi / threadsCount));
|
||||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, y));
|
for(auto j = 0; j < verticesCount; j++) {
|
||||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m + texThick, 0));
|
auto verticeCenter = threadCenter + r * (e0 * cosf(j * 2 * pi / verticesCount) + e1 * sinf(j * 2 * pi / verticesCount));
|
||||||
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(m, 0));
|
vertices.push_back(Vector4f(verticeCenter.x(), verticeCenter.y(), verticeCenter.z(), 1));
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3f const stepDirection(1, 0, 0);
|
|
||||||
Vector3f p1(bottomLeft[0], 0, -bottomLeft[1]);
|
|
||||||
|
|
||||||
while (p1[0] < bottomLeft[0] + W) {
|
|
||||||
|
|
||||||
auto p2 = p1 - Vector3f(0, 0, W);
|
|
||||||
f(p1, p2);
|
|
||||||
|
|
||||||
auto p3 = p1 + step * stepDirection;
|
|
||||||
f(p3, p2);
|
|
||||||
|
|
||||||
p1 = p3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
threads.push_back(vertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto transform = Translation3f(translate) * AngleAxis<float>(angle, direction);
|
||||||
|
auto matrix = transform.matrix();
|
||||||
|
|
||||||
|
for(auto i = 0; i < iterationsCount; i++) {
|
||||||
|
std::vector<std::vector<Vector4f>> newThreads;
|
||||||
|
|
||||||
|
for(auto j = 0; j < threadsCount; j++) {
|
||||||
|
auto vertices = threads[j];
|
||||||
|
std::vector<Vector4f> newVertices;
|
||||||
|
|
||||||
|
for(auto k = 0; k < verticesCount; k++) {
|
||||||
|
newVertices.push_back(matrix * vertices[k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
newThreads.push_back(newVertices);
|
||||||
|
|
||||||
|
for(auto k = 0; k < verticesCount; k++) {
|
||||||
|
auto vk = vertices[k];
|
||||||
|
auto vk1 = vertices[(k + 1) % verticesCount];
|
||||||
|
auto nvk = newVertices[k];
|
||||||
|
auto nvk1 = newVertices[(k + 1) % verticesCount];
|
||||||
|
|
||||||
|
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk.head(3));
|
||||||
|
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk1.head(3));
|
||||||
|
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk.head(3));
|
||||||
|
|
||||||
|
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + vk1.head(3));
|
||||||
|
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk1.head(3));
|
||||||
|
fabricRender.second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].push_back(start + nvk.head(3));
|
||||||
|
|
||||||
|
auto texThick = thick / texW;
|
||||||
|
auto m = (start[0] + end[0]) / 2 / texW;
|
||||||
|
auto y = H / texH;
|
||||||
|
|
||||||
|
auto texPiece = texH / iterationsCount;
|
||||||
|
|
||||||
|
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0));
|
||||||
|
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.01, 0));
|
||||||
|
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0.01));
|
||||||
|
|
||||||
|
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.01, 0));
|
||||||
|
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0.01, 0.01));
|
||||||
|
fabricRender.second.Data.Vec2CoordArr[CONST_STRING_TEXCOORD_ATTRIB].push_back(Vector2f(0, 0.01));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
threads = newThreads;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector3f const stepDirection(18, 0, 0);
|
||||||
|
Vector3f p1(bottomLeft[0], 0, -bottomLeft[1]);
|
||||||
|
Vector3f p2 = p1 - Vector3f(0, 0, W);
|
||||||
|
|
||||||
|
while(p1[0] < bottomLeft[0] + W)
|
||||||
|
{
|
||||||
|
g(p1, p2);
|
||||||
|
p1 += stepDirection;
|
||||||
|
p2 += stepDirection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
background.first.ShaderName ="DefaultShader";
|
background.first.ShaderName ="DefaultShader";
|
||||||
@ -194,11 +246,13 @@ void TMyApplication::InnerInit()
|
|||||||
|
|
||||||
fabricRender.first.SamplerMap[CONST_STRING_NORMALMAP_UNIFORM] = "NormalMap.png";
|
fabricRender.first.SamplerMap[CONST_STRING_NORMALMAP_UNIFORM] = "NormalMap.png";
|
||||||
fabricRender.first.SamplerMap[CONST_STRING_HEIGHTMAP_UNIFORM] = "HeightMap.png";
|
fabricRender.first.SamplerMap[CONST_STRING_HEIGHTMAP_UNIFORM] = "HeightMap.png";
|
||||||
fabricRender.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "linesAll.png";
|
fabricRender.first.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "clean-fabric-texture-4-780x585.jpg";
|
||||||
|
|
||||||
background.second.RefreshBuffer();
|
background.second.RefreshBuffer();
|
||||||
fabricRender.second.RefreshBuffer();
|
fabricRender.second.RefreshBuffer();
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
Inited = true;
|
Inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +340,6 @@ void TMyApplication::InnerDraw()
|
|||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
CheckGlError("");
|
CheckGlError("");
|
||||||
|
|
||||||
@ -312,6 +365,8 @@ void TMyApplication::InnerDraw()
|
|||||||
|
|
||||||
Renderer->DrawTriangleList(background.second);
|
Renderer->DrawTriangleList(background.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//glEnable(GL_CULL_FACE);
|
||||||
{
|
{
|
||||||
TRenderParamsSetter params(fabricRender.first);
|
TRenderParamsSetter params(fabricRender.first);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<ProjectGuid>{1CC98EEE-BBCB-4D79-B6D7-8511789172C5}</ProjectGuid>
|
<ProjectGuid>{1CC98EEE-BBCB-4D79-B6D7-8511789172C5}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>DoubleHitBallswin</RootNamespace>
|
<RootNamespace>DoubleHitBallswin</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
@ -48,7 +49,7 @@
|
|||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>NotSet</CharacterSet>
|
<CharacterSet>NotSet</CharacterSet>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
@ -150,7 +151,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;TARGET_WIN32;_WIN32_WINNT=0x0501;WIN32_LEAN_AND_MEAN;EIGEN_DONT_ALIGN_STATICALLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;TARGET_WIN32;_WIN32_WINNT=0x0501;WIN32_LEAN_AND_MEAN;EIGEN_DONT_ALIGN_STATICALLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_63_0/;../../../../boost_1_63_0/bin.v2/libs/system/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/date_time/build/msvc-14.0/release/address-model-64/link-static/threading-multi/;../../../../boost_1_63_0/bin.v2/libs/regex/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/thread/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/chrono/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/signals/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_67_0/;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510</AdditionalIncludeDirectories>
|
||||||
<DisableSpecificWarnings>4503</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4503</DisableSpecificWarnings>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@ -158,7 +159,7 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<AdditionalLibraryDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_63_0/stage/x64/lib;../../../../boost_1_63_0/bin.v2/libs/system/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/date_time/build/msvc-14.0/release/address-model-64/link-static/threading-multi/;../../../../boost_1_63_0/bin.v2/libs/regex/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/thread/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/chrono/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../boost_1_63_0/bin.v2/libs/signals/build/msvc-14.0/release/address-model-64/link-static/threading-multi;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510;../x64/Release</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>../../../game;../../../../tes-engine;../../../../eigen;../../../../boost_1_67_0/stage/lib;../../../../libs/boost-gil-extension;../../../../libs/jpeg-9;../../../../libs/jpeg-9/vc10;../../../../libs/lpng1510;../x64/Release</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>libjpeg.lib;libpng.lib;Engine.lib;opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>libjpeg.lib;libpng.lib;Engine.lib;opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
@ -8,8 +8,8 @@ int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst,
|
|||||||
LPSTR lpszCmdLine, int nCmdShow)
|
LPSTR lpszCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
|
|
||||||
int width = 512;
|
int width = 1024;
|
||||||
int height = 512;
|
int height = 1024;
|
||||||
|
|
||||||
|
|
||||||
if (CreateEngine(width, height))
|
if (CreateEngine(width, height))
|
||||||
|
Loading…
Reference in New Issue
Block a user