summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-29 22:41:26 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-29 22:41:26 +0300
commit8f95378c3be89c06c722da03ddbd3641c4fc2323 (patch)
tree4f1c14fb0ba57793f8979df43ffd293533606e1b
parentfc31f1003bec7e0117421a8c58668e61849eeba5 (diff)
downloadplus-8f95378c3be89c06c722da03ddbd3641c4fc2323.tar.gz
plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.tar.bz2
plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.tar.xz
plus-8f95378c3be89c06c722da03ddbd3641c4fc2323.zip
Move rwops code into virtfs namespace.
-rw-r--r--src/fs/virtfs/virtfsrwops.cpp100
-rw-r--r--src/fs/virtfs/virtfsrwops.h33
-rw-r--r--src/gui/fonts/font.cpp2
-rw-r--r--src/integrity_unittest.cc8
-rw-r--r--src/resources/atlas/atlasmanager.cpp2
-rw-r--r--src/resources/loaders/imageloader.cpp2
-rw-r--r--src/resources/loaders/musicloader.cpp2
-rw-r--r--src/resources/loaders/soundloader.cpp2
-rw-r--r--src/test/testlauncher.cpp4
9 files changed, 86 insertions, 69 deletions
diff --git a/src/fs/virtfs/virtfsrwops.cpp b/src/fs/virtfs/virtfsrwops.cpp
index f44cc6601..e66748967 100644
--- a/src/fs/virtfs/virtfsrwops.cpp
+++ b/src/fs/virtfs/virtfsrwops.cpp
@@ -52,17 +52,9 @@
#include "debug.h"
-#ifdef USE_SDL2
-#define RWOPSINT int64_t
-#define RWOPSSIZE size_t
-#else // USE_SDL2
-#define RWOPSINT int32_t
-#define RWOPSSIZE int
-#endif // USE_SDL2
-
-static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw,
- const RWOPSINT offset,
- const int whence)
+RWOPSINT VirtFs::rwops_seek(SDL_RWops *const rw,
+ const RWOPSINT offset,
+ const int whence)
{
if (!rw)
return -1;
@@ -80,14 +72,14 @@ static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw,
if (current == -1)
{
logger->assertLog(
- "virtfsrwops_seek: Can't find position in file.");
+ "VirtFs::rwops_seek: Can't find position in file.");
return -1;
} /* if */
pos = CAST_S32(current);
if (static_cast<int64_t>(pos) != current)
{
- logger->assertLog("virtfsrwops_seek: "
+ logger->assertLog("VirtFs::rwops_seek: "
"Can't fit current file position in an int!");
return -1;
} /* if */
@@ -102,14 +94,14 @@ static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw,
const int64_t len = VirtFs::fileLength(handle);
if (len == -1)
{
- logger->assertLog("virtfsrwops_seek:Can't find end of file.");
+ logger->assertLog("VirtFs::rwops_seek:Can't find end of file.");
return -1;
} /* if */
pos = static_cast<RWOPSINT>(len);
if (static_cast<int64_t>(pos) != len)
{
- logger->assertLog("virtfsrwops_seek: "
+ logger->assertLog("VirtFs::rwops_seek: "
"Can't fit end-of-file position in an int!");
return -1;
} /* if */
@@ -118,30 +110,30 @@ static RWOPSINT virtfsrwops_seek(SDL_RWops *const rw,
} /* else if */
else
{
- logger->assertLog("virtfsrwops_seek: Invalid 'whence' parameter.");
+ logger->assertLog("VirtFs::rwops_seek: Invalid 'whence' parameter.");
return -1;
} /* else */
if (pos < 0)
{
- logger->assertLog("virtfsrwops_seek: "
+ logger->assertLog("VirtFs::rwops_seek: "
"Attempt to seek past start of file.");
return -1;
} /* if */
if (!VirtFs::seek(handle, static_cast<uint64_t>(pos)))
{
- logger->assertLog("virtfsrwops_seek: seek error.");
+ logger->assertLog("VirtFs::rwops_seek: seek error.");
return -1;
} /* if */
return pos;
-} /* virtfsrwops_seek */
+} /* VirtFs::rwops_seek */
-static RWOPSSIZE virtfsrwops_read(SDL_RWops *const rw,
- void *const ptr,
- const RWOPSSIZE size,
- const RWOPSSIZE maxnum)
+RWOPSSIZE VirtFs::rwops_read(SDL_RWops *const rw,
+ void *const ptr,
+ const RWOPSSIZE size,
+ const RWOPSSIZE maxnum)
{
if (!rw)
return 0;
@@ -154,17 +146,17 @@ static RWOPSSIZE virtfsrwops_read(SDL_RWops *const rw,
{
if (!VirtFs::eof(handle)) /* not EOF? Must be an error. */
{
- logger->assertLog("virtfsrwops_seek: read error.");
+ logger->assertLog("VirtFs::rwops_seek: read error.");
}
} /* if */
return CAST_S32(rc);
-} /* virtfsrwops_read */
+} /* VirtFs::rwops_read */
-static RWOPSSIZE virtfsrwops_write(SDL_RWops *const rw,
- const void *const ptr,
- const RWOPSSIZE size,
- const RWOPSSIZE num)
+RWOPSSIZE VirtFs::rwops_write(SDL_RWops *const rw,
+ const void *const ptr,
+ const RWOPSSIZE size,
+ const RWOPSSIZE num)
{
if (!rw)
return 0;
@@ -175,13 +167,13 @@ static RWOPSSIZE virtfsrwops_write(SDL_RWops *const rw,
CAST_U32(num));
if (rc != static_cast<int64_t>(num))
{
- logger->assertLog("virtfsrwops_seek: write error.");
+ logger->assertLog("VirtFs::rwops_seek: write error.");
}
return CAST_S32(rc);
-} /* virtfsrwops_write */
+} /* VirtFs::rwops_write */
-static int virtfsrwops_close(SDL_RWops *const rw)
+int VirtFs::rwops_close(SDL_RWops *const rw)
{
if (!rw)
return 0;
@@ -189,30 +181,30 @@ static int virtfsrwops_close(SDL_RWops *const rw)
rw->hidden.unknown.data1);
if (!VirtFs::close(handle))
{
- logger->assertLog("virtfsrwops_seek: close error.");
+ logger->assertLog("VirtFs::rwops_seek: close error.");
return -1;
} /* if */
SDL_FreeRW(rw);
return 0;
-} /* virtfsrwops_close */
+} /* VirtFs::rwops_close */
#ifdef USE_SDL2
-static RWOPSINT virtfsrwops_size(SDL_RWops *const rw)
+RWOPSINT VirtFs::rwops_size(SDL_RWops *const rw)
{
VirtFile *const handle = static_cast<VirtFile *const>(
rw->hidden.unknown.data1);
return VirtFs::fileLength(handle);
-} /* virtfsrwops_size */
+} /* VirtFs::rwops_size */
#endif // USE_SDL2
-static SDL_RWops *create_rwops(VirtFile *const file)
+SDL_RWops *VirtFs::create_rwops(VirtFile *const file)
{
SDL_RWops *retval = nullptr;
if (!file)
{
- logger->assertLog("virtfsrwops_seek: create rwops error.");
+ logger->assertLog("VirtFs::rwops_seek: create rwops error.");
}
else
{
@@ -220,31 +212,31 @@ static SDL_RWops *create_rwops(VirtFile *const file)
if (retval)
{
#ifdef USE_SDL2
- retval->size = &virtfsrwops_size;
+ retval->size = &VirtFs::rwops_size;
#endif // USE_SDL2
- retval->seek = &virtfsrwops_seek;
- retval->read = &virtfsrwops_read;
- retval->write = &virtfsrwops_write;
- retval->close = &virtfsrwops_close;
+ retval->seek = &VirtFs::rwops_seek;
+ retval->read = &VirtFs::rwops_read;
+ retval->write = &VirtFs::rwops_write;
+ retval->close = &VirtFs::rwops_close;
retval->hidden.unknown.data1 = file;
} /* if */
} /* else */
return retval;
-} /* create_rwops */
+} /* VirtFs::create_rwops */
-SDL_RWops *VirtFs::MakeRWops(VirtFile *const handle)
+SDL_RWops *VirtFs::makeRwops(VirtFile *const handle)
{
SDL_RWops *retval = nullptr;
if (!handle)
{
- logger->assertLog("virtfsrwops_seek: NULL pointer passed to "
+ logger->assertLog("VirtFs::rwops_seek: NULL pointer passed to "
"RWopsmakeRWops().");
}
else
{
- retval = create_rwops(handle);
+ retval = VirtFs::create_rwops(handle);
}
return retval;
@@ -261,7 +253,7 @@ static bool checkFilePath(const std::string &restrict fname)
}
#endif // __APPLE__
-SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname)
+SDL_RWops *VirtFs::rwopsOpenRead(const std::string &restrict fname)
{
BLOCK_START("RWopsopenRead")
#ifdef __APPLE__
@@ -274,34 +266,34 @@ SDL_RWops *VirtFs::RWopsOpenRead(const std::string &restrict fname)
#endif // USE_FUZZER
#ifdef USE_PROFILER
- SDL_RWops *const ret = create_rwops(VirtFs::openRead(fname));
+ SDL_RWops *const ret = VirtFs::create_rwops(VirtFs::openRead(fname));
BLOCK_END("RWopsopenRead")
return ret;
#else // USE_PROFILER
- return create_rwops(VirtFs::openRead(fname));
+ return VirtFs::create_rwops(VirtFs::openRead(fname));
#endif // USE_PROFILER
} /* RWopsopenRead */
-SDL_RWops *VirtFs::RWopsOpenWrite(const std::string &restrict fname)
+SDL_RWops *VirtFs::rwopsOpenWrite(const std::string &restrict fname)
{
#ifdef __APPLE__
if (!checkFilePath(fname))
return nullptr;
#endif // __APPLE__
- return create_rwops(VirtFs::openWrite(fname));
+ return VirtFs::create_rwops(VirtFs::openWrite(fname));
} /* RWopsopenWrite */
-SDL_RWops *VirtFs::RWopsOpenAppend(const std::string &restrict fname)
+SDL_RWops *VirtFs::rwopsOpenAppend(const std::string &restrict fname)
{
#ifdef __APPLE__
if (!checkFilePath(fname))
return nullptr;
#endif // __APPLE__
- return create_rwops(VirtFs::openAppend(fname));
+ return VirtFs::create_rwops(VirtFs::openAppend(fname));
} /* RWopsopenAppend */
/* end of virtfsrwops.c ... */
diff --git a/src/fs/virtfs/virtfsrwops.h b/src/fs/virtfs/virtfsrwops.h
index 56fda969d..46d5acca0 100644
--- a/src/fs/virtfs/virtfsrwops.h
+++ b/src/fs/virtfs/virtfsrwops.h
@@ -50,15 +50,40 @@
#include <string>
#include <SDL_rwops.h>
+#ifdef USE_SDL2
+#define RWOPSINT int64_t
+#define RWOPSSIZE size_t
+#else // USE_SDL2
+#define RWOPSINT int32_t
+#define RWOPSSIZE int
+#endif // USE_SDL2
+
struct VirtFile;
namespace VirtFs
{
- SDL_RWops *RWopsOpenRead(const std::string &restrict fname);
- SDL_RWops *RWopsOpenWrite(const std::string &restrict fname) A_WARN_UNUSED;
- SDL_RWops *RWopsOpenAppend(const std::string &restrict fname)
+ SDL_RWops *create_rwops(VirtFile *const file);
+ RWOPSINT rwops_seek(SDL_RWops *const rw,
+ const RWOPSINT offset,
+ const int whence);
+ RWOPSSIZE rwops_read(SDL_RWops *const rw,
+ void *const ptr,
+ const RWOPSSIZE size,
+ const RWOPSSIZE maxnum);
+ RWOPSSIZE rwops_write(SDL_RWops *const rw,
+ const void *const ptr,
+ const RWOPSSIZE size,
+ const RWOPSSIZE num);
+ int rwops_close(SDL_RWops *const rw);
+#ifdef USE_SDL2
+ RWOPSINT rwops_size(SDL_RWops *const rw);
+#endif // USE_SDL2
+
+ SDL_RWops *rwopsOpenRead(const std::string &restrict fname);
+ SDL_RWops *rwopsOpenWrite(const std::string &restrict fname) A_WARN_UNUSED;
+ SDL_RWops *rwopsOpenAppend(const std::string &restrict fname)
A_WARN_UNUSED;
- SDL_RWops *MakeRWops(VirtFile *const handle) A_WARN_UNUSED;
+ SDL_RWops *makeRwops(VirtFile *const handle) A_WARN_UNUSED;
} // namespace VirtFs
#endif // SRC_FS_VIRTFSRWOPS_H
diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp
index 916c0b9a2..c4af92717 100644
--- a/src/gui/fonts/font.cpp
+++ b/src/gui/fonts/font.cpp
@@ -189,7 +189,7 @@ TTF_Font *Font::openFont(const char *const name,
{
// disabled for now because some systems can't use it. why?
// #ifdef USE_SDL2
-// SDL_RWops *const rw = VirtFs::RWopsOpenRead(name);
+// SDL_RWops *const rw = VirtFs::rwopsOpenRead(name);
// if (!rw)
// return nullptr;
// return TTF_OpenFontIndexRW(rw, 1, size, 0);
diff --git a/src/integrity_unittest.cc b/src/integrity_unittest.cc
index 0459d3018..34312b7b3 100644
--- a/src/integrity_unittest.cc
+++ b/src/integrity_unittest.cc
@@ -236,7 +236,7 @@ TEST_CASE("integrity tests", "integrity")
{
VirtFs::mountZip(prefix + "data/test/test.zip", Append_false);
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(name1);
REQUIRE(rw != nullptr);
unsigned char buf[size1];
const size_t sz = SDL_RWread(rw, buf, 1, size1);
@@ -254,7 +254,7 @@ TEST_CASE("integrity tests", "integrity")
{
VirtFs::mountZip(prefix + "data/test/test.zip", Append_false);
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(name1);
REQUIRE(rw != nullptr);
int64_t seek = SDL_RWseek(rw, 0, RW_SEEK_END);
if (seek == -1)
@@ -289,7 +289,7 @@ TEST_CASE("integrity tests", "integrity")
{
VirtFs::mountZip(prefix + "data/test/test.zip", Append_false);
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(name1);
REQUIRE(rw != nullptr);
if (IMG_isPNG(rw) == false)
{
@@ -307,7 +307,7 @@ TEST_CASE("integrity tests", "integrity")
{
VirtFs::mountZip(prefix + "data/test/test.zip", Append_false);
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(name1);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(name1);
REQUIRE(rw != nullptr);
Resource *const res = imageHelper->load(rw);
VirtFs::unmountZip(prefix + "data/test/test.zip");
diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp
index 249900c56..b9107a757 100644
--- a/src/resources/atlas/atlasmanager.cpp
+++ b/src/resources/atlas/atlasmanager.cpp
@@ -149,7 +149,7 @@ void AtlasManager::loadImages(const StringVect &files,
path = path.substr(0, p);
}
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(path);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(path);
if (rw)
{
Image *const image = d ? surfaceImageHelper->load(rw, *d)
diff --git a/src/resources/loaders/imageloader.cpp b/src/resources/loaders/imageloader.cpp
index 1a1805330..2bfba2706 100644
--- a/src/resources/loaders/imageloader.cpp
+++ b/src/resources/loaders/imageloader.cpp
@@ -63,7 +63,7 @@ namespace
d = new Dye(path1.substr(p + 1));
path1 = path1.substr(0, p);
}
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(path1);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(path1);
if (!rw)
{
delete d;
diff --git a/src/resources/loaders/musicloader.cpp b/src/resources/loaders/musicloader.cpp
index f1114b210..f23a9fc70 100644
--- a/src/resources/loaders/musicloader.cpp
+++ b/src/resources/loaders/musicloader.cpp
@@ -46,7 +46,7 @@ namespace
return nullptr;
const ResourceLoader *const
rl = static_cast<const ResourceLoader *const>(v);
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(rl->path);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(rl->path);
if (!rw)
{
reportAlways("Error loading resource: %s",
diff --git a/src/resources/loaders/soundloader.cpp b/src/resources/loaders/soundloader.cpp
index b3429b20e..be71a5ddb 100644
--- a/src/resources/loaders/soundloader.cpp
+++ b/src/resources/loaders/soundloader.cpp
@@ -46,7 +46,7 @@ namespace
return nullptr;
const ResourceLoader *const
rl = static_cast<const ResourceLoader *const>(v);
- SDL_RWops *const rw = VirtFs::RWopsOpenRead(rl->path);
+ SDL_RWops *const rw = VirtFs::rwopsOpenRead(rl->path);
if (!rw)
{
reportAlways("Error loading resource: %s",
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index 133c897fd..b05091ddd 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -432,7 +432,7 @@ PRAGMA45(GCC diagnostic pop)
int TestLauncher::testDye()
{
- SDL_RWops *rw = VirtFs::RWopsOpenRead(
+ SDL_RWops *rw = VirtFs::rwopsOpenRead(
"graphics/sprites/arrow_up.png");
Dye *d = nullptr;
@@ -455,7 +455,7 @@ int TestLauncher::testDye()
settings.tempDir + "/testimage2.png");
}
- rw = VirtFs::RWopsOpenRead(
+ rw = VirtFs::rwopsOpenRead(
"graphics/sprites/arrow_up.png");
d = new Dye("S:#0000ff,00ff00,5c5cff,ff0000");
image = surfaceImageHelper->load(rw, *d);