Page 1 of 2

script life cycle

Posted: 20 May 2013, 18:20
by mirpa
Hi,

could somebody elaborate a little bit about scripts? How do you handle them from text representation through compilation to execution or how do you intend to do it. I am not modder so I do not understand ESX/BSA file formats that well yet.

It seems to me, that script is stored in uncompressed binary format inside ESX and openmw uses compiler component just to translate console commands into bytecode so compiler component is mainly part of opencs.

In compiler there seems to be class for each syntactical unit (token) which handles everything from lexical analysis to code generation and error handling.

I didn't look at interpreter component yet. But I wonder how do you manage memory usage for script interpretation. In game there are big increases in memory usage around big cities like Balmora, Aldruhn... Game starts at ~400 MB Ram and it can reach 1 or 2 GB within 15 minutes or less.

Ps. Of course I have red Ghan's Morrowind Scripting for Dummies (briefly).

Btw. How do you study new classes - do you use some IDE feature or do you use (doxygen) documentation? I would appreciate more comments on design choices inside code on some places - but maybe it is because I am not used to OOP that much.

I always wondered if there is some design draft inside OSS projects. I intend to crawl through most of the code anyway so feel free to leave my post unanswered.

Thanks anyway.

Re: script life cycle

Posted: 21 May 2013, 09:00
by Zini
Vanilla Morrowind's CS compiled script into bytecode, which was stored in the ESX files and then executed by a VM in Morrowind. We do not support the same VM, but we do support the scripting language.

OpenMW compiles the scripts on the fly to bytecode for our own VM (the interpreter).

There are no memory issues regarding scripts (unless there is a bug we are not aware of; which is always a possibility). There is nothing to manage. Compiled scripts (except for dialogue scripts) are stored for later use, but this stuff is tiny.

The compiler works by first translating the character stream into tokens and then sending them to the parser. We have indeed separate parser classes for the different levels of syntactic constructs.

IIRC there was a memory leak in 0.23.0 (not sure how far it is going back) regarding graphics resources. That should be fixed in 0.24.0 though. Would be interesting to see if you are still getting this huge memory usage. We had also reports of memory usage problems related to the 32 bit version of OpenMW. Not sure what the state of that is, but are you running under 32 bit?

Re: script life cycle

Posted: 21 May 2013, 13:08
by mirpa
64-bit Linux, recent version from git/master.

Re: script life cycle

Posted: 21 May 2013, 14:28
by Gez
Zini wrote:Vanilla Morrowind's CS compiled script into bytecode, which was stored in the ESX files and then executed by a VM in Morrowind. We do not support the same VM, but we do support the scripting language.

OpenMW compiles the scripts on the fly to bytecode for our own VM (the interpreter).
There is at least one Morrowind mod (cdcooley's Companion Teleportation 1.1 IIRC) which only kept the byte code for the scripts to make the mod smaller. (Actually, it had like ten near-identical copies of the same script with different IDs, and only the first had kept its source code, with the text file explaining how to recreate the source code for the other scripts if you wanted to change stuff and recompile.)

So it might be a good idea, on the long term, to support reading the vanilla bytecode and translating it to OpenMW's bytecode format if the source code is missing.

Re: script life cycle

Posted: 21 May 2013, 14:32
by Zini
While I wouldn't reject a code contribution that does that (if done cleanly), personally I would see that as a waste of time. It would be quicker to just fix that plugin. I doubt there are many of these around. I don't see how it would even be possible to create something like this with the TES-CS.

Re: script life cycle

Posted: 21 May 2013, 22:35
by Gez
Zini wrote: I don't see how it would even be possible to create something like this with the TES-CS.
He used the Enchanted Editor to do that.

Re: script life cycle

Posted: 22 May 2013, 09:17
by Zini
Yeah. Sorry, but we do not support 3rd party binary extensions/tools/modifications to MW in any way. IMHO a plugin as this should simply be classified as broken.

Re: script life cycle

Posted: 22 May 2013, 18:30
by Tarius
Zini wrote:Yeah. Sorry, but we do not support 3rd party binary extensions/tools/modifications to MW in any way. IMHO a plugin as this should simply be classified as broken.
However, lacking the ability to edit stuff like Enchanted editor would be a big drawback. This would be in the realm of the CS though and you wouldnt need another tool.

Re: script life cycle

Posted: 22 May 2013, 19:26
by sirherrbatka
Enchanted editor is here for doing crazy hacks around the engine mostly so is it a case?

Re: script life cycle

Posted: 28 May 2013, 15:52
by claudekennilol
I used Enchanted Editor almost exclusively. It was much easier than loading up the CS and clunking around in there. I never did anything with it that couldn't be done with the CS though (disregarding editing saves as that wasn't esp/esm manipulation). Obviously this is in regard to scripting, and basic object manipulation, object placement was better in the CS.