Selaa lähdekoodia

Additional delta

Josh Engebretson 9 vuotta sitten
vanhempi
sitoutus
f49d1d7303

+ 11 - 0
Source/Atomic/Core/StringUtils.cpp

@@ -698,4 +698,15 @@ String GetFileSizeString(unsigned long long memorySize)
     return output;
     return output;
 }
 }
 
 
+// ATOMIC BEGIN
+
+String ToStringVariadic(const char* formatString, va_list args)
+{
+    String ret;
+    ret.AppendWithFormatArgs(formatString, args);
+    return ret;
+}
+
+// ATOMIC END
+
 }
 }

+ 4 - 0
Source/Atomic/Core/StringUtils.h

@@ -124,4 +124,8 @@ ATOMIC_API unsigned ToLower(unsigned ch);
 /// Convert a memory size into a formatted size string, of the style "1.5 Mb".
 /// Convert a memory size into a formatted size string, of the style "1.5 Mb".
 ATOMIC_API String GetFileSizeString(unsigned long long memorySize);
 ATOMIC_API String GetFileSizeString(unsigned long long memorySize);
 
 
+// ATOMIC BEGIN
+ATOMIC_API String ToStringVariadic(const char* formatString, va_list args);
+// ATOMIC END
+
 }
 }

+ 18 - 4
Source/Atomic/Engine/Engine.cpp

