Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to handle config files?  (Read 4420 times)

0 Members and 1 Guest are viewing this topic.

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
How to handle config files?
« on: May 03, 2014, 02:45:41 am »
So I've been wondering how to handle config files. I looked through various games' config files. Saw some were .ini others were .xml and some .dat

What I don't understand is when I changed configurations meant for gameplay it wouldn't take affect. I'm not quite sure I understand why. But then there's the setting config files which did work if I changed them.

For example divekick has gems which it has an xml config file for text that appears. But changing the text in that file doesn't change anything. So I'm kind of wondering, what's the point of these xml, ini, dat, etc. files if they don't actually change anything?

GemText.xml
<?xml version="1.0" encoding="utf-8" ?>
<gemText>
        <DiveGem>
                <jumpEffect>+20% JUMP</jumpEffect> <!-- I changed this from +10% JUMP -->
                <kickEffect></kickEffect>
                <meterEffect></meterEffect>
                <bonusEffect></bonusEffect>
        </DiveGem>
        <KickGem>
                <jumpEffect></jumpEffect>
                <kickEffect>+10% KICK</kickEffect>
                <meterEffect></meterEffect>
                <bonusEffect></bonusEffect>
        </KickGem>
        <StyleGem>
                <jumpEffect></jumpEffect>
                <kickEffect></kickEffect>
                <meterEffect>+10% METER</meterEffect>
                <bonusEffect></bonusEffect>
        </StyleGem>
        <ManlyGem>
                <jumpEffect>+10% JUMP</jumpEffect>
                <kickEffect>+10% KICK</kickEffect>
                <meterEffect>+10% METER</meterEffect>
                <bonusEffect>BEGIN MATCH WITH CONCUSSION</bonusEffect>
        </ManlyGem>
        <PumpedGem>
                <jumpEffect></jumpEffect>
                <kickEffect></kickEffect>
                <meterEffect></meterEffect>
                <bonusEffect>BEGIN MATCH WITH 30% METER</bonusEffect>
        </PumpedGem>
        <AdvancedDiveGem>
                <jumpEffect>+20% JUMP</jumpEffect>
                <kickEffect>-10% KICK</kickEffect>
                <meterEffect></meterEffect>
                <bonusEffect></bonusEffect>
        </AdvancedDiveGem>
        <AdvancedKickGem>
                <jumpEffect>-10% JUMP</jumpEffect>
                <kickEffect>+20% KICK</kickEffect>
                <meterEffect></meterEffect>
                <bonusEffect></bonusEffect>
        </AdvancedKickGem>
        <AdvancedStyleGem>
                <jumpEffect>-10% JUMP</jumpEffect>
                <kickEffect>-10% KICK</kickEffect>
                <meterEffect>+20% METER</meterEffect>
                <bonusEffect></bonusEffect>
        </AdvancedStyleGem>
        <ManliestGem>
                <jumpEffect>+30% JUMP</jumpEffect>
                <kickEffect>+30% KICK</kickEffect>
                <meterEffect>+20% METER</meterEffect>
                <bonusEffect>PERSONAL SUDDEN DEATH</bonusEffect>
        </ManliestGem>
        <AdrenalineGem>
                <jumpEffect></jumpEffect>
                <kickEffect></kickEffect>
                <meterEffect>-50% METER</meterEffect>
                <bonusEffect>BEGIN MATCH IN KICKFACTOR</bonusEffect>
        </AdrenalineGem>
</gemText>

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to handle config files?
« Reply #1 on: May 03, 2014, 03:26:07 am »
For your question about that game: since root node is called 'gemText' and it doesn't look friendly enough (engine would still have to parse that plus, then number, then discard % and rest of the string etc. after already parsing xml) I'm guessing it's simply text for GUI/Tooltip/Tutorial/Whatever and not actual statistics of these items.
As for the main 'question': I'm not sure what you are asking, are you asking for pros and cons of various formats or personal opinions/experience or something else?
« Last Edit: May 03, 2014, 03:29:42 am by FRex »
Back to C++ gamedev with SFML in May 2023

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: How to handle config files?
« Reply #2 on: May 03, 2014, 05:17:50 am »
Yeah I thought it would change text somewhere in the game but I didn't see anything change. I've tried other files that seemed like it would have affect on the actual gameplay as well and nothing changed.

