Skip to content

Commit 322c353

Browse files
bunch of important nbl::system fixes
1 parent 1d7c377 commit 322c353

File tree

6 files changed

+97
-71
lines changed

6 files changed

+97
-71
lines changed

examples_tests/52.SystemTest/main.cpp

Lines changed: 72 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,25 @@ class WindowEventCallback : public IWindow::IEventCallback
210210

211211
int main(int argc, char** argv)
212212
{
213-
path CWD = path(argv[0]).parent_path().generic_string() + "/";
214-
path mediaWD = CWD.generic_string() + "../../media/";
215-
auto system = CommonAPI::createSystem();
216-
// *** Select stdout/file logger ***
217-
auto logger = make_smart_refctd_ptr<system::CColoredStdoutLoggerWin32>();
218-
//auto logger = system::CFileLogger::create(logFileName);
219-
// *** If you don't want logging, uncomment this one line***
220-
// logger = nullptr;
221-
// **************************************************************************************
213+
const path CWD = path(argv[0]).parent_path().generic_string() + "/";
214+
const path mediaWD = CWD.generic_string() + "../../media/";
222215

223-
auto assetManager = core::make_smart_refctd_ptr<IAssetManager>(smart_refctd_ptr(system));
216+
auto system = CommonAPI::createSystem();
217+
// TODO: system->deleteFile("log.txt");
224218

225-
auto winManager = core::make_smart_refctd_ptr<CWindowManagerWin32>();
226-
219+
core::smart_refctd_ptr<system::ILogger> logger;
227220
{
228221
system::ISystem::future_t<smart_refctd_ptr<system::IFile>> future;
229-
system->createFile(future, "log.txt", nbl::system::IFile::ECF_READ_WRITE);
222+
system->createFile(future, CWD/"log.txt", nbl::system::IFile::ECF_READ_WRITE);
230223
auto file = future.get();
224+
logger = core::make_smart_refctd_ptr<system::CFileLogger>(std::move(file),false);
231225
}
232226

227+
auto assetManager = core::make_smart_refctd_ptr<IAssetManager>(smart_refctd_ptr(system));
228+
229+
auto winManager = core::make_smart_refctd_ptr<CWindowManagerWin32>();
230+
231+
233232
IWindow::SCreationParams params;
234233
params.callback = nullptr;
235234
params.width = 720;
@@ -240,26 +239,36 @@ int main(int argc, char** argv)
240239
params.flags = IWindow::ECF_NONE;
241240
params.windowCaption = "Test Window";
242241

243-
auto input = make_smart_refctd_ptr<InputSystem>(system::logger_opt_smart_ptr(logger));
244-
auto windowCb = make_smart_refctd_ptr<WindowEventCallback>(core::smart_refctd_ptr(input),system::logger_opt_smart_ptr(logger));
242+
auto input = make_smart_refctd_ptr<InputSystem>(system::logger_opt_smart_ptr(smart_refctd_ptr(logger)));
243+
auto windowCb = make_smart_refctd_ptr<WindowEventCallback>(core::smart_refctd_ptr(input),system::logger_opt_smart_ptr(smart_refctd_ptr(logger)));
245244
params.callback = windowCb;
246245
// *********************************
247246
auto window = winManager->createWindow(std::move(params));
248247
auto* cursorControl = window->getCursorControl();
249248

250249
system::ISystem::future_t<smart_refctd_ptr<system::IFile>> future;
251-
system->createFile(future, CWD.generic_string() + "testFile.txt", core::bitflag(nbl::system::IFile::ECF_READ_WRITE) | IFile::ECF_MAPPABLE);
250+
system->createFile(future, CWD/"testFile.txt", core::bitflag(nbl::system::IFile::ECF_READ_WRITE)/*Growing mappable files are a TODO |IFile::ECF_MAPPABLE*/);
252251
auto file = future.get();
253-
std::string fileData = "Test file data!";
254252

255-
system::future<size_t> writeFuture;
256-
file->write(writeFuture, fileData.data(), 0, fileData.length());
257-
assert(writeFuture.get() == fileData.length());
253+
{
254+
const std::string fileData = "Test file data!";
258255

259-
std::string readStr(fileData.length(), '\0');
260-
system::future<size_t> readFuture;
261-
file->read(readFuture, readStr.data(), 0, readStr.length());
262-
assert(readFuture.get() == fileData.length());
256+
system::IFile::success_t writeSuccess;
257+
file->write(writeSuccess, fileData.data(), 0, fileData.length());
258+
{
259+
const bool success = bool(writeSuccess);
260+
assert(success);
261+
}
262+
263+
std::string readStr(fileData.length(), '\0');
264+
system::IFile::success_t readSuccess;
265+
file->read(readSuccess, readStr.data(), 0, readStr.length());
266+
{
267+
const bool success = bool(readSuccess);
268+
assert(success);
269+
}
270+
assert(readStr == fileData);
271+
}
263272

264273
// polling for events!
265274
InputSystem::ChannelReader<IMouseEventChannel> mouse;
@@ -305,52 +314,26 @@ int main(int argc, char** argv)
305314
}
306315
}
307316
};
308-
309-
auto bigarch = system->openFileArchive(CWD.generic_string() + "../../media/sponza.zip");
310-
system->mount(std::move(bigarch), "sponza");
311-
312-
system->copy(CWD.generic_string() + "pngWriteSuccessful.png", "pngCopy.png");
313-
314-
system->createDirectory(CWD.generic_string() + "textures1");
315-
system->copy(CWD.generic_string() + "textures", CWD.generic_string() + "textures1");
316-
system->copy("sponza/textures", CWD.generic_string() + "textures");
317-
system->moveFileOrDirectory("file.tar", "movedFile.tar");
318-
system->listFilesInDirectory(CWD.generic_string() + "textures");
319-
{
320-
system::future<smart_refctd_ptr<IFile>> fut;
321-
system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ);
322-
auto file = fut.get();
323-
{
324-
system::future<smart_refctd_ptr<IFile>> fut;
325-
system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ);
326-
file = fut.get();
327-
}
328-
std::string str(5, '\0');
329-
system::future<size_t> readFut;
330-
file->read(readFut, str.data(), 0, 5);
331-
readFut.get();
332-
std::cout << str << std::endl;
333-
}
334317

