mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-19 08:52:33 +02:00
Added WeatherLoader! Hopefully correct as documentation is lacking! Woo!
This commit is contained in:
parent
df77d96ac6
commit
c2ebea6d84
76
framework2/WeatherLoader.cpp
Normal file
76
framework2/WeatherLoader.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include <renderwure/loaders/WeatherLoader.hpp>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
bool WeatherLoader::load(const std::string &filename)
|
||||||
|
{
|
||||||
|
std::ifstream fstream(filename.c_str());
|
||||||
|
|
||||||
|
if ( ! fstream.is_open())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(fstream, line)) {
|
||||||
|
if (line[0] == '/') // Comment line
|
||||||
|
continue;
|
||||||
|
|
||||||
|
WeatherData weather;
|
||||||
|
|
||||||
|
// Convert tabs into spaces
|
||||||
|
std::replace(line.begin(), line.end(), '\t', ' ');
|
||||||
|
// Remove all duplicate whitespace
|
||||||
|
line.erase(std::unique(line.begin(), line.end(), [](char l, char r) { return l == r && std::isspace(l); }), line.end());
|
||||||
|
|
||||||
|
std::stringstream ss(line);
|
||||||
|
std::string tmpstr;
|
||||||
|
|
||||||
|
weather.ambientColor = readRGB(ss);
|
||||||
|
weather.directLightColor = readRGB(ss);
|
||||||
|
weather.skyTopColor = readRGB(ss);
|
||||||
|
weather.skyBottomColor = readRGB(ss);
|
||||||
|
weather.sunCoreColor = readRGB(ss);
|
||||||
|
weather.sunCoronaColor = readRGB(ss);
|
||||||
|
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.sunCoreSize = atof(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.sunCoronaSize = atof(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.sunBrightness = atof(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.shadowIntensity = atoi(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.lightShading = atoi(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.poleShading = atoi(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.farClipping = atof(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.fogStart = atof(tmpstr.c_str());
|
||||||
|
std::getline(ss, tmpstr, ' '); weather.amountGroundLight = atof(tmpstr.c_str());
|
||||||
|
|
||||||
|
weather.lowCloudColor = readRGB(ss);
|
||||||
|
weather.topCloudColor = readRGB(ss);
|
||||||
|
weather.bottomCloudColor = readRGB(ss);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 4; i++) {
|
||||||
|
std::getline(ss, tmpstr, ' ');
|
||||||
|
weather.unknown[i] = atoi(tmpstr.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
this->weather.push_back(weather);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
GTAData::RGB WeatherLoader::readRGB(std::stringstream &ss)
|
||||||
|
{
|
||||||
|
GTAData::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;
|
||||||
|
}
|
43
framework2/include/renderwure/loaders/WeatherLoader.hpp
Normal file
43
framework2/include/renderwure/loaders/WeatherLoader.hpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef _WEATHERLOADER_HPP_
|
||||||
|
#define _WEATHERLOADER_HPP_
|
||||||
|
|
||||||
|
#include <renderwure/engine/GTAData.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
class WeatherLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct WeatherData {
|
||||||
|
GTAData::RGB ambientColor;
|
||||||
|
GTAData::RGB directLightColor;
|
||||||
|
GTAData::RGB skyTopColor;
|
||||||
|
GTAData::RGB skyBottomColor;
|
||||||
|
GTAData::RGB sunCoreColor;
|
||||||
|
GTAData::RGB sunCoronaColor;
|
||||||
|
float sunCoreSize;
|
||||||
|
float sunCoronaSize;
|
||||||
|
float sunBrightness;
|
||||||
|
int32_t shadowIntensity;
|
||||||
|
int32_t lightShading;
|
||||||
|
int32_t poleShading;
|
||||||
|
float farClipping;
|
||||||
|
float fogStart;
|
||||||
|
float amountGroundLight;
|
||||||
|
GTAData::RGB lowCloudColor;
|
||||||
|
GTAData::RGB topCloudColor;
|
||||||
|
GTAData::RGB bottomCloudColor;
|
||||||
|
uint8_t unknown[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
bool load(const std::string &filename);
|
||||||
|
|
||||||
|
std::vector<WeatherData> weather;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GTAData::RGB readRGB(std::stringstream &ss);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user