Hi, everyone. Does anyone know if there is some developer documentation available for the Gob engine or the Gob data files?
Somewhere in the forums it said that it's the smallest engine in ScummVM, and that it was originally researched by Ivan Dubrov, but I haven't found more information.
I looked at the source code and the parse*.cpps, but I found the code is rather sparsely commented. If there's any other documentation about the engine or the data format, please tell me. Since some people already spent so much time one the engine, I thought it'd be possible that they had shared their findings somehow.
There's no special task that I need the documentation for. I just find the games intriguing yet they appear to be relatively simple, so I'd like to know how the inner game logic works.
(On a sidenote: for some reason, I wasn't allowed to access the Doxygen web pages. Are they under construction?)
Thanks in advance!
Developer Documentation for the Gob Engine
Moderator: ScummVM Team
- DrMcCoy
- ScummVM Developer
- Posts: 595
- Joined: Sat Dec 17, 2005 1:33 pm
- Location: Braunschweig, Germany
- Contact:
Re: Developer Documentation for the Gob Engine
Apart from the source in ScummVM, not much, I'm afraid.g99k wrote:Hi, everyone. Does anyone know if there is some developer documentation available for the Gob engine or the Gob data files?
For the video files, there are entries in the MultimediaWiki for IMDs (apparently based on our code) and VMDs.
If you want to write some documentation based on the code yourself, you'd be welcome, of course.
Once you know where to start, the engine shouldn't be that hard to understand.
From the number of lines, directory size, etc., that's not true (anymore?).g99k wrote:Somewhere in the forums it said that it's the smallest engine in ScummVM
Well, it was constructed by reverse-engineering, after all.g99k wrote:I looked at the source code and the parse*.cpps, but I found the code is rather sparsely commented.
Ivan apparently didn't comment much and I'm unfortunately not quite the chatty type either . I often refrain from commenting because I think that piece of code is rather obvious (although it might not be for an outsider).
Yes, the parse*-files are quite hard to follow, but they're not needed for understanding the basic file formats. The functions there parse expression found in the script byte code (like "(VAR_23+6)/2").
Take a look at dataio.cpp, for example. It's for handling STK/ITK files, which are archive files bundling all the other data files. (Or take a look at a small STK extractor I've wrote for testing. It should be clearly readable.)
As I said, not really, sorry.g99k wrote:If there's any other documentation about the engine or the data format, please tell me.
Well, I for one can give you pointers on where to start looking, answer specific questions, etc..g99k wrote:Since some people already spent so much time one the engine, I thought it'd be possible that they had shared their findings somehow.
As for the gob games, most of the game logic is in the scripts.g99k wrote:There's no special task that I need the documentation for. I just find the games intriguing yet they appear to be relatively simple, so I'd like to know how the inner game logic works.
Re: Developer Documentation for the Gob Engine
The SCRIPTS!!! That's the word I was looking for! Yes, I'm after the scripts!DrMcCoy wrote:As for the gob games, most of the game logic is in the scripts.
My goal is to be able to read and understand several sample scripts. I don't care too much for the bytecode format itself, I just want to understand the logic.
Of course! I forgot that code speaks for itself. Here's what I got so far from reading your code:DrMcCoy wrote:I often refrain from commenting because I think that piece of code is rather obvious (although it might not be for an outsider).
Many classes are subclassed accourding to their goblin game version number (vXX). The global GobEngine variable _vm seems to have two main member variables to handle the different games:
- _inter of class Inter_vXX handles the game logic,
- _game of class Game_vXX holds the game data.
The actual parsing then seems to take place in Inter::funcBlock. The pointer is evaluated and 2 command opcodes plus parameters are read from the script data and passed for execution to Inter_vXX::executeFuncOpcode. Here, the 2 opcodes are combined to a single number which is used as an index to look up a function pointer in the _opcodesFuncVXX array, which is then executed with the parameters.
Code: Select all
OpcodeFuncProcV1 op = _opcodesFuncVXX[i*16 + j].proc;
...
return (this->*op) (params);
(I'm from Javaland, and I must say, C++ function pointers totally rule when it comes to producing obscure code. )
Okay, here's my questions:
- Can you maybe explain the mappings and different levels of opcode? Are there any rules for which function resides in which array?
- How do control flow statements (like "o1_if") work, and where are the tested variables stored?
- How do I enable script dumping? The command line argument didn't seem to work for me, even though I created a "dumps" folder.
- What does "tot" stand for? Is that a name for the script data?
- DrMcCoy
- ScummVM Developer
- Posts: 595
- Joined: Sat Dec 17, 2005 1:33 pm
- Location: Braunschweig, Germany
- Contact:
Re: Developer Documentation for the Gob Engine
I'd advice you to not take the GobEngine scripts. They are pretty...confusing/complex.g99k wrote:The SCRIPTS!!! That's the word I was looking for! Yes, I'm after the scripts!
Exactly.g99k wrote:Of course! I forgot that code speaks for itself.
2 actually. One for entering and one for leaving.g99k wrote:Each collision block has a pointer associated with it which points to a function in the script data blocks.
Engine versions 2 and above have an additional third one that's used for variable coordinates.
Well: the original exectuable did it like that!g99k wrote:Can you maybe explain the mappings and different levels of opcode?
Or rather, the orignal executable had huge switches and I changed it to use a table of function pointers instead (after what our SCUMM-engine does).
In the disassembly, funcBlock first checks through 0-4 of the first value and for each case, switches again.
o1_drawOperations just takes one byte and switches over it.
o1_goblinFunc takes two bytes and doesn't check for completely consecutive values, therefore I first run it through a translation table, so I won't need a function pointer table with 2006 entries.
You'd have to ask that the original devs.g99k wrote:Are there any rules for which function resides in which array?
Apparently, o1_drawOperations has many drawing related functions and in Gob1, goblinFunc had to do with goblins related function, that's why Ivan named then that way.
Although in later engine versions, goblinFunc doesn't do anything with the goblins anymore. The functions even change with games that otherwise use exactly the same engine version (Gob2, Ween and Bargon, for example).
They parse and evaluate an expression (with the functions in the Parse_*-classes).g99k wrote:How do control flow statements (like "o1_if") work, and where are the tested variables stored?
The variables are stored in Global::_inter_variables. And here's the tricky/ugly part:
Global::_inter_variables gets initialized as a consecutive block of memory for n (read from the game data) 32bit variables. But the scripts can access each variable as either:
- 1 32bit variable
- 2 16bit variables
- 4 8bit variables
- Arrays of above
- Strings
Which variable is of which type is completely managed by the scripts, the engine doesn't know about that (it only gets ordered to, for example, write these 8bit to position x in the variables memory).
The animation properties of each object are mapped onto that, too.
You don't/can't.g99k wrote:How do I enable script dumping?
You can comment out the "return;" in Parse::printExpr() and run ScummVM with "-d5 --debugflags=DrawOpcodes,FuncOpcodes,GoblinOpcodes", that will dump some script-related stuff to stdout as it goes.
You can also use the aforementioned STK-extractor to dump the *.TOT files, these are the scripts in raw byte code.
There's no script-decompiler for the GobEngine (yet), though.
Yeah, the files with the scripts in it are all called *.TOT. Why that is, I don't know. Probably an acronym for a related french term.g99k wrote:What does "tot" stand for? Is that a name for the script data?
Re: Developer Documentation for the Gob Engine
If you're just looking for some scripts example, then Gob engine is not the best choice. It used to be one of the smallest engines when it supported just Gobliiins (1st in the series), but now it became one of the most complex ones .g99k wrote:Somewhere in the forums it said that it's the smallest engine in ScummVM, and that it was originally researched by Ivan Dubrov, but I haven't found more information.
A quite good example of simple engine, which isn't going to become much bigger is AGI. Moreover, there are nice game editors for it, such as WinAGI which let you create whole game from the scratch. Also number of Fanmade games are shipped with complete and sometimes commented scripts sources.
Eugene
Re: Developer Documentation for the Gob Engine
DrMcCoy wrote:I'd advice you to not take the GobEngine scripts. They are pretty...confusing/complex.
Well, I guess you guys are probably right. I tried to look deeper into the script interpretation parts, but it's quite time-consuming. What you say about the variables being stored as a consecutive block doesn't sound too encouraging either.sev wrote:If you're just looking for some scripts example, then Gob engine is not the best choice. It used to be one of the smallest engines when it supported just Gobliiins (1st in the series), but now it became one of the most complex ones .
Maybe I'll really give up for the time being and try AGI instead, as you suggested. If I run into problems there, I'll open a new thread. At least it has way more comments, I noticed.
Two questions on the way out:
- If I can't enable script dumping, what's the command line option intended for? Are there some engines where it works?
- In case I get back to the Gob engine: Do you know the ScummVM version number where Gobliiins 1 support was complete, but the other Gob games hadn't yet been added? Maybe that single-game version is less confusing.
Re: Developer Documentation for the Gob Engine
-u option works only in SCUMM engine. For AGI engine you should just use WinAGI which will nicely decompile everything you need.g99k wrote: If I can't enable script dumping, what's the command line option intended for? Are there some engines where it works?
0.8.0g99k wrote: In case I get back to the Gob engine: Do you know the ScummVM version number where Gobliiins 1 support was complete, but the other Gob games hadn't yet been added?
Eugene