335318
IAssetLoader::SAssetLoadParams lp;
336319
lp.workingDirectory = mediaWD;
337320
//PNG loader test
338321
{
339-
auto asset = assetManager->getAsset("cegui_alfisko/screenshot.png", lp);
322+
auto asset = assetManager->getAsset("Cerberus_by_Andrew_Maximov/Textures/Cerberus_H.png", lp);
340323
assert(!asset.getContents().empty());
341-
auto cpuImage = static_cast<ICPUImage*>(asset.getContents().begin()->get());
324+
auto cpuImage = IAsset::castDown<ICPUImage>(asset.getContents()[0]);
342325
core::smart_refctd_ptr<ICPUImageView> imageView;
326+
343327
ICPUImageView::SCreationParams imgViewParams;
344328
imgViewParams.flags = static_cast<ICPUImageView::E_CREATE_FLAGS>(0u);
345-
imgViewParams.format = E_FORMAT::EF_R8G8B8_UINT;
329+
imgViewParams.format = cpuImage->getCreationParameters().format;
346330
imgViewParams.image = core::smart_refctd_ptr<ICPUImage>(cpuImage);
347331
imgViewParams.viewType = ICPUImageView::ET_2D;
348332
imgViewParams.subresourceRange = { static_cast<IImage::E_ASPECT_FLAGS>(0u),0u,1u,0u,1u };
349333
imageView = ICPUImageView::create(std::move(imgViewParams));
350334

351335
IAssetWriter::SAssetWriteParams wp(imageView.get());
352336
wp.workingDirectory = CWD;
353-
354337
assetManager->writeAsset("pngWriteSuccessful.png", wp);
355338
}
356339
//TODO OBJ loader test
@@ -367,7 +350,7 @@ int main(int argc, char** argv)
367350
{
368351
auto asset = assetManager->getAsset("dwarf.jpg", lp);
369352
assert(!asset.getContents().empty());
370-
auto cpuImage = static_cast<ICPUImage*>(asset.getContents().begin()->get());
353+
auto cpuImage = IAsset::castDown<ICPUImage>(asset.getContents()[0]);
371354
core::smart_refctd_ptr<ICPUImageView> imageView;
372355
ICPUImageView::SCreationParams imgViewParams;
373356
imgViewParams.flags = static_cast<ICPUImageView::E_CREATE_FLAGS>(0u);
@@ -382,6 +365,40 @@ int main(int argc, char** argv)
382365

383366
assetManager->writeAsset("jpgWriteSuccessful.jpg", wp);
384367
}
368+
369+
370+
auto bigarch = system->openFileArchive(CWD/"../../media/sponza.zip");
371+
system->mount(std::move(bigarch), "sponza");
372+
373+
system->copy(CWD/"pngWriteSuccessful.png", CWD/"pngCopy.png");
374+
375+
system->createDirectory(CWD/"textures1");
376+
system->copy(CWD/"textures", CWD/"textures1");
377+
system->copy("sponza/textures", CWD/"textures");
378+
379+
const auto items = system->listItemsInDirectory(CWD/"textures");
380+
for (const auto& item : items)
381+
logger->log("%s",system::ILogger::ELL_DEBUG,item.c_str());
382+
383+
/* TODO: Tart Archive reader test
384+
system->moveFileOrDirectory("file.tar","movedFile.tar");
385+
{
386+
system::future<smart_refctd_ptr<IFile>> fut;
387+
system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ);
388+
auto file = fut.get();
389+
{
390+
system::future<smart_refctd_ptr<IFile>> fut;
391+
system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ);
392+
file = fut.get();
393+
}
394+
std::string str(5, '\0');
395+
system::future<size_t> readFut;
396+
file->read(readFut, str.data(), 0, 5);
397+
readFut.get();
398+
std::cout << str << std::endl;
399+
}
400+
*/
401+
385402
while (windowCb->isWindowOpen())
386403
{
387404
input->getDefaultMouse(&mouse);

examples_tests/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ N = No support
8383
| 49.ComputeFFT | S | N | S | S | N | S | N | N | |
8484
| 50.NewAPITest | W | W | W | W | W | W | W | W | |
8585
| 51.RadixSort | W | N | W | W | N | W | N | W | |
86-
| 52.SystemTest | S | S | S | S | S | S | S | S | |
86+
| 52.SystemTest | Y | Y | Y | S | S | S | S | S | |
8787
| 53.ComputeShaders | S | N | S | S | N | S | N | S | |
8888
| 54.Transformations | Y | Y | B | S | S | S | S | S | |
89-
| 55.RGB18E7S3 | S | S | S | S | S | S | N | N | |
89+
| 55.RGB18E7S3 | Y | Y | Y | S | S | S | N | N | |
9090
| 56.RayQuery | N | N | Y | N | N | S | N | S | |
9191
| 57.AndroidSample | N | N | N | N | N | N | S | S | |
9292
| 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | |

include/nbl/asset/IAssetManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,14 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin
321321
SAssetBundle getAssetInHierarchy_impl(const std::string& _filePath, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override)
322322
{
323323
IAssetLoader::SAssetLoadContext ctx(_params, nullptr);
324-
system::path filePath = _filePath;
325324

325+
system::path filePath = _filePath;
326326
_override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel);
327+
if (!m_system->exists(filePath,system::IFile::ECF_READ))
328+
{
329+
filePath = _params.workingDirectory/filePath;
330+
_override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel);
331+
}
327332

