Mogre configfile saving settings

r4ccoon

09-08-2010 14:22:08

hi, I have been wondering why ConfigFile class does not a have saving method.
what I want to ask is how do i save settings back into the config file?

I am using mogre171

just for an insight, that i am creating a windows form interface to edit terrain width and height, and maybe terrain's height file.

Beauty

11-08-2010 01:06:37

Welcome to our Mogre forum :D

Which config file you mean?
The resources.cfg or an other one?

For common Ogre configuration (e.g. anti aliasing factor) in my application I wrote all needed settings to an XML file.
At program start I load and apply them. The XML config file can be changes by the application if needed.

r4ccoon

11-08-2010 02:54:26

yeah, i mean something like resources.cfg file. plugins.cfg, ogre.cfg, something like that.
but in this case i need cfg file on terrain.cfg.
in mogre you can do something like
_SceneMgr.SetWorldGeometry(terrainfilename);

so that is why i need to save the values back to the cfg file.

mikael

11-08-2010 05:10:53

you can also use Serialization to save/load your configs, if you create class which contais all names etc data.
(or maybe you meant something else)

Beauty

11-08-2010 16:04:35

It seems so that you use the Terrain Scene Manager which uses such a config file.
Just a few days ago I looked how to read terrain data from the scene manager which were loaded by the terrain config file. But I couldn't find a way.
I suppose the terain scene manager is very old, still works, but its development stopped some years ago.

In my application I need to know some terrain params like the world size.
So I wrote a small method which can read such values from the terrain config file.
If you are interested I can look for my param reading method and publish it.

To save a configuration back to a terrain config file, you could write a "modifier" method.
Read the config file, replace the value of the related field and save it.
No nice solution, but it should work.
If you know regular expressions, this job would need just a few lines of code.

Which params would you like to change?

The paging scene manager is an improved version of the terrain scene manager.
Maybe there is a better solution for reading and saving configurations.
But I can't tell you details, because I never used an other scene manager until today.

Ogre 1.7 contains a new terrain manager with several improvements.
Currently it's not available in Mogre, but user boyamer announced to write a wrapper for it. So maybe in a few weeks we could use this new terrain manager.



Related to ogre.cfg - this file isn't needed.
You can set and apply the params by source code.
Additionally you could read them from your own config file. And your own config file you could update as you like (means save settings).

Here is a code snippet how to set params:

// "root" still has to be defined
RenderSystem rs = root.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
root.RenderSystem = rs;
rs.SetConfigOption("Full Screen", "No");
rs.SetConfigOption("Video Mode", "1024 x 768 @ 32-bit colour");
root.Initialise(false, "Main Ogre Window");

NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = this.renderPanel.Handle.ToString();
misc["FSAA"] = "4"; // anti aliasing factor (0, 2, 4 ...)

var.renderWindow = root.CreateRenderWindow("Main RenderWindow", 1024, 768, false, misc);



For plugins.cfg is also a way (as I wrote somewhere), but I think mostly there is no need for this.
The content is still the same for an application. It just tells some needed libraries (e.g. DirectX, OpenGL, some add-ons). If you want your application for both (DirectX and OpenGL), then just add both.


The resource.cfg file is nice. There you can define all directories which contains your meshes, materials, etc.
All content of this directory will be loaded. So there is no need to add all new resources to this config file.

If you want to add resources by code, it's easy. You can use the ResourceGroupManager.
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName)


I hope I could help.

mstoyke

11-08-2010 16:19:11

I just saw in the Ogre roadmap for 1.8 that the terrain scene manager will be removed in the next major release of Ogre. So it's best not to use it anymore if you want to upgrade your project to 1.8 once we release an updated wrapper. As long as you want to stay with 1.7.x you should be fine.

As far as I know you can't easily write the cfg file for the scene manager, but I might be wrong. I recommend to take a look at Nini, a library to read and write all kind of configurations and ini-files. That's what I usually use in my projects.

Beauty

11-08-2010 17:29:08

Ok, good to know. I added a note to the wiki page of the terrain scene manager.

Also thanks for the hint of the Nini library. It also support XML config files :D