Grid Sage Forums

Grid Sage Forums

  • April 27, 2024, 05:12:38 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

LINKS: Website | Steam | Wiki

Author Topic: How to build Cogmind open source libraries  (Read 2263 times)

Luigi

  • Derelict
  • **
  • Kyzrati Patron
  • Posts: 25
  • Numba one numba two
    • View Profile
How to build Cogmind open source libraries
« on: January 03, 2022, 03:48:46 AM »

What
Recently I have come upon modern understanding (as of this post) of how to satisfy the Lesser GNU Public License clause of Cogmind's associated SDL 1.2.14 binary that was built against an old toolchain many years ago. You should be able to generally apply this to other SDL helper libraries if necessary.
Why
This post is intended for archival in the distant future when historians seeking to plug Cogmind into their latest hyperreality gamestation's graphics layer run into problems because of how Cogmind manages its memory across heaps, at least as of Cogmind b11 X9 (a patreon pre-release build). I believe this is included in Cogmind only due to its use of REX, but I don't really get how it all works in the end.
How
Without further ado, this works on a modern Debian machine, and I was able to apply this on an M1 Macbook Air running the latest macOS and mingw-w64 toolchain. Huge thanks to user Daid of the Roguelikes Discord for putting this together! What a cute cat they have in their profile picture :D

Code: [Select]
$ git clone git@github.com:libsdl-org/SDL-1.2.git
$ cd SDL-1.2/
$ git checkout release-1.2.14
$ ./autogen.sh
$ ./configure --host=i686-w64-mingw32 --disable-directx --disable-assembly --build=x86_64-w64-mingw32
$ make -j 12
$ file ./build/.libs/SDL.dll
./build/.libs/SDL.dll: PE32 executable (DLL) (console) Intel 80386, for MS Windows
$ daid@MSI:~/SDL-1.2$ i686-w64-mingw32-objdump -x ./build/.libs/SDL.dll | grep DLL
        DLL
 vma:            Hint    Time      Forward  DLL       First
        DLL Name: ADVAPI32.dll
        DLL Name: GDI32.dll
        DLL Name: KERNEL32.dll
        DLL Name: msvcrt.dll
        DLL Name: USER32.dll
        DLL Name: WINMM.DLL
        DLL Name: libgcc_s_dw2-1.dll

The last command is demonstrative of the need for this assembly configuration workaround.

Further information
If you are a developer interested and aware of the implications of SDL hooking, I welcome you to join the Roguelikes discord community where I am working on a Cogmind AI/TAS. A later post in this forum somewhere appropriate will link to the sources for this project if and when it is in a state I deem interesting.

Binary Archival
Attached to this post would be a copy of SDL source code that can also be used in the event the git remote specified above goes out of service. But the forum limits me to 1MB. It's a 5MB archive. I'll see what I can do.
« Last Edit: January 18, 2022, 07:18:14 PM by Luigi »
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4315
    • View Profile
    • Cogmind
Re: How to build Cogmind open source libraries
« Reply #1 on: January 04, 2022, 05:02:47 AM »

Hey Luigi, thanks for sharing this, very awesome work figuring it out xD

This might be easier one day once Cogmind uses a more modern architecture, but porting it over (along with all the other things dependent on my engine) would take some doing and no doubt introduce all kinds of new issues to resolve, so I'm definitely not in any kind of hurry to do it :P

(I do look forward to the resultant AI, and offering some support for it, but that's for another thread...)

To help contribute to this thread, I've collected the SDL sources for projects used by Cogmind in an archive that can be downloaded here (20 MB). Within you'll find projects for:
  SDL-1.2.14
  SDL_image-1.2.10
  SDL_mixer-1.2.11
  SDL_net-1.2.8
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Luigi

  • Derelict
  • **
  • Kyzrati Patron
  • Posts: 25
  • Numba one numba two
    • View Profile
Re: How to build Cogmind open source libraries
« Reply #2 on: January 16, 2022, 05:55:47 AM »

Hey Kyzrati, thanks for dropping those sources! I've noticed that SDL builds made like this have an issue after about 20 seconds of gameplay where the SDL mixer buffer throws an exception trying to free the audio resource.

Would it be possible for us to get a pointer to the sources for libvorbis-*.dll and the like? I have a feeling all the FOSS libraries need to be built with the same toolchain for SDL to be pluggable.
Logged

Kyzrati

  • Administrator
  • True Cogmind
  • *****
  • Posts: 4315
    • View Profile
    • Cogmind
Re: How to build Cogmind open source libraries
« Reply #3 on: January 16, 2022, 10:22:39 PM »

Yes these are available on GitHub from Xiph, though I don't think they'd need to be built alongside SDL for it to work. My guess is that issues with your mod would be coming from somewhere else, but yeah, you never know for sure with all this library stuff--a real pain in the neck xD
Logged
Josh Ge, Developer - Dev Blog | @GridSageGames | Patreon

Luigi

  • Derelict
  • **
  • Kyzrati Patron
  • Posts: 25
  • Numba one numba two
    • View Profile
Re: How to build Cogmind open source libraries
« Reply #4 on: January 22, 2022, 11:47:51 AM »

I figured it out, you just have to use mingw32 in highly specific ways listed here: https://how-to.fandom.com/wiki/How_to_setup_a_Simple_Direct_Media_Layer(SDL)_build_environment#Windows:_MinGW
Logged

Luigi

  • Derelict
  • **
  • Kyzrati Patron
  • Posts: 25
  • Numba one numba two
    • View Profile
Re: How to build Cogmind open source libraries
« Reply #5 on: February 21, 2022, 06:26:13 AM »

Adding this here for more instructions since I have started contributing to these projects and would like to document how they are built and used:



To get the tools you need:
https://www.msys2.org
Open a Mingw32 terminal


Code: [Select]
pacman -Syu mingw-w64-i686-toolchain curl mingw-w64-i686-libogg make
curl https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-1.3.7.tar.gz | tar xz
cd libvorbis-1.3.7/
CFLAGS='-march=native -O3 -ffast-math' ./configure --host=i686-w64-mingw32 --build=x86_64-w64-mingw32
make -j8 # replace 8 with your CPU core count
cp lib/.libs/*.dll "/c/Program Files (x86)/Steam/steamapps/common/Cogmind/"


This will compile a version of libvorbis and friends and drop it in the location of a retail copy of Cogmind.
It will use the fastest possible native language your CPU supports to decode the game audio and would be the fastest theoretical speedup, but it won't work on most machines other than your own.


One can verify my builds on the forum with the CFLAGS: "-msse4.1 -O3 -ffast-math". If you build it around the time I did, it should be bit-for-bit exact on a Windows 11 (and probably W10) machine.
This generally applies to all my mods, see the post above for the special case of SDL 1.2 or check the readme on my GitHub project.
« Last Edit: September 22, 2022, 04:06:25 PM by Luigi »
Logged