Commit graph

132 commits

Author SHA1 Message Date
Edoardo Lolletti
0e6d4ed79a Rename delete_group_no_unref to delete_group 2025-05-30 23:09:28 +02:00
Edoardo Lolletti
b01f23bfa6 Make group::is_readonly a bool
It is no longer used as multiple values "boolean" to indicate a group not to be collected
2025-05-30 23:09:23 +02:00
Edoardo Lolletti
50a2b9ba22 Add initial draft of lua managed group lifetime 2025-05-30 23:09:22 +02:00
Edoardo Lolletti
640de69d6d Ensure that the Check/SelectWithSum functions don't receive groups with cards for which the operation value function returns 0
Prevents errors down the line due to overpaying since a card with sum_param of 0 will never contribute to the total and error out when the client sends a response
2025-04-25 11:57:30 +02:00
Edoardo Lolletti
b91dd7f752 Assert various warnings when compiling x64 with msvc 2024-04-15 22:39:25 +02:00
Edoardo Lolletti
a388095e1f Wrap luaL calls so that the lua stack has always at least 5 elements
Functions from the auxiliary library, assume the stack has always at least 5 empty slots, add macro ensure_luaL_stack to wrap every such call so that the stack is checked for enough free space beforehand. This will make mandatory to use the latest version of visual studio 2017 as minimum for windows (it was already being required for c++17 support regardless), as it needs the conformant c++ preprocessor option to be used.
2024-04-13 10:36:47 +02:00
Edoardo Lolletti
16add063f6 Remove check_param_count where redoundant
LUA_FUNCTIONs don't really need to check the amount of parameters to be at least 1, as that's implicitly checked by the mandatory first parameter being the lua_object itself
2024-02-25 15:55:53 +01:00
Edoardo Lolletti
e97a1c2f94
Restructure the processor handling to use a variant object (#149)
Rewrite the whole ``process`` function of the processor to use instead tag dispatching on variant objects.
Each single processor message got rewritten as a struct, inheriting from a base templated Process struct, containing only the required data for that process, rather than using the generic structure that ended up needing to spam bitwise operations to pack as many arguments in a byte as possible. This makes things easier to follow and streamlines the addition of new processes:
 - Define its struct with the parameters it expects by also providing a constructor
   - If the process requires an answer, inherit it from ``Process<true>``, if it requires no answer, inherit it from ``Process<false>``
 - Add such struct to the ``processors`` variant type
 - Declare and implement its corresponding ``bool process(Processors::NewProcess& arg);`` function
2024-01-08 20:46:41 +01:00
Edoardo Lolletti
ff41aec90a Update header inclusion 2024-01-05 13:03:46 +01:00
Edoardo Lolletti
da45f91460 Update copyright for 2024 2024-01-03 01:21:08 +01:00
Edoardo Lolletti
6dc321de75 Make LuaParamType an enum class 2023-12-08 19:55:50 +01:00
Edoardo Lolletti
cdb14fd115 Use lua_createtable instead of lua_newtable
Allows preallocating the needed size for its elements since they're known in advance
2023-12-08 12:30:10 +01:00
Edoardo Lolletti
cb5516a931 Rename get_card_or_group and lua_tostring_or_empty
Use the lua_get prefix for consistency with the other higher level lua getters
2023-12-03 11:34:38 +01:00
Edoardo Lolletti
e7315fa5a6 Cleanup Group.__band and Group.__add
Update the function used to retrieve the parameters and simplify its logic
2023-12-03 11:19:22 +01:00
Edoardo Lolletti
0b83c96055 Use get_card_or_group in Group functions 2023-12-03 10:27:47 +01:00
Edoardo Lolletti
90d2773278 Group.Remove: support excluding groups as well
So to have its behaviour in line with other functions
2023-12-03 10:26:44 +01:00
Edoardo Lolletti
5d233d8068 GetNext: Fix crash on an empty group after calling GetFirst 2023-12-02 12:04:35 +01:00
Edoardo Lolletti
f89c5da422 Update get_card_or_group to return a pair group/card
To then be unpacked with c++ 17's structured binding
2023-11-26 17:47:46 +01:00
Edoardo Lolletti
434b775193 C++17 constructs 2023-11-26 17:47:46 +01:00
Edoardo Lolletti
20fbf2d87e LUA_FUNCTION: directly pass pduel in the function scope
Update lua functions to already have the pduel parameter passed inside them, thus not needing to manually retrieve them in the functions.
Add also a yieldk macro that does the same thing but for the yield continuation function, removing the redoundancies
2023-11-25 11:15:21 +01:00
Edoardo Lolletti
420d5b6107 LUA_FUNCTION: directly pass "self" parameter referring to the object
Most of the library functions are used as "class member functions" where the first parameter is always the corresponding lua object, update the LUA_FUNCTION macro so that the functions already have a "self" parameter corresponding to the already parsed lua object.
Added a new LUA_STATIC_FUNCTION macro for functions that are to be called without an associated object
2023-11-21 11:56:23 +01:00
Edoardo Lolletti
d9474f0551
Update Duel.AnnounceRace and Duel.AnnounceAttribute to handle new race (#136)
Do the required changes to make Duel.AnnounceRace work with the new types and also any possible newly added type removing some hardcodings down the way and adding some extra checks, also apply the same updates to Duel.AnnounceAttribute
2023-04-23 21:34:36 +02:00
Edoardo Lolletti
e73fb449a8 Silence downcast warnings 2023-02-07 16:43:27 +01:00
Edoardo Lolletti
6cf08f7b9f Make Group.Clear and Group.KeepAlive return the group itself 2023-02-05 11:23:31 +01:00
Edoardo Lolletti
9ed9fed741 Fix wrong parameter index for Group.FromCards 2022-10-27 12:49:36 +02:00
Edoardo Lolletti
151a5b7f71
Add support for table arguments in function already accepting a variable number of parameters (#131)
Also update the IsSetCard function family to work with a table as parameter as well
2022-10-26 18:13:11 +02:00
Edoardo Lolletti
0d3efa4b92 Minor update to Group.Split
Avoid set copy
2022-10-25 15:40:48 +02:00
Edoardo Lolletti
6f96c907b9 Merge the behaviour of Group.FromCards and Group.CreateGroup 2022-10-19 15:07:05 +02:00
Edoardo Lolletti
2ce69cbf50 Update some instances where the usage of lua_gettop was unoptimal or redoundant
In loops don't reevaluate it each iteration, in some functions already checking the value before entering a specific codepath don't repeat the same check
2022-10-19 15:04:27 +02:00
Edoardo Lolletti
47195b63d9 Allow passing nils to Group.FromCards 2022-10-19 14:43:02 +02:00
Edoardo Lolletti
43d1a5866e Revert "Make Group.FilterCount no longer create temp sets"
This reverts commit 20b0ef47b9.
With this change, a group being iterated by FilterCount was subject to having the container being iterated being altered mid iteration by the filter function, thus invalidating the iterators and possibly crashing the core.
2022-09-29 19:46:15 +02:00
Edoardo Lolletti
0da44c3a1c Same change as before in other functions
Group.GetMinGroup, Group.GetMaxGroup, Group.GetSum, Group.GetClass, Group.GetClasCount
2022-08-27 16:59:47 +02:00
Edoardo Lolletti
19474fe17c Make Group.GetBinClassCount use 64 bit integers for its internal counter
Functions could return a 64 bit value, account for that
2022-08-27 16:49:51 +02:00
Edoardo Lolletti
7906088aa9 Add explicit check to see if a group is being removed from itself
Prevent this scenario 082229328b
2022-08-10 16:05:20 +02:00
Edoardo Lolletti
f255e1c883 Add helper lua_error function
Add this function marked as noreturn to avoid putting unreachable() after every luaL_error call
2022-06-23 11:47:00 +02:00
Edoardo Lolletti
b6550fd9d3 Use teh new function to retrieve function indices in lua apis
Use the new function that return "0" if the object is not a function so that the functions can automatically take advantage of the change in check_matching that skips the second type check each function call.
2022-06-11 12:59:38 +02:00
Edoardo Lolletti
e8e19acef0 SelectUnselect: support nil as second group 2022-05-15 17:05:45 +02:00
Edoardo Lolletti
d4f2ccb70d Remove redoundant check in SelectUnselect
By checking if the 2 containers are equal, and then checking again for intersection, in the worst case the containers are iterated twice
2022-05-15 16:53:46 +02:00
Edoardo Lolletti
8482872e40 Update Group.Match
Split it in different paths depending on the passed parameters instead of repeating the checks in the comparation function
2022-05-15 16:48:51 +02:00
Edoardo Lolletti
17f879c519 Update intersection check in SelectUnselect
Made it O(n1+n2) instead of O(n1*n2) by manually expanding the set intersection algorithm
2022-05-15 16:47:13 +02:00
Edoardo Lolletti
20b0ef47b9 Make Group.FilterCount no longer create temp sets 2022-05-15 16:40:16 +02:00
Edoardo Lolletti
fd66b5d8df Add Group GetBitwiseAnd and GetBitwiseOr
Functions that similar to Group.GetSum return the corresponding bitwise operation based on the values returned by the provided function
2022-05-15 16:08:07 +02:00
Edoardo Lolletti
3ba3d949a4 Add static asserts to ensure constexpr evaluation 2022-05-15 16:02:35 +02:00
Edoardo Lolletti
40bffb91c4 Update Group library to use new declaration 2022-05-15 16:02:35 +02:00
Edoardo Lolletti
a01e6119a8 Fix wrong bound check in Group.TakeatPos
Was checking for the index to be greater than rather than greater or equal thus allowing to dereference 1 past the end of the group.
2022-03-29 16:49:02 +02:00
Edoardo Lolletti
7aa943c122 Silence warning 2022-03-26 20:12:55 +01:00
Edoardo Lolletti
4da35cb7f1 Use preincrement operator instead of postincrement in the codebase
Semantically the proper operator to use for oneline increments is the preincrement one, the postincrement is the one to be used only in teh cases where the previous value is required.
2022-03-05 13:56:43 +01:00
Edoardo Lolletti
472e837e1f Add safety check when calling Group.GetNext with an invalid internal iterator. 2022-02-10 23:17:35 +01:00
Edoardo Lolletti
6fe72bab09 Remove all NULL usage
Use nullptr
2021-12-13 14:07:51 +01:00
Edoardo Lolletti
c1aa459ef5 Always retrieve the duel object form the lua state in continuation functions
Don't retrieve it from the ctx argument passed in the callback function
2021-12-05 14:28:21 +01:00