Skip to content

Commit

Permalink
Merge develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewol authored Jun 21, 2024
2 parents e8ede61 + f264d38 commit 8d18eb4
Show file tree
Hide file tree
Showing 20 changed files with 390 additions and 163 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install g++ libegl1-mesa-dev libfreetype6-dev libogg-dev libvorbis-dev libsdl2-dev libarchive-dev zlib1g-dev libjpeg-dev libpng-dev
sudo add-apt-repository universe
sudo apt install libfuse2
- name: cmake
run: cmake -DCMAKE_BUILD_TYPE=Release -DUSC_GNU_WERROR=On .
run: cmake -DCMAKE_BUILD_TYPE=Release -DUSC_GNU_WERROR=Off .
- name: make
run: make
- name: Prepare for bundling AppImage
Expand Down Expand Up @@ -92,11 +94,11 @@ jobs:
- name: brew update
run: brew update
- name: Install packages
run: brew install freetype libvorbis sdl2 libpng jpeg libarchive
run: brew install freetype libvorbis sdl2 libpng jpeg-turbo libarchive
- name: cmake
run: |
eval "$(brew shellenv)"
cmake . -DLibArchive_LIBRARY=$HOMEBREW_PREFIX/opt/libarchive/lib/libarchive.dylib -DLibArchive_INCLUDE_DIR=$HOMEBREW_PREFIX/opt/libarchive/include -DCMAKE_BUILD_TYPE=Release
env:
DCMAKE_BUILD_TYPE: Release
run: cmake .
- name: make
run: make
- name: Upload artifact
Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[submodule "third_party/cpr"]
path = third_party/cpr
url = https://github.com/whoshuu/cpr.git
branch = 1.10.x
[submodule "third_party/miniaudio"]
path = third_party/miniaudio
url = https://github.com/dr-soft/miniaudio.git
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Root CMake file
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "v")
set(CMAKE_CXX_STANDARD_REQUIRED True)
#set(VCPKG_CRT_LINKAGE static)
#set(VCPKG_LIBRARY_LINKAGE static)
#set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "Vcpkg target triplet (ex. x86-windows)")
Expand All @@ -14,6 +16,7 @@ endif()

option(BUILD_SHARED_LIBS "Build libraries as shared libraries" OFF)
option(USC_GNU_WERROR "Set Werror for gcc." OFF)
option(USE_SYSTEM_CPR "Use system CPR" OFF)

project(USC VERSION 0.5.0)
if(WIN32 AND ${CMAKE_VERSION} VERSION_GREATER "3.12")
Expand Down Expand Up @@ -42,6 +45,29 @@ endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

set(CMAKE_MACOSX_RPATH 1)

# Set library paths for MacOS
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)

# Set homebrew's include dir
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
include_directories("${HOMEBREW_PREFIX}/include")

# Libarchive is shipped as a keg so we must get its path manually
execute_process(
COMMAND brew --prefix libarchive
OUTPUT_VARIABLE LIBARCHIVE_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
set(LibArchive_INCLUDE_DIR "${LIBARCHIVE_PREFIX}/include")
endif()

# Set folder where to find FindXXX.cmake and
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")

Expand Down Expand Up @@ -139,3 +165,9 @@ if(MSVC)
set_target_properties(Tests.Game PROPERTIES FOLDER "Tests")

endif(MSVC)

install(TARGETS usc-game RUNTIME)
install(DIRECTORY bin/audio DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/unnamed-sdvx-clone)
install(DIRECTORY bin/fonts DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/unnamed-sdvx-clone)
install(DIRECTORY bin/LightPlugins DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/unnamed-sdvx-clone)
install(DIRECTORY bin/skins DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/unnamed-sdvx-clone)
5 changes: 5 additions & 0 deletions Main/include/LuaRequests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct AsyncRequest
struct lua_State* L;
cpr::AsyncResponse r;
int callback;

AsyncRequest(struct lua_State* luaState, cpr::AsyncResponse asyncResponse, int callback)
: L(luaState), r(std::move(asyncResponse)), callback(callback)
{
}
};

