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
Fileformats? How to structure? standards?
Re: Fileformats? How to structure? standards?
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')() ).
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')() ).
Check out my blog on gamedev
Re: Fileformats? How to structure? standards?
Except it's very dangerous, because insecured(It's code after all).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.
You can also use Json. It's much more secure than loading lua, while being simpler to use than doing everything yourself.
-
- Party member
- Posts: 235
- Joined: Sat Dec 15, 2012 6:54 am
Re: Fileformats? How to structure? standards?
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.Automatik wrote:Except it's very dangerous, because insecured(It's code after all).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.
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?
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.
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?
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Fileformats? How to structure? standards?
Any game/program you download from the internet is "unsafe", not just LÖVE ones.MarekkPie wrote:Considering that .love files are just zip files, even the game code is "unsafe".
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.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.
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.
Help us help you: attach a .love.
Re: Fileformats? How to structure? standards?
Use pcall(function,args).It's like a try/catch.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.
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++)
Yes, but when someone download a love game, he know that there is code in it.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.
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Fileformats? How to structure? standards?
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.Automatik wrote:Use pcall(function,args).It's like a try/catch.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.
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++)
Help us help you: attach a .love.
Re: Fileformats? How to structure? standards?
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)micha wrote:There is no general ready to use lua or löve implementation for your needs.
Or pointers at how to structure custom foramts
Who is online
Users browsing this forum: No registered users and 15 guests