I guess I would like to know pros and cons for having config files that seem to store data for characters, enemies, and other stats in a game. Also, people's personal opinion on what they would do for config files, would they just use an ini file to store the settings or would they use text files for more than just settings?


Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How to handle config files?
« Reply #3 on: May 03, 2014, 07:29:41 am »
Personally I use libconfig ( http://www.hyperrealm.com/libconfig/ ) most of the time.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to handle config files?
« Reply #4 on: May 03, 2014, 05:39:42 pm »
For simple stuff that is read only I use Lua, for read and write complex stuff (including game data too) I'll use pugixml or roll my own that is tightly fitted to what I need.
Back to C++ gamedev with SFML in May 2023

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: How to handle config files?
« Reply #5 on: May 07, 2014, 04:32:24 am »
I'm not sure I understand what you mean by read only. What kind of things are read only and what kind of data would need to be read write?

The only thing that comes to mind for read write would be save files.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to handle config files?
« Reply #6 on: May 07, 2014, 07:51:24 am »
Configuration is read/write, too, if you want the user settings to be persistent.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: How to handle config files?
« Reply #7 on: May 07, 2014, 01:06:37 pm »
Yeah I thought it would change text somewhere in the game but I didn't see anything change. I've tried other files that seemed like it would have affect on the actual gameplay as well and nothing changed.

I can think of four possible scenarios off the top of my head:

1) You made the changes whilst the program was still running, and the configuration files only get read on start-up in the application
2) The configuration files are read in the build process for the program and therefore would require a rebuild to get the new values into the application
3) The configuration files are legacy and aren't used by the application at all
4) The configuration data is written to some kind of saved data file which is not being updated by the game after it has been created

I know nothing about the application you're referring to so this is only speculation.
Follow me on Twitter, why don'tcha? @select_this

Sixoul

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: How to handle config files?
« Reply #8 on: May 07, 2014, 07:06:51 pm »
Yeah I thought it would change text somewhere in the game but I didn't see anything change. I've tried other files that seemed like it would have affect on the actual gameplay as well and nothing changed.

I can think of four possible scenarios off the top of my head:

1) You made the changes whilst the program was still running, and the configuration files only get read on start-up in the application
2) The configuration files are read in the build process for the program and therefore would require a rebuild to get the new values into the application
3) The configuration files are legacy and aren't used by the application at all
4) The configuration data is written to some kind of saved data file which is not being updated by the game after it has been created

I know nothing about the application you're referring to so this is only speculation.

I was thinking maybe 2 but I wasn't actually sure if that was possible. I also thought maybe it was 4, but wasn't sure if that was viable. Thanks. How would something like 2 be handled?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to handle config files?
« Reply #9 on: May 07, 2014, 07:47:03 pm »
I don't recommend embedding configuration files into the build process. That defeats the whole purpose of changing configuration at runtime. What you could do, is providing hard-coded default values, when the config file can't be found. At least for smaller files.

Concerning when/how to change config files from the application: you usually store the local configuration in RAM. When the user modifies it, it must eventually be saved on hard disk. Now the question is, when you commit those changes. Either directly after a button was toggled (savest, but slow for large configs) or only in special situations, such as when the user leaves a menu (less save, but more efficient).

Concerning file formats: don't overcomplicate things. If you have a relatively flat structure with only few data types (string, number), you can build something on your own with std::fstream. In fact, I would do that anyway, you get a lot of experience about standard I/O and string handling. If you really need flexibility, you can use  hierachical format, such as XML, JSON. I personally don't like XML, it's extremely verbose. Lua tables are also an interesting choice, because they are more scalable -- you can not only store data, but also functionality to introduce scripting behavior. One thing to keep in mind is that the Lua interpreter just loads and doesn't save Lua files, so you need either an external serialization library or you do it yourself (shouldn't take too long). LuaBridge is a nice C++ binding.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: How to handle config files?
« Reply #10 on: May 07, 2014, 10:21:03 pm »
Quote
What kind of things are read only and what kind of data would need to be read write?
Anything that you feel should be. I have my filesystem settings file in Lua because I feel it's better that way: it's easier to edit by hand than XML, loading Lua via Selene (a small header only help library for Lua) is less code than loading XML with pugi and I don't really intend to change them from within c++ code (not that I can't, Lua code can be emitted easily but it's not provided out of the box in Lua lib like XML saving is provided in pugi).
« Last Edit: May 07, 2014, 10:23:32 pm by FRex »
Back to C++ gamedev with SFML in May 2023