1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

rwcore: fix Visual Studio warnings

This commit is contained in:
Anonymous Maarten 2018-08-29 22:46:00 +02:00
parent b92f9f059f
commit 8557f2176d
13 changed files with 49 additions and 54 deletions

View File

@ -107,7 +107,7 @@ public:
*/
struct SubGeometry {
GLuint start = 0;
size_t start = 0;
size_t material = 0;
std::vector<uint32_t> indices;
size_t numIndices = 0;

View File

@ -28,7 +28,7 @@ FontMap::FontMap(std::initializer_list<std::reference_wrapper<const gschar_unico
GameStringChar FontMap::to_GameStringChar(unicode_t u) const {
if (u < 0x20) {
/* Passthrough control characters */
return u;
return static_cast<GameStringChar>(u);
}
const auto &p = m_from_unicode.find(u);
if (p == m_from_unicode.end()) {

View File

@ -4,22 +4,22 @@
size_t unicode_to_utf8(unicode_t unicode, char c[4]) {
if (unicode < 0x80) { // 7 bits
c[0] = unicode;
c[0] = static_cast<char>(unicode);
return 1;
} else if (unicode < 0x800) { // 11 bits
c[0] = 0xc0 | (unicode >> 6);
c[1] = 0x80 | (unicode & 0x3f);
c[0] = static_cast<char>(0xc0 | (unicode >> 6));
c[1] = static_cast<char>(0x80 | (unicode & 0x3f));
return 2;
} else if (unicode < 0x10000) { // 16 bits
c[0] = 0xe0 | (unicode >> 12);
c[1] = 0x80 | ((unicode >> 6) & 0x3f);
c[2] = 0x80 | (unicode & 0x3f);
c[0] = static_cast<char>(0xe0 | (unicode >> 12));
c[1] = static_cast<char>(0x80 | ((unicode >> 6) & 0x3f));
c[2] = static_cast<char>(0x80 | (unicode & 0x3f));
return 3;
} else if (unicode < 0x110000) { // 21 bits
c[0] = 0xf0 | (unicode >> 18);
c[1] = 0x80 | ((unicode >> 12) & 0x3f);
c[2] = 0x80 | ((unicode >> 6) & 0x3f);
c[3] = 0x80 | (unicode & 0x3f);
c[0] = static_cast<char>(0xf0 | (unicode >> 18));
c[1] = static_cast<char>(0x80 | ((unicode >> 12) & 0x3f));
c[2] = static_cast<char>(0x80 | ((unicode >> 6) & 0x3f));
c[3] = static_cast<char>(0x80 | (unicode & 0x3f));
return 4;
} else {
return unicode_to_utf8(UnicodeValue::UNICODE_REPLACEMENT_CHARACTER, c);

View File

@ -29,7 +29,7 @@ void DrawBuffer::addGeometry(GeometryBuffer* gbuff) {
for (const AttributeIndex& at : gbuff->getDataAttributes()) {
GLuint vaoindex = semantic_to_attrib_array[at.sem];
glEnableVertexAttribArray(vaoindex);
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride,
reinterpret_cast<GLvoid*>(at.offset));
glVertexAttribPointer(vaoindex, static_cast<GLint>(at.size), at.type, GL_TRUE, at.stride,
reinterpret_cast<void*>(at.offset));
}
}

View File

@ -1,8 +1,5 @@
#include "gl/GeometryBuffer.hpp"
GeometryBuffer::GeometryBuffer() : vbo(0), num(0) {
}
GeometryBuffer::~GeometryBuffer() {
if (vbo != 0) {
glDeleteBuffers(1, &vbo);

View File

@ -20,10 +20,10 @@ struct AttributeIndex {
AttributeSemantic sem;
GLsizei size;
GLsizei stride;
GLsizei offset;
size_t offset;
GLenum type;
AttributeIndex(AttributeSemantic s, GLsizei sz, GLsizei strd, GLsizei offs,
AttributeIndex(AttributeSemantic s, GLsizei sz, GLsizei strd, size_t offs,
GLenum type = GL_FLOAT)
: sem(s), size(sz), stride(strd), offset(offs), type(type) {
}
@ -35,15 +35,15 @@ typedef std::vector<AttributeIndex> AttributeList;
* GeometryBuffer stores a set of vertex attribute data
*/
class GeometryBuffer {
GLuint vbo;
GLsizei num;
GLuint vbo = 0;
GLsizei num = 0;
AttributeList attributes;
AttributeList attributes{};
public:
GeometryBuffer();
GeometryBuffer() = default;
template <class T>
GeometryBuffer(const std::vector<T>& data) : vbo(0), num(0) {
GeometryBuffer(const std::vector<T>& data) {
uploadVertices(data);
}
@ -65,7 +65,7 @@ public:
*/
template <class T>
void uploadVertices(const std::vector<T>& data) {
uploadVertices(data.size(), data.size() * sizeof(T), data.data());
uploadVertices(static_cast<GLsizei>(data.size()), data.size() * sizeof(T), data.data());
// Assume T has a static method for attributes;
attributes = T::vertex_attributes();
}

View File

@ -2,8 +2,8 @@
#define _LIBRW_TEXTUREDATA_HPP_
#include <gl/gl_core_3_3.h>
#include <glm/glm.hpp>
#include <map>
#include <map>
#include <memory>
#include <string>

View File

@ -65,7 +65,7 @@ LoaderDFF::FrameList LoaderDFF::readFrameList(const RWBStream &stream) {
FrameList framelist;
framelist.reserve(numFrames);
for (size_t f = 0; f < numFrames; ++f) {
for (auto f = 0u; f < numFrames; ++f) {
auto data = reinterpret_cast<RWBSFrame *>(headerPtr);
headerPtr += sizeof(RWBSFrame);
auto frame =
@ -259,7 +259,7 @@ GeometryPtr LoaderDFF::readGeometry(const RWBStream &stream) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, geom->EBO);
size_t icount = std::accumulate(
geom->subgeom.begin(), geom->subgeom.end(), 0u,
geom->subgeom.begin(), geom->subgeom.end(), size_t{0u},
[](size_t a, const SubGeometry &b) { return a + b.numIndices; });
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint32_t) * icount, nullptr,
GL_STATIC_DRAW);

View File

@ -5,9 +5,6 @@
#include "rw/debug.hpp"
LoaderIMG::LoaderIMG() : m_version(GTAIIIVC), m_assetCount(0) {
}
bool LoaderIMG::load(const rwfs::path& filepath) {
auto dirPath = filepath;
dirPath.replace_extension(".dir");
@ -18,12 +15,13 @@ bool LoaderIMG::load(const rwfs::path& filepath) {
unsigned long fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
m_assetCount = fileSize / 32;
m_assets.resize(m_assetCount);
std::size_t expectedCount = fileSize / 32;
m_assets.resize(expectedCount);
std::size_t actualCount = fread(&m_assets[0], sizeof(LoaderIMGFile),
expectedCount, fp);
if ((m_assetCount = fread(&m_assets[0], sizeof(LoaderIMGFile),
m_assetCount, fp)) != fileSize / 32) {
m_assets.resize(m_assetCount);
if (expectedCount != actualCount) {
m_assets.resize(actualCount);
RW_ERROR("Error reading records in IMG archive");
}
@ -102,6 +100,6 @@ const LoaderIMGFile& LoaderIMG::getAssetInfoByIndex(size_t index) const {
return m_assets[index];
}
uint32_t LoaderIMG::getAssetCount() const {
return m_assetCount;
std::size_t LoaderIMG::getAssetCount() const {
return m_assets.size();
}

View File

@ -31,7 +31,7 @@ public:
};
/// Construct
LoaderIMG();
LoaderIMG() = default;
/// Load the structure of the archive
/// Omit the extension in filename so both .dir and .img are loaded when
@ -52,15 +52,14 @@ public:
const LoaderIMGFile& getAssetInfoByIndex(size_t index) const;
/// Returns the number of asset files in the archive
uint32_t getAssetCount() const;
std::size_t getAssetCount() const;
Version getVersion() const {
return m_version;
}
private:
Version m_version; ///< Version of this IMG archive
uint32_t m_assetCount; ///< Number of assets in the current archive
Version m_version = GTAIIIVC; ///< Version of this IMG archive
rwfs::path m_archive; ///< Path to the archive being used (no extension)
std::vector<LoaderIMGFile> m_assets; ///< Asset info of the archive

View File

@ -16,12 +16,14 @@ bool LoaderSDT::load(const rwfs::path& sdtPath, const rwfs::path& rawPath) {
unsigned long fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
m_assetCount = fileSize / 20;
m_assets.resize(m_assetCount);
size_t expectedCount = fileSize / 20;
m_assets.resize(expectedCount);
if ((m_assetCount = fread(&m_assets[0], sizeof(LoaderSDTFile),
m_assetCount, fp)) != fileSize / 20) {
m_assets.resize(m_assetCount);
size_t actualCount = fread(&m_assets[0], sizeof(LoaderSDTFile),
expectedCount, fp);
if (expectedCount != actualCount) {
m_assets.resize(actualCount);
RW_ERROR("Error reading records in SDT archive");
}
@ -118,8 +120,8 @@ const LoaderSDTFile& LoaderSDT::getAssetInfoByIndex(size_t index) const {
return m_assets[index];
}
uint32_t LoaderSDT::getAssetCount() const {
return m_assetCount;
size_t LoaderSDT::getAssetCount() const {
return m_assets.size();
}
LoaderSDT::Version LoaderSDT::getVersion() const {

View File

@ -79,13 +79,12 @@ public:
const LoaderSDTFile& getAssetInfoByIndex(size_t index) const;
/// Returns the number of asset files in the archive
uint32_t getAssetCount() const;
size_t getAssetCount() const;
Version getVersion() const;
LoaderSDTFile assetInfo{};
private:
Version m_version{GTAIIIVC}; ///< Version of this SDT archive
uint32_t m_assetCount{0}; ///< Number of assets in the current archive
std::string m_archive; ///< Path to the archive being used (no extension)
std::vector<LoaderSDTFile> m_assets; ///< Asset info of the archive
};

View File

@ -9,7 +9,7 @@
//Based on https://gist.github.com/socantre/3472964
template <class Dest, class Source>
inline Dest bit_cast(Source const &source) {
Dest dest = Dest{};
Dest dest;
std::memcpy(&dest, &source, sizeof(Dest));
return dest;
}
@ -18,10 +18,10 @@ template <class T, class S>
inline T lexical_cast(const S& s);
template <class T, class S>
inline T lexical_cast(const S& s, size_t base);
inline T lexical_cast(const S& s, int base);
template <>
inline int lexical_cast(const std::string& source, size_t base) {
inline int lexical_cast(const std::string& source, int base) {
char* end = nullptr; //for errors handling
int result = std::strtol(source.c_str(), &end, base);
RW_CHECK(end != source.c_str(), "Problem with conversion " << *end << " to int");