فهرست منبع

greatly improve rendering performance

Kolja Strohm 1 ماه پیش
والد
کامیت
a8c2cfa369

+ 5 - 0
FactoryCraft/FactoryClient.cpp

@@ -4,6 +4,7 @@
 #include <FileSystem.h>
 #include <Image.h>
 #include <M3File.h>
+#include <RenderThread.h>
 #include <Texture.h>
 
 #include "Globals.h"
@@ -473,6 +474,8 @@ FactoryClient::~FactoryClient()
     if (client) disconnect();
 }
 
+extern Framework::RenderTh* renderThread;
+
 void FactoryClient::loadServerInfo()
 {
     LoadMenu* loadMenu = (LoadMenu*)(Menu*)menuRegister->get("load");
@@ -747,7 +750,9 @@ void FactoryClient::loadServerInfo()
                              ->createOrGetTexture(Text("rendered/items/")
                                                       + itemTypes[i]->getId(),
                                  dynamic_cast<Image*>(b->getThis()));
+        renderThread->writeLock().lock();
         window->zScreen()->zGraphicsApi()->renderKamera(kam, t);
+        renderThread->writeLock().unlock();
         Image* result = new Image();
         t->copyToImage(result);
         itemTypes[i]->setBild(result);

+ 8 - 6
FactoryCraft/FactoryCraftModel.cpp

@@ -19,12 +19,17 @@ FactoryCraftModel::FactoryCraftModel()
             "blocks.ltdb/crack.png", 0);
     effectAlpha = 0;
     memset(averageLight, 0, 8);
+    *(int*)averageLight = 0xFFFFFF00;
+    fallbackVertexLightBuffer = uiFactory.initParam.bildschirm->zGraphicsApi()
+                                    ->createStructuredBuffer(16);
+    fallbackVertexLightBuffer->setData(averageLight);
 }
 
 FactoryCraftModel::~FactoryCraftModel()
 {
     breakTextur->release();
     if (vertexLightBuffer) vertexLightBuffer->release();
+    fallbackVertexLightBuffer->release();
     delete[] lightBuffer;
 }
 
@@ -55,12 +60,8 @@ void FactoryCraftModel::beforeRender(Framework::GraphicsApi* api,
         }
         else
         {
-            World::INSTANCE->zFallbackVertexLightBuffer()->setData(
-                averageLight);
-            World::INSTANCE->zFallbackVertexLightBuffer()->setChanged();
-            World::INSTANCE->zFallbackVertexLightBuffer()->copyToGPU(8);
-            cApi->setVertexLightBuffer(
-                World::INSTANCE->zFallbackVertexLightBuffer());
+            fallbackVertexLightBuffer->copyToGPU(8);
+            cApi->setVertexLightBuffer(fallbackVertexLightBuffer);
         }
         if (destroyedState > 0 && effectAlpha)
         {
@@ -149,4 +150,5 @@ void FactoryCraftModel::setAverageLight(unsigned char light[3])
     *(averageLight + 5) = light[2];
     *(averageLight + 6) = light[1];
     *(averageLight + 7) = light[0];
+    fallbackVertexLightBuffer->setChanged();
 }

+ 1 - 0
FactoryCraft/FactoryCraftModel.h

