• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Norman Barrows

binary save, adding vars, and changing savegame file formats

29 posts in this topic

That's just scary code to see all those casts and sizeofs written out over and over.

 

tell me about it!

 

i usually use inline wrapper functions like writefilebin()

 

when switching from text to binary, i was using the newer fwrite() with the extra checks and such. ran almost twice as slow. so then i dug into the docs and found that good old slam bytes from mem to disk was now called _fwrite_nolock(). 

 

when coding things like that, i'll make a "template"  fwrite....(,,,,);   with blanks to be filled in.

cut and paste, then just fill in the blanks. glorified word processing, that's all most coding is.

 

but i don't usually write code like that. usually i'd have a nice inline wrapper function that is designed to minimize typing. 

 

this was the first test code. and it worked so well (compared to text and locking version) there was no need to touch it.

 

but i'll definitely be writing a wrapper for it, as it looks like that will be required for save games in all my titles. so it gets added to Rockland's in-house game library.

0

Share this post


Link to post
Share on other sites

Shader "shiny" requires some new vertex information that only needs to exist for objects using "shiny" do you really want to add a field to a fixed structure and require that ALL the data in your game be re-built just to accommodate a single new object?

 

I would think that in OO one would handle that with inheritance. Dealing with the save file format is another issue though.

 

I would run into the problem you described when first working on models and animations. I would add a new field to the declaration of a model, then have to add that to all models already made. Fortunately, I was re-creating a modeling and animation system i'd built in the past so it only took a few models before i got all the parts in place - i think i forgot scaling the first time. so i had a nice 20 limb hierarchical animation system, but couldn't scale individual limbs.

0

Share this post


Link to post
Share on other sites

well, i decided to try a version that saves individual fields of each struct, written as binary. this way, when i add a new variable to a struct, i add it to save, then load and save the playtest games to convert them, then add it to load, and i'm done. i used inline wrappers for _fwrite_nolock. save times increased from 2 seconds for writing array of structs to 3 seconds for writing individual fields of structs. no keys. IDs, sizes, or version numbers, just the struct fields as they appear in the declarations. then i decided to try buffering it. i wrote a version that malloc'd a 100 meg buffer, memcpy'd the struct fields to the buffer, then wrote the entire thing with a single _fwrite_nolock. and then free the buffer of course. and buffering got me exactly sqaut. still 3 seconds to save.

 

lessons learned:

 

1. keeping the file open means you lose it if the power goes out. not a robust design.

2. buffering 60 meg of data vs writing it out one int and float and char[100] at a time did not provide any significant speedup. lots of calls to _fwrite_nolock is not a bottleneck.

3. writing more data slows things down (obviously). so the flexibility of a size,id,value format must be weighed against the overhead of the additional data written. a size,id,value format will always be slower than a format that simply saves fields in a pre-defined order. 

4. its more work to save individual fields than it is to save an entire struct, so its more work at first to create the code to save a struct one field at a time. however its much less work to add a new variable to a struct and convert existing save files when saving things one field at a time.

 

In my case, i only have to deal with in-house old file formats. for dealing with old file formats on the user's pc, you'd init all your data structures to default values, then load. if you get EOF, stop loading. new variables always appear at the end of the file, so when you run out of file, that's all there is to load form this older format, and the newer vars use the default values. when it saves it uses the new format, saving the new vars along with the loaded old data. this lets you import older file formats by simply adding EOF checks to reads for new variables added to the end of the format.

 

has anyone heard of a "init, load vars til eof, save all"  algo for automatically importing old save games? I don't recall that one in school (software engineering OSU). Algos from the regular world of computing (size,ID,value and "keep the file open") were mentioned. but as usual, what they teach in the regular computing world has issues (extra overhead or data loss on power outage) when it comes to using it for games.

0

Share this post


Link to post
Share on other sites

3. writing more data slows things down (obviously). so the flexibility of a size,id,value format must be weighed against the overhead of the additional data written. a size,id,value format will always be slower than a format that simply saves fields in a pre-defined order. 

 

it occurred to me that saving fields in a predefined order is essentially the same thing as a size,id,value format, where the size, id, and order of appearance are implicitly defined by the code that loads and saves the file.

0

Share this post


Link to post
Share on other sites

The other day i tried adding a new variable to the file format for the first time and it works great. just add the var to the struct, then add a line to load and save. now i have text file flexibility and (probably) the fastest possible binary speed.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0