Kaynağa Gözat

Minor cleanup - remove redundant null check for subsystems pointer.

Some of the subsystems are registered when the Engine is instantiated and I believe their references should remain valid until the engine stops.
Yao Wei Tjong 姚伟忠 12 yıl önce
ebeveyn
işleme
2e8744dc01

+ 2 - 2
Bin/Data/Scripts/Editor/EditorInspectorWindow.as

@@ -26,9 +26,9 @@ uint elementContainerIndex = M_MAX_UNSIGNED;
 
 void InitXMLResources()
 {
-    String[] resources = { "Attribute", "Variable", "Style" };
+    String[] resources = { "UI/EditorInspector_Attribute.xml", "UI/EditorInspector_Variable.xml", "UI/EditorInspector_Style.xml" };
     for (uint i = 0; i < resources.length; ++i)
-        xmlResources.Push(cache.GetResource("XMLFile", "UI/EditorInspector_" + resources[i] + ".xml"));
+        xmlResources.Push(cache.GetResource("XMLFile", resources[i]));
 }
 
 /// Delete all child containers in the inspector list.

+ 0 - 3
Source/Engine/Graphics/Renderer.cpp

@@ -571,9 +571,6 @@ ShaderVariation* Renderer::GetShader(ShaderType type, const char* name, const ch
     if (lastShaderName_ != name || !lastShader_)
     {
         ResourceCache* cache = GetSubsystem<ResourceCache>();
-        if (!cache)
-            return 0;
-        
         String fullShaderName = shaderPath_ + name + shaderExtension_;
         // Try to reduce repeated error log prints because of missing shaders
         if (lastShaderName_ == name && !cache->Exists(fullShaderName))

+ 5 - 11
Source/Engine/Graphics/Shader.cpp

@@ -73,8 +73,7 @@ Shader::Shader(Context* context) :
 Shader::~Shader()
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
-    if (cache)
-        cache->ResetDependencies(this);
+    cache->ResetDependencies(this);
 }
 
 void Shader::RegisterObject(Context* context)
@@ -188,21 +187,16 @@ ShaderVariation* Shader::GetVariation(ShaderType type, const char* defines)
 bool Shader::ProcessSource(String& code, Deserializer& source)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
-    if (!cache)
-        return false;
     
     // If the source if a non-packaged file, store the timestamp
     File* file = dynamic_cast<File*>(&source);
     if (file && !file->IsPackaged())
     {
         FileSystem* fileSystem = GetSubsystem<FileSystem>();
-        if (fileSystem)
-        {
-            String fullName = cache->GetResourceFileName(file->GetName());
-            unsigned fileTimeStamp = fileSystem->GetLastModifiedTime(fullName);
-            if (fileTimeStamp > timeStamp_)
-                timeStamp_ = fileTimeStamp;
-        }
+        String fullName = cache->GetResourceFileName(file->GetName());
+        unsigned fileTimeStamp = fileSystem->GetLastModifiedTime(fullName);
+        if (fileTimeStamp > timeStamp_)
+            timeStamp_ = fileTimeStamp;
     }
     
     // Store resource dependencies for includes so that we know to reload if any of them changes

+ 2 - 15
Source/Engine/LuaScript/LuaScript.cpp

@@ -123,14 +123,8 @@ bool LuaScript::ExecuteFile(const String& fileName)
     PROFILE(ExecuteFile);
 
     ResourceCache* cache = GetSubsystem<ResourceCache>();
-    if (!cache)
-        return false;
-
     LuaFile* luaFile = cache->GetResource<LuaFile>(fileName);
-    if (!luaFile)
-        return false;
-
-    return luaFile->LoadAndExecute(luaState_);
+    return luaFile && luaFile->LoadAndExecute(luaState_);
 }
 
 bool LuaScript::ExecuteString(const String& string)
@@ -153,12 +147,7 @@ bool LuaScript::ExecuteString(const String& string)
 bool LuaScript::ExecuteFunction(const String& functionName)
 {
     WeakPtr<LuaFunction> function = GetFunction(functionName);
-    if (function && function->BeginCall())
-    {
-        return function->EndCall();
-    }
-
-    return false;
+    return function && function->BeginCall() && function->EndCall();
 }
 
 void LuaScript::ScriptSendEvent(const String& eventName, VariantMap& eventData)
@@ -266,8 +255,6 @@ int LuaScript::AtPanic(lua_State* L)
 int LuaScript::Loader(lua_State* L)
 {
     ResourceCache* cache = ::GetContext(L)->GetSubsystem<ResourceCache>();
-    if (!cache)
-        return 0;
 
     // Get module name
     const char* name = luaL_checkstring(L, 1);

+ 21 - 33
Source/Engine/Resource/ResourceCache.cpp

@@ -476,19 +476,16 @@ bool ResourceCache::Exists(const String& nameIn) const
     }
     
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (fileSystem)
+    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
     {
-        for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
-        {
-            if (fileSystem->FileExists(resourceDirs_[i] + name))
-                return true;
-        }
-        
-        // Fallback using absolute path
-        if (fileSystem->FileExists(name))
+        if (fileSystem->FileExists(resourceDirs_[i] + name))
             return true;
     }
     
