1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-10-06 09:07:19 +02:00

rwlib: iwyu: reduce warnings

- use mapping file
- forward define FileContentsInfo, CutsceneTracks, GameTexts
- no more "#pragma once"
- add mapping file
This commit is contained in:
Anonymous Maarten 2017-10-30 23:44:40 +01:00 committed by Daniel Evans
parent bb09015cad
commit 90acef28f7
34 changed files with 171 additions and 97 deletions

View File

@ -116,10 +116,12 @@ if(CHECK_INCLUDES)
endif()
function(openrw_target_apply_options)
set(IWYU_MAPPING "${PROJECT_SOURCE_DIR}/openrw_iwyu.imp")
cmake_parse_arguments("OPENRW_APPLY" "" "TARGET" "" ${ARGN})
if(CHECK_INCLUDES)
iwyu_check(TARGET "${OPENRW_APPLY_TARGET}"
EXTRA_OPTS
"--mapping_file=${IWYU_MAPPING}"
)
endif()
endfunction()

14
openrw_iwyu.imp Normal file
View File

@ -0,0 +1,14 @@
# OpenRW's include-what-you-use mapping file
[
# c++ standard:
{ "include": [ "@<bits/shared_ptr\\.h>", "private", "<memory>", "public"] },
{ "include": [ "@<bits/std_function\\.h>", "private", "<functional>", "public"] },
{ "include": [ "@<bits/std_abs\\.h>", "private", "<cstdlib>", "public"] },
# GLM:
{ "include": [ "@<glm/detail/.*>", "private", "<glm/glm.hpp>", "public"] },
{ "include": [ "@<glm/gtc/.*>", "private", "<glm/gtc/matrix_transform.hpp>", "public"] },
# Boost filesystem:
{ "include": [ "@<boost/filesystem/.*>", "private", "<boost/filesystem.hpp>", "public"] },
# Boost iterator:
{ "include": [ "@<boost/range/iterator_range_core\\.hpp>", "private", "<boost/range/iterator_range.hpp>", "public"] },
]

View File

