소스 검색

add lightning to cube blocks

Kolja Strohm 1 주 전
부모
커밋
9e35ccff9b
50개의 변경된 파일738개의 추가작업 그리고 209개의 파일을 삭제
  1. 7 2
      FactoryCraft/Block.cpp
  2. 2 0
      FactoryCraft/Chat.cpp
  3. 2 0
      FactoryCraft/ChatMessage.cpp
  4. 2 0
      FactoryCraft/ChatOptions.cpp
  5. 11 2
      FactoryCraft/Chunk.cpp
  6. 9 2
      FactoryCraft/Chunk.h
  7. 12 0
      FactoryCraft/ChunkAnyHit.hlsl
  8. 101 15
      FactoryCraft/ChunkIntersection.hlsl
  9. 21 1
      FactoryCraft/Common.hlsl
  10. 1 1
      FactoryCraft/Constants.h
  11. 5 1
      FactoryCraft/CraftingGrid.cpp
  12. 1 0
      FactoryCraft/CraftingRecipies.cpp
  13. 21 14
      FactoryCraft/CustomDX12API.cpp
  14. 1 0
      FactoryCraft/CustomDX12API.h
  15. 11 0
      FactoryCraft/CustomMiss.hlsl
  16. 74 0
      FactoryCraft/CustomRayGen.hlsl
  17. 134 4
      FactoryCraft/DX12ChunkData.cpp
  18. 7 1
      FactoryCraft/DX12ChunkData.h
  19. 100 0
      FactoryCraft/DefaultAnyHit.hlsl
  20. 21 0
      FactoryCraft/DefaultClosestHit.hlsl
  21. 2 0
      FactoryCraft/Dialog.cpp
  22. 2 0
      FactoryCraft/Dimension.cpp
  23. 2 0
      FactoryCraft/DimensionMap.cpp
  24. 3 0
      FactoryCraft/Entity.cpp
  25. 2 1
      FactoryCraft/EntityType.cpp
  26. 17 5
      FactoryCraft/FactoryClient.cpp
  27. 5 7
      FactoryCraft/FactoryClient.h
  28. 60 0
      FactoryCraft/FactoryCraft.vcxproj
  29. 12 0
      FactoryCraft/FactoryCraft.vcxproj.filters
  30. 4 1
      FactoryCraft/Game.cpp
  31. 4 0
      FactoryCraft/Globals.cpp
  32. 4 2
      FactoryCraft/Globals.h
  33. 3 0
      FactoryCraft/InventoryView.cpp
  34. 5 2
      FactoryCraft/ItemBar.cpp
  35. 3 1
      FactoryCraft/ItemList.cpp
  36. 2 0
      FactoryCraft/ItemStack.cpp
  37. 1 0
      FactoryCraft/ListView.cpp
  38. 1 5
      FactoryCraft/Load.cpp
  39. 1 116
      FactoryCraft/Main.cpp
  40. 8 4
      FactoryCraft/ModelInfo.cpp
  41. 2 0
      FactoryCraft/PlayerKam.cpp
  42. 4 0
      FactoryCraft/RecipieIngredient.cpp
  43. 2 1
      FactoryCraft/RecipieIngredient.h
  44. 2 1
      FactoryCraft/RecipieOutput.cpp
  45. 1 0
      FactoryCraft/ServerSelection.cpp
  46. 12 0
      FactoryCraft/SimpleBlocksAnyHit.hlsl
  47. 2 0
      FactoryCraft/StatusBars.cpp
  48. 2 0
      FactoryCraft/UIMLProgressAndStateView.cpp
  49. 13 10
      FactoryCraft/World.cpp
  50. 14 10
      FactoryCraft/World.h

+ 7 - 2
FactoryCraft/Block.cpp

@@ -3,8 +3,10 @@
 #include <Shader.h>
 #include <Texture.h>
 
-#include "CustomDX12API.h"
+#include "Chunk.h"
+#include "FactoryClient.h"
 #include "Globals.h"
+#include "World.h"
 
 Block::Block(const BlockType* zType,
     Framework::Vec3<int> pos,
@@ -126,7 +128,10 @@ void Block::setLightData(Direction dir, unsigned char* data, Chunk* zC)
         sideVisible[getDirectionIndex(dir)] = 1;
     else
         sideVisible[getDirectionIndex(dir)] = 0;
-    // TODO: update chunk gpu data
+    if (zC)
+    {
+        zC->setLightChanged(1);
+    }
     int sum1 = 0;
     int sum2 = 0;
     int sum3 = 0;

+ 2 - 0
FactoryCraft/Chat.cpp

@@ -4,8 +4,10 @@
 #include <FileSystem.h>
 
 #include "ChatMessage.h"
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
+#include "World.h"
 
 Chat::Chat()
     : OptionsWindow([this]() { options->addStyle(Window::Style::Visible); }),

+ 2 - 0
FactoryCraft/ChatMessage.cpp

@@ -1,5 +1,7 @@
 #include "ChatMessage.h"
 
+#include <Timer.h>
+
 #include "Globals.h"
 
 ChatMessage::ChatMessage(char* data)

+ 2 - 0
FactoryCraft/ChatOptions.cpp

@@ -2,8 +2,10 @@
 
 #include <FileSystem.h>
 
+#include "FactoryClient.h"
 #include "Globals.h"
 #include "Initialization.h"
+#include "World.h"
 
 ChatOptions::ChatOptions()
     : Window()

+ 11 - 2
FactoryCraft/Chunk.cpp

@@ -2,7 +2,9 @@
 
 #include "Constants.h"
 #include "DX12ChunkData.h"
+#include "FactoryClient.h"
 #include "Globals.h"
+#include "World.h"
 
 Chunk::Chunk(Framework::Point location)
     : ReferenceCounter(),
@@ -330,6 +332,13 @@ bool Chunk::tick(std::function<void(Model3D*)> f, double time)
         res |= b->tick(time);
     }
     vLock.unlockRead();
+    if (lightChanged)
+    {
+        bLock.lockRead();
+        dx12Data->updateLightning(this);
+        bLock.unlockRead();
+        lightChanged = 0;
+    }
     return 1;
 }
 
@@ -554,9 +563,9 @@ Framework::Vec3<int> Chunk::getMax() const
         location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
 }
 
-void Chunk::setLightChanged(int type)
+void Chunk::setLightChanged(bool changed)
 {
-    lightChanged |= type;
+    lightChanged = changed;
 }
 
 Lock& Chunk::getBlockReadLock() const

+ 9 - 2
FactoryCraft/Chunk.h

@@ -34,7 +34,7 @@ private:
     Framework::ReadWriteLock vLock;
     Framework::ReadWriteLock aLock;
     Framework::RCArray<BlockAnimation> animations;
-    int lightChanged;
+    bool lightChanged;
     DX12ChunkData* dx12Data;
 
     void appendAnimation(
@@ -60,7 +60,7 @@ public:
     Framework::Point getCenter() const;
     Framework::Vec3<int> getMin() const;
     Framework::Vec3<int> getMax() const;
-    void setLightChanged(int modelType);
+    void setLightChanged(bool lightChanged);
     Lock& getBlockReadLock() const;
     DX12ChunkData* zDX12Data() const;
 
@@ -70,5 +70,12 @@ public:
              + localLocation.z;
     }
 
+    inline static Framework::Vec3<int> chunkCoordinates(int index)
+    {
+        return {index / (CHUNK_SIZE * WORLD_HEIGHT),
+            (index / WORLD_HEIGHT) % CHUNK_SIZE,
+            index % WORLD_HEIGHT};
+    }
+
     // friend ChunkModelBuilder;
 };

+ 12 - 0
FactoryCraft/ChunkAnyHit.hlsl

@@ -23,6 +23,10 @@ void ChunkAnyHit(inout HitInfo payload, Attributes attrib)
             payload.color[i] = color;
             float tmpDistance = payload.distance[i];
             payload.distance[i] = distance;
+            int tmpDayLight = payload.dayLight[i];
+            payload.dayLight[i] = attrib.dayLight;
+            int tmpDynamicLight = payload.dynamicLight[i];
+            payload.dynamicLight[i] = attrib.dynamicLight;
             if (color.w == 1.f)
             {
                 payload.hitCount = i + 1;
@@ -33,10 +37,16 @@ void ChunkAnyHit(inout HitInfo payload, Attributes attrib)
                 {
                     float4 tmpColor2 = payload.color[j];
                     float tmpDistance2 = payload.distance[j];
+                    int tmpDayLight2 = payload.dayLight[j];
+                    int tmpDynamicLight2 = payload.dynamicLight[j];
                     payload.color[j] = tmpColor;
                     payload.distance[j] = tmpDistance;
+                    payload.dayLight[j] = tmpDayLight;
+                    payload.dynamicLight[j] = tmpDynamicLight;
                     tmpColor = tmpColor2;
                     tmpDistance = tmpDistance2;
+                    tmpDayLight = tmpDayLight2;
+                    tmpDynamicLight = tmpDynamicLight2;
                 }
             }
             break;
