Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'yvt-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nonperforming committed Nov 15, 2022
2 parents a675484 + 9ef193e commit ed17aea
Show file tree
Hide file tree
Showing 24 changed files with 360 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ lastgoodbuild/
# Bog standard build directory
build/

# Nix
/outputs
/result

# fltk / fluid output leftovers
Sources/Gui/DetailConfigWindow.txt
Sources/Gui/MainWindow.txt
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ else()
if(NOT OpusFile_FOUND)
message(FATAL_ERROR "libopus/libopusfile not found, please install it (and make sure it's in your path)")
endif()
include(cmake/FindXext.cmake)
if(NOT XEXT_FOUND)
message(FATAL_ERROR "libXext, please install it (and make sure it's in your path)")
endif()
endif()


Expand Down Expand Up @@ -247,6 +251,8 @@ else()
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${FREETYPE_INCLUDE_DIRS})
include_directories(${OpusFile_INCLUDE_DIR})
include_directories(${Opus_INCLUDE_DIR})
include_directories(${Ogg_INCLUDE_DIR})
endif()

add_subdirectory(Resources)
Expand Down
83 changes: 79 additions & 4 deletions Resources/Scripts/Gui/StartupScreen/ConfigViewTabs.as
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ namespace spades {
_Tr("StartupScreen",
"Uses a number representation which allows wider dynamic range during rendering process. " "Additionally, this allows color calculation whose value is in linear correspondence with actual energy, " "that is, physically accurate blending can be achieved.")));

cfg.AddRow(StartupScreenConfigCheckItemEditor(
ui, StartupScreenConfig(ui, "r_vsync"), "0", "1",
_Tr("StartupScreen", "V-Sync"),
cfg.AddRow(StartupScreenConfigSelectItemEditor(
ui, StartupScreenConfig(ui, "r_vsync"), "0|1|-1",
_Tr("StartupScreen",
"Enables frame rate synchronization.")));
"Vertical Sync:Synchronizes screen updates to a monitor's refresh rate.|" "Off|" "On|" "Adaptive")));

