123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|595|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> best way to save data to a file...

Sat, 08 Mar 2008, 17:05
Orion Pax
Ok...I am thinking of creating a space game but cant think of the best way to save the info of the galaxy into a data file. Info like the location of the planets and ships and other heavenly bodies.....and such....
Sat, 08 Mar 2008, 17:18
power mousey

just curious and wondering, what language are you using?

Perhaps...perhaps. hey Nolan and others
a program and a challenge...a new quest for me to do in BlitzMax OOP. ahhhhhhhhhhh!!, True.


Sat, 08 Mar 2008, 17:36
Evil Roy Ferguso
Given the section, I'll assume that you're using one of the "classic" Blitzes -- in these languages, the "easiest" way is usually to just write how many of an object there is to the save file before writing all of your objects. When loading the file, just read that many in.

Say your save/load functions for an individual object are something like this, and CountSpaceShips() tells you how many space ships are currently active.



You can then do something like this to save:


And read the save file like this:


You can follow the same basic principles for each type quite easily - save the count of players, then the players, save the count of enemies, then the enemies, etc.
Sat, 08 Mar 2008, 17:57
HoboBen
If you're "thinking" of creating a space game, which I would guess means that you haven't gone into a great deal of detail planning stuff yet, I think it might be more important to plan out the structure of the types and creation functions...

To borrow E.R.Ferguson's type above:

; our space ship type
Type SpaceShip
Field hp
Field x#, y#
End Type

I would then decide to make a CreateSpaceShip function that takes values for x, y and maybe hp (optionally), e.g. CreateSpaceShip(x,y,[hp=100]), and then creates the type.

When that part is working/planned, I think then you should implement or plan the loading functions, and have the file that you load use the same CreateSpaceShip function. To edit E.R.F's above:



I'm suggesting this because planning "backwards" like this can make things difficult - instead of writing stuff to go from saved data into your program data, it's easier to implement the program data side (the types) first, and then finally just wrap the saved data in using your exisitng CreateType functions.

... if that made any sense!

-=-=-
blog | work | code | more code
Sat, 08 Mar 2008, 18:22
power mousey

So again, what language are you using Orion Pax?

perhaps Blitz Basic or Blitz 3D?? Or maybe Pure Basic, Ibasic, or even Dark Basic or DBPRO.
I would've helped you if I knew what language you are using. Some version of Blitz I assume or I imagine as my best guess.

I could've told you and shared with you what the others said and posted. But it helps to communicate and know what language you are using.
Oh well, whatever!

Sat, 08 Mar 2008, 21:48
JL235
I doubt this helps, but as this was discussed the other day with Afro I'm just gonna put it out there. With many other languages such as C# and Java you can simply write and read most objects to disk. It's called serialization and in this example would be perfect. In Java it's as simple as:


and hey presto, your whole map (and everything in it) is saved to disk. Reading it back is pretty much the same:
and now it's read your whole map (and everything in it) from disk and converted it to a Map object ready for use.

There are however some exceptions, Objects which are deemed to be 'non-transient' cannot be written to disk. I'm not certain but I'm pretty sure this includes images.

|edit| Yup, it don't include images. But since they are kept on disc anyway I expect that with a little juggling it's still a good solution to a very common problem. |edit|
Sun, 09 Mar 2008, 06:55
Jayenkai
Another option would be, of course, to use XML.
I really dislike XML, but sometimes it's kinda handy.
In this case, if all your data was saved as XML, people would be able to come along, easily tweak the data, and come out with a nice new set of systems/levels/what have you.




That way, using a simple xml reader, you can parse through the data, stick it into a nice neat bunch of type values, or whatever, and then bob's your uncle. Nice easily user-editable/tweakable/addable star system.
eg..



-=-=-
''Load, Next List!''
Sun, 09 Mar 2008, 14:50
Orion Pax
Well power mousey like ERF states, I am using one of the blitzes....Blitz3d to be exact. And from the sound of your reply it sounds like your gettin a bit fussy. I havent been on since my first post. Had to work this morning and because of day light savings time last night I had to get to bed early. But any kind of help would be greatful.

Thanks for the help guys. I was considering writing directly to disk but wasnt sure. Thought maybe a sql flavor would be faster. The game is going to be a multi player online game. And I thought maybe direct disk acess would be too slow? But then again I wouldnt have to write to disk (player info) until they logged off or every so often.

Another thing I was considering was format. Maybe you guys could know something that would be faster and more efficient?

Thanks again for any help.
Sun, 09 Mar 2008, 14:58
JL235
What do you mean by format?
Sun, 09 Mar 2008, 15:32
Orion Pax
Well should I write to file directly as text? I have always used string when reading writing to file for data but just wondering if bytes or short make a difference in speed and size.

EDIT

And would Writeline make a considerable larger file than writestring since it adds in LF + CR?

The map will be considerably big talking about 2000-50000 sectors of space with ports and planets and ships and lots of other things so speed is gonna be important during gameplay

Sun, 09 Mar 2008, 16:24
Phoenix
I take it that you would not generate the sectors procedurally since you talk about loading from files, which makes me say this: 2000-50,000 sectors would mean that you would need hundreds of people designing levels, perhaps even thousands of people. Think realistically.

And, there is a golden rule of thumb you know: optimizations go last of all. When you have the the whole game done; the core system, the UI, the networking, the rendering, etc, that's when you start bothering about optimization. Even then, line feeds and carriage returns wouldn't come close to touching the edge of your performance.

