1
0
forked from 0ad/0ad

Fix 204b04f2d4 compatibility with zipped mods, refs #5018.

Differential Revision: https://code.wildfiregames.com/D1480
Reviewed By: Itms
This was SVN commit r21814.
This commit is contained in:
elexis 2018-05-01 21:15:55 +00:00
parent b0ca04b555
commit 16fbe90342
4 changed files with 34 additions and 9 deletions

View File

@ -25,6 +25,7 @@
#include "lib/external_libraries/libsdl.h"
#include "lib/status.h"
#include "lib/timer.h"
#include "lib/file/vfs/vfs_path.h"
#include "maths/MathUtil.h"
#include "ps/CLogger.h"
#include "ps/FileIo.h"
@ -32,6 +33,10 @@
#include "ps/scripting/JSInterface_VFS.h"
#include "scriptinterface/ScriptRuntime.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include <string>
#include <vector>
// TODO: what's a good default? perhaps based on map size
#define RMS_RUNTIME_SIZE 96 * 1024 * 1024
@ -294,12 +299,8 @@ bool CMapGeneratorWorker::LoadScripts(const std::wstring& libraryName)
JS::Value CMapGeneratorWorker::LoadHeightmap(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& vfsPath)
{
OsPath realPath;
if (g_VFS->GetRealPath(vfsPath, realPath) != INFO::OK)
return JS::UndefinedValue();
std::vector<u16> heightmap;
if (LoadHeightmapImage(realPath, heightmap) != INFO::OK)
if (LoadHeightmapImageVfs(vfsPath, heightmap) != INFO::OK)
{
LOGERROR("Could not load heightmap file '%s'", utf8_from_wstring(vfsPath).c_str());
return JS::UndefinedValue();

View File

@ -21,12 +21,29 @@
#include "graphics/Patch.h"
#include "lib/file/file.h"
#include "lib/file/vfs/vfs_path.h"
#include "lib/os_path.h"
#include "lib/status.h"
#include "lib/tex/tex.h"
#include "maths/MathUtil.h"
#include "ps/Filesystem.h"
Status LoadHeightmapImage(const OsPath& filepath, std::vector<u16>& heightmap)
#include <algorithm>
#include <vector>
Status ParseHeightmapImage(const shared_ptr<u8>& fileData, size_t fileSize, std::vector<u16>& heightmap);
Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector<u16>& heightmap)
{
shared_ptr<u8> fileData;
size_t fileSize;
RETURN_STATUS_IF_ERR(g_VFS->LoadFile(filepath, fileData, fileSize));
return ParseHeightmapImage(fileData, fileSize, heightmap);
}
Status LoadHeightmapImageOs(const OsPath& filepath, std::vector<u16>& heightmap)
{
File file;
RETURN_STATUS_IF_ERR(file.Open(OsString(filepath), O_RDONLY));
@ -35,11 +52,16 @@ Status LoadHeightmapImage(const OsPath& filepath, std::vector<u16>& heightmap)
lseek(file.Descriptor(), 0, SEEK_SET);
shared_ptr<u8> fileData = shared_ptr<u8>(new u8[fileSize]);
Status readvalue = read(file.Descriptor(), fileData.get(), fileSize);
file.Close();
RETURN_STATUS_IF_ERR(readvalue);
return ParseHeightmapImage(fileData, fileSize, heightmap);
}
Status ParseHeightmapImage(const shared_ptr<u8>& fileData, size_t fileSize, std::vector<u16>& heightmap)
{
// Decode to a raw pixel format
Tex tex;
RETURN_STATUS_IF_ERR(tex.decode(fileData, fileSize));

View File

@ -18,11 +18,13 @@
#ifndef INCLUDED_MAPIO
#define INCLUDED_MAPIO
#include "lib/file/vfs/vfs_path.h"
#include "lib/os_path.h"
#include "lib/status.h"
// Opens the given texture file and stores it in a one-dimensional u16 vector.
Status LoadHeightmapImage(const OsPath& filepath, std::vector<u16>& heightmap);
Status LoadHeightmapImageVfs(const VfsPath& filepath, std::vector<u16>& heightmap);
Status LoadHeightmapImageOs(const OsPath& filepath, std::vector<u16>& heightmap);
class CMapIO
{

View File

@ -169,7 +169,7 @@ MESSAGEHANDLER(LoadMap)
MESSAGEHANDLER(ImportHeightmap)
{
std::vector<u16> heightmap_source;
if (LoadHeightmapImage(*msg->filename, heightmap_source) != INFO::OK)
if (LoadHeightmapImageOs(*msg->filename, heightmap_source) != INFO::OK)
{
LOGERROR("Failed to decode heightmap.");
return;