-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Hi, I have an idea how to make Mds parser better.
Problem
In current design we have ModelScriptBinParser/ModelScriptTextParser with base class ModelScriptParser.
Every time someone want's to add support for new chunk-type, code has to be written twice: once for Bin, once for Txt.
Possible solution
Move more logic into ModelScriptParser base class. It can be done, by introducing a new group of virtual functions, like:
virtual std::string readStr()=0;
virtual std::string readKeyword()=0;
virtual uint32_t readDWord()=0;
virtual int32_t readI32()=0;
virtual float readFloat()=0;
...
Prototype
Here is a prototype, I have in my fork:
https://github.com/Try/ZenLib/blob/master/zenload/modelScriptParser.cpp
Testing: run locally Gothic2Notr, Gothic2, Gothic1, Gothic reloaded.
Test suite: https://github.com/Try/ZenLib/blob/master/tests/test_mds.cpp
(sorry, but no test-data in repo - I've had to use dumps from game assets)
Benefits
- Less code
- Feature-consistency over gothic1-2
- Write once - debug everywhere king of code
Cons
- Debug everywhere king of code, because one line can change behavior for both formats.
- CHUNK_MESH_AND_TREE doesn't match between txt and bin formats - implemented as virtual function.
- Prototype contains unrelated changes(more chunks + removal of get-function in favor of public access)
- CHUNK_ERROR handling not implemented in prototype - text parser is always relaxed.
Andre, welcome back by the way :)