328333
system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future;
329334
m_system->createFile(future, filePath, system::IFile::ECF_READ);

include/nbl/system/CFileLogger.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace nbl::system
1010
class CFileLogger : public IThreadsafeLogger
1111
{
1212
public:
13-
CFileLogger(core::smart_refctd_ptr<IFile>&& _file, const core::bitflag<E_LOG_LEVEL> logLevelMask=ILogger::defaultLogMask())
14-
: IThreadsafeLogger(logLevelMask), m_file(std::move(_file))
13+
CFileLogger(core::smart_refctd_ptr<IFile>&& _file, const bool append, const core::bitflag<E_LOG_LEVEL> logLevelMask=ILogger::defaultLogMask())
14+
: IThreadsafeLogger(logLevelMask), m_file(std::move(_file)), m_pos(append ? m_file->getSize():0ull)
1515
{
1616
}
1717

@@ -22,11 +22,12 @@ class CFileLogger : public IThreadsafeLogger
2222
{
2323
const auto str = constructLogString(fmt, logLevel, args);
2424
ISystem::future_t<size_t> future;
25-
m_file->write(future,str.data(),m_file->getSize(),str.length());
26-
future.get(); // need to use the future to make sure op is actually executed :(
25+
m_file->write(future,str.data(),m_pos,str.length());
26+
m_pos += future.get(); // need to use the future to make sure op is actually executed :(
2727
}
2828

2929
core::smart_refctd_ptr<IFile> m_file;
30+
size_t m_pos;
3031
};
3132

