mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Uses span for vfs instead of passing shared_ptr
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -336,7 +336,7 @@ public:
|
||||
return m_file->Pathname();
|
||||
}
|
||||
|
||||
Status Load(const OsPath& /*name*/, const std::shared_ptr<u8>& buf, size_t size) const override
|
||||
Status Load(const OsPath& /*name*/, const std::span<u8> buffer) const override
|
||||
{
|
||||
AdjustOffset();
|
||||
|
||||
@@ -354,7 +354,7 @@ public:
|
||||
}
|
||||
|
||||
Stream stream(codec);
|
||||
stream.SetOutputBuffer(buf.get(), size);
|
||||
stream.SetOutputBuffer(buffer.data(), buffer.size());
|
||||
io::Operation op(*m_file.get(), 0, m_csize, m_ofs);
|
||||
StreamFeeder streamFeeder(stream);
|
||||
RETURN_STATUS_IF_ERR(io::Run(op, io::Parameters(), streamFeeder));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
|
||||
struct IFileLoader
|
||||
{
|
||||
@@ -38,7 +39,7 @@ struct IFileLoader
|
||||
virtual wchar_t LocationCode() const = 0;
|
||||
virtual const OsPath& Path() const = 0;
|
||||
|
||||
virtual Status Load(const OsPath& name, const std::shared_ptr<u8>& buf, size_t size) const = 0;
|
||||
virtual Status Load(const OsPath& name, const std::span<u8> buffer) const = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<IFileLoader> PIFileLoader;
|
||||
|
||||
@@ -48,9 +48,9 @@ RealDirectory::RealDirectory(const OsPath& path, size_t priority, size_t flags)
|
||||
}
|
||||
|
||||
|
||||
/*virtual*/ Status RealDirectory::Load(const OsPath& name, const std::shared_ptr<u8>& buf, size_t size) const
|
||||
/*virtual*/ Status RealDirectory::Load(const OsPath& name, const std::span<u8> buffer) const
|
||||
{
|
||||
return io::Load(m_path / name, buf.get(), size);
|
||||
return io::Load(m_path / name, buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
Status Load(const OsPath& name, const std::shared_ptr<u8>& buf, size_t size) const override;
|
||||
Status Load(const OsPath& name, const std::span<u8> buffer) const override;
|
||||
|
||||
Status Store(const OsPath& name, std::span<const u8> fileContents);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2025 Wildfire Games.
|
||||
/* Copyright (C) 2026 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
size_t Precedence() const override { return m_Precedence; }
|
||||
wchar_t LocationCode() const override { return L'\0'; }
|
||||
const OsPath& Path() const override { return m_Path; }
|
||||
Status Load(const OsPath& /*name*/, const std::shared_ptr<u8>& /*buf*/, size_t /*size*/) const override
|
||||
Status Load(const OsPath& /*name*/, const std::span<u8>) const override
|
||||
{
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public:
|
||||
size = file->Size();
|
||||
|
||||
RETURN_STATUS_IF_ERR(AllocateAligned(fileContents, size, maxSectorSize));
|
||||
RETURN_STATUS_IF_ERR(file->Loader()->Load(file->Name(), fileContents, file->Size()));
|
||||
RETURN_STATUS_IF_ERR(file->Loader()->Load(file->Name(), {fileContents.get(), file->Size()}));
|
||||
|
||||
stats_io_user_request(size);
|
||||
m_trace->NotifyLoad(pathname, size);
|
||||
|
||||
@@ -208,13 +208,13 @@ public:
|
||||
{
|
||||
std::string buffer;
|
||||
buffer.resize(fileInfo.Size());
|
||||
WARN_IF_ERR(archiveFile->Load("", DummySharedPtr((u8*)buffer.data()), buffer.size()));
|
||||
WARN_IF_ERR(archiveFile->Load("", {reinterpret_cast<u8*>(buffer.data()), buffer.size()}));
|
||||
Script::ParseJSON(Script::Request(m_ScriptInterface), buffer, &m_Metadata);
|
||||
}
|
||||
else if (pathname == L"simulation.dat" && m_SavedState)
|
||||
{
|
||||
m_SavedState->resize(fileInfo.Size());
|
||||
WARN_IF_ERR(archiveFile->Load("", DummySharedPtr((u8*)m_SavedState->data()), m_SavedState->size()));
|
||||
WARN_IF_ERR(archiveFile->Load("", {reinterpret_cast<u8*>(m_SavedState->data()), m_SavedState->size()}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user