Browse Source

Add Uint to JSONValue so values don't get munged by scientific notation on double

Josh Engebretson 10 years ago
parent
commit
bf8c119b08

+ 12 - 0
Source/Atomic/Resource/JSONValue.cpp

@@ -127,6 +127,13 @@ void JSONValue::SetInt(const String& name, int value)
     AddMember(name, jsonValue);
 }
 
+void JSONValue::SetUInt(const String& name, unsigned value)
+{
+    Value jsonValue;
+    jsonValue.SetUint(value);
+    AddMember(name, jsonValue);
+}
+
 void JSONValue::SetBool(const String& name, bool value)
 {
     Value jsonValue;
@@ -319,6 +326,11 @@ int JSONValue::GetInt(const String& name) const
     return GetMember(name).GetInt();
 }
 
+unsigned JSONValue::GetUInt(const String& name) const
+{
+    return GetMember(name).GetUint();
+}
+
 bool JSONValue::GetBool(const String& name) const
 {
     return GetMember(name).GetBool();

+ 4 - 0
Source/Atomic/Resource/JSONValue.h

@@ -82,6 +82,8 @@ public:
     JSONValue GetChild(const String& name, JSONValueType valueType = JSON_ANY) const;
     /// Set int.
     void SetInt(const String& name, int value);
+    /// Set unsigned int.
+    void SetUInt(const String& name, unsigned value);
     /// Set bool.
     void SetBool(const String& name, bool value);
     /// Set float.
@@ -133,6 +135,8 @@ public:
     Vector<String> GetValueNames() const;
     /// Return int.
     int GetInt(const String& name) const;
+    /// Return unsigned int.
+    unsigned GetUInt(const String& name) const;
     /// Return bool.
     bool GetBool(const String& name) const;
     /// Return float.

+ 19 - 4
Source/ToolCore/Assets/Asset.cpp

@@ -1,4 +1,5 @@
 
+#include <Atomic/IO/Log.h>
 #include <Atomic/IO/File.h>
 #include <Atomic/IO/FileSystem.h>
 
@@ -33,7 +34,7 @@ bool Asset::CheckCacheFile()
 
     String cacheFile = cachePath + guid_;
 
-    if (!fs->FileExists(cacheFile))
+    if (!fs->FileExists(cacheFile) || fs->GetLastModifiedTime(cacheFile) < fs->GetLastModifiedTime(path_))
         return false;
 
     return true;
@@ -68,11 +69,20 @@ bool Asset::Load()
 
     db->RegisterGUID(guid_);
 
-    timestamp_ = (unsigned) root.GetDouble("timestamp");
+    timestamp_ = root.GetUInt("timestamp");
 
     dirty_ = false;
-    if (!CheckCacheFile() || timestamp_ < fs->GetLastModifiedTime(path_))
+    if (!CheckCacheFile())
+    {
+        LOGINFOF("CheckCacheFile:false - %s", path_.CString());
         dirty_ = true;
+    }
+    else if (timestamp_ < fs->GetLastModifiedTime(path_))
+    {
+        LOGINFOF("Timestamp:false - %u vs modified %u - %s", timestamp_, fs->GetLastModifiedTime(path_), path_.CString());
+        dirty_ = true;
+    }
+
 
     // handle import
 
@@ -88,6 +98,7 @@ bool Asset::Load()
 // save .asset
 bool Asset::Save()
 {
+    FileSystem* fs = GetSubsystem<FileSystem>();
     String assetFilename = GetDotAssetFilename();
 
     json_ = new JSONFile(context_);
@@ -96,7 +107,11 @@ bool Asset::Save()
 
     root.SetInt("version", ASSET_VERSION);
     root.SetString("guid", guid_);
-    root.SetDouble("timestamp", (double) timestamp_);
+
+    // update this where?
+    timestamp_ = fs->GetLastModifiedTime(path_);
+
+    root.SetUInt("timestamp", timestamp_);
 
     // handle import
 

+ 2 - 0
Source/ToolCore/Assets/Asset.h

@@ -14,6 +14,8 @@ namespace ToolCore
 
 class Asset : public Object
 {
+    friend class AssetDatabase;
+
     OBJECT(Asset);
 
 public:

+ 1 - 0
Source/ToolCore/Assets/AssetDatabase.cpp

@@ -171,6 +171,7 @@ void AssetDatabase::ImportDirtyAssets()
     for (unsigned i = 0; i < assets.Size(); i++)
     {
         assets[i]->Import();
+        assets[i]->Save();
     }
 
 }