Skip to content
Draft
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
26 changes: 26 additions & 0 deletions .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: macOS-CI
on: [push, pull_request]

env:
QT_VERSION: "5.12.9"
MACOSX_DEPLOYMENT_TARGET: "10.12"

jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: Install Qt5
uses: jurplel/install-qt-action@v2
with:
arch: clang_64
version: ${{ env.QT_VERSION }}
- name: Build tworld2
run: |
cd $GITHUB_WORKSPACE
mkdir build-qt && cd build-qt
cmake -DCMAKE_BUILD_TYPE=Release -DOSHW=qt \
-DCMAKE_PREFIX_PATH="$RUNNER_WORKSPACE/Qt/$QT_VERSION/clang_64" \
-DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/dist-qt" ..
make -j2
make install
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install qtbase5-dev libsdl1.2-dev
sudo apt install qtbase5-dev qtmultimedia5-dev libsdl1.2-dev
- name: Build tworld (SDL)
run: |
mkdir build-sdl && cd build-sdl
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/win-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Win32-CI
on: [push, pull_request]

env:
QT_VERSION: "5.15.0"

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Install Qt5
uses: jurplel/install-qt-action@v2
with:
arch: win64_mingw81
version: ${{ env.QT_VERSION }}
- name: Build tworld2
run: |
mkdir build
cd build
cmake -G "MinGW Makefiles" -DOSHW=qt `
"-DCMAKE_PREFIX_PATH=${Env:RUNNER_WORKSPACE}/Qt/${Env:QT_VERSION}/mingw81_64" `
"-DCMAKE_INSTALL_PREFIX=${Env:$GITHUB_WORKSPACE}/dist-qt" `
"-DCMAKE_BUILD_TYPE=Debug" ..
cmake --build .
cmake --build . --target install
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ else()
message(FATAL_ERROR "${OSHW} is not a valid OSHW setting")
endif()

# We still require SDL even for the Qt build...
find_package(SDL REQUIRED)
if(OSHW STREQUAL "qt")
if(OSHW STREQUAL "sdl")
find_package(SDL REQUIRED)
elseif(OSHW STREQUAL "qt")
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTORCC TRUE)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Xml)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Multimedia Xml)
add_definitions(-DTWPLUSPLUS)
endif()

Expand Down
5 changes: 1 addition & 4 deletions oshw-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ target_sources(oshw-qt PRIVATE
../generic/_in.cpp
../generic/tile.c
../generic/timer.c
../oshw-sdl/sdlsfx.h
../oshw-sdl/sdlsfx.c
oshwbind.h
oshwbind.cpp
CCMetaData.h
Expand All @@ -25,13 +23,12 @@ target_include_directories(oshw-qt PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/generic
${SDL_INCLUDE_DIR}
)

target_link_libraries(oshw-qt PUBLIC
${SDL_LIBRARY}
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Multimedia
Qt5::Xml
)
3 changes: 1 addition & 2 deletions oshw-qt/TWApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ bool TileWorldApp::Initialize(bool bSilence, int nSoundBufSize,
if ( ! (
_generictimerinitialize(bShowHistogram) &&
_generictileinitialize() &&
_genericinputinitialize() &&
_sdlsfxinitialize(bSilence, nSoundBufSize)
_genericinputinitialize()
) )
return false;

Expand Down
183 changes: 182 additions & 1 deletion oshw-qt/TWMainWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,22 @@ extern int pedanticmode;
#include <QString>
#include <QTextStream>

#include <QThread>
#include <QSoundEffect>
#include <QAudioOutput>

#include <vector>

#include <string.h>
#include <ctype.h>

/* Some generic default settings for the audio output.
*/
#define DEFAULT_SND_FREQ 22050
#define DEFAULT_SND_CHAN 1
#define DEFAULT_SND_SIZE 16
#define DEFAULT_SND_TYPE QAudioFormat::SignedInt

class TWStyledItemDelegate : public QStyledItemDelegate
{
public:
Expand Down Expand Up @@ -204,6 +215,8 @@ TileWorldMainWnd::TileWorldMainWnd(QWidget* pParent, Qt::WindowFlags flags)
m_bWindowClosed(false),
m_pSurface(),
m_pInvSurface(),
m_bEnableAudio(false),
m_fVolume(1.0),
m_nKeyState(),
m_shortMessages(),
m_bKbdRepeatEnabled(true),
Expand Down Expand Up @@ -242,7 +255,15 @@ TileWorldMainWnd::TileWorldMainWnd(QWidget* pParent, Qt::WindowFlags flags)
m_pTblList->setItemDelegate(new TWStyledItemDelegate(m_pTblList));

m_pTextBrowser->setSearchPaths(QStringList{ QString::fromLocal8Bit(seriesdatdir) });


m_sounds.resize(SND_COUNT);
/*QAudioFormat audioFormat;
audioFormat.setSampleRate(DEFAULT_SND_FREQ);
audioFormat.setChannelCount(DEFAULT_SND_CHAN);
audioFormat.setSampleSize(DEFAULT_SND_SIZE);
audioFormat.setSampleType(DEFAULT_SND_TYPE);
m_pAudioOut = new QAudioOutput(audioFormat, this);*/

g_pApp->installEventFilter(this);

connect(m_pTblList, &QTableView::activated, this, &TileWorldMainWnd::OnListItemActivated);
Expand Down Expand Up @@ -1360,6 +1381,166 @@ void TileWorldMainWnd::SetSubtitle(const char* szSubtitle)
}


/* Activate or deactivate the sound system. Qt manages this for us, so
* we need only track whether it's enabled by the game engine.
*/
int setaudiosystem(int active)
{
g_pMainWnd->EnableAudio(!!active);
return TRUE;
}

void TileWorldMainWnd::EnableAudio(bool bEnabled)
{
m_bEnableAudio = bEnabled;
}

/* Load a single wave file into memory. The wave data is converted to
* the format expected by the sound device.
*/
int loadsfxfromfile(int index, char const *filename)
{
return g_pMainWnd->LoadSoundEffect(index, filename);
}

bool TileWorldMainWnd::LoadSoundEffect(int index, const char* szFilename)
{
if (index < 0 || index >= m_sounds.size())
return false;

freesfx(index);
if (szFilename)
{
QSoundEffect* pSoundEffect = new QSoundEffect(this);
pSoundEffect->setSource(QUrl::fromLocalFile(QString::fromLocal8Bit(szFilename)));
pSoundEffect->setVolume(m_fVolume);
m_sounds[index] = pSoundEffect;
}

return true;
}

/* Release all memory for the given sound effect.
*/
void freesfx(int index)
{
g_pMainWnd->FreeSoundEffect(index);
}

void TileWorldMainWnd::FreeSoundEffect(int index)
{
if (index < 0 || index >= m_sounds.size())
return;

if (m_sounds[index])
{
// Defer deletion in case the effect is still playing.
m_sounds[index]->deleteLater();
m_sounds[index] = nullptr;
}
}

/* Set the current volume level to v. If display is true, the
* new volume level is displayed to the user.
*/
int setvolume(int v, int display)
{
if (v < 0)
v = 0;
else if (v > 10)
v = 10;
setintsetting("volume", v);

// Qt uses a floating-point volume in [0.0, 1.0]
g_pMainWnd->SetAudioVolume(qreal(v) / 10.0);

if (display) {
char buf[16];
snprintf(buf, sizeof(buf), "Volume: %d", v);
setdisplaymsg(buf, 1000, 1000);
}
return TRUE;
}

void TileWorldMainWnd::SetAudioVolume(qreal fVolume)
{
m_fVolume = fVolume;
for (QSoundEffect* pSoundEffect : m_sounds)
{
if (pSoundEffect)
pSoundEffect->setVolume(fVolume);
}
}

/* Change the current volume level by delta. If display is true, the
* new volume level is displayed to the user.
*/
int changevolume(int delta, int display)
{
int volume = int(g_pMainWnd->GetAudioVolume() * 10.0);
return setvolume(volume + delta, display);
}

/* If action is negative, stop playing all sounds immediately.
* Otherwise, just temporarily pause or unpause sound-playing.
*/
void setsoundeffects(int action)
{
if (action < 0)
{
for (int i = 0; i < SND_COUNT; ++i)
g_pMainWnd->StopSoundEffect(i);
}
else
{
// TODO
}
}

/* Select the sounds effects to be played. sfx is a bitmask of sound
* effect indexes. Any continuous sounds that are not included in sfx
* are stopped. One-shot sounds that are included in sfx are
* restarted.
*/
void playsoundeffects(unsigned long sfx)
{
int i;
unsigned long flag;
for (i = 0, flag = 1u; i < SND_COUNT; ++i, flag <<= 1)
{
if (sfx & flag)
g_pMainWnd->PlaySoundEffect(i);
else if (i >= SND_ONESHOT_COUNT)
g_pMainWnd->StopSoundEffect(i);
}
}

void TileWorldMainWnd::PlaySoundEffect(int index)
{
if (index < 0 || index >= m_sounds.size())
return;

QSoundEffect* pSoundEffect = m_sounds[index];
if (pSoundEffect)
{
if (index >= SND_ONESHOT_COUNT)
pSoundEffect->setLoopCount(QSoundEffect::Infinite);
if (index < SND_ONESHOT_COUNT || !pSoundEffect->isPlaying())
pSoundEffect->play();
}
}

void TileWorldMainWnd::StopSoundEffect(int index)
{
if (index < 0 || index >= m_sounds.size())
return;

QSoundEffect* pSoundEffect = m_sounds[index];
if (pSoundEffect && pSoundEffect->isPlaying())
pSoundEffect->setLoopCount(0);
}


/* Display a message to the user. cfile and lineno can be NULL and 0
* respectively; otherwise, they identify the source code location
* where this function was called from. prefix is an optional string
Expand Down
19 changes: 17 additions & 2 deletions oshw-qt/TWMainWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <QLocale>

class QSortFilterProxyModel;
class QAudioOutput;
class QSoundEffect;

class TileWorldMainWnd : public QMainWindow, protected Ui::TWMainWnd
{
Expand Down Expand Up @@ -58,7 +60,15 @@ class TileWorldMainWnd : public QMainWindow, protected Ui::TWMainWnd
InputPromptType eInputType, int (*pfnInputCallback)());
int GetSelectedRuleset();
void SetSubtitle(const char* szSubtitle);


void EnableAudio(bool bEnabled);
bool LoadSoundEffect(int index, const char* szFilename);
void FreeSoundEffect(int index);
void PlaySoundEffect(int index);
void StopSoundEffect(int index);
void SetAudioVolume(qreal fVolume);
qreal GetAudioVolume() const { return m_fVolume; }

void ReadExtensions(gameseries* pSeries);
void Narrate(CCX::Text CCX::Level::*pmTxt, bool bForce = false);

Expand Down Expand Up @@ -99,7 +109,12 @@ private slots:
Qt_Surface* m_pSurface;
Qt_Surface* m_pInvSurface;
TW_Rect m_disploc;


//QAudioOutput* m_pAudioOut;
bool m_bEnableAudio;
qreal m_fVolume;
QVector<QSoundEffect*> m_sounds;

uint8_t m_nKeyState[TWK_LAST];

struct MessageData{ QString sMsg; uint32_t nMsgUntil, nMsgBoldUntil; };
Expand Down