saving with C++

Started by
13 comments, last by izua 17 years, 4 months ago
Try a site like: Beej's Networking Guide.

It kinda sounds like you are more concerned about learning how to set up a client-server archetecture,
"as-if" you are making a multiplayer game. That site should show you the basics you need to set up a
client-server protocol you can use to send you data to the server. The server in turn should then use
standard file io (fstream/FILE*) to put the data on the server's diskdrives.

Expanding on what exactly your program is/does and the end goals will help people to give you
more tailored information. Because there is "a way" "the easy way" and "the hard way" for doing everything.
And we(the community) don't know if you are set on "the hard way" because you dont understand what you are
doing, or if you want "the easy way" of doing something you didn't explain well that you were trying to do.

[Edited by - KulSeran on November 29, 2006 5:52:13 PM]
Advertisement
When someone plays your game, he plays it on his computer. Normally, you save the game on his computer. If you want to save it on a server, you'll need to make your game connect over the internet to the server, then tell the server what you want it to remember. The server must have some program installed on it (which you'll have to create too), that knows how to save something on that computer.

To save something on the computer the game is ran at, loopup fopen(). It'll let you save to a file. It won't, however, let you save your game on another computer (a server), and there is no simple way of just doing that.
You are looking for a magic bullet that doesn't exist. If you insist on server-side storage (which seems bizarre for a singleplayer game) then you need to make a server-side program that can accept save requests and handle file organization, and then in the client you need to set up a network connection with the server. This is all explained in the network guide linked above.

People are answering your question with very valid and useful help. It is you that refuses to listen. Please learn to control yourself and think about other peoples ideas before you dismiss them.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

What you save and how you save depends entirely on your own specific game. Saving means saving state. state means things that are different between frames and things that are important and meaningful to the game world.

For instance for a typical game entity you'd save things like:

current hitpoints
AI state (moving, shooting, etc)
facing angle
current velocity

Now the _what_ you save is entirely up to you.

The _how_ you save is using "binary file I/O". You can google that phrase for code.

The basic algorithm of saving is this:

User Clicks save
Game iterates all objects that need to be saved
for each object dump it's type and it's data to the file stream
after iterating all objects close the file stream.
data is now saved in some file on the HD.


User clicks Load
Game opens the save file
game processes the save file re-instancing every object that needs to be created
as it's instancing each object it loads the saved data into that object

-me
I think i got it.
So you want a single-player desktop game with server-side saving..

here's what i'd do if i'd go for easy code:

client side - curl. Maybe i even encrypt the data in a simple way.
server side - apache and php, driven by mysql. (well, it's easy). There should be some hidden form, to where curl will post the savedata, and php will handle it to mysql. you'll need to take some additional measures to prevent hacking.

another way is to go straighforward with classic networking, but it's not as easy as curl. or you can try sdl_net :)

This topic is closed to new replies.

Advertisement