Skip to content

Commit

Permalink
!XI Copy from //ce/main_stabilisation for CRYENGINE 5.5.1.
Browse files Browse the repository at this point in the history
Copied from Perforce
 Change: 1875853
  • Loading branch information
Build committed Nov 1, 2018
2 parents 13620c3 + b0494c2 commit 1d96cac
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 126 deletions.
178 changes: 95 additions & 83 deletions Code/CryEngine/RenderDll/Common/Textures/TextureCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,15 @@ static bool CopyDummy(const char* szImposter, const char* szSrcFile, const char*
success = (pSrcFile && (hDestFile != INVALID_HANDLE_VALUE));
if (success)
{
#define CHUNK_SIZE 64 * 1024

char* buf = new char[CHUNK_SIZE];
constexpr size_t chunkSize = 64 * 1024;
char* buf = new char[chunkSize];
size_t readBytes = 0;
DWORD writtenBytes = 0;
size_t totalBytes = 0;

while (!gEnv->pCryPak->FEof(pSrcFile))
{
readBytes = gEnv->pCryPak->FReadRaw(buf, sizeof(char), CHUNK_SIZE, pSrcFile);
readBytes = gEnv->pCryPak->FReadRaw(buf, sizeof(char), chunkSize, pSrcFile);
success = WriteFile(hDestFile, buf, sizeof(char) * readBytes, &writtenBytes, NULL) != FALSE;

if (!success || (readBytes != writtenBytes))
Expand All @@ -188,8 +187,6 @@ static bool CopyDummy(const char* szImposter, const char* szSrcFile, const char*

delete[] buf;

#undef CHUNK_SIZE

// Prevent zero-byte files being returned as valid DDSs.
success = success && (totalBytes != 0);
}
Expand Down Expand Up @@ -552,37 +549,46 @@ class CTemporaryAsset
*/
bool CTextureCompiler::HasQueuedResourceCompiler(const char* szSrcFile, const char* szDstFile)
{
CryAutoReadLock<CryRWLock> lock(m_rwLockWatch);

// check if to be generated from the same source
m_rwLockWatch.RLock();
TWatchItem queued = m_mWatchList.find(szDstFile);
bool doadd = (queued == m_mWatchList.end());
bool exists = (!doadd && (queued->second == szSrcFile));
m_rwLockWatch.RUnlock();

const bool doAdd = (queued == m_mWatchList.end());
const bool exists = (!doAdd && (queued->second == szSrcFile));
return exists;
}

CResourceCompilerHelper::ERcCallResult CTextureCompiler::QueueResourceCompiler(const char* szSrcFile, const char* szDstFile, const bool bWindow, const bool bRefresh)
{
if (AddToWatchList(szDstFile, szSrcFile))
{
ForkOffResourceCompiler(szSrcFile, szDstFile, bWindow, bRefresh);
}

return eRcCallResult_queued;
}

bool CTextureCompiler::AddToWatchList(const char* szDstFile, const char* szSrcFile)
{
// check if to be generated from the same source
if (HasQueuedResourceCompiler(szSrcFile, szDstFile))
{
return eRcCallResult_queued;
return false;
}

CryAutoWriteLock<CryRWLock> lock(m_rwLockWatch);

// replace/place source
m_rwLockWatch.WLock();
TWatchItem queued = m_mWatchList.find(szDstFile);
bool doadd = (queued == m_mWatchList.end());
bool exists = (!doadd && (queued->second == szSrcFile));
const bool doAdd = (queued == m_mWatchList.end());
const bool exists = (!doAdd && (queued->second == szSrcFile));

if (exists)
{
m_rwLockWatch.WUnlock();
return eRcCallResult_queued;
return false;
}

if (!doadd)
if (!doAdd)
{
queued->second = szSrcFile;
}
Expand All @@ -597,7 +603,6 @@ CResourceCompilerHelper::ERcCallResult CTextureCompiler::QueueResourceCompiler(c
{
// If this fails it's not critical, although it'll show
// the "ReplaceMe" texture instead of a proper one.
// return eRcCallResult_notFound;
}

// Provide cubemap's diffuse texture dummy as well if it is necessary
Expand All @@ -610,34 +615,28 @@ CResourceCompilerHelper::ERcCallResult CTextureCompiler::QueueResourceCompiler(c
{
// If this fails it's not critical, although it'll show
// the "ReplaceMe" texture instead of a proper one.
// return eRcCallResult_notFound;
}
}
}
}
m_rwLockWatch.WUnlock();

ForkOffResourceCompiler(szSrcFile, szDstFile, bWindow, bRefresh);
return eRcCallResult_queued;
return true;
}

void CTextureCompiler::ForkOffResourceCompiler(const char* szSrcFile, const char* szDstFile, const bool bWindow, const bool bRefresh)
{
m_rwLockProcessing.WLock();
CryAutoWriteLock<CryRWLock> lock(m_rwLockProcessing);

bool empty = !m_qProcessingList.size();
#if defined(STLPORT)
#if defined(STLPORT)
m_qProcessingList.push_back(TProcItem());
#else
#else
m_qProcessingList.emplace_back(TProcItem());
#endif
#endif
TProcItem& addedrc = m_qProcessingList.back();

// have to be valid after the unlock
addedrc.src = szSrcFile;
addedrc.dst = szDstFile;
addedrc.windowed = bWindow;
addedrc.refresh = bRefresh;
m_rwLockProcessing.WUnlock();

// This approach spawns 1 new thread every time we had an empty list.
// The thread automatically consumes the list for as long as it's not empty
Expand Down Expand Up @@ -672,13 +671,7 @@ void CTextureCompiler::ConsumeQueuedResourceCompiler(TProcItem* item)
{
// no need to protect
int pending = m_qProcessingList.size();

m_rwLockNotify.RLock();
std::for_each(m_sNotifyList.begin(), m_sNotifyList.end(), [=](IAsyncTextureCompileListener* notify)
{
notify->OnCompilationQueueTriggered(pending);
});
m_rwLockNotify.RUnlock();
NotifyCompilationQueueTriggered(pending);

while (item)
{
Expand All @@ -689,15 +682,9 @@ void CTextureCompiler::ConsumeQueuedResourceCompiler(TProcItem* item)
continue;
}

{
m_rwLockNotify.RLock();
std::for_each(m_sNotifyList.begin(), m_sNotifyList.end(), [=](IAsyncTextureCompileListener* notify)
{
notify->OnCompilationStarted(item->src.c_str(), item->dst.c_str(), pending);
});
m_rwLockNotify.RUnlock();
NotifyCompilationStarted(item, pending);

iLog->Log("Compile texture from \"%s\", to \"%s\"\n", item->src.c_str(), item->dst.c_str());
iLog->Log("Compile texture from \"%s\", to \"%s\"\n", item->src.c_str(), item->dst.c_str());

// Always use a temporary file as outfile, otherwise RC may write to the
// file before it's even loaded as a dummy.
Expand All @@ -706,47 +693,73 @@ void CTextureCompiler::ConsumeQueuedResourceCompiler(TProcItem* item)
item->returnval = InvokeResourceCompiler(item->src.c_str(), tmpAsset.GetTmpPath().c_str(), item->windowed, true);
}

m_rwLockNotify.RLock();
std::for_each(m_sNotifyList.begin(), m_sNotifyList.end(), [=](IAsyncTextureCompileListener* notify)
{
notify->OnCompilationFinished(item->src.c_str(), item->dst.c_str(), item->returnval);
});
m_rwLockNotify.RUnlock();
}
NotifyCompilationFinished(item);
GetNextItem(item, pending);
}

TProcQueue::iterator foundrc;
NotifyCompilationQueueDepleted();
}

m_rwLockWatch.WLock();
m_rwLockProcessing.WLock();
void CTextureCompiler::GetNextItem(TProcItem* &item, int &pending)
{
CryAutoWriteLock<CryRWLock> lockWatch(m_rwLockWatch);
CryAutoWriteLock<CryRWLock> lockProcessing(m_rwLockProcessing);

for (foundrc = m_qProcessingList.begin(); (&(*foundrc) != item) && (foundrc != m_qProcessingList.end()); ++foundrc)
;
if (foundrc != m_qProcessingList.end())
{
m_mWatchList.erase(item->dst);
m_qProcessingList.erase(foundrc);
if (m_qProcessingList.size())
item = &m_qProcessingList.front();
else
item = NULL;
pending = m_qProcessingList.size();
}
// Severe container-damage, should not happen.
else
{
assert(0);
}
TProcQueue::iterator foundrc;
for (foundrc = m_qProcessingList.begin(); (&(*foundrc) != item) && (foundrc != m_qProcessingList.end()); ++foundrc)
{
// empty by intention
}

m_rwLockWatch.WUnlock();
m_rwLockProcessing.WUnlock();
if (foundrc == m_qProcessingList.end())
{
CRY_ASSERT_MESSAGE(foundrc != m_qProcessingList.end(), "Severe container-damage, should not happen.");
return;
}

m_rwLockNotify.RLock();
std::for_each(m_sNotifyList.begin(), m_sNotifyList.end(), [=](IAsyncTextureCompileListener* notify)
m_mWatchList.erase(item->dst);
m_qProcessingList.erase(foundrc);
if (m_qProcessingList.size())
item = &m_qProcessingList.front();
else
item = NULL;
pending = m_qProcessingList.size();
}

void CTextureCompiler::NotifyCompilationQueueDepleted()
{
CryAutoReadLock<CryRWLock> lock(m_rwLockNotify);
for (IAsyncTextureCompileListener* notify : m_sNotifyList)
{
notify->OnCompilationQueueDepleted();
});
m_rwLockNotify.RUnlock();
};
}

