1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Merge pull request #618 from madebr/fix_msvc_warnings

Fix Visual Studio and XCode Warnings
This commit is contained in:
Daniel Evans 2018-09-17 21:32:59 +01:00 committed by GitHub
commit 5951b978d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
117 changed files with 561 additions and 400 deletions

View File

@ -17,12 +17,10 @@ environment:
USE_CONAN: 1
platform:
# - Win32
- x64
configuration:
# - Debug
- Release
- RelWithDebInfo
matrix:
fast_finish: false

View File

@ -6,25 +6,30 @@ git:
matrix:
include:
- os: linux
compiler: gcc
env: NAME="Ubuntu Linux (Latest)" NAME_SUFFIX="ubuntu"
services: docker
script:
- scripts/docker/docker_travis.sh "ubuntu_latest.docker"
- os: linux
env: NAME="Fedora Linux (Latest)" NAME_SUFFIX="fedora"
compiler: clang
env: NAME="Fedora Linux (Latest)" NAME_SUFFIX="fedora-llvm"
services: docker
script:
- scripts/docker/docker_travis.sh "fedora_latest.docker"
- os: linux
compiler: gcc
env: NAME="Arch Linux (Latest)" NAME_SUFFIX="arch" DEBUG=1
services: docker
script:
- scripts/docker/docker_travis.sh "arch_latest.docker"
- os: linux
compiler: gcc
env: NAME="conan" NAME_SUFFIX="conan" USE_CONAN=1
script:
- scripts/docker/docker_travis.sh "conan_base.docker"
- os: osx
compiler: clang
env: NAME="Apple macOS" NAME_SUFFIX="mac"
osx_image: xcode9.4
install:

View File

