Fix reached macOS UI primitives and audio fade behavior
This commit is contained in:
@@ -71,9 +71,13 @@ auto CScreen::RenderLine2d(float sx, float sy, float ex, float ey, float) -> voi
|
||||
UIRenderAdd({UIRenderCommand::Line, sx, sy, ex, ey, ms_diffuseColor});
|
||||
}
|
||||
|
||||
auto CScreen::RenderBox2d(float, float, float, float, float) -> void
|
||||
auto CScreen::RenderBox2d(float sx, float sy, float ex, float ey, float) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
// 40250's four line pairs, including its one-pixel extension of the bottom edge.
|
||||
UIRenderAdd({UIRenderCommand::Line, sx, sy, ex, sy, ms_diffuseColor});
|
||||
UIRenderAdd({UIRenderCommand::Line, sx, sy, sx, ey, ms_diffuseColor});
|
||||
UIRenderAdd({UIRenderCommand::Line, ex, sy, ex, ey, ms_diffuseColor});
|
||||
UIRenderAdd({UIRenderCommand::Line, sx, ey, ex + 1.0f, ey, ms_diffuseColor});
|
||||
}
|
||||
|
||||
auto CScreen::RenderBar2d(float sx, float sy, float ex, float ey, float) -> void
|
||||
@@ -81,9 +85,13 @@ auto CScreen::RenderBar2d(float sx, float sy, float ex, float ey, float) -> void
|
||||
UIRenderAdd({UIRenderCommand::Bar, sx, sy, ex, ey, ms_diffuseColor});
|
||||
}
|
||||
|
||||
auto CScreen::RenderGradationBar2d(float, float, float, float, DWORD, DWORD, float) -> void
|
||||
auto CScreen::RenderGradationBar2d(float sx, float sy, float ex, float ey, DWORD start, DWORD end, float) -> void
|
||||
{
|
||||
MT_PLATFORM_STUB();
|
||||
if (sx == ex || sy == ey)
|
||||
return;
|
||||
UIRenderCommand command{UIRenderCommand::GradientBar, sx, sy, ex, ey, start};
|
||||
command.end_argb = end;
|
||||
UIRenderAdd(std::move(command));
|
||||
}
|
||||
|
||||
auto CScreen::RenderCircle2d(float, float, float, float, int) -> void
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
// Commands emitted by the 40250 UI drawing calls, consumed by Godot's CanvasItem.
|
||||
// The port layer stays independent of godot-cpp.
|
||||
struct UIRenderCommand {
|
||||
enum Kind { Bar, Line, Text, Image } kind;
|
||||
enum Kind { Bar, Line, Text, Image, GradientBar } kind;
|
||||
float x1, y1, x2, y2;
|
||||
std::uint32_t argb;
|
||||
std::uint32_t end_argb = 0; // GradientBar only: colour on the bottom edge.
|
||||
float clip_x1 = 0, clip_y1 = 0, clip_x2 = 0, clip_y2 = 0;
|
||||
std::string text;
|
||||
// Image only: text is the texture's file, drawn as the quad (vertices 0..3 = TL, TR, BL, BR)
|
||||
|
||||
@@ -16,6 +16,9 @@ struct AudioCommand
|
||||
FadeOutAllMusic = 7,
|
||||
SetSoundVolume = 8,
|
||||
SetMusicVolume = 9,
|
||||
FadeInMusic = 10,
|
||||
FadeLimitOutMusic = 11,
|
||||
SetSoundVolume3D = 12,
|
||||
};
|
||||
|
||||
Type type = PlaySound2D;
|
||||
|
||||
@@ -171,14 +171,20 @@ void CSoundManager::SetMusicVolumeGrade(int iGrade)
|
||||
|
||||
void CSoundManager::SaveVolume()
|
||||
{
|
||||
m_fBackupMusicVolume = m_fMusicVolume;
|
||||
m_fBackupSoundVolume = m_fSoundVolume;
|
||||
if (m_isSoundDisable)
|
||||
return;
|
||||
const float musicVolume = m_fMusicVolume;
|
||||
const float soundVolume = m_fSoundVolume;
|
||||
SetMusicVolume(0.0f);
|
||||
SetSoundVolume(0.0f);
|
||||
m_fBackupMusicVolume = musicVolume;
|
||||
m_fBackupSoundVolume = soundVolume;
|
||||
m_isSoundDisable = TRUE;
|
||||
}
|
||||
|
||||
void CSoundManager::RestoreVolume()
|
||||
{
|
||||
m_isSoundDisable = FALSE;
|
||||
SetMusicVolume(m_fBackupMusicVolume);
|
||||
SetSoundVolume(m_fBackupSoundVolume);
|
||||
}
|
||||
@@ -251,8 +257,13 @@ void CSoundManager::PlayCharacterSound3D(float fx, float fy, float fz, const cha
|
||||
PlaySound3D(fx, fy, fz, c_szFileName, 1);
|
||||
}
|
||||
|
||||
void CSoundManager::SetSoundVolume3D(int, float)
|
||||
void CSoundManager::SetSoundVolume3D(int index, float volume)
|
||||
{
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::SetSoundVolume3D;
|
||||
cmd.id = index;
|
||||
cmd.volume = volume;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::StopAllSound3D()
|
||||
@@ -274,9 +285,16 @@ void CSoundManager::PlayMusic(const char * c_szFileName)
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::FadeInMusic(const char * c_szFileName, float)
|
||||
void CSoundManager::FadeInMusic(const char * c_szFileName, float speed)
|
||||
{
|
||||
PlayMusic(c_szFileName);
|
||||
if (!c_szFileName || !c_szFileName[0])
|
||||
return;
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::FadeInMusic;
|
||||
cmd.filename = c_szFileName;
|
||||
cmd.volume = m_fMusicVolume;
|
||||
cmd.speed = speed;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::FadeOutMusic(const char * c_szFileName, float fSpeed)
|
||||
@@ -288,9 +306,14 @@ void CSoundManager::FadeOutMusic(const char * c_szFileName, float fSpeed)
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::FadeLimitOutMusic(const char * c_szFileName, float, float fSpeed)
|
||||
void CSoundManager::FadeLimitOutMusic(const char * c_szFileName, float limit, float speed)
|
||||
{
|
||||
FadeOutMusic(c_szFileName, fSpeed);
|
||||
AudioCommand cmd;
|
||||
cmd.type = AudioCommand::FadeLimitOutMusic;
|
||||
cmd.filename = c_szFileName ? c_szFileName : "";
|
||||
cmd.volume = __ConvertRatioVolumeToApplyVolume(limit);
|
||||
cmd.speed = speed;
|
||||
PushAudioCommand(cmd);
|
||||
}
|
||||
|
||||
void CSoundManager::FadeOutAllMusic()
|
||||
|
||||
@@ -91,14 +91,17 @@ Array Metin2PythonHost::ui_render_commands() {
|
||||
Array out;
|
||||
for (const auto &command : UIRenderCommands()) {
|
||||
Dictionary item;
|
||||
item["kind"] = command.kind == UIRenderCommand::Bar ? "bar" :
|
||||
item["kind"] = command.kind == UIRenderCommand::GradientBar ? "gradient_bar" :
|
||||
(command.kind == UIRenderCommand::Bar ? "bar" :
|
||||
(command.kind == UIRenderCommand::Line ? "line" :
|
||||
(command.kind == UIRenderCommand::Image ? "image" : "text"));
|
||||
(command.kind == UIRenderCommand::Image ? "image" : "text")));
|
||||
item["x1"] = command.x1;
|
||||
item["y1"] = command.y1;
|
||||
item["x2"] = command.x2;
|
||||
item["y2"] = command.y2;
|
||||
item["argb"] = static_cast<int64_t>(command.argb);
|
||||
if (command.kind == UIRenderCommand::GradientBar)
|
||||
item["end_argb"] = static_cast<int64_t>(command.end_argb);
|
||||
item["clip_x1"] = command.clip_x1;
|
||||
item["clip_y1"] = command.clip_y1;
|
||||
item["clip_x2"] = command.clip_x2;
|
||||
@@ -259,6 +262,9 @@ Array Metin2PythonHost::audio_commands() {
|
||||
case AudioCommand::FadeOutAllMusic: item["type"] = "fade_out_all_music"; break;
|
||||
case AudioCommand::SetSoundVolume: item["type"] = "set_sound_volume"; break;
|
||||
case AudioCommand::SetMusicVolume: item["type"] = "set_music_volume"; break;
|
||||
case AudioCommand::FadeInMusic: item["type"] = "fade_in_music"; break;
|
||||
case AudioCommand::FadeLimitOutMusic: item["type"] = "fade_limit_out_music"; break;
|
||||
case AudioCommand::SetSoundVolume3D: item["type"] = "set_sound_volume_3d"; break;
|
||||
default: continue;
|
||||
}
|
||||
item["filename"] = String::utf8(cmd.filename.c_str());
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "../src/platform/ScriptLib/PythonHost.h"
|
||||
#include "../src/platform/UserInterface/UserInterface.h"
|
||||
#include "../src/platform/EterLib/UIRenderCommands.h"
|
||||
#include "EterLib/GrpScreen.h"
|
||||
#include <dinput.h> // DIK_ESCAPE
|
||||
|
||||
#include <cmath>
|
||||
@@ -108,9 +109,31 @@ static void frames(int count)
|
||||
PythonBoot::UIUpdate();
|
||||
}
|
||||
|
||||
static void drawing_primitives()
|
||||
{
|
||||
UIRenderSetSize(800, 600);
|
||||
UIRenderBeginFrame();
|
||||
CScreen screen;
|
||||
screen.SetDiffuseColor(0xFF123456u);
|
||||
screen.RenderBox2d(10, 20, 30, 40);
|
||||
screen.RenderGradationBar2d(50, 60, 70, 80, 0xFF102030u, 0xFF405060u);
|
||||
const auto& commands = UIRenderCommands();
|
||||
CHECK(commands.size() == 5);
|
||||
if (commands.size() == 5)
|
||||
{
|
||||
CHECK(commands[0].kind == UIRenderCommand::Line && near(commands[0].x1, 10) && near(commands[0].y2, 20));
|
||||
CHECK(commands[3].kind == UIRenderCommand::Line && near(commands[3].x2, 31));
|
||||
CHECK(commands[4].kind == UIRenderCommand::GradientBar && commands[4].argb == 0xFF102030u &&
|
||||
commands[4].end_argb == 0xFF405060u);
|
||||
}
|
||||
UIRenderSetSize(0, 0);
|
||||
UIRenderBeginFrame();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
drawing_primitives();
|
||||
const char* strict = std::getenv("MT_ASSETS_STRICT");
|
||||
const bool is_strict = strict && std::string(strict) == "1";
|
||||
const std::string client = argc > 1 ? argv[1] : "";
|
||||
|
||||
@@ -1161,6 +1161,15 @@ int main(int argc, char** argv)
|
||||
CHECK(py("snd.SetSoundVolume(3)"));
|
||||
CHECK(py("snd.SetSoundVolumef(0.6)"));
|
||||
CHECK(CSoundManager::Instance().GetSoundVolume() > 0.0f);
|
||||
const float savedMusic = CSoundManager::Instance().GetMusicVolume();
|
||||
const float savedSound = CSoundManager::Instance().GetSoundVolume();
|
||||
CSoundManager::Instance().SaveVolume();
|
||||
CSoundManager::Instance().SaveVolume();
|
||||
CHECK(CSoundManager::Instance().GetMusicVolume() == 0.0f);
|
||||
CHECK(CSoundManager::Instance().GetSoundVolume() == 0.0f);
|
||||
CSoundManager::Instance().RestoreVolume();
|
||||
CHECK(std::abs(CSoundManager::Instance().GetMusicVolume() - savedMusic) < 0.001f);
|
||||
CHECK(std::abs(CSoundManager::Instance().GetSoundVolume() - savedSound) < 0.001f);
|
||||
|
||||
// Scales
|
||||
CHECK(py("snd.SetSoundScale(250.0)"));
|
||||
|
||||
Reference in New Issue
Block a user