{
StartupScreenComplexConfig cplx;
Expand Down Expand Up @@ -473,8 +472,11 @@ namespace spades {
StartupScreenConfigView @configViewOpenAL;
StartupScreenConfigView @configViewYSR;

StartupScreenAudioOpenALEditor @editOpenAL;

private ConfigItem s_audioDriver("s_audioDriver");
private ConfigItem s_eax("s_eax");
private ConfigItem s_openalDevice("s_openalDevice");

StartupScreenAudioTab(StartupScreenUI @ui, Vector2 size) {
super(ui.manager);
Expand Down Expand Up @@ -536,6 +538,7 @@ namespace spades {
{
StartupScreenConfigView cfg(Manager);


cfg.AddRow(StartupScreenConfigSliderItemEditor(
ui, StartupScreenConfig(ui, "s_maxPolyphonics"), 16.0, 256.0, 8.0,
_Tr("StartupScreen", "Polyphonics"),
Expand All @@ -547,6 +550,13 @@ namespace spades {
ui, StartupScreenConfig(ui, "s_eax"), "0", "1", _Tr("StartupScreen", "EAX"),
_Tr("StartupScreen",
"Enables extended features provided by the OpenAL driver to create " "more ambience.")));
AddLabel(0.f, 90.f, 20.f, _Tr("StartupScreen", "Devices"));
{
StartupScreenAudioOpenALEditor e(ui);
AddChild(e);
@editOpenAL = e;
cfg.AddRow(editOpenAL);
}

cfg.Finalize();
cfg.SetHelpTextHandler(HelpTextHandler(this.HandleHelpText));
Expand Down Expand Up @@ -609,6 +619,71 @@ namespace spades {
ui.helper.CheckConfigCapability("s_audioDriver", "null").length == 0;
configViewOpenAL.LoadConfig();
configViewYSR.LoadConfig();
editOpenAL.LoadConfig();

s_openalDevice.StringValue = editOpenAL.openal.StringValue;
}
}

class StartupScreenAudioOpenALEditor : spades::ui::UIElement, LabelAddable {
StartupScreenUI @ui;
StartupScreenHelper @helper;
ConfigItem openal("openal");

spades::ui::Button @dropdownButton;

StartupScreenAudioOpenALEditor(StartupScreenUI @ui) {
super(ui.manager);
@this.ui = ui;
@helper = ui.helper;
{
StartupScreenDropdownListDropdownButton e(Manager);
AddChild(e);
e.Bounds = AABB2(80.f, 0.f, 400.f, 20.f);
@e.Activated = spades::ui::EventHandler(this.ShowDropdown);
@dropdownButton = e;
}
}

void LoadConfig() {
string drivername = openal.StringValue;
string name = _Tr("StartupScreen", "Default device", drivername);
if (drivername == "") {
name = _Tr("StartupScreen", "Default device");
}

int cnt = helper.GetNumAudioOpenALDevices();
for (int i = 0; i < cnt; i++) {
if (drivername == helper.GetAudioOpenALDevice(i)) {
name = helper.GetAudioOpenALDevice(i);
}
}

dropdownButton.Caption = name;
}

private void ShowDropdown(spades::ui::UIElement @) {
string[] items = {_Tr("StartupScreen", "Default device")};
int cnt = helper.GetNumAudioOpenALDevices();
for (int i = 0; i < cnt; i++) {
string s = helper.GetAudioOpenALDevice(i);
items.insertLast(s);
}
spades::ui::ShowDropDownList(this, items,
spades::ui::DropDownListHandler(this.DropdownHandler));
}

private void DropdownHandler(int index) {
if (index >= 0) {
if (index == 0) {
openal = "default";
} else {
openal = helper.GetAudioOpenALDevice(index - 1);
}

// Reload the startup screen so the language config takes effect
ui.Reload();
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Resources/downloadpak.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ OUTPUT_DIR="."
if [ -f "$PAK_NAME" ]; then
exit 0
fi
# TODO: Check if the extracted files are present and up-to-date (#988)

wget "$PAK_URL" -O "$PAK_NAME"
if [ -n "$OPENSPADES_DEVPAK_PATH" ]; then
cp "$OPENSPADES_DEVPAK_PATH" "$PAK_NAME"
else
wget "$PAK_URL" -O "$PAK_NAME"
fi
unzip -o "$PAK_NAME" -d "$OUTPUT_DIR"

# relocate paks to the proper location
Expand Down
50 changes: 25 additions & 25 deletions Sources/Audio/ALDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ DEFINE_SPADES_SETTING(s_maxPolyphonics, "96");
DEFINE_SPADES_SETTING(s_eax, "1");
DEFINE_SPADES_SETTING(s_alPreciseErrorCheck, "1");
DEFINE_SPADES_SETTING(s_gain, "1");
DEFINE_SPADES_SETTING(s_openalDevice, "");

// lm: seems to be missing for me..
#ifndef ALC_ALL_DEVICES_SPECIFIER
Expand Down Expand Up @@ -421,6 +422,7 @@ namespace spades {

Internal() {
SPADES_MARK_FUNCTION();
const char *ext, *dev;

if (al::qalGetString(AL_EXTENSIONS)) {
std::vector<std::string> strs = Split(al::qalGetString(AL_EXTENSIONS), " ");
Expand All @@ -430,28 +432,13 @@ namespace spades {
}
}

SPLog("--- All devices ---");
const ALCchar *ext = al::qalcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
while (ext && *ext) {
SPLog("%s", ext);
ext += (std::strlen(ext) + 1);
}
SPLog("-------------------");

SPLog("--- Devices ---");
ext = al::qalcGetString(NULL, ALC_DEVICE_SPECIFIER);
while (ext && *ext) {
SPLog("%s", ext);
ext += (std::strlen(ext) + 1);
}
SPLog("---------------");
const ALCchar *dev = al::qalcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
if (dev && *dev) {
SPLog("Default device: %s", dev);
}
dev = s_openalDevice.CString();
SPLog("OpenAL opening device: %s", dev);
if (!strcmp(dev, "default"))
dev = NULL;
alDevice = al::qalcOpenDevice(dev);

alDevice = al::qalcOpenDevice(NULL);
if (!alDevice) {
if (UNLIKELY(!alDevice)) {
if ((ext = al::qalcGetString(NULL, ALC_EXTENSIONS))) {
std::vector<std::string> strs = Split(ext, " ");
SPLog("OpenAL ALC Extensions (NULL):");
Expand All @@ -476,7 +463,7 @@ namespace spades {
}

alContext = al::qalcCreateContext(alDevice, NULL);
if (!alContext) {
if (UNLIKELY(!alContext)) {
al::qalcCloseDevice(alDevice);
SPRaise("Failed to create OpenAL context.");
}
Expand Down Expand Up @@ -558,15 +545,15 @@ namespace spades {
ALSrc *AllocChunk() {
SPADES_MARK_FUNCTION();

size_t start = SampleRandomInt<std::size_t>(0, srcs.size() - 1);
size_t start = SampleRandomInt<std::size_t>(0, srcs.size() - 1);
for (size_t i = 0; i < srcs.size(); i++) {
ALSrc *src = srcs[(i + start) % srcs.size()];
if (src->IsPlaying())
continue;
return src;
}

ALSrc *src = SampleRandomElement(srcs);
ALSrc *src = SampleRandomElement(srcs);
src->Terminate();
return src;
}
Expand All @@ -575,7 +562,7 @@ namespace spades {
SPADES_MARK_FUNCTION();

ALSrc *src = AllocChunk();
if (!src)
if (UNLIKELY(!src))
return;

src->stereo = chunk->GetFormat() == AL_FORMAT_STEREO16;
Expand Down Expand Up @@ -755,6 +742,19 @@ namespace spades {
d = new Internal();
}

std::vector<std::string> ALDevice::DeviceList() {
std::vector<std::string> devs;
const ALCchar *ext = al::qalcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
if (!ext || *ext == '\0')
ext = al::qalcGetString(NULL, ALC_DEVICE_SPECIFIER);
while (ext && *ext) {
devs.push_back(ext);
ext += std::strlen(ext) + 1;
}

return devs;
}

bool ALDevice::TryLoad() {
try {
al::Link();
Expand Down
2 changes: 2 additions & 0 deletions Sources/Audio/ALDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace spades {

client::IAudioChunk *RegisterSound(const char *name) override;

static std::vector<std::string> DeviceList();

void ClearCache() override;

void SetGameMap(client::GameMap *) override;
Expand Down
3 changes: 2 additions & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ endif()
if(WIN32)
target_link_libraries(OpenSpades ws2_32.lib winmm.lib)
elseif(UNIX AND NOT APPLE)
target_link_libraries(OpenSpades Xext)
target_link_libraries(OpenSpades ${XEXT_LIBRARY})
include_directories(${XEXT_INCLUDE_DIR})
endif()

if(UNIX)
Expand Down
10 changes: 10 additions & 0 deletions Sources/Core/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,19 @@ namespace spades {

#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__((deprecated))
#define PURE __attribute__((pure))
#define LIKELY(cond) __builtin_expect(!!(cond), true)
#define UNLIKELY(cond) __builtin_expect(!!(cond), false)
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#define LIKELY(cond) (cond)
#define UNLIKELY(cond) (cond)
#define PURE
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#define PURE
#pragma message("WARNING: You need to implement LIKELY/UNLIKELY for this compiler")
#define LIKELY(cond) (cond)
#define UNLIKELY(cond) (cond)
#endif
6 changes: 3 additions & 3 deletions Sources/Draw/SWFeatureLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ namespace spades {
return tmp;
}
#else
static inline float fastDiv(float a, float b) { return a / b; }
static inline float fastRcp(float b) { return 1.f / b; }
static inline float fastRSqrt(float b) { return 1.f / sqrtf(b); }
static inline PURE float fastDiv(float a, float b) { return a / b; }
static inline PURE float fastRcp(float b) { return 1.f / b; }
static inline PURE float fastRSqrt(float b) { return 1.f / sqrtf(b); }
#endif
static inline float fastSqrt(float s) {
if (s == 0.f)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Draw/SWMapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ namespace spades {
LinePixel px;
px.depth = dist;
#if ENABLE_SSE
if (flevel == SWFeatureLevel::SSE2) {
if constexpr (flevel == SWFeatureLevel::SSE2) {
__m128i m;
uint32_t col = map.GetColorWrapped(x, y, z);
m = _mm_setr_epi32(col, 0, 0, 0);
Expand Down Expand Up @@ -887,7 +887,7 @@ namespace spades {
// though this isn't a problem as long as the color comes
// in the LSB's
#if ENABLE_SSE
if (flevel == SWFeatureLevel::SSE2) {
if constexpr (flevel == SWFeatureLevel::SSE2) {
__m128i m;

if (under == 1) {
Expand Down Expand Up @@ -985,7 +985,7 @@ namespace spades {
// though this isn't a problem as long as the color comes
// in the LSB's
#if ENABLE_SSE
if (flevel == SWFeatureLevel::SSE2) {
if constexpr (flevel == SWFeatureLevel::SSE2) {
__m128i m;

if (under == 1) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Draw/SWModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace spades {
SPAssert(normal < 28);
int bright = brights[normal];
#if ENABLE_SSE2
if (lvl == SWFeatureLevel::SSE2) {
if constexpr (lvl == SWFeatureLevel::SSE2) {
auto m = _mm_setr_epi32(color, 0, 0, 0);
auto f = _mm_set1_epi16(bright << 8);

Expand Down
4 changes: 2 additions & 2 deletions Sources/Draw/SWUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ namespace spades {
}
}

static inline int ToFixed8(float v) {
static inline PURE int ToFixed8(float v) {
int i = static_cast<int>(v * 255.f + .5f);
return std::max(std::min(i, 255), 0);
}

static inline int ToFixedFactor8(float v) {
static inline PURE int ToFixedFactor8(float v) {
int i = static_cast<int>(v * 256.f + .5f);
return std::max(std::min(i, 256), 0);
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/Gui/MainScreenHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,14 @@ namespace spades {
curl_easy_setopt(cHandle.get(), CURLOPT_URL, cl_serverListUrl.CString());
curl_easy_setopt(cHandle.get(), CURLOPT_WRITEFUNCTION, curlWriteCallback);
curl_easy_setopt(cHandle.get(), CURLOPT_WRITEDATA, this);
if (0 == curl_easy_perform(cHandle.get())) {
curl_easy_setopt(cHandle.get(), CURLOPT_LOW_SPEED_TIME, 30l);
curl_easy_setopt(cHandle.get(), CURLOPT_LOW_SPEED_LIMIT, 15l);
curl_easy_setopt(cHandle.get(), CURLOPT_CONNECTTIMEOUT, 30l);
auto reqret = curl_easy_perform(cHandle.get());
if (CURLE_OK == reqret) {
ProcessResponse();
} else {
SPRaise("HTTP request error.");
SPRaise("HTTP request error (%s).", curl_easy_strerror(reqret));
}
} else {
SPRaise("Failed to create cURL object.");
Expand Down
Loading

0 comments on commit ed17aea

Please sign in to comment.