@@ -54,6 +64,8 @@ void ChunkAnyHit(inout HitInfo payload, Attributes attrib)
     {
         payload.color[payload.hitCount] = color;
         payload.distance[payload.hitCount] = distance;
+        payload.dayLight[payload.hitCount] = attrib.dayLight;
+        payload.dynamicLight[payload.hitCount] = attrib.dynamicLight;
         payload.hitCount++;
     }
     if (color.w < 1.f)

+ 101 - 15
FactoryCraft/ChunkIntersection.hlsl

@@ -12,22 +12,38 @@ cbuffer ChunkShaderInfo : register(b0, space2)
 
 StructuredBuffer<int> textureIdBuffer : register(t1, space2);
 StructuredBuffer<int> indexBuffer : register(t1, space3);
+ByteAddressBuffer lightBuffer : register(t1, space4);
 
 #define minPos(x, y) min(x>0?x:y,y>0?y:x)
 #define minPosV(v1, v2) float3(minPos(v1.x, v2.x), minPos(v1.y, v2.y), minPos(v1.z, v2.z))
 
 #define between(v1, vmin, vmax) (v1.x >= vmin.x && v1.x <= vmax.x && v1.y >= vmin.y && v1.y <= vmax.y && v1.z >= vmin.z && v1.z <= vmax.z)
 
-float GetEntry(float3 minp, float3 maxp, float3 invDir, float3 origin)
+float3 getLight(int index)
 {
-    if (between(origin, minp, maxp))
+    uint raw = lightBuffer.Load(index / 4);
+    uint shift = (index % 4) * 8;
+    float r = ((raw >> shift) & 0xFF) / 255.0;
+    shift += 8;
+    if (shift == 32)
     {
-        return 0;
+        raw = lightBuffer.Load(index / 4 + 4);
+        shift = 0;
     }
-    float3 t1 = (minp - origin) * invDir;
-    float3 t2 = (maxp - origin) * invDir;
-    float3 tmin = min(t1, t2);
-    return max(max(tmin.x, tmin.y), tmin.z);
+    float g = ((raw >> shift) & 0xFF) / 255.0;
+    shift += 8;
+    if (shift == 32)
+    {
+        raw = lightBuffer.Load(index / 4 + 4);
+        shift = 0;
+    }
+    float b = ((raw >> shift) & 0xFF) / 255.0;
+    return float3(r, g, b);
+}
+
+float3 interpolateLight(float3 topLeft, float3 topRight, float3 bottomLeft, float3 bottomRight, float2 coords)
+{
+    return (topLeft * (1 - coords.x) + topRight * coords.x) * (1 - coords.y) + (bottomLeft * (1 - coords.x) + bottomRight * coords.x) * coords.y;
 }
 
 [shader("intersection")]
