summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-04Added logging priorities and use SDLs logging facilitiesThorbjørn Lindeijer1-9/+9
By using SDL logging, we can rely on SDL to filter the log messages by their priority before they get sent to our custom output function. For example, we now no longer get entries for created and destroyed Window instances by default, since these have only "debug" priority whereas the default priority for the "app" category is "info". We can also get log messages raised by SDL itself in our log now. Log levels can be controlled per category through the "SDL_LOGGING" environment variable. Many existing log messages have been assigned a category based on their existing prefix.
2025-03-01Fixed leaking of resources referenced by resourcesThorbjørn Lindeijer1-6/+8
While cleaning up resources on shutdown, the resources they in turn referenced (like an Image referenced by an ImageSet) ended up in mOrphanedResources. Since the orphaned resources were only taken into account once, a lot of remaining orphans never got deleted. Technically a non-issue because it leaked on shutdown only, but it resulted in many faulty log entries about resources still being referenced as well as much noise from memory leak detectors.
2025-02-26Use ResourceRef for all resource typesThorbjørn Lindeijer1-73/+37
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-20Fixed stutter when new music starts playingThorbjørn Lindeijer1-1/+10
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 Lindeijer1-138/+3
* 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-68/+67
* 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.
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-04-08Use ResourceRef<Image> in more placesThorbjørn Lindeijer1-4/+9
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-03-26Use SDL2 support for color and system mouse cursorsThorbjørn Lindeijer1-5/+10
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 Lindeijer1-24/+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-21Use std::function in ResourceManagerThorbjørn Lindeijer1-74/+31
Simplifies the code a little. Also use ResourceRef in SubImage to avoid manual reference counting.
2024-03-07Some code simplifications in ResourceManager::loadFileThorbjørn Lindeijer1-16/+9
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-01-29Removed remnants of alpha cache in ResourceManagerThorbjørn Lindeijer1-22/+0
Continuation of 2c51c98625b225cecfb9628c30d62d4e30f7e3e1, which had already removed most of the alpha cache in Image.
2024-01-29Apply C++11 fixitsThorbjørn Lindeijer1-3/+2
modernize-loop-convert modernize-deprecated-headers
2024-01-26Apply C++11 fixitsThorbjørn Lindeijer1-30/+30
modernize-use-auto modernize-use-nullptr modernize-use-override modernize-use-using
2012-02-09Fixed wallpaper prescaling issuesThorbjørn Lindeijer1-4/+24
Image::SDLgetScaledImage was changed so that it tries to find an existing scaled version of the image first, and generates it when none exists. When it needs to generate one, this resource is added to the resource manager, partly to avoid duplicating the work later but mainly to keep memory management straightforward. This function also used to leak the scaled SDL_Surface since it wrongly assumed that Image::load would free it. To avoid filling up the memory with scaled wallpapers that are waiting 30 seconds until they will be deleted, the Resource::decRef function was extended with a parameter that allows telling it what to do with orphans. Calling decRef with Resource::DeleteImmediately will delete the resource immediately in case the resource is orphaned. Reviewed-by: Yohann Ferreira
2012-01-26Updated copyrights to 2012Thorbjørn Lindeijer1-1/+1
2012-01-24Use SDL_RWops directly on top of PhysFSThorbjørn Lindeijer1-23/+14
This avoids the creation of a temporary buffer containing a complete file for the sole purpose of wrapping it up in an SDL_RWops. The necessary wrapper is by Ryan C. Gordon and is included in the PhysFS repository under 'extras'. Reviewed-by: Yohann Ferreira
2010-10-16Implement opacity cache for SDL surfaces.Andrei Karas1-0/+15
Enabled by default. Can be disabled in configuration option "alphaCache" if set it to 0. Reviewed-by: Bertram
2010-08-13Simplify handling of compressed filesJared Adams1-9/+36
ResourceManager will now check for ".gz" and act appropriately (unless told not to). Compression handling functions are now in new utils/zlib files, along with a function to load a file from drive, uncompressing it if it ends in ".gz". Reviewed-by: Freeyorp
2010-05-21Fix some issues found by CppcheckJared Adams1-1/+5
2010-02-28Make the gui more themeable and distribute two themesJared Adams1-1/+2
The older gray theme and the new wood theme are available as themes. The gray theme needs some new graphics for hilights. Add a theme option for branding and add path/to/branding/data to the PhysFS search path. Reviewed-by: Thorbjørn Lindeijer Reviewed-by: Chuck Miller
2010-02-22Modify copyright headersFreeyorp1-1/+2
2010-02-20License header update for The Mana ClientThorbjørn Lindeijer1-4/+3
2010-02-07Updated Copyright year to 2010!Bertram1-1/+1
Also added the update copyright tool from the Wormux Team. ( And not forgetting credit's due. :P )
2010-01-12Standardize header orderJared Adams1-3/+5
Also remove some extra new lines and fix eAthena's PartyTab define guards.
2010-01-10Change code styleAndrei Karas1-3/+6
2009-07-24Made the wallpaper be rescaled when necessary under SDL and OpenGL.Bertram1-0/+13
The SDL methods to rescale the wallpaper has been optimized to permit rescaling at load time while OpenGL draws directly rescaled. Does someone know how to smooth the rescaled image under OpenGL?
2009-04-18Don't leak the music file after copying itBjørn Lindeijer1-1/+3
2009-04-16Renamed ResourceManager::moveFile to ResourceManager::copyFile and catched ↵Philipp Sehmisch1-1/+1
error when it fails.
2009-04-16Added support for playing music in zip files.Philipp Sehmisch1-0/+26
2009-03-27Fixed include structure in resource/ directoryBjørn Lindeijer1-10/+11
There is also a new rule that trivial constructors and destructors should no longer be trivially "documented", since this just takes up space with no gain.
2009-03-25A host of code style fixesBjørn Lindeijer1-1/+1
Mostly putting & and * in the right place and making some getters const.
2009-02-15Removed unnecessary parenthesis at constructorsBjørn Lindeijer1-1/+1
When not passing any parameters to constructors, there is no reason for using parenthesis.
2009-02-11Removed many pointless comparisons with NULLBjørn Lindeijer1-1/+1
Sometimes it's nice for clarity, but most of the time this is just clutter. C++ != Java. :)
2009-02-10Merge branch 'aethyra/master'Bjørn Lindeijer1-1/+1
Conflicts: docs/FAQ.txt packaging/windows/make-translations.vbs src/Makefile.am src/gui/colour.cpp src/gui/colour.h src/gui/popupmenu.cpp src/gui/setup_colours.h src/main.cpp src/main.h src/resources/resourcemanager.cpp src/text.cpp src/text.h src/textmanager.cpp src/textmanager.h
2009-02-09Changed AETHYRA_DATADIR to PKG_DATADIR.Ira Rice1-1/+1
Signed-off-by: Ira Rice <irarice@gmail.com>
2009-02-09Merged with Aethyra master as of 2009-01-27Bjørn Lindeijer1-10/+7
Conflicts: Almost everywhere.
2009-01-23Removed unnecessary references to The Mana World in code headersBjørn Lindeijer1-4/+4
This dates back to the old days of TMW, but the usage instructions of GPLv2 don't mention this being necessary. Since it doesn't add anything, avoid the branding in these sections.
2009-01-23Removed unnecessary references to The Mana World in code headersBjørn Lindeijer1-4/+4
This dates back to the old days of TMW, but the usage instructions of GPLv2 don't mention this being necessary. Since it doesn't add anything, avoid the branding in these sections.
2009-01-19Fixed a directory creation error reported by our Windows users (whyIra Rice1-2/+2
doesn't PhysFS handle this properly?!?) when there's already an update directory. Also fixed the recorder class so that it's fixed on Windows as well. Signed-off-by: Ira Rice <irarice@gmail.com>
2009-01-15Style cleanups throughout most of the code. Splitting function type fromIra Rice1-2/+1
the function names should no longer be around. Signed-off-by: Ira Rice <irarice@gmail.com>
2009-01-04Code reformattingBjørn Lindeijer1-6/+6
Mainly making sure 'const std::string &' is used everywhere instead of 'std::string const &'. The former has always been the preferred order in this project. (cherry picked from mainline)
2008-12-08Code reformattingBjørn Lindeijer1-31/+18
I wish I had never fallen for this weird style, and I hope removing it will prevent others from introducing new code like this. :-)
2008-12-08Code reformattingBjørn Lindeijer1-33/+20
I wish I had never fallen for this weird style, and I hope removing it will prevent others from introducing new code like this. :-)
2008-11-30Delete resources after removing from the orphan list, to avoid double frees ↵Fate1-1/+1
during recursion
2008-11-23Delete resources after removing from the orphan list, to avoid double frees ↵Fate1-1/+1
during recursion
2008-11-18Pedantic fixes to the client, where I alphabetized all of the include Ira Rice1-8/+4
statements, as well as removing the new skill dialog, which we do not, nor will we use (if we do, it'd be a new one that we'd make). WARNING!!! This, and all other previous builds have a linker error for the Gnome libraries version 4.3.2 on my setup. It's assumed that this is also the case for other users of this library as well. I'm currently assuming that there's a bug in the compiler itself, and will look into reporting this, but in the mean time, it doesn't build for these users, unfortunately. Sorry about this.
2008-11-16Got rid of CVS/Subversion $Id$ markersBjørn Lindeijer1-2/+0
I don't know why we dealt with these things for so long. Did we ever get anything out of it?