Browse Source

Split data files to Data & CoreData. CoreData contains the bare necessary files needed to run, like shaders and default materials.
Added systemCommand() function.
Added file extensions to ignore in PackageTool.
Optimized Console text update.
Cleaned up ShaderCompiler code.

Lasse Öörni 15 years ago
parent
commit
97d3e56a1f

+ 0 - 0
Bin/Data/Materials/Default.xml → Bin/CoreData/Materials/Default.xml


+ 0 - 0
Bin/Data/Materials/DefaultAlpha.xml → Bin/CoreData/Materials/DefaultAlpha.xml


+ 0 - 0
Bin/Data/Materials/DefaultDiff.xml → Bin/CoreData/Materials/DefaultDiff.xml


+ 0 - 0
Bin/Data/Materials/DefaultDiffAlpha.xml → Bin/CoreData/Materials/DefaultDiffAlpha.xml


+ 0 - 0
Bin/Data/Materials/DefaultDiffAlphaMask.xml → Bin/CoreData/Materials/DefaultDiffAlphaMask.xml


+ 0 - 0
Bin/Data/Materials/DefaultDiffNormal.xml → Bin/CoreData/Materials/DefaultDiffNormal.xml


+ 0 - 0
Bin/Data/Materials/DefaultDiffNormalAlphaMask.xml → Bin/CoreData/Materials/DefaultDiffNormalAlphaMask.xml


+ 0 - 0
Bin/Data/Textures/Ramp.png → Bin/CoreData/Textures/Ramp.png


+ 0 - 0
Bin/Data/Textures/Ramp.xml → Bin/CoreData/Textures/Ramp.xml


+ 0 - 0
Bin/Data/Textures/RampExtreme.png → Bin/CoreData/Textures/RampExtreme.png


+ 0 - 0
Bin/Data/Textures/RampExtreme.xml → Bin/CoreData/Textures/RampExtreme.xml


+ 0 - 0
Bin/Data/Textures/RampWide.png → Bin/CoreData/Textures/RampWide.png


+ 0 - 0
Bin/Data/Textures/RampWide.xml → Bin/CoreData/Textures/RampWide.xml


+ 0 - 0
Bin/Data/Textures/Spot.png → Bin/CoreData/Textures/Spot.png


+ 0 - 0
Bin/Data/Textures/Spot.xml → Bin/CoreData/Textures/Spot.xml


+ 0 - 0
Bin/Data/Textures/SpotWide.png → Bin/CoreData/Textures/SpotWide.png


+ 0 - 0
Bin/Data/Textures/SpotWide.xml → Bin/CoreData/Textures/SpotWide.xml


+ 0 - 0
Bin/Data/Textures/UI.png → Bin/CoreData/Textures/UI.png


+ 0 - 0
Bin/Data/Textures/UI.xml → Bin/CoreData/Textures/UI.xml


+ 0 - 0
Bin/Data/UI/DefaultStyle.xml → Bin/CoreData/UI/DefaultStyle.xml


+ 2 - 0
Bin/CreatePackages.bat

@@ -0,0 +1,2 @@
+PackageTool CoreData CoreData.pak
+PackageTool Data Data.pak

+ 5 - 5
CMakeLists.txt

@@ -89,18 +89,18 @@ endmacro ()
 # Macro for shader asset compilation
 # Macro for shader asset compilation
 macro (add_shader NAME)
 macro (add_shader NAME)
     add_custom_command (
     add_custom_command (
-        OUTPUT ../../Bin/Data/Shaders/SM2/${NAME}.xml
-        COMMAND ../../Bin/ShaderCompiler ${NAME}.xml ../../Bin/Data/Shaders/SM2 SM2
+        OUTPUT ../../Bin/CoreData/Shaders/SM2/${NAME}.xml
+        COMMAND ../../Bin/ShaderCompiler ${NAME}.xml ../../Bin/CoreData/Shaders/SM2 SM2
         DEPENDS ShaderCompiler Common.hlsl ${NAME}.hlsl ${NAME}.xml
         DEPENDS ShaderCompiler Common.hlsl ${NAME}.hlsl ${NAME}.xml
     )
     )
 
 
     add_custom_command (
     add_custom_command (
-        OUTPUT ../../Bin/Data/Shaders/SM3/${NAME}.xml
-        COMMAND ../../Bin/ShaderCompiler ${NAME}.xml ../../Bin/Data/Shaders/SM3 SM3
+        OUTPUT ../../Bin/CoreData/Shaders/SM3/${NAME}.xml
+        COMMAND ../../Bin/ShaderCompiler ${NAME}.xml ../../Bin/CoreData/Shaders/SM3 SM3
         DEPENDS ShaderCompiler Common.hlsl ${NAME}.hlsl ${NAME}.xml
         DEPENDS ShaderCompiler Common.hlsl ${NAME}.hlsl ${NAME}.xml
     )
     )
 
 