3233
}

src/nbl/asset/interchange/CImageLoaderJPG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ bool CImageLoaderJPG::isALoadableFileFormat(system::IFile* _file, const system::
159159
uint32_t header = 0;
160160
system::IFile::success_t success;
161161
_file->read(success, &header, 6, sizeof(uint32_t));
162-
return success && (header&0x00FFD8FFu)==0x00FFD8FFu;
162+
return success && ((header&0x00FFD8FFu)==0x00FFD8FFu || header == 0x4a464946 || header == 0x4649464a || header == 0x66697845u || header == 0x70747468u); // maybe 0x4a464946 can go
163163
#endif
164164
}
165165

src/nbl/system/ISystem.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ core::vector<system::path> ISystem::listItemsInDirectory(const system::path& p)
8484
core::vector<system::path> res;
8585
res.reserve(512u);
8686

87-
auto addArchiveItems = [this,&res](const path& archPath) -> void
87+
auto addArchiveItems = [this,&res](const path& archPath, const path& dirPath) -> void
8888
{
8989
const auto archives = m_cachedArchiveFiles.findRange(archPath);
9090
for (auto& arch : archives)
9191
{
92-
const auto assets = arch.second->listAssets();
92+
const auto assets = arch.second->listAssets(std::filesystem::relative(dirPath,archPath));
9393
for (auto& item : assets)
9494
res.push_back(archPath/item.pathRelativeToArchive);
9595
}
@@ -102,7 +102,7 @@ core::vector<system::path> ISystem::listItemsInDirectory(const system::path& p)
102102
{
103103
res.push_back(entry.path());
104104
// entry could have been an archive
105-
addArchiveItems(entry.path());
105+
addArchiveItems(entry.path(),p);
106106
}
107107
else
108108
{
@@ -122,13 +122,15 @@ core::vector<system::path> ISystem::listItemsInDirectory(const system::path& p)
122122
}
123123
#endif
124124
// check for part of subpath being an archive
125-
system::path path = std::filesystem::exists(p) ? std::filesystem::canonical(p.parent_path()):p.parent_path();
125+
auto path = std::filesystem::exists(p) ? std::filesystem::canonical(p):p;
126126
// going up the directory tree
127127
while (!path.empty() && path.parent_path()!=path)
128128
{
129-
path = std::filesystem::exists(path) ? std::filesystem::canonical(path):path;
130-
addArchiveItems(path);
129+
addArchiveItems(path,p);
130+
const bool ex = std::filesystem::exists(path);
131131
path = path.parent_path();
132+
if (ex)
133+
path = std::filesystem::canonical(path);
132134
}
133135
}
134136
return res;
@@ -165,12 +167,13 @@ bool ISystem::copy(const system::path& from, const system::path& to)
165167
createFile(readFileFut,from,core::bitflag(IFile::ECF_READ)|IFile::ECF_COHERENT);
166168
createFile(writeFileFut,to,IFile::ECF_WRITE);
167169
auto readF = readFileFut.get();
170+
const IFile* readFptr = readF.get();
168171
auto writeF = writeFileFut.get();
169-
if (!readF || !readF->getMappedPointer() || !writeF)
172+
if (!readF || !readFptr->getMappedPointer() || !writeF)
170173
return false;
171174

172175
IFile::success_t bytesWritten;
173-
writeF->write(bytesWritten,readF->getMappedPointer(),0,readF->getSize());
176+
writeF->write(bytesWritten,readFptr->getMappedPointer(),0,readF->getSize());
174177
return bool(bytesWritten);
175178
};
176179
if (isPathReadOnly(from))

0 commit comments

Comments
 (0)