void CTextureCompiler::NotifyCompilationFinished(TProcItem* item)
{
CryAutoReadLock<CryRWLock> lock(m_rwLockNotify);
for (IAsyncTextureCompileListener* notify : m_sNotifyList)
{
notify->OnCompilationFinished(item->src.c_str(), item->dst.c_str(), item->returnval);
};
}

void CTextureCompiler::NotifyCompilationStarted(TProcItem* item, int pending)
{
CryAutoReadLock<CryRWLock> lock(m_rwLockNotify);
for (IAsyncTextureCompileListener* notify : m_sNotifyList)
{
notify->OnCompilationStarted(item->src.c_str(), item->dst.c_str(), pending);
};
}

void CTextureCompiler::NotifyCompilationQueueTriggered(int pending)
{
CryAutoReadLock<CryRWLock> lock(m_rwLockNotify);
for (IAsyncTextureCompileListener* notify : m_sNotifyList)
{
notify->OnCompilationQueueTriggered(pending);
};
}

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -915,16 +928,15 @@ CTextureCompiler::EResult CTextureCompiler::ProcessTextureIfNeeded(
//////////////////////////////////////////////////////////////////////////
void CTextureCompiler::AddAsyncTextureCompileListener(IAsyncTextureCompileListener* pListener)
{
m_rwLockNotify.WLock();
CryAutoWriteLock<CryRWLock> lock(m_rwLockNotify);
m_sNotifyList.insert(pListener);
m_rwLockNotify.WUnlock();

}

void CTextureCompiler::RemoveAsyncTextureCompileListener(IAsyncTextureCompileListener* pListener)
{
m_rwLockNotify.WLock();
CryAutoWriteLock<CryRWLock> lock(m_rwLockNotify);
m_sNotifyList.erase(pListener);
m_rwLockNotify.WUnlock();
}

#else
Expand Down
15 changes: 11 additions & 4 deletions Code/CryEngine/RenderDll/Common/Textures/TextureCompiler.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.

#ifndef _TEXTURECOMPILER_H
#define _TEXTURECOMPILER_H
#pragma once

#include <stdio.h> // strlen()
#include <functional>
Expand Down Expand Up @@ -112,13 +111,21 @@ class CTextureCompiler : public CResourceCompilerHelper, NoCopy
// szDstFile usually the path to a DDS
bool HasQueuedResourceCompiler(const char* szSrcFile, const char* szDstFile);
ERcCallResult QueueResourceCompiler(const char* szSrcFile, const char* szDstFile, const bool bWindow, const bool bRefresh);

#endif // CRY_ENABLE_RC_HELPER

void AddAsyncTextureCompileListener(IAsyncTextureCompileListener* pListener);
void RemoveAsyncTextureCompileListener(IAsyncTextureCompileListener* pListener);

private:
#if defined(CRY_ENABLE_RC_HELPER)
bool AddToWatchList(const char* szDstFile, const char* szSrcFile);
void NotifyCompilationQueueTriggered(int pending);
void NotifyCompilationStarted(TProcItem* item, int pending);
void NotifyCompilationFinished(TProcItem* item);
void NotifyCompilationQueueDepleted();
void GetNextItem(TProcItem* &item, int &pending);

// Arguments:
// szFilePath - could be source or destination filename
// dwIndex - used to iterate through all input filenames, start with 0 and increment by 1
Expand All @@ -129,7 +136,6 @@ class CTextureCompiler : public CResourceCompilerHelper, NoCopy
const unsigned int index,
char* inputFilename,
size_t inputFilenameSizeInBytes);
#endif