-    set (ALL_SHADERS ${ALL_SHADERS} ../../Bin/Data/Shaders/SM2/${NAME}.xml ../../Bin/Data/Shaders/SM3/${NAME}.xml)
+    set (ALL_SHADERS ${ALL_SHADERS} ../../Bin/CoreData/Shaders/SM2/${NAME}.xml ../../Bin/CoreData/Shaders/SM3/${NAME}.xml)
 endmacro ()
 endmacro ()
 
 
 # Recurse subdirectories
 # Recurse subdirectories

+ 11 - 0
Engine/Common/File.cpp

@@ -27,6 +27,7 @@
 #include "PackageFile.h"
 #include "PackageFile.h"
 #include "StringUtils.h"
 #include "StringUtils.h"
 
 
+#include <cstdlib>
 #include <direct.h>
 #include <direct.h>
 #include <windows.h>
 #include <windows.h>
 
 
@@ -253,6 +254,16 @@ bool createDirectory(const std::string& pathName)
     return success;
     return success;
 }
 }
 
 
+int systemCommand(const std::string& commandLine)
+{
+    if (allowedDirectories.empty())
+        return system(commandLine.c_str());
+    else
+    {
+        LOGERROR("Executing an external command is not allowed");
+        return -1;
+    }
+}
 
 
 void registerDirectory(const std::string& pathName)
 void registerDirectory(const std::string& pathName)
 {
 {

+ 2 - 0
Engine/Common/File.h

@@ -105,6 +105,8 @@ std::string getCurrentDirectory();
 bool setCurrentDirectory(const std::string& pathName);
 bool setCurrentDirectory(const std::string& pathName);
 //! Create a directory
 //! Create a directory
 bool createDirectory(const std::string& pathName);
 bool createDirectory(const std::string& pathName);
+//! Execute an external command, block until it exists and return the exit code. Will fail if any allowed paths are defined
+int systemCommand(const std::string& commandLine);
 //! Register a path as being allowed to access
 //! Register a path as being allowed to access
 void registerDirectory(const std::string& pathName);
 void registerDirectory(const std::string& pathName);
 //! Check if a path is allowed to be accessed. If no paths defined, all are allowed
 //! Check if a path is allowed to be accessed. If no paths defined, all are allowed

+ 5 - 4
Engine/Engine/Console.cpp

@@ -268,9 +268,10 @@ void Console::handleLogMessage(StringHash eventType, VariantMap& eventData)
     
     
     for (unsigned i = 0; i < rows.size(); ++i)
     for (unsigned i = 0; i < rows.size(); ++i)
     {
     {
-        for (int j = 0; j < (int)mRows.size() - 1; ++j)
-            mRows[j]->setText(mRows[j + 1]->getText());
-        
-        mRows[mRows.size() - 1]->setText(rows[i]);
+        // Remove the first row, change its text and re-add to the bottom
+        Text* text = static_cast<Text*>(mRowContainer->getChild(0));
+        mRowContainer->removeChild(text);
+        text->setText(rows[i]);
+        mRowContainer->addChild(text);
     }
     }
 }
 }

+ 1 - 1
Engine/Engine/RegisterCommon.cpp