struct CompleteRequest
Expand Down
22 changes: 13 additions & 9 deletions Main/include/Scoring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ struct ScoreTick
ScoreTick() = default;
ScoreTick(ObjectState* object) : object(object) {};

// Returns the time frame in which this tick can be hit
MapTime GetHitWindow(const HitWindow& hitWindow) const;
// Hit rating when hitting object at given time
ScoreHitRating GetHitRating(const HitWindow& hitWindow, MapTime currentTime) const;
// Hit rating when hitting object give a delta
ScoreHitRating GetHitRatingFromDelta(const HitWindow& hitWindow, MapTime delta) const;
// Check a flag
Expand Down Expand Up @@ -233,6 +237,8 @@ class Scoring : public Unique

struct AutoplayInfo autoplayInfo;

float laserDistanceLeniency = 1.0f / 12.0f;

// Actual positions of the laser
float laserPositions[2];
// Sampled target position of the lasers in the map
Expand Down Expand Up @@ -299,8 +305,6 @@ class Scoring : public Unique
HitStat* m_AddOrUpdateHitStat(ObjectState* object);
void m_CleanupHitStats();

LaserObjectState* m_GetLaserObjectWithinTwoBeats(uint8 index);

// Updates laser output with or without interpolation
bool m_interpolateLaserOutput = false;

Expand All @@ -315,20 +319,20 @@ class Scoring : public Unique
// Input values for laser [-1,1]
float m_laserInput[2] = { 0.0f };
// Decides if the coming tick should be auto completed
float m_autoLaserTime[2] = { 0.0f };
const double m_laserDistanceLeniency = 1 / 6.;
const float m_autoLaserDuration = 4.5f / 60.f;
const float m_autoLaserDurationAfterSlam = 8.25f / 60.f;

//Ehhhh maybe
const MapTime m_offsetLaserConstant = 5;
float m_autoLaserTime[2] = { 0,0 };

// Saves the time when a button was hit, used to decide if a button was held before a hold object was active
MapTime m_buttonHitTime[6] = { 0, 0, 0, 0, 0, 0 };
MapTime m_buttonReleaseTime[6] = { 0, 0, 0, 0, 0, 0 };
// Saves the time when a button was hit or released for bounce guarding
MapTime m_buttonGuardTime[6] = { 0, 0, 0, 0, 0, 0 };

// Max number of ticks to assist
float m_assistLevel = 1.5f;
float m_assistPunish = 1.5f;
float m_assistChangePeriod = 50.0f;
float m_assistChangeExponent = 1.0f;
float m_assistTime = 0.0f;
// Offet to use for calculating judge (ms)
int32 m_inputOffset = 0;
int32 m_laserOffset = 0;
Expand Down
55 changes: 55 additions & 0 deletions Main/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ int32 Application::Run()
AddTickable(ss);
}
else // Start regular game, goto title screen
{
g_audio->SetGlobalVolume(g_gameConfig.GetFloat(GameConfigKeys::MasterVolume));
AddTickable(TitleScreen::Create());
}
}
}

Expand Down Expand Up @@ -989,6 +992,58 @@ bool Application::m_Init()
}
}

