The Gang Garrison 2 Forum

Gang Garrison Development => Development Discussion => Topic started by: BedtimeGuy on September 30, 2018, 06:14:10 am

Title: Quick question about how GG2 maps are read
Post by: BedtimeGuy on September 30, 2018, 06:14:10 am
Hi, I'm workin on a game of my own, and I realized that a feature I wanted to implement was very similar to how GG2's maps work. Hopefully it's ok to ask my question here.

Basically, how does GG2 go about reading what looks like a plain old PNG, and generate collision for the walls, and other objects as added in Garrison Builder? I know you have to make a wallmask first, but it seems like magic to me that it ends up being one PNG. Also, surely GG2 is doing something better than reading the image pixel by pixel and making each pixel that needs to be solid/have collison that way. Something involving making a bunch of... fitting rectangles for areas that are black in the wallmask?

Totally understand if y'all tell me to fk off and read the source, I've just never touched GameMaker before at all, so I didn't get much from that lmao
Title: Re: Quick question about how GG2 maps are read
Post by: Phantom Brave on September 30, 2018, 06:43:23 am
We store it in the metadata text. Here: https://github.com/Gang-Garrison-2/Gang-Garrison-2/blob/master/Extensions/GG2DLL/GG2DLL/GG2DLL.cpp#L71
Title: Re: Quick question about how GG2 maps are read
Post by: MedO on September 30, 2018, 06:45:44 am
Hello, and welcome to the forums.

The trick is that a .png file is more than just the plain image information, it consists of many "chunks" that are used for different purposes. There is one for the actual image data, but there are also others for things like color profiles, thumbnails and so on. When we save a gg2 map, we add a custom text chunk which contains the entity information as well as the wallmask.
The entity information is stored in something similar to JSON (but slightly different so that it maps better to Game Maker data structures), called GGON: https://github.com/Gang-Garrison-2/Gang-Garrison-2/blob/master/Documentation/GGON.md
The wallmask is first converted to a .png of its own first, and then that .png is encoded as something akin to base64 so that we can store it in our text chunk as well.
Title: Re: Quick question about how GG2 maps are read
Post by: BedtimeGuy on September 30, 2018, 06:28:13 pm
ahhh, that makes a lot of sense! Thanks for the quick and very helpful answers  :smiley16:
And thanks for the welcome to the forums, although I used to be quite active on here many, many moons ago. Not sure I even remember my old username lmao
Title: Re: Quick question about how GG2 maps are read
Post by: #freeprime on October 14, 2018, 01:26:58 am
https://github.com/Gang-Garrison-2/Gang-Garrison-2/blob/master/Extensions/GG2DLL/GG2DLL/GG2DLL.cpp#L78 this triggers me can someone fix it

edit: the mixing of tabs and spaces in general triggers me, can someone fix it
Title: Re: Quick question about how GG2 maps are read
Post by: MedO on October 14, 2018, 06:43:11 am
If it bothers you then you can fix it  :hehe: