Giter Club home page Giter Club logo

Comments (3)

phobos2077 avatar phobos2077 commented on June 17, 2024 1

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.

phobos2077 avatar phobos2077 commented on June 17, 2024

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:

  1. 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.
  2. 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.

phobos2077 avatar phobos2077 commented on June 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.