Author Topic: Map/Scenario development in linux  (Read 3897 times)

Offline pente

  • Newbie
  • *
  • Posts: 38
Map/Scenario development in linux
« on: April 11, 2019, 03:30:25 AM »
I might at some point try to make a simple mission or some such, and was looking for how to set up a functioning development environment in linux. Does anyone (Hooman?) know how to go about doing that? I've never used MSVS so I'm hoping to avoid having to set up a VM or some such.

I attempted to run OP2Mapper v2.2.1 under wine and, after installing VB6 (If you get the error message "Library MSVBVM60.DLL not found", run "winetricks vb6run") I got the following sequence of 4 error messages while the loading dialog said "Loading shell...":

Run-time error '440': Automation error       ject
Run-time error '429': ActiveX component can't create object
Run-time error '429': ActiveX component can't create object
Run-time error '440': Automation error

Is OP2Mapper the only way to make Outpost 2 maps? Is the map file format documented somewhere?

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Map/Scenario development in linux
« Reply #1 on: April 11, 2019, 11:29:27 AM »
I don't do mission development from Linux. The main problem is name mangling differences between MSVC and Mingw. I've found Mingw is able to compile a DLL that the game will load as a level, but only an empty level that doesn't do anything. As soon as you try to call any interesting method from the level DLL, you end up with linking problems trying to build the DLL due to name mangling differences. Each compiler has their own way of mangling names, which is partly intentional, since each compiler tends to produce a slightly different and incompatible ABI for C++. It's only really the C ABI that is widely supported by various compilers and languages, not the C++ ABI (which is kind of lacking in standardization).

I've heard that Clang can produce MSVC compatible binaries, with identical name mangling and C++ ABI (or near identical, save some very uncommon corner cases like multiple virtual diamond inheritance or something like that). That may be an option for producing levels from Linux, though I've never tried it. It would require using Clang as a cross compiler from Linux to produce a Windows binary. The toolchain supports this from a capability standpoint, but not so much from a user level standpoint. There's no easy to use packaging to call Clang as a cross compiler. You'd have to do a lot of manual setup yourself. That may mean getting Windows header files from an MSVC install, or whatever else you might need, and configuring all the right options so the compiler knows where to look for platform specific header and library files. It's apparently quite complicated to get working.

If you manage to use Clang as a cross compiler, I'd love to know the details.

----

With that said, you can still run the code through Mingw for static checking purposes. You just won't be able to link the result for anything non-trivial. That can at least help you prevent brain-dead errors when trying to help other people with their code.

You can also use Clang for static checking purposes, but not for code with Windows specific includes, unless you've also figured out a cross compiler setup. Still very useful though, as Clang has some excellent static checking.

Another helpful tool is AppVeyor. I can make contributions to a project from Linux, statically check the result with Mingw, and push the results to GitHub, which would then run the code through MSVC on AppVeyor. That would catch any compile issues that are a problem for MSVC but not a problem for Mingw.

You can potentially run unit tests on AppVeyor too. That would let you know if the code actually works, as opposed to merely compiles. Though I've never written unit tests for an Outpost 2 mission.

It may also be possible to get AppVeyor to publish the compiled files as a GitHub release. I haven't experimented with that yet, though would love to set that up for a few projects.

----

I've never run OP2Mapper from Linux. I know it uses a few common controls. Maybe if those extra controls are registered it might help. I'm not too sure of the details on doing that.

I wasn't aware of the "winetricks vb6run" part. That's helpful to know. Perhaps I'll experiment a bit.

----

In the SVN, under the OllyDbg folder, there is a folder of text files that describe many Outpost 2 related file formats and in memory structures. It contains near complete info on the map file format. There are some gaps in details for saved games, which is a related format, and shares a lot of code.

The OP2Utility project on GitHub has code for loading and saving map data. It was used in the OP2MapImager project, also on GitHub. The methods are pretty raw though. There's no map editing capability around it. You'd have to build your own map editor on top of it if that's what you were looking for.

There's also an older OP2Editor backend, which the Mapper uses, and was used as the basis for much of the code in OP2Utility. It's much older, and uses COM which has been deprecated by Microsoft.
« Last Edit: April 11, 2019, 11:37:57 AM by Hooman »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Map/Scenario development in linux
« Reply #2 on: April 11, 2019, 12:06:17 PM »
I tried the VB6 runtime install:
Code: [Select]
winetricks vb6run

The gets the Mapper to load a bit further. It then fails trying to load components.

I tried the component registration for OP2Mapper:
Code: [Select]
regsvr32 cpopmenu6.ocx
regsvr32 vbaldtab6.ocx
regsvr32 vbaltbar6.ocx
regsvr32 vbaltreeview6.ocx

Unfortunately I seem to be missing one of the controls:
Code: [Select]
regsvr32: Failed to load DLL 'vbaldtab6.ocx'

I'm not sure what to do about that. I assume that control somehow got left out of the packaging.

Offline pente

  • Newbie
  • *
  • Posts: 38
Re: Map/Scenario development in linux
« Reply #3 on: April 11, 2019, 08:16:06 PM »
Thanks for the detailed response. I looked around for more information on the web along the lines of the topics you brought up. It looks like I will set aside my scenario writing ambitions until some unlikely future point that I have a VM and want to deal with compiling code on Windows.

Do you happen to recollect how you invoked mingw to get as far as you did? Or have a guess what target (https://clang.llvm.org/docs/CrossCompilation.html) one should use for compiling with clang? (I'm guessing i386 and pc, but for the rest of the parameters I wouldn't know.)

The map file format looks simple enough, but it seems if I want to get involved there I'd have to write my own tooling which is more of a time investment than is likely to happen. I get the impression that working out what all those tile indices mean is a bit much of a headache, and I've seen plenty of complaints about tile transitions.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Map/Scenario development in linux
« Reply #4 on: April 11, 2019, 11:41:44 PM »
Mingw is already setup as a cross compiler, and comes packaged with Windows header files. You pretty much just call it, though you will need to translate MSVC project specific settings to Mingw command line options.

Edit: I use the following alias for the below commands:
Code: [Select]
alias mingw='i686-w64-mingw32-g++'

For reference, I was able to use this with Brett's Yukon Trail mission:
Code: [Select]
mingw -I OP2MissionSDK/ *.cpp

The -I is to set an additional include directory for the SDK.

As Mingw is not able to link due to the name mangling differences, the above would produce a ton of linker errors after the compile step. If you want to avoid the spurious errors and just do syntax checking, you could use:
Code: [Select]
mingw -fsyntax-only -I OP2MissionSDK/ *.cpp



I came across this page for Clang Cross Compilation.



To get setup with a Windows Virtual Machine, Microsoft can help with that:
Get a Windows 10 development environment

It's a free download (time limited). A bit large though, about 16GB download, and 20GB unpacked.

If you want to keep using it past the time limit, I believe you'd be able to buy a licence and register it with the VM. It should also be possible to redownload/reinstall at the end of the trial period.

« Last Edit: April 11, 2019, 11:43:18 PM by Hooman »