// little helper function (to stay independent)
static string AddSuffix(string in, const char* suffix)
Expand All @@ -144,6 +150,8 @@ class CTextureCompiler : public CResourceCompilerHelper, NoCopy
}

static bool IsFileOpened(const char* szPath);
#endif

public:
// only for image formats supported by the resource compiler
// Arguments:
Expand All @@ -164,4 +172,3 @@ class CTextureCompiler : public CResourceCompilerHelper, NoCopy
}
};

#endif
10 changes: 3 additions & 7 deletions Code/Sandbox/EditorQt/Objects/ObjectLayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void CLayerChangeEvent::Send() const
CObjectLayerManager::CObjectLayerManager(CObjectManager* pObjectManager) :
m_pObjectManager(pObjectManager),
m_layersPath(LAYER_PATH),
m_bCanModifyLayers(false),
m_bCanModifyLayers(true),
m_bOverwriteDuplicates(false),
m_visibleSetLayer(CryGUID::Null())
{
Expand All @@ -152,18 +152,14 @@ void CObjectLayerManager::OnEditorNotifyEvent(EEditorNotifyEvent event)
{
switch (event)
{
case eNotify_OnBeginNewScene:
case eNotify_OnBeginSceneOpen:
m_bCanModifyLayers = false;
break;
case eNotify_OnEndNewScene:
case eNotify_OnEndSceneOpen:
m_bCanModifyLayers = true;
break;
case eNotify_OnLayerImportBegin:
m_bCanModifyLayers = false;
break;
case eNotify_OnLayerImportEnd:
m_bCanModifyLayers = true;
break;
}
}

Expand Down
Loading

0 comments on commit 1d96cac

Please sign in to comment.