Skip to content

Commit dab5e95

Browse files
committed
Initial dynamic weather support
1 parent 556cdfb commit dab5e95

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

rwengine/src/data/Weather.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class Weather {
4040
float a, float tod);
4141

4242
std::vector<Entry> entries;
43+
44+
// Taken from: https://www.gtamodding.com/wiki/Time_cycle#Weather_lists
45+
// TODO: This weather list applies only for GTA III
46+
const uint16_t WeatherList[64] = {
47+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 0,
48+
0, 0, 1, 3, 3, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2,
49+
2, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 2, 1
50+
};
4351
};
4452

4553
#endif

rwengine/src/engine/GameState.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct BasicState {
6464
uint8_t _align3[2]{0};
6565
uint16_t nextWeather{0};
6666
uint8_t _align4[2]{0};
67-
uint16_t forcedWeather{0};
67+
uint16_t forcedWeather{0xFFFF};
6868
uint8_t _align5[2]{0};
6969
float weatherInterpolation{1.f};
7070
uint8_t dateTime[24]{0}; // Unused

rwengine/src/script/modules/GTA3ModuleImpl.inl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4870,8 +4870,7 @@ void opcode_01b6(const ScriptArguments& args, const ScriptWeather weatherID) {
48704870
opcode 01b7
48714871
*/
48724872
void opcode_01b7(const ScriptArguments& args) {
4873-
RW_UNUSED(args);
4874-
args.getState()->basic.forcedWeather = -1;
4873+
args.getState()->basic.forcedWeather = UINT16_MAX;
48754874
}
48764875

48774876
/**

rwgame/RWGame.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ void RWGame::tick(float dt) {
533533
static float clockAccumulator = 0.f;
534534
static float scriptTimerAccumulator = 0.f;
535535
static ScriptInt beepTime = std::numeric_limits<ScriptInt>::max();
536+
static uint8_t prevGameHour = state.basic.gameHour;
536537
if (currState->shouldWorldUpdate()) {
537538
world->chase.update(dt);
538539

@@ -554,6 +555,8 @@ void RWGame::tick(float dt) {
554555
clockAccumulator -= 1.f;
555556
}
556557

558+
interpolateWeather(prevGameHour);
559+
557560
constexpr float timerClockRate = 1.f / 30.f;
558561

559562
if (state.scriptTimerVariable && !state.scriptTimerPaused) {
@@ -844,3 +847,23 @@ void RWGame::globalKeyEvent(const SDL_Event& event) {
844847
handleCheatInput(symbol);
845848
}
846849
}
850+
851+
void RWGame::interpolateWeather(uint8_t prevGameHour) {
852+
if (prevGameHour != state.basic.gameHour) {
853+
state.basic.lastWeather = state.basic.nextWeather;
854+
855+
// TODO: VC and SA has more than 4 weather conditions
856+
if (state.basic.forcedWeather > 3) {
857+
if (state.basic.weatherType < 63) {
858+
++state.basic.weatherType;
859+
} else {
860+
state.basic.weatherType = 0;
861+
}
862+
state.basic.nextWeather =
863+
data.weather.WeatherList[state.basic.weatherType];
864+
}
865+
}
866+
867+
state.basic.weatherInterpolation = state.basic.gameMinute / 60.f;
868+
}
869+

rwgame/RWGame.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ class RWGame final : public GameBase {
131131
void renderDebugView();
132132

133133
void tickObjects(float dt) const;
134+
135+
void interpolateWeather(uint8_t prevGameHour);
134136
};
135137

136138
#endif
139+

0 commit comments

Comments
 (0)