if (Path::gameDir.empty()) {
char* xdgDataDir = std::getenv("XDG_DATA_HOME");

if (xdgDataDir) {
String gameDir = Utility::Sprintf("%s%c%s", xdgDataDir, Path::sep, "unnamed-sdvx-clone");

auto gameDataSourceDir = Path::RemoveLast(Path::GetExecutablePath());
String xdgDataDirs(std::getenv("XDG_DATA_DIRS"));
// iterate over XDG_DATA_DIRS and look for a folder with the correct name
// if it exists, overwrite gameDataSourceDir with it and break
std::stringstream ss (xdgDataDirs);
String dir;
while (getline (ss, dir, ':')) {
String fullDir = Utility::Sprintf("%s%c%s", dir, Path::sep, "unnamed-sdvx-clone");
if (Path::IsDirectory(fullDir)) {
gameDataSourceDir = fullDir;
break;
}
}

Path::gameDir = gameDir;

if (!Path::IsDirectory(gameDir)) {
Logf("%s does not yet exist. Creating...", Logger::Severity::Info, *gameDir);

auto response = Path::CreateDir(gameDir);
if (response == 1) {
Logf("Created: %s", Logger::Severity::Info, *gameDir, response);
} else {
Logf("Failed creating directory %s. The game will probably crash soon.", Logger::Severity::Info, *gameDir, response);
}

std::list<String> requiredDirectories = { "skins", "fonts", "audio", "LightPlugins" };

for (String directory : requiredDirectories) {
auto sourceDir = Utility::Sprintf("%s%c%s", gameDataSourceDir, Path::sep, directory);
auto destDir = Path::Absolute(directory);

response = Path::CopyDir(sourceDir, destDir);
if (response == 1) {
Logf("Copied: %s to %s", Logger::Severity::Info, *sourceDir, *destDir, response);
} else {
Logf("Failed copying %s to %s. The game will probably crash soon.", Logger::Severity::Error, *sourceDir, *destDir, response);
}
}

} else {
Logf("Setting gamedir to $XDG_DATA_HOME (%s). If data is missing, you can either copy the game data in %s to that directory, unset the $XDG_DATA_HOME variable or run the game with -gamedir=%s", Logger::Severity::Warning, *gameDir, *gameDataSourceDir, *gameDataSourceDir);
}
}
}

// Set the locale so that functions such as `fopen` use UTF-8.
{
String prevLocale = setlocale(LC_CTYPE, nullptr);
Expand Down
86 changes: 62 additions & 24 deletions Main/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,10 @@ class Game_Impl : public Game
g_application->SetButtonLights(g_input.GetButtonBits() & 0b111111);
}

float brightness = 1.2 - (m_playback.GetBeatTime() * m_currentTiming->beatDuration) / 700.0;
brightness = Math::Clamp(brightness, 0.2f, 1.0f);

float brightness = 1.0 - (m_playback.GetBeatTime() * 0.8);
brightness = Math::Clamp(brightness, 0.0f, 1.0f);


Color rgbColor = Color::FromHSV(180, 1.0, brightness);
for (size_t i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -2204,12 +2205,42 @@ class Game_Impl : public Game

void OnButtonHit(Input::Button button, ScoreHitRating rating, ObjectState* hitObject, MapTime delta)
{
auto luaPopInt = [this] {
int a = lua_tonumber(m_lua, lua_gettop(m_lua));
lua_pop(m_lua, 1);
return a;
};

ButtonObjectState* st = (ButtonObjectState*)hitObject;
uint32 buttonIdx = (uint32)button;
Color c = m_track->hitColors[(size_t)rating];
auto buttonIndex = (uint32) button;
auto buttonIndex = (uint32)button;
bool skipEffect = m_scoring.HoldObjectAvailable(buttonIndex, false) && (!m_delayedHitEffects || buttonIndex > 3);


//call lua button_hit if it exists
lua_getglobal(m_lua, "button_hit");
if (lua_isfunction(m_lua, -1))
{
lua_pushnumber(m_lua, buttonIdx);
lua_pushnumber(m_lua, (int)rating);
lua_pushnumber(m_lua, delta);
if (lua_pcall(m_lua, 3, 3, 0) != 0)
{
Logf("Lua error on calling button_hit: %s", Logger::Severity::Error, lua_tostring(m_lua, -1));
}

uint8 b = luaPopInt();
uint8 g = luaPopInt();
uint8 r = luaPopInt();

if ((r | g | b) > 0) {
c = Color(Colori(r, g, b));
}

}
lua_settop(m_lua, 0);

if (!skipEffect)
m_track->AddHitEffect(buttonIdx, c, st && st->type == ObjectType::Hold);

Expand Down Expand Up @@ -2256,46 +2287,53 @@ class Game_Impl : public Game
}
}


}

