mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Replace some SDL functions with our own
This commit is contained in:
@@ -14,9 +14,7 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <SDL_platform.h>
|
||||
|
||||
#if defined(DEBUG) && defined(__WINDOWS__)
|
||||
#if defined(DEBUG) && defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef GetMessage
|
||||
@@ -29,7 +27,7 @@ namespace Debug
|
||||
void Break()
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
#if defined(__WINDOWS__)
|
||||
#if defined(_WIN32)
|
||||
if (IsDebuggerPresent())
|
||||
{
|
||||
DebugBreak();
|
||||
|
||||
@@ -427,7 +427,7 @@ void game_logic_update()
|
||||
|
||||
// start autosave timer after update
|
||||
if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE)
|
||||
gLastAutoSaveUpdate = SDL_GetTicks();
|
||||
gLastAutoSaveUpdate = platform_get_ticks();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,7 +585,7 @@ sint32 game_do_command_p(sint32 command, sint32 *eax, sint32 *ebx, sint32 *ecx,
|
||||
|
||||
// start autosave timer after game command
|
||||
if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE)
|
||||
gLastAutoSaveUpdate = SDL_GetTicks();
|
||||
gLastAutoSaveUpdate = platform_get_ticks();
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,8 @@ void chat_draw(rct_drawpixelinfo * dpi)
|
||||
|
||||
// Draw chat history
|
||||
for (sint32 i = 0; i < CHAT_HISTORY_SIZE; i++, y -= stringHeight) {
|
||||
if (!gChatOpen && SDL_TICKS_PASSED(SDL_GetTicks(), chat_history_get_time(i) + 10000)) {
|
||||
uint32 expireTime = chat_history_get_time(i) + 10000;
|
||||
if (!gChatOpen && platform_get_ticks() > expireTime) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ void chat_history_add(const char *src)
|
||||
sint32 index = _chatHistoryIndex % CHAT_HISTORY_SIZE;
|
||||
memset(_chatHistory[index], 0, CHAT_INPUT_SIZE);
|
||||
memcpy(_chatHistory[index], src, min(strlen(src), CHAT_INPUT_SIZE - 1));
|
||||
_chatHistoryTime[index] = SDL_GetTicks();
|
||||
_chatHistoryTime[index] = platform_get_ticks();
|
||||
_chatHistoryIndex++;
|
||||
Mixer_Play_Effect(SOUND_NEWS_ITEM, 0, SDL_MIX_MAXVOLUME, 0, 1.5f, true);
|
||||
network_append_chat_log(src);
|
||||
|
||||
@@ -85,7 +85,7 @@ sint32 NetworkConnection::ReadPacket()
|
||||
}
|
||||
if (InboundPacket.BytesTransferred == sizeof(InboundPacket.Size) + InboundPacket.Size)
|
||||
{
|
||||
_lastPacketTime = SDL_GetTicks();
|
||||
_lastPacketTime = platform_get_ticks();
|
||||
return NETWORK_READPACKET_SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -150,13 +150,13 @@ void NetworkConnection::SendQueuedPackets()
|
||||
|
||||
void NetworkConnection::ResetLastPacketTime()
|
||||
{
|
||||
_lastPacketTime = SDL_GetTicks();
|
||||
_lastPacketTime = platform_get_ticks();
|
||||
}
|
||||
|
||||
bool NetworkConnection::ReceivedPacketRecently()
|
||||
{
|
||||
#ifndef DEBUG
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), _lastPacketTime + 7000))
|
||||
if (platform_get_ticks() > _lastPacketTime + 7000)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ public:
|
||||
{
|
||||
switch (_status) {
|
||||
case ADVERTISE_STATUS_UNREGISTERED:
|
||||
if (_lastAdvertiseTime == 0 || SDL_TICKS_PASSED(SDL_GetTicks(), _lastAdvertiseTime + MASTER_SERVER_REGISTER_TIME))
|
||||
if (_lastAdvertiseTime == 0 || platform_get_ticks() > _lastAdvertiseTime + MASTER_SERVER_REGISTER_TIME)
|
||||
{
|
||||
SendRegistration();
|
||||
}
|
||||
break;
|
||||
case ADVERTISE_STATUS_REGISTERED:
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), _lastHeartbeatTime + MASTER_SERVER_HEARTBEAT_TIME))
|
||||
if (platform_get_ticks() > _lastHeartbeatTime + MASTER_SERVER_HEARTBEAT_TIME)
|
||||
{
|
||||
SendHeartbeat();
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
private:
|
||||
void SendRegistration()
|
||||
{
|
||||
_lastAdvertiseTime = SDL_GetTicks();
|
||||
_lastAdvertiseTime = platform_get_ticks();
|
||||
|
||||
// Send the registration request
|
||||
http_request_t request = { 0 };
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
request.root = jsonBody;
|
||||
request.type = HTTP_DATA_JSON;
|
||||
|
||||
_lastHeartbeatTime = SDL_GetTicks();
|
||||
_lastHeartbeatTime = platform_get_ticks();
|
||||
http_request_async(&request, [](http_response_t *response) -> void
|
||||
{
|
||||
if (response == nullptr)
|
||||
|
||||
@@ -80,7 +80,7 @@ struct ByteSwapT<2>
|
||||
{
|
||||
static uint16 SwapBE(uint16 value)
|
||||
{
|
||||
return SDL_SwapBE16(value);
|
||||
return (uint16)((value << 8) | (value >> 8));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,7 +89,10 @@ struct ByteSwapT<4>
|
||||
{
|
||||
static uint32 SwapBE(uint32 value)
|
||||
{
|
||||
return SDL_SwapBE32(value);
|
||||
return (uint32)(((value << 24) |
|
||||
((value << 8) & 0x00FF0000) |
|
||||
((value >> 8) & 0x0000FF00) |
|
||||
(value >> 24)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <SDL_platform.h>
|
||||
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../OpenRCT2.h"
|
||||
|
||||
@@ -380,10 +378,12 @@ void Network::UpdateServer()
|
||||
it++;
|
||||
}
|
||||
}
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), last_tick_sent_time + 25)) {
|
||||
|
||||
uint32 ticks = platform_get_ticks();
|
||||
if (ticks > last_tick_sent_time + 25) {
|
||||
Server_Send_TICK();
|
||||
}
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), last_ping_sent_time + 3000)) {
|
||||
if (ticks > last_ping_sent_time + 3000) {
|
||||
Server_Send_PING();
|
||||
Server_Send_PINGLIST();
|
||||
}
|
||||
@@ -427,7 +427,7 @@ void Network::UpdateClient()
|
||||
window_network_status_open(str_connecting, []() -> void {
|
||||
gNetwork.Close();
|
||||
});
|
||||
server_connect_time = SDL_GetTicks();
|
||||
server_connect_time = platform_get_ticks();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1044,7 +1044,7 @@ void Network::Server_Send_GAMECMD(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx
|
||||
|
||||
void Network::Server_Send_TICK()
|
||||
{
|
||||
last_tick_sent_time = SDL_GetTicks();
|
||||
last_tick_sent_time = platform_get_ticks();
|
||||
std::unique_ptr<NetworkPacket> packet(NetworkPacket::Allocate());
|
||||
*packet << (uint32)NETWORK_COMMAND_TICK << (uint32)gCurrentTicks << (uint32)gScenarioSrand0;
|
||||
uint32 flags = 0;
|
||||
@@ -1085,11 +1085,11 @@ void Network::Client_Send_PING()
|
||||
|
||||
void Network::Server_Send_PING()
|
||||
{
|
||||
last_ping_sent_time = SDL_GetTicks();
|
||||
last_ping_sent_time = platform_get_ticks();
|
||||
std::unique_ptr<NetworkPacket> packet(NetworkPacket::Allocate());
|
||||
*packet << (uint32)NETWORK_COMMAND_PING;
|
||||
for (auto it = client_connection_list.begin(); it != client_connection_list.end(); it++) {
|
||||
(*it)->PingTime = SDL_GetTicks();
|
||||
(*it)->PingTime = platform_get_ticks();
|
||||
}
|
||||
SendPacketToClients(*packet, true);
|
||||
}
|
||||
@@ -1254,7 +1254,7 @@ void Network::ProcessGameCommandQueue()
|
||||
NetworkPlayer* player = GetPlayerByID(gc.playerid);
|
||||
if (player) {
|
||||
player->LastAction = NetworkActions::FindCommand(command);
|
||||
player->LastActionTime = SDL_GetTicks();
|
||||
player->LastActionTime = platform_get_ticks();
|
||||
player->AddMoneySpent(cost);
|
||||
}
|
||||
}
|
||||
@@ -1860,7 +1860,7 @@ void Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket
|
||||
|
||||
sint32 commandCommand = args[4];
|
||||
|
||||
uint32 ticks = SDL_GetTicks(); //tick count is different by time last_action_time is set, keep same value.
|
||||
uint32 ticks = platform_get_ticks(); //tick count is different by time last_action_time is set, keep same value.
|
||||
|
||||
// Check if player's group permission allows command to run
|
||||
NetworkGroup* group = GetGroupByID(connection.Player->Group);
|
||||
@@ -1875,7 +1875,7 @@ void Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket
|
||||
if (commandCommand == GAME_COMMAND_PLACE_SCENERY) {
|
||||
if (
|
||||
ticks - connection.Player->LastPlaceSceneryTime < ACTION_COOLDOWN_TIME_PLACE_SCENERY &&
|
||||
// Incase SDL_GetTicks() wraps after ~49 days, ignore larger logged times.
|
||||
// Incase platform_get_ticks() wraps after ~49 days, ignore larger logged times.
|
||||
ticks > connection.Player->LastPlaceSceneryTime
|
||||
) {
|
||||
if (!(group->CanPerformCommand(MISC_COMMAND_TOGGLE_SCENERY_CLUSTER))) {
|
||||
@@ -1889,7 +1889,7 @@ void Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket
|
||||
else if (commandCommand == GAME_COMMAND_DEMOLISH_RIDE) {
|
||||
if (
|
||||
ticks - connection.Player->LastDemolishRideTime < ACTION_COOLDOWN_TIME_DEMOLISH_RIDE &&
|
||||
// Incase SDL_GetTicks() wraps after ~49 days, ignore larger logged times.
|
||||
// Incase platform_get_ticks() wraps after ~49 days, ignore larger logged times.
|
||||
ticks > connection.Player->LastDemolishRideTime
|
||||
) {
|
||||
Server_Send_SHOWERROR(connection, STR_CANT_DO_THIS, STR_NETWORK_ACTION_RATE_LIMIT_MESSAGE);
|
||||
@@ -1912,7 +1912,7 @@ void Network::Server_Handle_GAMECMD(NetworkConnection& connection, NetworkPacket
|
||||
}
|
||||
|
||||
connection.Player->LastAction = NetworkActions::FindCommand(commandCommand);
|
||||
connection.Player->LastActionTime = SDL_GetTicks();
|
||||
connection.Player->LastActionTime = platform_get_ticks();
|
||||
connection.Player->AddMoneySpent(cost);
|
||||
|
||||
if (commandCommand == GAME_COMMAND_PLACE_SCENERY) {
|
||||
@@ -1986,7 +1986,7 @@ void Network::Client_Handle_PING(NetworkConnection& connection, NetworkPacket& p
|
||||
|
||||
void Network::Server_Handle_PING(NetworkConnection& connection, NetworkPacket& packet)
|
||||
{
|
||||
sint32 ping = SDL_GetTicks() - connection.PingTime;
|
||||
sint32 ping = platform_get_ticks() - connection.PingTime;
|
||||
if (ping < 0) {
|
||||
ping = 0;
|
||||
}
|
||||
@@ -2204,7 +2204,7 @@ void network_add_player_money_spent(uint32 index, money32 cost)
|
||||
|
||||
sint32 network_get_player_last_action(uint32 index, sint32 time)
|
||||
{
|
||||
if (time && SDL_TICKS_PASSED(SDL_GetTicks(), gNetwork.player_list[index]->LastActionTime + time)) {
|
||||
if (time && platform_get_ticks() > gNetwork.player_list[index]->LastActionTime + time) {
|
||||
return -999;
|
||||
}
|
||||
return gNetwork.player_list[index]->LastAction;
|
||||
@@ -2213,7 +2213,7 @@ sint32 network_get_player_last_action(uint32 index, sint32 time)
|
||||
void network_set_player_last_action(uint32 index, sint32 command)
|
||||
{
|
||||
gNetwork.player_list[index]->LastAction = NetworkActions::FindCommand(command);
|
||||
gNetwork.player_list[index]->LastActionTime = SDL_GetTicks();
|
||||
gNetwork.player_list[index]->LastActionTime = platform_get_ticks();
|
||||
}
|
||||
|
||||
rct_xyz16 network_get_player_last_action_coord(uint32 index)
|
||||
|
||||
@@ -43,6 +43,7 @@ extern "C"
|
||||
#include "../localisation/localisation.h"
|
||||
#include "../management/news_item.h"
|
||||
#include "../peep/peep.h"
|
||||
#include "../platform/platform.h"
|
||||
#include "../rct2.h"
|
||||
#include "../util/util.h"
|
||||
#include "../world/sprite.h"
|
||||
@@ -142,7 +143,7 @@ namespace Twitch
|
||||
switch (_twitchState) {
|
||||
case TWITCH_STATE_LEFT:
|
||||
{
|
||||
uint32 currentTime = SDL_GetTicks();
|
||||
uint32 currentTime = platform_get_ticks();
|
||||
uint32 timeSinceLastPulse = currentTime - _twitchLastPulseTick;
|
||||
if (_twitchLastPulseTick == 0 || timeSinceLastPulse > PulseTime)
|
||||
{
|
||||
@@ -153,7 +154,7 @@ namespace Twitch
|
||||
}
|
||||
case TWITCH_STATE_JOINED:
|
||||
{
|
||||
uint32 currentTime = SDL_GetTicks();
|
||||
uint32 currentTime = platform_get_ticks();
|
||||
uint32 timeSinceLastPulse = currentTime - _twitchLastPulseTick;
|
||||
if (_twitchLastPulseTick == 0 || timeSinceLastPulse > PulseTime) {
|
||||
_twitchLastPulseTick = currentTime;
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <SDL_platform.h>
|
||||
#include "crash.h"
|
||||
|
||||
#ifdef USE_BREAKPAD
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
#if defined(_WIN32)
|
||||
#include <breakpad/client/windows/handler/exception_handler.h>
|
||||
#include <string>
|
||||
#include <ShlObj.h>
|
||||
|
||||
@@ -188,6 +188,7 @@ void platform_get_cursor_position(sint32 *x, sint32 *y);
|
||||
void platform_get_cursor_position_scaled(sint32 *x, sint32 *y);
|
||||
void platform_set_cursor_position(sint32 x, sint32 y);
|
||||
uint32 platform_get_ticks();
|
||||
void platform_sleep(uint32 ms);
|
||||
void platform_resolve_user_data_path();
|
||||
void platform_resolve_openrct_data_path();
|
||||
void platform_get_openrct_data_path(utf8 *outPath, size_t outSize);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "../audio/audio.h"
|
||||
#include "../audio/AudioMixer.h"
|
||||
#include "../config/Config.h"
|
||||
@@ -761,7 +762,21 @@ void platform_set_cursor_position(sint32 x, sint32 y)
|
||||
|
||||
uint32 platform_get_ticks()
|
||||
{
|
||||
return SDL_GetTicks();
|
||||
#ifdef _WIN32
|
||||
return GetTickCount();
|
||||
#else
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
||||
log_fatal("clock_gettime failed");
|
||||
exit(-1);
|
||||
}
|
||||
return (uint32)(ts.tv_nsec / 1000000);
|
||||
#endif
|
||||
}
|
||||
|
||||
void platform_sleep(uint32 ms)
|
||||
{
|
||||
SDL_Delay(ms);
|
||||
}
|
||||
|
||||
uint8 platform_get_currency_value(const char *currCode) {
|
||||
|
||||
@@ -380,7 +380,7 @@ sint32 check_file_paths()
|
||||
|
||||
void rct2_update()
|
||||
{
|
||||
sint32 tickCount = SDL_GetTicks();
|
||||
sint32 tickCount = platform_get_ticks();
|
||||
gTicksSinceLastUpdate = min(tickCount - gLastTickCount, 500);
|
||||
gLastTickCount = tickCount;
|
||||
if (game_is_not_paused()) {
|
||||
|
||||
@@ -362,7 +362,7 @@ void scenario_autosave_check()
|
||||
if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE) return;
|
||||
|
||||
// Milliseconds since last save
|
||||
uint32 timeSinceSave = SDL_GetTicks() - gLastAutoSaveUpdate;
|
||||
uint32 timeSinceSave = platform_get_ticks() - gLastAutoSaveUpdate;
|
||||
|
||||
bool shouldSave = false;
|
||||
switch (gConfigGeneral.autosave_frequency) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#ifndef _SAWYERCODING_H_
|
||||
#define _SAWYERCODING_H_
|
||||
|
||||
#include <SDL.h>
|
||||
#include "../common.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
// Include common.h before SDL, otherwise M_PI gets redefined
|
||||
#include "../common.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../localisation/localisation.h"
|
||||
#include "../platform/platform.h"
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "../game.h"
|
||||
#include "../localisation/string_ids.h"
|
||||
#include "../object.h"
|
||||
#include "../platform/platform.h"
|
||||
#include "../util/util.h"
|
||||
#include "../windows/error.h"
|
||||
#include "map.h"
|
||||
@@ -142,7 +143,7 @@ void mapgen_generate(mapgen_settings *settings)
|
||||
sint32 x, y, mapSize, floorTexture, wallTexture, waterLevel;
|
||||
rct_map_element *mapElement;
|
||||
|
||||
util_srand((sint32)SDL_GetTicks());
|
||||
util_srand((sint32)platform_get_ticks());
|
||||
|
||||
mapSize = settings->mapSize;
|
||||
floorTexture = settings->floor;
|
||||
|
||||
Reference in New Issue
Block a user