@@ -78,19 +94,19 @@ void ChunkIntersection()
     int3 blockMax = int3(CHUNK_SIZE - 1, CHUNK_SIZE - 1, WORLD_HEIGHT - 1);
     switch (hitSide)
     {
-        case 0: // front
+        case 0: // front | NORTH
             block.y = blockMin.y;
             nextBorder.y = blockMin.y + 1 + chunkMin.y;
             break;
-        case 1: // back
+        case 1: // back | SOUTH
             block.y = blockMax.y;
             nextBorder.y = blockMax.y + chunkMin.y;
             break;
-        case 2: // left
+        case 2: // left | EAST
             block.x = blockMax.x;
             nextBorder.x = blockMax.x + chunkMin.x;
             break;
-        case 3: // right
+        case 3: // right | WEST
             block.x = blockMin.x;
             nextBorder.x = blockMin.x + 1 + chunkMin.x;
             break;
@@ -108,27 +124,97 @@ void ChunkIntersection()
         int index = (block.x * CHUNK_SIZE + block.y) * WORLD_HEIGHT + block.z;
         if (indexBuffer[index] >= 0 && distance > minDistance && hitSide >= 0)
         {
+            int lightOffset = indexBuffer[index] * 8;
+            float3 topLeftDayLight;
+            float3 topRightDayLight;
+            float3 bottomLeftDayLight;
+            float3 bottomRightDayLight;
+            float3 topLeftDynamicLight;
+            float3 topRightDynamicLight;
+            float3 bottomLeftDynamicLight;
+            float3 bottomRightDynamicLight;
+            /**
+                Light indices are stored in the following order:
+                lightOffset      = TOP | NORTH | EAST
+                lightOffset + 6  = TOP | SOUTH | EAST
+                lightOffset + 12 = TOP | SOUTH | WEST
+                lightOffset + 18 = TOP | NORTH | WEST
+                lightOffset + 24 = BOTTOM | NORTH | EAST
+                lightOffset + 30 = BOTTOM | SOUTH | EAST
+                lightOffset + 36 = BOTTOM | SOUTH | WEST
+                lightOffset + 42 = BOTTOM | NORTH | WEST
+            **/
             switch (hitSide)
             {
-                case 0: // front
+                case 0: // front | NORTH
                     intersectionAttributes.texCoord = float2(1 - (currentPos.x - floor(currentPos.x)), 1 - (currentPos.z - floor(currentPos.z)));
+                    topLeftDayLight = getLight(lightOffset + 0);
+                    topLeftDynamicLight = getLight(lightOffset + 3);
+                    topRightDayLight = getLight(lightOffset + 18);
+                    topRightDynamicLight = getLight(lightOffset + 21);
+                    bottomLeftDayLight = getLight(lightOffset + 24);
+                    bottomLeftDynamicLight = getLight(lightOffset + 27);
+                    bottomRightDayLight = getLight(lightOffset + 42);
+                    bottomRightDynamicLight = getLight(lightOffset + 45);
                     break;
-                case 1: // back
+                case 1: // back | SOUTH
                     intersectionAttributes.texCoord = float2(currentPos.x - floor(currentPos.x), 1 - (currentPos.z - floor(currentPos.z)));
+                    topLeftDayLight = getLight(lightOffset + 12);
+                    topLeftDynamicLight = getLight(lightOffset + 15);
+                    topRightDayLight = getLight(lightOffset + 6);
+                    topRightDynamicLight = getLight(lightOffset + 9);
+                    bottomLeftDayLight = getLight(lightOffset + 36);
+                    bottomLeftDynamicLight = getLight(lightOffset + 39);
+                    bottomRightDayLight = getLight(lightOffset + 30);
+                    bottomRightDynamicLight = getLight(lightOffset + 33);
                     break;
-                case 2: // left
+                case 2: // left | EAST
                     intersectionAttributes.texCoord = float2(1 - (currentPos.y - floor(currentPos.y)), 1 - (currentPos.z - floor(currentPos.z)));
+                    topLeftDayLight = getLight(lightOffset + 6);
+                    topLeftDynamicLight = getLight(lightOffset + 9);
+                    topRightDayLight = getLight(lightOffset + 0);
+                    topRightDynamicLight = getLight(lightOffset + 3);
+                    bottomLeftDayLight = getLight(lightOffset + 30);
+                    bottomLeftDynamicLight = getLight(lightOffset + 33);
+                    bottomRightDayLight = getLight(lightOffset + 24);
+                    bottomRightDynamicLight = getLight(lightOffset + 27);
                     break;
-                case 3: // right
+                case 3: // right | WEST
                     intersectionAttributes.texCoord = float2(currentPos.y - floor(currentPos.y), 1 - (currentPos.z - floor(currentPos.z)));
+                    topLeftDayLight = getLight(lightOffset + 18);
+                    topLeftDynamicLight = getLight(lightOffset + 21);
+                    topRightDayLight = getLight(lightOffset + 12);
+                    topRightDynamicLight = getLight(lightOffset + 15);
+                    bottomLeftDayLight = getLight(lightOffset + 42);
+                    bottomLeftDynamicLight = getLight(lightOffset + 45);
+                    bottomRightDayLight = getLight(lightOffset + 36);
+                    bottomRightDynamicLight = getLight(lightOffset + 39);
                     break;
                 case 4: // top
                     intersectionAttributes.texCoord = float2(1 - (currentPos.x - floor(currentPos.x)), 1 - (currentPos.y - floor(currentPos.y)));
+                    topLeftDayLight = getLight(lightOffset + 6);
+                    topLeftDynamicLight = getLight(lightOffset + 9);
+                    topRightDayLight = getLight(lightOffset + 12);
+                    topRightDynamicLight = getLight(lightOffset + 15);
+                    bottomLeftDayLight = getLight(lightOffset + 0);
+                    bottomLeftDynamicLight = getLight(lightOffset + 3);
+                    bottomRightDayLight = getLight(lightOffset + 18);
+                    bottomRightDynamicLight = getLight(lightOffset + 21);
                     break;
                 case 5: // bottom
                     intersectionAttributes.texCoord = float2(1 - (currentPos.x - floor(currentPos.x)), currentPos.y - floor(currentPos.y));
+                    topLeftDayLight = getLight(lightOffset + 24);
+                    topLeftDynamicLight = getLight(lightOffset + 27);
+                    topRightDayLight = getLight(lightOffset + 42);
+                    topRightDynamicLight = getLight(lightOffset + 45);
+                    bottomLeftDayLight = getLight(lightOffset + 30);
+                    bottomLeftDynamicLight = getLight(lightOffset + 33);
+                    bottomRightDayLight = getLight(lightOffset + 36);
+                    bottomRightDynamicLight = getLight(lightOffset + 39);
                     break;
             }
+            intersectionAttributes.dayLight = packLight(interpolateLight(topLeftDayLight, topRightDayLight, bottomLeftDayLight, bottomRightDayLight, intersectionAttributes.texCoord));
+            intersectionAttributes.dynamicLight = packLight(interpolateLight(topLeftDynamicLight, topRightDynamicLight, bottomLeftDynamicLight, bottomRightDynamicLight, intersectionAttributes.texCoord));
             intersectionAttributes.textureId = textureIdBuffer[indexBuffer[index] + hitSide];
             ReportHit(distance, hitSide, intersectionAttributes);
             if (RayTCurrent() < THit)

+ 21 - 1
FactoryCraft/Common.hlsl

@@ -11,6 +11,8 @@ struct [raypayload] HitInfo
 {
     float4 color[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit, miss) : read(caller, anyhit, closesthit, miss);
 float distance[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
+int dayLight[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
+int dynamicLight[MAX_TRANSPACENT_HITS] : write(caller, closesthit, anyhit) : read(caller, anyhit, closesthit);
 uint hitCount : write(caller, anyhit, closesthit, miss) : read(caller, anyhit, closesthit, miss);
 };
 
@@ -20,9 +22,27 @@ struct Attributes
 {
     float2 texCoord;
     int textureId;
+    int dayLight;
+    int dynamicLight;
 };
 
 struct SimpleBlocksAttributes
 {
     float2 bary;
-};
+};
+
+uint packLight(float3 light)
+{
+    uint r = (uint) (light.r * 255.0) & 0xFF;
+    uint g = (uint) (light.g * 255.0) & 0xFF;
+    uint b = (uint) (light.b * 255.0) & 0xFF;
+    return (r << 16) | (g << 8) | b;
+}
+
+float3 unpackLight(int light)
+{
+    float r = ((light >> 16) & 0xFF) / 255.0f;
+    float g = ((light >> 8) & 0xFF) / 255.0f;
+    float b = (light & 0xFF) / 255.0f;
+    return float3(r, g, b);
+}

+ 1 - 1
FactoryCraft/Constants.h

@@ -5,6 +5,6 @@
 #ifdef _DEBUG
 #    define CHUNK_VISIBILITY_RANGE 10
 #else
-#    define CHUNK_VISIBILITY_RANGE 16
+#    define CHUNK_VISIBILITY_RANGE 20
 #endif
 #define MAX_VIEW_DISTANCE CHUNK_SIZE* CHUNK_VISIBILITY_RANGE

+ 5 - 1
FactoryCraft/CraftingGrid.cpp

@@ -4,10 +4,13 @@
 #include <XML.h>
 
 #include "DragController.h"
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
+#include "ItemType.h"
 #include "UIMLToolTip.h"
 #include "UIMLUtils.h"
+#include "World.h"
 
 using namespace Framework;
 
@@ -174,7 +177,8 @@ CraftingGridView::~CraftingGridView()
 {
     DragController<InventoryDragSource, int>* controller
         = menuRegister ? ((Game*)(Menu*)menuRegister->get("game"))
-              ->zInventoryDragController() : 0;
+                             ->zInventoryDragController()
+                       : 0;
     if (menuRegister && controller->getCurrentDragContainer() == this)
         controller->stopDrag();
     if (slots) slots->release();

+ 1 - 0
FactoryCraft/CraftingRecipies.cpp

@@ -4,6 +4,7 @@
 #include <XML.h>
 
 #include "Globals.h"
+#include "ItemType.h"
 #include "RecipieGroup.h"
 
 CraftingRecipiesElement::CraftingRecipiesElement()

+ 21 - 14
FactoryCraft/CustomDX12API.cpp

@@ -1,18 +1,17 @@
 #include "CustomDX12API.h"
 
-#include <d3d12.h>
 #include <DX12Buffer.h>
 #include <DX12CommandQueue.h>
-#include <DX12DefaultAnyHitShader.h>
-#include <DX12DefaultHitShader.h>
-#include <DX12DefaultMissShader.h>
-#include <DX12DefaultRayGenShader.h>
 #include <DX12Shader.h>
 #include <DX12TLAS.h>
 
 #include "CustomChunkAnyHitShader.h"
 #include "CustomChunkClosestHitShader.h"
 #include "CustomChunkIntersectionShader.h"
+#include "CustomCustomMissShader.h"
+#include "CustomCustomRayGenShader.h"
+#include "CustomDefaultAnyHitShader.h"
+#include "CustomDefaultClosestHitShader.h"
 #include "CustomSimpleBlocksAnyHitShader.h"
 #include "CustomSimpleBlocksClosestHitShader.h"
 #include "Dimension.h"
@@ -31,7 +30,7 @@ void CustomDX12API::initializePipeline()
     if (pipeline->getShaders().getEntryCount() == 0)
     { // add default shaders
         DX12Shader* rayGenShader = new DX12Shader(
-            DX12DefaultRayGenShaderBytes, sizeof(DX12DefaultRayGenShaderBytes));
+            CustomCustomRayGenShader, sizeof(CustomCustomRayGenShader));
         // RayGen from RayGen.hlsl
         DX12ShaderSignature* rayGenSignature = new DX12ShaderSignature();
         rayGenSignature->addRegisterUsageLinkedToDescriptorHeap(
@@ -48,7 +47,7 @@ void CustomDX12API::initializePipeline()
         pipeline->addShader(rayGenShader);
 
         DX12Shader* missShader = new DX12Shader(
-            DX12DefaultMissShaderBytes, sizeof(DX12DefaultMissShaderBytes));
+            CustomCustomMissShader, sizeof(CustomCustomMissShader));
         // Miss from Miss.hlsl
         missShader->addFunction(new DX12ShaderFunction(
             "Miss", new DX12ShaderSignature(), DX12_SHADER_FUNCTION_TYPE_MISS));
@@ -76,15 +75,15 @@ void CustomDX12API::initializePipeline()
             = hitSignature->addRegisterUsageLinkedToShaderBindingTable(
                 DX12_SHADER_REGISTER_T_SHADER_RESOURCE, 1, 5);
         DX12Shader* anyHitShader = new DX12Shader(
-            DX12DefaultAnyHitShaderBytes, sizeof(DX12DefaultAnyHitShaderBytes));
+            CustomDefaultAnyHitShader, sizeof(CustomDefaultAnyHitShader));
         DX12ShaderFunction* anyHitFunction = new DX12ShaderFunction(
             "AnyHit", hitSignature, DX12_SHADER_FUNCTION_TYPE_ANY_HIT);
         // AnyHit from AnyHit.hlsl
         anyHitShader->addFunction(anyHitFunction);
         pipeline->addShader(anyHitShader);
 
-        DX12Shader* hitShader = new DX12Shader(
-            DX12DefaultHitShaderBytes, sizeof(DX12DefaultHitShaderBytes));
+        DX12Shader* hitShader = new DX12Shader(CustomDefaultClosestHitShader,
+            sizeof(CustomDefaultClosestHitShader));
         // ClosestHit from Hit.hlsl
         DX12ShaderFunction* closestHitFunction
             = new DX12ShaderFunction("ClosestHit",
@@ -95,7 +94,7 @@ void CustomDX12API::initializePipeline()
 
         defaultHitGroup = new DX12ShaderHitGroup("HitGroup");
         defaultHitGroup->setAttributeSize(8);
-        defaultHitGroup->setPayloadSize(20 * DEFAULT_MAX_TRANSPARENT_HITS + 4);
+        defaultHitGroup->setPayloadSize(28 * DEFAULT_MAX_TRANSPARENT_HITS + 4);
         defaultHitGroup->setAnyHitShaderFunction(anyHitFunction);
         defaultHitGroup->setClosestHitShaderFunction(closestHitFunction);
         pipeline->addHitGroup(defaultHitGroup);
@@ -119,6 +118,9 @@ void CustomDX12API::initializePipeline()
         sbtChunkDataBufferOffset
             = chunkHitSignature->addRegisterUsageLinkedToShaderBindingTable(
                 DX12_SHADER_REGISTER_B_CONST_BUFFER, 0, 2);
+        sbtChunkLightBufferOffset
+            = chunkHitSignature->addRegisterUsageLinkedToShaderBindingTable(
+                DX12_SHADER_REGISTER_T_SHADER_RESOURCE, 1, 4);
 
         DX12Shader* chunkIntersectionShader
             = new DX12Shader(CustomChunkIntersectionShader,
@@ -152,8 +154,8 @@ void CustomDX12API::initializePipeline()
         chunkHitGroup->setIntersectionShaderFunction(chunkIntersectionFunction);
         chunkHitGroup->setAnyHitShaderFunction(chunkAnyHitFunction);
         chunkHitGroup->setClosestHitShaderFunction(chunkClosestHitFunction);
-        chunkHitGroup->setAttributeSize(12);
-        chunkHitGroup->setPayloadSize(20 * DEFAULT_MAX_TRANSPARENT_HITS + 4);
+        chunkHitGroup->setAttributeSize(20);
+        chunkHitGroup->setPayloadSize(28 * DEFAULT_MAX_TRANSPARENT_HITS + 4);
         pipeline->addHitGroup(chunkHitGroup);
 
         // simple blocks hit shaders
@@ -213,7 +215,7 @@ void CustomDX12API::initializePipeline()
             simpleBlocksClosestHitFunction);
         simpleBlocksHitGroup->setAttributeSize(8);
         simpleBlocksHitGroup->setPayloadSize(
-            20 * DEFAULT_MAX_TRANSPARENT_HITS + 4);
+            28 * DEFAULT_MAX_TRANSPARENT_HITS + 4);
         pipeline->addHitGroup(simpleBlocksHitGroup);
 
         pipeline->setMaxRecursionDepth(10);
@@ -353,6 +355,11 @@ void CustomDX12API::renderWorld(Framework::World3D* zWorld,
                         chunkData->zChunkInfoBuffer()
                             ->zBuffer()
                             ->GetGPUVirtualAddress());
+                    zSBT->setHitGroupShaderInput(hitGroupOffset,
+                        sbtChunkLightBufferOffset,
+                        chunkData->zLightBuffer()
+                            ->zBuffer()
+                            ->GetGPUVirtualAddress());
                 }
                 chunkData->setBufferChanged(0);
                 ++objectIndex;

+ 1 - 0
FactoryCraft/CustomDX12API.h

@@ -10,6 +10,7 @@ private:
     int* sbtChunkTextureIdBufferOffset;
     int* sbtChunkIndexBufferOffset;
     int* sbtChunkDataBufferOffset;
+    int* sbtChunkLightBufferOffset;
     int* sbtSimpleBlocksTextureIdBufferOffset;
     int* sbtSimpleBlocksIndexBufferOffset;
     int* sbtSimpleBlocksVertexDataBufferOffset;

+ 11 - 0
FactoryCraft/CustomMiss.hlsl

@@ -0,0 +1,11 @@
+#include "Common.hlsl"
+
+[shader("miss")]
+void Miss(inout HitInfo payload : SV_RayPayload)
+{
+    if (payload.hitCount < MAX_TRANSPACENT_HITS)
+    {
+        payload.color[payload.hitCount] = float4(0.2f, 0.2f, 0.2f, -1.f);
+        payload.hitCount++;
+    }
+}

+ 74 - 0
FactoryCraft/CustomRayGen.hlsl

@@ -0,0 +1,74 @@
+#include "Common.hlsl"
+
+// Raytracing output texture, accessed as a UAV
+RWTexture2D<float4> gOutput : register(u0);
+
+RWTexture2D<float4> guiTexture : register(u1);
+
+// Raytracing acceleration structure, accessed as a SRV
+RaytracingAccelerationStructure TLAS : register(t0);
+
+cbuffer RayGenerationSettings : register(b0)
+{
+    int renderGui;
+    int useRays;
+    float minDistance;
+    float maxDistance;
+    float4x4 inverseView;
+    float4x4 inverseProjection;
+}
+
+[shader("raygeneration")]
+void RayGen()
+{
+  // Initialize the ray payload
+    HitInfo rayPayload;
+    rayPayload.hitCount = 0;
+    float3 color = float3(0, 0, 0);
+
+    // Get the location within the dispatched 2D grid of work items
+    // (often maps to pixels, so this could represent a pixel coordinate).
+    float2 dispatchDimensions = float2(DispatchRaysDimensions().xy);
+    uint2 dispatchIndex = DispatchRaysIndex().xy;
+    float2 dispatchPercentage = (dispatchIndex + 0.5) / dispatchDimensions;
+    
+    if (useRays)
+    {
+        float2 d = (dispatchPercentage * 2.f - 1.f);
+        RayDesc ray;
+        ray.Origin = mul(inverseView, float4(0, 0, 0, 1)).xyz;
+        float4 target = mul(inverseProjection, float4(d.x, -d.y, -1, 1));
+        target.w = 1;
+        ray.Direction = mul(inverseView, target).xyz - ray.Origin;
+        ray.TMin = minDistance;
+        ray.TMax = maxDistance;
+        TraceRay(TLAS, /*RayFlags*/0, /*InstanceInclusionMask*/0xFF, /*RayContributionToHitGroupIndex*/0,
+            /*MultiplierForGeometryContributionToHitGroupIndex*/0, /*MissShaderIndex*/0, ray, rayPayload);
+        float dayLightFactor = 1.f; // TODO: set this based on time
+        float3 minLight = float3(0.1f, 0.1f, 0.1f);
+        float3 dayLight = unpackLight(rayPayload.dayLight[rayPayload.hitCount - 1]);
+        float3 dynamicLight = unpackLight(rayPayload.dynamicLight[rayPayload.hitCount - 1]);
+        float3 light = max(minLight, max(dynamicLight, dayLight * dayLightFactor));
+        color = rayPayload.color[rayPayload.hitCount - 1].rgb * light;
+        for (int i = rayPayload.hitCount - 2; i >= 0; i--)
+        {
+            dayLight = unpackLight(rayPayload.dayLight[i]);
+            dynamicLight = unpackLight(rayPayload.dynamicLight[i]);
+            light = max(minLight, max(dynamicLight, dayLight * dayLightFactor));
+            color = rayPayload.color[i].rgb * light * rayPayload.color[i].a + color * (1 - rayPayload.color[i].a);
+        }
+    }
+    
+    uint outWidth, outHeight;
+    gOutput.GetDimensions(outWidth, outHeight);
+    uint2 outputIndex = uint2(dispatchPercentage * float2(outWidth, outHeight));
+    if (renderGui)
+    {
+        uint guiWidth, guiHeight;
+        guiTexture.GetDimensions(guiWidth, guiHeight);
+        uint2 guiIndex = uint2(dispatchPercentage * float2(guiWidth, guiHeight));
+        float4 guiColor = guiTexture[guiIndex];
+        color = color * (1 - guiColor.a) + guiColor.rgb * guiColor.a;
+    }
+    gOutput[outputIndex] = float4(color, 1.f);
+}

+ 134 - 4
FactoryCraft/DX12ChunkData.cpp

@@ -3,10 +3,9 @@
 #include <DX12BLASModel.h>
 #include <DX12CommandQueue.h>
 
-#include "Block.h"
-#include "Constants.h"
 #include "d3dx12.h"
 #include "Dimension.h"
+#include "World.h"
 
 DX12ChunkData::DX12ChunkData(Framework::Point center)
     : ReferenceCounter(),
@@ -37,7 +36,10 @@ DX12ChunkData::DX12ChunkData(Framework::Point center)
       maxZ(0),
       minMaxChanged(0),
       customBufferChanged(0),
-      customBlocksChanged(0)
+      customBlocksChanged(0),
+      lightBufferSize(0),
+      lightBuffer(0),
+      dxLightBuffer(0)
 {
     memset(
         blockIndices, -1, sizeof(int) * CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT);
@@ -101,6 +103,11 @@ DX12ChunkData::~DX12ChunkData()
     {
         customBlockMatrixBuffer->release();
     }
+    if (dxLightBuffer)
+    {
+        dxLightBuffer->release();
+    }
+    delete[] lightBuffer;
     delete[] blockIndices;
 }
 
@@ -124,6 +131,11 @@ Framework::DX12Buffer* DX12ChunkData::zTextureIdBuffer() const
     return textureIdBuffer;
 }
 
+Framework::DX12Buffer* DX12ChunkData::zLightBuffer() const
+{
+    return dxLightBuffer;
+}
+
 Framework::DX12Buffer* DX12ChunkData::zCustomBlocksBlasBuffer() const
 {
     return customBlocksBlasBuffer;
@@ -275,6 +287,105 @@ void DX12ChunkData::setBlock(int index, Block* zBlock)
     cs.unlock();
 }
 
+void DX12ChunkData::updateLightning(Chunk* zChunk)
+{
+    int neededSize = textureIds.getEntryCount() * 8;
+    if (neededSize > lightBufferSize)
+    {
+        delete[] lightBuffer;
+        lightBuffer = new unsigned char[neededSize];
+        lightBufferSize = neededSize;
+        if (dxLightBuffer)
+        {
+            dxLightBuffer->setData(lightBuffer, 1);
+            dxLightBuffer->setLength(neededSize);
+        }
+    }
+    Directions vertexDirections[] = {TOP | NORTH | EAST,
+        TOP | SOUTH | EAST,
+        TOP | SOUTH | WEST,
+        TOP | NORTH | WEST,
+        BOTTOM | NORTH | EAST,
+        BOTTOM | SOUTH | EAST,
+        BOTTOM | SOUTH | WEST,
+        BOTTOM | NORTH | WEST};
+    for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; ++i)
+    {
+        if (blockIndices[i] >= 0)
+        {
+            Vec3<int> blockLocation = Chunk::chunkCoordinates(i);
+            Block* zBlock = zChunk->zBlockAt(blockLocation);
+            int offset = blockIndices[i] * 8;
+            for (int j = 0; j < 8; ++j)
+            {
+                Directions dir = vertexDirections[j];
+                int lightData[6];
+                memset(lightData, 0, sizeof(int) * 6);
+                int count = 0;
+                for (int d = 0; d < 6; d++)
+                {
+                    Direction direction = getDirectionFromIndex(d);
+                    if ((dir | direction) == dir)
+                    {
+                        Vec3<int> neighborLocation
+                            = blockLocation + getDirection(direction);
+                        if (neighborLocation.z >= 0
+                            && neighborLocation.z < WORLD_HEIGHT)
+                        {
+                            if (neighborLocation.x >= 0
+                                && neighborLocation.x < CHUNK_SIZE
+                                && neighborLocation.y >= 0
+                                && neighborLocation.y < CHUNK_SIZE)
+                            {
+                                int index = Chunk::index(neighborLocation);
+                                if (blockIndices[index] < 0)
+                                {
+                                    for (int k = 0; k < 6; ++k)
+                                    {
+                                        lightData[k]
+                                            += (int)zBlock->getLightData(
+                                                direction)[k];
+                                    }
+                                    ++count;
+                                }
+                            }
+                            else
+                            {
+                                if (!World::INSTANCE->zBlockAt(
+                                        neighborLocation
+                                        + Vec3<int>(zChunk->getCenter().x
+                                                        - CHUNK_SIZE / 2,
+                                            zChunk->getCenter().y
+                                                - CHUNK_SIZE / 2,
+                                            0)))
+                                {
+                                    for (int k = 0; k < 6; ++k)
+                                    {
+                                        lightData[k]
+                                            += (int)zBlock->getLightData(
+                                                direction)[k];
+                                    }
+                                    ++count;
+                                }
+                            }
+                        }
+                    }
+                }
+                for (int k = 0; k < 6; ++k)
+                {
+                    lightBuffer[offset + j * 6 + k]
+                        = count > 0 ? (unsigned char)(lightData[k] / count) : 0;
+                }
+            }
+        }
+    }
+    if (dxLightBuffer)
+    {
+        dxLightBuffer->setChanged();
+        dxLightBuffer->copyToGPU();
+    }
+}
+
 struct ModelIdMapping
 {
     int modelId;
@@ -464,7 +575,8 @@ void DX12ChunkData::updateBuffers(
         {
             Mat4<float> transform
                 = Mat4<float>::translation(
-                      (Vec3<float>)Dimension::chunkCoordinates(block->getLocation())
+                      (Vec3<float>)Dimension::chunkCoordinates(
+                          block->getLocation())
                       + Vec3<float>(
                           0.5f - CHUNK_SIZE / 2, 0.5f - CHUNK_SIZE / 2, 0.5f))
                 * Mat4<float>::rotationZ(block->getZRotation())
@@ -719,6 +831,24 @@ void DX12ChunkData::updateBuffers(
         chunkInfoBuffer->copyToGPU();
         changed = 0;
     }
+    if (!dxLightBuffer)
+    {
+        dxLightBuffer = new DX12Buffer(sizeof(unsigned char),
+            zDevice,
+            dynamic_cast<DX12CommandQueue*>(zQueue->getThis()),
+            D3D12_RESOURCE_FLAG_NONE);
+        if (!lightBuffer)
+        {
+            int neededSize
+                = max(textureIds.getEntryCount() * 8, 6 * 8 * 16 * 16 * 2);
+            lightBuffer = new unsigned char[neededSize];
+            lightBufferSize = neededSize;
+            memset(lightBuffer, -1, lightBufferSize);
+        }
+        dxLightBuffer->setData(lightBuffer, 1);
+        dxLightBuffer->setLength(lightBufferSize);
+        dxLightBuffer->copyToGPU();
+    }
     cs.unlock();
 }
 

+ 7 - 1
FactoryCraft/DX12ChunkData.h

@@ -1,6 +1,5 @@
 #pragma once
 
-#include <d3d12.h>
 #include <DX12Buffer.h>
 #include <Point.h>
 
@@ -12,6 +11,8 @@ struct ChunkShaderInfo
     unsigned int blockCount;
 };
 
+struct ID3D12Resource;
+
 class DX12ChunkData : public ReferenceCounter
 {
 private:
@@ -24,6 +25,9 @@ private:
     Framework::DX12Buffer* customBlocksBlasBuffer;
     Framework::DX12Buffer* blockIndexBuffer;
     Framework::DX12Buffer* textureIdBuffer;
+    unsigned char* lightBuffer;
+    int lightBufferSize;
+    Framework::DX12Buffer* dxLightBuffer;
     RCArray<DX12Buffer> vertexBuffers;
     RCArray<DX12Buffer> indexBuffers;
     Framework::DX12Buffer* customBlockTextures;
@@ -55,12 +59,14 @@ public:
     Framework::DX12Buffer* zBlasBuffer() const;
     Framework::DX12Buffer* zBlockIndexBuffer() const;
     Framework::DX12Buffer* zTextureIdBuffer() const;
+    Framework::DX12Buffer* zLightBuffer() const;
     Framework::DX12Buffer* zCustomBlocksBlasBuffer() const;
     Framework::DX12Buffer* zCustomBlocksTextureBuffer() const;
     Framework::DX12Buffer* zCustomBlocksVertexDataBuffer() const;
     Framework::DX12Buffer* zCustomBlocksCombinedIndexBuffer() const;
     Framework::DX12Buffer* zCustomBlocksIndexOffsetBuffer() const;
     void setBlock(int index, Block* zBlock);
+    void updateLightning(Chunk* zChunk);
     void updateBuffers(
         ID3D12Device5* zDevice, Framework::DX12CommandQueue* zQueue);
     int getLastObjectIndex() const;

+ 100 - 0
FactoryCraft/DefaultAnyHit.hlsl

@@ -0,0 +1,100 @@
+#include "Common.hlsl"
+
+Texture2D<float4> textures[] : register(t0, space1);
+SamplerState gSampler : register(s0, space0);
+
+struct VertexData
+{
+    float2 texcoord;
+    float3 normal;
+};
+
+StructuredBuffer<int> textureIdBuffer : register(t1, space2);
+StructuredBuffer<int> indexBuffer : register(t1, space3);
+StructuredBuffer<VertexData> vertexData : register(t1, space4);
+StructuredBuffer<int> polygonSizeBuffer : register(t1, space5);
+
+[shader("anyhit")]
+void AnyHit(inout HitInfo payload, SimpleBlocksAttributes attrib)
+{
+    //payload.colorAndDistance = float4(1, 1, 1, 1.0);
+    int instanceId = InstanceID();
+    int currentTriangle = PrimitiveIndex();
+    int textureId = 0;
+    for (int i = 0; currentTriangle >= 0; i++)
+    {
+        currentTriangle -= polygonSizeBuffer[i];
+        textureId = textureIdBuffer[i];
+    }
+    Texture2D<float4> texture = textures[textureId];
+    int index = PrimitiveIndex() * 3;
+    VertexData v0 = vertexData[indexBuffer[index]];
+    VertexData v1 = vertexData[indexBuffer[index + 1]];
+    VertexData v2 = vertexData[indexBuffer[index + 2]];
+    float2 texcoord = v0.texcoord * (1 - attrib.bary.x - attrib.bary.y) + v1.texcoord * attrib.bary.x + v2.texcoord * attrib.bary.y;
+    float4 color = texture.SampleLevel(gSampler, texcoord, 0);
+    if (color.w == 0.f)
+    {
+        IgnoreHit();
+    }
+    float distance = RayTCurrent();
+    bool found = false;
+    for (int i = 0; i < payload.hitCount; i++)
+    {
+        if (payload.distance[i] > distance)
+        {
+            found = true;
+            float4 tmpColor = payload.color[i];
+            payload.color[i] = color;
+            float tmpDistance = payload.distance[i];
+            payload.distance[i] = distance;
+            int tmpDayLight = payload.dayLight[i];
+            payload.dayLight[i] = 0xFFFFFF;
+            int tmpDynamicLight = payload.dynamicLight[i];
+            payload.dynamicLight[i] = 0xFFFFFF;
+            if (color.w == 1.f)
+            {
+                payload.hitCount = i + 1;
+            }
+            else
+            {
+                for (int j = i + 1; j < payload.hitCount + 1 && j < MAX_TRANSPACENT_HITS; j++)
+                {
+                    float4 tmpColor2 = payload.color[j];
+                    float tmpDistance2 = payload.distance[j];
+                    int tmpDayLight2 = payload.dayLight[j];
+                    int tmpDynamicLight2 = payload.dynamicLight[j];
+                    payload.color[j] = tmpColor;
+                    payload.distance[j] = tmpDistance;
+                    payload.dayLight[j] = tmpDayLight;
+                    payload.dynamicLight[j] = tmpDynamicLight;
+                    tmpColor = tmpColor2;
+                    tmpDistance = tmpDistance2;
+                    tmpDayLight = tmpDayLight2;
+                    tmpDynamicLight = tmpDynamicLight2;
+                }
+            }
+            break;
+        }
+        else
+        {
+            if (payload.color[i].w == 1.f)
+            {
+                found = true;
+                break;
+            }
+        }
+    }
+    if (!found && payload.hitCount < MAX_TRANSPACENT_HITS)
+    {
+        payload.color[payload.hitCount] = color;
+        payload.distance[payload.hitCount] = distance;
+        payload.dayLight[payload.hitCount] = 0xFFFFFF;
+        payload.dynamicLight[payload.hitCount] = 0xFFFFFF;
+        payload.hitCount++;
+    }
+    if (color.w < 1.f)
+    {
+        IgnoreHit();
+    }
+}

+ 21 - 0
FactoryCraft/DefaultClosestHit.hlsl

@@ -0,0 +1,21 @@
+#include "Common.hlsl"
+
+Texture2D<float4> textures[] : register(t0, space1);
+SamplerState gSampler : register(s0, space0);
+
+struct VertexData
+{
+    float2 texcoord;
+    float3 normal;
+};
+
+StructuredBuffer<int> textureIdBuffer : register(t1, space2);
+StructuredBuffer<int> indexBuffer : register(t1, space3);
+StructuredBuffer<VertexData> vertexData : register(t1, space4);
+StructuredBuffer<int> polygonSizeBuffer : register(t1, space5);
+
+[shader("closesthit")]
+void ClosestHit(inout HitInfo payload, SimpleBlocksAttributes attrib)
+{
+    // TODO: reflection rays and shadow rays ...
+}

+ 2 - 0
FactoryCraft/Dialog.cpp

@@ -9,6 +9,7 @@
 #include "CraftingGrid.h"
 #include "CraftingRecipies.h"
 #include "Equipment.h"
+#include "FactoryClient.h"
 #include "Globals.h"
 #include "InventoryView.h"
 #include "ItemStack.h"
@@ -20,6 +21,7 @@
 #include "UIMLCraftingProgress.h"
 #include "UIMLFuelState.h"
 #include "UnshapedRecipie.h"
+#include "World.h"
 
 using namespace Framework;
 

+ 2 - 0
FactoryCraft/Dimension.cpp

@@ -1,8 +1,10 @@
 #include "Dimension.h"
 
 #include <File.h>
+#include <Timer.h>
 
 #include "Constants.h"
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
 #include "World.h"

+ 2 - 0
FactoryCraft/DimensionMap.cpp

@@ -3,6 +3,8 @@
 #include <FileSystem.h>
 
 #include "Constants.h"
+#include "Entity.h"
+#include "FactoryClient.h"
 #include "Globals.h"
 #include "World.h"
 

+ 3 - 0
FactoryCraft/Entity.cpp

@@ -3,8 +3,11 @@
 #include <Globals.h>
 #include <math.h>
 
+#include "Chunk.h"
 #include "Game.h"
 #include "Globals.h"
+#include "PlayerKam.h"
+#include "World.h"
 
 Entity::Entity(const EntityType* zType,
     Framework::Model3DData* model,

+ 2 - 1
FactoryCraft/EntityType.cpp

@@ -1,7 +1,8 @@
 #include "EntityType.h"
 
 #include "Entity.h"
-#include "Globals.h"
+#include "PlayerKam.h"
+#include "World.h"
 
 EntityType::EntityType(int id, ModelInfo model)
     : id(id),

+ 17 - 5
FactoryCraft/FactoryClient.cpp

@@ -1,13 +1,23 @@
 #include "FactoryClient.h"
 
-#include <DX12Texture.h>
+#include <Camera3D.h>
 #include <File.h>
 #include <FileSystem.h>
+#include <GraphicsApi.h>
 #include <Image.h>
 #include <M3File.h>
 #include <RenderThread.h>
+#include <Screen.h>
+#include <Texture.h>
+#include <Timer.h>
+#include <Trie.h>
+#include <World3D.h>
 
+#include "Area.h"
+#include "BlockType.h"
+#include "EntityType.h"
 #include "Globals.h"
+#include "ItemType.h"
 #include "Load.h"
 
 using namespace Network;
@@ -979,7 +989,7 @@ void FactoryClient::sendPlayerAction(const char* data, unsigned short length)
     cs.unlock();
 }
 
-void FactoryClient::sendPlayerFaceDirection(Vec3<float> dir)
+void FactoryClient::sendPlayerFaceDirection(Framework::Vec3<float> dir)
 {
     if (!foreground) return;
     cs.lock();
@@ -1023,7 +1033,7 @@ void FactoryClient::entityAPIRequest(
 }
 
 void FactoryClient::blockAPIRequest(
-    Vec3<int> pos, const char* message, unsigned short length)
+    Framework::Vec3<int> pos, const char* message, unsigned short length)
 {
     if (!foreground) return;
     cs.lock();
@@ -1073,8 +1083,10 @@ void FactoryClient::componentAPIRequest(
     cs.unlock();
 }
 
-void FactoryClient::blockAPIRequest(
-    int dimensionId, Vec3<int> pos, const char* message, unsigned short length)
+void FactoryClient::blockAPIRequest(int dimensionId,
+    Framework::Vec3<int> pos,
+    const char* message,
+    unsigned short length)
 {
     if (!foreground) return;
     cs.lock();

+ 5 - 7
FactoryCraft/FactoryClient.h

@@ -1,16 +1,14 @@
 #pragma once
 
+#include <Client.h>
 #include <Critical.h>
 #include <Either.h>
-#include <Client.h>
 #include <Network.h>
 #include <Point.h>
 #include <Text.h>
-#include <Thread.h>
+#include <Vec3.h>
 #include <VecN.h>
 
-#include "Entity.h"
-
 class FactoryClient : public Framework::ReferenceCounter
 {
 private:
@@ -40,16 +38,16 @@ public:
     Network::NetworkReader* getNextBackgroundMessage();
     void endMessageReading(bool bg);
     void sendPlayerAction(const char* data, unsigned short length);
-    void sendPlayerFaceDirection(Vec3<float> dir);
+    void sendPlayerFaceDirection(Framework::Vec3<float> dir);
     void sendPlayerMovement(int flags);
     void entityAPIRequest(
         int entityId, const char* message, unsigned short length);
     void blockAPIRequest(
-        Vec3<int> pos, const char* message, unsigned short length);
+        Framework::Vec3<int> pos, const char* message, unsigned short length);
     void componentAPIRequest(
         int* address, int addrLen, const char* message, unsigned short length);
     void blockAPIRequest(int dimensionId,
-        Vec3<int> pos,
+        Framework::Vec3<int> pos,
         const char* message,
         unsigned short length);
     void chunkAPIRequest(

+ 60 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -344,6 +344,66 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
       <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
       </ObjectFileOutput>
     </FxCompile>
+    <FxCompile Include="CustomMiss.hlsl">
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </ObjectFileOutput>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+      </ObjectFileOutput>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.8</ShaderModel>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.8</ShaderModel>
+    </FxCompile>
+    <FxCompile Include="CustomRayGen.hlsl">
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+      </ObjectFileOutput>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </ObjectFileOutput>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.8</ShaderModel>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.8</ShaderModel>
+    </FxCompile>
+    <FxCompile Include="DefaultAnyHit.hlsl">
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </ObjectFileOutput>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+      </ObjectFileOutput>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.8</ShaderModel>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.8</ShaderModel>
+    </FxCompile>
+    <FxCompile Include="DefaultClosestHit.hlsl">
+      <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+      </ObjectFileOutput>
+      <VariableName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader</VariableName>
+      <HeaderFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Custom%(Filename)Shader.h</HeaderFileOutput>
+      <ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+      </ObjectFileOutput>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">6.8</ShaderModel>
+      <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Library</ShaderType>
+      <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">6.8</ShaderModel>
+    </FxCompile>
     <FxCompile Include="SimpleBlocksAnyHit.hlsl">
       <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">-Fd Custom%(Filename).pdb %(AdditionalOptions)</AdditionalOptions>
       <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Library</ShaderType>

+ 12 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -437,6 +437,18 @@
     <FxCompile Include="SimpleBlocksClosestHit.hlsl">
       <Filter>graphics\shader</Filter>
     </FxCompile>
+    <FxCompile Include="CustomRayGen.hlsl">
+      <Filter>graphics\shader</Filter>
+    </FxCompile>
+    <FxCompile Include="CustomMiss.hlsl">
+      <Filter>graphics\shader</Filter>
+    </FxCompile>
+    <FxCompile Include="DefaultClosestHit.hlsl">
+      <Filter>graphics\shader</Filter>
+    </FxCompile>
+    <FxCompile Include="DefaultAnyHit.hlsl">
+      <Filter>graphics\shader</Filter>
+    </FxCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="Common.hlsl">

+ 4 - 1
FactoryCraft/Game.cpp

@@ -1,13 +1,16 @@
 #include "Game.h"
 
-#include <AsynchronCall.h>
 #include <FileSystem.h>
 #include <Screen.h>
 
+#include "Block.h"
+#include "FactoryClient.h"
 #include "Globals.h"
 #include "Initialization.h"
 #include "ItemBar.h"
+#include "PlayerKam.h"
 #include "StatusBars.h"
+#include "World.h"
 
 Game::Game(Screen* zScreen)
     : Menu(zScreen),

+ 4 - 0
FactoryCraft/Globals.cpp

@@ -4,9 +4,13 @@
 #include <Text.h>
 
 #include "AddServerMenu.h"
+#include "BlockType.h"
+#include "EntityType.h"
 #include "Game.h"
+#include "ItemType.h"
 #include "Load.h"
 #include "ServerSelection.h"
+#include "World.h"
 
 void initVariables()
 {

+ 4 - 2
FactoryCraft/Globals.h

@@ -9,14 +9,16 @@
 #include <UIInitialization.h>
 #include <Window.h>
 
-#include "ItemType.h"
 #include "Menu.h"
-#include "World.h"
 
 #ifndef variable
 #    define variable extern
 #endif
 
+class BlockType;
+class EntityType;
+class ItemType;
+
 variable Framework::HashMap<Framework::Text, Framework::RCPointer<Menu>>*
     menuRegister;
 variable UIInit uiFactory;

+ 3 - 0
FactoryCraft/InventoryView.cpp

@@ -4,9 +4,12 @@
 #include <XML.h>
 
 #include "DragController.h"
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
+#include "ItemType.h"
 #include "UIMLToolTip.h"
+#include "World.h"
 
 using namespace Framework;
 

+ 5 - 2
FactoryCraft/ItemBar.cpp

@@ -1,10 +1,13 @@
 #include "ItemBar.h"
 
-#include <Image.h>
 #include <FileSystem.h>
+#include <Image.h>
 #include <XML.h>
 
+#include "FactoryClient.h"
 #include "Globals.h"
+#include "ItemType.h"
+#include "World.h"
 
 using namespace Framework;
 
@@ -12,7 +15,7 @@ ItemBarElement::ItemBarElement()
     : UIMLElement()
 {}
 
-//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
+//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig ist
 bool ItemBarElement::isApplicableFor(Framework::XML::Element& element)
 {
     return element.getName().isEqual("itemBar");

+ 3 - 1
FactoryCraft/ItemList.cpp

@@ -1,14 +1,16 @@
 #include "ItemList.h"
 
 #include <FileSystem.h>
+#include <Globals.h>
 #include <Scroll.h>
 #include <TextField.h>
 
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
+#include "ItemType.h"
 #include "UIMLToolTip.h"
 #include "World.h"
-#include <Globals.h>
 
 ItemList::ItemList()
     : DrawableBackground(),

+ 2 - 0
FactoryCraft/ItemStack.cpp

@@ -1,8 +1,10 @@
 #include "ItemStack.h"
 
+#include <Image.h>
 #include <XML.h>
 
 #include "Globals.h"
+#include "ItemType.h"
 #include "UIMLToolTip.h"
 
 ItemStackElement::ItemStackElement()

+ 1 - 0
FactoryCraft/ListView.cpp

@@ -7,6 +7,7 @@
 #include <Window.h>
 #include <XML.h>
 
+#include "FactoryClient.h"
 #include "World.h"
 
 ListViewElement::ListViewElement()

+ 1 - 5
FactoryCraft/Load.cpp

@@ -2,17 +2,13 @@
 
 #include <Array.h>
 #include <AsynchronCall.h>
-#include <File.h>
 #include <FileSystem.h>
-#include <GraphicsApi.h>
-#include <M3File.h>
 #include <Text.h>
-#include <Texture.h>
 
 #include "FactoryClient.h"
 #include "Globals.h"
 #include "Initialization.h"
-#include "ServerSelection.h"
+#include "ItemType.h"
 
 LoadMenu::LoadMenu(Screen* zScreen)
     : Menu(zScreen)

+ 1 - 116
FactoryCraft/Main.cpp

@@ -2,131 +2,16 @@
 #include <FileSystem.h>
 #include <Font.h>
 #include <GraphicsApi.h>
-#include <HttpRequest.h>
-#include <JSON.h>
 #include <main.h>
 #include <Network.h>
 #include <RenderThread.h>
 #include <Screen.h>
-#include <Texture.h>
 #include <Window.h>
 
 #include "CustomDX12API.h"
 #include "Globals.h"
 #include "Initialization.h"
-
-void createModels(Screen* zScreen);
-
-/* Test rendering of specific block types
-int KSGStart Framework::Start(Framework::Startparam p)
-{
-    Network::Start(20);
-    initVariables();
-    setDebugDX(1);
-
-    File d;
-    d.setFile("data/schriften");
-    auto list = d.getFileList();
-    for (Text* fontFile : *list)
-    {
-        LTDSFile dat;
-        dat.setPfad(
-            new Text(Text("data/schriften/").operator+(fontFile->getText())));
-        dat.readData();
-        Text* name = fontFile->getTeilText(0, fontFile->getLength() - 5);
-        fontRegister->put(*name, RCPointer<Font>::of(dat.loadFont()));
-        name->release();
-    }
-    list->release();
-
-    NativeWindow window;
-    ::window = &window;
-    WNDCLASS wc = Framework::F_Normal(p.hinst);
-    wc.lpszClassName = "Factory Craft";
-    window.create(WS_POPUPWINDOW, wc);
-    Monitor m = Framework::getMonitor(0);
-    window.setBounds(Point(m.x, m.y), Point(m.width, m.height));
-    window.setDisplayMode(SW_SHOWNORMAL);
-    window.setPreCloseAction([&window](void* p, void* f) {
-        StopMessageLoop(window.getWindowHandle());
-    });
-    window.setMouseAction(_ret1ME);
-    window.setKeyboardAction(_ret1TE);
-    Screen3D screen(
-        dynamic_cast<NativeWindow*>(window.getThis()), new CustomDX11API());
-    screen.setHandleUserInputsOnTick(1);
-    window.setScreen(dynamic_cast<Screen*>(screen.getThis()));
-    screen.setFillColor(0);
-
-    uiFactory = Framework::defaultUI(fontRegister->get("normal"), &screen);
-
-    createModels(&screen);
-
-    // loading textures
-    File texturF;
-    texturF.setFile("data/textures");
-    RCArray<Text>* files = texturF.getFileList();
-    if (files)
-    {
-        int count = 0;
-        for (Text* fileName : *files)
-        {
-            LTDBFile dat;
-            dat.setFile(new Text(Text("data/textures/") + *fileName));
-            dat.readData(0);
-            count += dat.getImageCount();
-        }
-        for (Text* fileName : *files)
-        {
-            LTDBFile dat;
-            dat.setFile(new Text(Text("data/textures/") + *fileName));
-            dat.readData(0);
-            for (Text* name : *dat.zImageListe())
-            {
-                Image* b = dat.load(0, new Text(*name));
-                screen.zGraphicsApi()
-                    ->createOrGetTexture(*fileName + "/" + *name, b)
-                    ->release();
-            }
-        }
-        files->release();
-    }
-
-    BlockType* type = new BlockType(
-        26, 1, ModelInfo("cube", "fluids.ltdb/water.png", 0, 6), 10, 1); //
-block type to render Block* b = type->createBlock(Vec3<float>(0, 0, 0));
-    unsigned char light[] = {255, 255, 255, 255, 255, 255};
-    b->setLightData(TOP, light);
-    b->setLightData(NORTH, light);
-    b->setLightData(EAST, light);
-    b->setLightData(SOUTH, light);
-    b->setLightData(WEST, light);
-    b->setLightData(BOTTOM, light);
-    Chunk *c = new Chunk(Point(0, 0));
-    c->setBlock(b);
-    World3D* w = new World3D();
-    w->addCollection(c);
-    Cam3D* kam = new Cam3D();
-    kam->setStyle(
-        Cam3D::Style::Movable | Cam3D::Style::Rotatable | Cam3D::Style::Tick);
-    kam->setPosition(Vec3<float>(10, 0, 0));
-    kam->setAusrichtung(Vec3<float>(0, 0, 0));
-    kam->setWorld(w);
-    screen.addKamera(kam);
-
-    RenderTh rTh;
-    rTh.setMaxFps(60);
-    rTh.setQuiet(1);
-    rTh.setScreen(dynamic_cast<Screen*>(screen.getThis()));
-
-    rTh.beginn();
-    StartMessageLoop();
-    rTh.terminate();
-    releaseVariables();
-    Network::Exit();
-    return 0;
-}
-*/
+#include "World.h"
 
 int KSGStart Framework::Start(Framework::Startparam p)
 {

+ 8 - 4
FactoryCraft/ModelInfo.cpp

@@ -1,12 +1,17 @@
 #include "ModelInfo.h"
 
+#include <GraphicsApi.h>
 #include <Texture.h>
 
 #include "Globals.h"
 
 using namespace Framework;
 
-ModelInfo::ModelInfo(const char* model, const char *texture, bool transparent, int numTextures, float size)
+ModelInfo::ModelInfo(const char* model,
+    const char* texture,
+    bool transparent,
+    int numTextures,
+    float size)
     : modelPath(model),
       transparent(transparent),
       size(size)
@@ -50,9 +55,8 @@ Framework::Model3DTexture* ModelInfo::getTexture() const
     int index = 0;
     for (Text* texturPath : texturPaths)
     {
-        Texture* tex
-            = uiFactory.initParam.bildschirm->zGraphicsApi()->createOrGetTexture(
-                texturPath->getText(), 0);
+        Texture* tex = uiFactory.initParam.bildschirm->zGraphicsApi()
+                           ->createOrGetTexture(texturPath->getText(), 0);
         texture->setPolygonTexture(index++, tex);
     }
     return texture;

+ 2 - 0
FactoryCraft/PlayerKam.cpp

@@ -2,8 +2,10 @@
 
 #include <Globals.h>
 
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
+#include "World.h"
 
 class MovementFlags
 {

+ 4 - 0
FactoryCraft/RecipieIngredient.cpp

@@ -1,10 +1,14 @@
 #include "RecipieIngredient.h"
 
 #include <FileSystem.h>
+#include <Image.h>
 #include <ToolTip.h>
 #include <XML.h>
 
+#include "FactoryClient.h"
 #include "Globals.h"
+#include "ItemType.h"
+#include "World.h"
 
 RecipieIngredientElement::RecipieIngredientElement()
     : Framework::UIMLElement()

+ 2 - 1
FactoryCraft/RecipieIngredient.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include <Image.h>
 #include <TextField.h>
 #include <UIMLView.h>
 
@@ -12,7 +13,7 @@ private:
 
 public:
     RecipieIngredientElement();
-    //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
+    //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
     //! ist
     bool isApplicableFor(Framework::XML::Element& element) override;
     //! erstellt eine neue Drawable zu einem gegebenen xml Element

+ 2 - 1
FactoryCraft/RecipieOutput.cpp

@@ -3,13 +3,14 @@
 #include <XML.h>
 
 #include "Globals.h"
+#include "ItemType.h"
 #include "UIMLToolTip.h"
 
 RecipieOutputElement::RecipieOutputElement()
     : Framework::UIMLElement()
 {}
 
-//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
+//! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
 //! ist
 bool RecipieOutputElement::isApplicableFor(Framework::XML::Element& element)
 {

+ 1 - 0
FactoryCraft/ServerSelection.cpp

@@ -15,6 +15,7 @@
 #include "Globals.h"
 #include "Initialization.h"
 #include "Load.h"
+#include "World.h"
 
 using namespace Framework;
 

+ 12 - 0
FactoryCraft/SimpleBlocksAnyHit.hlsl

@@ -45,6 +45,10 @@ void SimpleBlocksAnyHit(inout HitInfo payload, SimpleBlocksAttributes attrib)
             payload.color[i] = color;
             float tmpDistance = payload.distance[i];
             payload.distance[i] = distance;
+            int tmpDayLight = payload.dayLight[i];
+            payload.dayLight[i] = 0xFFFFFF;
+            int tmpDynamicLight = payload.dynamicLight[i];
+            payload.dynamicLight[i] = 0xFFFFFF;
             if (color.w == 1.f)
             {
                 payload.hitCount = i + 1;
@@ -55,10 +59,16 @@ void SimpleBlocksAnyHit(inout HitInfo payload, SimpleBlocksAttributes attrib)
                 {
                     float4 tmpColor2 = payload.color[j];
                     float tmpDistance2 = payload.distance[j];
+                    int tmpDayLight2 = payload.dayLight[j];
+                    int tmpDynamicLight2 = payload.dynamicLight[j];
                     payload.color[j] = tmpColor;
                     payload.distance[j] = tmpDistance;
+                    payload.dayLight[j] = tmpDayLight;
+                    payload.dynamicLight[j] = tmpDynamicLight;
                     tmpColor = tmpColor2;
                     tmpDistance = tmpDistance2;
+                    tmpDayLight = tmpDayLight2;
+                    tmpDynamicLight = tmpDynamicLight2;
                 }
             }
             break;
@@ -76,6 +86,8 @@ void SimpleBlocksAnyHit(inout HitInfo payload, SimpleBlocksAttributes attrib)
     {
         payload.color[payload.hitCount] = color;
         payload.distance[payload.hitCount] = distance;
+        payload.dayLight[payload.hitCount] = 0xFFFFFF;
+        payload.dynamicLight[payload.hitCount] = 0xFFFFFF;
         payload.hitCount++;
     }
     if (color.w < 1.f)

+ 2 - 0
FactoryCraft/StatusBars.cpp

@@ -4,7 +4,9 @@
 #include <Image.h>
 #include <XML.h>
 
+#include "FactoryClient.h"
 #include "Globals.h"
+#include "World.h"
 
 StatusBarsElement::StatusBarsElement()
     : UIMLElement()

+ 2 - 0
FactoryCraft/UIMLProgressAndStateView.cpp

@@ -5,7 +5,9 @@
 #include <TextField.h>
 #include <ToolTip.h>
 
+#include "FactoryClient.h"
 #include "Globals.h"
+#include "World.h"
 
 #undef max
 

+ 13 - 10
FactoryCraft/World.cpp

@@ -8,8 +8,11 @@
 #include <World3D.h>
 
 #include "Constants.h"
+#include "Dimension.h"
+#include "FactoryClient.h"
 #include "Game.h"
 #include "Globals.h"
+#include "PlayerKam.h"
 
 using namespace Network;
 using namespace Framework;
@@ -200,24 +203,24 @@ int World::update(bool background)
         {
             currentDimension->removeDistantChunks(
                 {(int)player->getPos().x, (int)player->getPos().y});
-            Point currentChunk
+            Framework::Point currentChunk
                 = getChunkCenter((int)player->getX(), (int)player->getY());
             for (int x = 0; x <= CHUNK_VISIBILITY_RANGE; x++)
             {
                 for (int y = 0; y <= CHUNK_VISIBILITY_RANGE; y++)
                 {
-                    std::function<void(Point)> requestChunk =
-                        [this](Point center) {
+                    std::function<void(Framework::Point)> requestChunk =
+                        [this](Framework::Point center) {
                             Chunk* zC = currentDimension->zChunk(center);
                             if (!zC)
                             {
                                 char msg[1];
                                 msg[0]
                                     = 0; // add observer and request chaunk data
-                                Point pos = center;
+                                Framework::Point pos = center;
                                 subLock.lockRead();
                                 bool found = 0;
-                                for (Point p : subscriptions)
+                                for (Framework::Point p : subscriptions)
                                 {
                                     if (p == pos)
                                     {
@@ -258,7 +261,7 @@ int World::update(bool background)
 
 void World::onTick(double time)
 {
-    //selectionModel->tick(0.1);
+    // selectionModel->tick(0.1);
     this->time += time;
     if (this->time >= dayLength + nightLength + transitionLength * 2)
     {
@@ -489,11 +492,11 @@ void World::setTarget(Framework::Model3D* zTarget)
     }
 }
 
-void World::onChunkAdded(Point pos)
+void World::onChunkAdded(Framework::Point pos)
 {
     subLock.lockWrite();
     int index = 0;
-    for (Point p : subscriptions)
+    for (Framework::Point p : subscriptions)
     {
         if (p == pos)
         {
@@ -519,12 +522,12 @@ FactoryCraftModel* World::zSelectedEffectModel() const
     return selectionModel;
 }
 
-Chunk* World::zChunk(Point center)
+Chunk* World::zChunk(Framework::Point center)
 {
     return currentDimension->zChunk(center);
 }
 
-Lock& World::getChunkReadLock()
+Framework::Lock& World::getChunkReadLock()
 {
     return currentDimension->getReadLock();
 }

+ 14 - 10
FactoryCraft/World.h

@@ -1,13 +1,17 @@
 #pragma once
 
-#include <Camera3D.h>
+#include <Critical.h>
 #include <Screen.h>
 #include <Thread.h>
 #include <World3D.h>
 
-#include "Dimension.h"
-#include "FactoryClient.h"
-#include "PlayerKam.h"
+class PlayerKam;
+class FactoryClient;
+class Dimension;
+class Entity;
+class Chunk;
+class FactoryCraftModel;
+class Block;
 
 class World : public Framework::Thread
 {
@@ -22,11 +26,11 @@ private:
     bool firstMessage;
     int ownEntityId;
     Framework::Model3D* currentTarget;
-    Array<Point> subscriptions;
+    Framework::Array<Framework::Point> subscriptions;
     FactoryClient* client;
     FactoryCraftModel* selectionModel;
-    ReadWriteLock subLock;
-    Critical targetLock;
+    Framework::ReadWriteLock subLock;
+    Framework::Critical targetLock;
     float dayLightFactor;
     double time;
     double dayLength;
@@ -53,9 +57,9 @@ public:
     int getCurrentPlayerId() const;
     Entity* getCurrentPlayerEntity() const;
     void setTarget(Framework::Model3D* zTarget);
-    void onChunkAdded(Point pos);
-    Chunk* zChunk(Point center);
-    Lock& getChunkReadLock();
+    void onChunkAdded(Framework::Point pos);
+    Chunk* zChunk(Framework::Point center);
+    Framework::Lock& getChunkReadLock();
     Framework::Model3D* getCurrentTarget() const;
     FactoryCraftModel* zSelectedEffectModel() const;
     FactoryClient* zClient() const;