mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 18:32:44 +01:00
clang-format files in rwengine/src
This commit is contained in:
parent
7b7e65e002
commit
36a2c57d91
@ -1,14 +1,12 @@
|
||||
#include <BinaryStream.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace RW
|
||||
{
|
||||
namespace RW {
|
||||
|
||||
std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string& filename)
|
||||
{
|
||||
std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string &filename) {
|
||||
std::ifstream dfile(filename, std::ios_base::binary);
|
||||
if (!dfile.is_open()) {
|
||||
std::cerr << "Error opening file " << filename << std::endl;
|
||||
@ -32,7 +30,8 @@ std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string& filename)
|
||||
|
||||
size_t offset = 0;
|
||||
while (offset < length) {
|
||||
nativeSectionHeader_t *sectionHeader = reinterpret_cast<nativeSectionHeader_t *>(data + offset);
|
||||
nativeSectionHeader_t *sectionHeader =
|
||||
reinterpret_cast<nativeSectionHeader_t *>(data + offset);
|
||||
sectionHeader_t *sec = new sectionHeader_t;
|
||||
sec->ID = sectionHeader->ID;
|
||||
sec->size = sectionHeader->size;
|
||||
@ -47,9 +46,10 @@ std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string& filename)
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "Section " << std::hex << sectionHeader->ID
|
||||
<< " (" << sectionIdString(sectionHeader->ID) << ")"
|
||||
<< " - " << std::dec << sectionHeader->size << " bytes" << std::endl;
|
||||
std::cout << "Section " << std::hex << sectionHeader->ID << " ("
|
||||
<< sectionIdString(sectionHeader->ID) << ")"
|
||||
<< " - " << std::dec << sectionHeader->size << " bytes"
|
||||
<< std::endl;
|
||||
/*
|
||||
std::cout << "Offset " << std::hex << offset << std::endl;
|
||||
*/
|
||||
@ -59,10 +59,12 @@ std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string& filename)
|
||||
case STRUCT:
|
||||
bytesOfData = sectionHeader->size;
|
||||
sec->data = new uint8_t[bytesOfData];
|
||||
memcpy(sec->data, data + offset + sizeof(nativeSectionHeader_t), bytesOfData);
|
||||
memcpy(sec->data, data + offset + sizeof(nativeSectionHeader_t),
|
||||
bytesOfData);
|
||||
break;
|
||||
}
|
||||
// std::cout << "It has " << std::dec << bytesOfData << " bytes of data!" << std::endl;
|
||||
// std::cout << "It has " << std::dec << bytesOfData << " bytes of
|
||||
// data!" << std::endl;
|
||||
offset += sizeof(nativeSectionHeader_t) + bytesOfData;
|
||||
|
||||
// std::cout << std::endl;
|
||||
@ -75,15 +77,18 @@ std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string& filename)
|
||||
return BS;
|
||||
}
|
||||
|
||||
std::string BinaryStream::sectionIdString(uint32_t id)
|
||||
{
|
||||
std::string BinaryStream::sectionIdString(uint32_t id) {
|
||||
switch (id) {
|
||||
case STRUCT: return "STRUCT";
|
||||
case EXTENSION: return "EXTENSION";
|
||||
case TEXTURE_NATIVE: return "TEXTURE_NATIVE";
|
||||
case TEXTURE_DICTIONARY: return "TEXTURE_DICTIONARY";
|
||||
default: return "UNKNOWN";
|
||||
case STRUCT:
|
||||
return "STRUCT";
|
||||
case EXTENSION:
|
||||
return "EXTENSION";
|
||||
case TEXTURE_NATIVE:
|
||||
return "TEXTURE_NATIVE";
|
||||
case TEXTURE_DICTIONARY:
|
||||
return "TEXTURE_DICTIONARY";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,21 +2,19 @@
|
||||
#ifndef _BINARYSTREAM_HPP_
|
||||
#define _BINARYSTREAM_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace RW
|
||||
{
|
||||
namespace RW {
|
||||
|
||||
class BinaryStream
|
||||
{
|
||||
class BinaryStream {
|
||||
private:
|
||||
struct nativeSectionHeader_t
|
||||
{
|
||||
struct nativeSectionHeader_t {
|
||||
uint32_t ID;
|
||||
uint32_t size;
|
||||
uint32_t version;
|
||||
};
|
||||
|
||||
public:
|
||||
enum {
|
||||
STRUCT = 0x0001,
|
||||
@ -38,7 +36,6 @@ public:
|
||||
|
||||
static std::string sectionIdString(uint32_t id);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,22 +1,19 @@
|
||||
#include <TextureArchive.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
namespace RW
|
||||
{
|
||||
namespace RW {
|
||||
|
||||
std::unique_ptr<TextureArchive> TextureArchive::create(BinaryStream &binaryStream)
|
||||
{
|
||||
std::unique_ptr<TextureArchive> TextureArchive::create(
|
||||
BinaryStream &binaryStream) {
|
||||
auto textureArchive = std::unique_ptr<TextureArchive>(new TextureArchive);
|
||||
|
||||
auto section = binaryStream.rootHeader;
|
||||
|
||||
assert(
|
||||
section->ID == BinaryStream::TEXTURE_DICTIONARY
|
||||
&& "BinaryStream passed to this function must be a TEXTURE DICTIONARY"
|
||||
);
|
||||
assert(section->ID == BinaryStream::TEXTURE_DICTIONARY &&
|
||||
"BinaryStream passed to this function must be a TEXTURE DICTIONARY");
|
||||
|
||||
// Struct
|
||||
section = section->next;
|
||||
@ -29,14 +26,20 @@ std::unique_ptr<TextureArchive> TextureArchive::create(BinaryStream &binaryStrea
|
||||
Texture texture = *reinterpret_cast<Texture *>(section->data);
|
||||
|
||||
if (texture.header.rasterFormat & 0x2000) {
|
||||
memcpy(texture.body.palette, section->data + sizeof(TextureHeader) - 4, 1024);
|
||||
memcpy(texture.body.palette,
|
||||
section->data + sizeof(TextureHeader) - 4, 1024);
|
||||
|
||||
texture.body.pixels = new uint8_t[texture.header.width * texture.header.height];
|
||||
memcpy(texture.body.pixels, section->data + sizeof(TextureHeader) + 1024, texture.header.width * texture.header.height);
|
||||
texture.body.pixels =
|
||||
new uint8_t[texture.header.width * texture.header.height];
|
||||
memcpy(texture.body.pixels,
|
||||
section->data + sizeof(TextureHeader) + 1024,
|
||||
texture.header.width * texture.header.height);
|
||||
} else {
|
||||
size_t bufSize = texture.header.width * texture.header.height * texture.header.bpp/8;
|
||||
size_t bufSize = texture.header.width * texture.header.height *
|
||||
texture.header.bpp / 8;
|
||||
texture.body.pixels = new uint8_t[bufSize];
|
||||
memcpy(texture.body.pixels, section->data + sizeof(TextureHeader), bufSize);
|
||||
memcpy(texture.body.pixels, section->data + sizeof(TextureHeader),
|
||||
bufSize);
|
||||
}
|
||||
|
||||
textureArchive->textures.push_back(texture);
|
||||
@ -46,5 +49,4 @@ std::unique_ptr<TextureArchive> TextureArchive::create(BinaryStream &binaryStrea
|
||||
|
||||
return textureArchive;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,11 +6,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace RW
|
||||
{
|
||||
namespace RW {
|
||||
|
||||
class TextureArchive
|
||||
{
|
||||
class TextureArchive {
|
||||
public:
|
||||
struct TextureHeader {
|
||||
uint32_t platformID;
|
||||
@ -38,13 +36,11 @@ public:
|
||||
TextureBody body;
|
||||
};
|
||||
|
||||
|
||||
size_t numTextures;
|
||||
std::vector<Texture> textures;
|
||||
|
||||
static std::unique_ptr<TextureArchive> create(BinaryStream &binaryStream);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user