Actually, you wouldn't be loading stuff in real time, would you? That's why there are loading screens. You can load levels in the memory before starting the game.

Sun, 09 Mar 2008, 17:00
Orion Pax
Designing the levels wouldnt require but 1 person. Its going to go like this. A full 3d space game (still trying to figure out how to number the sectors in a 3d environment). The game will have 10 different types of ports for the players to dock to. A random amount of ports of a random type will be placed through out space. Then a random amount of wormholes will be generated through out the game. Sorta star trek style but with tradewars 2002 in mind. Then there will be earth, in the center of the galaxy (just to make it easy), maybe a handfull of randomly generated planets of a random type placed randomly throughout space. Then a handful of AI controlled ships.

That is the basic layout. Going to make it so I can input how many of what I want and it will generate the universe. And make it so at any time I can "re-bang" the universe when seen fit.

Im going to use 7 textures for planets, meaning I'm going to have 7 different planet types. So all I have to do is create a sphere and texture it with the proper texture as needed.

Then there are going to be a handfull of various items in each sector. Like mines, ports, beacons, outpost, probes, debris, comets and asteroids. All of these items are user generated items (most ports will be server generated tho).

So there is only going to be 1 level. Its just a matter of limiting visibility enough for the game to look good but not slow it down. Its going to take some time to code. I have some ideas written down.
Sun, 09 Mar 2008, 18:28
power mousey

well, I was trying to help and its good to communicate
inorder to clarify and discover further information out. And you were still on...by the way.
I just wanted to know what language you used so I could show you some code examples.
Provided I know and have used the language.

In any case....
doesn't matter anymore
nuff said to you, and...







Sun, 09 Mar 2008, 18:48
Nolan
No need to be an ass, Mousey. He told you the language, and it's your choice to help him -- but don't act like he did something wrong.

-=-=-
nolandc.com
Sun, 09 Mar 2008, 19:17
HoboBen
Sounds like you've got some exciting plans there, Orion - but to add to Pheonix's comment about optimization, see rules 1+2

In fact, everything on that page is golden - reading that short page I would say has had the best effect on my programming skills out of anything that I have ever read. When I find a project getting complicated, taking a moment to remember Pike's notes there can put me on the right path.

-=-=-
blog | work | code | more code
Sun, 09 Mar 2008, 19:25
power mousey

I'm not being an ass. Just laying it down of what happened. But I will take your advice, ass.
Sun, 09 Mar 2008, 19:30
Stealth
<Flame War>



|edit| Jay sez:By PowerMousey.. AGAIN |edit|

-=-=-
Quit posting and try Google.
Sun, 09 Mar 2008, 19:37
JL235
Even though I hate it, I'd advise going down the XML root as it won't tie you to one language. You can write the client in BB, the server in C#/Java and use Ruby/PHP/Python/Perl scripts to look at game info via the web.
Sun, 09 Mar 2008, 19:50
Orion Pax
Thanks HoboBen! That page makes a lot of good points. And I will bookmark it and make a point to read it when I get stuck.

JL235, I wish I could do it like that but I have no skills in C# or java. I have done some in PHP and know of excellent sources to learn php on the net.
Sun, 09 Mar 2008, 21:04
JL235
My point wasn't that you should use x or y language. I only named those ones as examples. My point wasn't actually to do with any specific languages, that was the real point.

XML is one universal way to structure data for use between systems. By storing your game info in XML then you are not tying yourself to any specific system, platform, machine, program, language or framework. It will be completely independent of your program. It's simple and keeps your options open, which both can only be a good thing.
Mon, 10 Mar 2008, 07:47
mike_g
Yes, thats a nice thing about XML. However I wouldent recommend it for a game thats storing large sets of data as the tags create a hell of a lot of bloat.

You can read any file in pretty much any language as long as you know how its structured, and that can be commented in a readme or something.
Mon, 10 Mar 2008, 17:26
Afr0
Yes, thats a nice thing about XML. However I wouldent recommend it for a game thats storing large sets of data as the tags create a hell of a lot of bloat.


Agreed.
Note to MMO developers: XML can be good for pretty much anything (though I personally don't like it much) except as a replacement for database functionality.
Things that should *only* be stored in a database due to security, speed, avoiding bloat, maintainability and other factors, include;

- Account Details
- Character Details
- Post/Mail Details (this one is debatable, however)
- Auction (House) Details

Edit: If you want a horrifying example of what I'm talking about, download the RunUO source from RunUO.com

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 11 Mar 2008, 04:58
HoboBen
I usually prefer more compact ways of storing data than XML, but when the data is hierarchical, such as universe > galaxies > solar systems > words, it can be quite a nice way of structuring things.

Course, you usually don't want to load the entire universe at once, so you could structure things by putting them into separate folders instead, or a combination of the two, e.g. folders for galaxies containing XML documents that contain the properties of all the worlds in a solar system.

-=-=-
blog | work | code | more code
Thu, 13 Mar 2008, 19:22
Orion Pax
Well I finally decided that I am just going to use a code. And keep it as small and simple as possible. For example all the sectors will be listed numerically. The first thing it comes to is how many sectors there are in the universe. Then a separator. Then you will see an 'X', a 'Y' and a 'Z'. Immediately following each is the location of the sector in physical space in the game. Then after that you will see a P12 meaning 2 planets P1 stands for Planets and P2 for Ports. Then after that a separator and then the first planets type 0-6 then a separator and the planets name. so on and so forth.

An abbreviated code I guess.
Thu, 13 Mar 2008, 20:00
Jayenkai
Sounds good enough to me!