@@ -9,6 +9,7 @@ class FactoryCraftModel : public Framework::Model3D
 {
 private:
     Framework::DXBuffer* vertexLightBuffer;
+    Framework::DXBuffer* fallbackVertexLightBuffer;
     __int64* lightBuffer;
     int vertexLightBufferCount;
     bool visible;

+ 28 - 26
FactoryCraft/Game.cpp

@@ -168,35 +168,37 @@ void Game::api(char* data)
                 char* uiml = new char[uimlLen + 1];
                 memcpy(uiml, data + 7 + len, uimlLen);
                 uiml[uimlLen] = 0;
-                UIMLDialog* dialog
-                    = new UIMLDialog(uiml, [this](UIMLDialog* dialog) {
-                          window->zScreen()->postAction([this, dialog]() {
-                              int index = 0;
-                              dialogLock.lockWrite();
-                              for (UIMLDialog* d : dialogs)
-                              {
-                                  if (d == dialog)
+                window->zScreen()->postAction([this, uiml]() {
+                    UIMLDialog* dialog
+                        = new UIMLDialog(uiml, [this](UIMLDialog* dialog) {
+                              window->zScreen()->postAction([this, dialog]() {
+                                  int index = 0;
+                                  dialogLock.lockWrite();
+                                  for (UIMLDialog* d : dialogs)
                                   {
-                                      window->zScreen()->removeMember(d);
-                                      dialogs.remove(index);
-                                      World::INSTANCE->zKamera()
-                                          ->setControlEnabled(
-                                              dialogs.getEntryCount() == 0);
-                                      updateRecipieVisibility();
-                                      break;
+                                      if (d == dialog)
+                                      {
+                                          window->zScreen()->removeMember(d);
+                                          dialogs.remove(index);
+                                          World::INSTANCE->zKamera()
+                                              ->setControlEnabled(
+                                                  dialogs.getEntryCount() == 0);
+                                          updateRecipieVisibility();
+                                          break;
+                                      }
+                                      index++;
                                   }
-                                  index++;
-                              }
-                              dialogLock.unlockWrite();
+                                  dialogLock.unlockWrite();
+                              });
                           });
-                      });
-                dialogLock.lockWrite();
-                dialogs.add(dialog);
-                dialogLock.unlockWrite();
-                updateRecipieVisibility();
-                World::INSTANCE->zKamera()->setControlEnabled(0);
-                window->zScreen()->addMember(dialog);
-                delete[] uiml;
+                    dialogLock.lockWrite();
+                    dialogs.add(dialog);
+                    dialogLock.unlockWrite();
+                    updateRecipieVisibility();
+                    World::INSTANCE->zKamera()->setControlEnabled(0);
+                    window->zScreen()->addMember(dialog);
+                    delete[] uiml;
+                    });
             }
             break;
         }

+ 3 - 0
FactoryCraft/Main.cpp

@@ -128,6 +128,8 @@ block type to render Block* b = type->createBlock(Vec3<float>(0, 0, 0));
 }
 */
 
+RenderTh* renderThread;
+
 int KSGStart Framework::Start(Framework::Startparam p)
 {
     Network::Start(20);
@@ -205,6 +207,7 @@ int KSGStart Framework::Start(Framework::Startparam p)
             World::INSTANCE->onTick(time);
         }
     });
+    renderThread = &rTh;
 
     rTh.beginn();
     StartMessageLoop();

+ 0 - 13
FactoryCraft/World.cpp

@@ -38,14 +38,6 @@ World::World(Screen3D* zScreen, FactoryClient* client)
     dayLength = 1000;
     transitionLength = 0;
     nightLength = 0;
-    fallbackVertexLightBuffer
-        = zScreen->zGraphicsApi()->createStructuredBuffer(16);
-    char data[16];
-    memset(data, 0, 16);
-    *(int*)data = 0xFFFFFF00;
-    fallbackVertexLightBuffer->setData(data);
-    fallbackVertexLightBuffer->setLength(16);
-    fallbackVertexLightBuffer->copyToGPU();
     selectionModel = new FactoryCraftModel();
     selectionModel->setModelData(zScreen->zGraphicsApi()->getModel("cube"));
     selectionModel->setSize(1.005f);
@@ -545,9 +537,4 @@ FactoryClient* World::zClient() const
 float World::getDayLightFactor() const
 {
     return dayLightFactor;
-}
-
-Framework::DXBuffer* World::zFallbackVertexLightBuffer()
-{
-    return fallbackVertexLightBuffer;
 }

+ 0 - 2
FactoryCraft/World.h

@@ -32,7 +32,6 @@ private:
     double dayLength;
     double transitionLength;
     double nightLength;
-    Framework::DXBuffer* fallbackVertexLightBuffer;
 
 public:
     World(Framework::Screen3D* zScreen, FactoryClient* client);
@@ -61,5 +60,4 @@ public:
     FactoryCraftModel* zSelectedEffectModel() const;
     FactoryClient* zClient() const;
     float getDayLightFactor() const;
-    Framework::DXBuffer* zFallbackVertexLightBuffer();
 };