Commit Graph

84 Commits

Author SHA1 Message Date
sukibaby 0aa41b305d Make static vectors of default driver lists
Currently we are storing the default driver lists as a macro, and splitting them into RString vectors every time they are needed. This commit changes the macros in `arch_default.h` into vectors of RStrings, so that they do not need to be split each time.

I have updated all references where the default driver lists are being called so that the vector is used directly.

A new function is added to RageUtil to make a compatible vector of RStrings from user input which may be separated with a comma.

RageSoundDriver was refactored to check user input in Preferences.ini against the default driver list, and in case of incorrect spelling or failure, provides a detailed error message (including a list of valid options) in logs so the user can resolve the problem.

`fix_bogus_sound_driver_pref` is no longer needed, since we are now telling the user what their valid options are if the user provides an incorrect entry for the `SoundDrivers` preference, instead of silently attempting to guess what the user wanted. Since I think it's rare that someone wants to specify a driver to begin with, we should let them know their exact options if they put something wrong here, instead of silently failing or using an unwanted driver.

I tested this on Windows by specifying `DirectSound-sw` in Preferences.ini, and it worked as expected. I also tried putting an unusable value in, and got the error in logs letting me know what my valid driver options were. Of course, input and movies all work as expected too.
2024-09-22 10:51:58 -07:00
sukibaby eb35a9b9af Switch from Float to Integer Time Values
- Use fast data types where possible so the compiler can optimize for speed based on platform
    - for example, 128 bits might be fastest on ARM
    - good future-proofing

- Refactor GetTimeSinceStart() to be a bit faster
    - multiplication is much faster than division

- Implement a RageTimer method to get the seconds value as a plain int, for the places which cast the seconds value to an int

- Changing from GetTimeSinceStartFast() to GetTimeSinceStart() where accuracy is important

- Changing from GetTimeSinceStart() to GetUsecsSinceStart() for timestamp diffs

- Adjust RageThreads to accomodate an unsigned timestamp value
   - a constant for the maximum value of `uint_fast64_t` replaces `-1` to accommodate the change from signed to unsigned for the `locked_at` variable
   - i have separate constants for `std::numeric_limits<std::uint_fast64_t>::max()` and `static_cast<std::uint_fast64_t>(-1)`, so the reader understands -1 represents an error code, though they evaluate to the same value, so i could remove one of the two

- Add two methods to calculate the MMSSMsMs / MMSSMsMsMs time value from usecs directly instead of inferring it from a seconds value, in RageUtil

- Use a similar counter/modulo based method for WheelNotifyIcon, similar to what i did for text_glow in NoteField in 2eeee03

- Make `g_iStartTime` static const for safety

Rename two timer functions:
GetUsecsSinceStart -> GetTimeSinceStartMicroseconds
GetMicrosecondsSinceStart -> GetSystemTimeAsMicroseconds

Remove std prefix from uint_fast64_t
2024-09-22 01:27:45 -07:00
sukibaby 5e00535522 Prevent divide by 0 in calc_mean 2024-08-07 00:56:16 -07:00
Rafał Florczak f7f88f9544 Guard against signedness of chars and wchars on different targets 2024-05-30 17:38:47 -07:00
sukibaby c2ac89dcb6 Improve calc_mean function
A problem with using std::accumulate to calculate the mean is that small numbers get rounded down to zero when dealing with floating point numbers. This is solved by implementing the Kahan summation algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm).
2024-05-30 17:36:55 -07:00
sukibaby 705a069400 Resolve the SM5 sync drift issue
Summary of changes

1) Fix issues in RageTimer and RageSoundPosMap
2) Calculate seconds from microseconds more accurately
3) Replace lrint(x) with static_cast<int>(x+0.5) for better performance
4) Replace C style casting with C++ style casting
5) Make important values 64-bit wide
6) Update RageUtil.cpp (timer conversion RStrings had some math which needed to be fixed after fixing RageTimer's math)
7) Ensure floating point math is done as floating point
8) Improve code commentary all around
9) Improve clarity and efficiency of RageSoundPosMap "return closest position" error logging
2024-05-12 08:05:41 -07:00
Gareth Francis 7009a16dea RageUtil::UnicodeUpperLower: Prevent negative characters from segfaulting under GCC 2024-04-10 14:09:10 -07:00
Michael Votaw e8947d9f70 Added a new SmEscape parameter to allow us to specify what characters to escape (defaults to '\\', ':', ';')
Added new SmEscape function to handle escaping a vector of strings
Added SmUnescape() to remove the '\\' preceding an escaped character.
2024-03-06 01:45:26 -08:00
Martin Natano bacecae1f7 Decouple <vector> 2023-04-21 22:13:41 +02:00
Martin Natano aa87f85eef Decouple <cstdint> 2023-04-21 22:13:41 +02:00
Martin Natano 78fb2e9fc3 Decouple <cstddef> 2023-04-20 11:21:29 +02:00
Martin Natano b68ca517e6 Clean up math functions
- Remove checking for standard functions from the build system
- Prefix all invocations with std::
- Replace suffixed functions with unprefixed versions
- Include <cmath> in all files that use it and remove the global include

