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

Merge pull request #696 from ShFil119/various

Various (smaller changes)
This commit is contained in:
Daniel Evans 2019-03-18 20:05:51 +00:00 committed by GitHub
commit a3916ca677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 162 additions and 151 deletions

View File

@ -145,10 +145,10 @@ struct Geometry {
struct Texture {
std::string name;
std::string alphaName;
TextureData::Handle texture;
TextureData* texture = nullptr;
template<class String1, class String2>
Texture(String1&& _name, String2&& _alphaName, const TextureData::Handle &_texture)
Texture(String1&& _name, String2&& _alphaName, TextureData* _texture)
: name(std::forward<String1>(_name))
, alphaName(std::forward<String2>(_alphaName))
, texture(_texture) {

View File

@ -4,9 +4,9 @@
#include <gl/gl_core_3_3.h>
#include <glm/vec2.hpp>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
/**
* Stores a handle and metadata about a loaded texture.
@ -33,11 +33,9 @@ public:
return hasAlpha;
}
typedef std::shared_ptr<TextureData> Handle;
static Handle create(GLuint name, const glm::ivec2& size,
static auto create(GLuint name, const glm::ivec2& size,
bool transparent) {
return std::make_shared<TextureData>(name, size, transparent);
return std::make_unique<TextureData>(name, size, transparent);
}
private:
@ -45,6 +43,6 @@ private:
glm::ivec2 size;
bool hasAlpha;
};
using TextureArchive = std::map<std::string, TextureData::Handle>;
using TextureArchive = std::unordered_map<std::string, std::unique_ptr<TextureData>>;
#endif

View File

@ -363,9 +363,8 @@ void LoaderDFF::readTexture(Geometry::Material &material,
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
std::transform(alpha.begin(), alpha.end(), alpha.begin(), ::tolower);
TextureData::Handle textureinst =
texturelookup ? texturelookup(name, alpha) : nullptr;
material.textures.emplace_back(std::move(name), std::move(alpha), textureinst);
auto textureInstPtr = textureLookup ? textureLookup(name, alpha) : nullptr;
material.textures.emplace_back(std::move(name), std::move(alpha), textureInstPtr);
}
void LoaderDFF::readGeometryExtension(const GeometryPtr &geom,

View File

@ -25,19 +25,19 @@ public:
class LoaderDFF {
public:
using TextureLookupCallback = std::function<TextureData::Handle(
const std::string&, const std::string&)>;
using TextureLookupCallback =
std::function<TextureData*(const std::string&, const std::string&)>;
using GeometryList = std::vector<GeometryPtr>;
using FrameList = std::vector<ModelFramePtr>;
ClumpPtr loadFromMemory(const FileContentsInfo& file);
void setTextureLookupCallback(const TextureLookupCallback& tlc) {
texturelookup = tlc;
textureLookup = tlc;
}
private:
TextureLookupCallback texturelookup;
TextureLookupCallback textureLookup;
FrameList readFrameList(const RWBStream& stream);

View File

@ -12,16 +12,18 @@
#include "platform/FileHandle.hpp"
#include "rw/debug.hpp"
GLuint gErrorTextureData[] = {0xFFFF00FF, 0xFF000000, 0xFF000000, 0xFFFF00FF};
GLuint gDebugTextureData[] = {0xFF0000FF, 0xFF00FF00};
GLuint gTextureRed[] = {0xFF0000FF};
GLuint gTextureGreen[] = {0xFF00FF00};
GLuint gTextureBlue[] = {0xFFFF0000};
namespace {
constexpr GLuint gErrorTextureData[] = {0xFFFF00FF, 0xFF000000, 0xFF000000, 0xFFFF00FF};
constexpr GLuint gDebugTextureData[] = {0xFF0000FF, 0xFF00FF00};
constexpr GLuint gTextureRed[] = {0xFF0000FF};
constexpr GLuint gTextureGreen[] = {0xFF00FF00};
constexpr GLuint gTextureBlue[] = {0xFFFF0000};
} // namespace
static
TextureData::Handle getErrorTexture() {
static GLuint errTexName = 0;
static TextureData::Handle tex;
std::unique_ptr<TextureData> getErrorTexture() {
GLuint errTexName = 0;
std::unique_ptr<TextureData> tex = nullptr;
if (errTexName == 0) {
glGenTextures(1, &errTexName);
glBindTexture(GL_TEXTURE_2D, errTexName);
@ -51,9 +53,8 @@ void processPalette(uint32_t* fullColor, RW::BinaryStreamSection& rootSection) {
}
}
static
TextureData::Handle createTexture(RW::BSTextureNative& texNative,
RW::BinaryStreamSection& rootSection) {
static std::unique_ptr<TextureData> createTexture(
RW::BSTextureNative& texNative, RW::BinaryStreamSection& rootSection) {
// TODO: Exception handling.
if (texNative.platform != 8) {
RW_ERROR("Unsupported texture platform " << std::dec
@ -191,9 +192,7 @@ bool TextureLoader::loadFromMemory(const FileContentsInfo& file,
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
std::transform(alpha.begin(), alpha.end(), alpha.begin(), ::tolower);
auto texture = createTexture(texNative, rootSection);
inTextures[name] = texture;
inTextures[name] = createTexture(texNative, rootSection);
}
return true;

View File

@ -42,9 +42,9 @@ void WinBreak();
#if defined(RW_DEBUG) && defined(RW_VERBOSE_DEBUG_MESSAGES)
#include <iostream>
#define RW_MESSAGE(msg) \
std::cout << __FILE__ << ":" << __LINE__ << ": " << msg << std::endl
std::cout << __FILE__ << ":" << __LINE__ << ": " << msg << '\n'
#define RW_ERROR(msg) \
std::cerr << __FILE__ << ":" << __LINE__ << ": " << msg << std::endl
std::cerr << __FILE__ << ":" << __LINE__ << ": " << msg << '\n'
#else
#define RW_MESSAGE(msg)
#define RW_ERROR(msg)

View File

@ -24,6 +24,6 @@ void checkALerror(const std::string& file, unsigned int line) {
std::cerr << err;
}
std::cerr << std::endl;
std::cerr << '\n';
}
}

View File

@ -38,12 +38,7 @@ void Logger::verbose(const std::string& component, const std::string& message) {
log(component, Logger::Verbose, message);
}
std::map<Logger::MessageSeverity, char> severityStr{{Logger::Error, 'E'},
{Logger::Warning, 'W'},
{Logger::Info, 'I'},
{Logger::Verbose, 'V'}};
void StdOutReceiver::messageReceived(const Logger::LogMessage& message) {
std::cout << severityStr[message.severity] << " [" << message.component
<< "] " << message.message << std::endl;
std::cout << Logger::messageSeverityName[message.severity] << " ["
<< message.component << "] " << message.message << '\n';
}

View File

@ -1,6 +1,7 @@
#ifndef _RWENGINE_LOGGER_HPP_
#define _RWENGINE_LOGGER_HPP_
#include <array>
#include <initializer_list>
#include <string>
#include <utility>
@ -13,7 +14,8 @@
*/
class Logger {
public:
enum MessageSeverity { Verbose, Info, Warning, Error };
enum MessageSeverity { Verbose = 0, Info, Warning, Error};
static constexpr std::array<char, 4> messageSeverityName{{'V', 'I', 'W', 'E'}};
struct LogMessage {
/// The component that produced the message

View File

@ -48,13 +48,12 @@ void GameData::load() {
/// @todo cuts.img files should be loaded differently to gta3.img
loadIMG("anim/cuts.img");
textureslots["particle"] = loadTextureArchive("particle.txd");
textureslots["icons"] = loadTextureArchive("icons.txd");
textureslots["hud"] = loadTextureArchive("hud.txd");
textureslots["fonts"] = loadTextureArchive("fonts.txd");
textureslots["generic"] = loadTextureArchive("generic.txd");
auto misc = loadTextureArchive("misc.txd");
textureslots["generic"].insert(misc.begin(), misc.end());
textureSlots["particle"] = loadTextureArchive("particle.txd");
textureSlots["icons"] = loadTextureArchive("icons.txd");
textureSlots["hud"] = loadTextureArchive("hud.txd");
textureSlots["fonts"] = loadTextureArchive("fonts.txd");
textureSlots["generic"] = loadTextureArchive("generic.txd");
loadToTextureArchive("misc.txd", textureSlots["generic"]);
loadCarcols("data/carcols.dat");
loadWeather("data/timecyc.dat");
@ -362,12 +361,12 @@ void GameData::loadTXD(const std::string& name) {
currenttextureslot = slot;
// Check if this texture slot is loaded already
auto slotit = textureslots.find(slot);
if (slotit != textureslots.end()) {
auto slotit = textureSlots.find(slot);
if (slotit != textureSlots.end()) {
return;
}
textureslots[slot] = loadTextureArchive(name);
textureSlots[slot] = loadTextureArchive(name);
}
TextureArchive GameData::loadTextureArchive(const std::string& name) {
@ -390,6 +389,21 @@ TextureArchive GameData::loadTextureArchive(const std::string& name) {
return textures;
}
void GameData::loadToTextureArchive(const std::string& name,
TextureArchive& archive) {
RW_PROFILE_COUNTER_ADD("loadTextureArchive", 1);
/// @todo refactor loadTXD to use correct file locations
auto file = index.openFile(name);
if (!file.data) {
logger->error("Data", "Failed to open txd: " + name);
}
TextureLoader l;
if (!l.loadFromMemory(file, archive)) {
logger->error("Data", "Error loading txd: " + name);
}
}
void GameData::getNameAndLod(std::string& name, int& lod) {
auto lodpos = name.rfind("_l");
if (lodpos != std::string::npos) {
@ -696,22 +710,21 @@ void GameData::loadSplash(const std::string& name) {
std::string lower(name);
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
auto splashTXD = loadTextureArchive(lower + ".txd");
textureslots["generic"].insert(splashTXD.begin(), splashTXD.end());
textureSlots["generic"] = loadTextureArchive(lower + ".txd");
engine->state->currentSplash = lower;
}
TextureData::Handle GameData::findSlotTexture(const std::string &slot, const std::string &texture) const {
auto slotit = textureslots.find(slot);
if (slotit == textureslots.end()) {
TextureData* GameData::findSlotTexture(const std::string &slot, const std::string &texture) const {
auto slotIt = textureSlots.find(slot);
if (slotIt == textureSlots.end()) {
return nullptr;
}
auto textureit = slotit->second.find(texture);
if (textureit == slotit->second.end()) {
auto textureIt = slotIt->second.find(texture);
if (textureIt == slotIt->second.end()) {
return nullptr;
}
return textureit->second;
return textureIt->second.get();
}
ZoneData *GameData::findZone(const std::string &name) {

View File

@ -130,6 +130,11 @@ public:
*/
TextureArchive loadTextureArchive(const std::string& name);
/**
* Loads to named a texture archive from the game data
*/
void loadToTextureArchive(const std::string& name, TextureArchive& archive);
/**
* Converts combined {name}_l{LOD} into name and lod.
*/
@ -190,7 +195,7 @@ public:
void loadSplash(const std::string& name);
TextureData::Handle findSlotTexture(const std::string& slot,
TextureData* findSlotTexture(const std::string& slot,
const std::string& texture) const;
FileIndex index;
@ -260,7 +265,7 @@ public:
/**
* Texture slots, containing loaded textures.
*/
std::map<std::string, TextureArchive> textureslots;
std::unordered_map<std::string, TextureArchive> textureSlots;
/**
* Texture atlases.

View File

@ -116,9 +116,9 @@ bool GameWorld::placeItems(const std::string& name) {
if (ipll.load(name)) {
// Find the object.
for (const auto& inst : ipll.m_instances) {
if (!createInstance(inst->id, inst->pos, inst->rot)) {
if (!createInstance(inst.id, inst.pos, inst.rot)) {
logger->error("World", "No object data for instance " +
std::to_string(inst->id) + " in " +
std::to_string(inst.id) + " in " +
name);
}
}

View File

@ -606,11 +606,11 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << "Player Health: " << ped.info.health << " ("
<< ped.info.armour << ")" << std::endl;
std::cout << "Player model: " << ped.modelName << std::endl;
<< ped.info.armour << ")" << '\n';
std::cout << "Player model: " << ped.modelName << '\n';
for (const auto &wep : players[p].info.weapons) {
std::cout << "ID " << wep.weaponId << " " << wep.inClip << " "
<< wep.totalBullets << std::endl;
<< wep.totalBullets << '\n';
}
#endif
}
@ -640,19 +640,19 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
}
#ifdef RW_DEBUG
std::cout << "Garages: " << garageData.garageCount << std::endl;
std::cout << "Bombs Free: " << garageData.freeBombs << std::endl;
std::cout << "Sprays Free: " << garageData.freeResprays << std::endl;
std::cout << "Garages: " << garageData.garageCount << '\n';
std::cout << "Bombs Free: " << garageData.freeBombs << '\n';
std::cout << "Sprays Free: " << garageData.freeResprays << '\n';
std::cout << "Portland IE: " << garageData.bfImportExportPortland
<< std::endl;
<< '\n';
std::cout << "Shoreside IE: " << garageData.bfImportExportShoreside
<< std::endl;
std::cout << "GA21 last shown: " << garageData.GA_21lastTime << std::endl;
<< '\n';
std::cout << "GA21 last shown: " << garageData.GA_21lastTime << '\n';
for (const auto &car : garageData.cars) {
if (car.modelId == 0) continue;
std::cout << " " << car.modelId << " " << uint16_t(car.colorFG) << "/"
<< uint16_t(car.colorBG) << " " << car.immunities
<< std::endl;
<< '\n';
}
#endif
@ -677,7 +677,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << " v " << veh.modelId << " " << veh.state.position.x << " "
<< veh.state.position.y << " " << veh.state.position.z
<< std::endl;
<< '\n';
#endif
}
std::vector<Block3Boat> boats(boatCount);
@ -690,7 +690,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << " b " << veh.modelId << " " << veh.state.position.x << " "
<< veh.state.position.y << " " << veh.state.position.z
<< std::endl;
<< '\n';
#endif
}
@ -737,7 +737,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
}
#ifdef RW_DEBUG
std::cout << "Objects " << objectCount << std::endl;
std::cout << "Objects " << objectCount << '\n';
for (size_t o = 0; o < objectCount; ++o) {
auto& obj = objects[o];
glm::vec3 right = glm::normalize(
@ -754,9 +754,9 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
std::cout << "forward " << forward.x << " " << forward.y << " "
<< forward.z << " ";
std::cout << "down " << down.x << " " << down.y << " " << down.z
<< std::endl;
<< '\n';
}
std::cout << std::endl;
std::cout << '\n';
#endif
// Block 5
@ -787,13 +787,13 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
}
#ifdef RW_DEBUG
std::cout << "Cranes: " << craneData.numCranes << std::endl;
std::cout << "Cranes: " << craneData.numCranes << '\n';
for (size_t c = 0; c < craneData.numCranes; ++c) {
Block6Crane& crane = craneData.cranes[c];
std::cout << "pickup " << crane.x1Pickup << " " << crane.y1Pickup << " "
<< crane.x2Pickup << " " << crane.y2Pickup << std::endl;
<< crane.x2Pickup << " " << crane.y2Pickup << '\n';
std::cout << "vehicles collected " << uint16_t(crane.vehiclesCollected)
<< std::endl;
<< '\n';
}
#endif
@ -810,7 +810,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
for (const auto &pickup : pickupData.pickups) {
if (pickup.type == 0) continue;
std::cout << " " << uint16_t(pickup.type) << " " << pickup.position.x << " "
<< pickup.position.y << " " << pickup.position.z << std::endl;
<< pickup.position.y << " " << pickup.position.z << '\n';
}
#endif
@ -828,11 +828,11 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
}
#ifdef RW_DEBUG
std::cout << "Payphones: " << payphoneData.numPayphones << std::endl;
std::cout << "Payphones: " << payphoneData.numPayphones << '\n';
for (const auto& payphone : payphones) {
std::cout << " " << uint16_t(payphone.state) << " " << payphone.position.x
<< " " << payphone.position.y << " " << payphone.position.z
<< std::endl;
<< '\n';
}
#endif
@ -849,16 +849,16 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << "Hospitals: " << restartData.numHospitals
<< " police: " << restartData.numPolice << std::endl;
<< " police: " << restartData.numPolice << '\n';
for (int s = 0; s < restartData.numHospitals; ++s) {
Block9Restart& p = restartData.hospitalRestarts[s];
std::cout << " H " << p.position.x << " " << p.position.y << " "
<< p.position.z << std::endl;
<< p.position.z << '\n';
}
for (int s = 0; s < restartData.numPolice; ++s) {
Block9Restart& p = restartData.policeRestarts[s];
std::cout << " P " << p.position.x << " " << p.position.y << " "
<< p.position.z << std::endl;
<< p.position.z << '\n';
}
#endif
@ -877,7 +877,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
for (const auto &blip : radarData.blips) {
if (blip.type == 0) continue;
std::cout << " " << blip.position.x << " " << blip.position.y << " "
<< blip.position.z << std::endl;
<< blip.position.z << '\n';
}
#endif
@ -937,10 +937,10 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << "zones: " << zoneData.numNavZones << " "
<< zoneData.numZoneInfos << " " << zoneData.numMapZones << " "
<< zoneData.numAudioZones << std::endl;
<< zoneData.numAudioZones << '\n';
for (int z = 0; z < zoneData.numNavZones; ++z) {
Block11Zone& zone = zoneData.navZones[z];
std::cout << " " << zone.name << std::endl;
std::cout << " " << zone.name << '\n';
auto& dayinfo = zoneData.dayNightInfo[zone.dayZoneInfo];
std::cout << " DAY " << dayinfo.density << " " << dayinfo.peddensity
<< " " << dayinfo.copdensity << " "
@ -948,11 +948,11 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
for (BlockDword gang : dayinfo.gangpeddensity) {
std::cout << " " << gang;
}
std::cout << "] " << dayinfo.pedgroup << std::endl;
std::cout << "] " << dayinfo.pedgroup << '\n';
for (BlockDword dw : dayinfo.unknown1) {
std::cout << " " << dw;
}
std::cout << std::endl;
std::cout << '\n';
auto& nightinfo = zoneData.dayNightInfo[zone.nightZoneInfo];
std::cout << " NIGHT " << nightinfo.density << " "
@ -961,15 +961,15 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
for (BlockDword gang : nightinfo.gangpeddensity) {
std::cout << " " << gang;
}
std::cout << "] " << nightinfo.pedgroup << std::endl;
std::cout << "] " << nightinfo.pedgroup << '\n';
for (BlockDword dw : nightinfo.unknown1) {
std::cout << " " << dw;
}
std::cout << std::endl;
std::cout << '\n';
}
for (int z = 0; z < zoneData.numMapZones; ++z) {
Block11Zone& zone = zoneData.mapZones[z];
std::cout << " " << zone.name << std::endl;
std::cout << " " << zone.name << '\n';
}
#endif
@ -1007,7 +1007,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
for (const auto &gang : gangData.gangs) {
std::cout << " " << gang.carModelId << " " << gang.weaponPrimary << " "
<< gang.weaponSecondary << std::endl;
<< gang.weaponSecondary << '\n';
}
#endif
@ -1030,11 +1030,11 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << "Car generators: " << carGeneratorData.generatorCount
<< std::endl;
<< '\n';
for (size_t g = 0; g < carGeneratorData.generatorCount; ++g) {
Block13CarGenerator& gen = carGenerators[g];
std::cout << " " << gen.modelId << " " << gen.position.x << " "
<< gen.position.y << " " << gen.position.z << std::endl;
<< gen.position.y << " " << gen.position.z << '\n';
}
#endif
@ -1052,7 +1052,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
}
#ifdef RW_DEBUG
std::cout << "particles: " << particleCount << std::endl;
std::cout << "particles: " << particleCount << '\n';
#endif
// Block 15
@ -1072,7 +1072,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
}
#ifdef RW_DEBUG
std::cout << "Audio Objects: " << audioCount << std::endl;
std::cout << "Audio Objects: " << audioCount << '\n';
#endif
// Block 16
@ -1096,7 +1096,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
#ifdef RW_DEBUG
std::cout << "Player money: " << state.playerInfo.money << " ("
<< state.playerInfo.displayedMoney << ")" << std::endl;
<< state.playerInfo.displayedMoney << ")" << '\n';
#endif
// Block 17
@ -1158,9 +1158,9 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
READ_VALUE(state.gameStats.lastMissionGXT);
#ifdef RW_DEBUG
std::cout << "Player kills: " << state.gameStats.playerKills << std::endl;
std::cout << "Player kills: " << state.gameStats.playerKills << '\n';
std::cout << "longest flight " << state.gameStats.longestDodoFlight
<< std::endl;
<< '\n';
#endif
// Block 18
@ -1183,7 +1183,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
std::cout << " ";
}
}
std::cout << std::endl;
std::cout << '\n';
}
#endif
@ -1241,7 +1241,7 @@ bool SaveGame::loadGame(GameState& state, const std::string& file) {
if (playerCount > 0) {
auto& ply = players[0];
std::cout << ply.reference << std::endl;
std::cout << ply.reference << '\n';
auto player = state.world->createPlayer(players[0].info.position);
CharacterState& cs = player->getCurrentState();
cs.health = players[0].info.health;
@ -1354,7 +1354,7 @@ std::vector<SaveGameInfo> SaveGame::getAllSaveGameInfo() {
auto homedir = getenv("HOME");
#endif
if (homedir == nullptr) {
std::cerr << "Unable to determine home directory" << std::endl;
std::cerr << "Unable to determine home directory" << '\n';
return {};
}
const char gameDir[] = "GTA3 User Files";

View File

@ -80,18 +80,18 @@ bool LoaderIPL::load(std::istream &str) {
getline(strstream, rotZ, ',');
getline(strstream, rotW, ',');
auto instance = std::make_shared<InstanceData>(
m_instances.emplace_back(
lexical_cast<int>(id), // ID
model.substr(1, model.size() - 1),
glm::vec3(lexical_cast<float>(posX), lexical_cast<float>(posY),
glm::vec3(lexical_cast<float>(posX),
lexical_cast<float>(posY),
lexical_cast<float>(posZ)),
glm::vec3(lexical_cast<float>(scaleX), lexical_cast<float>(scaleY),
glm::vec3(lexical_cast<float>(scaleX),
lexical_cast<float>(scaleY),
lexical_cast<float>(scaleZ)),
glm::normalize(
glm::quat(-lexical_cast<float>(rotW), lexical_cast<float>(rotX),
lexical_cast<float>(rotY), lexical_cast<float>(rotZ))));
m_instances.push_back(instance);
glm::normalize(glm::quat(
-lexical_cast<float>(rotW), lexical_cast<float>(rotX),
lexical_cast<float>(rotY), lexical_cast<float>(rotZ))));
} else if (section == ZONE) {
ZoneData zone;

View File

@ -6,6 +6,7 @@
#include <vector>
#include <data/ZoneData.hpp>
#include <data/InstanceData.hpp>
struct InstanceData;
@ -22,7 +23,7 @@ public:
bool load(std::istream& stream);
/// The list of instances from the IPL file
std::vector<std::shared_ptr<InstanceData>> m_instances;
std::vector<InstanceData> m_instances;
/// List of Zones
ZoneDataList zones;

View File

@ -86,8 +86,8 @@ void ProjectileObject::explode() {
auto& explosion = engine->createParticleEffect();
auto tex = engine->data->findSlotTexture("particle", "explo02");
explosion.texture = tex;
auto texPtr = engine->data->findSlotTexture("particle", "explo02");
explosion.texture = texPtr;
explosion.size = glm::vec2(exp_size);
explosion.starttime = engine->getGameTime();
explosion.lifetime = 0.5f;

View File

@ -88,12 +88,12 @@ void DebugDraw::flush(GameRenderer &renderer) {
}
void DebugDraw::reportErrorWarning(const char *warningString) {
std::cerr << warningString << std::endl;
std::cerr << warningString << '\n';
}
void DebugDraw::draw3dText(const btVector3 &location, const char *textString) {
RW_UNUSED(location);
std::cout << textString << std::endl;
std::cout << textString << '\n';
}
void DebugDraw::setDebugMode(int debugMode) {

View File

@ -270,9 +270,9 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
GLuint splashTexName = 0;
const auto fc = world->state->fadeColour;
if ((fc.r + fc.g + fc.b) == 0 && !world->state->currentSplash.empty()) {
auto splash = world->data->findSlotTexture("generic", world->state->currentSplash);
if (splash) {
splashTexName = splash->getName();
auto splashTexPtr = world->data->findSlotTexture("generic", world->state->currentSplash);
if (splashTexPtr) {
splashTexName = splashTexPtr->getName();
}
}

View File

@ -125,8 +125,8 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
for (int m = 0; m < MAP_BLOCK_SIZE; ++m) {
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()}};
auto texturePtr = world->data->findSlotTexture(name, name);
dp.textures = {{texturePtr->getName()}};
dp.count = 4;
@ -151,9 +151,8 @@ void MapRenderer::draw(GameWorld* world, const MapInfo& mi) {
glDisable(GL_STENCIL_TEST);
// We only need the outer ring if we're clipping.
glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ONE, GL_ZERO);
TextureData::Handle radarDisc =
data->findSlotTexture("hud", "radardisc");
dp.textures = {{radarDisc->getName()}};
auto radarDiscTexPtr = data->findSlotTexture("hud", "radardisc");
dp.textures = {{radarDiscTexPtr->getName()}};
glm::mat4 model{1.0f};
model = glm::translate(model, glm::vec3(mi.screenPosition, 0.0f));
@ -265,8 +264,8 @@ void MapRenderer::prepareBlip(const glm::vec2& coord, const glm::mat4& view,
GLuint tex = 0;
if (!texture.empty()) {
auto sprite = data->findSlotTexture("hud", texture);
tex = sprite->getName();
auto spriteTexPtr = data->findSlotTexture("hud", texture);
tex = spriteTexPtr->getName();
}
renderer.setUniform(rectProg.get(), "colour", colour);

View File

@ -143,8 +143,8 @@ TextRenderer::TextRenderer(GameRenderer &renderer) : renderer(renderer) {
}
void TextRenderer::setFontTexture(font_t font, const std::string& textureName) {
auto ftexture = renderer.getData().findSlotTexture("fonts", textureName);
const glm::u32vec2 textureSize = ftexture->getSize();
auto fTexturePtr = renderer.getData().findSlotTexture("fonts", textureName);
const glm::u32vec2 textureSize = fTexturePtr->getSize();
glm::u8vec2 glyphOffset{textureSize.x / 16, textureSize.x / 16};
if (font != FONT_PAGER) {
glyphOffset.y += glyphOffset.y / 4;
@ -344,8 +344,8 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti,
dp.start = 0;
dp.blendMode = BlendMode::BLEND_ALPHA;
dp.count = gb.getCount();
auto ftexture = renderer.getData().findSlotTexture("fonts", fontMetaData.textureName);
dp.textures = {{ftexture->getName()}};
auto fTexturePtr = renderer.getData().findSlotTexture("fonts", fontMetaData.textureName);
dp.textures = {{fTexturePtr->getName()}};
dp.depthMode = DepthMode::OFF;
renderer.getRenderer().drawArrays(glm::mat4(1.0f), &db, dp);

View File

@ -1,4 +1,4 @@
#ifndef _RWENGINE_VISUALFX_HPP_
#ifndef _RWENGINE_VISUALFX_HPP_
#define _RWENGINE_VISUALFX_HPP_
#include <glm/vec2.hpp>
@ -50,7 +50,7 @@ struct ParticleFX final : public VisualFX {
float lifetime{-1.f};
/** Texture name */
TextureData::Handle texture;
TextureData* texture = nullptr;
/** Size of particle */
glm::vec2 size{1.f, 1.f};

View File

@ -102,9 +102,9 @@ void WaterRenderer::setDataTexture(GLuint fbBinding, GLuint dataTex) {
void WaterRenderer::render(GameRenderer &renderer, GameWorld* world) {
auto& r = renderer.getRenderer();
auto waterTex = world->data->findSlotTexture("particle", "water_old");
RW_CHECK(waterTex != nullptr, "Water texture is null");
if (waterTex == nullptr) {
auto waterTexPtr = world->data->findSlotTexture("particle", "water_old");
RW_CHECK(waterTexPtr != nullptr, "Water texture is null");
if (waterTexPtr == nullptr) {
// Can't render water if we don't have a texture.
return;
}
@ -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 = {{waterTexPtr->getName(), dataTexture}};
r.drawArrays(m, &gridDraw, wdp);

View File

@ -203,12 +203,12 @@ void HUDDrawer::drawPlayerInfo(ai::PlayerController* player, GameWorld* world,
itemTextureName = "detonator";
}
TextureData::Handle itemTexture =
auto itemTexturePtr =
render.getData().findSlotTexture("hud", itemTextureName);
RW_CHECK(itemTexture != nullptr, "Item has 0 texture");
if (itemTexture != nullptr) {
RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture");
render.drawTexture(itemTexture.get(),
RW_CHECK(itemTexturePtr != nullptr, "Item has 0 texture");
if (itemTexturePtr != nullptr) {
RW_CHECK(itemTexturePtr->getName() != 0, "Item has 0 texture");
render.drawTexture(itemTexturePtr,
glm::vec4(iconX, iconY, hudParameters.uiWeaponSize,
hudParameters.uiWeaponSize));
}

View File

@ -119,7 +119,7 @@ std::optional<RWArgConfigLayer> RWArgumentParser::parseArguments(int argc, const
}
po::notify(vm);
} catch (po::error& ex) {
std::cerr << "Error parsing arguments: " << ex.what() << std::endl;
std::cerr << "Error parsing arguments: " << ex.what() << '\n';
return std::nullopt;
} catch (boost::exception& ex) {
std::cerr << "A boost::exception object was thrown (bug in Boost.Program_options?).\n";

View File

@ -579,7 +579,7 @@ void RWGame::tick(float dt) {
try {
vm->execute(dt);
} catch (SCMException& ex) {
std::cerr << ex.what() << std::endl;
std::cerr << ex.what() << '\n';
log.error("Script", ex.what());
throw;
}

View File

@ -56,7 +56,7 @@ void BenchmarkState::enter() {
track.push_back(point);
}
std::cout << "Loaded " << track.size() << " points" << std::endl;
std::cout << "Loaded " << track.size() << " points" << '\n';
}
void BenchmarkState::exit() {
@ -66,7 +66,7 @@ void BenchmarkState::exit() {
<< "Duration: " << duration << " seconds\n"
<< "Avg frametime: " << std::setprecision(3)
<< (duration / frameCounter) << " (" << (frameCounter / duration)
<< " fps)" << std::endl;
<< " fps)" << '\n';
}
void BenchmarkState::tick(float dt) {

View File

@ -500,7 +500,7 @@ void DebugState::printCameraDetails() {
std::cout << " " << _debugCam.position.x << " " << _debugCam.position.y
<< " " << _debugCam.position.z << " " << _debugCam.rotation.x
<< " " << _debugCam.rotation.y << " " << _debugCam.rotation.z
<< " " << _debugCam.rotation.w << std::endl;
<< " " << _debugCam.rotation.w << '\n';
}
void DebugState::spawnVehicle(unsigned int id) {

View File

@ -11,7 +11,7 @@ PauseState::PauseState(RWGame* game) : State(game) {
Menu menu{{{t.text(MenuDefaults::kResumeGameId), [&] { done(); }},
{t.text(MenuDefaults::kOptionsId),
[] { std::cout << "Options" << std::endl; }},
[] { std::cout << "Options" << '\n'; }},
{t.text(MenuDefaults::kQuitGameId),
[=] { game->getStateManager().clear(); }}},
glm::vec2(200.f, 200.f)};

View File

@ -44,7 +44,7 @@ void ModelViewer::showObject(uint16_t object) {
LoaderDFF dffLoader;
dffLoader.setTextureLookupCallback(
[&](const std::string& texture, const std::string&) {
return textures.at(texture);
return textures.at(texture).get();
});
auto file = world()->data->index.openFile(modelName);

View File

@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(instance_data_is_correct) {
BOOST_REQUIRE(loader.load(test_data_stream));
const auto expectedInstance = InstanceData(112, "ModelB", {10.0f, 12.0f, 5.0f}, {1.f, 1.f, 1.f}, {0.0f, 0.f, 0.f, 1.0f});
BOOST_TEST(*loader.m_instances[1] == expectedInstance);
BOOST_TEST(loader.m_instances[1] == expectedInstance);
}
BOOST_AUTO_TEST_SUITE_END()