@ -31,6 +31,7 @@ set(RWENGINE_SOURCES
src/core/Profiler.cpp
src/core/Profiler.hpp
src/data/forward.hpp
src/data/AnimGroup.cpp
src/data/AnimGroup.hpp
src/data/Chase.cpp

View File

@ -0,0 +1,7 @@
#ifndef _RWENGINE_FORWARD_HPP_
#define _RWENGINE_FORWARD_HPP_
struct CutsceneTracks;
class GameTexts;
#endif

View File

@ -7,8 +7,8 @@
#include <loaders/LoaderCOL.hpp>
#include <loaders/LoaderIDE.hpp>
#include <loaders/LoaderIPL.hpp>
#include <platform/FileHandle.hpp>
#include <script/SCMFile.hpp>
#include <core/Logger.hpp>
#include <loaders/GenericDATLoader.hpp>
#include <loaders/LoaderGXT.hpp>

View File

@ -1,8 +1,12 @@
#include <loaders/LoaderCutsceneDAT.hpp>
#include "loaders/LoaderCutsceneDAT.hpp"
#include <algorithm>
#include <sstream>
#include <glm/glm.hpp>
#include <data/CutsceneData.hpp>
#include <platform/FileHandle.hpp>
#include <rw/defines.hpp>
void LoaderCutsceneDAT::load(CutsceneTracks &tracks, FileHandle file) {

View File

@ -1,8 +1,9 @@
#pragma once
#ifndef _LOADERCUTSCENEDAT_HPP_
#define _LOADERCUTSCENEDAT_HPP_
#include <data/CutsceneData.hpp>
#include <platform/FileHandle.hpp>
#include <data/forward.hpp>
#include <rw/forward.hpp>
class LoaderCutsceneDAT {
public:

View File

@ -1,4 +1,7 @@
#include <loaders/LoaderGXT.hpp>
#include "loaders/LoaderGXT.hpp"
#include <data/GameTexts.hpp>
#include "platform/FileHandle.hpp"
void LoaderGXT::load(GameTexts &texts, FileHandle &file) {
auto data = file->data;

View File

@ -1,8 +1,8 @@
#pragma once
#ifndef _LOADERGXT_HPP_
#define _LOADERGXT_HPP_
#include <data/GameTexts.hpp>
#include <platform/FileHandle.hpp>
#include <data/forward.hpp>
#include <rw/forward.hpp>
class LoaderGXT {
public:

View File

@ -1,5 +1,8 @@
#include "data/Clump.hpp"
#include <iostream>
#include <algorithm>
#include <limits>
#include <memory>
#include <queue>
#include <glm/gtc/matrix_transform.hpp>

View File

@ -1,12 +1,13 @@
#pragma once
#ifndef _MODEL_HPP_
#define _MODEL_HPP_
#include <algorithm>
#include <glm/glm.hpp>
#include <memory>
#ifndef _LIBRW_CLUMP_HPP_
#define _LIBRW_CLUMP_HPP_
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
#include <glm/glm.hpp>
#include <gl/gl_core_3_3.h>
#include <gl/DrawBuffer.hpp>
#include <gl/GeometryBuffer.hpp>
#include <gl/TextureData.hpp>

View File

@ -1,7 +1,10 @@
#include <gl/DrawBuffer.hpp>
#include <gl/GeometryBuffer.hpp>
#include "gl/DrawBuffer.hpp"
#include <map>
#include <gl/gl_core_3_3.h>
#include <gl/GeometryBuffer.hpp>
/* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */
std::map<AttributeSemantic, GLuint> semantic_to_attrib_array = {
{ATRS_Position, 0}, {ATRS_Normal, 1}, {ATRS_Colour, 2}, {ATRS_TexCoord, 3}};

View File

@ -1,6 +1,5 @@
#pragma once
#ifndef _DRAWBUFFER_HPP_
#define _DRAWBUFFER_HPP_
#ifndef _LIBRW_DRAWBUFFER_HPP_
#define _LIBRW_DRAWBUFFER_HPP_
#include <gl/gl_core_3_3.h>
class GeometryBuffer;

View File

@ -1,4 +1,4 @@
#include <gl/GeometryBuffer.hpp>
#include "gl/GeometryBuffer.hpp"
GeometryBuffer::GeometryBuffer() : vbo(0), num(0) {
}

View File

@ -1,6 +1,5 @@
#pragma once
#ifndef _GEOMETRYBUFFER_HPP_
#define _GEOMETRYBUFFER_HPP_
#ifndef _LIBRW_GEOMETRYBUFFER_HPP_
#define _LIBRW_GEOMETRYBUFFER_HPP_
#include <gl/gl_core_3_3.h>
#include <vector>

View File

@ -1 +1 @@
#include <gl/TextureData.hpp>
#include "gl/TextureData.hpp"

View File

@ -1,9 +1,11 @@
#pragma once
#ifndef _LIBRW_TEXTUREDATA_HPP_
#define _LIBRW_TEXTUREDATA_HPP_
#include <gl/gl_core_3_3.h>
#include <glm/glm.hpp>
#include <map>
#include <memory>
#include <string>
/**
* Stores a handle and metadata about a loaded texture.
@ -43,3 +45,5 @@ private:
bool hasAlpha;
};
using TextureArchive = std::map<std::string, TextureData::Handle>;
#endif

View File

@ -1,12 +1,20 @@
#include <data/Clump.hpp>
#include <loaders/LoaderDFF.hpp>
#include <rw/defines.hpp>
#include "loaders/LoaderDFF.hpp"
#include <algorithm>
#include <cctype>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <memory>
#include <numeric>
#include <set>
#include <glm/glm.hpp>
#include "data/Clump.hpp"
#include "gl/gl_core_3_3.h"
#include "loaders/RWBinaryStream.hpp"
#include "platform/FileHandle.hpp"
#include "rw/defines.hpp"
enum DFFChunks {
CHUNK_STRUCT = 0x0001,

View File

@ -1,14 +1,15 @@
#pragma once
#ifndef _LOADERDFF_HPP_
#define _LOADERDFF_HPP_
#ifndef _LIBRW_LOADERDFF_HPP_
#define _LIBRW_LOADERDFF_HPP_
#include <data/Clump.hpp>
#include <gl/TextureData.hpp>
#include <loaders/RWBinaryStream.hpp>
#include <platform/FileHandle.hpp>
#include <rw/forward.hpp>
#include <functional>
#include <string>
#include <vector>
class RWBStream;
class DFFLoaderException {
std::string _message;

View File

@ -1,6 +1,9 @@
#include <loaders/LoaderIMG.hpp>
#include "loaders/LoaderIMG.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <cstdio>
#include "rw/defines.hpp"
LoaderIMG::LoaderIMG() : m_version(GTAIIIVC), m_assetCount(0) {
}
@ -21,7 +24,7 @@ bool LoaderIMG::load(const rwfs::path& filepath) {
if ((m_assetCount = fread(&m_assets[0], sizeof(LoaderIMGFile),
m_assetCount, fp)) != fileSize / 32) {
m_assets.resize(m_assetCount);
std::cout << "Error reading records in IMG archive" << std::endl;
RW_ERROR("Error reading records in IMG archive");
}
fclose(fp);
@ -51,7 +54,7 @@ char* LoaderIMG::loadToMemory(const std::string& assetname) {
bool found = findAssetInfo(assetname, assetInfo);
if (!found) {
std::cerr << "Asset '" << assetname << "' not found!" << std::endl;
RW_ERROR("Asset '" << assetname << "' not found!");
return nullptr;
}
@ -63,7 +66,7 @@ char* LoaderIMG::loadToMemory(const std::string& assetname) {
fseek(fp, assetInfo.offset * 2048, SEEK_SET);
if (fread(raw_data, 2048, assetInfo.size, fp) != assetInfo.size) {
std::cerr << "Error reading asset " << assetInfo.name << std::endl;
RW_ERROR("Error reading asset " << assetInfo.name);
}
fclose(fp);

View File

@ -1,9 +1,9 @@
#pragma once
#ifndef _LOADERIMG_HPP_
#define _LOADERIMG_HPP_
#ifndef _LIBRW_LOADERIMG_HPP_
#define _LIBRW_LOADERIMG_HPP_
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <rw/filesystem.hpp>
@ -23,7 +23,7 @@ public:
class LoaderIMG {
public:
/// Multiple versions of .IMG files
enum Versions {
enum Version {
GTAIIIVC, ///< GTA III and GTA VC archives -- only this one is
///implemented
GTASA,
@ -55,8 +55,12 @@ public:
/// Returns the number of asset files in the archive
uint32_t getAssetCount() const;
Version getVersion() const {
return m_version;
}
private:
Versions m_version; ///< Version of this IMG archive
Version m_version; ///< Version of this IMG archive
uint32_t m_assetCount; ///< Number of assets in the current archive
rwfs::path m_archive; ///< Path to the archive being used (no extension)

View File

@ -1,8 +1,11 @@
#include <loaders/LoaderSDT.hpp>
#include "loaders/LoaderSDT.hpp"
#include <cstring>
#include <cstdio>
#include <string>
#include "rw/defines.hpp"
LoaderSDT::LoaderSDT() : m_version(GTAIIIVC), m_assetCount(0) {
}
@ -43,7 +46,7 @@ bool LoaderSDT::load(const std::string& filename) {
if ((m_assetCount = fread(&m_assets[0], sizeof(LoaderSDTFile),
m_assetCount, fp)) != fileSize / 20) {
m_assets.resize(m_assetCount);
std::cout << "Error reading records in SDT archive" << std::endl;
RW_ERROR("Error reading records in SDT archive");
}
fclose(fp);
@ -68,8 +71,7 @@ char* LoaderSDT::loadToMemory(size_t index, bool asWave) {
bool found = findAssetInfo(index, assetInfo);
if (!found) {
std::cerr << "Asset " << std::to_string(index) << " not found!"
<< std::endl;
RW_ERROR("Asset " << std::to_string(index) << " not found!");
return nullptr;
}
@ -105,8 +107,7 @@ char* LoaderSDT::loadToMemory(size_t index, bool asWave) {
fseek(fp, assetInfo.offset, SEEK_SET);
if (fread(sample_data, 1, assetInfo.size, fp) != assetInfo.size) {
std::cerr << "Error reading asset " << std::to_string(index)
<< std::endl;
RW_ERROR("Error reading asset " << std::to_string(index));
}
fclose(fp);
@ -148,3 +149,7 @@ const LoaderSDTFile& LoaderSDT::getAssetInfoByIndex(size_t index) const {
uint32_t LoaderSDT::getAssetCount() const {
return m_assetCount;
}
LoaderSDT::Version LoaderSDT::getVersion() const {
return m_version;
}

View File

@ -1,9 +1,9 @@
#pragma once
#ifndef _LOADERSDT_HPP_
#define _LOADERSDT_HPP_
#ifndef _LIBRW_LOADERSDT_HPP_
#define _LIBRW_LOADERSDT_HPP_
#include <cstdint>
#include <iostream>
#include <cstddef>
#include <string>
#include <vector>
/// \brief Points to one file within the archive
@ -26,7 +26,7 @@ public:
class LoaderSDT {
public:
/// Multiple versions of .SDT files
enum Versions {
enum Version {
GTA2,
GTAIIIVC ///< GTA III and GTA VC archives -- only this one is
///implemented
@ -57,8 +57,10 @@ public:
/// Returns the number of asset files in the archive
uint32_t getAssetCount() const;
Version getVersion() const;
private:
Versions m_version; ///< Version of this SDT archive
Version m_version; ///< Version of this SDT archive
uint32_t m_assetCount; ///< Number of assets in the current archive
std::string m_archive; ///< Path to the archive being used (no extension)

View File

@ -1,16 +1,24 @@
#include <gl/TextureData.hpp>
#include <loaders/LoaderTXD.hpp>
#include "loaders/LoaderTXD.hpp"
#include <algorithm>
#include <iostream>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <string>
#include <vector>
#include "gl/gl_core_3_3.h"
#include "loaders/RWBinaryStream.hpp"
#include "platform/FileHandle.hpp"
#include "rw/defines.hpp"
GLuint gErrorTextureData[] = {0xFFFF00FF, 0xFF000000, 0xFF000000, 0xFFFF00FF};
GLuint gDebugTextureData[] = {0xFF0000FF, 0xFF00FF00};
GLuint gTextureRed[] = {0xFF0000FF};
GLuint gTextureGreen[] = {0xFF00FF00};
GLuint gTextureBlue[] = {0xFFFF0000};
static
TextureData::Handle getErrorTexture() {
static GLuint errTexName = 0;
static TextureData::Handle tex;
@ -27,6 +35,8 @@ TextureData::Handle getErrorTexture() {
}
const size_t paletteSize = 1024;
static
void processPalette(uint32_t* fullColor, RW::BinaryStreamSection& rootSection) {
uint8_t* dataBase = reinterpret_cast<uint8_t*>(
rootSection.raw() + sizeof(RW::BSSectionHeader) +
@ -41,12 +51,13 @@ void processPalette(uint32_t* fullColor, RW::BinaryStreamSection& rootSection) {
}
}
static
TextureData::Handle createTexture(RW::BSTextureNative& texNative,
RW::BinaryStreamSection& rootSection) {
// TODO: Exception handling.
if (texNative.platform != 8) {
std::cerr << "Unsupported texture platform " << std::dec
<< texNative.platform << std::endl;
RW_ERROR("Unsupported texture platform " << std::dec
<< texNative.platform);
return getErrorTexture();
}
@ -62,8 +73,8 @@ TextureData::Handle createTexture(RW::BSTextureNative& texNative,
RW::BSTextureNative::FORMAT_888);
if (!(isPal8 || isFulc)) {
std::cerr << "Unsuported raster format " << std::dec
<< texNative.rasterformat << std::endl;
RW_ERROR("Unsupported raster format " << std::dec
<< texNative.rasterformat);
return getErrorTexture();
}

View File

@ -1,18 +1,8 @@
#pragma once
#ifndef _TEXTURELOADER_HPP_
#define _TEXTURELOADER_HPP_
#ifndef _LIBRW_TEXTURELOADER_HPP_
#define _LIBRW_TEXTURELOADER_HPP_
#include <loaders/RWBinaryStream.hpp>
#include <functional>
#include <map>
#include <platform/FileHandle.hpp>
#include <string>
// This might suffice
#include <gl/TextureData.hpp>
class FileIndex;
#include <rw/forward.hpp>
class TextureLoader {
public:

View File

@ -1,5 +1,5 @@
#ifndef _RWBINARYSTREAM_H_
#define _RWBINARYSTREAM_H_
#ifndef _LIBRW_RWBINARYSTREAM_HPP_
#define _LIBRW_RWBINARYSTREAM_HPP_
#include <cstdint>
#include <glm/glm.hpp>

View File

@ -1,5 +1,5 @@
#ifndef RWENGINE_FILEHANDLE_HPP
#define RWENGINE_FILEHANDLE_HPP
#ifndef _LIBRW_FILEHANDLE_HPP_
#define _LIBRW_FILEHANDLE_HPP_
#include <memory>
@ -18,6 +18,4 @@ struct FileContentsInfo {
}
};
using FileHandle = std::shared_ptr<FileContentsInfo>;
#endif

View File

@ -1,7 +1,14 @@
#include "platform/FileIndex.hpp"
#include <algorithm>
#include <fstream>
#include <loaders/LoaderIMG.hpp>
#include <platform/FileIndex.hpp>
#include <memory>
#include <stdexcept>
#include <boost/range/iterator_range.hpp>
#include "loaders/LoaderIMG.hpp"
#include "platform/FileHandle.hpp"
void FileIndex::indexGameDirectory(const rwfs::path& base_path) {
gamedatapath_ = base_path;

View File

@ -1,12 +1,14 @@
#ifndef RWENGINE_FILEINDEX_HPP
#define RWENGINE_FILEINDEX_HPP
#include <platform/FileHandle.hpp>
#include <rw/filesystem.hpp>
#ifndef _LIBRW_FILEINDEX_HPP_
#define _LIBRW_FILEINDEX_HPP_
#include <algorithm>
#include <cctype>
#include <map>
#include <string>
#include <unordered_map>
#include <rw/filesystem.hpp>
#include <rw/forward.hpp>
class FileIndex {
private:

View File

@ -1,4 +1,4 @@
#include "rw/defines.hpp"
#include <functional>
#if RW_DEBUG
std::function<void()> _rw_abort_cb[2] = {nullptr, nullptr};

View File

@ -1,5 +1,5 @@
#ifndef RWLIB_FILESYSTEM_HPP
#define RWLIB_FILESYSTEM_HPP
#ifndef _LIBRW_FILESYSTEM_HPP_
#define _LIBRW_FILESYSTEM_HPP_
#define RW_FS_CXX17 0
#define RW_FS_CXXTS 1

View File

@ -1,5 +1,5 @@
#ifndef RWLIB_FORWARD_HPP
#define RWLIB_FORWARD_HPP
#ifndef _LIBRW_RW_FORWARD_HPP_
#define _LIBRW_RW_FORWARD_HPP_
#include <map>
#include <memory>
@ -8,6 +8,7 @@
// Forward Declarations
struct Animation;
class Clump;
struct FileContentsInfo;
class ModelFrame;
struct Geometry;
class Atomic;
@ -15,6 +16,7 @@ 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>;

View File

@ -1,6 +1,5 @@
#pragma once
#ifndef _RWTYPES_HPP_
#define _RWTYPES_HPP_
#ifndef _LIBRW_TYPES_HPP_
#define _LIBRW_TYPES_HPP_
#include <cstdint>
#include <glm/glm.hpp>

View File

@ -1,5 +1,6 @@
#include <boost/test/unit_test.hpp>
#include <loaders/RWBinaryStream.hpp>
#include <platform/FileHandle.hpp>
#include "test_Globals.hpp"
BOOST_AUTO_TEST_SUITE(RWBStreamTests)