e.g. floorf(x) -> std::floor(x)
2023-04-19 19:31:40 +02:00
Brian Phlipot d079940fea Address PR feedback. 2023-02-02 11:54:17 -08:00
Brian Phlipot 4a6b1a743c Enable more compiler warnings and treat them as errors. 2023-02-02 11:54:17 -08:00
Brian Phlipot 37aff00d6e Require C++20 for building Stepmania. 2022-10-03 16:21:19 -07:00
Michael Sundqvist 0cba3579de Remove global "using namespace std;" declarations, use "std::" prefixes on all std elements
Fix whitespace changes
2022-07-31 22:14:38 +02:00
Martin Natano 1b959d6762 Use type switch in JsonEncode
lua_isnumber and lua_isstring try to coerce the values to their
respective type, so a type switch is more reliable.

Fixes https://github.com/Simply-Love/Simply-Love-SM5/issues/406
2022-07-04 20:24:22 +02:00
Martin Natano 5f08636ad0 std::binary_function is deprecated and unnecessary in C++11 2022-05-31 12:55:03 +02:00
Martin Natano 9723a67ad7 Upgrade pcre 4.5 -> 8.45 2022-05-30 23:57:33 +02:00
Martin Natano 4c0aef69dd Remove legacy network code 2022-04-11 14:50:00 -07:00
Martin Natano e1b5664f21 Update jsoncpp from version 0.5.0 to 1.9.5
Aside from including a ton of bug fixes, this should fix an issue in the
CI pipeline when building with system libraries that was caused by a
minor incompatibility between 0.5.0 and less ancient versions.

Also, switch to the amalgamated source, because it makes it easier to
keep it up to date.
https://github.com/open-source-parsers/jsoncpp/wiki/Amalgamated-(Possibly-outdated)
2022-02-19 14:10:55 +01:00
Martin Natano b4f86a2052 Add json encoding/decoding functions to lua
This adds two global functions:

- `JsonEncode()`: Encode data as JSON. Optionally "minify" the result.
- `JsonDecode()`: Decode JSON data.
2021-10-13 19:33:02 +02:00
Martin Natano 8c2f13da2c Fix BinaryToHex()
Previously the function stopped short on nul bytes ("\0") due to usage
of the SArg() macro, which does not retrieve the length of the lua
string.

