Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rwengine/src/audio/SoundSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int read_packet(void* opaque, uint8_t* buf, int buf_size) {
memcpy(buf, input->ptr, buf_size);
input->ptr += buf_size;
input->size -= buf_size;
return buf_size;
return buf_size <= 0 ? AVERROR_EOF : buf_size;
}
} // namespace

Expand Down
2 changes: 1 addition & 1 deletion rwengine/src/audio/SoundSource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SoundSource {
AVFrame* frame = nullptr;
AVFormatContext* formatContext = nullptr;
AVStream* audioStream = nullptr;
AVCodec* codec = nullptr;
const AVCodec* codec = nullptr;
SwrContext* swr = nullptr;
AVCodecContext* codecContext = nullptr;
AVPacket readingPacket;
Expand Down
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
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document wether this comes from the game files or wether it's just typed by hand by observing what the game does.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented 13c4e76

};

#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
17 changes: 17 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,22 @@ void RWGame::tick(float dt) {
clockAccumulator -= 1.f;
}

if (prevGameHour != state.basic.gameHour) {
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;

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

if (state.scriptTimerVariable && !state.scriptTimerPaused) {
Expand Down