@ -6,7 +6,7 @@
set(_ARGS_BOOL
USE_CONAN
DEBUG
BUILD_TYPE
CHECK_IWYU
BUILD_TOOLS
BUILD_VIEWER
@ -39,6 +39,7 @@ set(_ARGS_ONEVAL
set(_ARGS_MULVAL
CONFIGURE_EXTRA_OPTIONS
BUILD_EXTRA_FLAGS
)
foreach(_ARG ${_ARGS_BOOL} ${_ARGS_ONEVAL} ${_ARGS_MULVAL})
@ -66,6 +67,12 @@ endif()
message(STATUS "Starting test...")
ctest_start("${MODEL_NAME}" ${_CTEST_START_EXTRA_ARGS})
set(ALL_BUILD_TYPES Release Debug MinSizeRel RelWithDebInfo)
list(FIND ALL_BUILD_TYPES "${BUILD_TYPE}" BUILD_TYPE_INDEX)
if(BUILD_TYPE_INDEX EQUAL -1)
message(FATAL_ERROR "Unknown build type '${BUILD_TYPE}'")
endif()
if(USE_CONAN)
find_program(CONAN_BIN
NAMES conan
@ -108,7 +115,7 @@ if(USE_CONAN)
endif()
endif()
if(DEBUG)
if(BUILD_TYPE STREQUAL "Debug")
set(CONAN_CONFIGURATION "Debug")
else()
set(CONAN_CONFIGURATION "Release")
@ -148,15 +155,9 @@ if(USE_CONAN)
endif()
# CTEST_CONFIGURATION_TYPE is needed on Windows (no leading underscore)
if(DEBUG)
set(_CMAKE_BUILD_TYPE "Debug")
set(_CTEST_BUILD_CONFIGURATION "Debug")
set(CTEST_CONFIGURATION_TYPE "Debug")
else()
set(_CMAKE_BUILD_TYPE "Release")
set(_CTEST_BUILD_CONFIGURATION "Release")
set(CTEST_CONFIGURATION_TYPE "Release")
endif()
set(_CMAKE_BUILD_TYPE "${BUILD_TYPE}")
set(_CTEST_BUILD_CONFIGURATION "${BUILD_TYPE}")
set(CTEST_CONFIGURATION_TYPE "${BUILD_TYPE}")
set(_CONFIGURE_OPTIONS
"-DBUILD_TOOLS=${BUILD_TOOLS}"
@ -186,6 +187,7 @@ ctest_configure(
message(STATUS "Building...")
ctest_build(
CONFIGURATION "${_CTEST_BUILD_CONFIGURATION}"
FLAGS ${BUILD_EXTRA_FLAGS}
NUMBER_ERRORS _NB_BUILD_ERRORS
)

View File

@ -1,10 +1,11 @@
set(CMAKE_GENERATOR "Xcode")
if(ENV{DEBUG})
set(DEBUG "$ENV{DEBUG}")
if($ENV{DEBUG})
set(BUILD_TYPE "Debug")
else()
set(DEBUG FALSE)
set(BUILD_TYPE "Release")
endif()
set(CONFIGURE_EXTRA_OPTIONS ";")
set(BUILD_EXTRA_FLAGS "")
set(BUILD_TOOLS TRUE)
set(BUILD_VIEWER TRUE)
set(COVERAGE_COMMAND gcov)

View File

@ -1,10 +1,17 @@
set(CMAKE_GENERATOR "Unix Makefiles")
if($ENV{DEBUG})
set(DEBUG "$ENV{DEBUG}")
set(BUILD_TYPE "Debug")
else()
set(DEBUG FALSE)
set(BUILD_TYPE "Release")
endif()
set(CONFIGURE_EXTRA_OPTIONS ";")
include(ProcessorCount)
ProcessorCount(CORES_COUNT)
set(BUILD_EXTRA_FLAGS "")
if(NOT CORES_COUNT EQUAL 0)
list(APPEND BUILD_EXTRA_FLAGS "-j${CORES_COUNT}")
endif()
set(BUILD_TOOLS TRUE)
set(BUILD_VIEWER TRUE)
set(COVERAGE_COMMAND gcov)

View File

@ -23,14 +23,9 @@ else()
endif()
set(CONFIGURE_EXTRA_OPTIONS ";")
set(BUILD_EXTRA_FLAGS "")
if(CONFIGURATION STREQUAL "Debug")
set(DEBUG TRUE)
elseif(CONFIGURATION STREQUAL "Release")
set(DEBUG FALSE)
else()
message(FATAL_ERROR "Unknown configuration '${CONFIGURATION}'")
endif()
set(BUILD_TYPE "${CONFIGURATION}")
set(CONAN_ARCH "x86_64")

View File

@ -52,14 +52,24 @@ endif()
find_path(GLM_INCLUDE_DIR "glm/glm.hpp"
PATHS ${_glm_HEADER_SEARCH_DIRS})
if(GLM_INCLUDE_DIR)
file(READ "${GLM_INCLUDE_DIR}/glm/detail/setup.hpp" _GLM_SETUP_HPP)
string(REGEX MATCH "GLM: version ([0-9a-zA-Z\.\-]+)" _GLM_VERSION "${_GLM_SETUP_HPP}")
if(NOT _GLM_VERSION)
message(AUTHOR_WARNING "Cannot detect GLM version: regex does not match")
endif()
set(GLM_VERSION "${CMAKE_MATCH_1}")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLM DEFAULT_MSG
GLM_INCLUDE_DIR)
find_package_handle_standard_args(GLM
FOUND_VAR GLM_FOUND
REQUIRED_VARS GLM_INCLUDE_DIR
VERSION_VAR GLM_VERSION
)
if(GLM_FOUND)
set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}")
add_library(glm INTERFACE)
target_include_directories(glm SYSTEM
INTERFACE "${GLM_INCLUDE_DIR}")
add_library(glm::glm ALIAS glm)
add_library(glm::glm INTERFACE IMPORTED)
set_property(TARGET glm::glm
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GLM_INCLUDE_DIR})
endif()

View File

@ -1,6 +1,10 @@
add_library(rw_interface INTERFACE)
add_library(openrw::interface ALIAS rw_interface)
add_library(rw_checks INTERFACE)
add_library(openrw::checks ALIAS rw_checks)
target_link_libraries(rw_interface INTERFACE rw_checks)
# target_compile_features(rw_interface INTERFACE cxx_std_14) is not supported by CMake 3.2
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 14)
@ -13,14 +17,19 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang
"-Wextra"
"-Wdouble-promotion"
"-Wpedantic"
"-Wmissing-braces"
"$<IF:$<COMPILE_LANGUAGE:CXX>,-Wold-style-cast,>"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_definitions(rw_interface
target_compile_definitions(rw_checks
INTERFACE
"_SCL_SECURE_NO_WARNINGS"
"_CRT_SECURE_NO_WARNINGS"
)
target_compile_options(rw_interface
INTERFACE
"/MP"
)
else()
message(FATAL_ERROR "Unknown compiler ID: '${CMAKE_CXX_COMPILER_ID}'")
endif()
@ -54,6 +63,7 @@ endif()
target_compile_definitions(rw_interface
INTERFACE
"$<$<CONFIG:Debug>:RW_DEBUG>"
"GLM_FORCE_PURE"
"GLM_FORCE_RADIANS"
"GLM_ENABLE_EXPERIMENTAL"
"$<$<BOOL:${RW_VERBOSE_DEBUG_MESSAGES}>:RW_VERBOSE_DEBUG_MESSAGES>"
@ -142,13 +152,13 @@ if(TEST_COVERAGE)
message("TEST_COVERAGE enabled. Enabling BUILD_TESTS.")
set(BUILD_TESTS "ON")
endif()
target_compile_options(rw_interface
target_compile_options(rw_checks
INTERFACE
"-O0"
"-fprofile-arcs"
"-ftest-coverage"
)
target_link_libraries(rw_interface
target_link_libraries(rw_checks
INTERFACE
gcov
)
@ -157,32 +167,30 @@ endif()
foreach(SAN ${ENABLE_SANITIZERS})
if(SAN STREQUAL "address")
message(STATUS "Address sanitizer enabled.")
target_compile_options(rw_interface INTERFACE "-fsanitize=address")
target_link_libraries(rw_interface INTERFACE "-fsanitize=address")
target_compile_options(rw_checks INTERFACE "-fsanitize=address")
target_link_libraries(rw_checks INTERFACE "-fsanitize=address")
elseif(SAN STREQUAL "leak")
message(STATUS "Leak sanitizer enabled.")
target_compile_options(rw_interface INTERFACE "-fsanitize=leak")
target_link_libraries(rw_interface INTERFACE "-fsanitize=leak")
target_compile_options(rw_checks INTERFACE "-fsanitize=leak")
target_link_libraries(rw_checks INTERFACE "-fsanitize=leak")
elseif(SAN STREQUAL "thread")
message(STATUS "Thread sanitizer enabled.")
target_compile_options(rw_interface INTERFACE "-fsanitize=thread")
target_link_libraries(rw_interface INTERFACE "-fsanitize=thread")
target_compile_options(rw_checks INTERFACE "-fsanitize=thread")
target_link_libraries(rw_checks INTERFACE "-fsanitize=thread")
elseif(SAN STREQUAL "undefined")
message(STATUS "Undefined behaviour sanitizer enabled.")
target_compile_options(rw_interface INTERFACE "-fsanitize=undefined")
target_link_libraries(rw_interface INTERFACE "-fsanitize=undefined")
target_compile_options(rw_checks INTERFACE "-fsanitize=undefined")
target_link_libraries(rw_checks INTERFACE "-fsanitize=undefined")
else()
message(FATAL_ERROR "Illegal sanitizer: ${SAN}")
endif()
endforeach()
include(CMakeParseArguments)
function(openrw_target_apply_options)
set(IWYU_MAPPING "${PROJECT_SOURCE_DIR}/openrw_iwyu.imp")
cmake_parse_arguments("OPENRW_APPLY" "" "TARGET" "" ${ARGN})
cmake_parse_arguments("ORW" "INSTALL;INSTALL_PDB" "TARGET" "" ${ARGN})
if(CHECK_IWYU)
iwyu_check(TARGET "${OPENRW_APPLY_TARGET}"
iwyu_check(TARGET "${ORW_TARGET}"
EXTRA_OPTS
"--mapping_file=${IWYU_MAPPING}"
)
@ -190,10 +198,41 @@ function(openrw_target_apply_options)
if(CHECK_CLANGTIDY)
clang_tidy_check_target(
TARGET "${OPENRW_APPLY_TARGET}"
TARGET "${ORW_TARGET}"
FORMAT_STYLE "file"
FIX "${CHECK_CLANGTIDY_FIX}"
CHECK_ALL
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set_property(
TARGET "${ORW_TARGET}"
APPEND
PROPERTY STATIC_LIBRARY_FLAGS "-no_warning_for_no_symbols"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_property(
TARGET "${ORW_TARGET}"
APPEND
PROPERTY LINK_FLAGS "/ignore:4099"
)
endif()
if(ORW_INSTALL)
install(
TARGETS "${ORW_TARGET}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
if(ORW_INSTALL_PDB)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
install(FILES "$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:RELWITHDEBINFO>>:$<TARGET_PDB_FILE:${ORW_TARGET}>>"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()
endif()
endfunction()

View File

@ -16,7 +16,7 @@ set(FILESYSTEM_LIBRARY "BOOST" CACHE STRING "Which filesystem library to use")
set_property(CACHE FILESYSTEM_LIBRARY PROPERTY STRINGS "CXX17" "CXXTS" "BOOST")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel")
endif()
option(CHECK_IWYU "Enable IncludeWhatYouUse (Analyze #includes in C and C++ source files)")

View File

@ -18,6 +18,7 @@ find_package(Threads REQUIRED)
target_link_libraries(microprofile
PUBLIC
Threads::Threads
openrw::checks
)
add_library(microprofile::microprofile ALIAS microprofile)

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

@ -200,8 +200,8 @@ static const FontMap::gschar_unicode_map_t map_gta3_font_2_priv = {
const FontMap fontmap_gta3_font_common({map_gta3_font_common});
const std::array<FontMap, 3> fontmaps_gta3_font = {
FontMap({map_gta3_font_common, map_gta3_font_0_priv}),
FontMap({map_gta3_font_common, map_gta3_font_1_priv}),
FontMap({map_gta3_font_common, map_gta3_font_2_priv}),
};
const std::array<FontMap, 3> fontmaps_gta3_font = {{
FontMap{map_gta3_font_common, map_gta3_font_0_priv},
FontMap{map_gta3_font_common, map_gta3_font_1_priv},
FontMap{map_gta3_font_common, map_gta3_font_2_priv},
}};

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");

View File

@ -41,8 +41,10 @@ set(RWENGINE_SOURCES
src/data/PathData.hpp
src/data/PedData.cpp
src/data/PedData.hpp
src/data/VehicleGenerator.hpp
src/data/WeaponData.hpp
src/data/Weather.cpp
src/data/Weather.hpp
src/data/ZoneData.hpp
src/dynamics/CollisionInstance.cpp
@ -53,6 +55,7 @@ set(RWENGINE_SOURCES
src/engine/Animator.hpp
src/engine/GameData.cpp
src/engine/GameData.hpp
src/engine/GameInputState.hpp
src/engine/GameState.cpp
src/engine/GameState.hpp
src/engine/GameWorld.cpp
@ -136,6 +139,7 @@ set(RWENGINE_SOURCES
src/script/ScriptTypes.hpp
src/script/modules/GTA3Module.cpp
src/script/modules/GTA3Module.hpp
src/script/modules/GTA3ModuleImpl.inl
)
add_library(rwengine

View File

@ -19,11 +19,11 @@ AIGraph::~AIGraph() {
void AIGraph::createPathNodes(const glm::vec3& position,
const glm::quat& rotation, PathData& path) {
size_t startIndex = nodes.size();
auto startIndex = static_cast<std::uint32_t>(nodes.size());
std::vector<AIGraphNode*> pathNodes;
pathNodes.reserve(path.nodes.size());
for (size_t n = 0; n < path.nodes.size(); ++n) {
for (auto n = 0u; n < path.nodes.size(); ++n) {
auto& node = path.nodes[n];
AIGraphNode* ainode = nullptr;
glm::vec3 nodePosition = position + (rotation * node.position);
@ -71,7 +71,7 @@ void AIGraph::createPathNodes(const glm::vec3& position,
RW_MESSAGE("Warning: Node outside of grid at coord "
<< gridcoord.x << " " << gridcoord.y);
}
auto index = (gridcoord.x * WORLD_GRID_WIDTH) + gridcoord.y;
auto index = static_cast<std::size_t>((gridcoord.x * WORLD_GRID_WIDTH) + gridcoord.y);
gridNodes[index].push_back(ainode);
}
}

View File

@ -4,8 +4,15 @@
#include <limits>
#include <utility>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletDynamics/Character/btKinematicCharacterController.h>
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/gtc/constants.hpp>
#include <glm/gtc/quaternion.hpp>
@ -336,7 +343,7 @@ bool Activities::DriveTo::update(CharacterObject *character,
// Choose the next node randomly
if(nextTargetNode == nullptr) {
auto& random = character->engine->randomEngine;
int i = std::uniform_int_distribution<>(0, potentialNodes.size() - 1)(random);
auto i = std::uniform_int_distribution<std::size_t>(0, potentialNodes.size() - 1)(random);
nextTargetNode = potentialNodes.at(i);
}

View File

@ -67,7 +67,7 @@ void DefaultAIController::update(float dt) {
auto lastTarget = targetNode;
std::random_device rd;
std::default_random_engine re(rd());
std::uniform_int_distribution<> d(
std::uniform_int_distribution<size_t> d(
0, lastTarget->connections.size() - 1);
targetNode = lastTarget->connections.at(d(re));
setNextActivity(std::make_unique<Activities::GoTo>(
@ -156,7 +156,7 @@ void DefaultAIController::update(float dt) {
// If we haven't found a node, choose one randomly
if (!targetNode) {
auto& random = getCharacter()->engine->randomEngine;
int nodeIndex = std::uniform_int_distribution<>(0, lastTargetNode->connections.size() - 1)(random);
size_t nodeIndex = std::uniform_int_distribution<size_t>(0, lastTargetNode->connections.size() - 1)(random);
targetNode = lastTargetNode->connections.at(nodeIndex);
}

View File

@ -11,8 +11,6 @@ private:
glm::vec3 direction{};
glm::quat lastRotation = glm::vec3(0.f, 0.f, 0.f);
bool missionRestartRequired = false;
bool adrenalineEffect = false;

View File

@ -97,12 +97,6 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
auto& random = world->randomEngine;
std::vector<GameObject*> created;
int availablePeds =
maximumPedestrians - world->pedestrianPool.objects.size();
int availableCars =
maximumCars - world->vehiclePool.objects.size();
/// @todo Check how "in player view" should be determined.
// Don't check the frustum for things more than 1/2 of the radius away
@ -148,34 +142,35 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
peds.insert(peds.end(), group.cbegin(), group.cend());
// Vehicles for normal traffic @todo create correct vehicle list
static constexpr std::array<uint16_t, 32> cars = {90, 91, 92, 94, 95, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
111, 112, 116, 119, 128, 129, 130, 134, 135, 136, 138, 139, 144, 146};
static constexpr std::array<uint16_t, 32> cars = {{
90, 91, 92, 94, 95, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
111, 112, 116, 119, 128, 129, 130, 134, 135, 136, 138, 139, 144, 146
}};
auto availablePedsNodes = findAvailableNodes(AIGraphNode::Pedestrian, camera, radius);
// We have not reached the limit of spawned pedestrians
if (availablePeds > 0) {
int counter = availablePeds;
if (maximumPedestrians > world->pedestrianPool.objects.size()) {
const auto availablePeds = maximumPedestrians - world->pedestrianPool.objects.size();
size_t counter = availablePeds;
// maxSpawn can be -1 for "as many as possible"
if (maxSpawn > -1) {
counter = std::min(availablePeds, maxSpawn);
counter = std::min(availablePeds, static_cast<size_t>(maxSpawn));
}
for (AIGraphNode* spawn : availablePedsNodes) {
if (spawn->type != AIGraphNode::Pedestrian) {
continue;
}
if (counter > -1) {
if (counter <= 0) {
break;
}
counter--;
if (counter == 0) {
break;
}
counter--;
// Spawn a pedestrian from the available pool
const uint16_t pedId = peds[std::uniform_int_distribution<>(
0, peds.size() - 1)(random)];
const auto pedId = static_cast<std::uint16_t>(
peds[std::uniform_int_distribution<size_t>(0, peds.size() - 1)(random)]);
auto ped = world->createPedestrian(pedId, spawn->position);
ped->applyOffset();
ped->setLifetime(GameObject::TrafficLifetime);
@ -187,25 +182,23 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
auto availableVehicleNodes = findAvailableNodes(AIGraphNode::Vehicle, camera, radius);
// We have not reached the limit of spawned vehicles
if (availableCars > 0) {
int counter = availableCars;
if (maximumCars > world->vehiclePool.objects.size()) {
const auto availableCars = maximumCars - world->vehiclePool.objects.size();
size_t counter = availableCars;
// maxSpawn can be -1 for "as many as possible"
if (maxSpawn > -1) {
counter = std::min(availableCars, maxSpawn);
counter = std::min(availableCars, static_cast<size_t>(maxSpawn));
}
for (AIGraphNode* spawn : availableVehicleNodes) {
if (spawn->type != AIGraphNode::Vehicle) {
continue;
}
if (counter > -1) {
if (counter <= 0) {
break;
}
counter--;
if (counter == 0) {
break;
}
counter--;
// Get the next node, to spawn in between
AIGraphNode* next = spawn->connections.at(0);
@ -243,15 +236,15 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
strafe * (2.5f + 5.f * static_cast<float>(lane - 1));
// Spawn a vehicle from the available pool
const uint16_t carId = cars[std::uniform_int_distribution<>(
0, cars.size() - 1)(random)];
const auto carId = static_cast<std::uint16_t>(cars[std::uniform_int_distribution<std::size_t>(
0, cars.size() - 1)(random)]);
auto vehicle = world->createVehicle(carId, next->position + diff + laneOffset, orientation);
vehicle->applyOffset();
vehicle->setLifetime(GameObject::TrafficLifetime);
vehicle->setHandbraking(false);
// Spawn a pedestrian and put it into the vehicle
int pedId = peds[std::uniform_int_distribution<>(0, peds.size() - 1)(random)];
const auto pedId = peds[std::uniform_int_distribution<std::size_t>(0, peds.size() - 1)(random)];
CharacterObject* character = world->createPedestrian(pedId, vehicle->getPosition());
character->setLifetime(GameObject::TrafficLifetime);
character->setCurrentVehicle(vehicle, 0);

View File

@ -39,8 +39,8 @@ private:
GameWorld* world = nullptr;
float pedDensity = 1.f;
float carDensity = 1.f;
int maximumPedestrians = 20;
int maximumCars = 10;
size_t maximumPedestrians = 20;
size_t maximumCars = 10;
};
#endif

View File

@ -70,7 +70,7 @@ struct Sound {
buffer->setMaxDistance(maxDist);
}
int getScriptObjectID() const {
size_t getScriptObjectID() const {
return id;
}
};

View File

@ -24,7 +24,8 @@ bool SoundBuffer::bufferData(SoundSource& soundSource) {
alCheck(alBufferData(
buffer,
soundSource.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16,
&soundSource.data.front(), soundSource.data.size() * sizeof(int16_t),
&soundSource.data.front(),
static_cast<ALsizei>(soundSource.data.size() * sizeof(int16_t)),
soundSource.sampleRate));
alCheck(alSourcei(source, AL_BUFFER, buffer));

View File

@ -226,7 +226,7 @@ void SoundManager::playSfx(size_t name, const glm::vec3& position, bool looping,
buffer->second.setPitch(1.f);
buffer->second.setGain(1.f);
if (maxDist != -1) {
buffer->second.setMaxDistance(maxDist);
buffer->second.setMaxDistance(static_cast<float>(maxDist));
}
buffer->second.play();
}

View File

@ -248,7 +248,7 @@ struct InputData {
/// to buffer.
static int read_packet(void* opaque, uint8_t* buf, int buf_size) {
auto* input = reinterpret_cast<InputData*>(opaque);
buf_size = FFMIN(buf_size, input->size);
buf_size = std::min(buf_size, static_cast<int>(input->size));
/* copy internal data to buf */
memcpy(buf, input->ptr, buf_size);
input->ptr += buf_size;

View File

@ -1,8 +1,10 @@
#ifndef _RWENGINE_SOUND_SOURCE_HPP_
#define _RWENGINE_SOUND_SOURCE_HPP_
#include <rw/filesystem.hpp>
#include <loaders/LoaderSDT.hpp>
#include <rw/filesystem.hpp>
#include <cstdint>
/// Opaque for raw sound,
/// cooperate with ffmpeg
@ -16,14 +18,14 @@ public:
void loadFromFile(const rwfs::path& filePath);
/// Load sound from sdt file
void loadSfx(LoaderSDT& sdt, size_t index, bool asWave = true);
void loadSfx(LoaderSDT& sdt, std::size_t index, bool asWave = true);
private:
/// Raw data
std::vector<int16_t> data;
size_t channels;
size_t sampleRate;
std::uint32_t channels;
std::uint32_t sampleRate;
};
#endif

View File

@ -96,7 +96,7 @@ void ChaseCoordinator::start() {
void ChaseCoordinator::update(float dt) {
chaseTime += dt;
size_t frameNum = chaseTime * KEYFRAMES_PER_SECOND;
auto frameNum = static_cast<size_t>(chaseTime * KEYFRAMES_PER_SECOND);
for (auto &it : chaseVehicles) {
RW_CHECK(frameNum < it.second.keyframes.size(),
"Vehicle out of chase keyframes");

View File

@ -273,7 +273,7 @@ private:
std::array<AtomicPtr, 3> atomics_;
float loddistances_[3] = {};
uint8_t numatomics_ = 0;
uint8_t alpha_ = 0; /// @todo ask aap why
// uint8_t alpha_ = 0; /// @todo ask aap why
bool isbigbuilding_ = 0;
uint8_t furthest_ = 0;

View File

@ -53,7 +53,7 @@ struct VehicleGenerator {
, remainingSpawns(remainingSpawns_) {
}
int getScriptObjectID() const {
size_t getScriptObjectID() const {
return generatorID;
}
};

View File

@ -4,7 +4,14 @@
#include <cstddef>
#include <limits>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
@ -95,9 +102,12 @@ bool CollisionInstance::createPhysicsBody(GameObject* object,
auto& faces = collision->faces;
if (!verts.empty() && !faces.empty()) {
m_vertArray = std::make_unique<btTriangleIndexVertexArray>(
faces.size(), reinterpret_cast<int*>(faces.data()),
sizeof(CollisionModel::Triangle), verts.size(),
reinterpret_cast<float*>(verts.data()), sizeof(glm::vec3));
static_cast<int>(faces.size()),
reinterpret_cast<int*>(faces.data()),
static_cast<int>(sizeof(CollisionModel::Triangle)),
static_cast<int>(verts.size()),
reinterpret_cast<float*>(verts.data()),
static_cast<int>(sizeof(glm::vec3)));
auto trishape =
std::make_unique<btBvhTriangleMeshShape>(m_vertArray.get(), false);
trishape->setMargin(0.05f);

View File

@ -1,7 +1,13 @@
#ifndef _RWENGINE_RAYCASTCALLBACKS_HPP_
#define _RWENGINE_RAYCASTCALLBACKS_HPP_
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
/**
* Implements raycast callback that ignores a specified btCollisionObject

View File

@ -1,7 +1,13 @@
#include "engine/GameWorld.hpp"
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/gtx/norm.hpp>
@ -224,8 +230,8 @@ VehicleObject* GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos,
auto palit = data->vehiclePalettes.find(
vti->name); // modelname is conveniently lowercase (usually)
if (palit != data->vehiclePalettes.end() && !palit->second.empty()) {
std::uniform_int_distribution<int> uniform(0, palit->second.size() - 1);
int set = uniform(randomEngine);
std::uniform_int_distribution<size_t> uniform(0, palit->second.size() - 1);
size_t set = uniform(randomEngine);
prim = data->vehicleColours[palit->second[set].first];
sec = data->vehicleColours[palit->second[set].second];
} else {
@ -394,13 +400,13 @@ PickupObject* GameWorld::createPickup(const glm::vec3& pos, int id, int type) {
Garage* GameWorld::createGarage(const glm::vec3 coord0, const glm::vec3 coord1,
Garage::Type type) {
const int id = garages.size();
const size_t id = garages.size();
garages.emplace_back(std::make_unique<Garage>(this, id, coord0, coord1, type));
return garages.back().get();
}
Payphone* GameWorld::createPayphone(const glm::vec2 coord) {
int id = payphones.size();
const size_t id = payphones.size();
payphones.emplace_back(std::make_unique<Payphone>(this, id, coord));
return payphones.back().get();
}

View File

@ -9,7 +9,14 @@
#include <string>
#include <vector>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <LinearMath/btScalar.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>

View File

@ -1,6 +1,13 @@
#include "Garage.hpp"
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/gtx/quaternion.hpp>
#include "dynamics/CollisionInstance.hpp"
@ -14,8 +21,8 @@
#include "objects/InstanceObject.hpp"
#include "objects/VehicleObject.hpp"
Garage::Garage(GameWorld* engine_, const int id_, const glm::vec3 coord0,
const glm::vec3 coord1, const Type type_)
Garage::Garage(GameWorld* engine_, size_t id_, const glm::vec3& coord0,
const glm::vec3& coord1, Type type_)
: engine(engine_), id(id_), type(type_) {
min.x = std::min(coord0.x, coord1.x);
min.y = std::min(coord0.y, coord1.y);

View File

@ -72,9 +72,9 @@ public:
enum class State { Closed, Closing, Opening, Opened };
GameWorld* engine;
int id;
size_t id;
int getScriptObjectID() const {
size_t getScriptObjectID() const {
return id;
}
@ -91,8 +91,8 @@ public:
bool resprayDone = false;
Garage(GameWorld* engine_, const int id_, const glm::vec3 coord0,
const glm::vec3 coord1, const Type type_);
Garage(GameWorld* engine_, size_t id_, const glm::vec3& coord0,
const glm::vec3& coord1, Type type_);
~Garage() = default;
void makeDoorSwing();

View File

@ -11,7 +11,7 @@
#include "objects/GameObject.hpp"
#include "objects/InstanceObject.hpp"
Payphone::Payphone(GameWorld* engine_, const int id_, const glm::vec2 coord)
Payphone::Payphone(GameWorld* engine_, size_t id_, const glm::vec2& coord)
: engine(engine_), id(id_) {
// Find payphone object, original game does this differently
for (const auto& p : engine->instancePool.objects) {

View File

@ -26,13 +26,13 @@ public:
State state = State::Idle;
int id;
size_t id;
int getScriptObjectID() const {
size_t getScriptObjectID() const {
return id;
}
Payphone(GameWorld* engine_, const int id_, const glm::vec2 coord);
Payphone(GameWorld* engine_, size_t id_, const glm::vec2& coord);
~Payphone() = default;
// Makes a payphone ring
@ -46,4 +46,4 @@ public:
void tick(float dt);
};
#endif
#endif

View File

@ -5,7 +5,7 @@
#include "fonts/FontMapGta3.hpp"
void ScreenText::tick(float dt) {
int millis = dt * 1000;
int millis = static_cast<int>(dt * 1000);
// Remove all the immedate text
m_textQueues[static_cast<size_t>(ScreenTextType::Immediate)].clear();

View File

@ -16,7 +16,7 @@ void Weapon::fireHitscan(WeaponData* weapon, CharacterObject* owner) {
const auto& raydirection = owner->getLookDirection();
const auto rayend = owner->getPosition() + raydirection * weapon->hitRange;
auto fireOrigin = glm::vec3(handMatrix[3]);
float dmg = weapon->damage;
float dmg = static_cast<float>(weapon->damage);
owner->engine->doWeaponScan({dmg, fireOrigin, rayend, weapon});
}

View File

@ -5,9 +5,15 @@
#include <cstdlib>
#include <memory>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#include <BulletDynamics/Character/btKinematicCharacterController.h>
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <rw/debug.hpp>

View File

@ -3,8 +3,14 @@
#include <cstdint>
#include <string>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <btBulletDynamicsCommon.h>
#include <glm/gtc/quaternion.hpp>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <rw/types.hpp>

View File

@ -2,8 +2,15 @@
#include <cmath>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/gtc/quaternion.hpp>
#include "ai/PlayerController.hpp"
@ -191,9 +198,9 @@ void PickupObject::tick(float dt) {
float time = engine->getGameTime();
float colourValue = 0.5f * (std::sin(time * 3.0664064f) * 0.3f + 0.3f);
uint32_t* colour = &colours[m_colourId];
float red = (*colour >> 16) & 0xFF;
float green = (*colour >> 8) & 0xFF;
float blue = *colour & 0xFF;
float red = static_cast<float>((*colour >> 16) & 0xFF);
float green = static_cast<float>((*colour >> 8) & 0xFF);
float blue = static_cast<float>(*colour & 0xFF);
m_corona.colour =
glm::vec4(red / 255.f, green / 255.f, blue / 255.f, 1.f) * colourValue;
@ -402,9 +409,11 @@ bool CollectablePickup::onPlayerTouch() {
auto text = ScreenText::format(
engine->data->texts.text(gxtEntry),
GameStringUtil::fromString(
std::to_string(state->playerInfo.hiddenPackagesCollected), FONT_PRICEDOWN),
std::to_string(state->playerInfo.hiddenPackagesCollected),
FONT_PRICEDOWN),
GameStringUtil::fromString(
std::to_string(state->playerInfo.hiddenPackageCount), FONT_PRICEDOWN));
std::to_string(state->playerInfo.hiddenPackageCount),
FONT_PRICEDOWN));
state->text.addText<ScreenTextType::HiddenPackageText>(
ScreenTextEntry::makeHiddenPackageText(gxtEntry, text));

View File

@ -17,7 +17,7 @@ class BaseModelInfo;
class GameWorld;
class CharacterObject;
class VehicleObject;
class VisualFX;
struct VisualFX;
/**
* @brief The PickupObject class
@ -234,7 +234,7 @@ public:
bool onPlayerTouch() override;
};
const static std::array<glm::vec3, 106> bigNVeinyPickupsLocations = {
constexpr static std::array<glm::vec3, 106> bigNVeinyPickupsLocations = {{
glm::vec3(913.62219f, -155.13692f, 4.9699469f),
glm::vec3(913.92401f, -124.12943f, 4.9692569f),
glm::vec3(913.27899f, -93.524231f, 7.4325991f),
@ -340,7 +340,8 @@ const static std::array<glm::vec3, 106> bigNVeinyPickupsLocations = {
glm::vec3(1481.5685f, -701.30237f, 11.977908f),
glm::vec3(1511.4004f, -696.83295f, 11.972709f),
glm::vec3(1542.1796f, -695.61676f, 11.970441f),
glm::vec3(1570.3301f, -684.6239f, 11.969202f)};
glm::vec3(1570.3301f, -684.6239f, 11.969202f),
}};
/**
* @brief The BigNVeinyPickup class

View File

@ -1,7 +1,14 @@
#include "objects/ProjectileObject.hpp"
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/gtc/quaternion.hpp>
#include "data/WeaponData.hpp"
@ -55,7 +62,7 @@ void ProjectileObject::explode() {
const float exp_size = 10.f;
const float damageSize = 5.f;
const float damage = _info.weapon->damage;
const float damage = static_cast<float>(_info.weapon->damage);
for (auto& o : engine->allObjects) {
if (o == this) continue;

View File

@ -5,8 +5,15 @@
#include <cstdlib>
#include <limits>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletDynamics/Vehicle/btRaycastVehicle.h>
#include <btBulletDynamicsCommon.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/gtx/quaternion.hpp>
#include <data/Clump.hpp>
@ -1042,7 +1049,7 @@ float VehicleObject::isInFront(const glm::vec3& point) {
normal = glm::normalize(normal);
const glm::vec3 vecTemp(testPoint.x - v1.x, 0, testPoint.y - v1.y);
double distance = glm::dot(vecTemp, normal);
float distance = glm::dot(vecTemp, normal);
return distance;
}
@ -1073,7 +1080,7 @@ float VehicleObject::isOnSide(const glm::vec3& point) {
normal = glm::normalize(normal);
const glm::vec3 vecTemp(testPoint.x - v1.x, 0, testPoint.y - v1.y);
double distance = glm::dot(vecTemp, normal);
float distance = glm::dot(vecTemp, normal);
return distance;
}

View File

@ -7,7 +7,15 @@
#include <string>
#include <unordered_map>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <btBulletDynamicsCommon.h>
#include <LinearMath/btScalar.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
@ -15,7 +23,6 @@
#include <objects/GameObject.hpp>
#include <objects/VehicleInfo.hpp>
#include <btBulletDynamicsCommon.h>
class Atomic;
class CharacterObject;

View File

@ -3,7 +3,14 @@
#include <iostream>
#include <glm/glm.hpp>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <LinearMath/btVector3.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <data/Clump.hpp>
#include <gl/DrawBuffer.hpp>
@ -61,7 +68,7 @@ void DebugDraw::flush(GameRenderer *renderer) {
dbuff->addGeometry(lineBuff.get());
Renderer::DrawParameters dp;
dp.textures = {texture};
dp.textures = {{texture}};
dp.ambient = 1.f;
dp.colour = glm::u8vec4(255, 255, 255, 255);
dp.start = 0;

View File

@ -4,8 +4,14 @@
#include <cstddef>
#include <vector>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <LinearMath/btIDebugDraw.h>
#include <LinearMath/btScalar.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <data/Clump.hpp>
#include <gl/gl_core_3_3.h>

View File

@ -25,12 +25,7 @@
#include "render/GameShaders.hpp"
#include "render/VisualFX.hpp"
const size_t skydomeSegments = 8, skydomeRows = 10;
constexpr uint32_t kMissingTextureBytes[] = {
0xFF0000FF, 0xFFFF00FF, 0xFF0000FF, 0xFFFF00FF, 0xFFFF00FF, 0xFF0000FF,
0xFFFF00FF, 0xFF0000FF, 0xFF0000FF, 0xFFFF00FF, 0xFF0000FF, 0xFFFF00FF,
0xFFFF00FF, 0xFF0000FF, 0xFFFF00FF, 0xFF0000FF,
};
constexpr size_t skydomeSegments = 8, skydomeRows = 10;
/// @todo collapse all of these into "VertPNC" etc.
struct ParticleVert {
@ -80,13 +75,6 @@ GameRenderer::GameRenderer(Logger* log, GameData* _data)
glGenVertexArrays(1, &vao);
glGenTextures(1, &m_missingTexture);
glBindTexture(GL_TEXTURE_2D, m_missingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
kMissingTextureBytes);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenFramebuffers(1, &framebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, framebufferName);
glGenTextures(2, fbTextures);
@ -144,12 +132,12 @@ GameRenderer::GameRenderer(Logger* log, GameData* _data)
skydomeIndBuff.resize(rows * segments * 6);
for (size_t r = 0, i = 0; r < (rows - 1); ++r) {
for (size_t s = 0; s < (segments - 1); ++s) {
skydomeIndBuff[i++] = r * segments + s;
skydomeIndBuff[i++] = r * segments + (s + 1);
skydomeIndBuff[i++] = (r + 1) * segments + (s + 1);
skydomeIndBuff[i++] = r * segments + s;
skydomeIndBuff[i++] = (r + 1) * segments + (s + 1);
skydomeIndBuff[i++] = (r + 1) * segments + s;
skydomeIndBuff[i++] = static_cast<GLuint>(r * segments + s);
skydomeIndBuff[i++] = static_cast<GLuint>(r * segments + (s + 1));
skydomeIndBuff[i++] = static_cast<GLuint>((r + 1) * segments + (s + 1));
skydomeIndBuff[i++] = static_cast<GLuint>(r * segments + s);
skydomeIndBuff[i++] = static_cast<GLuint>((r + 1) * segments + (s + 1));
skydomeIndBuff[i++] = static_cast<GLuint>((r + 1) * segments + s);
}
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, skydomeIBO);
@ -325,11 +313,11 @@ RenderList GameRenderer::createObjectRenderList(const GameWorld *world) {
// run in parallel with a good threading system.
RenderList renderList;
// Naive optimisation, assume 50% hitrate
renderList.reserve(world->allObjects.size() * 0.5f);
renderList.reserve(static_cast<size_t>(world->allObjects.size() * 0.5f));
ObjectRenderer objectRenderer(_renderWorld,
(cullOverride ? cullingCamera : _camera),
_renderAlpha, getMissingTexture());
_renderAlpha);
// World Objects
for (auto object : world->allObjects) {
@ -421,7 +409,7 @@ void GameRenderer::renderSplash(GameWorld* world, GLuint splashTexName, glm::u16
wdp.depthMode = DepthMode::OFF;
wdp.blendMode = BlendMode::BLEND_ALPHA;
wdp.count = ssRectGeom.getCount();
wdp.textures = {splashTexName};
wdp.textures = {{splashTexName}};
renderer->drawArrays(glm::mat4(1.0f), &ssRectDraw, wdp);
}
@ -437,7 +425,7 @@ void GameRenderer::renderPostProcess() {
Renderer::DrawParameters wdp;
wdp.start = 0;
wdp.count = ssRectGeom.getCount();
wdp.textures = {fbTextures[0]};
wdp.textures = {{fbTextures[0]}};
wdp.depthMode = DepthMode::OFF;
renderer->drawArrays(glm::mat4(1.0f), &ssRectDraw, wdp);
@ -488,7 +476,7 @@ void GameRenderer::renderEffects(GameWorld* world) {
glm::vec3(particle->size,1.0f)) * glm::inverse(lookMat);
Renderer::DrawParameters dp;
dp.textures = {particle->texture->getName()};
dp.textures = {{particle->texture->getName()}};
dp.ambient = 1.f;
dp.colour = glm::u8vec4(particle->colour * 255.f);
dp.start = 0;
@ -529,7 +517,7 @@ void GameRenderer::drawRect(const glm::vec4& colour, TextureData* texture, glm::
wdp.depthMode = DepthMode::OFF;
wdp.blendMode = BlendMode::BLEND_ALPHA;
wdp.count = ssRectGeom.getCount();
wdp.textures = {texture ? texture->getName() : 0};
wdp.textures = {{texture ? texture->getName() : 0}};
renderer->drawArrays(glm::mat4(1.0f), &ssRectDraw, wdp);
}
@ -544,7 +532,7 @@ void GameRenderer::renderLetterbox() {
wdp.depthMode = DepthMode::OFF;
wdp.blendMode = BlendMode::BLEND_NONE;
wdp.count = ssRectGeom.getCount();
wdp.textures = {0};
wdp.textures = {{0}};
renderer->drawArrays(glm::mat4(1.0f), &ssRectDraw, wdp);
renderer->setUniform(ssRectProg.get(), "offset", glm::vec2{0.f, 1.f * (1.f - cinematicExperienceSize)});

View File

@ -59,9 +59,6 @@ class GameRenderer {
GLuint fbRenderBuffers[1];
std::unique_ptr<Renderer::ShaderProgram> postProg;
/// Texture used to replace textures missing from the data
GLuint m_missingTexture;
GeometryBuffer particleGeom;
DrawBuffer particleDraw;
@ -88,10 +85,6 @@ public:
return data;
}
GLuint getMissingTexture() const {
return m_missingTexture;
}
size_t getCulledCount() {
return culled;
}

View File

@ -125,7 +125,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
std::string num = (m < 10 ? "0" : "");
std::string name = "radar" + num + std::to_string(m);
auto texture = world->data->findSlotTexture(name, name);
dp.textures = {texture->getName()};
dp.textures = {{texture->getName()}};
dp.count = 4;
@ -152,7 +152,7 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ONE, GL_ZERO);
TextureData::Handle radarDisc =
data->findSlotTexture("hud", "radardisc");
dp.textures = {radarDisc->getName()};
dp.textures = {{radarDisc->getName()}};
glm::mat4 model{1.0f};
model = glm::translate(model, glm::vec3(mi.screenPosition, 0.0f));

View File

@ -51,7 +51,7 @@ void ObjectRenderer::renderGeometry(Geometry* geom,
dp.colour = {255, 255, 255, 255};
dp.count = subgeom.numIndices;
dp.start = subgeom.start;
dp.textures = {0};
dp.textures = {{0}};
dp.visibility = 1.f;
if (object && object->type() == GameObject::Instance) {
@ -69,7 +69,7 @@ void ObjectRenderer::renderGeometry(Geometry* geom,
if (tex->isTransparent()) {
isTransparent = true;
}
dp.textures = {tex->getName()};
dp.textures = {{tex->getName()}};
}
}
@ -277,9 +277,9 @@ void ObjectRenderer::renderVehicle(VehicleObject* vehicle,
auto wheelatomic = woi->getDistanceAtomic(mindist);
for (size_t w = 0; w < vehicle->info->wheels.size(); ++w) {
auto& wi = vehicle->physVehicle->getWheelInfo(w);
auto& wi = vehicle->physVehicle->getWheelInfo(static_cast<int>(w));
// Construct our own matrix so we can use the local transform
vehicle->physVehicle->updateWheelTransform(w, false);
vehicle->physVehicle->updateWheelTransform(static_cast<int>(w), false);
bool isRhino = (vehicle->getVehicle()->vehiclename_ == "RHINO");
auto up = -wi.m_wheelDirectionCS;

View File

@ -35,11 +35,10 @@ struct Geometry;
class ObjectRenderer {
public:
ObjectRenderer(GameWorld* world, const ViewCamera& camera,
float renderAlpha, GLuint errorTexture)
float renderAlpha)
: m_world(world)
, m_camera(camera)
, m_renderAlpha(renderAlpha)
, m_errorTexture(errorTexture) {
, m_renderAlpha(renderAlpha) {
}
/**
@ -69,12 +68,10 @@ public:
* @param render
*/
void renderClump(Clump* model, const glm::mat4& worldtransform, GameObject* object, RenderList& render);
private:
GameWorld* m_world;
const ViewCamera& m_camera;
float m_renderAlpha;
GLuint m_errorTexture;
void renderInstance(InstanceObject* instance, RenderList& outList);
void renderCharacter(CharacterObject* pedestrian, RenderList& outList);

View File

@ -299,7 +299,8 @@ void OpenGLRenderer::draw(const glm::mat4& model, DrawBuffer* draw,
const Renderer::DrawParameters& p) {
setDrawState(model, draw, p);
glDrawElements(draw->getFaceType(), p.count, GL_UNSIGNED_INT,
glDrawElements(draw->getFaceType(), static_cast<GLsizei>(p.count),
GL_UNSIGNED_INT,
reinterpret_cast<void*>(sizeof(RenderIndex) * p.start));
}
@ -307,7 +308,7 @@ void OpenGLRenderer::drawArrays(const glm::mat4& model, DrawBuffer* draw,
const Renderer::DrawParameters& p) {
setDrawState(model, draw, p);
glDrawArrays(draw->getFaceType(), p.start, p.count);
glDrawArrays(draw->getFaceType(), static_cast<GLint>(p.start), static_cast<GLsizei>(p.count));
}
void OpenGLRenderer::drawBatched(const RenderList& list) {

View File

@ -85,7 +85,7 @@ public:
/// Number of indices
size_t count{};
/// Start index.
unsigned int start{};
size_t start{};
/// Textures to use
Textures textures{};
/// Blending mode
@ -403,7 +403,7 @@ private:
template <class T>
void uploadUBO(Buffer& buffer, const T& data) {
uploadUBOEntry(buffer, &data, sizeof(T));
#ifdef RW_PROFILER
#ifdef RW_GRAPHICS_STATS
if (currentDebugDepth > 0) {
profileInfo[currentDebugDepth - 1].uploads++;
}
@ -425,7 +425,9 @@ private:
// Debug group profiling timers
ProfileInfo profileInfo[MAX_DEBUG_DEPTH];
GLuint debugQuery;
#ifdef RW_GRAPHICS_STATS
int currentDebugDepth = 0;
#endif
};
/// @todo remove these from here

View File

@ -20,10 +20,10 @@ unsigned charToIndex(std::uint16_t g) {
return g - 32;
}
glm::vec4 indexToTexCoord(int index, const glm::u32vec2 &textureSize, const glm::u8vec2 &glyphOffset) {
static glm::vec4 indexToTexCoord(size_t index, const glm::u32vec2 &textureSize, const glm::u8vec2 &glyphOffset) {
constexpr unsigned TEXTURE_COLUMNS = 16;
const float x = index % TEXTURE_COLUMNS;
const float y = index / TEXTURE_COLUMNS;
const float x = static_cast<float>(index % TEXTURE_COLUMNS);
const float y = static_cast<float>(index / TEXTURE_COLUMNS);
// Add offset to avoid 'leakage' between adjacent glyphs
float s = (x * glyphOffset.x + 0.5f) / textureSize.x;
float t = (y * glyphOffset.y + 0.5f) / textureSize.y;
@ -70,7 +70,7 @@ void main()
constexpr size_t GLYPHS_NB = 193;
using FontWidthLut = std::array<std::uint8_t, GLYPHS_NB>;
constexpr std::array<std::uint8_t, 193> fontWidthsPager = {
constexpr std::array<std::uint8_t, 193> fontWidthsPager = {{
3, 3, 6, 8, 6, 10, 8, 3, 5, 5, 7, 0, 3, 7, 3, 0, // 1
6, 4, 6, 6, 7, 6, 6, 6, 6, 6, 3, 0, 0, 0, 0, 6, // 2
0, 6, 6, 6, 6, 6, 6, 6, 6, 3, 6, 6, 5, 8, 7, 6, // 3
@ -84,9 +84,9 @@ constexpr std::array<std::uint8_t, 193> fontWidthsPager = {
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 11
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // 12
8,
};
}};
constexpr std::array<std::uint8_t, 193> fontWidthsPriceDown = {
constexpr std::array<std::uint8_t, 193> fontWidthsPriceDown = {{
11, 13, 30, 27, 20, 24, 22, 12, 14, 14, 0, 26, 9, 14, 9, 26, // 1
20, 19, 20, 20, 22, 20, 20, 19, 20, 20, 13, 29, 24, 29, 24, 20, // 2
27, 20, 20, 20, 20, 20, 17, 20, 20, 10, 20, 20, 15, 30, 20, 20, // 3
@ -100,9 +100,9 @@ constexpr std::array<std::uint8_t, 193> fontWidthsPriceDown = {
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // 11
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // 12
16,
};
}};
constexpr std::array<std::uint8_t, 193> fontWidthsArial = {
constexpr std::array<std::uint8_t, 193> fontWidthsArial = {{
27, 25, 55, 43, 47, 65, 53, 19, 29, 31, 21, 45, 23, 35, 27, 29, // 1
47, 33, 45, 43, 49, 47, 47, 41, 47, 45, 25, 23, 53, 43, 53, 39, // 2
61, 53, 51, 47, 49, 45, 43, 49, 53, 23, 41, 53, 45, 59, 53, 51, // 3
@ -116,7 +116,7 @@ constexpr std::array<std::uint8_t, 193> fontWidthsArial = {
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19, // 11
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // 12
19,
};
}};
}
@ -284,7 +284,7 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
// will need to be wrapped
if (ti.wrapX > 0 && coord.x > 0.f && !std::isspace(c)) {
auto wend = std::find_if(std::begin(text) + i, std::end(text),
[](char x) { return std::isspace(x); });
[](auto c) { return std::isspace(c); });
if (wend != std::end(text)) {
auto word = std::distance(std::begin(text) + i, wend);
if (lineLength + word >= ti.wrapX) {
@ -350,7 +350,7 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
dp.blendMode = BlendMode::BLEND_ALPHA;
dp.count = gb.getCount();
auto ftexture = renderer->getData()->findSlotTexture("fonts", fontMetaData.textureName);
dp.textures = {ftexture->getName()};
dp.textures = {{ftexture->getName()}};
dp.depthMode = DepthMode::OFF;
renderer->getRenderer()->drawArrays(glm::mat4(1.0f), &db, dp);

View File

@ -32,9 +32,9 @@ public:
}
void update(const glm::mat4& proj) {
for (size_t i = 0; i < 6; ++i) {
for (auto i = 0u; i < 6; ++i) {
float sign = (i % 2 == 0) ? 1.f : -1.f;
int r = i / 2;
auto r = i / 2;
planes[i].normal.x = proj[0][3] + proj[0][r] * sign;
planes[i].normal.y = proj[1][3] + proj[1][r] * sign;
planes[i].normal.z = proj[2][3] + proj[2][r] * sign;

View File

@ -49,7 +49,7 @@ WaterRenderer::WaterRenderer(GameRenderer* renderer) {
}
}
gridGeom.uploadVertices(grid.size(), sizeof(glm::vec2) * grid.size(),
gridGeom.uploadVertices(static_cast<GLsizei>(grid.size()), sizeof(glm::vec2) * grid.size(),
grid.data());
gridGeom.getDataAttributes().emplace_back(ATRS_Position, 2, 0, 0, GL_FLOAT);
gridDraw.addGeometry(&gridGeom);
@ -58,15 +58,15 @@ WaterRenderer::WaterRenderer(GameRenderer* renderer) {
void WaterRenderer::setWaterTable(const float* waterHeights, const unsigned int nHeights,
const uint8_t* tiles, const unsigned int nTiles) {
// Determine the dimensions of the input tiles
int edgeNum = sqrt(nTiles);
auto edgeNum = static_cast<unsigned int>(sqrt(nTiles));
float tileSize = WATER_WORLD_SIZE / edgeNum;
glm::vec2 wO{-WATER_WORLD_SIZE / 2.f, -WATER_WORLD_SIZE / 2.f};
std::vector<glm::vec3> vertexData;
for (int x = 0; x < edgeNum; x++) {
for (auto x = 0u; x < edgeNum; x++) {
int xi = x * WATER_HQ_DATA_SIZE;
for (int y = 0; y < edgeNum; y++) {
for (auto y = 0u; y < edgeNum; y++) {
if (tiles[xi + y] >= nHeights) continue;
// Tiles with the magic value contain no water.
@ -87,7 +87,7 @@ void WaterRenderer::setWaterTable(const float* waterHeights, const unsigned int
}
}
maskGeom.uploadVertices(vertexData.size(),
maskGeom.uploadVertices(static_cast<GLsizei>(vertexData.size()),
sizeof(glm::vec3) * vertexData.size(),
vertexData.data());
maskGeom.getDataAttributes().emplace_back(ATRS_Position, 3, 0, 0, GL_FLOAT);
@ -112,7 +112,7 @@ void WaterRenderer::render(GameRenderer* renderer, GameWorld* world) {
Renderer::DrawParameters wdp;
wdp.start = 0;
wdp.count = maskGeom.getCount();
wdp.textures = {0};
wdp.textures = {{0}};
glm::mat4 m(1.0);
glEnable(GL_STENCIL_TEST);
@ -147,7 +147,7 @@ void WaterRenderer::render(GameRenderer* renderer, GameWorld* world) {
r->setUniform(waterProg.get(), "inverseVP", ivp);
wdp.count = gridGeom.getCount();
wdp.textures = {waterTex->getName(), dataTexture};
wdp.textures = {{waterTex->getName(), dataTexture}};
r->drawArrays(m, &gridDraw, wdp);

View File

@ -3,7 +3,7 @@
#include <algorithm>
#include <cstddef>
void SCMFile::loadFile(char *data, unsigned int size) {
void SCMFile::loadFile(char *data, size_t size) {
_data = std::make_unique<SCMByte[]>(size);
std::copy(data, data + size, _data.get());

View File

@ -29,7 +29,7 @@ public:
return _data.get();
}
void loadFile(char* data, unsigned int size);
void loadFile(char* data, size_t size);
SCMByte* data() const {
return _data.get();

View File

@ -228,7 +228,7 @@ SCMByte* ScriptMachine::getGlobals() {
void ScriptMachine::execute(float dt) {
RW_PROFILE_SCOPEC(__func__, MP_ORANGERED);
int ms = dt * 1000.f;
int ms = static_cast<int>(dt * 1000.f);
for (auto t = _activeThreads.begin(); t != _activeThreads.end(); ++t) {
auto& thread = *t;
executeThread(thread, ms);

View File

@ -167,15 +167,14 @@ public:
template <typename T>
typename std::enable_if<std::is_integral<T>::value, T>::type
getRandomNumber(T min, T max) {
std::uniform_int_distribution<> dist(min, max);
std::uniform_int_distribution<T> dist(min, max);
return dist(randomNumberGen);
}
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value, T>::type
getRandomNumber(T min, T max) {
std::uniform_real_distribution<> dist(static_cast<double>(min),
static_cast<double>(max));
std::uniform_real_distribution<T> dist(min, max);
return dist(randomNumberGen);
}

View File

@ -77,7 +77,7 @@ struct ScriptObjectType {
T* operator=(T* object) {
RW_CHECK(m_id != nullptr,
"ScriptObjectType has pointer to null memory location");
*m_id = object->getScriptObjectID();
*m_id = static_cast<ScriptInt>(object->getScriptObjectID());
m_object = object;
return object;
}

View File

@ -5456,7 +5456,7 @@ void opcode_01e8(const ScriptArguments& args, ScriptVec3 coord0, ScriptVec3 coor
void opcode_01e9(const ScriptArguments& args, const ScriptVehicle vehicle,
ScriptInt& numOfPassengers) {
RW_UNUSED(args);
numOfPassengers = vehicle->seatOccupants.size();
numOfPassengers = static_cast<int>(vehicle->seatOccupants.size());
}
/**
@ -5469,7 +5469,7 @@ void opcode_01e9(const ScriptArguments& args, const ScriptVehicle vehicle,
void opcode_01ea(const ScriptArguments& args, const ScriptVehicle vehicle,
ScriptInt& maxNumOfPassengers) {
RW_UNUSED(args);
maxNumOfPassengers = vehicle->info->seats.size();
maxNumOfPassengers = static_cast<int>(vehicle->info->seats.size());
}
/**
@ -7740,7 +7740,7 @@ void opcode_02dd(const ScriptArguments& args, const ScriptString areaName, Scrip
}
// Only return a result if we found a character
unsigned int candidateCount = candidates.size();
const auto candidateCount = candidates.size();
if (candidateCount > 0) {
// Return the handle for any random character in this zone and use lifetime for use by script
// @todo verify if the lifetime is actually changed in the original game

View File

@ -8,21 +8,28 @@ set(RWGAME_SOURCES
GameBase.hpp
GameBase.cpp
RWGame.hpp
RWGame.cpp
GameConfig.hpp
GameConfig.cpp
GameWindow.hpp
GameWindow.cpp
DrawUI.cpp
DrawUI.hpp
MenuSystem.hpp
MenuSystem.cpp
GameInput.hpp
GameInput.cpp
game.hpp
WindowIcon.hpp
StateManager.hpp
StateManager.cpp
State.hpp
State.cpp
MenuSystem.hpp
MenuSystem.cpp
GameInput.hpp
GameInput.cpp
states/LoadingState.hpp
states/LoadingState.cpp
states/IngameState.hpp
@ -36,7 +43,6 @@ set(RWGAME_SOURCES
states/BenchmarkState.hpp
states/BenchmarkState.cpp
DrawUI.cpp
)
add_executable(rwgame
@ -55,8 +61,7 @@ target_link_libraries(rwgame
SDL2::SDL2
)
openrw_target_apply_options(TARGET rwgame)
install(TARGETS rwgame
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
openrw_target_apply_options(
TARGET rwgame
INSTALL INSTALL_PDB
)

View File

@ -37,8 +37,8 @@ constexpr float ui_worldSizeMax = 300.f;
void drawScriptTimer(GameWorld* world, GameRenderer* render) {
if (world->state->scriptTimerVariable) {
float scriptTimerTextX =
render->getRenderer()->getViewport().x - ui_outerMargin;
float scriptTimerTextX = static_cast<float>(
render->getRenderer()->getViewport().x - ui_outerMargin);
float scriptTimerTextY = ui_scriptTimerHeight;
TextRenderer::TextInfo ti;
@ -97,13 +97,13 @@ void drawMap(ViewCamera& currentView, PlayerController* player,
void drawPlayerInfo(PlayerController* player, GameWorld* world,
GameRenderer* render) {
float infoTextX = render->getRenderer()->getViewport().x -
(ui_outerMargin + ui_weaponSize + ui_infoMargin);
float infoTextX = static_cast<float>(render->getRenderer()->getViewport().x -
(ui_outerMargin + ui_weaponSize + ui_infoMargin));
float infoTextY = 0.f + ui_outerMargin;
float iconX = render->getRenderer()->getViewport().x -
(ui_outerMargin + ui_weaponSize);
float iconX = static_cast<float>(render->getRenderer()->getViewport().x -
(ui_outerMargin + ui_weaponSize));
float iconY = ui_outerMargin;
float wantedX = render->getRenderer()->getViewport().x - (ui_outerMargin);
float wantedX = static_cast<float>(render->getRenderer()->getViewport().x - ui_outerMargin);
float wantedY = ui_wantedLevelHeight;
TextRenderer::TextInfo ti;
@ -292,7 +292,7 @@ void drawOnScreenText(GameWorld* world, GameRenderer* renderer) {
for (auto& l : alltext) {
for (auto& t : l) {
ti.size = t.size;
ti.size = static_cast<float>(t.size);
ti.font = t.font;
ti.text = t.text;
ti.wrapX = t.wrapX;

View File

@ -1,4 +1,5 @@
#pragma once
#ifndef _RWGAME_DRAWUI_HPP_
#define _RWGAME_DRAWUI_HPP_
#include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp>
@ -8,3 +9,5 @@ void drawHUD(ViewCamera& currentView, PlayerController* player,
GameWorld* world, GameRenderer* render);
void drawOnScreenText(GameWorld* world, GameRenderer* renderer);
#endif

View File

@ -104,7 +104,7 @@ struct BoolTranslator {
boost::optional<external_type> res;
try {
res = std::stoi(stripComments(str)) != 0;
} catch (std::invalid_argument &e) {
} catch (std::invalid_argument &) {
}
return res;
}
@ -120,7 +120,7 @@ struct IntTranslator {
boost::optional<external_type> res;
try {
res = std::stoi(stripComments(str));
} catch (std::invalid_argument &e) {
} catch (std::invalid_argument &) {
}
return res;
}
@ -191,6 +191,7 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType,
try {
sourceValue = srcTree.get<config_t>(key, translator);
} catch (pt::ptree_bad_path &e) {
RW_UNUSED(e);
// Catches missing key-value pairs: fail when required
if (!optional) {
parseResult.failRequiredMissing(key);
@ -199,6 +200,7 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType,
}
sourceValue = defaultValue;
} catch (pt::ptree_bad_data &e) {
RW_UNUSED(e);
// Catches illegal value data: always fail
parseResult.failInvalidData(key);
RW_MESSAGE(e.what());

View File

@ -15,7 +15,7 @@ void GameWindow::create(const std::string& title, size_t w, size_t h,
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, w, h, style);
SDL_WINDOWPOS_CENTERED, static_cast<int>(w), static_cast<int>(h), style);
if (window == nullptr) {
// Window creation failure is fatal
std::string sdlErrorStr = SDL_GetError();

View File

@ -116,7 +116,7 @@ public:
glm::vec2 c(x - offset.x, y - offset.y);
for (size_t i = 0; i < entries.size(); ++i) {
if (c.y > 0.f && c.y < size) {
activeEntry = i;
activeEntry = static_cast<int>(i);
return;
} else {
c.y -= size;
@ -149,7 +149,7 @@ public:
if (activeEntry >= static_cast<int>(entries.size())) {
activeEntry = 0;
} else if (activeEntry < 0) {
activeEntry = entries.size() - 1;
activeEntry = static_cast<int>(entries.size() - 1);
}
}

View File

@ -211,20 +211,21 @@ void RWGame::handleCheatInput(char symbol) {
});
checkForCheat("GUNSGUNSGUNS", [&] {
constexpr std::array<int, 11> ammo = {1, //baseball bat
100,//pistol
100,//uzi
20, //shotgun
5, //grenade
5, //molotov
5, //rocket launcher
20, //flamethrower
200,//ak47
200,//m16
5 //sniper rifle
};
constexpr std::array<int, 11> ammo = {{
1, //baseball bat
100,//pistol
100,//uzi
20, //shotgun
5, //grenade
5, //molotov
5, //rocket launcher
20, //flamethrower
200,//ak47
200,//m16
5 //sniper rifle
}};
for (std::array<int, 11>::size_type i = 0; i < ammo.size(); i++)
player->addToInventory(i+1,ammo[i]);
player->addToInventory(static_cast<int>(i+1),ammo[i]);
state.showHelpMessage("CHEAT2"); // III / VC: Inputting weapon cheats.
});

View File

@ -3,8 +3,14 @@
#include <chrono>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
// FIXME: should be in rwengine, deeply hidden
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>

View File

@ -15,7 +15,7 @@ int main(int argc, char* argv[]) {
RWGame game(logger, argc, argv);
return game.run();
} catch (std::invalid_argument& ex) {
} catch (std::invalid_argument&) {
// This exception is thrown when either an invalid command line option
// or a --help is found. The RWGame constructor prints a usage message
// in this case and then throws this exception.

View File

@ -214,11 +214,11 @@ std::shared_ptr<Menu> DebugState::createWeatherMenu() {
Menu::create({{"Back", [=] { this->enterMenu(createDebugMenu()); }}},
kDebugFont, kDebugEntryHeight);
const std::array<std::string, 4> w{"Sunny", "Cloudy", "Rainy", "Foggy"};
const std::array<std::string, 4> w{{"Sunny", "Cloudy", "Rainy", "Foggy"}};
for (std::size_t i = 0; i < w.size(); ++i) {
menu->lambda(w[i],
[=] { game->getWorld()->state->basic.nextWeather = i; });
[=] { game->getWorld()->state->basic.nextWeather = static_cast<std::uint16_t>(i); });
}
menu->offset = kDebugMenuOffset;
@ -230,7 +230,7 @@ std::shared_ptr<Menu> DebugState::createMissionsMenu() {
Menu::create({{"Back", [=] { this->enterMenu(createDebugMenu()); }}},
kDebugFont, kDebugEntryHeightMissions);
const std::array<std::string, 80> w{
const std::array<std::string, 80> w{{
"Intro Movie",
"Hospital Info Scene",
"Police Station Info Scene",
@ -311,7 +311,7 @@ std::shared_ptr<Menu> DebugState::createMissionsMenu() {
"Bullion Run",
"Rumble",
"The Exchange",
};
}};
for (std::size_t i = 0; i < w.size(); ++i) {
menu->lambda(w[i], [=] {

View File

@ -21,7 +21,14 @@
#include <glm/gtx/matrix_major_storage.hpp>
#include <glm/gtx/norm.hpp>
#ifdef _MSC_VER
#pragma warning(disable : 4305)
#endif
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#ifdef _MSC_VER
#pragma warning(default : 4305)
#endif
constexpr float kAutoLookTime = 2.f;
constexpr float kAutolookMinVelocity = 0.2f;

View File

@ -11,6 +11,7 @@ target_link_libraries(rwfontmap
Qt5::Gui
)
install(TARGETS rwfontmap
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
openrw_target_apply_options(
TARGET rwfontmap
INSTALL INSTALL_PDB
)

View File

@ -9,15 +9,20 @@ add_executable(rwviewer
ViewerWindow.hpp
ViewerWindow.cpp
models/AnimationListModel.hpp
models/AnimationListModel.cpp
models/ObjectListModel.hpp
models/ObjectListModel.cpp
models/DFFFramesTreeModel.hpp
models/DFFFramesTreeModel.cpp
models/IMGArchiveModel.hpp
models/IMGArchiveModel.cpp
models/ItemListModel.hpp
models/ItemListModel.cpp
models/TextModel.hpp
models/TextModel.cpp
views/ViewerInterface.hpp
views/ObjectViewer.hpp
views/ObjectViewer.cpp
views/ModelViewer.hpp
@ -28,23 +33,18 @@ add_executable(rwviewer
views/WorldViewer.cpp
views/ViewerInterface.hpp
views/ViewerInterface.cpp
ViewerWidget.cpp
QOpenGLContextWrapper.hpp
QOpenGLContextWrapper.cpp
ViewerWidget.hpp
ItemListModel.hpp
ItemListModel.cpp
ItemListWidget.hpp
ItemListWidget.cpp
IMGArchiveModel.hpp
IMGArchiveModel.cpp
ViewerWidget.cpp
widgets/AnimationListWidget.hpp
widgets/AnimationListWidget.cpp
widgets/ItemListWidget.hpp
widgets/ItemListWidget.cpp
widgets/ModelFramesWidget.hpp
widgets/ModelFramesWidget.cpp
AnimationListModel.hpp
AnimationListModel.cpp
AnimationListWidget.hpp
AnimationListWidget.cpp
QOpenGLContextWrapper.cpp
QOpenGLContextWrapper.hpp
)
target_link_libraries(rwviewer
@ -54,10 +54,9 @@ target_link_libraries(rwviewer
Qt5::Widgets
)
openrw_target_apply_options(TARGET rwviewer)
install(TARGETS rwviewer
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
openrw_target_apply_options(
TARGET rwviewer
INSTALL INSTALL_PDB
)
if(USE_CONAN)

View File

@ -82,7 +82,7 @@ void ViewerWidget::drawModel(GameRenderer& r, ClumpPtr& model) {
glm::vec4(0.f), 90.f, vc.frustum.far});
model->getFrame()->updateHierarchyTransform();
ObjectRenderer _renderer(world(), vc, 1.f, 0);
ObjectRenderer _renderer(world(), vc, 1.f);
RenderList renders;
_renderer.renderClump(model.get(), glm::mat4(1.0f), nullptr, renders);
r.getRenderer()->drawBatched(renders);
@ -103,7 +103,7 @@ void ViewerWidget::drawObject(GameRenderer &r, GameObject *object) {
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
glm::vec4(0.f), 90.f, vc.frustum.far});
ObjectRenderer objectRenderer(world(), vc, 1.f, 0);
ObjectRenderer objectRenderer(world(), vc, 1.f);
RenderList renders;
objectRenderer.buildRenderList(object, renders);
std::sort(renders.begin(), renders.end(),
@ -183,7 +183,7 @@ void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
dp.colour = {255, 255, 255, 255};
glLineWidth(1.f);
}
dp.textures = {whiteTex};
dp.textures = {{whiteTex}};
RW_CHECK(_renderer != nullptr, "GameRenderer is null");
if(_renderer != nullptr) {

View File

@ -167,7 +167,7 @@ void ViewerWindow::loadGame(const QString& path) {
}
void ViewerWindow::showObjectModel(uint16_t) {
#pragma message("implement me")
RW_MESSAGE("showObjectModel unimplemented"); // FIXME: unimplemented
}
void ViewerWindow::updateRecentGames() {

View File

@ -25,7 +25,7 @@ QVariant AnimationListModel::headerData(int section,
}
int AnimationListModel::rowCount(const QModelIndex&) const {
return animations.size();
return static_cast<int>(animations.size());
}
int AnimationListModel::columnCount(const QModelIndex&) const {

View File

@ -1,4 +1,3 @@
#pragma once
#ifndef _ANIMATIONLISTMODEL_HPP_
#define _ANIMATIONLISTMODEL_HPP_
#include <QAbstractItemModel>
@ -16,15 +15,15 @@ public:
: QAbstractListModel(parent), animations(anims) {
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
const AnimationList& getAnimations() const {
return animations;

View File

@ -13,7 +13,7 @@ int DFFFramesTreeModel::columnCount(const QModelIndex&) const {
int DFFFramesTreeModel::rowCount(const QModelIndex& parent) const {
ModelFrame* f = static_cast<ModelFrame*>(parent.internalPointer());
if (f) {
return f->getChildren().size();
return static_cast<int>(f->getChildren().size());
}
if (parent.row() == -1) {
@ -40,7 +40,7 @@ QModelIndex DFFFramesTreeModel::parent(const QModelIndex& child) const {
if (cp->getParent()) {
for (size_t i = 0; i < cp->getParent()->getChildren().size(); ++i) {
if (cp->getParent()->getChildren()[i].get() == c->getParent()) {
return createIndex(i, 0, c->getParent());
return createIndex(static_cast<int>(i), 0, c->getParent());
}
}
} else {

View File

@ -1,4 +1,3 @@
#pragma once
#ifndef _DFFFRAMESTREEMODEL_HPP_
#define _DFFFRAMESTREEMODEL_HPP_
#include <QAbstractItemModel>

View File

@ -30,7 +30,7 @@ QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation,
}
int IMGArchiveModel::rowCount(const QModelIndex&) const {
return archive.getAssetCount();
return static_cast<int>(archive.getAssetCount());
}
int IMGArchiveModel::columnCount(const QModelIndex&) const {

View File

@ -1,4 +1,3 @@
#pragma once
#ifndef _IMGARCHIVEMODEL_HPP_
#define _IMGARCHIVEMODEL_HPP_
#include <QAbstractItemModel>
@ -14,19 +13,19 @@ public:
: QAbstractListModel(parent), archive(archive) {
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
const LoaderIMG& getArchive() const {
return archive;
}
};
#endif
#endif

View File

@ -14,7 +14,7 @@ ItemListModel::ItemListModel(GameWorld *world, QObject *parent)
}
int ItemListModel::rowCount(const QModelIndex &) const {
return _world->data->modelinfo.size();
return static_cast<int>(_world->data->modelinfo.size());
}
int ItemListModel::columnCount(const QModelIndex &) const {

View File

@ -19,17 +19,17 @@ public:
qint16 getIDOf(unsigned int row) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column, const QModelIndex& parent) const;
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
};
#endif // ITEMLISTMODEL_HPP

View File

@ -5,7 +5,7 @@ ObjectListModel::ObjectListModel(GameData *dat, QObject *parent)
}
int ObjectListModel::rowCount(const QModelIndex &) const {
return _gameData->modelinfo.size();
return static_cast<int>(_gameData->modelinfo.size());
}
int ObjectListModel::columnCount(const QModelIndex &) const {

View File

@ -17,17 +17,17 @@ public:
return _gameData;
}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column, const QModelIndex& parent) const;
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
};
#endif // _OBJECTLISTMODEL_HPP_

View File

@ -8,18 +8,18 @@ TextModel::TextModel(QObject *parent)
}
void TextModel::setData(const TextMapType &textMap) {
void TextModel::setMapData(const TextMapType &textMap) {
beginResetModel();
m_textMap = textMap;
endResetModel();
}
int TextModel::rowCount(const QModelIndex &) const {
return m_textMap.keys.size();
return static_cast<int>(m_textMap.keys.size());
}
int TextModel::columnCount(const QModelIndex &) const {
return m_textMap.languages.size();
return static_cast<int>(m_textMap.languages.size());
}
const GameString &TextModel::lookupIndex(const QModelIndex &index) const {

Some files were not shown because too many files have changed in this diff Show More