Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2172 closed task (fixed)

[PATCH] Switch ConfigDB scripting to global functions

Reported by: Yves Owned by: Yves
Priority: Should Have Milestone: Alpha 15
Component: Core engine Keywords: Spidermonkey
Cc: Patch:

Description

Same goal, same comments and same approach as #2126. I don't use macros here because there are less similar functions. The ConfigDB didn't actually use CJSObject, but it implemented properties directly using the JSAPI and used a JSNative function as an object constructor. I didn't figure out how to do the latter with the new Spidermonkey API. The main reason I changed it is not because I didn't figure out how to implement it with the same approach of course. This solution is cleaner in my opinion and it uses less fancy Spidermonkey features that aren't actually required. This should also make future upgrades easier.

I've done some tests using the console because currently some of these functions aren't even used anywhere:

  • Open console from main menu
  • warn(Engine.ConfigDB_GetValue("system", "sound.mastergain"));

--> WARNING: 0.9

  • Engine.ConfigDB_CreateValue("system", "sound.mastergain", 0.8);
  • warn(Engine.ConfigDB_GetValue("system", "sound.mastergain"));

--> WARNING: 0.8

  • Engine.ConfigDB_Reload("system");
  • warn(Engine.ConfigDB_GetValue("system", "sound.mastergain"));

--> WARNING 0.9

I noticed that the VFS uses a cache and therefore doesn't reload new config settings if you change them in a config file after starting the game and then call the reload function. This behaviour doesn't change with the patch, so I won't fix it as part of this ticket.

I will have to update: http://trac.wildfiregames.com/wiki/Exposed_ConfigDB_Functions

Any comments are welcome!

Attachments (2)

ConfigDB_global_functions_v1.0.diff (14.4 KB ) - added by Yves 11 years ago.
ConfigDB_global_functions_v1.1.diff (14.4 KB ) - added by Yves 11 years ago.
Changed the configuration context to from "system" to "user" acording to leper's input

Download all attachments as: .zip

Change History (4)

by Yves, 11 years ago

Changed the configuration context to from "system" to "user" acording to leper's input

comment:1 by Yves, 11 years ago

Resolution: fixed
Status: newclosed

In 13914:

Changes the ConfigDB to expose global functions to scripts instead of properties and custom objects.
Fixes #2172
Refs #1886

comment:2 by Yves, 11 years ago

Keywords: review removed

I've committed the latest version of the patch with the following additional changes:

  • I changed %s to %hs (thanks to Philip!)
  • I updated a comment (thanks to Josh for reminding me of the comments!)
Note: See TracTickets for help on using tickets.