Skip to content

Commit

Permalink
Add option to disable mmap (switch has no mmap)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dextinfire committed Nov 4, 2024
1 parent c31b3ba commit 21cfd21
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ set(Impacto_Src
src/io/vfs.cpp
src/io/assetpath.cpp
src/io/memorystream.cpp
src/io/memorymappedfilestream.cpp
src/io/physicalfilestream.cpp
src/io/uncompressedstream.cpp
src/io/zlibstream.cpp
Expand Down Expand Up @@ -572,7 +571,6 @@ set(Impacto_Header
src/io/stream.h
src/io/vfsarchive.h
src/io/memorystream.h
src/io/memorymappedfilestream.h
src/io/physicalfilestream.h
src/io/uncompressedstream.h
src/io/zlibstream.h
Expand Down Expand Up @@ -622,11 +620,10 @@ set(Impacto_Header

vendor/squish/squish.h

vendor/mio/mio.hpp


vendor/vma/vk_mem_alloc.h
vendor/minilua/minilua.h
)
)

if (WIN32)
list(APPEND Impacto_Src
Expand All @@ -637,6 +634,7 @@ endif ()
if (NX OR EMSCRIPTEN)
set(IMPACTO_DISABLE_VULKAN ON)
set(IMPACTO_DISABLE_DX9 ON)
set(IMPACTO_DISABLE_MMAP ON)
endif ()

if(ANDROID)
Expand Down Expand Up @@ -715,6 +713,16 @@ FetchContent_MakeAvailable(fmt)
FetchContent_MakeAvailable(pugixml)
FetchContent_MakeAvailable(utf8cpp)

if (NOT DEFINED IMPACTO_DISABLE_MMAP)
list(APPEND Impacto_Src
src/io/memorymappedfilestream.cpp
)
list(APPEND Impacto_Header
src/io/memorymappedfilestream.h
vendor/mio/mio.hpp
)
endif ()

if (NOT DEFINED IMPACTO_DISABLE_IMGUI)
FetchContent_Declare(
ImGui
Expand Down
3 changes: 2 additions & 1 deletion src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
#cmakedefine IMPACTO_DISABLE_FFMPEG
#cmakedefine IMPACTO_DISABLE_OPENAL
#cmakedefine IMPACTO_DISABLE_MSPACK
#cmakedefine IMPACTO_DISABLE_IMGUI
#cmakedefine IMPACTO_DISABLE_IMGUI
#cmakedefine IMPACTO_DISABLE_MMAP
13 changes: 10 additions & 3 deletions src/io/vfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
#include "../impacto.h"
#include <vector>
#include "vfsarchive.h"
#include "memorymappedfilestream.h"
#include "memorystream.h"
#include "../log.h"
#include "../profile/vfs.h"
#ifndef IMPACTO_DISABLE_MMAP
#include "memorymappedfilestream.h"
#else
#include "physicalfilestream.h"
#endif

#include "afsarchive.h"
#include "cpkarchive.h"
Expand Down Expand Up @@ -76,8 +80,11 @@ IoError VfsMount(std::string const& mountpoint,
}

Stream* archiveFile;
err = MemoryMappedFileStream<AccessMode::read>::Create(archiveFileName,
&archiveFile);
#ifndef IMPACTO_DISABLE_MMAP
err = MemoryMappedFileStream<AccessMode::read>::Create(archiveFileName, &archiveFile);
#else
err = PhysicalFileStream::Create(archiveFileName, &archiveFile);
#endif
if (err != IoError_OK) {
ImpLog(LL_Debug, LC_IO, "Could not open physical file \"%s\"\n",
archiveFileName.c_str());
Expand Down

0 comments on commit 21cfd21

Please sign in to comment.