473,473 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Saving Objects

I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.

Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html

I seem to get somthing to save. So far in my handle for the pieces I
have a save function that will have the pieces save themselvs. Here
is the data I want to save:

class unit{
protected:

coord loc;
coord currentLoc;
graphics * gr;
tbox * combatBox;
std::vector<color>colors;

float attack;
float dattack;
float defence;

More numbers...

Here is how I am starting:
void unit::write(std::fstream& f){

f.write((char*)&loc, sizeof (loc));
f.write((char*)&colors, sizeof (colors));

Am I going about it the right or wrong way?

Jan 31 '07 #1
10 2062
On Jan 31, 11:56 am, "JoeC" <enki...@yahoo.comwrote:
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.

Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html
[snip]
Am I going about it the right or wrong way?
The FAQ covers this subject in depth:

http://www.parashift.com/c++-faq-lit...alization.html

Best regards,

Tom


Jan 31 '07 #2
On Jan 31, 11:21 am, "Thomas Tutone" <Thomas8675...@yahoo.comwrote:
On Jan 31, 11:56 am, "JoeC" <enki...@yahoo.comwrote:
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.
Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html

[snip]
Am I going about it the right or wrong way?

The FAQ covers this subject in depth:

http://www.parashift.com/c++-faq-lit...alization.html

Best regards,

Tom
Thanks I did go to that link in my research but I am not sure how it
is supposed to help me. I don't see any exaples of saving data
there. I created a two person game and I would like to create a play
by e-mail system where after each turn the file of pieces are saved
and sent off to play the next turn. I also have a city control object
and the number of points each side has.

Would it be better if I created a text file put in all the necessary
information and sent that off and use the objects contsrtuctors and
set the approate variables when the program is loaded back up. I have
used files to some extent already, it is that I have yet to do
anything complicated and I would like to get suggestions on stratigies
or at least a starting point.

Jan 31 '07 #3

JoeC napsal:
I am writing a game and all my game pieces are stored in a single
vector of piece handles. I have the basics I can read and write char
and number files but I am trying to do comthing more complicated. I
am trying to save the data I need to save and I can fill in some when
the necessary data is saved.

Vector->piece handle -pointer to the pieces. How do I go about
saving that data into a file. I have been doing some research to some
sites: http://www.angelfire.com/country/aldev0/cpphowto/
cpp_BinaryFileIO.html

I seem to get somthing to save. So far in my handle for the pieces I
have a save function that will have the pieces save themselvs. Here
is the data I want to save:

class unit{
protected:

coord loc;
coord currentLoc;
graphics * gr;
tbox * combatBox;
std::vector<color>colors;

float attack;
float dattack;
float defence;

More numbers...

Here is how I am starting:
void unit::write(std::fstream& f){

f.write((char*)&loc, sizeof (loc));
f.write((char*)&colors, sizeof (colors));

Am I going about it the right or wrong way?
Hi. I recommend you to find some XML library and store your data in
XML file. If XML is not for any reason what you can use, use text
file. It will save you lot of time with reading data and it is better
portable too.

Jan 31 '07 #4
XML is a very good choice, simply because the format is standardized
and it's human-readable. You should look into XML formats and decide
if that's the course for you. If so, then try http://www.grinninglizard.com/tinyxml/,
which I found to be a very easy-to-use C++ XML library. I might have
some XML code around on my harddrive so if I'll poke around to see if
there's anything that could be of use to you (I used to write games
using TinyXML for saving/loading files as well).

If you don't want to use XML, then the way you're going about it is
fine as well, if your game is simple enough. Beware though, if you
make changes between your saving routine and your loading routine
you'll run into problems. For example, if you change the order in
which you save but leave the order in which you load different
variables, that'll run you up the crapper. XML will solve that problem
because every variable is tagged, so you know *exactly* what you're
loading.

Hope that helps,
Cheers,
Henry

http://hamath.blogspot.com - Science, Technology, Interesting Stuff
Blog

Feb 1 '07 #5
On Jan 31, 6:34 pm, "gamedia...@gmail.com" <gamedia...@gmail.com>
wrote:
XML is a very good choice, simply because the format is standardized
and it's human-readable. You should look into XML formats and decide
if that's the course for you. If so, then tryhttp://www.grinninglizard.com/tinyxml/,
which I found to be a very easy-to-use C++ XML library. I might have
some XML code around on my harddrive so if I'll poke around to see if
there's anything that could be of use to you (I used to write games
using TinyXML for saving/loading files as well).

If you don't want to use XML, then the way you're going about it is
fine as well, if your game is simple enough. Beware though, if you
make changes between your saving routine and your loading routine
you'll run into problems. For example, if you change the order in
which you save but leave the order in which you load different
variables, that'll run you up the crapper. XML will solve that problem
because every variable is tagged, so you know *exactly* what you're
loading.

Hope that helps,
Cheers,
Henry

http://hamath.blogspot.com- Science, Technology, Interesting Stuff
Blog

Thanks, I didn't know that XML was out there I though it was
Extendable Marck-up Language.

Feb 1 '07 #6
JoeC wrote:
On Jan 31, 6:34 pm, "gamedia...@gmail.com" <gamedia...@gmail.com>
wrote:
>XML is a very good choice, simply because the format is standardized
and it's human-readable. You should look into XML formats and decide

Thanks, I didn't know that XML was out there I though it was
Extendable Marck-up Language.
It is. XML stands for eXtensible Markup Language. However, gamedia is
right. It's an excellent language for storing structured data.

Feb 1 '07 #7
It is, XML stands for eXtensible Markup Language. But the power of it
comes from allowing you to custom-define any sort of data you want,
which is helpful. Anyways, good luck!

Cheers, Henry Yuen
--------
http://hamath.blogspot.com - Science, technology, and interesting
stuff Blog

Feb 1 '07 #8
ga********@gmail.com wrote:
It is, XML stands for eXtensible Markup Language. But the power of it
comes from allowing you to custom-define any sort of data you want,
which is helpful. Anyways, good luck!
Darn near identical and simultaneous posts! Wow!
Feb 1 '07 #9
On Jan 31, 9:32 pm, red floyd <no.s...@here.dudewrote:
gamedia...@gmail.com wrote:
It is, XML stands for eXtensible Markup Language. But the power of it
comes from allowing you to custom-define any sort of data you want,
which is helpful. Anyways, good luck!

Darn near identical and simultaneous posts! Wow!
That is jaw-dropping.

Feb 1 '07 #10
On Jan 31, 11:32 pm, red floyd <no.s...@here.dudewrote:
gamedia...@gmail.com wrote:
It is, XML stands for eXtensible Markup Language. But the power of it
comes from allowing you to custom-define any sort of data you want,
which is helpful. Anyways, good luck!

Darn near identical and simultaneous posts! Wow!


I don't know much about XML but trying the save information with
fstream is getting pretty cumbersome. It dosn't even work when I am
trying to save information in a vector. When I get some time I will
take a closer look at XML

Feb 1 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ramon | last post by:
Hi! I have a fairly complex object (with other objects as attributes (which in turn, have other objects as attributes), methods, etc) and I would like to save it to the disc so I can load it in...
4
by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle...
4
by: Jerivix Entadi | last post by:
I'm attempting to create an application to work with a fluid database of people. I'm doing this in a command line, text-based manner. I need to know two things: 1) How do I save data, perhaps a...
1
by: Inon Zukerman | last post by:
hello everyone. My problem is as follows : my application keeps a hashtable with Outlook.MailItem objects. I need to save and load this hashtable (with those objects inside) when starting and...
4
by: John Kandell | last post by:
Hi, Would someone be able to shed some light on what is the cost of saving a DataTable to session vs saving a custom object of the same data. For example, let's say I had a DataTable with 1000...
3
by: shuisheng | last post by:
Dear All, Assume I have two classes: material and shape, as follows class Material { double density; // material attribute, may have more vector<Shape*pShape; // shape objects assocaited...
4
by: ulaskaraoz | last post by:
Hi, I have a std::map instance that I want to save into harddisk so that I donot have to recompute it each time. The map itself is keyed by a string and the values are pointers to other objects....
2
by: tomlebold | last post by:
It takes five minutes when using object linking and embedding to save a PDF file using a normal from. The data type is image in an SQL Sever table. We are trying to keep track of the legal...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.