@@ -610,7 +610,7 @@ static void registerSerialization(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("string getCurrentDirectory()", asFUNCTION(getCurrentDirectory), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getCurrentDirectory()", asFUNCTION(getCurrentDirectory), asCALL_CDECL);
     engine->RegisterGlobalFunction("void setCurrentDirectory(const string& in)", asFUNCTION(setCurrentDirectory), asCALL_CDECL);
     engine->RegisterGlobalFunction("void setCurrentDirectory(const string& in)", asFUNCTION(setCurrentDirectory), asCALL_CDECL);
     engine->RegisterGlobalFunction("bool createDirectory(const string& in)", asFUNCTION(createDirectory), asCALL_CDECL);
     engine->RegisterGlobalFunction("bool createDirectory(const string& in)", asFUNCTION(createDirectory), asCALL_CDECL);
-    
+    engine->RegisterGlobalFunction("int systemCommand(const string& in)", asFUNCTION(systemCommand), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getPath(const string& in)", asFUNCTION(getPath), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getPath(const string& in)", asFUNCTION(getPath), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getFileName(const string& in)", asFUNCTION(getFileName), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getFileName(const string& in)", asFUNCTION(getFileName), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getExtension(const string& in, bool)", asFUNCTION(getExtension), asCALL_CDECL);
     engine->RegisterGlobalFunction("string getExtension(const string& in, bool)", asFUNCTION(getExtension), asCALL_CDECL);

+ 21 - 0
Tools/PackageTool/PackageTool.cpp

@@ -55,6 +55,12 @@ std::string gBasePath;
 std::vector<FileEntry> gEntries;
 std::vector<FileEntry> gEntries;
 unsigned gChecksum = 0;
 unsigned gChecksum = 0;
 
 
+std::string ignoreExtensions[] = {
+    ".bak",
+    ".rule",
+    ""
+};
+
 int main(int argc, char** argv)
 int main(int argc, char** argv)
 {
 {
     std::vector<std::string> arguments;
     std::vector<std::string> arguments;
@@ -90,6 +96,21 @@ void run(const std::vector<std::string>& arguments)
     scanDirectory(fileNames, dirName, "*.*", SCAN_FILES, true);
     scanDirectory(fileNames, dirName, "*.*", SCAN_FILES, true);
     if (!fileNames.size())
     if (!fileNames.size())
         errorExit("No files found");
         errorExit("No files found");
+    
+    // Check for extensions to ignore
+    for (unsigned i = fileNames.size() - 1; i < fileNames.size(); --i)
+    {
+        std::string extension = getExtension(fileNames[i]);
+        for (unsigned j = 0; ignoreExtensions[j].length(); ++j)
+        {
+            if (extension == ignoreExtensions[j])
+            {
+                fileNames.erase(fileNames.begin() + i);
+                break;
+            }
+        }
+    }
+    
     for (unsigned i = 0; i < fileNames.size(); ++i)
     for (unsigned i = 0; i < fileNames.size(); ++i)
         processFile(fileNames[i], dirName);
         processFile(fileNames[i], dirName);
     
     

+ 18 - 54
Tools/ShaderCompiler/ShaderCompiler.cpp

@@ -26,14 +26,9 @@
 #include "StringUtils.h"
 #include "StringUtils.h"
 #include "XMLFile.h"
 #include "XMLFile.h"
 
 
-#include <cstdio>
-#include <cstdlib>
 #include <cstring>
 #include <cstring>
 #include <fstream>
 #include <fstream>
 #include <iostream>
 #include <iostream>
-#include <string>
-#include <vector>
-#include <map>
 
 
 #include "DebugNew.h"
 #include "DebugNew.h"
 
 
@@ -570,24 +565,21 @@ bool compile(ShaderType type, const std::string& input, const std::string& outpu
 {
 {
     bool compiled = false;
     bool compiled = false;
     
     
+    std::string allDefines;
+    for (unsigned i = 0; i < defines.size(); ++i)
+        allDefines += "/D" + defines[i] + " ";
+    for (unsigned i = 0; i < gDefines.size(); ++i)
+        allDefines += "/D" + gDefines[i] + " ";
+    
     if (type == VS)
     if (type == VS)
     {
     {
         if (!gUseSM3)
         if (!gUseSM3)
         {
         {
             std::string outFile = output + ".vs2";
             std::string outFile = output + ".vs2";
-            std::string command = "fxc /Tvs_2_0 /O3 /Evs /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt ";
-            for (unsigned i = 0; i < defines.size(); ++i)
-            {
-                command += "/D" + defines[i] + " ";
-            }
-            for (unsigned i = 0; i < gDefines.size(); ++i)
-            {
-                command += "/D" + gDefines[i] + " ";
-            }
-            
-            command += gInDir + input + ".hlsl";
+            std::string command = "fxc /Tvs_2_0 /O3 /Evs /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt " + allDefines +
+                gInDir + input + ".hlsl";
             
             
-            if (system(command.c_str()))
+            if (systemCommand(command))
                 errorExit("Failed to compile shader " + outFile);
                 errorExit("Failed to compile shader " + outFile);
             
             
             compiled = true;
             compiled = true;
@@ -595,20 +587,10 @@ bool compile(ShaderType type, const std::string& input, const std::string& outpu
         else
         else
         {
         {
             std::string outFile = output + ".vs3";
             std::string outFile = output + ".vs3";
-            std::string command = "fxc /Tvs_3_0 /O3 /Evs /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt ";
-            for (unsigned i = 0; i < defines.size(); ++i)
-            {
-                command += "/D" + defines[i] + " ";
-            }
-            for (unsigned i = 0; i < gDefines.size(); ++i)
-            {
-                command += "/D" + gDefines[i] + " ";
-            }
-            
+            std::string command = "fxc /Tvs_3_0 /O3 /Evs /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt " + allDefines +
+                gInDir + input + ".hlsl";
             
             
-            command += gInDir + input + ".hlsl";
-            
-            if (system(command.c_str()))
+            if (systemCommand(command))
                 errorExit("Failed to compile shader " + outFile);
                 errorExit("Failed to compile shader " + outFile);
             
             
             compiled = true;
             compiled = true;
@@ -620,20 +602,11 @@ bool compile(ShaderType type, const std::string& input, const std::string& outpu
         if (!gUseSM3)
         if (!gUseSM3)
         {
         {
             std::string outFile = output + ".ps2";
             std::string outFile = output + ".ps2";
-            std::string command = "fxc /Tps_2_0 /O3 /Eps /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt ";
-            for (unsigned i = 0; i < defines.size(); ++i)
-            {
-                command += "/D" + defines[i] + " ";
-            }
-            for (unsigned i = 0; i < gDefines.size(); ++i)
-            {
-                command += "/D" + gDefines[i] + " ";
-            }
-            
-            command += gInDir + input + ".hlsl";
+            std::string command = "fxc /Tps_2_0 /O3 /Eps /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt " + allDefines +
+                gInDir + input + ".hlsl";
             
             
             std::cout << command << std::endl;
             std::cout << command << std::endl;
-            if (system(command.c_str()))
+            if (systemCommand(command))
                 errorExit("Failed to compile shader " + outFile);
                 errorExit("Failed to compile shader " + outFile);
             
             
             compiled = true;
             compiled = true;
@@ -641,20 +614,11 @@ bool compile(ShaderType type, const std::string& input, const std::string& outpu
         else
         else
         {
         {
             std::string outFile = output + ".ps3";
             std::string outFile = output + ".ps3";
-            std::string command = "fxc /Tps_3_0 /O3 /Gfp /Eps /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt ";
-            for (unsigned i = 0; i < defines.size(); ++i)
-            {
-                command += "/D" + defines[i] + " ";
-            }
-            for (unsigned i = 0; i < gDefines.size(); ++i)
-            {
-                command += "/D" + gDefines[i] + " ";
-            }
-            
-            command += gInDir + input + ".hlsl";
+            std::string command = "fxc /Tps_3_0 /O3 /Gfp /Eps /Fo" + gOutDir + gInDir + outFile + " /Fcoutput.txt " + allDefines +
+                gInDir + input + ".hlsl";
             
             
             std::cout << command << std::endl;
             std::cout << command << std::endl;
-            if (system(command.c_str()))
+            if (systemCommand(command))
                 errorExit("Failed to compile shader" + outFile);
                 errorExit("Failed to compile shader" + outFile);
             
             
             compiled = true;
             compiled = true;