+    // Fallback using absolute path
+    if (fileSystem->FileExists(name))
+        return true;
+
     return false;
 }
 
@@ -521,13 +518,10 @@ unsigned ResourceCache::GetTotalMemoryUse() const
 String ResourceCache::GetResourceFileName(const String& name) const
 {
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (fileSystem)
+    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
     {
-        for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
-        {
-            if (fileSystem->FileExists(resourceDirs_[i] + name))
-                return resourceDirs_[i] + name;
-        }
+        if (fileSystem->FileExists(resourceDirs_[i] + name))
+            return resourceDirs_[i] + name;
     }
     
     return String();
@@ -541,9 +535,6 @@ String ResourceCache::GetPreferredResourceDir(const String& path) const
     bool parentHasKnownDirs = false;
     
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    // If no filesystem, can not check directory existence, so just return the original path
-    if (!fileSystem)
-        return fixedPath;
     
     for (unsigned i = 0; checkDirs[i] != 0; ++i)
     {
@@ -581,7 +572,7 @@ String ResourceCache::SanitateResourceName(const String& nameIn) const
 
     // If the path refers to one of the resource directories, normalize the resource name
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (fileSystem && resourceDirs_.Size())
+    if (resourceDirs_.Size())
     {
         String namePath = GetPath(name);
         String exePath = fileSystem->GetProgramDir();
@@ -789,25 +780,22 @@ File* ResourceCache::SearchResourceDirs(const String& nameIn)
 {
     // Then the filesystem
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (fileSystem)
+    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
     {
-        for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
+        if (fileSystem->FileExists(resourceDirs_[i] + nameIn))
         {
-            if (fileSystem->FileExists(resourceDirs_[i] + nameIn))
-            {
-                // Construct the file first with full path, then rename it to not contain the resource path,
-                // so that the file's name can be used in further GetFile() calls (for example over the network)
-                File* file(new File(context_, resourceDirs_[i] + nameIn));
-                file->SetName(nameIn);
-                return file;
-            }
+            // Construct the file first with full path, then rename it to not contain the resource path,
+            // so that the file's name can be used in further GetFile() calls (for example over the network)
+            File* file(new File(context_, resourceDirs_[i] + nameIn));
+            file->SetName(nameIn);
+            return file;
         }
-
-        // Fallback using absolute path
-        if (fileSystem->FileExists(nameIn))
-            return new File(context_, nameIn);
     }
 
+    // Fallback using absolute path
+    if (fileSystem->FileExists(nameIn))
+        return new File(context_, nameIn);
+
     return 0;
 }
 

+ 1 - 2
Source/Engine/Script/ScriptFile.cpp

@@ -733,8 +733,7 @@ void ScriptFile::ReleaseModule()
         SetMemoryUse(0);
         
         ResourceCache* cache = GetSubsystem<ResourceCache>();
-        if (cache)
-            cache->ResetDependencies(this);
+        cache->ResetDependencies(this);
     }
 }
 

+ 1 - 7
Source/Engine/UI/FileSelector.cpp

@@ -111,8 +111,7 @@ FileSelector::FileSelector(Context* context) :
     defaultFilters.Push("*.*");
     SetFilters(defaultFilters, 0);
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (fileSystem)
-        SetPath(fileSystem->GetCurrentDir());
+    SetPath(fileSystem->GetCurrentDir());
 
     // Focus the fileselector's filelist initially when created, and bring to front
     UI* ui = GetSubsystem<UI>();
@@ -195,9 +194,6 @@ void FileSelector::SetButtonTexts(const String& okText, const String& cancelText
 void FileSelector::SetPath(const String& path)
 {
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (!fileSystem)
-        return;
-
     if (fileSystem->DirExists(path))
     {
         path_ = AddTrailingSlash(path);
@@ -292,8 +288,6 @@ void FileSelector::SetLineEditText(LineEdit* edit, const String& text)
 void FileSelector::RefreshFiles()
 {
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (!fileSystem)
-        return;
 
     ignoreEvents_ = true;
 

+ 0 - 3
Source/Engine/UI/MessageBox.cpp

@@ -55,9 +55,6 @@ MessageBox::MessageBox(Context* context, const String& messageString, const Stri
     }
 
     UI* ui = GetSubsystem<UI>();
-    if (!ui)
-        return;
-    
     window_ = ui->LoadLayout(layoutFile, styleFile);
     ui->GetRoot()->AddChild(window_);