mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
add string format and SDL get audio devices
This commit is contained in:
43
src/audio.c
43
src/audio.c
@@ -18,10 +18,53 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
|
||||
#include <SDL.h>
|
||||
#include "audio.h"
|
||||
#include "addresses.h"
|
||||
#include "rct2.h"
|
||||
|
||||
int gAudioDeviceCount;
|
||||
audio_device *gAudioDevices = NULL;
|
||||
|
||||
void audio_init(int i)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
RCT2_ERROR("SDL_Init %s", SDL_GetError());
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void audio_quit()
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates audio devices.
|
||||
*/
|
||||
void audio_get_devices()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (gAudioDevices != NULL)
|
||||
free(gAudioDevices);
|
||||
|
||||
gAudioDeviceCount = SDL_GetNumAudioDevices(SDL_FALSE);
|
||||
if (gAudioDeviceCount > 0) {
|
||||
gAudioDeviceCount++;
|
||||
gAudioDevices = malloc(gAudioDeviceCount * sizeof(audio_device));
|
||||
|
||||
strcpy(gAudioDevices[0].name, "Default sound device");
|
||||
for (i = 1; i < gAudioDeviceCount; i++) {
|
||||
const char *utf8_name = SDL_GetAudioDeviceName(i - 1, SDL_FALSE);
|
||||
if (utf8_name == NULL)
|
||||
utf8_name = "(UNKNOWN)";
|
||||
|
||||
strcpy(gAudioDevices[i].name, utf8_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_dsound_devices()
|
||||
{
|
||||
RCT2_CALLPROC(0x0040502E);
|
||||
|
||||
12
src/audio.h
12
src/audio.h
@@ -21,6 +21,18 @@
|
||||
#ifndef _AUDIO_H_
|
||||
#define _AUDIO_H_
|
||||
|
||||
typedef struct {
|
||||
char name[256];
|
||||
} audio_device;
|
||||
|
||||
extern int gAudioDeviceCount;
|
||||
extern audio_device *gAudioDevices;
|
||||
|
||||
void audio_init();
|
||||
void audio_quit();
|
||||
void audio_get_devices();
|
||||
|
||||
|
||||
#include <dsound.h>
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,7 @@ enum {
|
||||
extern const sint16 days_in_month[MONTH_COUNT];
|
||||
|
||||
int date_get_month(int months);
|
||||
int date_get_year(int months);
|
||||
int date_get_total_months(int month, int year);
|
||||
void date_reset();
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <shlobj.h>
|
||||
#include <SDL.h>
|
||||
#include "addresses.h"
|
||||
#include "audio.h"
|
||||
#include "climate.h"
|
||||
#include "config.h"
|
||||
#include "date.h"
|
||||
@@ -76,6 +77,9 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta
|
||||
RCT2_GLOBAL(0x01423A08, HINSTANCE) = hInstance;
|
||||
RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, LPSTR) = lpCmdLine;
|
||||
get_system_info();
|
||||
|
||||
audio_init();
|
||||
audio_get_devices();
|
||||
RCT2_CALLPROC(0x0040502E); // get_dsound_devices()
|
||||
|
||||
config_init();
|
||||
|
||||
1369
src/string_ids.c
1369
src/string_ids.c
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,7 @@ void generate_string_file();
|
||||
void reset_saved_strings();
|
||||
|
||||
enum {
|
||||
// Font format codes
|
||||
FORMAT_TINYFONT = 7,
|
||||
FORMAT_BIGFONT,
|
||||
FORMAT_MEDIUMFONT,
|
||||
@@ -35,19 +36,31 @@ enum {
|
||||
|
||||
FORMAT_OUTLINE,
|
||||
|
||||
// Non ascii-characters
|
||||
FORMAT_ENDQUOTES = 34,
|
||||
|
||||
// Argument format codes
|
||||
FORMAT_COMMA32 = 123,
|
||||
FORMAT_COMMA2DP32 = 125,
|
||||
FORMAT_INT32,
|
||||
FORMAT_COMMA2DP32,
|
||||
FORMAT_COMMA16,
|
||||
FORMAT_CURRENCY2DP = 128,
|
||||
FORMAT_UINT16,
|
||||
FORMAT_CURRENCY2DP,
|
||||
FORMAT_CURRENCY,
|
||||
FORMAT_STRINGID,
|
||||
FORMAT_STRINGID2,
|
||||
FORMAT_STRING,
|
||||
FORMAT_MONTHYEAR = 133,
|
||||
FORMAT_VELOCITY = 135,
|
||||
FORMAT_LENGTH = 140,
|
||||
FORMAT_SPRITE = 141,
|
||||
FORMAT_MONTHYEAR,
|
||||
FORMAT_MONTH,
|
||||
FORMAT_VELOCITY,
|
||||
FORMAT_POP16,
|
||||
FORMAT_PUSH16,
|
||||
FORMAT_DURATION,
|
||||
FORMAT_REALTIME,
|
||||
FORMAT_LENGTH,
|
||||
FORMAT_SPRITE,
|
||||
|
||||
// Colour format codes
|
||||
FORMAT_BLACK = 142,
|
||||
FORMAT_GREY,
|
||||
FORMAT_WHITE,
|
||||
@@ -63,6 +76,7 @@ enum {
|
||||
FORMAT_PEARLAQUA,
|
||||
FORMAT_PALESILVER,
|
||||
|
||||
// Extra non-ascii characters
|
||||
FORMAT_AMINUSCULE = 159,
|
||||
FORMAT_UP,
|
||||
FORMAT_POUND = 163,
|
||||
|
||||
16
src/util.c
16
src/util.c
@@ -23,6 +23,20 @@
|
||||
int squaredmetres_to_squaredfeet(int squaredMetres)
|
||||
{
|
||||
// 1 metre squared = 10.7639104 feet squared
|
||||
// how it is done in RCT2
|
||||
// RCT2 approximates as 11
|
||||
return squaredMetres * 11;
|
||||
}
|
||||
|
||||
int metres_to_feet(int metres)
|
||||
{
|
||||
// 1 metre = 3.2808399 feet
|
||||
// RCT2 approximates as 3.28125
|
||||
return (metres * 840) / 256;
|
||||
}
|
||||
|
||||
int mph_to_kmph(int mph)
|
||||
{
|
||||
// 1 mph = 1.60934 kmph
|
||||
// RCT2 approximates as 1.609375
|
||||
return (mph * 1648) / 1024;
|
||||
}
|
||||
@@ -22,5 +22,7 @@
|
||||
#define _UTIL_H_
|
||||
|
||||
int squaredmetres_to_squaredfeet(int squaredMetres);
|
||||
int metres_to_feet(int metres);
|
||||
int mph_to_kmph(int mph);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -283,7 +283,6 @@ static void window_options_mouseup()
|
||||
static void window_options_mousedown()
|
||||
{
|
||||
int num_items, i;
|
||||
sint64 device;
|
||||
short widgetIndex;
|
||||
rct_window *w;
|
||||
rct_widget *widget;
|
||||
@@ -305,22 +304,14 @@ static void window_options_mousedown()
|
||||
|
||||
switch (widgetIndex) {
|
||||
case WIDX_SOUND_DROPDOWN:
|
||||
num_items = RCT2_GLOBAL(RCT2_ADDRESS_NUM_DSOUND_DEVICES, uint32);
|
||||
if (num_items == 0)
|
||||
break;
|
||||
|
||||
window_options_draw_dropdown_box(w, widget, num_items);
|
||||
window_options_draw_dropdown_box(w, widget, gAudioDeviceCount);
|
||||
|
||||
// populate the list with the sound devices
|
||||
device = RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, sint32) + 0x10;
|
||||
|
||||
for (i = 0; i < num_items; i++) {
|
||||
for (i = 0; i < gAudioDeviceCount; i++) {
|
||||
gDropdownItemsFormat[i] = 1142;
|
||||
gDropdownItemsArgs[i] = 1170 | (device << 16);
|
||||
device += 0x210;
|
||||
gDropdownItemsArgs[i] = 1170 | ((uint64)gAudioDevices[i].name << 16);
|
||||
}
|
||||
gDropdownItemsChecked |= (1 << RCT2_GLOBAL(0x9AF280, uint32));
|
||||
|
||||
break;
|
||||
case WIDX_HEIGHT_LABELS_DROPDOWN:
|
||||
window_options_draw_dropdown_box(w, widget, 2);
|
||||
@@ -380,7 +371,7 @@ static void window_options_mousedown()
|
||||
|
||||
break;
|
||||
case WIDX_RESOLUTION_DROPDOWN:
|
||||
RCT2_CALLPROC_EBPSAFE(0x006BB2AF);
|
||||
// RCT2_CALLPROC_EBPSAFE(0x006BB2AF);
|
||||
break;
|
||||
case WIDX_TEMPERATURE_DROPDOWN:
|
||||
window_options_draw_dropdown_box(w, widget, 2);
|
||||
@@ -522,25 +513,19 @@ static void window_options_update(rct_window *w)
|
||||
__asm__ ( "mov %[w], esi " : [w] "+m" (w) );
|
||||
#endif
|
||||
|
||||
|
||||
sint32 format_args = RCT2_GLOBAL(0x009AF280, sint32);
|
||||
sint32 currentSoundDevice = RCT2_GLOBAL(0x009AF280, sint32);
|
||||
|
||||
// sound devices
|
||||
if (format_args == -1 || RCT2_GLOBAL(RCT2_ADDRESS_NUM_DSOUND_DEVICES, sint32) == 0) {
|
||||
if (currentSoundDevice == -1 || gAudioDeviceCount == 0) {
|
||||
RCT2_GLOBAL(0x013CE952, uint16) = STR_SOUND_NONE;
|
||||
} else {
|
||||
format_args = RCT2_GLOBAL(RCT2_ADDRESS_DSOUND_DEVICES, uint32) + format_args * 0x210 + 16;
|
||||
RCT2_GLOBAL(0x013CE952, uint16) = 1170;
|
||||
RCT2_GLOBAL(0x013CE952 + 2, uint32) = format_args;
|
||||
RCT2_GLOBAL(0x013CE952 + 2, uint32) = (uint32)gAudioDevices[currentSoundDevice].name;
|
||||
}
|
||||
|
||||
// height: units/real values
|
||||
if ((RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS))
|
||||
format_args = STR_UNITS;
|
||||
else
|
||||
format_args = STR_REAL_VALUES;
|
||||
|
||||
RCT2_GLOBAL(0x013CE952 + 6, uint16) = (uint16)format_args;
|
||||
RCT2_GLOBAL(0x013CE952 + 6, uint16) = ((RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_SHOW_HEIGHT_AS_UNITS)) ?
|
||||
STR_UNITS : STR_REAL_VALUES;
|
||||
|
||||
// music: on/off
|
||||
RCT2_GLOBAL(0x013CE952 + 8, uint16) = STR_OFF +
|
||||
|
||||
Reference in New Issue
Block a user