2014-10-09 01:30:22 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (c) 2014 Ted John
|
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
|
|
|
* This file is part of OpenRCT2.
|
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-08-04 01:08:42 +02:00
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2015-08-04 01:08:42 +02:00
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "addresses.h"
|
|
|
|
#include "audio/audio.h"
|
|
|
|
#include "audio/mixer.h"
|
|
|
|
#include "cmdline.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "editor.h"
|
2015-07-05 13:12:34 +02:00
|
|
|
#include "game.h"
|
2015-07-05 17:48:25 +02:00
|
|
|
#include "hook.h"
|
2015-07-19 01:57:42 +02:00
|
|
|
#include "interface/chat.h"
|
2015-07-04 21:00:32 +02:00
|
|
|
#include "interface/window.h"
|
2015-07-09 19:00:46 +02:00
|
|
|
#include "interface/viewport.h"
|
2014-10-09 01:30:22 +02:00
|
|
|
#include "localisation/localisation.h"
|
2015-05-25 21:36:40 +02:00
|
|
|
#include "network/http.h"
|
2015-02-12 12:30:57 +01:00
|
|
|
#include "network/network.h"
|
2014-10-09 01:30:22 +02:00
|
|
|
#include "openrct2.h"
|
2014-10-09 15:03:54 +02:00
|
|
|
#include "platform/platform.h"
|
2015-07-10 21:29:50 +02:00
|
|
|
#include "ride/ride.h"
|
2015-07-15 00:59:29 +02:00
|
|
|
#include "title.h"
|
2014-10-10 23:50:22 +02:00
|
|
|
#include "util/sawyercoding.h"
|
2015-07-15 00:59:29 +02:00
|
|
|
#include "util/util.h"
|
2015-02-08 04:19:24 +01:00
|
|
|
#include "world/mapgen.h"
|
2014-10-09 01:30:22 +02:00
|
|
|
|
|
|
|
int gOpenRCT2StartupAction = STARTUP_ACTION_TITLE;
|
2015-08-01 17:40:15 +02:00
|
|
|
utf8 gOpenRCT2StartupActionPath[512] = { 0 };
|
|
|
|
utf8 gExePath[MAX_PATH];
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2015-05-29 21:45:21 +02:00
|
|
|
// This should probably be changed later and allow a custom selection of things to initialise like SDL_INIT
|
|
|
|
bool gOpenRCT2Headless = false;
|
|
|
|
|
2015-06-13 14:30:50 +02:00
|
|
|
bool gOpenRCT2ShowChangelog;
|
|
|
|
|
2014-10-09 15:31:51 +02:00
|
|
|
/** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to 0. */
|
|
|
|
int _finished;
|
|
|
|
|
2015-07-06 23:21:25 +02:00
|
|
|
// Used for object movement tweening
|
|
|
|
static struct { sint16 x, y, z; } _spritelocations1[MAX_SPRITES], _spritelocations2[MAX_SPRITES];
|
|
|
|
|
2014-10-09 15:31:51 +02:00
|
|
|
static void openrct2_loop();
|
|
|
|
|
2015-08-04 22:41:45 +02:00
|
|
|
static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *newDirectory, const utf8 *extension)
|
2015-02-14 03:16:03 +01:00
|
|
|
{
|
2015-08-04 22:41:45 +02:00
|
|
|
utf8 *ch, filter[MAX_PATH], oldPath[MAX_PATH], newPath[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
int fileEnumHandle;
|
|
|
|
file_info fileInfo;
|
2015-08-04 01:08:42 +02:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
if (!platform_ensure_directory_exists(newDirectory)) {
|
|
|
|
log_error("Could not create directory %s.", newDirectory);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create filter path
|
|
|
|
strcpy(filter, originalDirectory);
|
|
|
|
ch = strchr(filter, '*');
|
|
|
|
if (ch != NULL)
|
|
|
|
*ch = 0;
|
|
|
|
strcat(filter, "*");
|
|
|
|
strcat(filter, extension);
|
|
|
|
|
|
|
|
fileEnumHandle = platform_enumerate_files_begin(filter);
|
|
|
|
while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) {
|
|
|
|
strcpy(newPath, newDirectory);
|
|
|
|
strcat(newPath, fileInfo.path);
|
2015-08-04 01:08:42 +02:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
strcpy(oldPath, originalDirectory);
|
|
|
|
ch = strchr(oldPath, '*');
|
|
|
|
if (ch != NULL)
|
|
|
|
*ch = 0;
|
|
|
|
strcat(oldPath, fileInfo.path);
|
|
|
|
|
|
|
|
if (!platform_file_exists(newPath))
|
2015-08-04 22:41:45 +02:00
|
|
|
platform_file_copy(oldPath, newPath, false);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
platform_enumerate_files_end(fileEnumHandle);
|
2015-02-15 18:31:16 +01:00
|
|
|
|
|
|
|
fileEnumHandle = platform_enumerate_directories_begin(originalDirectory);
|
|
|
|
while (platform_enumerate_directories_next(fileEnumHandle, filter)) {
|
|
|
|
strcpy(newPath, newDirectory);
|
|
|
|
strcat(newPath, filter);
|
|
|
|
|
|
|
|
strcpy(oldPath, originalDirectory);
|
|
|
|
ch = strchr(oldPath, '*');
|
|
|
|
if (ch != NULL)
|
|
|
|
*ch = 0;
|
|
|
|
strcat(oldPath, filter);
|
|
|
|
|
|
|
|
if (!platform_ensure_directory_exists(newPath)) {
|
|
|
|
log_error("Could not create directory %s.", newPath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
openrct2_copy_files_over(oldPath, newPath, extension);
|
|
|
|
}
|
|
|
|
platform_enumerate_directories_end(fileEnumHandle);
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-08-04 22:41:45 +02:00
|
|
|
// TODO move to platform
|
2015-06-16 05:34:52 +02:00
|
|
|
static void openrct2_set_exe_path()
|
|
|
|
{
|
2015-08-04 01:08:42 +02:00
|
|
|
#ifdef _WIN32
|
2015-08-01 17:40:15 +02:00
|
|
|
wchar_t exePath[MAX_PATH];
|
|
|
|
wchar_t tempPath[MAX_PATH];
|
|
|
|
wchar_t *exeDelimiter;
|
2015-06-16 05:34:52 +02:00
|
|
|
int exeDelimiterIndex;
|
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
GetModuleFileNameW(NULL, exePath, MAX_PATH);
|
|
|
|
exeDelimiter = wcsrchr(exePath, platform_get_path_separator());
|
2015-06-16 05:34:52 +02:00
|
|
|
exeDelimiterIndex = (int)(exeDelimiter - exePath);
|
2015-08-01 17:40:15 +02:00
|
|
|
lstrcpynW(tempPath, exePath, exeDelimiterIndex + 1);
|
|
|
|
tempPath[exeDelimiterIndex] = L'\0';
|
|
|
|
_wfullpath(exePath, tempPath, MAX_PATH);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, exePath, countof(exePath), gExePath, countof(gExePath), NULL, NULL);
|
2015-08-04 01:08:42 +02:00
|
|
|
#else
|
|
|
|
char exePath[MAX_PATH];
|
|
|
|
ssize_t bytesRead;
|
|
|
|
bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH);
|
|
|
|
if (bytesRead == -1) {
|
|
|
|
log_fatal("failed to read /proc/self/exe");
|
|
|
|
}
|
|
|
|
exePath[MAX_PATH - 1] = '\0';
|
|
|
|
strncpy(gExePath, exePath, MAX_PATH);
|
|
|
|
#endif // _WIN32
|
2015-06-16 05:34:52 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
/**
|
|
|
|
* Copy saved games and landscapes to user directory
|
|
|
|
*/
|
|
|
|
static void openrct2_copy_original_user_files_over()
|
|
|
|
{
|
2015-08-04 22:41:45 +02:00
|
|
|
utf8 path[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
platform_get_user_directory(path, "save");
|
2015-08-04 22:41:45 +02:00
|
|
|
openrct2_copy_files_over((utf8*)RCT2_ADDRESS_SAVED_GAMES_PATH, path, ".sv6");
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
platform_get_user_directory(path, "landscape");
|
2015-08-04 22:41:45 +02:00
|
|
|
openrct2_copy_files_over((utf8*)RCT2_ADDRESS_LANDSCAPES_PATH, path, ".sc6");
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
bool openrct2_initialise()
|
2014-10-09 01:30:22 +02:00
|
|
|
{
|
2015-08-04 22:41:45 +02:00
|
|
|
utf8 userPath[MAX_PATH];
|
2015-02-14 03:16:03 +01:00
|
|
|
|
|
|
|
platform_get_user_directory(userPath, NULL);
|
|
|
|
if (!platform_ensure_directory_exists(userPath)) {
|
|
|
|
log_fatal("Could not create user directory (do you have write access to your documents folder?)");
|
2015-05-29 00:04:02 +02:00
|
|
|
return false;
|
2015-02-14 03:16:03 +01:00
|
|
|
}
|
|
|
|
|
2015-06-16 05:34:52 +02:00
|
|
|
openrct2_set_exe_path();
|
|
|
|
|
2015-02-16 23:47:11 +01:00
|
|
|
config_set_defaults();
|
|
|
|
if (!config_open_default()) {
|
|
|
|
if (!config_find_or_browse_install_directory()) {
|
|
|
|
log_fatal("An RCT2 install directory must be specified!");
|
2015-05-29 00:04:02 +02:00
|
|
|
return false;
|
2015-02-16 23:47:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 14:30:50 +02:00
|
|
|
gOpenRCT2ShowChangelog = true;
|
|
|
|
if (gConfigGeneral.last_run_version != NULL && (strcmp(gConfigGeneral.last_run_version, OPENRCT2_VERSION) == 0))
|
|
|
|
gOpenRCT2ShowChangelog = false;
|
|
|
|
gConfigGeneral.last_run_version = OPENRCT2_VERSION;
|
2015-02-16 23:47:11 +01:00
|
|
|
config_save_default();
|
2014-10-09 15:03:54 +02:00
|
|
|
|
|
|
|
// TODO add configuration option to allow multiple instances
|
2015-02-12 12:30:57 +01:00
|
|
|
// if (!gOpenRCT2Headless && !platform_lock_single_instance()) {
|
|
|
|
// log_fatal("OpenRCT2 is already running.");
|
|
|
|
// return false;
|
|
|
|
// }
|
2014-10-09 15:03:54 +02:00
|
|
|
|
2014-10-09 01:30:22 +02:00
|
|
|
get_system_info();
|
2015-05-29 21:45:21 +02:00
|
|
|
if (!gOpenRCT2Headless) {
|
|
|
|
audio_init();
|
|
|
|
audio_get_devices();
|
2015-08-04 01:08:42 +02:00
|
|
|
#ifdef _WIN32
|
2015-05-29 21:45:21 +02:00
|
|
|
get_dsound_devices();
|
2015-08-04 01:08:42 +02:00
|
|
|
#else
|
|
|
|
STUB();
|
|
|
|
#endif // _WIN32
|
2015-05-29 21:45:21 +02:00
|
|
|
}
|
2015-02-16 23:47:11 +01:00
|
|
|
language_open(gConfigGeneral.language);
|
2015-05-25 21:36:40 +02:00
|
|
|
http_init();
|
2015-05-30 22:00:13 +02:00
|
|
|
|
2015-06-01 17:02:09 +02:00
|
|
|
themes_set_default();
|
|
|
|
themes_load_presets();
|
2015-06-24 18:22:12 +02:00
|
|
|
title_sequences_set_default();
|
|
|
|
title_sequences_load_presets();
|
2015-05-30 22:00:13 +02:00
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
// Hooks to allow RCT2 to call OpenRCT2 functions instead
|
2015-07-29 17:34:13 +02:00
|
|
|
addhook(0x006E732D, (int)gfx_set_dirty_blocks, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when all callers are decompiled
|
|
|
|
addhook(0x006E7499, (int)gfx_redraw_screen_rect, 0, (int[]){ EAX, EBX, EDX, EBP, END }, 0, 0); // remove when 0x6E7FF3 is decompiled
|
|
|
|
addhook(0x006B752C, (int)ride_crash, 0, (int[]){ EDX, EBX, END }, 0, 0); // remove when all callers are decompiled
|
|
|
|
addhook(0x0069A42F, (int)peep_window_state_update, 0, (int[]){ ESI, END }, 0, 0); // remove when all callers are decompiled
|
|
|
|
addhook(0x006BB76E, (int)sound_play_panned, 0, (int[]){EAX, EBX, ECX, EDX, EBP, END}, EAX, 0); // remove when all callers are decompiled
|
|
|
|
addhook(0x006C42D9, (int)scrolling_text_setup, 0, (int[]){EAX, ECX, EBP, END}, 0, EBX); // remove when all callers are decompiled
|
|
|
|
addhook(0x006C2321, (int)gfx_get_string_width, 0, (int[]){ESI, END}, 0, ECX); // remove when all callers are decompiled
|
2015-08-03 15:29:05 +02:00
|
|
|
addhook(0x006C2555, (int)format_string, 0, (int[]){EDI, EAX, ECX, END}, 0, 0); // remove when all callers are decompiled
|
2015-07-10 02:39:16 +02:00
|
|
|
|
2014-11-23 00:30:03 +01:00
|
|
|
if (!rct2_init())
|
2015-05-29 00:04:02 +02:00
|
|
|
return false;
|
2015-07-19 01:57:42 +02:00
|
|
|
|
|
|
|
chat_init();
|
2014-11-23 00:30:03 +01:00
|
|
|
|
2015-02-14 03:16:03 +01:00
|
|
|
openrct2_copy_original_user_files_over();
|
|
|
|
|
2015-07-15 00:59:29 +02:00
|
|
|
// TODO move to audio initialise function
|
|
|
|
if (str_is_null_or_empty(gConfigSound.device)) {
|
|
|
|
Mixer_Init(NULL);
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = 0;
|
|
|
|
} else {
|
|
|
|
Mixer_Init(gConfigSound.device);
|
|
|
|
for (int i = 0; i < gAudioDeviceCount; i++) {
|
|
|
|
if (strcmp(gAudioDevices[i].name, gConfigSound.device) == 0) {
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_SOUND_DEVICE, uint32) = i;
|
|
|
|
}
|
2015-07-14 23:49:46 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-15 00:59:29 +02:00
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
/**
|
|
|
|
* Launches the game, after command line arguments have been parsed and processed.
|
|
|
|
*/
|
|
|
|
void openrct2_launch()
|
|
|
|
{
|
|
|
|
if (openrct2_initialise()) {
|
2014-10-09 01:30:22 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, uint8) = 0;
|
2015-07-26 16:07:58 +02:00
|
|
|
if((gOpenRCT2StartupAction == STARTUP_ACTION_TITLE) && gConfigGeneral.play_intro)
|
|
|
|
gOpenRCT2StartupAction = STARTUP_ACTION_INTRO;
|
|
|
|
|
2015-06-03 18:11:19 +02:00
|
|
|
switch (gOpenRCT2StartupAction) {
|
|
|
|
case STARTUP_ACTION_INTRO:
|
2015-07-26 16:07:58 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_RUN_INTRO_TICK_PART, uint8) = 1;
|
2015-06-03 18:11:19 +02:00
|
|
|
break;
|
|
|
|
case STARTUP_ACTION_TITLE:
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_TITLE_DEMO;
|
|
|
|
break;
|
|
|
|
case STARTUP_ACTION_OPEN:
|
|
|
|
assert(gOpenRCT2StartupActionPath != NULL);
|
|
|
|
rct2_open_file(gOpenRCT2StartupActionPath);
|
|
|
|
|
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) = SCREEN_FLAGS_PLAYING;
|
2015-08-16 18:29:47 +02:00
|
|
|
|
2015-08-18 09:30:55 +02:00
|
|
|
#ifndef DISABLE_NETWORK
|
2015-08-16 18:29:47 +02:00
|
|
|
if (gNetworkStart == NETWORK_MODE_SERVER) {
|
|
|
|
network_begin_server(gNetworkStartPort);
|
|
|
|
}
|
2015-08-18 09:30:55 +02:00
|
|
|
#endif // DISABLE_NETWORK
|
2015-06-03 18:11:19 +02:00
|
|
|
break;
|
|
|
|
case STARTUP_ACTION_EDIT:
|
|
|
|
if (strlen(gOpenRCT2StartupActionPath) == 0) {
|
|
|
|
editor_load();
|
|
|
|
} else {
|
|
|
|
editor_load_landscape(gOpenRCT2StartupActionPath);
|
|
|
|
}
|
|
|
|
break;
|
2015-02-12 12:30:57 +01:00
|
|
|
}
|
|
|
|
|
2015-08-18 09:30:55 +02:00
|
|
|
#ifndef DISABLE_NETWORK
|
2015-07-10 21:53:41 +02:00
|
|
|
if (gNetworkStart == NETWORK_MODE_CLIENT) {
|
2015-02-12 12:30:57 +01:00
|
|
|
network_begin_client(gNetworkStartHost, gNetworkStartPort);
|
|
|
|
}
|
2015-08-18 09:30:55 +02:00
|
|
|
#endif // DISABLE_NETWORK
|
2015-02-12 12:30:57 +01:00
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
openrct2_loop();
|
2014-10-09 01:30:22 +02:00
|
|
|
}
|
2015-05-29 00:04:02 +02:00
|
|
|
openrct2_dispose();
|
2014-10-09 01:30:22 +02:00
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
// HACK Some threads are still running which causes the game to not terminate. Investigation required!
|
|
|
|
exit(gExitCode);
|
|
|
|
}
|
2015-05-25 21:36:40 +02:00
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
void openrct2_dispose()
|
|
|
|
{
|
2015-02-12 12:30:57 +01:00
|
|
|
network_close();
|
2015-05-25 21:36:40 +02:00
|
|
|
http_dispose();
|
2015-06-08 18:16:18 +02:00
|
|
|
language_close_all();
|
2015-02-12 21:51:40 +01:00
|
|
|
platform_free();
|
2014-10-09 15:31:51 +02:00
|
|
|
}
|
|
|
|
|
2015-07-05 00:51:23 +02:00
|
|
|
/**
|
|
|
|
* Determines whether its worth tweening a sprite or not when frame smoothing is on.
|
|
|
|
*/
|
|
|
|
static bool sprite_should_tween(rct_sprite *sprite)
|
|
|
|
{
|
|
|
|
if (sprite->unknown.linked_list_type_offset == SPRITE_LINKEDLIST_OFFSET_VEHICLE)
|
|
|
|
return true;
|
|
|
|
if (sprite->unknown.linked_list_type_offset == SPRITE_LINKEDLIST_OFFSET_PEEP)
|
|
|
|
return true;
|
|
|
|
if (sprite->unknown.linked_list_type_offset == SPRITE_LINKEDLIST_OFFSET_UNKNOWN)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-09 15:31:51 +02:00
|
|
|
/**
|
|
|
|
* Run the main game loop until the finished flag is set at 40fps (25ms interval).
|
|
|
|
*/
|
|
|
|
static void openrct2_loop()
|
|
|
|
{
|
|
|
|
uint32 currentTick, ticksElapsed, lastTick = 0;
|
2015-07-06 23:21:25 +02:00
|
|
|
static uint32 uncapTick = 0;
|
2015-07-04 21:00:32 +02:00
|
|
|
static int fps = 0;
|
|
|
|
static uint32 secondTick = 0;
|
2014-10-09 15:31:51 +02:00
|
|
|
|
2015-05-29 00:04:02 +02:00
|
|
|
log_verbose("begin openrct2 loop");
|
|
|
|
|
2014-10-09 15:31:51 +02:00
|
|
|
_finished = 0;
|
|
|
|
do {
|
2015-07-05 13:12:34 +02:00
|
|
|
if (gConfigGeneral.uncap_fps && gGameSpeed <= 4) {
|
2015-07-04 21:00:32 +02:00
|
|
|
currentTick = SDL_GetTicks();
|
2015-07-06 23:21:25 +02:00
|
|
|
if (uncapTick == 0) {
|
2015-07-05 00:51:23 +02:00
|
|
|
// Reset sprite locations
|
2015-07-04 21:00:32 +02:00
|
|
|
uncapTick = SDL_GetTicks();
|
2015-07-06 23:21:25 +02:00
|
|
|
openrct2_reset_object_tween_locations();
|
2015-07-04 21:00:32 +02:00
|
|
|
}
|
2015-07-05 00:51:23 +02:00
|
|
|
|
2015-08-05 14:01:25 +02:00
|
|
|
// Limit number of updates per loop (any long pauses or debugging can make this update for a very long time)
|
|
|
|
if (currentTick - uncapTick > 25 * 60) {
|
|
|
|
uncapTick = currentTick - 25 - 1;
|
|
|
|
}
|
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
while (uncapTick <= currentTick && currentTick - uncapTick > 25) {
|
2015-07-05 00:51:23 +02:00
|
|
|
// Get the original position of each sprite
|
2015-07-04 21:00:32 +02:00
|
|
|
for (uint16 i = 0; i < MAX_SPRITES; i++) {
|
2015-07-06 23:21:25 +02:00
|
|
|
_spritelocations1[i].x = g_sprite_list[i].unknown.x;
|
|
|
|
_spritelocations1[i].y = g_sprite_list[i].unknown.y;
|
|
|
|
_spritelocations1[i].z = g_sprite_list[i].unknown.z;
|
2015-07-04 21:00:32 +02:00
|
|
|
}
|
2015-08-04 01:08:42 +02:00
|
|
|
|
2015-07-05 00:51:23 +02:00
|
|
|
// Update the game so the sprite positions update
|
2015-07-04 21:00:32 +02:00
|
|
|
rct2_update();
|
2015-07-05 00:51:23 +02:00
|
|
|
|
|
|
|
// Get the next position of each sprite
|
2015-07-04 21:00:32 +02:00
|
|
|
for (uint16 i = 0; i < MAX_SPRITES; i++) {
|
2015-07-06 23:21:25 +02:00
|
|
|
_spritelocations2[i].x = g_sprite_list[i].unknown.x;
|
|
|
|
_spritelocations2[i].y = g_sprite_list[i].unknown.y;
|
|
|
|
_spritelocations2[i].z = g_sprite_list[i].unknown.z;
|
2015-07-04 21:00:32 +02:00
|
|
|
}
|
2015-07-05 00:51:23 +02:00
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
uncapTick += 25;
|
|
|
|
}
|
2015-07-05 00:51:23 +02:00
|
|
|
|
|
|
|
// Tween the position of each sprite from the last position to the new position based on the time between the last
|
|
|
|
// tick and the next tick.
|
2015-07-04 21:00:32 +02:00
|
|
|
float nudge = 1 - ((float)(currentTick - uncapTick) / 25);
|
|
|
|
for (uint16 i = 0; i < MAX_SPRITES; i++) {
|
2015-07-05 00:51:23 +02:00
|
|
|
if (!sprite_should_tween(&g_sprite_list[i]))
|
2015-07-04 21:00:32 +02:00
|
|
|
continue;
|
2015-07-05 00:51:23 +02:00
|
|
|
|
|
|
|
sprite_move(
|
2015-07-06 23:21:25 +02:00
|
|
|
_spritelocations2[i].x + (sint16)((_spritelocations1[i].x - _spritelocations2[i].x) * nudge),
|
|
|
|
_spritelocations2[i].y + (sint16)((_spritelocations1[i].y - _spritelocations2[i].y) * nudge),
|
|
|
|
_spritelocations2[i].z + (sint16)((_spritelocations1[i].z - _spritelocations2[i].z) * nudge),
|
2015-07-05 00:51:23 +02:00
|
|
|
&g_sprite_list[i]
|
|
|
|
);
|
2015-08-22 12:56:32 +02:00
|
|
|
invalidate_sprite_2(&g_sprite_list[i]);
|
2015-07-04 21:00:32 +02:00
|
|
|
}
|
2015-07-05 00:51:23 +02:00
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
platform_process_messages();
|
|
|
|
rct2_draw();
|
|
|
|
platform_draw();
|
|
|
|
fps++;
|
|
|
|
if (SDL_GetTicks() - secondTick >= 1000) {
|
|
|
|
fps = 0;
|
|
|
|
secondTick = SDL_GetTicks();
|
|
|
|
}
|
2015-07-05 00:51:23 +02:00
|
|
|
|
|
|
|
// Restore the real positions of the sprites so they aren't left at the mid-tween positions
|
2015-07-04 21:00:32 +02:00
|
|
|
for (uint16 i = 0; i < MAX_SPRITES; i++) {
|
2015-07-05 00:51:23 +02:00
|
|
|
if (!sprite_should_tween(&g_sprite_list[i]))
|
2015-07-04 21:00:32 +02:00
|
|
|
continue;
|
2015-07-05 00:51:23 +02:00
|
|
|
|
2015-08-22 12:56:32 +02:00
|
|
|
invalidate_sprite_2(&g_sprite_list[i]);
|
2015-07-06 23:21:25 +02:00
|
|
|
sprite_move(_spritelocations2[i].x, _spritelocations2[i].y, _spritelocations2[i].z, &g_sprite_list[i]);
|
2015-07-04 21:00:32 +02:00
|
|
|
}
|
2015-07-30 00:30:05 +02:00
|
|
|
network_update();
|
2015-07-04 21:00:32 +02:00
|
|
|
} else {
|
2015-07-06 23:21:25 +02:00
|
|
|
uncapTick = 0;
|
2015-07-04 21:00:32 +02:00
|
|
|
currentTick = SDL_GetTicks();
|
|
|
|
ticksElapsed = currentTick - lastTick;
|
|
|
|
if (ticksElapsed < 25) {
|
|
|
|
if (ticksElapsed < 15)
|
|
|
|
SDL_Delay(15 - ticksElapsed);
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-09 15:31:51 +02:00
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
lastTick = currentTick;
|
2014-10-09 15:31:51 +02:00
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
platform_process_messages();
|
2015-07-05 00:51:23 +02:00
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
rct2_update();
|
2015-07-05 00:51:23 +02:00
|
|
|
|
2015-07-04 21:00:32 +02:00
|
|
|
rct2_draw();
|
|
|
|
platform_draw();
|
|
|
|
}
|
2014-10-09 15:31:51 +02:00
|
|
|
} while (!_finished);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes the OpenRCT2 game loop to finish.
|
|
|
|
*/
|
|
|
|
void openrct2_finish()
|
|
|
|
{
|
|
|
|
_finished = 1;
|
2015-07-06 23:21:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void openrct2_reset_object_tween_locations()
|
|
|
|
{
|
|
|
|
for (uint16 i = 0; i < MAX_SPRITES; i++) {
|
|
|
|
_spritelocations1[i].x = _spritelocations2[i].x = g_sprite_list[i].unknown.x;
|
|
|
|
_spritelocations1[i].y = _spritelocations2[i].y = g_sprite_list[i].unknown.y;
|
|
|
|
_spritelocations1[i].z = _spritelocations2[i].z = g_sprite_list[i].unknown.z;
|
|
|
|
}
|
2015-07-26 16:07:58 +02:00
|
|
|
}
|
2015-08-04 00:16:30 +02:00
|
|
|
|
|
|
|
#if _MSC_VER >= 1900
|
|
|
|
/**
|
|
|
|
* Temporary fix for libraries not compiled with VS2015
|
|
|
|
*/
|
|
|
|
FILE **__iob_func()
|
|
|
|
{
|
|
|
|
static FILE* streams[3];
|
|
|
|
streams[0] = stdin;
|
|
|
|
streams[1] = stdout;
|
|
|
|
streams[2] = stderr;
|
|
|
|
return streams;
|
|
|
|
}
|
|
|
|
#endif
|