Skip to content

Commit

Permalink
Merge pull request #14 from Monika0000/dev
Browse files Browse the repository at this point in the history
(Scripts) Исправила перезагрузку скриптов
  • Loading branch information
innerviewer authored Jun 3, 2023
2 parents 76d80ec + 6945562 commit bb2a307
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions Engine/Core/libs/Graphics/inc/Graphics/Types/Framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace SR_GTYPES_NS {
void SetDepthEnabled(bool depthEnabled);
void SetSampleCount(uint8_t samples);

SR_NODISCARD bool IsFileResource() const noexcept override { return false; }
SR_NODISCARD uint8_t GetSamplesCount() const;
SR_NODISCARD bool IsDepthEnabled() const { return m_depthEnabled; }
SR_NODISCARD bool IsDirty() const { return m_dirty; }
Expand Down
2 changes: 1 addition & 1 deletion Engine/Core/libs/Scripting/libs/EvoScript
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace SR_SCRIPTING_NS {
m_script = EvoScriptManager::Instance().Load(path);
}

if (!m_script) {
SR_ERROR("EvoBehaviour::Load() : failed to load script!");
return false;
}

SRAssert(!m_behaviourContext);

InitHooks();
Expand All @@ -29,7 +34,7 @@ namespace SR_SCRIPTING_NS {
}

if (!m_behaviourContext) {
SR_ERROR("Failed to initialize behaviour context!");
SR_ERROR("EvoBehaviour::Load() : failed to initialize behaviour context!");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ namespace SR_SCRIPTING_NS {
return m_scripts.at(localPath.ToStringRef());
}

SR_LOG("EvoScriptManager::Load() : load \"" + localPath.ToStringRef() + "\" script");

if (!ReloadScript(localPath)) {
SR_ERROR("EvoScriptManager::Load() : failed to reload script!\n\tPath: " + localPath.ToStringRef());
return EvoScriptManager::ScriptPtr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace SR_SCRIPTING_NS {
pResource->Unload();
}

SR_LOG("EvoScriptResourceReloader::Reload() : reload \"" + path.ToStringRef() + "\" script...");

if (!EvoScriptManager::Instance().ReloadScript(path)) {
SR_ERROR("EvoScriptResourceReloader::Reload() : failed to reload script!\n\tPath: " + path.ToStringRef());
FreeStashedProperties(stashedProps);
Expand Down
3 changes: 2 additions & 1 deletion Engine/Core/libs/Utils/inc/Utils/Common/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace SR_UTILS_NS {
}

SR_MAYBE_UNUSED static bool IsSingletonInitialized() noexcept {
return GetSingleton() != nullptr;
auto&& pSingleton = GetSingleton();
return pSingleton && *pSingleton;
}

SR_MAYBE_UNUSED static void DestroySingleton() {
Expand Down
3 changes: 2 additions & 1 deletion Engine/Core/libs/Utils/inc/Utils/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace SR_UTILS_NS {
#define SR_SAFE_PTR_ASSERT(expr, msg) SRAssert2(expr, SR_UTILS_NS::Format("[SafePtr] %s \n\tPtr: %p", msg, (void *) m_ptr));

#define SRAssert2Once(expr, msg) ((!(expr) && SR_UTILS_NS::Debug::Instance().AssertOnceCheck(SR_MAKE_ASSERT(msg))) || SRAssert2(expr, msg))
#define SRHalt(msg) SRAssert2(false, msg)
#else
#define SR_CHECK_ERROR(fun, notEquals, errorMsg) fun
#define SRAssert2(expr, msg) (SR_NOOP)
Expand All @@ -143,13 +144,13 @@ namespace SR_UTILS_NS {
#define SR_SAFE_PTR_ASSERT(expr, msg) (SR_NOOP)
#define SRAssert2Once(expr, msg) (SR_NOOP)
#define SRVerifyFalse2(expr, msg) ((!(expr)))
#define SRHalt(msg) SR_ERROR(msg)
#endif

#define SRVerifyFalse(expr) SRVerifyFalse2(expr, "An exception has been occured.")

#define SRAssert1Once(expr) SRAssert2Once(expr, #expr)
#define SRAssertOnce(expr) SRAssert2Once(expr, "An exception has been occured.")
#define SRHalt(msg) SRAssert2(false, msg)
#define SRHaltOnce(msg) SRAssert2Once(false, msg)
#define SRHalt0() SRAssert(false)
#define SRHaltOnce0() SRAssert2Once(false, "An exception has been occured.")
Expand Down
3 changes: 3 additions & 0 deletions Engine/Core/libs/Utils/inc/Utils/ResourceManager/IResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace SR_UTILS_NS {
bool TryExecute(const SR_HTYPES_NS::Function<bool()>& fun, bool def) const;
bool Execute(const SR_HTYPES_NS::Function<bool()>& fun) const;

/// является ли ресурс файловым
SR_NODISCARD virtual bool IsFileResource() const noexcept { return true; }

SR_NODISCARD virtual uint64_t GetFileHash() const;
SR_NODISCARD bool IsRegistered() const noexcept { return m_isRegistered; }
SR_NODISCARD bool IsLoaded() const noexcept { return m_loadState == LoadState::Loaded; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ namespace SR_UTILS_NS {
using HardPtr = std::shared_ptr<ResourceInfo>;
using WeakPtr = std::weak_ptr<ResourceInfo>;

ResourceInfo(uint64_t fileHash, uint64_t resourceHash, ResourceType* pResourceType)
ResourceInfo(uint64_t fileHash, uint64_t resourceHash, uint64_t pathHash, ResourceType* pResourceType)
: m_fileHash(fileHash)
, m_resourceHash(resourceHash)
, m_resourceType(pResourceType)
, m_pathHash(pathHash)
{ }

SR_NODISCARD IResource* GetResource() const;
Expand All @@ -37,6 +38,8 @@ namespace SR_UTILS_NS {
uint64_t m_fileHash = 0;
/// текущий хэш самого ресурса (параметры и тд)
uint64_t m_resourceHash = 0;
/// хеш пути ресурса
uint64_t m_pathHash = 0;

ResourcesSet m_loaded;
};
Expand All @@ -61,7 +64,7 @@ namespace SR_UTILS_NS {
SR_NODISCARD Info& GetInfo();
SR_NODISCARD std::pair<ResourcePath, ResourceInfo::HardPtr> GetInfoByIndex(uint64_t index);
SR_NODISCARD IResourceReloader* GetReloader() const noexcept { return m_reloader; }
SR_NODISCARD std::string_view GetName() const { return m_name; }
SR_NODISCARD const std::string& GetName() const { return m_name; }

void Remove(IResource* pResource);
void Add(IResource* pResource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ namespace SR_UTILS_NS {
}

void ResourceType::Add(IResource* pResource) {
if (pResource->GetResourceHashPath() == 0 && pResource->IsFileResource()) {
SRHalt("ResourceType::Add() : resource path have a zero hash!");
return;
}

m_copies[pResource->GetResourceHashId()].insert(pResource);
m_resources.insert(pResource);

Expand All @@ -104,7 +109,7 @@ namespace SR_UTILS_NS {
pResource->m_resourceInfo = pInfo.get();
}
else {
auto&& pInfo = std::make_shared<ResourceInfo>(pResource->GetFileHash(), pResource->GetResourceHash(), this);
auto&& pInfo = std::make_shared<ResourceInfo>(pResource->GetFileHash(), pResource->GetResourceHash(), path, this);
pIt = m_info.insert(std::make_pair(path, pInfo)).first;
goto retry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ namespace SR_UTILS_NS {
ResourceManager::Hash ResourceManager::RegisterResourcePath(const Path &path) {
SR_SCOPED_LOCK

if (path.Empty()) {
SRHalt("ResourceManager::RegisterResourcePath() : empty path!");
}

const ResourceManager::Hash hash = path.GetHash();

auto&& pIt = m_hashPaths.find(hash);
Expand Down Expand Up @@ -499,7 +503,17 @@ namespace SR_UTILS_NS {
pResourceReloader = m_defaultReloader;
}

auto&& path = GetResourcePath(pHardPtr->m_resourceHash);
auto&& path = GetResourcePath(pHardPtr->m_pathHash);

if (path.Empty()) {
SR_ERROR("ResourceManager::ReloadResources() : resource have empty path!\n\tResource name: " +
pHardPtr->m_resourceType->GetName() + "\n\tHash name: " + std::to_string(pHardPtr->m_resourceHash) +
"\n\tFile hash: " + std::to_string(pHardPtr->m_fileHash) +
"\n\tPath hash: " + std::to_string(pHardPtr->m_pathHash)
);
continue;
}

if (pResourceReloader && !pResourceReloader->Reload(path, pHardPtr.get())) {
SR_ERROR("ResourceManager::ReloadResources() : failed to reload resource!\n\tPath: " + path.ToStringRef());
}
Expand Down

0 comments on commit bb2a307

Please sign in to comment.