mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Split Weather Data from the loader
- WeatherLoader now just a namespace with a single function
This commit is contained in:
parent
e5694b383c
commit
d3306922b2
@ -46,6 +46,7 @@ set(RWENGINE_SOURCES
|
||||
src/data/PedData.cpp
|
||||
src/data/PedData.hpp
|
||||
src/data/WeaponData.hpp
|
||||
src/data/Weather.cpp
|
||||
src/data/ZoneData.hpp
|
||||
|
||||
src/dynamics/CollisionInstance.cpp
|
||||
|
45
rwengine/src/data/Weather.cpp
Normal file
45
rwengine/src/data/Weather.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "Weather.hpp"
|
||||
|
||||
RWTypes::RGB mix(RWTypes::RGB x, RWTypes::RGB y, float a) {
|
||||
RWTypes::RGB n;
|
||||
n.r = x.r * (1.f - a) + y.r * a;
|
||||
n.g = x.g * (1.f - a) + y.g * a;
|
||||
n.b = x.b * (1.f - a) + y.b * a;
|
||||
return n;
|
||||
}
|
||||
|
||||
int32_t mixint(int32_t x, int32_t y, float a) {
|
||||
return x * (1.f - a) + y * a;
|
||||
}
|
||||
|
||||
#define MIXPROP(prop) data.prop = mix(x.prop, y.prop, a)
|
||||
#define MIXPROP2(prop) data.prop = glm::mix(x.prop, y.prop, a)
|
||||
#define MIXPROP_INT(prop) data.prop = mixint(x.prop, y.prop, a)
|
||||
|
||||
Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
||||
size_t hour = floor(tod);
|
||||
const auto& x = entries[static_cast<size_t>(cond) + hour];
|
||||
const auto& y = entries[static_cast<size_t>(cond) + (hour + 1) % 24];
|
||||
const float a = tod - std::floor(tod);
|
||||
|
||||
Entry data;
|
||||
MIXPROP(ambientColor);
|
||||
MIXPROP(directLightColor);
|
||||
MIXPROP(skyTopColor);
|
||||
MIXPROP(skyBottomColor);
|
||||
MIXPROP(sunCoreColor);
|
||||
MIXPROP2(sunCoreSize);
|
||||
MIXPROP2(sunCoronaSize);
|
||||
MIXPROP2(sunBrightness);
|
||||
MIXPROP_INT(shadowIntensity);
|
||||
MIXPROP_INT(lightShading);
|
||||
MIXPROP_INT(poleShading);
|
||||
MIXPROP2(farClipping);
|
||||
MIXPROP2(fogStart);
|
||||
MIXPROP2(amountGroundLight);
|
||||
MIXPROP(lowCloudColor);
|
||||
MIXPROP(topCloudColor);
|
||||
MIXPROP(bottomCloudColor);
|
||||
|
||||
return data;
|
||||
}
|
47
rwengine/src/data/Weather.hpp
Normal file
47
rwengine/src/data/Weather.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef _RWENGINE_WEATHER_HPP_
|
||||
#define _RWENGINE_WEATHER_HPP_
|
||||
|
||||
#include <rw/types.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
enum WeatherCondition { Sunny = 0, Cloudy = 24, Rainy = 48, Foggy = 72 };
|
||||
|
||||
class Weather {
|
||||
public:
|
||||
struct Entry {
|
||||
RWTypes::RGB ambientColor;
|
||||
RWTypes::RGB directLightColor;
|
||||
RWTypes::RGB skyTopColor;
|
||||
RWTypes::RGB skyBottomColor;
|
||||
RWTypes::RGB sunCoreColor;
|
||||
RWTypes::RGB sunCoronaColor;
|
||||
float sunCoreSize;
|
||||
float sunCoronaSize;
|
||||
float sunBrightness;
|
||||
int32_t shadowIntensity;
|
||||
int32_t lightShading;
|
||||
int32_t poleShading;
|
||||
float farClipping;
|
||||
float fogStart;
|
||||
float amountGroundLight;
|
||||
RWTypes::RGB lowCloudColor;
|
||||
RWTypes::RGB topCloudColor;
|
||||
RWTypes::RGB bottomCloudColor;
|
||||
uint8_t unknown[4];
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief getWeatherData returns interpolated Weather data for the time of
|
||||
* day.
|
||||
* @param cond weather condition
|
||||
* @param tod float time of day
|
||||
* @return Correctly interpolated values.
|
||||
*/
|
||||
Entry getWeatherData(WeatherCondition cond, float tod);
|
||||
|
||||
std::vector<Entry> entries;
|
||||
};
|
||||
|
||||
#endif
|
@ -16,16 +16,13 @@
|
||||
#include <rw/types.hpp>
|
||||
|
||||
#include "core/Logger.hpp"
|
||||
//#include "data/WeaponData.hpp"
|
||||
#include "engine/GameState.hpp"
|
||||
#include "engine/GameWorld.hpp"
|
||||
#include "loaders/LoaderCOL.hpp"
|
||||
#include "loaders/LoaderDFF.hpp"
|
||||
#include "loaders/LoaderIDE.hpp"
|
||||
#include "loaders/LoaderIFP.hpp"
|
||||
#include "loaders/LoaderIMG.hpp"
|
||||
#include "loaders/LoaderIPL.hpp"
|
||||
#include "loaders/LoaderTXD.hpp"
|
||||
#include "loaders/WeatherLoader.hpp"
|
||||
#include "platform/FileHandle.hpp"
|
||||
#include "script/SCMFile.hpp"
|
||||
#include "loaders/GenericDATLoader.hpp"
|
||||
@ -281,7 +278,9 @@ void GameData::loadCarcols(const std::string& path) {
|
||||
|
||||
void GameData::loadWeather(const std::string& path) {
|
||||
auto syspath = index.findFilePath(path).string();
|
||||
weatherLoader.load(syspath);
|
||||
if (!WeatherLoader::load(syspath, weather)) {
|
||||
throw std::runtime_error("Loading Weather " + path + " failed");
|
||||
}
|
||||
}
|
||||
|
||||
void GameData::loadHandling(const std::string& path) {
|
||||
|
@ -17,15 +17,15 @@
|
||||
#include <rw/defines.hpp>
|
||||
#include <rw/forward.hpp>
|
||||
|
||||
#include <data/AnimGroup.hpp>
|
||||
#include <data/GameTexts.hpp>
|
||||
#include <data/ModelData.hpp>
|
||||
#include <data/PedData.hpp>
|
||||
#include <data/Weather.hpp>
|
||||
#include <data/ZoneData.hpp>
|
||||
#include <data/AnimGroup.hpp>
|
||||
#include <loaders/LoaderDFF.hpp>
|
||||
#include <loaders/LoaderIMG.hpp>
|
||||
#include <loaders/LoaderTXD.hpp>
|
||||
#include <loaders/WeatherLoader.hpp>
|
||||
#include <objects/VehicleInfo.hpp>
|
||||
#include <gl/TextureData.hpp>
|
||||
|
||||
@ -269,9 +269,9 @@ public:
|
||||
TextureLoader textureLoader;
|
||||
|
||||
/**
|
||||
* Weather Loader
|
||||
* Weather Data
|
||||
*/
|
||||
WeatherLoader weatherLoader;
|
||||
Weather weather;
|
||||
|
||||
/**
|
||||
* Texture slots, containing loaded textures.
|
||||
|
@ -7,9 +7,24 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
namespace {
|
||||
RWTypes::RGB readRGB(std::stringstream &ss) {
|
||||
RWTypes::RGB color;
|
||||
std::string r, g, b;
|
||||
|
||||
bool WeatherLoader::load(const std::string& filename) {
|
||||
std::getline(ss, r, ' ');
|
||||
std::getline(ss, g, ' ');
|
||||
std::getline(ss, b, ' ');
|
||||
|
||||
color.r = atoi(r.c_str());
|
||||
color.b = atoi(b.c_str());
|
||||
color.g = atoi(g.c_str());
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
bool WeatherLoader::load(const std::string& filename, Weather& outWeather) {
|
||||
std::ifstream fstream(filename.c_str());
|
||||
|
||||
if (!fstream.is_open()) return false;
|
||||
@ -19,7 +34,7 @@ bool WeatherLoader::load(const std::string& filename) {
|
||||
if (line[0] == '/') // Comment line
|
||||
continue;
|
||||
|
||||
WeatherData weather;
|
||||
Weather::Entry weather;
|
||||
|
||||
// Convert tabs into spaces
|
||||
std::replace(line.begin(), line.end(), '\t', ' ');
|
||||
@ -68,68 +83,9 @@ bool WeatherLoader::load(const std::string& filename) {
|
||||
weather.unknown[i] = atoi(tmpstr.c_str());
|
||||
}
|
||||
|
||||
this->weather.push_back(weather);
|
||||
outWeather.entries.push_back(weather);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RWTypes::RGB mix(RWTypes::RGB x, RWTypes::RGB y, float a) {
|
||||
RWTypes::RGB n;
|
||||
n.r = x.r * (1.f - a) + y.r * a;
|
||||
n.g = x.g * (1.f - a) + y.g * a;
|
||||
n.b = x.b * (1.f - a) + y.b * a;
|
||||
return n;
|
||||
}
|
||||
|
||||
int32_t mixint(int32_t x, int32_t y, float a) {
|
||||
return x * (1.f - a) + y * a;
|
||||
}
|
||||
|
||||
#define MIXPROP(prop) data.prop = mix(x.prop, y.prop, a)
|
||||
#define MIXPROP2(prop) data.prop = glm::mix(x.prop, y.prop, a)
|
||||
#define MIXPROP_INT(prop) data.prop = mixint(x.prop, y.prop, a)
|
||||
|
||||
WeatherLoader::WeatherData WeatherLoader::getWeatherData(WeatherCondition cond,
|
||||
float tod) {
|
||||
size_t hour = floor(tod);
|
||||
const WeatherData& x = weather[static_cast<size_t>(cond) + hour];
|
||||
const WeatherData& y = weather[static_cast<size_t>(cond) + (hour + 1) % 24];
|
||||
const float a = tod - std::floor(tod);
|
||||
|
||||
WeatherData data;
|
||||
MIXPROP(ambientColor);
|
||||
MIXPROP(directLightColor);
|
||||
MIXPROP(skyTopColor);
|
||||
MIXPROP(skyBottomColor);
|
||||
MIXPROP(sunCoreColor);
|
||||
MIXPROP2(sunCoreSize);
|
||||
MIXPROP2(sunCoronaSize);
|
||||
MIXPROP2(sunBrightness);
|
||||
MIXPROP_INT(shadowIntensity);
|
||||
MIXPROP_INT(lightShading);
|
||||
MIXPROP_INT(poleShading);
|
||||
MIXPROP2(farClipping);
|
||||
MIXPROP2(fogStart);
|
||||
MIXPROP2(amountGroundLight);
|
||||
MIXPROP(lowCloudColor);
|
||||
MIXPROP(topCloudColor);
|
||||
MIXPROP(bottomCloudColor);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
RWTypes::RGB WeatherLoader::readRGB(std::stringstream& ss) {
|
||||
RWTypes::RGB color;
|
||||
std::string r, g, b;
|
||||
|
||||
std::getline(ss, r, ' ');
|
||||
std::getline(ss, g, ' ');
|
||||
std::getline(ss, b, ' ');
|
||||
|
||||
color.r = atoi(r.c_str());
|
||||
color.b = atoi(b.c_str());
|
||||
color.g = atoi(g.c_str());
|
||||
|
||||
return color;
|
||||
}
|
||||
|
@ -1,54 +1,12 @@
|
||||
#ifndef _RWENGINE_WEATHERLOADER_HPP_
|
||||
#define _RWENGINE_WEATHERLOADER_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <data/Weather.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <rw/types.hpp>
|
||||
|
||||
class WeatherLoader {
|
||||
public:
|
||||
struct WeatherData {
|
||||
RWTypes::RGB ambientColor;
|
||||
RWTypes::RGB directLightColor;
|
||||
RWTypes::RGB skyTopColor;
|
||||
RWTypes::RGB skyBottomColor;
|
||||
RWTypes::RGB sunCoreColor;
|
||||
RWTypes::RGB sunCoronaColor;
|
||||
float sunCoreSize;
|
||||
float sunCoronaSize;
|
||||
float sunBrightness;
|
||||
int32_t shadowIntensity;
|
||||
int32_t lightShading;
|
||||
int32_t poleShading;
|
||||
float farClipping;
|
||||
float fogStart;
|
||||
float amountGroundLight;
|
||||
RWTypes::RGB lowCloudColor;
|
||||
RWTypes::RGB topCloudColor;
|
||||
RWTypes::RGB bottomCloudColor;
|
||||
uint8_t unknown[4];
|
||||
};
|
||||
|
||||
enum WeatherCondition { Sunny = 0, Cloudy = 24, Rainy = 48, Foggy = 72 };
|
||||
|
||||
bool load(const std::string &filename);
|
||||
|
||||
std::vector<WeatherData> weather;
|
||||
|
||||
/**
|
||||
* @brief getWeatherData returns interpolated Weather data for the time of
|
||||
* day.
|
||||
* @param cond weather condition
|
||||
* @param tod float time of day
|
||||
* @return Correctly interpolated values.
|
||||
*/
|
||||
WeatherData getWeatherData(WeatherCondition cond, float tod);
|
||||
|
||||
private:
|
||||
RWTypes::RGB readRGB(std::stringstream &ss);
|
||||
};
|
||||
namespace WeatherLoader {
|
||||
bool load(const std::string &filename, Weather& outWeather);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -240,9 +240,9 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
||||
float tod = world->getHour() + world->getMinute() / 60.f;
|
||||
|
||||
// Requires a float 0-24
|
||||
auto weatherID = static_cast<WeatherLoader::WeatherCondition>(
|
||||
world->state->basic.nextWeather * 24);
|
||||
auto weather = world->data->weatherLoader.getWeatherData(weatherID, tod);
|
||||
auto weatherID = static_cast<WeatherCondition>(
|
||||
world->state->basic.nextWeather * 24);
|
||||
auto weather = world->data->weather.getWeatherData(weatherID, tod);
|
||||
|
||||
glm::vec3 skyTop = weather.skyTopColor;
|
||||
glm::vec3 skyBottom = weather.skyBottomColor;
|
||||
|
Loading…
Reference in New Issue
Block a user