summaryrefslogtreecommitdiff
path: root/src/utils
AgeCommit message (Collapse)AuthorFilesLines
2025-04-29Changed removeColors to work in-placeThorbjørn Lindeijer2-9/+8
Can avoid some memory allocations. Also simplified its implementation a little. Also made ChatLogger::getDateString use the full year.
2025-04-25GUI: Added support for multiple color palettes to ThemeThorbjørn Lindeijer1-4/+4
Each Skin can point to a different palette, which can be used to tweak text colors where necessary. For now there is no generic solution for this, instead a number of locations have been adjusted to take the palette into account: * ChatWindow sets its palette on the BrowserBox used in its tabs. * Popup sets its palette on child widgets when they are added (covering BrowserBox, Label and TextBox). * ItemPopup now uses its palette when looking up colors. The BrowserBox now retrieves its numbered text colors from the theme. Also added OLDCHAT, AWAYCHAT and GLOBAL theme colors, with ##g, ##o and ##a to choose these colors respectively. Fixed ImageRect move constructor. TextPreview class was cleaned up from unused functionality. Being name colors are no longer different between the name shown on the being and the name shown in the SpeechDialog.
2025-04-25Introduced theme dropdown in interface setupThorbjørn Lindeijer1-2/+11
* Added Theme dropdown to Interface setup * Added CARET theme color * Fixed issue with logging errors in `check` function in `theme.cpp` * Fixed XML::Children::Iterator to iterate only element nodes * Changed default theme to "jewelry" Changing the theme (or font size) shows a dialog that points out a restart is required to apply these changes. This is necessary at the moment because many things, like default or minimum window sizes, are only calculated once.
2025-03-24Expanded GUI theming capabilitiesThorbjørn Lindeijer2-11/+28
* Moved previously hardcoded values for frame size, padding and title bar height to the Skin. * Added support for rendering colored rectangles (used for scroll bar background). * Scroll bar width is now determined by its skin. * Added separate skins for horizontal and vertical scroll bars and horizontal and vertical scroll markers and added a skin for the shortcut box. * Added support for hovered state on window close button.
2025-03-13Removed needless case-insensitive string comparisonsThorbjørn Lindeijer2-33/+0
These are not necessary since we can instead make sure the referenced values match case, like we do for everything else. This affects server types in the server list and colors referenced in theme files. The server version was also compared case-insensitively for some reason.
2025-03-01Further Download related cleanupsThorbjørn Lindeijer1-0/+39
* Moved the memory buffer and mutex handling into the Download class to simplify the code updating the UI in ServerDialog and UpdaterWindow. * Replaced the "DownloadUpdate" callback function with simply polling Download::getState, since in the end polling was happening anyway. This changes also fixes handling of the Enter key while downloading updates, which no longer cancels the update process. Also, when pressing Escape while things are being downloaded, the first press cancels and only the second press goes back to login. Introduced a ThreadSafe template class, which wraps any type and makes it only accessible by calling lock(). This ensures the data is never accessed without locking the relevant mutex.
2025-02-28Replaced buffered SDL_RWops wrapper with PHYSFS_setBufferThorbjørn Lindeijer3-223/+13
This removes the buffered SDL_RWops functionality that was just added in 51b0c3239265ddee2d1bf445f873299cc8193ab9. We just call PHYSFS_setBuffer instead. Using the PhysicsFS buffer is a little bit slower, likely because it operates at a lower level, but it is fast enough for our purposes. Uncompressed music files loaded from ZIP files can start playing in about 1-2 ms. I've also landed a fix for the problem in SDL_mixer, which works even better in any case: https://github.com/libsdl-org/SDL_mixer/pull/671
2025-02-26Use ResourceRef for all resource typesThorbjørn Lindeijer1-0/+9
All ResourceManager functions that load resources now return respective ResourceRef values, which helps to make sure resources are properly cleaned up. The Sound class was cleaned up and now also allows SoundEffect resources to be unloaded. The Animation class now keeps its ImageSet loaded only as long as necessary. Previously, SimpleAnimation and ParticleEmitter would keep the ImageSet loaded indefinitely by never decreasing its reference count. Reduced duplicated animation loading code between SimpleAnimation and ParticleEmitter.
2025-02-20Simplified filling of the BufferedRWops bufferThorbjørn Lindeijer1-23/+5
In fact filling the buffer only happens when the buffer was exhausted or empty, so we always want to fill it entirely and don't need to bother with moving remaining contents. This is what happens when you let AI write your code.
2025-02-20Fixed stutter when new music starts playingThorbjørn Lindeijer3-0/+241
This is a workaround for a performance issue when SDL_mixer is using stb_vorbis. Since stb_vorbis will request the file one byte at a time, the overhead of using SDL_RWops to call PHYSFS_readBytes is too high. Solved by introducing a buffered SDL_RWops wrapper with a fixed 2048 byte buffer. This is a more optimal solution than loading the entire OGG file in memory. Now starting a new song takes less than 1ms, when the OGG file isn't compressed (almost down to 0.2ms when SDL_mixer uses libvorbisfile). See https://github.com/libsdl-org/SDL_mixer/issues/670 Closes https://git.themanaworld.org/mana/mana/-/issues/93
2025-02-17Further ResourceManager and PhysFS cleanupsThorbjørn Lindeijer4-82/+50
* Wrapped remaining PhysFS API calls and set PHYSFS_DEPRECATED to suppress deprecation warnings for PHYSFS_getUserDir, since no alternative is available for now. * Removed support for decompressing .gz files, since it has been unused for years and doesn't seem useful when updates are anyway served in an archive. * Use SDL_LoadFile and SDL_LoadFile_RW convenience functions (raises minimum SDL version to 2.0.10). * Removed ResourceManager::copyFile, since it was unused and will likely stay unused. * Removed ResourceManager::loadTextFile. Instead, split up the string in BrowserBox::addRows without making additional copies.
2025-02-17Wrapped PhysFS usage in a convenience APIThorbjørn Lindeijer1-0/+234
* Most direct PhysFS calls now contained within a single header file. * File class that automatically closes. * Files class allows iterating files with range-based for. * Use std::optional to force error handling where applicable.
2025-02-14Fixed handling of update URLs which mention a portThorbjørn Lindeijer2-54/+32
This appears to have been a regression in f405849b49614254f42eb3ee6147434458978623, which for some reason erased the port (and any trailing parts) from not just the update directory but also from the update URL. Unfortunately we can't access Mana-Mantis #381 at the moment, but presumably the port was removed due to the colon being a problematic character. Instead, now the colon (and other special characters) are replaced by _ when determining the update directory. Closes https://git.themanaworld.org/mana/mana/-/issues/80
2025-02-13Implemented support for item replacementsThorbjørn Lindeijer1-0/+5
Specifying an unknown sprite or direction is reported as error and will not cause any replacements. Specific item replacements are supported also when not specifying the sprite. Replacements do not affect particle effects. Part of https://git.themanaworld.org/mana/mana/-/issues/92
2025-01-21Replaced include guards with #pragma onceThorbjørn Lindeijer14-52/+15
Thanks to https://github.com/cgmb/guardonce and a follow-up replace to remove duplicated newlines at end of file: find src -type f -name '*.h' -exec \ sed --in-place -e :a -e '/^\n*$/{$d;N;};/\n$/ba' {} \; Source: https://unix.stackexchange.com/questions/81685/how-to-remove-multiple-newlines-at-eof Fixes compile on macOS, which appears to have been due to the EVENT_H include guard.
2025-01-20Made client config statically typedThorbjørn Lindeijer2-29/+91
This makes accessing the config values much faster, since it no longer needs to do a lookup nor string conversion, which means we could remove some needless copying of the values. Overall it makes it easier to find out where settings are used and it puts the defaults along with the declaration. Options with default values are no longer saved to the config file. This does not include unrecognized options, which are kept around to provide some compatibility with older clients. While most basic options have kept the same name, more complicated settings like window geometry, shortcuts, outfits, etc. now have their own XML elements. Older clients will ignore these and erase them when saving the configuration.
2025-01-20Cleaned up path handling a bitThorbjørn Lindeijer2-44/+34
2025-01-20Wrapped xmlNodePtr access with a Node classThorbjørn Lindeijer2-144/+143
Slightly more ergonomic and this eliminates direct libxml2 usage from many places.
2025-01-18Introduced small convenience wrapper to write XMLThorbjørn Lindeijer4-15/+121
Might not seem worth it right now, but it will be if we write out more XML structures.
2024-10-18Avoid accessing static members through instancesThorbjørn Lindeijer1-2/+2
Fixed with clang-tidy `readability-static-accessed-through-instance` check.
2024-10-08Smoother being movementThorbjørn Lindeijer2-1/+11
There was a slight stutter in being movement, since each time a being reached the next position along its path, it would only continue to the following position with the next logic tick. Now the logic has been adjusted to keep moving until all the time for the current frame was used up, or the path was exhausted. A slight stutter remains for keyboard movement, as well as broken walk animation playback, since it will only set a new path once the current one is finished (see e554d9b2be1ec2fcb15065ae70151302adeef602). Also simplified some logic in Viewport::draw and removed some obsolete code in LocalPlayer::startWalking.
2024-10-08Added convenient and efficient Timer classThorbjørn Lindeijer2-0/+169
The Timer is efficient because it does not depend on incrementing a counter to keep track of time, nor does it call SDL_GetTicks every time its state is checked (this happens once per frame instead). Along with global functions Time::absoluteTimeMs() and Time::deltaTimeMs(), this replaces previous globals tick_time, cur_time and get_elapsed_time(). For now, there is still a fixed 100 times per second logic call rate, but the new Time::deltaTimeMs() function should allow getting rid of this.
2024-09-27Replaced for_each_xml_child_node macro with helper classThorbjørn Lindeijer2-4/+30
The new XML::Children class enables using a C++11 range-based for loop to iterate over the children of an xmlNodePtr.
2024-04-17macOS: Create an app bundleThorbjørn Lindeijer2-2/+26
Also enable using `cpack -G DragNDrop` to create a DMG to easily drag Mana into the Applications folder. The DMG is also available as a CI artifact. The minimum deployment target has been set to 10.15, as required due to usage of std::filesystem::create_directories.
2024-04-08Use C++17 to implement mkdir_rThorbjørn Lindeijer2-68/+9
Should be a lot less fragile and might also help to resolve encoding issues.
2024-04-08Windows: Modernize getSpecialFolderLocationThorbjørn Lindeijer2-30/+29
Ported from CSIDL to newer FOLDERID API and used wcstombs_s to convert the returned path to a multi-byte string. Fixes issues when the Windows username contains special characters.
2024-04-02General code cleanupsThorbjørn Lindeijer1-1/+1
* Removed some unused includes * Removed unused ListBox::mFont * Removed wrong cast to SDL_Scancode * Removed superfluous .c_str() * Removed superfluous explicit std::string construction * Removed unused variable * Use more emplace_back * Turned FindBeingFunctor into a lambda * Avoid needless pointer references for ambient layers and use a vector
2024-03-28Fixed compile against libxml2 2.12ewew ukek2-23/+22
Quote from Fedora mailing lists: The latest released versions of libxml2 have a couple of important changes in header files that have unintentionally caused some packages to fail to build without modification, including: * several functions now accept or return a const xmlError struct * cyclic dependencies in header files were fixed (by dropping some includes)
2024-03-25Avoid string allocations during text rendering and sizingThorbjørn Lindeijer2-12/+0
Now a text chunk has a maximum length of 4k characters, but that should be plenty of space since they're only single lines.
2024-03-25Removed an unnecessary extra allocation in strprintfThorbjørn Lindeijer1-5/+4
We can use vsnprintf to write to the std::string directly.
2024-03-13Use snprintf instead of sprintfThorbjørn Lindeijer1-5/+5
Amendment of dd1db3753ecf8a4d782aee1f518759763d8caf87.
2024-03-11Implemented ability to open external links in news and chatThorbjørn Lindeijer1-0/+8
* Use ConfirmDialog to confirm the opening of the external link. * ConfirmDialog now centers on its parent window when provided. * Reset hovered link when mouse exits the BrowserBox.
2024-02-29Re-download updates when their checksum no longer matchesThorbjørn Lindeijer1-1/+1
The Mana World currently likes to just update its "TMW.zip" file, whereas updates were always given unique names in the past. With this change, the client checks the Adler32 checksum to know when it should re-download an update file. This matches the behavior of ManaPlus commit 96150f1aeacf55d311c41ffe12d9e754b1cda001.
2024-02-22General code cleanupsThorbjørn Lindeijer3-15/+13
* Use default member initializers * Use range-based loops * Don't use 'else' after 'return' * Removed some unused includes * Construct empty strings with std::string() instead of "" * Clear strings with .clear() instead of assigning "" * Check whether strings are empty with .empty() instead of comparing to "" * Removed redundant initializations
2024-02-13General code cleanupsThorbjørn Lindeijer1-6/+5
* Removing unused includes * Use member initialization * Use range-based for loops * Use nullptr * Removed no longer used aliases * Use override * Don't use else after return * Use '= delete' to remove implicit members * Use std::string::empty instead of comparing to ""
2024-02-05Updated C++ standard to C++17Thorbjørn Lindeijer2-7/+25
C++17 should be universal enough by now. This raises the minimum CMake to 3.8, which should also pose no problem since Ubuntu 18.04 already shipped with CMake 3.10. C++17's 'if' initialization statement is now used in an efficient implementation of 'join' for vector<string>, found on StackOverflow.
2024-02-02Restored support for setting monster ID offset on monsters tagThorbjørn Lindeijer2-2/+12
Apparently this was supported before, but support for that was lost in bd1fdd87eed48ba3ffcc413936d6a6a60a429a97. Fixes #46
2024-01-29Apply C++11 fixitsThorbjørn Lindeijer3-6/+6
modernize-loop-convert modernize-deprecated-headers
2024-01-29Updated PhysFS RWops helper to the latest versionThorbjørn Lindeijer2-59/+117
Fixes compatibility with SDL2. The old version compiled for whatever reason, but it would crash when the client tried to play a sound.
2024-01-26Apply C++11 fixitsThorbjørn Lindeijer6-23/+23
modernize-use-auto modernize-use-nullptr modernize-use-override modernize-use-using
2024-01-25Always use C++11 and remove related compatibility option/codeThorbjørn Lindeijer1-4/+0
2024-01-25Ported to SDL2Thorbjørn Lindeijer2-304/+16
2024-01-24Removed undefined '__EXPORT__'Thorbjørn Lindeijer1-5/+4
There should be no need to export the functions explicitly, given that they are compiled as part of the executable.
2024-01-24Fixed a few coding errors the compiler complained aboutThorbjørn Lindeijer1-1/+1
2024-01-24Fixed compilation issues and use of deprecated C++ featuresThorbjørn Lindeijer1-4/+2
* Fixed compiler errors due to dynamic exception specifications * Replace std::auto_ptr with std::unique_ptr * Replace std::mem_fun with std::mem_fn * Prefix for_each with std:: (apparently not needed before) * Just use lambda instead of std::bind2nd * Removed usages of std::unary_function
2013-05-04Client-side settings are now available from settings.xmlPrzemysław Grzywacz2-0/+195
2013-04-27Small cleanupThorbjørn Lindeijer1-4/+0
2012-03-24Merge branch '0.6'Thorbjørn Lindeijer1-0/+5
2012-03-24Introduced compile-time option to disable use of C++0xThorbjørn Lindeijer1-0/+5
This is in order to still support older compilers, in particular GCC 4.2.1, so that Mana may be compiled for Maemo 5. Reviewed-by: Yohann Ferreira
2012-03-18Removed some 'const' keywords from value returnsThorbjørn Lindeijer2-7/+7
It makes no sense to mark a return value as const when it is returned by value. This only makes sense if the return value is passed by reference, in order to prevent the receiver from modifying the value. Also made some other small adjustments. A std::string does not need to be initialized to "" explicitly and getSafeUtf8String could take its parameter by reference. Reviewed-by: Yohann Ferreira