summaryrefslogtreecommitdiff
path: root/src/resources
AgeCommit message (Collapse)AuthorFilesLines
2025-01-21Replaced include guards with #pragma onceHEADmasterThorbjørn Lindeijer27-105/+28
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-21Fixed ConfigOptionChanged eventsThorbjørn Lindeijer1-1/+1
With the statically typed config we no longer get an event for each changed config value. Where relevant, this is now done through `setConfigValue`. The `Event` now uses a `std::any`, which for `ConfigOptionChanged` events is set to the changed `Config` member. This allows for a type-safe check on which config value was changed.
2025-01-20Made client config statically typedThorbjørn Lindeijer5-86/+45
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 Lindeijer1-3/+3
2025-01-20Wrapped xmlNodePtr access with a Node classThorbjørn Lindeijer23-351/+321
Slightly more ergonomic and this eliminates direct libxml2 usage from many places.
2024-10-18Some code cleanups in ResourceManagerThorbjørn Lindeijer1-10/+4
* Use 'time' instead of 'gettimeofday', since we only use the timestamp anyway. * Use the iterator returned by std::map::erase.
2024-10-18General code cleanupsThorbjørn Lindeijer3-19/+11
2024-10-12Added support for hit/miss sounds on equipment for all playersThorbjørn Lindeijer2-6/+6
Previously only the local player's weapon "strike" sound would play, regardless of hit or miss. Now the sound is played in response to the SMSG_BEING_ACTION message, so it can be played for all players. Also added alias "miss", which is used by TMW in some places. Finally, when no weapon is equipped, it falls back to the sounds defined on the racesprite item (fixes punch sound on TMW). Closes #68
2024-10-08Do a single logic update each frameThorbjørn Lindeijer1-1/+1
The logic update now uses Time::deltaTimeMs() where needed to make it framerate-independent. This means there will no longer be multiple logic calls per frame (as was usually the case with logic ticking at 100 fps whereas the game would generally run at 60 fps). At the same time, the game can be more precise at higher framerates and should now run smoother at 144 Hz, for example. Previously the game would sometimes skip logic ticks at that rate. This change affects: * Updating of animations * Being movement speed * More moving of manual time variables to Timer Notoriously, the particle system still does 100 ticks/second.
2024-10-08Added convenient and efficient Timer classThorbjørn Lindeijer2-3/+3
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-10-02Removed getter/setter cruft from BeingInfoThorbjørn Lindeijer4-125/+68
Made the class and the code in general more readable by removing all the needless getters and setters. Also used "enum class" for SoundEvent.
2024-09-30Added support for particle effects on equipmentThorbjørn Lindeijer2-4/+6
The effect is also there when the equipment is dropped, because it uses the same field as the floor item. Removed unused ItemInfo::particle. Based roughly on M+ commit 44e5d8bcb7fea443ca9ed3844454b11ac6e4dbed. Closes #85
2024-09-28Replaced all "xmlChildrenNode" with "children"Thorbjørn Lindeijer4-10/+10
Because "xmlChildrenNode" is a macro defined for compatibility with libxml1, which we don't support.
2024-09-28Removed getter/setter cruft from ItemInfoThorbjørn Lindeijer7-309/+171
Made the class and the code in general more readable by removing all the needless getters and setters.
2024-09-27Replaced for_each_xml_child_node macro with helper classThorbjørn Lindeijer10-28/+27
The new XML::Children class enables using a C++11 range-based for loop to iterate over the children of an xmlNodePtr.
2024-08-04Removed unused Skin::mName and Skin::mFilePathThorbjørn Lindeijer2-29/+8
2024-08-04Add to npc option targetSelection to allow/disallow npc selection.Thorbjørn Lindeijer3-0/+13
The targetSelection attribute is supported on monsters and NPCs. Also changed return value of Being::getInfo to indicate it can't return nullptr. (cherry picked from M+ commit dbc3b324a0c5dcb1a0ee29b289e71423a06e85fd)
2024-04-08Fixed assertion failure on exitThorbjørn Lindeijer1-0/+4
Regression introduced in 14dc8218eeebd1583e6bd3c49013b3e501f47228.
2024-04-08Use ResourceRef<Image> in more placesThorbjørn Lindeijer6-26/+68
Automatic reference counting of images is now used by Item, Icon, AnimatedSprite, ImageSprite, ParticleEmitter, Minimap, Desktop and Emote. Since ResourceManager::get automatically adds a reference, it needs to be explicitly subtracted when the resource is managed by ResourceRef. This is taken care of by the new ResourceManager::getImageRef. Also removed the apprently unused and duplicate "mDrawImage" from Item (which also didn't get decRef called on it). Fixes cleanup of emote ImageSet and ImageSprite instances, as well as particle images.
2024-04-02General code cleanupsThorbjørn Lindeijer5-8/+6
* 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-26Use SDL2 support for color and system mouse cursorsThorbjørn Lindeijer3-20/+33
This way the cursor is not limited by the framerate nor affected by input lag. Also, when custom cursor is disabled, a few different system cursors are now used instead. It also avoids an issue on Wayland, where hiding the cursor (as done to render our own one) would cause the cursor to get locked within the window. On macOS it fixes two cursors being visible when hovering the window while it is in the background. The cursor can unfortunately no longer gently fade away.
2024-03-21Removed unused ResourceManager methodsThorbjørn Lindeijer2-43/+0
* ResourceManager::addResource * ResourceManager::get(const std::string &) These were once added in 32996cee607c52ecef9be4638df554dd89b39c24, but they are no longer necessary after the port to SDL2 (2c51c98625b225cecfb9628c30d62d4e30f7e3e1).
2024-03-21Removed the unused Image::mLoaded memberThorbjørn Lindeijer2-41/+19
2024-03-21Use std::function in ResourceManagerThorbjørn Lindeijer4-85/+35
Simplifies the code a little. Also use ResourceRef in SubImage to avoid manual reference counting.
2024-03-13Use snprintf instead of sprintfThorbjørn Lindeijer1-2/+2
Amendment of dd1db3753ecf8a4d782aee1f518759763d8caf87.
2024-03-12General code cleanupsThorbjørn Lindeijer10-34/+13
* Use default member initializers * Use range-based for loops * Avoid needless pointer references for ShopItem::mDuplicates * Removed type aliases that are only used once or twice * Removed more unused includes * Removed some unused functions * Removed superfluous .c_str() * Rely on default copy and assignment operators for Vector class * Use std::unique_ptr in some places * Removed duplicated mPlayerMoney updating in SellDialog * Removed duplicated Game::handleInput call * Removed unused SDLInput::mMouseInWindow * Removed remnant of manual widget positioning in HelpWindow * Removed superfluous initialization of static pointers
2024-03-07Some code simplifications in ResourceManager::loadFileThorbjørn Lindeijer1-16/+9
2024-03-07Fixed ambient layers "keepratio" optionThorbjørn Lindeijer3-10/+21
I had broken this in 264be2108c51837fa92085f6c839e66aebbcfc9e by no longer reading out the property. Made some further simplifications and two more fixes: * When the original image's size was not 800x600, it wouldn't get scaled as expected due to the integer division being performed before the multiplication. * I had changed the default resolution to 1280x720, while mKeepRatio expects to scale the original image as if it was displayed on an 800x600 screen. So now it's hardcoded on 800x600 rather than using the defaultScreenWidth/Height variables. * Removed the confusing x/y parameters from AmbientLayer::draw, which were actually set to the graphics width/height. * Changed SDLGraphics::drawRescaledImagePattern to not repeatedly set the source origin.
2024-03-07Use the native TMX tile animation formatThorbjørn Lindeijer4-105/+113
Rewrote the tile animation loading code based on XML tags, replacing the code that loaded tile animations from tile properties. Also made a number of code simplifications and optimizations: * Replaced a number of pointer members with value members. * Pass around Animation and TileAnimation by value, using std::move to avoid allocating copies. * push -> emplace * push_front -> emplace_front * push_back -> emplace_back * Use range-based for loops * Use std::vector instead of std::list for storing affected tiles (less fragmentation) * Avoid string copies and allocations while parsing CSV layer data. * Replaced xmlNodeGetContent with directly accessing 'content'.
2024-03-07Fixed tile animations for CSV mapsThorbjørn Lindeijer1-6/+3
The affected tiles were only tracked for base64-encoded layer data.
2024-03-06General code cleanupsThorbjørn Lindeijer7-54/+35
* Use final for all message handlers, Client, LocalPlayer, Being::getType, Being::setPosition and Being::setMap. (avoids some warnings about virtual dispatch in constructors) * Use auto in more places * Use emplace_back instead of push_back in some places * Use default member initializers * Less else after return * Removed superfluous .c_str() * Removed type aliases that are only used once * Removed more unused includes
2024-03-04Fixed character displayThorbjørn Lindeijer6-30/+47
This change fixes hair style to take into account "race", which makes the faces visible again. Hair colors should also be fixed now, with partial support for itemcolors.xml added. The Mana client now also supports per-character gender, and it now hides the hair style and color buttons on character creation, when there are none to choose from. Closes #43
2024-03-02Changed server type to "enum class"Thorbjørn Lindeijer2-2/+2
2024-03-02Added support for customizing NPC and Monster hover cursorThorbjørn Lindeijer4-16/+61
To match support for this in M+, since TMW uses this functionality on two of its NPCs.
2024-03-02Updated mouse cursors to latest versionThorbjørn Lindeijer2-4/+3
The new cursor types are not used yet for now.
2024-03-02General code cleanupsThorbjørn Lindeijer11-123/+71
* Don't needlessly store or return raw pointers in BeingInfo * Less copying, more moving * Less else after return * Make AddDEF a template instead of a macro * Removed some unused includes * Use range-based for loops
2024-02-27Added VSync and windowed fullscreen optionsThorbjørn Lindeijer2-1/+2
The configuration and setup UI were adjusted to the new options. This also fixes issues in applying new video settings. Default resolution was changed from 800x600 to 1280x720. VSync is enabled by default while FPS limit was disabled. Display aspect ratio for the resolution options. I had to work around some macOS issues: * Don't change window size when it appears to be "maximized", since it just changes the rendering area while leaving the window maximized. * Unset fullscreen display mode temporarily to allow changing resolutions, otherwise the rendering area no longer matches the screen and mouse input is also off. * Removed SDL_WINDOW_ALLOW_HIGHDPI for now because it causes issues on macOS, since we're not actually handling the scaling factor. A Video class and an SDLGraphics subclass were split off from Graphics. This setup has Less duplication and leaves the OpenGLGraphics and SDLGraphics better separated. Fixes #57 Fixes #58
2024-02-22General code cleanupsThorbjørn Lindeijer4-13/+7
* 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-19Updated PhysicsFS API usageThorbjørn Lindeijer1-9/+14
Unfortunately, since we're making a difference between config and data, and also want to know where to write screenshots, we can't get rid of PHYSFS_getUserDir entirely. We'd need a replacement to get rid of the deprecation warnings. Also removed copying of old config file at "/.tmw/config.xml".
2024-02-15Fix handling of non-consecutive emote IDsThorbjørn Lindeijer2-47/+37
Previous code was assuming there would be no gaps in the emote IDs. Also cleaned up some confusion where the "emote ID" being passed around in the code was often offset by 1. Now it is only offset in communication with tmwAthena and when saving the shortcuts.
2024-02-13Fixed music playbackThorbjørn Lindeijer2-21/+7
A faulty version check was disabling music loading entirely.
2024-02-13General code cleanupsThorbjørn Lindeijer7-40/+24
* 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-09C++11: Use default member initializersThorbjørn Lindeijer6-39/+24
This patch is not exhaustive.
2024-02-02Restored support for setting monster ID offset on monsters tagThorbjørn Lindeijer3-2/+16
Apparently this was supported before, but support for that was lost in bd1fdd87eed48ba3ffcc413936d6a6a60a429a97. Fixes #46
2024-01-29Removed unused includes in various filesThorbjørn Lindeijer5-13/+3
2024-01-29Removed remnants of alpha cache in ResourceManagerThorbjørn Lindeijer2-35/+0
Continuation of 2c51c98625b225cecfb9628c30d62d4e30f7e3e1, which had already removed most of the alpha cache in Image.
2024-01-29Apply C++11 fixitsThorbjørn Lindeijer11-80/+65
modernize-loop-convert modernize-deprecated-headers
2024-01-28Added support for map/layer maskThorbjørn Lindeijer4-27/+104
A custom "Mask" property on a layer or a "foregroundXmask" property on a map can now be used in combination with the SMSG_MAP_MASK to dynamically disable certain map layers from the server. Feature previously seen on ManaPlus and implemented for Mana client for compatibility. Also added a ResourceRef class for automating the Resource reference counting. Closes #44
2024-01-26Added fallback for XML data files and support absolute pathsThorbjørn Lindeijer1-14/+34
For compatibility with TMW, which has not yet adopted a central "settings.xml" that includes all the other files. Also, a "name" attribute with an absolute path is now supported in addition to the relative "file" attribute, since that is what ManaPlus supported. This resolves most of issue #43.
2024-01-26Apply C++11 fixitsThorbjørn Lindeijer36-155/+155
modernize-use-auto modernize-use-nullptr modernize-use-override modernize-use-using