Refactor: store special exits and their lock status separately#4526
Conversation
This will enable some simplification of code. During development it became clear that the Lua API `getSpecialExits(...)` function was a bit defective and did not behave as documented in the Wiki: it was only showing one special exit at random that led to a particular exit room in the (admittedly unlikely) event of there being more than one. It also used the special exit name/command as a key in a sub-table with the special exit lock status of that exit as a "0" or "1" string value. This PR repairs the above function by adding an optional boolean argument that: * if omitted or false, replicates the previous behaviour but if there is more than one special exit to the same room it always picks one with the lowest exit weight that is unlocked or if there is none it picks one with the lowest weight that is locked. This will be compatible with old scripts. * if true, returns ALL the exits in the sub-table that lead to the particular room id that is the key in the main table, again those exit commands are the keys with a value being a "0" or "1" depending on whether the exit is unlocked or locked respectively. For the record, the original implementation of special exits was introduced in commit: e0ba28d and that was supported by the addition of map format version 6. Locking of Special Exits was added in somewhere between: 19f8563 and: 070912e (which revised the map format to 11). Also: * use a couple of `const QString`s as templates in the `dlgRoomExit.cpp` file to remove 95 duplicated `QStringLiterals` from the read-only code segment of the compile object file. * add `const` where relevant to some `TRoom` methods. * work harder to ensure than when a special exit is deleted from a `TRoom` then elements that were related to it are also cleaned up. * prepare to save the new `TRoom` data structures in the next Mudlet map file format (21) when it is enabled. In the meantime a workaround to convert the in-game data to the current format is utilised for all current map formats Mudlet can currently use. This will impact a little on the save/loading speeds but that is the cost of simplifying the code that works with special exits elsewhere in the application. * revise and extend the error handling for the room special exit functions generally so that they confirm to our throwing an error on argument type issue (and reporting the faulty argument) and returning `nil` plus an error message for a run-time value problem. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
Cause a build failure but only in some (Clang) compilers: "Error: /Users/runner/work/Mudlet/Mudlet/src/TLuaInterpreter.cpp:5382:97: error: cannot pass object of non-trivial type 'QString' through variadic function; call will abort at runtime [-Wnon-pod-varargs] in: lua_pushfstring(L, "the special exit name/command \"%s\" does not exist in room id %d", dir, fromRoomID); Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
src/T2DMap.cpp
Outdated
| qWarning(R"(T2DMap::slot_customLineProperties() - WARNING: missing command "%s" from custom lines for room id %i)", | ||
| qPrintable(exit), room->getId()); | ||
| } | ||
| qWarning().noquote().nospace() << "T2DMap::slot_customLineProperties() WARNING - missing command \"" << exit << "\" from custom lines for room id " << room->getId(); |
There was a problem hiding this comment.
I am not sure what this error message actually means
There was a problem hiding this comment.
Haven't looked at the surrounding code but I'd expect that to mean that one or more of the customExitLine(|Style|Color|EndsInArrow) QMaps has a key that is NOT an exit - from what I recall of looking through the code it didn't always clear out those details when an exit in a particular direction was removed,,,,
There was a problem hiding this comment.
Ah ok, can you clarify the message to be better?
There was a problem hiding this comment.
Changed to:
qWarning().noquote().nospace() << "T2DMap::slot_customLineProperties() WARNING - missing no exit \"" << exit << "\" to be associated with a custom exit line with that designation in room id " << room->getId();|
|
||
| bool showAllExits = false; | ||
| if (lua_gettop(L) > 1) { | ||
| if (!lua_isboolean(L, 2)) { |
There was a problem hiding this comment.
I think it is better to be consistent in how we deal with bad functions: create a getSpecialExits1 rather than complicating the code, and usage, of the original.
There was a problem hiding this comment.
It turns out that due to insufficient testing data I didn't find out that the output being displayed (from using lua display(getSpecialExits()) was not as wrong as I thought - because I had chosen 1, 2, 3 as three different special exit room ids the list format output from display(...) which did NOT show the keys was correct. The only defect was that for multiple special exits with the same destination it just listed ONE of them at random. So the fix - to show (one of) the best (unlocked and lowest exit weighting) one is entirely backwards compatible when the existing function is used as is...
All that needs to be done is to fix the detail of the example code and to add a warning that:
"In the corner case where there is more than one special exit from this room to the same destination room, only one room is shown chosen at random prior to Mudlet 4.y.z - after that point only the best, in terms of being unlocked and of lowest exit weighting (or one of the best if there is a tie) special exits to that room is listed unless the optional
trueargument is given which will cause all of them to be listed."
| } | ||
|
|
||
| void TRoom::setId(int _id) | ||
| void TRoom::setId(const int roomId) |
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
📚 Wiki updated to match: https://wiki.mudlet.org/w/Manual:Mapper_Functions#getSpecialExits . |
|
Although "This branch has no conflicts with the base branch" it will clobber #4546 - but that is only a draft at this point so I can sort the clash out shortly... |
Since Mudlet#4526 was merged into the development branch 4 days ago reading of maps will LOCK ALL special exits and for really old formats (prior to 11) will chop the first letter of the special exit name/command each time the file is loaded... This was caused by a copy-paste area in the code the regenerated the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Since Mudlet#4526 was merged into the development branch 4 days ago reading of maps will prepend a '0' before the first letter of the special exit name/command for every special exit that is NOT locked each time the file is loaded... This was caused by a copy-paste area in the code the regenerated the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Since Mudlet#4526 was merged into the development branch 4 days ago reading of maps will prepend a '0' before the first letter of the special exit name/command for every special exit that is NOT locked each time the file is loaded... This was caused by a copy-paste area in the code the regenerated the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Since Mudlet#4526 was merged into the development branch 4 days ago reading of maps will prepend a '0' before the first letter of the special exit name/command for every special exit that is NOT locked each time the file is loaded... This was caused by a copy-paste error in the code the regenerated the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Since Mudlet#4526 was merged into the development branch 4 days ago reading of maps will prepend a '0' before the first letter of the special exit name/command for every special exit that is NOT locked each time the file is loaded... This was caused by a copy-paste error in the code that converted the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Since Mudlet#4526 was merged into the development branch 4 days ago reading of old maps (formats *before* *8*) built from Mudlet prior to 8e0f9db (merged on 2011/01/24) will chop the first character from the name/command of every special exit... This was caused by a copy-paste error in the code that converted the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
…ad (#4574) Since #4526 was merged into the development branch 4 days ago reading of old maps (formats before 8) built from Mudlet prior to 8e0f9db (merged on 2011/01/24) will chop the first character from the name/command of every special exit... This was caused by a copy-paste error in the code that converted the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
This is an error that slipped in as a result of Mudlet#4526 and resulted in the exit room id being stored as the special exit name in the BGL graph that is built for the A* search algorithm to work on. Consquently if that route was used in a path the special exit command produced for that step was garbage which also tripped off warnings about invalid characters being sent to the MUD as an exit direction. Thanks to @ryanstadther for bringing this to my attention! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
This is an error that slipped in as a result of #4526 and resulted in the exit room id being stored as the special exit name in the BGL graph that is built for the A* search algorithm to work on. Consquently if that route was used in a path the special exit command produced for that step was garbage which also tripped off warnings about invalid characters being sent to the MUD as an exit direction. Thanks to @ryanstadther for bringing this to my attention! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
…t#4526) This will enable some simplification of code. During development it became clear that the Lua API `getSpecialExits(...)` function was a bit defective and did not behave as documented in the Wiki: it was only showing one special exit at random that led to a particular exit room in the (admittedly unlikely) event of there being more than one. It also used the special exit name/command as a key in a sub-table with the special exit lock status of that exit as a "0" or "1" string value. This PR repairs the above function by adding an optional boolean argument that: * if omitted or false, replicates the previous behaviour but if there is more than one special exit to the same room it always picks one with the lowest exit weight that is unlocked or if there is none it picks one with the lowest weight that is locked. This will be compatible with old scripts. * if true, returns ALL the exits in the sub-table that lead to the particular room id that is the key in the main table, again those exit commands are the keys with a value being a "0" or "1" depending on whether the exit is unlocked or locked respectively. For the record, the original implementation of special exits was introduced in commit: e0ba28d and that was supported by the addition of map format version 6. Locking of Special Exits was added in somewhere between: 19f8563 and: 070912e (which revised the map format to 11). Also: * use a couple of `const QString`s as templates in the `dlgRoomExit.cpp` file to remove 95 duplicated `QStringLiterals` from the read-only code segment of the compile object file. * add `const` where relevant to some `TRoom` methods. * work harder to ensure than when a special exit is deleted from a `TRoom` then elements that were related to it are also cleaned up. * prepare to save the new `TRoom` data structures in the next Mudlet map file format (21) when it is enabled. In the meantime a workaround to convert the in-game data to the current format is utilised for all current map formats Mudlet can currently use. This will impact a little on the save/loading speeds but that is the cost of simplifying the code that works with special exits elsewhere in the application. * revise and extend the error handling for the room special exit functions generally so that they confirm to our throwing an error on argument type issue (and reporting the faulty argument) and returning `nil` plus an error message for a run-time value problem. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
…ad (Mudlet#4574) Since Mudlet#4526 was merged into the development branch 4 days ago reading of old maps (formats before 8) built from Mudlet prior to 8e0f9db (merged on 2011/01/24) will chop the first character from the name/command of every special exit... This was caused by a copy-paste error in the code that converted the older style of storing the special exits and their locked status that was used prior to that PR. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
…#4722) This is an error that slipped in as a result of Mudlet#4526 and resulted in the exit room id being stored as the special exit name in the BGL graph that is built for the A* search algorithm to work on. Consquently if that route was used in a path the special exit command produced for that step was garbage which also tripped off warnings about invalid characters being sent to the MUD as an exit direction. Thanks to @ryanstadther for bringing this to my attention! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
This will enable some simplification of code.
During development it became clear that the Lua API
getSpecialExits(...)function was a bit defective and did not behave as documented in the Wiki: it was only showing one special exit at random that led to a particular exit room in the (admittedly unlikely) event of there being more than one. It also used the special exit name/command as a key in a sub-table with the special exit lock status of that exit as a "0" or "1" string value. Edit: which does not correspond to the current documentation!This PR repairs the above function by adding an optional boolean argument that:
For the record, the original implementation of special exits was introduced in commit: e0ba28d and that was supported by the addition of map format version 6. Locking of Special Exits was added in somewhere between: 19f8563 and: 070912e (which revised the map format to 11).
Also:
const QStrings as templates in thedlgRoomExit.cppfile to remove 95 duplicatedQStringLiteralsfrom the read-only code segment of the compile object file.constwhere relevant to someTRoommethods.TRoomthen elements that were related to it are also cleaned up.TRoomdata structures in the next Mudlet map file format (21) when it is enabled. In the meantime a workaround to convert the in-game data to the current format is utilised for all current map formats Mudlet can currently use. This will impact a little on the save/loading speeds but that is the cost of simplifying the code that works with special exits elsewhere in the application.nilplus an errormessage for a run-time value problem.Signed-off-by: Stephen Lyons slysven@virginmedia.com