Merge branch 'master' into jgrpp

# Conflicts:
#	os/macosx/notarize.sh
#	src/3rdparty/CMakeLists.txt
#	src/3rdparty/squirrel/squirrel/sqcompiler.cpp
#	src/3rdparty/squirrel/squirrel/sqdebug.cpp
#	src/3rdparty/squirrel/squirrel/sqvm.cpp
#	src/console_cmds.cpp
#	src/core/span_type.hpp
#	src/crashlog.cpp
#	src/currency.h
#	src/date_gui.cpp
#	src/driver.cpp
#	src/fios.cpp
#	src/genworld_gui.cpp
#	src/hotkeys.cpp
#	src/misc_gui.cpp
#	src/music/os2_m.cpp
#	src/network/core/os_abstraction.h
#	src/network/network_server.cpp
#	src/newgrf.cpp
#	src/newgrf_config.h
#	src/newgrf_text.cpp
#	src/openttd.cpp
#	src/os/macosx/font_osx.cpp
#	src/os/macosx/misc_osx.cpp
#	src/os/os2/CMakeLists.txt
#	src/os/os2/os2.cpp
#	src/os/unix/CMakeLists.txt
#	src/os/windows/font_win32.cpp
#	src/os/windows/win32_main.cpp
#	src/saveload/saveload.cpp
#	src/script/api/script_text.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/stdafx.h
#	src/strings.cpp
#	src/timetable_gui.cpp
#	src/town_gui.cpp
#	src/train_cmd.cpp
#	src/video/dedicated_v.cpp
#	src/video/video_driver.cpp
#	src/video/win32_v.cpp
#	src/viewport.cpp
#	src/waypoint_gui.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2023-09-12 20:06:47 +01:00
242 changed files with 4733 additions and 6402 deletions

View File

@@ -36,12 +36,6 @@ if(NOT OPTION_DEDICATED)
bemidi.h
CONDITION HAIKU
)
add_files(
os2_m.cpp
os2_m.h
CONDITION OPTION_OS2
)
endif()
add_files(

View File

@@ -60,8 +60,7 @@ const byte *MidiGetStandardSysexMessage(MidiSysexMessage msg, size_t &length)
* RAII-compliant to make teardown in error situations easier.
*/
class ByteBuffer {
byte *buf;
size_t buflen;
std::vector<byte> buf;
size_t pos;
public:
/**
@@ -73,31 +72,22 @@ public:
*/
ByteBuffer(FILE *file, size_t len)
{
this->buf = MallocT<byte>(len);
if (fread(this->buf, 1, len, file) == len) {
this->buflen = len;
this->buf.resize(len);
if (fread(this->buf.data(), 1, len, file) == len) {
this->pos = 0;
} else {
/* invalid state */
this->buflen = 0;
this->buf.clear();
}
}
/**
* Destructor, frees the buffer.
*/
~ByteBuffer()
{
free(this->buf);
}
/**
* Return whether the buffer was constructed successfully.
* @return true is the buffer contains data
*/
bool IsValid() const
{
return this->buflen > 0;
return this->buf.size() > 0;
}
/**
@@ -106,7 +96,7 @@ public:
*/
bool IsEnd() const
{
return this->pos >= this->buflen;
return this->pos >= this->buf.size();
}
/**
@@ -149,8 +139,8 @@ public:
bool ReadBuffer(byte *dest, size_t length)
{
if (this->IsEnd()) return false;
if (this->buflen - this->pos < length) return false;
memcpy(dest, this->buf + this->pos, length);
if (this->buf.size() - this->pos < length) return false;
std::copy(std::begin(this->buf) + this->pos, std::begin(this->buf) + this->pos + length, dest);
this->pos += length;
return true;
}
@@ -164,8 +154,8 @@ public:
bool ReadDataBlock(MidiFile::DataBlock *dest, size_t length)
{
if (this->IsEnd()) return false;
if (this->buflen - this->pos < length) return false;
dest->data.insert(dest->data.end(), this->buf + this->pos, this->buf + this->pos + length);
if (this->buf.size() - this->pos < length) return false;
dest->data.insert(dest->data.end(), std::begin(this->buf) + this->pos, std::begin(this->buf) + this->pos + length);
this->pos += length;
return true;
}
@@ -178,7 +168,7 @@ public:
bool Skip(size_t count)
{
if (this->IsEnd()) return false;
if (this->buflen - this->pos < count) return false;
if (this->buf.size() - this->pos < count) return false;
this->pos += count;
return true;
}

View File

@@ -1,91 +0,0 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file os2_m.cpp Music playback on OS/2. */
#include "../stdafx.h"
#include "../openttd.h"
#include "os2_m.h"
#include "midifile.hpp"
#include "../base_media_base.h"
#define INCL_DOS
#define INCL_OS2MM
#define INCL_WIN
#include <stdarg.h>
#include <os2.h>
#include <os2me.h>
#include "../safeguards.h"
/**********************
* OS/2 MIDI PLAYER
**********************/
/* Interesting how similar the MCI API in OS/2 is to the Win32 MCI API,
* eh? Anyone would think they both came from the same place originally! ;)
*/
/**
* Send a midi command.
* @param cmd The command to send.
* @return The result of sending it.
*/
static long CDECL MidiSendCommand(const char *cmd, ...)
{
va_list va;
char buf[512];
va_start(va, cmd);
vseprintf(buf, lastof(buf), cmd, va);
va_end(va);
return mciSendString(buf, nullptr, 0, nullptr, 0);
}
/** OS/2's music player's factory. */
static FMusicDriver_OS2 iFMusicDriver_OS2;
void MusicDriver_OS2::PlaySong(const MusicSongInfo &song)
{
std::string filename = MidiFile::GetSMFFile(song);
MidiSendCommand("close all");
if (filename.empty()) return;
if (MidiSendCommand("open %s type sequencer alias song", filename.c_str()) != 0) {
return;
}
MidiSendCommand("play song from 0");
}
void MusicDriver_OS2::StopSong()
{
MidiSendCommand("close all");
}
void MusicDriver_OS2::SetVolume(byte vol)
{
MidiSendCommand("set song audio volume %d", ((vol/127)*100));
}
bool MusicDriver_OS2::IsSongPlaying()
{
char buf[16];
mciSendString("status song mode", buf, sizeof(buf), nullptr, 0);
return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
}
const char *MusicDriver_OS2::Start(const StringList &parm)
{
return 0;
}
void MusicDriver_OS2::Stop()
{
MidiSendCommand("close all");
}

View File

@@ -1,39 +0,0 @@
/*
* This file is part of OpenTTD.
* OpenTTD 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, version 2.
* OpenTTD 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. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file os2_m.h Base for OS2 music playback. */
#ifndef MUSIC_OS2_H
#define MUSIC_OS2_H
#include "music_driver.hpp"
/** OS/2's music player. */
class MusicDriver_OS2 : public MusicDriver {
public:
const char *Start(const StringList &param) override;
void Stop() override;
void PlaySong(const MusicSongInfo &song) override;
void StopSong() override;
bool IsSongPlaying() override;
void SetVolume(byte vol) override;
const char *GetName() const override { return "os2"; }
};
/** Factory for OS/2's music player. */
class FMusicDriver_OS2 : public DriverFactoryBase {
public:
FMusicDriver_OS2() : DriverFactoryBase(Driver::DT_MUSIC, 10, "os2", "OS/2 Music Driver") {}
Driver *CreateInstance() const override { return new MusicDriver_OS2(); }
};
#endif /* MUSIC_OS2_H */