Does the scripting system use Qt?

For AI and campaign script related discussions and questions
Post Reply
MIH-XTC
Trained
Trained
Posts: 358
Joined: 31 Jan 2014, 07:06

Does the scripting system use Qt?

Post by MIH-XTC » 01 Jul 2019, 00:22

Why are the Javascript functions implemented using Qt if they’re not related to the GUI?

I’m asking out of my own personal curiosity as a software developer.

I wanted to know what it would take to make a Python API so I started looking at where the Javascript API functions are defined. They’re defined in the qtscript files correct? For example, I searched for where countStruct() is defined and it's in qtscripts. Why Qt though if none of the scripts are related to the GUI? I thought Qt was for GUI.

pastdue
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 217
Joined: 13 Aug 2017, 17:44

Re: Does the scripting system use Qt?

Post by pastdue » 01 Jul 2019, 04:22

Currently, WZ uses QtScript as its ECMAScript engine.

At some point, the goal is to replace this with a different engine while maintaining compatibility with existing scripts (and potentially supporting new ECMAScript E5/E5.1 features).

MIH-XTC
Trained
Trained
Posts: 358
Joined: 31 Jan 2014, 07:06

Re: Does the scripting system use Qt?

Post by MIH-XTC » 01 Jul 2019, 14:15

pastdue wrote:
01 Jul 2019, 04:22
Currently, WZ uses QtScript as its ECMAScript engine.

At some point, the goal is to replace this with a different engine while maintaining compatibility with existing scripts (and potentially supporting new ECMAScript E5/E5.1 features).
Ah okay, that makes a lot of sense. I didn't know what Qt Script was, I wasn't aware Qt provided a library for ECMAScript integration.

I was curious where the Javascript interpreter is to see if it would make sense to do the same thing in Python.

It also makes sense why Qt given that it was many years ago.

But that stinks the scripting API is tightly coupled to Qt because it uses all Qt data types.

In a perfect modern world, would it be ideal to have the scripting API in plain C++ with a stand alone engine like node.js?

I still don't understand why qtscriptfuncs.cpp would be specific to Javascript though. If it's just a bunch of functions that return values shouldn't we be able to use any scripting language on the front-end?

I'm somewhat of a novice programmer and trying to figure out how things work and what is considered best architecture practice.

Thanks!

pastdue
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 217
Joined: 13 Aug 2017, 17:44

Re: Does the scripting system use Qt?

Post by pastdue » 01 Jul 2019, 15:19

At the time QtScript was chosen (and integrated), Qt was much more widely used in the codebase (in fact, there was even a Qt backend for creating the window and such). So, at the time, it made sense to use Qt data types in all the Qt-script-related files, because Qt data types were used everywhere.

There has been a lot of work since 3.2.x to dramatically reduce the Qt dependencies. Currently, it's (mostly) limited to the scripting engine and the script debugger window.

As part of the refactoring needed to swap out QtScript for a different ECMAScript engine, we'll try to keep in mind making it easier to integrate different scripting engines - whether they are ECMAScript or a different language entirely. (And yes, we've been replacing Qt types with C++ stdlib containers / types as we proceed.)

In general, the WZ codebase has existed since the 1990s (and was originally C, DirectX-based, etc), and has been gradually refactored and rewritten since then - but there is still a lot of old code / architecture (ex. globals galore!) and it's still pretty brittle in places. It should not be considered an example of modern development / C++ coding style, but perhaps could be used as an example of how to gradually keep an old codebase working (and improve / "uplift" pieces) as time goes on. Some parts of it are better / "fresher" than others.

User avatar
NoQ
Special
Special
Posts: 6225
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Does the scripting system use Qt?

Post by NoQ » 02 Jul 2019, 06:35

/me sometimes thinks about trying to write an AI in rust so that to compile it to wasm and load into warzone.

Post Reply