RFC: Add db:: accessor for LDB and LMT data
Depends on: https://github.com/EasyRPG/liblcf/pull/384
Fix: #2281
This is a new interface to access the lcf database and treemap from all Player code.
Essentially we will change from this:
auto& actors = lcf::Data::actors;
auto* actor = lcf::ReaderUtil::GetElement(actors, 1);
To this
auto& actors = db::Actors();
// Assumed id is always valid, asserts in debug build
auto& actor = db::Get(actors, 1);
// Requires you to check the pointer for validity
auto* actor = db::GetPtr(actors, 1);
// Like before, but also logs a warning if id is invalid
auto* actor = db::GetPtr(actors, 1, "MyFunction");
The reasons for changing this interface are:
- The database singleton is now part of player code and not lcf
- Enables us refactor player before removing
lcf::Dataand all singletons from liblcf. - More concise name
db:: - Potentially faster compile speeds. Including
db.hdoesn't bring in any lcf/rpg headers, only forward declarations.
I'm posting this for review on the interface. Once everyone is on board with the design, I'll add commits to this porting Player code to use the new interface. Need to avoid rebase hell on this one.
Imo this looks fine. The Editor code is also already written in such a way that there is no global access anymore. What I would suggest here:
- [x] Merge all other PRs first (obviously) ;)
- [ ] Convert one class (e.g. Actors) first as a "playground"
- [ ] When the interface is decided after playing around change the rest
- [ ] Remove lcf global instances (needs changes to LDB/LMT loading)
Closing this due to lack of interest and progress. Please reopen when there are any updates.