-
Notifications
You must be signed in to change notification settings - Fork 26
Add controller "get" command #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Looks good. Would you please be so nice to put your API description into a file instead of only mentioning it in the PR description? |
I added documentation for the drawer controller's digilines functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested using a mesecons luacontroller.
DRAWER = "AA"
if event.type == "program" then
digiline_send(DRAWER, {command = "get", count = 9 })
print("Sent!")
end
if event.channel == DRAWER then
-- Callback
print(event.msg)
end
- 1x Lua controller
- 1x drawers controller
- 2x drawers
Will merge in a few days unless there are objections.
This approach sounds fine, it limits digiline dataload. I haven't been able to read and test the actual code yet.
|
@SwissalpS The code in the PR does not re-index a drawer network for each |
The code of this PR isn't using the cached index I have concerns that this can easily be used to bring a server to a crawl. |
The keys of the cached table index are item names, and this PR aims to provide information about each individual drawer. If two drawers contain the same item, the cached table index will only store one of those drawers, whereas the "get" command would return both of them. If the table index approach in #100 was implemented then this PR could use it instead, but for now, the cached table index doesn't provide enough information for the "get" command. |
Not merging until the cache topic is resolved. @SwissalpS As of now, the One improvement that I would consider is to replace |
When re-writing this mod to not use entities to store data I found that a lot of time is spent when serializing the network table. I was looking at options to also fix the updating issue. I'm not sure from memory if I ever finished testing which method would be fastest. My recollection hints that I was going to go for an in memory cache that is rebuilt after every reboot as areas get loaded. Similar to how [technic.plus] indexes it's networks. Short: I suggest caching in memory and updating on tube take/put events as well as manual take/put actions. |
I implemented a DFS with a The drawer controller should know if any of these events have occurred when a "get" command is sent to it. This DFS implementation should significantly speed up the process of finding all connected drawers within range, not only for the "get" command but for drawer indexing as well. I believe that further changes to how the drawer index is interpreted are out of the scope of this PR. |
for name, _ in pairs(core.registered_items) do | ||
if core.get_item_group(name, "drawer") > 0 or core.get_item_group(name, "drawer_connector") > 0 then | ||
drawer_content_ids[core.get_content_id(name)] = true | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should run in on_mods_loaded
, in case further registrations follow after this code is executed.
if visited[index] then return end | ||
visited[index] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could set data[index] = nil
to mark it as done.
elseif content_id ~= controller_content_id then | ||
return | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think all controllers should be traversed. From what I can see, the previous code did not do that.
If you need this as a start condition, then perhaps pass a 2nd (optional) argument to dfs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, should I traverse only one drawer controller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, otherwise players can make bigger networks than the max radius.
@@ -1,0 +1 @@ | |||
drawers.controller_max_matches (Maximum controller request matches) int 50 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A description that this is about digilines might be helpful to the player/user.
It would be great to benchmark at least the time used for version before and after the VManip and other changes to make sure these actually do improve the performance time-wise. |
Implements #96. Send a table to a drawer controller and receive information on all drawers in its network:
command
(string) -"get"
offset
(integer) - Used to paginate the results if the amount of drawers in the network exceedsdrawers.CONTROLLER_MAX_COUNT
. Defaults to 1.max_count
(integer) - Must be between 1 andCONTROLLER_MAX_COUNT
. Defaults toCONTROLLER_MAX_COUNT
. Maximum amount of drawers to return.Feel free to respond with suggestions for improvement.
Example Response