Update buffer.

This commit is contained in:
lzwdgc 2018-06-22 01:50:38 +03:00
parent 8933e1203e
commit 4515228ca6
7 changed files with 24 additions and 19 deletions

View file

@ -100,14 +100,14 @@ buffer::buffer(const buffer &rhs, uint32_t size, uint32_t offset)
std::string buffer::read_string(uint32_t blocksize) const std::string buffer::read_string(uint32_t blocksize) const
{ {
std::vector<uint8_t> data(blocksize); std::vector<uint8_t> data(blocksize);
read(data.data(), data.size()); _read(data.data(), data.size());
return (const char *)data.data(); return (const char *)data.data();
} }
std::wstring buffer::read_wstring(uint32_t blocksize) const std::wstring buffer::read_wstring(uint32_t blocksize) const
{ {
std::vector<uint16_t> data(blocksize); std::vector<uint16_t> data(blocksize);
read(data.data(), data.size()); _read(data.data(), data.size());
return (const wchar_t *)data.data(); return (const wchar_t *)data.data();
} }

View file

@ -23,8 +23,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#define READ(b, var) b.read(&var) #define READ(b, var) b.read(var)
#define READ_N(b, var, sz) b.read(&var, sz) #define READ_N(b, var, sz) b.read(var, sz)
#define READ_STRING(b, var) var = b.read_string() #define READ_STRING(b, var) var = b.read_string()
#define READ_STRING_N(b, var, sz) var = b.read_string(sz) #define READ_STRING_N(b, var, sz) var = b.read_string(sz)
@ -50,9 +50,9 @@ public:
buffer(const buffer &rhs, uint32_t size, uint32_t offset); buffer(const buffer &rhs, uint32_t size, uint32_t offset);
template <typename T> template <typename T>
uint32_t read(T *dst, uint32_t size = 1) const uint32_t read(T &dst, uint32_t size = 1) const
{ {
return _read((void *)dst, size * sizeof(T), 0); return _read((void *)&dst, size * sizeof(T), 0);
} }
std::string read_string(uint32_t blocksize = 0x20) const; std::string read_string(uint32_t blocksize = 0x20) const;
std::wstring read_wstring(uint32_t blocksize = 0x20) const; std::wstring read_wstring(uint32_t blocksize = 0x20) const;
@ -102,16 +102,16 @@ public:
void read_vector(std::vector<T> &v) const void read_vector(std::vector<T> &v) const
{ {
SizeType n = 0; SizeType n = 0;
read(&n); read(n);
read_vector<T, SizeType>(v, n); read_vector<T, SizeType>(v, n);
} }
std::string read_pascal_string() const std::string read_pascal_string() const
{ {
uint32_t n = 0; uint32_t n = 0;
read(&n); read(n);
std::string s(n, 0); std::string s(n, 0);
read(s.data(), n); _read(s.data(), n);
return s; return s;
} }
@ -128,6 +128,9 @@ public:
const uint8_t *getPtr() const { return ptr; } const uint8_t *getPtr() const { return ptr; }
uint32_t _read(void *dst, uint32_t size, uint32_t offset = 0) const;
uint32_t _write(const void *src, uint32_t size);
private: private:
std::shared_ptr<std::vector<uint8_t>> buf_; std::shared_ptr<std::vector<uint8_t>> buf_;
mutable uint32_t index_ = 0; mutable uint32_t index_ = 0;
@ -135,7 +138,4 @@ private:
mutable uint32_t data_offset = 0; mutable uint32_t data_offset = 0;
mutable uint32_t size_ = 0; mutable uint32_t size_ = 0;
uint32_t end_; uint32_t end_;
uint32_t _read(void *dst, uint32_t size, uint32_t offset = 0) const;
uint32_t _write(const void *src, uint32_t size);
}; };

View file

@ -27,6 +27,7 @@
#include <primitives/executor.h> #include <primitives/executor.h>
#include <algorithm> #include <algorithm>
#include <fstream>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <math.h> #include <math.h>
@ -299,7 +300,7 @@ try
// to check correctness // to check correctness
process_lang(*storage.get(), d / "ru", &polygon4::LocalizedString::ru); process_lang(*storage.get(), d / "ru", &polygon4::LocalizedString::ru);
for (auto &f : boost::make_iterator_range(fs::directory_iterator(d), {})) for (auto &f : fs::directory_iterator(d))
{ {
if (!fs::is_directory(f)) if (!fs::is_directory(f))
continue; continue;

View file

@ -80,14 +80,14 @@ std::string translate(const std::string &s)
template <typename T> template <typename T>
void aim_vector3<T>::load(const buffer &b) void aim_vector3<T>::load(const buffer &b)
{ {
READ(b, x); READ(b, base::x);
READ(b, z); READ(b, base::z);
READ(b, y); READ(b, base::y);
} }
void aim_vector4::load(const buffer &b, uint32_t flags) void aim_vector4::load(const buffer &b, uint32_t flags)
{ {
aim_vector3::load(b); base::load(b);
if (flags & F_USE_W_COORDINATE) if (flags & F_USE_W_COORDINATE)
READ(b, w); READ(b, w);
} }

View file

@ -80,11 +80,15 @@ enum class MaterialType : uint32_t
template <typename T> template <typename T>
struct aim_vector3 : vector3<T> struct aim_vector3 : vector3<T>
{ {
using base = vector3<T>;
void load(const buffer &b); void load(const buffer &b);
}; };
struct aim_vector4 : aim_vector3<float> struct aim_vector4 : aim_vector3<float>
{ {
using base = aim_vector3<float>;
float w = 1.0f; float w = 1.0f;
std::string print() const; std::string print() const;

View file

@ -158,7 +158,7 @@ struct screen_segment : public segment
void load(const buffer &b) void load(const buffer &b)
{ {
b.read((uint8_t*)screenshot.getData().data(), screenshot.getBytesLength()); b._read((uint8_t*)screenshot.getData().data(), screenshot.getBytesLength());
// rows should be swapped now: bottom is the first row etc. // rows should be swapped now: bottom is the first row etc.
} }
}; };

View file

@ -55,7 +55,7 @@ void convert(const path &fn)
READ(src, width); READ(src, width);
READ(src, height); READ(src, height);
src.seek(0x10); src.seek(0x10);
src.read(&dxt5_flag, 1); src._read(&dxt5_flag, 1);
src.seek(0x4C); src.seek(0x4C);
auto s = fn.string() + ".bmp"; auto s = fn.string() + ".bmp";