Page 1 of 2
Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 1:32 am
by Pinkishu
So yeah, I'll have to make a couple file formats for a project i'm working on and I wondered if there are any standard pre-made formats one could use or what to look at when designing a file format specification.
The file formats i'm at atm are: Levels (basically a tile-based level, 64 by 64 tiles, 3 layers of tiles possible (below player, same-level as player, above player)) and animations
So a format that would load pictures and split them into frames using reasonably numbering, then its either a single-direction animation or a 4-direction animation (for players, characters etc, as they can face north/east/south/west), it tells which frames from the images to use in which animation-frame, what color to draw them in, how long each animation-frame lasts, which direction (if not single-dir) an animation-frame is attributed to and such things
Are there any standards that fit those descriptions?
If not, what should I use for them? A readable format liek Plaintext or JSON? A custom format which is efficient in size, using only the bits it needs? etc
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 10:16 am
by micha
There is no general ready to use lua or löve implementation for your needs.
For loading maps you can have a look at
Advanced Tiled Loader. As far as I know it can load map files in different formats. So you can create your maps with some external software and directly load the maps.
Besides that there are generally two approaches to saving data. The first one is to make up your own format. For example a map can be stored as a block of numbers in a text file. Your loading routine has to read this data character by character and construct the map internally.
The second approach is to save data in lua-language. As you know the constructor for tables in lua is very well human readable. So you can just create a file that when executed, produces all data inside your game. Have a look here, for more details:
PiL.
The first approach has the advantage that it is simpler to write such files. The files might also be slightly smaller and a bit easier to read. The second one has the advantage that the loading function is already implemented (you only have to love.filesystem.load('file')() ).
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 11:23 am
by Automatik
The second approach is to save data in lua-language. As you know the constructor for tables in lua is very well human readable. So you can just create a file that when executed, produces all data inside your game. Have a look here, for more details: PiL.
Except it's very dangerous, because insecured(It's code after all).
You can also
use Json. It's much more secure than loading lua, while being simpler to use than doing everything yourself.
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 2:13 pm
by scutheotaku
Automatik wrote:The second approach is to save data in lua-language. As you know the constructor for tables in lua is very well human readable. So you can just create a file that when executed, produces all data inside your game. Have a look here, for more details: PiL.
Except it's very dangerous, because insecured(It's code after all).
You can also
use Json. It's much more secure than loading lua, while being simpler to use than doing everything yourself.
Though it's only dangerous if that code needs to be secured. In most cases, I'm not sure what the point of securing level or animation files would be.
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 2:22 pm
by Automatik
If they are custom levels downloaded on the net, the player could execute code without expecting it ("It's just a level, right? It shouldn't be dangerous.")
And once a program is executed, it can do anything a user can do.
Maurice, on stabyourself.net wrote:I was writing a blogpost about how customizability is always a problem because of the format that I let users specify attributes in (loading lua is too dangerous because people like to download these mods, and text parsers are annoying to write), but then I thought “Why don’t I just use JSON?” and then I just used JSON and it works perfectly. Or I’ll use sandboxing lua.
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 2:30 pm
by MarekkPie
Considering that .love files are just zip files, even the game code is "unsafe". I believe LOVE does do some sandboxing already, but I'll leave it to someone who knows more about it to discuss exactly what they are doing.
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 6:24 pm
by Robin
MarekkPie wrote:Considering that .love files are just zip files, even the game code is "unsafe".
Any game/program you download from the internet is "unsafe", not just LÖVE ones.
MarekkPie wrote:I believe LOVE does do some sandboxing already, but I'll leave it to someone who knows more about it to discuss exactly what they are doing.
Nope. If you're paranoid like me, there's SELÖVE (my fork of LÖVE), which does do sandboxing. I haven't had the time to keep it up to date lately. If anyone wants to help with that, I'd be very thankful.
On the topic of levels downloaded from the internet: either using SELÖVE or constructing your game so that things from the internet are executed in sandboxes should be enough to keep you safe, although they might still crash your game. In the worst case, you'll need to go to the write directory of the game and delete the offending level.
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 6:46 pm
by Automatik
Robin wrote:although they might still crash your game. In the worst case, you'll need to go to the write directory of the game and delete the offending level.
Use pcall(function,args).It's like a try/catch.
It return a boolean, and if succeded, what return the function.
If it crashed, it return the error message. (I used that in Not Pacman++)
MarekkPie wrote:Considering that .love files are just zip files, even the game code is "unsafe". I believe LOVE does do some sandboxing already, but I'll leave it to someone who knows more about it to discuss exactly what they are doing.
Yes, but when someone download a love game, he know that there is code in it.
If he download a level, he don't expect to have potencially malicious code in it, that's why it's us, developpers, who must secure our games.
Re: Fileformats? How to structure? standards?
Posted: Sun Mar 17, 2013 8:28 pm
by Robin
Automatik wrote:Robin wrote:although they might still crash your game. In the worst case, you'll need to go to the write directory of the game and delete the offending level.
Use pcall(function,args).It's like a try/catch.
It return a boolean, and if succeded, what return the function.
If it crashed, it return the error message. (I used that in Not Pacman++)
pcall does nothing against memory leakage and infinite loops. They are worse than errors as they can potentially bring your computer to a grinding halt before you can even quit the game.
Re: Fileformats? How to structure? standards?
Posted: Mon Mar 18, 2013 12:35 am
by Pinkishu
micha wrote:There is no general ready to use lua or löve implementation for your needs.
Yeah, I wasn't asking for implementation
" just if there are some kind of standardized formats developers are encouraged to use (like for some things its encourage to use JSON, or some RFC-format like IRC communication)
Or pointers at how to structure custom foramts