@@ -232,7 +232,10 @@ bool Engine::Initialize(const VariantMap& parameters)
             unsigned j = 0;
             unsigned j = 0;
             for (; j < resourcePrefixPaths.Size(); ++j)
             for (; j < resourcePrefixPaths.Size(); ++j)
             {
             {
-                String packageName = resourcePrefixPaths[j] + resourcePaths[i] + ".pak";
+                // ATOMIC BEGIN
+                String packageName = resourcePrefixPaths[j] + resourcePaths[i] + PAK_EXTENSION;
+                // ATOMIC END
+
                 if (fileSystem->FileExists(packageName))
                 if (fileSystem->FileExists(packageName))
                 {
                 {
                     if (cache->AddPackageFile(packageName))
                     if (cache->AddPackageFile(packageName))
@@ -324,7 +327,9 @@ bool Engine::Initialize(const VariantMap& parameters)
 
 
                 // Add all the found package files (non-recursive)
                 // Add all the found package files (non-recursive)
                 Vector<String> paks;
                 Vector<String> paks;
-                fileSystem->ScanDir(paks, autoLoadPath, "*.pak", SCAN_FILES, false);
+                // ATOMIC BEGIN
+                fileSystem->ScanDir(paks, autoLoadPath, ToString("*.%s", PAK_EXTENSION), SCAN_FILES, false);
+                // ATOMIC END
                 for (unsigned y = 0; y < paks.Size(); ++y)
                 for (unsigned y = 0; y < paks.Size(); ++y)
                 {
                 {
                     String pak = paks[y];
                     String pak = paks[y];
@@ -372,8 +377,10 @@ bool Engine::Initialize(const VariantMap& parameters)
 #endif
 #endif
 
 
         if (!graphics->SetMode(
         if (!graphics->SetMode(
-            GetParameter(parameters, "WindowWidth", 0).GetInt(),
-            GetParameter(parameters, "WindowHeight", 0).GetInt(),
+// ATOMIC BEGIN
+            GetParameter(parameters, "WindowMaximized", false).GetBool() ? 0 : GetParameter(parameters, "WindowWidth", 0).GetInt(),
+            GetParameter(parameters, "WindowMaximized", false).GetBool() ? 0 : GetParameter(parameters, "WindowHeight", 0).GetInt(),
+// ATOMIC END
             GetParameter(parameters, "FullScreen", true).GetBool(),
             GetParameter(parameters, "FullScreen", true).GetBool(),
             GetParameter(parameters, "Borderless", false).GetBool(),
             GetParameter(parameters, "Borderless", false).GetBool(),
             GetParameter(parameters, "WindowResizable", false).GetBool(),
             GetParameter(parameters, "WindowResizable", false).GetBool(),
@@ -918,6 +925,13 @@ VariantMap Engine::ParseParameters(const Vector<String>& arguments)
             }
             }
             else if (argument == "touch")
             else if (argument == "touch")
                 ret["TouchEmulation"] = true;
                 ret["TouchEmulation"] = true;
+            // ATOMIC BEGIN
+            else if (argument == "logname" && !value.Empty())
+            {
+                ret["LogName"] = value;
+                ++i;
+            }
+            // ATOMIC END
 #ifdef ATOMIC_TESTING
 #ifdef ATOMIC_TESTING
             else if (argument == "timeout" && !value.Empty())
             else if (argument == "timeout" && !value.Empty())
             {
             {

+ 8 - 0
Source/Atomic/Graphics/Material.cpp

@@ -1270,4 +1270,12 @@ void Material::HandleAttributeAnimationUpdate(StringHash eventType, VariantMap&
         SetShaderParameterAnimation(finishedNames[i], 0);
         SetShaderParameterAnimation(finishedNames[i], 0);
 }
 }
 
 
+// ATOMIC BEGIN
+const char** Material::GetTextureUnitNames()
+{
+    return textureUnitNames;
+}
+// ATOMIC END
+
+
 }
 }

+ 5 - 0
Source/Atomic/Graphics/Material.h

@@ -237,6 +237,11 @@ public:
     /// Parse a shader parameter value from a string. Retunrs either a bool, a float, or a 2 to 4-component vector.
     /// Parse a shader parameter value from a string. Retunrs either a bool, a float, or a 2 to 4-component vector.
     static Variant ParseShaderParameterValue(const String& value);
     static Variant ParseShaderParameterValue(const String& value);
 
 
+    // ATOMIC BEGIN
+    /// Return the names of supported texture units, with null sentinel on list
+    static const char** GetTextureUnitNames();
+    // ATOMIC END
+
 private:
 private:
     /// Helper function for loading JSON files
     /// Helper function for loading JSON files
     bool BeginLoadJSON(Deserializer& source);
     bool BeginLoadJSON(Deserializer& source);

+ 32 - 0
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -2308,6 +2308,38 @@ void Graphics::Restore()
     {
     {
         impl_->context_ = SDL_GL_CreateContext(window_);
         impl_->context_ = SDL_GL_CreateContext(window_);
 
 
+// ATOMIC BEGIN
+#if defined(__linux__)
+
+    String driverx( (const char*)glGetString(GL_VERSION) );
+    Vector<String>tokens = driverx.Split (' ');
+    if (tokens.Size() > 2) // must have enough tokens to work with
+    {
+        // Size() - 2 is the manufacturer, "Mesa" is the target
+        if ( tokens[ tokens.Size()-2].Compare ( "Mesa", false ) == 0 )
+        {
+            // Size() - 1  is the version number, convert to long, can be n | n.n | n.n.n
+            Vector<String>versionx = tokens[tokens.Size()-1].Split ('.');
+            int majver = 0;
+            int minver = 0;
+            int pointver = 0;
+            if ( tokens.Size() > 1 ) majver = atoi(versionx[0].CString());
+            if ( tokens.Size() > 2 ) minver = atoi(versionx[1].CString());
+            if ( tokens.Size() > 3 ) pointver = atoi(versionx[2].CString());
+
+            int allver = (majver * 10000) + (minver * 1000) + pointver;
+
+            if ( allver < 101004 ) // Mesa drivers less than this version cause linux display artifacts
+            {                      // so remove this context and let it fall back to GL2
+                SDL_GL_DeleteContext(impl_->context_);
+                impl_->context_ = NULL;
+                LOGINFOF ( "Mesa GL Driver: %s detected, forcing GL2 context creation.  Please use gl2 command line option to avoid this warning.", driverx.CString() );
+            }
+        }
+    }
+#endif
+// ATOMIC END
+
 #ifndef GL_ES_VERSION_2_0
 #ifndef GL_ES_VERSION_2_0
         // If we're trying to use OpenGL 3, but context creation fails, retry with 2
         // If we're trying to use OpenGL 3, but context creation fails, retry with 2
         if (!forceGL2_ && !impl_->context_)
         if (!forceGL2_ && !impl_->context_)

+ 8 - 2
Source/Atomic/IO/File.cpp

@@ -49,7 +49,10 @@ static const wchar_t* openMode[] =
     L"rb",
     L"rb",
     L"wb",
     L"wb",
     L"r+b",
     L"r+b",
-    L"w+b"
+    L"w+b",
+// ATOMIC BEGIN
+    L"a+b"
+// ATOMIC END
 };
 };
 #else
 #else
 static const char* openMode[] =
 static const char* openMode[] =
@@ -57,7 +60,10 @@ static const char* openMode[] =
     "rb",
     "rb",
     "wb",
     "wb",
     "r+b",
     "r+b",
-    "w+b"
+    "w+b",
+// ATOMIC BEGIN
+    "a+b"
+// ATOMIC END
 };
 };
 #endif
 #endif
 
 

+ 4 - 1
Source/Atomic/IO/File.h

@@ -52,7 +52,10 @@ enum FileMode
 {
 {
     FILE_READ = 0,
     FILE_READ = 0,
     FILE_WRITE,
     FILE_WRITE,
-    FILE_READWRITE
+    FILE_READWRITE,
+// ATOMIC BEGIN
+    FILE_APPEND
+// ATOMIC END
 };
 };
 
 
 class PackageFile;
 class PackageFile;

+ 3 - 1
Source/Atomic/IO/FileSystem.cpp

@@ -812,7 +812,9 @@ void FileSystem::ScanDirInternal(Vector<String>& result, String path, const Stri
     if (path.Length() > startPath.Length())
     if (path.Length() > startPath.Length())
         deltaPath = path.Substring(startPath.Length());
         deltaPath = path.Substring(startPath.Length());
 
 
-    String filterExtension = filter.Substring(filter.Find('.'));
+// ATOMIC BEGIN
+    String filterExtension = filter.Substring(filter.FindLast('.'));
+// ATOMIC END
     if (filterExtension.Contains('*'))
     if (filterExtension.Contains('*'))
         filterExtension.Clear();
         filterExtension.Clear();
 
 

+ 58 - 0
Source/Atomic/Resource/Image.cpp

@@ -2201,6 +2201,64 @@ bool Image::HasAlphaChannel() const
     return components_ > 3;
     return components_ > 3;
 }
 }
 
 
+bool Image::SetSubimage(const Image* image, const IntRect& rect)
+{
+    if (!data_)
+        return false;
+
+    if (depth_ > 1 || IsCompressed())
+    {
+        ATOMIC_LOGERROR("SetSubimage not supported for Compressed or 3D images");
+        return false;
+    }
+
+    if (rect.left_ < 0 || rect.top_ < 0 || rect.right_ > width_ || rect.bottom_ > height_ || !rect.Width() || !rect.Height())
+    {
+        ATOMIC_LOGERROR("Can not set subimage in image " + GetName() + " with invalid region");
+        return false;
+    }
+
+    int width = rect.Width();
+    int height = rect.Height();
+    if (width == image->GetWidth() && height == image->GetHeight())
+    {
+        int components = Min((int)components_, (int)image->components_);
+
+        unsigned char* src = image->GetData();
+        unsigned char* dest = data_.Get() + (rect.top_ * width_ + rect.left_) * components_;
+        for (int i = 0; i < height; ++i)
+        {
+            memcpy(dest, src, width * components);
+
+            src += width * image->components_;
+            dest += width_ * components_;
+        }
+    }
+    else
+    {
+        unsigned uintColor;
+        unsigned char* dest = data_.Get() + (rect.top_ * width_ + rect.left_) * components_;
+        unsigned char* src = (unsigned char*)&uintColor;
+        for (int y = 0; y < height; ++y)
+        {
+            for (int x = 0; x < width; ++x)
+            {
+                // Calculate float coordinates between 0 - 1 for resampling
+                float xF = (image->width_ > 1) ? (float)x / (float)(width - 1) : 0.0f;
+                float yF = (image->height_ > 1) ? (float)y / (float)(height - 1) : 0.0f;
+                uintColor = image->GetPixelBilinear(xF, yF).ToUInt();
+
+                memcpy(dest, src, components_);
+
+                dest += components_;
+            }
+            dest += (width_ - width) * components_;
+        }
+    }
+
+    return true;
+}
+
 
 
 // ATOMIC END
 // ATOMIC END
 
 

+ 2 - 0
Source/Atomic/Resource/Image.h

@@ -202,6 +202,8 @@ public:
     /// Whether this texture has an alpha channel
     /// Whether this texture has an alpha channel
     bool HasAlphaChannel() const;
     bool HasAlphaChannel() const;
     bool SaveDDS(const String& fileName) const;
     bool SaveDDS(const String& fileName) const;
+    /// Copy contents of the image into the defined rect, scaling if necessary. This image should already be large enough to include the rect. Compressed and 3D images are not supported.
+    bool SetSubimage(const Image* image, const IntRect& rect);
     // ATOMIC END
     // ATOMIC END
 
 
 private:
 private:

+ 24 - 0
Source/Atomic/Resource/ResourceCache.cpp

@@ -383,8 +383,32 @@ bool ResourceCache::ReloadResource(Resource* resource)
 
 
     bool success = false;
     bool success = false;
     SharedPtr<File> file = GetFile(resource->GetName());
     SharedPtr<File> file = GetFile(resource->GetName());
+
+// ATOMIC BEGIN
+
     if (file)
     if (file)
+    {
+#ifdef ATOMIC_PLATFORM_DESKTOP
+        String ext = GetExtension(resource->GetName());
+        if (ext == ".jpg" || ext == ".png" || ext == ".tga")
+        {
+            String ddsName = "DDS/" + resource->GetName() + ".dds";
+            SharedPtr<File> ddsFile = GetFile(ddsName, false);
+            if (ddsFile != NULL)
+                success = resource->Load(*(ddsFile.Get()));
+            else
+                success = resource->Load(*(file.Get()));
+        }
+        else
+        {
+            success = resource->Load(*(file.Get()));
+        }
+#else
         success = resource->Load(*(file.Get()));
         success = resource->Load(*(file.Get()));
+#endif
+    }
+
+// ATOMIC END
 
 
     if (success)
     if (success)
     {
     {

+ 5 - 1
Source/AtomicEditor/Application/AEEditorPrefs.cpp

@@ -128,8 +128,12 @@ namespace AtomicEditor
 
 
             prefs[editor ? "editorWindow" : "playerWindow"] = window;
             prefs[editor ? "editorWindow" : "playerWindow"] = window;
 
 
+
+            // TODO: add highDPI support
+            bool highDPI = false;
+
             //Setting the mode to 0 width/height will use engine defaults for window size and layout
             //Setting the mode to 0 width/height will use engine defaults for window size and layout
-            graphics->SetMode(0, 0, graphics->GetFullscreen(), graphics->GetBorderless(), graphics->GetResizable(), graphics->GetVSync(), graphics->GetTripleBuffer(), graphics->GetMultiSample(), editor);
+            graphics->SetMode(0, 0, graphics->GetFullscreen(), graphics->GetBorderless(), graphics->GetResizable(), highDPI, graphics->GetVSync(), graphics->GetTripleBuffer(), graphics->GetMultiSample());
 
 
             SavePreferences(prefs);
             SavePreferences(prefs);
         }
         }