before the fix: `BinaryToHex("a\0b")` -> `"61"`
after the fix: `BinaryToHex("a\0b")` -> `"610062"`
2021-09-19 22:07:31 +02:00
Gareth Francis aeb5c7598f Handle exceptions in int conversions (#2092)
* RageUtil: Add exception-safe wrappers around std::stoi, stol, stoll

* Replace use of std::stoi with exception-safe StringToInt
2021-02-15 12:36:51 -08:00
quietly turning fdef606b46 expose RageUtil's BinaryToHex to Lua
The hashing functions that CryptManger currently exposes to Lua
return hash strings formatted in binary.  Themes using those hash
functions may want to compare hex strings.

RageUtil already had a BinaryToHex utility; this commit exposes it
as a global function, following along with other utility functions
in RageUtil.
2020-09-09 15:16:24 -04:00
teejusb 620ef3609d Revert to use std::strtof insted of std::stof to make travis happy 2020-04-08 22:41:19 -07:00
teejusb 1d365fbc18 Fix float parsing errors 2020-04-08 22:01:16 -07:00
Prcuvu de4dc62846 Split Chinese language into Simplified script and Traditional script
ArchHooks function modified for Windows.
2020-02-08 15:46:00 +08:00
teejusb 7e3789b131 Integrate C++11 branch into 5_1-new 2019-06-22 12:35:38 -07:00
Kyzentun 2aee27a276 Backport custom song support. Prefs are CustomSongsEnable, CustomSongsMaxCount, CustomSongsLoadTimeout, CustomSongsMaxSeconds, CustomSongsMaxMegabytes. Metrics are NumProfileSongGroupColors and the colors with it. Profile custom load function is passed PlayerNumber now. Stepmania must run as root to save USB profile scores. (#1470) 2017-06-06 05:30:06 -07:00
Kyzentun Keeslala 2b6768aed9 Remove UndocumentedFeature lua function. It has no legitimate purpose and just crashes with a message. 2016-05-20 19:02:54 -06:00
Jason Felds bec18a0d36 Fix minor windows pedantic warnings. 2016-03-27 22:03:15 -04:00
Jason Felds 537af8d866 Remember to fill in new char's.
...we seriously need to use a standard <string>.

*glares at Yaniel*
2015-09-26 21:03:46 -04:00
Jason Felds cf545a3c01 Remove the need for the RString buffer.
For most areas, the call to `c_str()` is plenty.

For `RageUtil`, it's just a matter of new and delete.
2015-09-16 22:29:53 -04:00
Prcuvu 5af37530d4 Rewrite power_of_two, using binary search. 2015-09-02 20:05:02 +08:00
Kyzentun Keeslala 5f50a8ea26 Added get_music_file_length and RageSound:get_length lua functions. Updated changelog. 2015-06-10 14:41:28 -06:00
Kyzentun Keeslala 771e24d1ca Added kludge to shift tex coords for bottom cap by one pixel to get rid of seam. power_of_two rewritten to use math instead of a while loop. 2015-06-07 18:27:35 -06:00
Kyzentun 1c3db82537 Modified StepsID operators to consider 0 equal to all other hash values. See comment in source for details. Changed operator>>(RString&, int&) functions to be based off a template. 2015-04-10 09:10:51 -06:00
Kyzentun 2f1a348565 Commify handles negative numbers now. 2015-04-02 18:02:38 -06:00
Kyzentun d789ef7c6b Exposed commify function to lua and made it handle decimal numbers. 2015-04-02 13:36:41 -06:00
Kyzentun 8b09da8e64 Various changes to speed up start up time:
Added delay_save_cache to SongCacheIndex so that it doesn't write the entire cache index file after every song is loaded when loading songs.
Added m_SongsByDir to SongManager so that GetSongFromDir doesn't have to walk the entire list of songs.
Minor changes to when LoadEnabledSongsFromPref occurs and how SanityCheckGroupDir works to speed up loading.
Song::ReloadFromSongDir removes cache file to force an actual reload from the song dir instead of reloading from the cache.  ReloadFromSongDir exposed to lua.
Reordered Actor::LoadFromNode to put Command first because that case is more common.
Course::GetTrailUnsorted reserves entries before starting to save time reallocating.
join in RageUtil calculates the final size of the concatenated strings reserves it to save time reallocating.
Added time log file to RageLog for profiling.
2015-03-30 17:45:52 -06:00
Kyzentun a2798e16f4 More aggressive caching. In general, this makes Stepmania avoid looking in the song directory at all if the song is in the cache, in order to load songs faster. All the RadarValue calculations were also rolled into one to reduce the time needed to build the cache. 2015-03-23 11:35:30 -06:00
Andrew Udvare 36a412f6e4 Add --with-system-pcre; allow building against system PCRE library 2015-01-28 16:11:26 -08:00
Kyzentun ca4eb65b61 Added lerp, lerp_color, approach, and multiapproach lua functions. 2014-10-23 00:13:13 -06:00
Kyzentun e3f8d272c1 istream::operator bool() is explicit in C++11, use git diff 2014-09-02 14:33:55 -06:00
Kyzentun d5878da037 Added Arbitrary Remap option to Alter Menu in Edit Mode. 2014-08-30 13:38:16 -06:00
Ben "root" Anderson 263240debc Apparently MinGW needs this too. 2013-10-27 15:36:05 -05:00
Jason Felds a8fe2634ca Do string validation before parsing.
...this is NOT the right place for this.

At some point, we need to either use std::stof directly
and/or just accept that we need to use exceptions.
2013-05-04 13:43:54 -04:00
Jason Felds f5c877cbb6 Replace StringToInt with the std version.
Again, RageUtil isn't the right home.
2013-05-04 11:59:25 -04:00
Jason Felds 490327cf55 Remove the IntToString function, use std.
...this seriously didn't belong in Rage.
2013-05-04 11:22:10 -04:00