Browse Source

Improved changed file handling

JoshEngebretson 10 years ago
parent
commit
19e71db219

+ 1 - 1
Script/AtomicEditor/ui/inspector/ModelInspector.ts

@@ -46,7 +46,7 @@ class ModelInspector extends InspectorWidget {
 
         }
 
-        this.importer.import(this.asset.guid);
+        this.asset.import();
         this.asset.save();
 
     }

+ 43 - 101
Script/TypeScript/Atomic.d.ts

@@ -890,7 +890,6 @@ declare module Atomic {
    export var SHADOW_MIN_PIXELS: number;
    export var INSTANCING_BUFFER_DEFAULT_SIZE: number;
    export var MAX_VIEWPORT_TEXTURES: number;
-   export var NUM_SCREEN_BUFFERS: number;
    export var MAX_TEXTURE_QUALITY_LEVELS: number;
 
 
@@ -3125,13 +3124,11 @@ declare module Atomic {
 
    export class Graphics extends AObject {
 
-      windowIcon: Image;
       windowTitle: string;
+      windowIcon: Image;
       srgb: boolean;
       flushGPU: boolean;
-      forceGL2: boolean;
       orientations: string;
-      textureForUpdate: Texture;
       defaultTextureFilterMode: TextureFilterMode;
       textureAnisotropy: number;
       viewport: IntRect;
@@ -3147,8 +3144,8 @@ declare module Atomic {
       height: number;
       multiSample: number;
       fullscreen: boolean;
-      borderless: boolean;
       resizable: boolean;
+      borderless: boolean;
       vSync: boolean;
       tripleBuffer: boolean;
       numPrimitives: number;
@@ -3159,7 +3156,6 @@ declare module Atomic {
       instancingSupport: boolean;
       lightPrepassSupport: boolean;
       deferredSupport: boolean;
-      anisotropySupport: boolean;
       hardwareShadowSupport: boolean;
       readableDepthSupport: boolean;
       sRGBSupport: boolean;
@@ -3168,7 +3164,6 @@ declare module Atomic {
       vertexShader: ShaderVariation;
       pixelShader: ShaderVariation;
       depthStencil: RenderSurface;
-      depthTexture: Texture2D;
       depthConstantBias: number;
       depthSlopeScaledBias: number;
       stencilTest: boolean;
@@ -3183,8 +3178,6 @@ declare module Atomic {
       stencilWriteMask: number;
       useClipPlane: boolean;
       renderTargetDimensions: IntVector2;
-      vbo: number;
-      ubo: number;
       alphaFormat: number;
       luminanceFormat: number;
       luminanceAlphaFormat: number;
@@ -3203,15 +3196,14 @@ declare module Atomic {
       readableDepthFormat: number;
       pixelUVOffset: Vector2;
       maxBones: number;
-      gL3Support: boolean;
 
       // Construct.
       constructor();
 
-      // Set window icon.
-      setWindowIcon(windowIcon: Image): void;
       // Set window title.
       setWindowTitle(windowTitle: string): void;
+      // Set window icon.
+      setWindowIcon(windowIcon: Image): void;
       // Set window size.
       setWindowSize(width: number, height: number): void;
       // Center window.
@@ -3220,10 +3212,8 @@ declare module Atomic {
       raiseWindow(): void;
       // Set whether the main window uses sRGB conversion on write.
       setSRGB(enable: boolean): void;
-      // Set whether to flush the GPU command buffer to prevent multiple frames being queued and uneven frame timesteps. Not yet implemented on OpenGL.
+      // Set whether to flush the GPU command buffer to prevent multiple frames being queued and uneven frame timesteps. Default off, may decrease performance if enabled.
       setFlushGPU(enable: boolean): void;
-      // Set forced use of OpenGL 2 even if OpenGL 3 is available. Must be called before setting the screen mode for the first time. Default false.
-      setForceGL2(enable: boolean): void;
       // Set allowed screen orientations as a space-separated list of "LandscapeLeft", "LandscapeRight", "Portrait" and "PortraitUpsideDown". Affects currently only iOS platform.
       setOrientations(orientations: string): void;
       // Toggle between full screen and windowed mode. Return true if successful.
@@ -3240,7 +3230,7 @@ declare module Atomic {
       clear(flags: number, color?: Color, depth?: number, stencil?: number): void;
       // Resolve multisampled backbuffer to a texture rendertarget. The texture's size should match the viewport size.
       resolveToTexture(destination: Texture2D, viewport: IntRect): boolean;
-      // Draw indexed, instanced geometry.
+      // Draw indexed, instanced geometry. An instancing vertex buffer must be set.
       drawInstanced(type: PrimitiveType, indexStart: number, indexCount: number, minVertex: number, vertexCount: number, instanceCount: number): void;
       // Set shaders.
       setShaders(vs: ShaderVariation, ps: ShaderVariation): void;
@@ -3256,14 +3246,10 @@ declare module Atomic {
       clearTransformSources(): void;
       // Set texture.
       setTexture(index: number, texture: Texture): void;
-      // Bind texture unit 0 for update. Called by Texture.
-      setTextureForUpdate(texture: Texture): void;
       // Set default texture filtering mode.
       setDefaultTextureFilterMode(mode: TextureFilterMode): void;
       // Set texture anisotropy.
       setTextureAnisotropy(level: number): void;
-      // Dirty texture parameters of all textures (when global settings change.)
-      setTextureParametersDirty(): void;
       // Reset all rendertargets, depth-stencil surface and viewport.
       resetRenderTargets(): void;
       // Reset specific rendertarget.
@@ -3308,43 +3294,39 @@ declare module Atomic {
       getMultiSample(): number;
       // Return whether window is fullscreen.
       getFullscreen(): boolean;
-      // Return whether window is borderless.
-      getBorderless(): boolean;
       // Return whether window is resizable.
       getResizable(): boolean;
+      // Return whether window is borderless.
+      getBorderless(): boolean;
       // Return whether vertical sync is on.
       getVSync(): boolean;
       // Return whether triple buffering is enabled.
       getTripleBuffer(): boolean;
       // Return whether the main window is using sRGB conversion on write.
       getSRGB(): boolean;
-      // Return whether the GPU command buffer is flushed each frame. Not yet implemented on OpenGL.
+      // Return whether the GPU command buffer is flushed each frame.
       getFlushGPU(): boolean;
-      // Return whether OpenGL 2 use is forced.
-      getForceGL2(): boolean;
       // Return allowed screen orientations.
       getOrientations(): string;
-      // Return whether device is lost, and can not yet render.
+      // Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching.
       isDeviceLost(): boolean;
       // Return number of primitives drawn this frame.
       getNumPrimitives(): number;
       // Return number of batches drawn this frame.
       getNumBatches(): number;
-      // Return dummy color texture format for shadow maps. 0 if not needed, may be nonzero on OS X to work around an Intel driver issue.
+      // Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported.
       getDummyColorFormat(): number;
       // Return shadow map depth texture format, or 0 if not supported.
       getShadowMapFormat(): number;
       // Return 24-bit shadow map depth texture format, or 0 if not supported.
       getHiresShadowMapFormat(): number;
-      // Return whether hardware instancing is supported.
+      // Return whether hardware instancing is supported..
       getInstancingSupport(): boolean;
       // Return whether light pre-pass rendering is supported.
       getLightPrepassSupport(): boolean;
       // Return whether deferred rendering is supported.
       getDeferredSupport(): boolean;
-      // Return whether anisotropic texture filtering is supported.
-      getAnisotropySupport(): boolean;
-      // Return whether shadow map depth compare is done in hardware. Always true on OpenGL.
+      // Return whether shadow map depth compare is done in hardware.
       getHardwareShadowSupport(): boolean;
       // Return whether a readable hardware depth format is available.
       getReadableDepthSupport(): boolean;
@@ -3356,24 +3338,22 @@ declare module Atomic {
       getDesktopResolution(): IntVector2;
       // Return a shader variation by name and defines.
       getShader(type: ShaderType, name: string, defines?: string): ShaderVariation;
-      // Return vertex shader.
+      // Return current vertex shader.
       getVertexShader(): ShaderVariation;
-      // Return pixel shader.
+      // Return current pixel shader.
       getPixelShader(): ShaderVariation;
       // Return texture unit index by name.
       getTextureUnit(name: string): TextureUnit;
       // Return texture unit name by index.
       getTextureUnitName(unit: TextureUnit): string;
-      // Return texture by texture unit index.
+      // Return current texture by texture unit index.
       getTexture(index: number): Texture;
       // Return default texture filtering mode.
       getDefaultTextureFilterMode(): TextureFilterMode;
-      // Return rendertarget by index.
+      // Return current rendertarget by index.
       getRenderTarget(index: number): RenderSurface;
-      // Return depth-stencil surface.
+      // Return current depth-stencil surface.
       getDepthStencil(): RenderSurface;
-      // Return readable depth-stencil texture. Not created automatically on OpenGL.
-      getDepthTexture(): Texture2D;
       // Return the viewport coordinates.
       getViewport(): IntRect;
       // Return texture anisotropy.
@@ -3422,26 +3402,14 @@ declare module Atomic {
       windowResized(): void;
       // Window was moved through user interaction. Called by Input subsystem.
       windowMoved(): void;
-      // Clean up too large scratch buffers.
-      cleanupScratchBuffers(): void;
-      // Clean up a render surface from all FBOs.
-      cleanupRenderSurface(surface: RenderSurface): void;
-      // Clean up shader programs when a shader variation is released or destroyed.
-      cleanupShaderPrograms(variation: ShaderVariation): void;
-      // Release/clear GPU objects and optionally close the window.
-      release(clearGPUObjects: boolean, closeWindow: boolean): void;
-      // Restore GPU objects and reinitialize state. Requires an open window.
-      restore(): void;
       // Maximize the Window.
       maximize(): void;
       // Minimize the Window.
       minimize(): void;
-      // Mark the FBO needing an update.
-      markFBODirty(): void;
-      // Bind a VBO, avoiding redundant operation.
-      setVBO(object: number): void;
-      // Bind a UBO, avoiding redundant operation.
-      setUBO(object: number): void;
+      // Clean up too large scratch buffers.
+      cleanupScratchBuffers(): void;
+      // Clean up shader programs when a shader variation is released or destroyed.
+      cleanupShaderPrograms(variation: ShaderVariation): void;
       // Return the API-specific alpha texture format.
       getAlphaFormat(): number;
       // Return the API-specific luminance texture format.
@@ -3478,8 +3446,6 @@ declare module Atomic {
       getPixelUVOffset(): Vector2;
       // Return maximum number of supported bones for skinning.
       getMaxBones(): number;
-      // Return whether is using an OpenGL 3 context.
-      getGL3Support(): boolean;
 
    }
 
@@ -3490,11 +3456,9 @@ declare module Atomic {
       linkedRenderTarget: RenderSurface;
       linkedDepthStencil: RenderSurface;
       parentTexture: Texture;
-      renderBuffer: number;
       width: number;
       height: number;
       usage: TextureUsage;
-      target: number;
 
       // Construct with parent texture.
       constructor(parentTexture: Texture);
@@ -3511,16 +3475,10 @@ declare module Atomic {
       setLinkedDepthStencil(depthStencil: RenderSurface): void;
       // Queue manual update of the viewport(s).
       queueUpdate(): void;
-      // Create a renderbuffer. Return true if successful.
-      createRenderBuffer(width: number, height: number, format: number): boolean;
-      // Handle device loss.
-      onDeviceLost(): void;
-      // Release renderbuffer if any.
+      // Release surface.
       release(): void;
       // Return parent texture.
       getParentTexture(): Texture;
-      // Return renderbuffer if created.
-      getRenderBuffer(): number;
       // Return width.
       getWidth(): number;
       // Return height.
@@ -3533,14 +3491,10 @@ declare module Atomic {
       getViewport(index: number): Viewport;
       // Return viewport update mode.
       getUpdateMode(): RenderSurfaceUpdateMode;
-      // Return linked color buffer.
+      // Return linked color rendertarget.
       getLinkedRenderTarget(): RenderSurface;
-      // Return linked depth buffer.
+      // Return linked depth-stencil surface.
       getLinkedDepthStencil(): RenderSurface;
-      // Set surface's OpenGL target.
-      setTarget(target: number): void;
-      // Return surface's OpenGL target.
-      getTarget(): number;
       // Clear update flag. Called by Renderer.
       wasUpdated(): void;
 
@@ -3558,8 +3512,6 @@ declare module Atomic {
       // Construct.
       constructor(owner: Shader, type: ShaderType);
 
-      // Mark the GPU resource destroyed on context destruction.
-      onDeviceLost(): void;
       // Release the shader.
       release(): void;
       // Compile the shader. Return true if successful.
@@ -3572,7 +3524,7 @@ declare module Atomic {
       getOwner(): Shader;
       // Return shader type.
       getShaderType(): ShaderType;
-      // Return name.
+      // Return shader name.
       getName(): string;
       // Return defines.
       getDefines(): string;
@@ -3580,6 +3532,10 @@ declare module Atomic {
       getFullName(): string;
       // Return compile error/warning string.
       getCompilerOutput(): string;
+      // Return whether uses a parameter.
+      hasParameter(param: string): boolean;
+      // Return whether uses a texture unit (only for pixel shaders.)
+      hasTextureUnit(unit: TextureUnit): boolean;
 
    }
 
@@ -3591,13 +3547,11 @@ declare module Atomic {
       borderColor: Color;
       srgb: boolean;
       backupTexture: Texture;
-      target: number;
       format: number;
       levels: number;
       width: number;
       height: number;
       depth: number;
-      parametersDirty: boolean;
       usage: TextureUsage;
       components: number;
       parameters: XMLFile;
@@ -3611,7 +3565,7 @@ declare module Atomic {
       setFilterMode(filter: TextureFilterMode): void;
       // Set addressing mode by texture coordinate.
       setAddressMode(coord: TextureCoordinate, address: TextureAddressMode): void;
-      // Set shadow compare mode.
+      // Set shadow compare mode. No-op on D3D9.
       setShadowCompare(enable: boolean): void;
       // Set border color for border addressing mode.
       setBorderColor(color: Color): void;
@@ -3621,12 +3575,6 @@ declare module Atomic {
       setBackupTexture(texture: Texture): void;
       // Set mip levels to skip on a quality setting when loading. Ensures higher quality levels do not skip more.
       setMipsToSkip(quality: number, mips: number): void;
-      // Dirty the parameters.
-      setParametersDirty(): void;
-      // Update changed parameters to OpenGL. Called by Graphics when binding the texture.
-      updateParameters(): void;
-      // Return texture's OpenGL target.
-      getTarget(): number;
       // Return texture format.
       getFormat(): number;
       // Return whether the texture format is compressed.
@@ -3639,13 +3587,11 @@ declare module Atomic {
       getHeight(): number;
       // Return height.
       getDepth(): number;
-      // Return whether parameters are dirty.
-      getParametersDirty(): boolean;
       // Return filtering mode.
       getFilterMode(): TextureFilterMode;
       // Return addressing mode by texture coordinate.
       getAddressMode(coord: TextureCoordinate): TextureAddressMode;
-      // Return whether shadow compare is enabled.
+      // Return whether shadow compare is enabled. Always false on D3D9.
       getShadowCompare(): boolean;
       // Return border color.
       getBorderColor(): Color;
@@ -3667,14 +3613,8 @@ declare module Atomic {
       getRowDataSize(width: number): number;
       // Return number of image components required to receive pixel data from GetData(), or 0 for compressed images.
       getComponents(): number;
-      // Return the non-internal texture format corresponding to an OpenGL internal format.
-      getExternalFormat(format: number): number;
-      // Return the data type corresponding to an OpenGL internal format.
-      getDataType(format: number): number;
       // Set additional parameters from an XML file.
       setParameters(xml: XMLFile): void;
-      // Return the corresponding SRGB texture format if supported. If not supported, return format unchanged.
-      getSRGBFormat(format: number): number;
 
    }
 
@@ -3687,11 +3627,11 @@ declare module Atomic {
 
       // Finish resource loading. Always called from the main thread. Return true if successful.
       endLoad(): boolean;
-      // Mark the GPU resource destroyed on context destruction.
+      // Release default pool resources.
       onDeviceLost(): void;
-      // Recreate the GPU resource and restore data if applicable.
+      // Recreate default pool resources.
       onDeviceReset(): void;
-      // Release the texture.
+      // Release texture.
       release(): void;
       // Set size, format and usage. Zero size will follow application window size. Return true if successful.
       setSize(width: number, height: number, format: number, usage?: TextureUsage): boolean;
@@ -3709,11 +3649,11 @@ declare module Atomic {
 
       // Finish resource loading. Always called from the main thread. Return true if successful.
       endLoad(): boolean;
-      // Mark the GPU resource destroyed on context destruction.
+      // Release default pool resources.
       onDeviceLost(): void;
-      // Recreate the GPU resource and restore data if applicable.
+      // Recreate default pool resources.
       onDeviceReset(): void;
-      // Release the texture.
+      // Release texture.
       release(): void;
       // Set size, format and usage. Zero size will follow application window size. Return true if successful.
       setSize(width: number, height: number, depth: number, format: number, usage?: TextureUsage): boolean;
@@ -3729,11 +3669,11 @@ declare module Atomic {
 
       // Finish resource loading. Always called from the main thread. Return true if successful.
       endLoad(): boolean;
-      // Mark the GPU resource destroyed on context destruction.
+      // Release default pool resources.
       onDeviceLost(): void;
-      // Recreate the GPU resource and restore data if applicable.
+      // ReCreate default pool resources.
       onDeviceReset(): void;
-      // Release the texture.
+      // Release texture.
       release(): void;
       // Set size, format and usage. Return true if successful.
       setSize(size: number, format: number, usage?: TextureUsage): boolean;
@@ -7924,6 +7864,8 @@ declare module Atomic {
       createDirs(root: string, subdirectory: string): boolean;
       // Copy a directory, directoryOut must not exist
       copyDir(directoryIn: string, directoryOut: string): boolean;
+      // Check if a file or directory exists at the specified path
+      exists(pathName: string): boolean;
       createDirsRecursive(directoryIn: string, directoryOut: string): boolean;
       scanDir(pathName:string, filter:string, flags:number, recursive:boolean);
 

+ 5 - 8
Script/TypeScript/ToolCore.d.ts

@@ -249,6 +249,7 @@ declare module ToolCore {
       importer: AssetImporter;
       parent: Asset;
       dirty: boolean;
+      fileTimestamp: number;
       dotAssetFilename: string;
 
       // Construct.
@@ -270,6 +271,10 @@ declare module ToolCore {
       getParent(): Asset;
       setDirty(dirty: boolean): void;
       isDirty(): boolean;
+      // Get the last timestamp as seen by the AssetDatabase
+      getFileTimestamp(): number;
+      // Sets the time stamp to the asset files current time
+      updateFileTimestamp(): void;
       getDotAssetFilename(): string;
       isFolder(): boolean;
       load(): boolean;
@@ -306,8 +311,6 @@ declare module ToolCore {
       constructor(asset: Asset);
 
       setDefaults(): void;
-      // Imports to cached data
-      import(guid: string): boolean;
       preload(): boolean;
       getAsset(): Asset;
       requiresCacheFile(): boolean;
@@ -320,7 +323,6 @@ declare module ToolCore {
       constructor(asset: Asset);
 
       setDefaults(): void;
-      import(guid: string): boolean;
 
    }
 
@@ -331,7 +333,6 @@ declare module ToolCore {
 
       setDefaults(): void;
       isComponentFile(): boolean;
-      import(guid: string): boolean;
 
    }
 
@@ -341,7 +342,6 @@ declare module ToolCore {
       constructor(asset: Asset);
 
       setDefaults(): void;
-      import(guid: string): boolean;
       saveMaterial(): void;
 
    }
@@ -380,7 +380,6 @@ declare module ToolCore {
       getAnimationCount(): number;
       setAnimationCount(count: number): void;
       getAnimationInfo(index: number): AnimationImportInfo;
-      import(guid: string): boolean;
 
    }
 
@@ -390,7 +389,6 @@ declare module ToolCore {
       constructor(asset: Asset);
 
       setDefaults(): void;
-      import(guid: string): boolean;
       preload(): boolean;
 
    }
@@ -401,7 +399,6 @@ declare module ToolCore {
       constructor(asset: Asset);
 
       setDefaults(): void;
-      import(guid: string): boolean;
 
    }
 

+ 14 - 2
Source/ToolCore/Assets/Asset.cpp

@@ -25,7 +25,8 @@ namespace ToolCore
 Asset::Asset(Context* context) :
     Object(context),
     dirty_(false),
-    isFolder_(false)
+    isFolder_(false),
+    fileTimestamp_(0xffffffff)
 {
 
 }
@@ -35,6 +36,16 @@ Asset::~Asset()
 
 }
 
+void Asset::UpdateFileTimestamp()
+{
+    FileSystem* fs = GetSubsystem<FileSystem>();
+
+    if (fs->FileExists(path_))
+    {
+        fileTimestamp_ = fs->GetLastModifiedTime(path_);
+    }
+}
+
 Asset* Asset::GetParent()
 {
     AssetDatabase* db = GetSubsystem<AssetDatabase>();
@@ -90,10 +101,11 @@ bool Asset::CheckCacheFile()
 
 bool Asset::Import()
 {
+
     if (importer_.Null())
         return true;
 
-    return importer_->Import(guid_);
+    return importer_->Import();
 }
 
 bool Asset::Preload()

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

@@ -48,6 +48,12 @@ public:
     void SetDirty(bool dirty) { dirty_ = dirty; }
     bool IsDirty() const { return dirty_; }
 
+    /// Get the last timestamp as seen by the AssetDatabase
+    unsigned GetFileTimestamp() { return fileTimestamp_; }
+
+    /// Sets the time stamp to the asset files current time
+    void UpdateFileTimestamp();
+
     // get the .asset filename
     String GetDotAssetFilename();
 
@@ -74,6 +80,12 @@ private:
     bool dirty_;
     bool isFolder_;
 
+    // the current timestamp of the asset as seen by the asset database
+    // used to catch when the asset needs to be marked dirty when notified
+    // that the file has changed (the resource system will send a changed file
+    // event when the resource is first added)
+    unsigned fileTimestamp_;
+
     SharedPtr<JSONFile> json_;
     SharedPtr<AssetImporter> importer_;
 };

+ 29 - 7
Source/ToolCore/Assets/AssetDatabase.cpp

@@ -22,8 +22,7 @@ namespace ToolCore
 AssetDatabase::AssetDatabase(Context* context) : Object(context)
 {
     SubscribeToEvent(E_PROJECTLOADED, HANDLER(AssetDatabase, HandleProjectLoaded));
-    SubscribeToEvent(E_PROJECTUNLOADED, HANDLER(AssetDatabase, HandleProjectUnloaded));
-    SubscribeToEvent(E_FILECHANGED, HANDLER(AssetDatabase, HandleFileChanged));
+    SubscribeToEvent(E_PROJECTUNLOADED, HANDLER(AssetDatabase, HandleProjectUnloaded));    
 }
 
 AssetDatabase::~AssetDatabase()
@@ -141,6 +140,13 @@ Asset* AssetDatabase::GetAssetByPath(const String& path)
 
 void AssetDatabase::PruneOrphanedDotAssetFiles()
 {
+
+    if (project_.Null())
+    {
+        LOGDEBUG("AssetDatabase::PruneOrphanedDotAssetFiles - called without project loaded");
+        return;
+    }
+
     FileSystem* fs = GetSubsystem<FileSystem>();
 
     const String& resourcePath = project_->GetResourcePath();
@@ -189,6 +195,9 @@ void AssetDatabase::AddAsset(SharedPtr<Asset>& asset)
 
     assets_.Push(asset);
 
+    // set to the current timestamp
+    asset->UpdateFileTimestamp();
+
     VariantMap eventData;
     eventData[ResourceAdded::P_GUID] = asset->GetGUID();
     SendEvent(E_RESOURCEADDED, eventData);
@@ -241,6 +250,7 @@ bool AssetDatabase::ImportDirtyAssets()
         assets[i]->Import();
         assets[i]->Save();
         assets[i]->dirty_ = false;
+        assets[i]->UpdateFileTimestamp();
     }
 
     return assets.Size() != 0;
@@ -409,6 +419,8 @@ void AssetDatabase::HandleProjectLoaded(StringHash eventType, VariantMap& eventD
     cache->AddResourceDir(GetCachePath());
 
     Scan();
+
+    SubscribeToEvent(E_FILECHANGED, HANDLER(AssetDatabase, HandleFileChanged));
 }
 
 void AssetDatabase::HandleProjectUnloaded(StringHash eventType, VariantMap& eventData)
@@ -418,6 +430,8 @@ void AssetDatabase::HandleProjectUnloaded(StringHash eventType, VariantMap& even
     assets_.Clear();
     usedGUID_.Clear();
     project_ = 0;
+
+    UnsubscribeFromEvent(E_FILECHANGED);
 }
 
 void AssetDatabase::HandleFileChanged(StringHash eventType, VariantMap& eventData)
@@ -431,6 +445,14 @@ void AssetDatabase::HandleFileChanged(StringHash eventType, VariantMap& eventDat
 
     SplitPath(fullPath, pathName, fileName, ext);
 
+    // ignore changes in the Cache resource dir
+    if (fullPath == GetCachePath() || pathName.StartsWith(GetCachePath()))
+        return;
+
+    // don't care about directories and asset file changes
+    if (fs->DirExists(fullPath) || ext == ".asset")
+        return;
+
     Asset* asset = GetAssetByPath(fullPath);
 
     if (!asset && fs->FileExists(fullPath))
@@ -447,13 +469,13 @@ void AssetDatabase::HandleFileChanged(StringHash eventType, VariantMap& eventDat
         }
         else
         {
-            asset->SetDirty(true);
-            Scan();
+            if (asset->GetFileTimestamp() != fs->GetLastModifiedTime(asset->GetPath()))
+            {
+                asset->SetDirty(true);
+                Scan();
+            }
         }
-
     }
-
-
 }
 
 

+ 4 - 2
Source/ToolCore/Assets/AssetImporter.h

@@ -14,6 +14,8 @@ class Asset;
 /// deals with .asset files
 class AssetImporter : public Object
 {
+    friend class Asset;
+
     OBJECT(AssetImporter);
 
 public:
@@ -28,8 +30,6 @@ public:
 
     virtual void SetDefaults();
 
-    /// Imports to cached data
-    virtual bool Import(const String& guid) = 0;
     virtual bool Preload() { return true; }
 
     Asset* GetAsset() { return asset_; }
@@ -38,6 +38,8 @@ public:
 
 protected:
 
+    virtual bool Import() { return true; }
+
     WeakPtr<Asset> asset_;
     JSONValue jsonRoot_;   
     bool requiresCacheFile_;

+ 1 - 7
Source/ToolCore/Assets/AudioImporter.cpp

@@ -24,14 +24,8 @@ void AudioImporter::SetDefaults()
     AssetImporter::SetDefaults();
 }
 
-bool AudioImporter::Import(const String& guid)
+bool AudioImporter::Import()
 {
-    AssetDatabase* db = GetSubsystem<AssetDatabase>();
-    Asset* asset = db->GetAssetByGUID(guid);
-
-    if (!asset)
-        return false;
-
     return true;
 }
 

+ 2 - 2
Source/ToolCore/Assets/AudioImporter.h

@@ -17,10 +17,10 @@ public:
 
     virtual void SetDefaults();
 
-    bool Import(const String& guid);
-
 protected:
 
+    bool Import();
+
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();
 

+ 1 - 7
Source/ToolCore/Assets/FolderImporter.cpp

@@ -21,14 +21,8 @@ void FolderImporter::SetDefaults()
     AssetImporter::SetDefaults();
 }
 
-bool FolderImporter::Import(const String& guid)
+bool FolderImporter::Import()
 {
-    AssetDatabase* db = GetSubsystem<AssetDatabase>();
-    Asset* asset = db->GetAssetByGUID(guid);
-
-    if (!asset)
-        return false;
-
     return true;
 }
 

+ 2 - 2
Source/ToolCore/Assets/FolderImporter.h

@@ -17,10 +17,10 @@ public:
 
     virtual void SetDefaults();
 
-    bool Import(const String& guid);
-
 protected:
 
+    bool Import();
+
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();
 

+ 1 - 1
Source/ToolCore/Assets/JavascriptImporter.cpp

@@ -27,7 +27,7 @@ void JavascriptImporter::SetDefaults()
     AssetImporter::SetDefaults();
 }
 
-bool JavascriptImporter::Import(const String& guid)
+bool JavascriptImporter::Import()
 {
     isComponentFile_ = false;
 

+ 2 - 2
Source/ToolCore/Assets/JavascriptImporter.h

@@ -19,10 +19,10 @@ public:
 
     bool IsComponentFile() { return isComponentFile_; }
 
-    bool Import(const String& guid);
-
 protected:
 
+    bool Import();
+
     bool isComponentFile_;
 
     virtual bool LoadSettingsInternal();

+ 2 - 2
Source/ToolCore/Assets/MaterialImporter.cpp

@@ -12,7 +12,7 @@ namespace ToolCore
 
 MaterialImporter::MaterialImporter(Context* context, Asset* asset) : AssetImporter(context, asset)
 {
-
+    requiresCacheFile_ = false;
 }
 
 MaterialImporter::~MaterialImporter()
@@ -25,7 +25,7 @@ void MaterialImporter::SetDefaults()
     AssetImporter::SetDefaults();
 }
 
-bool MaterialImporter::Import(const String& guid)
+bool MaterialImporter::Import()
 {
     return true;
 }

+ 2 - 2
Source/ToolCore/Assets/MaterialImporter.h

@@ -17,12 +17,12 @@ public:
 
     virtual void SetDefaults();
 
-    bool Import(const String& guid);
-
     void SaveMaterial();
 
 protected:
 
+    bool Import();
+
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();
 

+ 2 - 8
Source/ToolCore/Assets/ModelImporter.cpp

@@ -180,15 +180,9 @@ bool ModelImporter::ImportAnimations()
     return true;
 }
 
-bool ModelImporter::Import(const String& guid)
+bool ModelImporter::Import()
 {
-    AssetDatabase* db = GetSubsystem<AssetDatabase>();
-    Asset* asset = db->GetAssetByGUID(guid);
-
-    if (!asset)
-        return false;
-
-    String modelAssetFilename = asset->GetPath();
+    String modelAssetFilename = asset_->GetPath();
 
     importNode_ = new Node(context_);
 

+ 2 - 2
Source/ToolCore/Assets/ModelImporter.h

@@ -65,10 +65,10 @@ public:
 
     AnimationImportInfo* GetAnimationInfo(unsigned index) { return animationInfo_[index]; }
 
-    bool Import(const String& guid);
-
 protected:
 
+    bool Import();
+
     bool ImportModel();
     bool ImportAnimations();
     bool ImportAnimation(const String &filename, const String& name, float startTime=-1.0f, float endTime=-1.0f);

+ 1 - 1
Source/ToolCore/Assets/PrefabImporter.cpp

@@ -74,7 +74,7 @@ void PrefabImporter::HandlePrefabSave(StringHash eventType, VariantMap& eventDat
 
 }
 
-bool PrefabImporter::Import(const String& guid)
+bool PrefabImporter::Import()
 {
     FileSystem* fs = GetSubsystem<FileSystem>();
 

+ 2 - 1
Source/ToolCore/Assets/PrefabImporter.h

@@ -22,11 +22,12 @@ public:
 
     virtual void SetDefaults();
 
-    bool Import(const String& guid);
     virtual bool Preload();
 
 protected:
 
+    bool Import();
+
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();
 

+ 1 - 7
Source/ToolCore/Assets/SceneImporter.cpp

@@ -21,14 +21,8 @@ void SceneImporter::SetDefaults()
     AssetImporter::SetDefaults();
 }
 
-bool SceneImporter::Import(const String& guid)
+bool SceneImporter::Import()
 {
-    AssetDatabase* db = GetSubsystem<AssetDatabase>();
-    Asset* asset = db->GetAssetByGUID(guid);
-
-    if (!asset)
-        return false;
-
     return true;
 }
 

+ 2 - 2
Source/ToolCore/Assets/SceneImporter.h

@@ -17,10 +17,10 @@ public:
 
     virtual void SetDefaults();
 
-    bool Import(const String& guid);
-
 protected:
 
+    bool Import();
+
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();
 

+ 4 - 8
Source/ToolCore/Assets/TextureImporter.cpp

@@ -24,16 +24,12 @@ void TextureImporter::SetDefaults()
     AssetImporter::SetDefaults();
 }
 
-bool TextureImporter::Import(const String& guid)
+bool TextureImporter::Import()
 {
     AssetDatabase* db = GetSubsystem<AssetDatabase>();
-    Asset* asset = db->GetAssetByGUID(guid);
-
-    if (!asset)
-        return false;
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
-    SharedPtr<Image> image = cache->GetTempResource<Image>(asset->GetPath());
+    SharedPtr<Image> image = cache->GetTempResource<Image>(asset_->GetPath());
 
     if (image.Null())
         return false;
@@ -45,10 +41,10 @@ bool TextureImporter::Import(const String& guid)
 
     // not sure entirely what we want to do here, though if the cache file doesn't exist
     // will reimport
-    image->SavePNG(cachePath + asset->GetGUID());
+    image->SavePNG(cachePath + asset_->GetGUID());
 
     // save thumbnail
-    image->SavePNG(cachePath + asset->GetGUID() + "_thumbnail.png");
+    image->SavePNG(cachePath + asset_->GetGUID() + "_thumbnail.png");
 
     return true;
 }

+ 2 - 2
Source/ToolCore/Assets/TextureImporter.h

@@ -17,10 +17,10 @@ public:
 
     virtual void SetDefaults();
 
-    bool Import(const String& guid);
-
 protected:
 
+    bool Import();
+
     virtual bool LoadSettingsInternal();
     virtual bool SaveSettingsInternal();