Skip to content

Commit

Permalink
Initial dynamic weather support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lihis committed Jan 9, 2025
1 parent 556cdfb commit dab5e95
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
8 changes: 8 additions & 0 deletions rwengine/src/data/Weather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class Weather {
float a, float tod);

std::vector<Entry> entries;

// Taken from: https://www.gtamodding.com/wiki/Time_cycle#Weather_lists
// TODO: This weather list applies only for GTA III
const uint16_t WeatherList[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 0,
0, 0, 1, 3, 3, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2,
2, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 2, 1
};
};

#endif
2 changes: 1 addition & 1 deletion rwengine/src/engine/GameState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct BasicState {
uint8_t _align3[2]{0};
uint16_t nextWeather{0};
uint8_t _align4[2]{0};
uint16_t forcedWeather{0};
uint16_t forcedWeather{0xFFFF};
uint8_t _align5[2]{0};
float weatherInterpolation{1.f};
uint8_t dateTime[24]{0}; // Unused
Expand Down
3 changes: 1 addition & 2 deletions rwengine/src/script/modules/GTA3ModuleImpl.inl
Original file line number Diff line number Diff line change
Expand Up @@ -4870,8 +4870,7 @@ void opcode_01b6(const ScriptArguments& args, const ScriptWeather weatherID) {
opcode 01b7
*/
void opcode_01b7(const ScriptArguments& args) {
RW_UNUSED(args);
args.getState()->basic.forcedWeather = -1;
args.getState()->basic.forcedWeather = UINT16_MAX;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions rwgame/RWGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ void RWGame::tick(float dt) {
static float clockAccumulator = 0.f;
static float scriptTimerAccumulator = 0.f;
static ScriptInt beepTime = std::numeric_limits<ScriptInt>::max();
static uint8_t prevGameHour = state.basic.gameHour;
if (currState->shouldWorldUpdate()) {
world->chase.update(dt);

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

interpolateWeather(prevGameHour);

constexpr float timerClockRate = 1.f / 30.f;

if (state.scriptTimerVariable && !state.scriptTimerPaused) {
Expand Down Expand Up @@ -844,3 +847,23 @@ void RWGame::globalKeyEvent(const SDL_Event& event) {
handleCheatInput(symbol);
}
}

void RWGame::interpolateWeather(uint8_t prevGameHour) {
if (prevGameHour != state.basic.gameHour) {
state.basic.lastWeather = state.basic.nextWeather;

// TODO: VC and SA has more than 4 weather conditions
if (state.basic.forcedWeather > 3) {
if (state.basic.weatherType < 63) {
++state.basic.weatherType;
} else {
state.basic.weatherType = 0;
}
state.basic.nextWeather =
data.weather.WeatherList[state.basic.weatherType];
}
}

state.basic.weatherInterpolation = state.basic.gameMinute / 60.f;
}

3 changes: 3 additions & 0 deletions rwgame/RWGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class RWGame final : public GameBase {
void renderDebugView();

void tickObjects(float dt) const;

void interpolateWeather(uint8_t prevGameHour);
};

#endif

0 comments on commit dab5e95

Please sign in to comment.