Comments (5)
Great analysis. I know a bit more about the inner workings of factorio serialization, so I'll clarify where I can.
This appears to be fine when handling LuaEntity references; I guess this is because the game can properly (de)serialize those and always returns the same references from global data and surface queries. but I don't know for sure.
Yes, this is exactly how it works. If you save a reference to a LuaEntity, and then compare the saved reference in a loaded-save against a newly retrieved reference (say from surface.find_filtered_entities
), and the entities are the same, the references will also be same. There is definitely back-end logic keeping these all in sync in Factorio. It is safe to assume references will never change.
However, the Trains.to_entity method above always returns a new table, so the references will never match.
Yep. Fuax-references won't work unless we also persisted them, which would be a lot of overhead. Also persisting faux-references would leak memory as we could never tell when to deference and free the memory, as there is no way to tell when a train when it was 'dead' or not. I agree this is not the best approach.
To that end, I would propose making a slight change to the Entity module to have it call an equals method on the input entity if there is such a method and the entity references don't match.
Makes sense to me. All your proposed code & changes look good. I would make on additional suggestion, on top of what you already have, to provide helper-methods to cut down on the verbosity a bit:
function Trains.set_data(train, data)
return Entity.set_data(Trains.to_entity(train), data)
end
function Trains.get_data(train)
return Entity.get_data(Trains.to_entity(train))
end
Look forward to reading your PR.
from factorio-stdlib.
Hi Afforess,
This isn't forgotten. Unfortunately. work stuff has come up, and reduced the time and effort I can put in to this.
from factorio-stdlib.
As far as I am concerned, this is covered and completed by #50, @AndyBursh if you disagree, feel free to let me know.
from factorio-stdlib.
I'm 50/50 on it being complete. I haven't yet implemented, or put any thought in to, handling train id changing events within the module. The idea there would be to perform the book keeping necessary to make sure data is always associated with the lead engine. That said, I'm not even convinced that's a job for a library and not an application-specific behaviour
from factorio-stdlib.
@Afforess Would you rather discuss this in a separate issue, or reopen this one?
from factorio-stdlib.
Related Issues (20)
- Upgrade Readme and Wiki HOT 2
- To Do List
- Data.Util.Duplicate on normal/expensive recipes HOT 6
- Wiki with list of functions and their functionalities HOT 2
- Recipe:clear_ingredients error HOT 5
- Small errors found with trains/events HOT 6
- add_ingredient issue HOT 8
- 0.18 support? HOT 1
- remove_prereq nullifies prerequisites value of technology table.
- errors found with trains/events
- add_ingredient cant find items that are modules
- Event handler filter is ignored if more than one event ID is specified in `register`
- spidertron-remotes aren't checked as "items" so a recipe result (and more) may fail to find one HOT 1
- documentation broken HOT 2
- Event.register not passing pattern to function HOT 1
- Inconsistency of technology pack methods
- Gui events not working HOT 1
- String.contains doesn't work with strings that contain a hyphen.
- Question: Which tool can be used to interpret the code documentation in VSCode
- This does not look right: return (Area.size(Area)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factorio-stdlib.