mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Remove unneed FileHandle (aka shared_ptr)
This commit is contained in:
parent
0743ac9681
commit
27333efd8c
@ -292,8 +292,7 @@ void GameData::loadHandling(const std::string& path) {
|
||||
SCMFile* GameData::loadSCM(const std::string& path) {
|
||||
auto scm_h = index.openFileRaw(path);
|
||||
SCMFile* scm = new SCMFile;
|
||||
scm->loadFile(scm_h->data, scm_h->length);
|
||||
scm_h.reset();
|
||||
scm->loadFile(scm_h.data, scm_h.length);
|
||||
return scm;
|
||||
}
|
||||
|
||||
@ -371,7 +370,7 @@ void GameData::loadTXD(const std::string& name) {
|
||||
TextureArchive GameData::loadTextureArchive(const std::string& name) {
|
||||
/// @todo refactor loadTXD to use correct file locations
|
||||
auto file = index.openFile(name);
|
||||
if (!file) {
|
||||
if (!file.data) {
|
||||
logger->error("Data", "Failed to open txd: " + name);
|
||||
return {};
|
||||
}
|
||||
@ -397,7 +396,7 @@ void GameData::getNameAndLod(std::string& name, int& lod) {
|
||||
|
||||
ClumpPtr GameData::loadClump(const std::string& name) {
|
||||
auto file = index.openFile(name);
|
||||
if (!file) {
|
||||
if (!file.data) {
|
||||
logger->error("Data", "Failed to load model " + name);
|
||||
return nullptr;
|
||||
}
|
||||
@ -420,7 +419,7 @@ ClumpPtr GameData::loadClump(const std::string& name, const std::string& texture
|
||||
|
||||
void GameData::loadModelFile(const std::string& name) {
|
||||
auto file = index.openFileRaw(name);
|
||||
if (!file) {
|
||||
if (!file.data) {
|
||||
logger->log("Data", Logger::Error, "Failed to load model file " + name);
|
||||
return;
|
||||
}
|
||||
@ -486,7 +485,7 @@ bool GameData::loadModel(ModelID model) {
|
||||
loadTXD(slotname + ".txd");
|
||||
|
||||
auto file = index.openFile(name + ".dff");
|
||||
if (!file) {
|
||||
if (!file.data) {
|
||||
logger->error("Data", "Failed to load model for " +
|
||||
std::to_string(model) + " [" + name + "]");
|
||||
return false;
|
||||
@ -523,9 +522,9 @@ bool GameData::loadModel(ModelID model) {
|
||||
void GameData::loadIFP(const std::string& name) {
|
||||
auto f = index.openFile(name);
|
||||
|
||||
if (f) {
|
||||
if (f.data) {
|
||||
LoaderIFP loader;
|
||||
if (loader.loadFromMemory(f->data)) {
|
||||
if (loader.loadFromMemory(f.data)) {
|
||||
animations.insert(loader.animations.begin(),
|
||||
loader.animations.end());
|
||||
}
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "objects/PickupObject.hpp"
|
||||
#include "objects/VehicleObject.hpp"
|
||||
|
||||
#include "platform/FileHandle.hpp"
|
||||
|
||||
#include "render/ViewCamera.hpp"
|
||||
|
||||
#ifdef RW_WINDOWS
|
||||
@ -695,7 +697,7 @@ void GameWorld::loadCutscene(const std::string& name) {
|
||||
|
||||
CutsceneData* cutscene = new CutsceneData;
|
||||
|
||||
if (datfile) {
|
||||
if (datfile.data) {
|
||||
LoaderCutsceneDAT loaderdat;
|
||||
loaderdat.load(cutscene->tracks, datfile);
|
||||
}
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include "data/CutsceneData.hpp"
|
||||
#include "platform/FileHandle.hpp"
|
||||
|
||||
void LoaderCutsceneDAT::load(CutsceneTracks &tracks, const FileHandle& file) {
|
||||
std::string dataStr(file->data, file->length);
|
||||
void LoaderCutsceneDAT::load(CutsceneTracks &tracks, const FileContentsInfo& file) {
|
||||
std::string dataStr(file.data, file.length);
|
||||
std::stringstream ss(dataStr);
|
||||
|
||||
int numZooms = 0;
|
||||
|
@ -7,7 +7,7 @@ struct CutsceneTracks;
|
||||
|
||||
class LoaderCutsceneDAT {
|
||||
public:
|
||||
void load(CutsceneTracks& tracks, const FileHandle& file);
|
||||
void load(CutsceneTracks& tracks, const FileContentsInfo& file);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include <fonts/GameTexts.hpp>
|
||||
#include <platform/FileHandle.hpp>
|
||||
|
||||
void LoaderGXT::load(GameTexts &texts, const FileHandle &file) {
|
||||
auto data = file->data;
|
||||
void LoaderGXT::load(GameTexts &texts, const FileContentsInfo &file) {
|
||||
auto data = file.data;
|
||||
|
||||
data += 4; // TKEY
|
||||
|
||||
|
@ -6,7 +6,7 @@ class GameTexts;
|
||||
|
||||
class LoaderGXT {
|
||||
public:
|
||||
void load(GameTexts& texts, const FileHandle& file);
|
||||
void load(GameTexts& texts, const FileContentsInfo& file);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -455,10 +455,10 @@ AtomicPtr LoaderDFF::readAtomic(FrameList &framelist,
|
||||
return atomic;
|
||||
}
|
||||
|
||||
ClumpPtr LoaderDFF::loadFromMemory(const FileHandle& file) {
|
||||
ClumpPtr LoaderDFF::loadFromMemory(const FileContentsInfo& file) {
|
||||
auto model = std::make_shared<Clump>();
|
||||
|
||||
RWBStream rootStream(file->data, file->length);
|
||||
RWBStream rootStream(file.data, file.length);
|
||||
|
||||
auto rootID = rootStream.getNextChunk();
|
||||
if (rootID != CHUNK_CLUMP) {
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
using GeometryList = std::vector<GeometryPtr>;
|
||||
using FrameList = std::vector<ModelFramePtr>;
|
||||
|
||||
ClumpPtr loadFromMemory(const FileHandle& file);
|
||||
ClumpPtr loadFromMemory(const FileContentsInfo& file);
|
||||
|
||||
void setTextureLookupCallback(const TextureLookupCallback& tlc) {
|
||||
texturelookup = tlc;
|
||||
|
@ -172,9 +172,9 @@ TextureData::Handle createTexture(RW::BSTextureNative& texNative,
|
||||
transparent);
|
||||
}
|
||||
|
||||
bool TextureLoader::loadFromMemory(const FileHandle& file,
|
||||
bool TextureLoader::loadFromMemory(const FileContentsInfo& file,
|
||||
TextureArchive& inTextures) {
|
||||
auto data = file->data;
|
||||
auto data = file.data;
|
||||
RW::BinaryStreamSection root(data);
|
||||
/*auto texDict =*/root.readStructure<RW::BSTextureDictionary>();
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
class TextureLoader {
|
||||
public:
|
||||
bool loadFromMemory(const FileHandle& file, TextureArchive& inTextures);
|
||||
bool loadFromMemory(const FileContentsInfo& file, TextureArchive& inTextures);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,6 @@
|
||||
#ifndef _LIBRW_FILEHANDLE_HPP_
|
||||
#define _LIBRW_FILEHANDLE_HPP_
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Contains a pointer to a file's contents.
|
||||
|
@ -50,7 +50,7 @@ rwfs::path FileIndex::findFilePath(const std::string &filePath) const {
|
||||
return getIndexedDataAt(filePath)->path;
|
||||
}
|
||||
|
||||
FileHandle FileIndex::openFileRaw(const std::string &filePath) const {
|
||||
FileContentsInfo FileIndex::openFileRaw(const std::string &filePath) const {
|
||||
const auto *indexData = getIndexedDataAt(filePath);
|
||||
std::ifstream dfile(indexData->path, std::ios::binary);
|
||||
if (!dfile.is_open()) {
|
||||
@ -69,7 +69,7 @@ FileHandle FileIndex::openFileRaw(const std::string &filePath) const {
|
||||
auto data = new char[length];
|
||||
dfile.read(data, length);
|
||||
|
||||
return std::make_shared<FileContentsInfo>(data, length);
|
||||
return {data, static_cast<size_t>(length)};
|
||||
}
|
||||
|
||||
void FileIndex::indexArchive(const std::string &archive) {
|
||||
@ -91,11 +91,12 @@ void FileIndex::indexArchive(const std::string &archive) {
|
||||
}
|
||||
}
|
||||
|
||||
FileHandle FileIndex::openFile(const std::string &filePath) {
|
||||
FileContentsInfo FileIndex::openFile(const std::string &filePath) {
|
||||
auto cleanFilePath = normalizeFilePath(filePath);
|
||||
auto indexedDataPos = indexedData_.find(cleanFilePath);
|
||||
|
||||
if (indexedDataPos == indexedData_.end()) {
|
||||
return nullptr;
|
||||
return {nullptr, 0};
|
||||
}
|
||||
|
||||
const auto &indexedData = indexedDataPos->second;
|
||||
@ -129,9 +130,5 @@ FileHandle FileIndex::openFile(const std::string &filePath) {
|
||||
dfile.read(data, length);
|
||||
}
|
||||
|
||||
if (data == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_shared<FileContentsInfo>(data, length);
|
||||
return {data, length};
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
* @return FileHandle to the file
|
||||
* @throws if this FileIndex has not indexed the path
|
||||
*/
|
||||
FileHandle openFileRaw(const std::string &filePath) const;
|
||||
FileContentsInfo openFileRaw(const std::string &filePath) const;
|
||||
|
||||
/**
|
||||
* Adds the files contained within the given Archive file to the
|
||||
@ -54,7 +54,7 @@ public:
|
||||
* @param filePath name of the file to open
|
||||
* @return FileHandle to the file, nullptr if this FileINdexed has not indexed the path
|
||||
*/
|
||||
FileHandle openFile(const std::string &filePath);
|
||||
FileContentsInfo openFile(const std::string &filePath);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -16,7 +16,6 @@ class Clump;
|
||||
|
||||
// Pointer types
|
||||
using AnimationPtr = std::shared_ptr<Animation>;
|
||||
using FileHandle = std::shared_ptr<FileContentsInfo>;
|
||||
using ModelFramePtr = std::shared_ptr<ModelFrame>;
|
||||
using GeometryPtr = std::shared_ptr<Geometry>;
|
||||
using AtomicPtr = std::shared_ptr<Atomic>;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <engine/Animator.hpp>
|
||||
#include <fstream>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <platform/FileHandle.hpp>
|
||||
#include <widgets/ModelFramesWidget.hpp>
|
||||
#include "ViewerWidget.hpp"
|
||||
|
||||
@ -47,7 +48,7 @@ void ModelViewer::showObject(uint16_t object) {
|
||||
});
|
||||
|
||||
auto file = world()->data->index.openFile(modelName);
|
||||
if (!file) {
|
||||
if (!file.data) {
|
||||
RW_ERROR("Couldn't load " << modelName);
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <data/CutsceneData.hpp>
|
||||
#include <loaders/LoaderCutsceneDAT.hpp>
|
||||
#include <platform/FileHandle.hpp>
|
||||
#include "test_Globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(CutsceneTests)
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <platform/FileHandle.hpp>
|
||||
#include <platform/FileIndex.hpp>
|
||||
#include "test_Globals.hpp"
|
||||
|
||||
@ -50,7 +51,7 @@ BOOST_AUTO_TEST_CASE(test_openFile) {
|
||||
index.indexTree(Global::getGamePath() + "/data");
|
||||
|
||||
auto handle = index.openFile("cullzone.dat");
|
||||
BOOST_CHECK(handle != nullptr);
|
||||
BOOST_CHECK(handle.data != nullptr);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_indexArchive) {
|
||||
@ -59,14 +60,14 @@ BOOST_AUTO_TEST_CASE(test_indexArchive) {
|
||||
|
||||
{
|
||||
auto handle = index.openFile("landstal.dff");
|
||||
BOOST_CHECK(handle == nullptr);
|
||||
BOOST_CHECK(handle.data == nullptr);
|
||||
}
|
||||
|
||||
index.indexArchive("models/gta3.img");
|
||||
|
||||
{
|
||||
auto handle = index.openFile("landstal.dff");
|
||||
BOOST_CHECK(handle != nullptr);
|
||||
BOOST_CHECK(handle.data != nullptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <data/Clump.hpp>
|
||||
#include <platform/FileHandle.hpp>
|
||||
#include "test_Globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LoaderDFFTests)
|
||||
|
@ -10,7 +10,7 @@ BOOST_AUTO_TEST_CASE(iterate_stream_test) {
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("landstal.dff");
|
||||
|
||||
RWBStream stream(d->data, d->length);
|
||||
RWBStream stream(d.data, d.length);
|
||||
|
||||
RWBStream::ChunkID id = stream.getNextChunk();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <engine/ScreenText.hpp>
|
||||
#include <fonts/GameTexts.hpp>
|
||||
#include <loaders/LoaderGXT.hpp>
|
||||
#include <platform/FileHandle.hpp>
|
||||
#include "test_Globals.hpp"
|
||||
|
||||
#define T(x) GameStringUtil::fromString(x, FONT_PRICEDOWN)
|
||||
|
Loading…
Reference in New Issue
Block a user