Comments (3)
Some analysis of FO2 built in parser:
- It stores data in a 2-level sorted dictionary (first level is section name => section, sections are key=>value pairs).
- Dictionaries use half division method to find values by key, which is O(log(n))
- When adding new key/value pair, they first find an index to place they key based on order, then shift elements from the end to the new index - O(n)
- Config parser supports comments after semicolon in section header as well as value (GetPrivateProfile** doesn't - it returns strings with the comment, which may break some existing script if for some dumb reason it relies on this "feature")
- Because it reads the file (txt or cfg) once, it should be much more efficient than current Sfall functions, even without the cost of reading from registry. Just by the fact that we save on disk IO operations.
So I suggest for ddraw.ini definitely only read Config once before init (and maybe dispose it after). For INI requests from scripts we should provide our own unordered_map<string, Config>
. If key not found, then use FO2 parser to parse the ini. Important to unload configs and clear this map on game reload (to be able to quickly iterate mod settings).
from sfall.
In all this excitement I forgot that scripts can write INI, not just read from it. This complicates matters somewhat, as FO parser can't write. And if you use parser like this to write, you will loose all of the comments. So for writing we have to:
- Use separate INI parser/writer only for writing that would be able to open file, find line in it (if it exists), and then write it, keeping comments intact if possible.
- Keep using WritePrivateProfileString function that already does that. Doesn't matter if it's inefficient as much, since current mods don't do INI writes often. But who knows, this may change.
from sfall.
Using config parser from the engine directly didn't work well. I was able to read data no problem, but I couldn't simply cache these configs (keep them for whole game session and call config_exit
on reload). There was a consistent memory access violation for some reason. I could just replace all memory allocation calls within config_*
and dictionary*
functions, but opted instead to re-implement these functions partially in normal C++. Seems to work perfectly so far for all ini reads, sfall and script.
For "set" functions, I went for option (2) from the last comment. For future I think it should be fairly straightforward to add a method to Config for writing strings directly into file:
- Limited to normal file system files.
- Partially reuse function for parsing the line.
- Preserve comment after value.
- Read file line-by-line and copy it (either to a tmp file or memory).
- When line to replace is found, write a modified version instead of the original.
- Write the rest of the lines.
- Delete and replace the original INI with the new one (or overwrite it from memory).
Possible optimization for this would be to place setString requests into a buffer within IniReader class. Then at the end of the frame or after some other delay, execute all string replacement in a file with one sweep.
from sfall.
Related Issues (20)
- Write conflicts HOT 3
- Memory access violation when putting weapon in hand slot [Debug]
- Some functions "pretend" to be "safe" while being unsafe HOT 2
- "string_format" metarule is inconsistent with sprintf opcode
- String truncation not working properly with new INI parser
- cannot open input file 'dinput.lib error. HOT 1
- Interpreter: Subtracting negative int value from a float value produces unexpected result HOT 2
- Add optional importing of variables/procedures
- Jinxed trait inherits from player character to party members when party control is on HOT 1
- Exclude pariah dog from party control when combat control is on HOT 3
- [Feature Request] Two Column Inventory. HOT 4
- list of quest catagory name
- Add opcode for 'register_object_animate_and_move_straight_"
- Prevent game lock during combat with "reg_anim_animate_forever"
- LOADSAVE: ** Error reading load function #3 data! ** HOT 3
- Add an option to chainload cnc-ddraw. HOT 88
- OBJ_DATA_WHO_HIT_ME value changes from 0 to -1 when map is entered again HOT 6
- A new weapon like the Molotov Cocktail? HOT 3
- (4.4.3) Random freezes HOT 1
- Game permanently freezing with RPU and latest sfall HOT 14
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 sfall.