void OnButtonMiss(Input::Button button, bool hitEffect, ObjectState* object)
{
uint32 buttonIdx = (uint32)button;

auto luaPopInt = [this] {
int a = lua_tonumber(m_lua, lua_gettop(m_lua));
lua_pop(m_lua, 1);
return a;
};
Color c = m_track->hitColors[0];

//call lua button_hit if it exists
lua_getglobal(m_lua, "button_hit");
if (lua_isfunction(m_lua, -1))
{
lua_pushnumber(m_lua, buttonIdx);
lua_pushnumber(m_lua, (int)rating);
lua_pushnumber(m_lua, delta);
if (lua_pcall(m_lua, 3, 0, 0) != 0)
lua_pushnumber(m_lua, (int)ScoreHitRating::Miss);
lua_pushnumber(m_lua, 0);
if (lua_pcall(m_lua, 3, 3, 0) != 0)
{
Logf("Lua error on calling button_hit: %s", Logger::Severity::Error, lua_tostring(m_lua, -1));
}

uint8 b = luaPopInt();
uint8 g = luaPopInt();
uint8 r = luaPopInt();

if ((r | g | b) > 0) {
c = Color(Colori(r, g, b));
}
}
lua_settop(m_lua, 0);
}

void OnButtonMiss(Input::Button button, bool hitEffect, ObjectState* object)
{
uint32 buttonIdx = (uint32)button;

if (hitEffect)
{
ButtonObjectState* st = (ButtonObjectState*)object;
//m_hiddenObjects.insert(object);
Color c = m_track->hitColors[0];
m_track->AddHitEffect(buttonIdx, c);
}
m_track->AddEffect(new ButtonHitRatingEffect(buttonIdx, ScoreHitRating::Miss));


lua_getglobal(m_lua, "button_hit");
if (lua_isfunction(m_lua, -1))
{
lua_pushnumber(m_lua, buttonIdx);
lua_pushnumber(m_lua, (int)ScoreHitRating::Miss);
lua_pushnumber(m_lua, 0);
if (lua_pcall(m_lua, 3, 0, 0) != 0)
{
Logf("Lua error on calling button_hit: %s", Logger::Severity::Error, lua_tostring(m_lua, -1));
}
}
lua_settop(m_lua, 0);

}

void OnComboChanged(uint32 newCombo)
Expand Down
2 changes: 0 additions & 2 deletions Main/src/GameConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "Shared/Log.hpp"
#include "HitStat.hpp"
#include "Input.hpp"

// When this should change, the UpdateVersion MUST be updated to update the old config files.
// If there's no need to update the UpdateVersion, there's no need to touch this too.
Expand Down Expand Up @@ -347,7 +346,6 @@ ConfigBase::KeyList GameConfigProfileSettings = {
Key(HitWindowPerfect),
Key(HitWindowGood),
Key(HitWindowHold),
Key(HitWindowSlam),
Key(GlobalOffset),
Key(InputOffset),
Key(LaserOffset),
Expand Down
3 changes: 1 addition & 2 deletions Main/src/GameplaySettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ void GameplaySettingsDialog::InitTabs()

Tab judgeWindowTab = std::make_unique<TabData>();
judgeWindowTab->name = "Judgement";
judgeWindowTab->settings.push_back(CreateIntSetting(GameConfigKeys::HitWindowPerfect, "Crit Window", { 0, HitWindow::NORMAL.perfect }));
judgeWindowTab->settings.push_back(CreateIntSetting(GameConfigKeys::HitWindowPerfect, "Crit Window", {0, HitWindow::NORMAL.perfect}));
judgeWindowTab->settings.push_back(CreateIntSetting(GameConfigKeys::HitWindowGood, "Near Window", { 0, HitWindow::NORMAL.good }));
judgeWindowTab->settings.push_back(CreateIntSetting(GameConfigKeys::HitWindowHold, "Hold Window", { 0, HitWindow::NORMAL.hold }));
judgeWindowTab->settings.push_back(CreateIntSetting(GameConfigKeys::HitWindowSlam, "Slam Window", { 0, HitWindow::NORMAL.slam }));
judgeWindowTab->settings.push_back(CreateButton("Set to NORMAL", [](const auto&) { HitWindow::NORMAL.SaveConfig(); }));
judgeWindowTab->settings.push_back(CreateButton("Set to HARD", [](const auto&) { HitWindow::HARD.SaveConfig(); }));

Expand Down
Loading

0 comments on commit 8d18eb4

Please sign in to comment.