游戏如何处理保存的内容? [英] How do games handle saved content?

查看:69
本文介绍了游戏如何处理保存的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SO上没有看到这个问题的答案,这让我担心它非常简单,我只是想念一些东西,但事情就这样了。

I don't see an answer to this question here on SO which makes me afraid that it's incredibly simple and I'm just missing something but here goes.

背景知识,随时可以跳过:我需要一门我几年前就跳过的学士学位课程。从理论上讲,它是计算机图形学,但是自从我离开以后,它已经变得更加游戏开发。这很棒,因为对我而言,它比填充算法和翻译更有趣,而且以前还没有。这是四年制的课程,每隔两年才提供一次,但是我设法说服了该部门让我对同一主题进行了四年制的独立研究,并称其足够好。

Background, feel free to skip: I need a single course for my bachelor's degree that I skipped out on years ago. Theoretically it's Computer Graphics, but since I left it has become more Game Development. And that's great because to me it's more interesting than the fill algorithms and translations and whatnot that it used to be. It's a 4th year course only offered every other year, but I've managed to talk the department into letting me take a 4th year independent study on the same topic and call that good enough.

运行独立研究的教授没有教授实际的计算机图形学课程,因此,尽管他是一个聪明的人,但这并不是他的专业。因此,我的大部分问题都留给了我,还有一本教科书和互联网。您知道...应该像独立研究一样。 :)

The prof "running" the independent study doesn't teach the actual Computer Graphics course so while he's a smart guy this isn't really his field. So most of my questions are left to me, a text book and the internet. You know...like an independent study should be. :)

/背景

我有一个喜欢开发有趣游戏系统的伙伴。我计划将他的一款台式游戏带入使用XNA的计算机游戏中。

I've got a buddy that likes to develop game systems for fun. I plan to take one of his table top games and make it into a computer game using XNA.

我没有预见到任何游戏机制上不可克服的挑战,但有一件事情我很好奇大多数游戏如何保存其内容?我的意思是说,有两种方式,希望我能清楚地表达出来。

I don't foresee any insurmountable challenges with the game mechanics but one thing I'm curious about is how do most games save their content? I mean that in a couple of ways and hopefully I can express them clearly.

以您曾经玩过的任何RPG游戏为例。您可以点击保存按钮,保存世界,您的角色信息以及其他必要信息。然后,您可以点击加载按钮,然后将其恢复。

Take the case of any RPG you've ever played. You can hit the "Save" button and save the world, your character's information and whatever other information is necessary. Then later on you can hit the "Load" button and bring it back.

或者是NPC对话。当我碰到Merchant#853时,他随机地吐出3种不同的问候中的一种。

Or the case of NPC dialogue. When I bump into Merchant #853 he randomly spits out one of 3 different greetings.

我还能想到其他一些东西,但实际上它们只是相同的变化而已主题。即使有这两个示例,在我看来也可以使用同一机制,但是该机制是什么?

There are others that I can think of but they're really just variations on the same theme. Even with those two examples it seems to me the same mechanic could be used, but what is that mechanic?

我已经从事Web开发多年了,所以我自动跳到数据库!。数据库是解决任何问题的方法。我可以看到它在这里如何工作,但是开销似乎很陡。 这是我的6mb编译游戏...哦,还有68mb MySQL安装。甚至更糟,因为我使用的是XNA,也许我需要找到一种捆绑SQL Server的方法。 :)

I've been doing web development for years so my mind automatically jumps to "databases!". A database is the solution to any problem. And I can see how it could work here but the overhead seems pretty steep. "Here's my 6mb compiled game...oh and 68mb MySQL installation." Or even worse since I'm using XNA, maybe I'd need to find a way to bundle SQL Server. :)

我想也许是XML,但这对我来说也不对。如果要在XBox上运行,它将如何工作?还是Zune? (这些对于我的工作不是必需的,但是必须在某个解决方案中将它们考虑在内。)

I thought maybe XML but that doesn't feel right to me either. How would it work if I wanted to run on the XBox? Or Zune? (Those aren't necessary for what I'm doing, but there must be a solution somewhere that takes them into account.)

有人知道这个秘密吗?还是有一些想法?

Anyone know the secret? Or have some ideas anyway?

感谢
Jeff

Thanks Jeff

推荐答案

保存游戏的主要方式有两种,一种简单,一种复杂。第一种方法是简单地存储当前水平,当前分数和其他一些统计数据。这在超级马里奥银河(Super Mario Galaxy)等游戏以及最早期的基于控制台模块的游戏中都可以看到。保存游戏不会恢复您的确切位置,而只会恢复您完成的关卡。这些保存游戏通常非常简单,所需的内存也很少。

There are two main ways how games are saved, a simple one and a complex one. The first way is to simply stores the current level, the current score and a handful of other stats. This is seen in games such as Super Mario Galaxy and most earlier console module based games. The save game doesn't restore your exact position, but just which levels you have completed. These save games are generally very simple and require very little memory.

第二种方法不仅可以存储整体进度,还可以存储每个小细节,例如敌人的位置,它们当前的动画帧等,以便加载保存游戏将使您处于停止的确切位置,所有敌人都就位,而不是回到关卡开始时。这些保存游戏的大小通常会比其他版本大得多,因此通常会在PC游戏中看到。

The second way not only stores your overall progress, but stores each and every little detail, such as enemy positions, their current animation frame and so on, so that loading a save game will place you at the exact spot where you stopped, with all the enemies right in place, instead of back at the start of a level. These savegames tend to get much bigger than the other version and thus are mostly seen on PC games.

这两种方案都不使用数据库,因为数据库的目的是为了提供动态查询数据结构的能力,游戏需要的不是查询单个片段的方法,而是静态存储它们的方法。当保存游戏被加载时,它被完全加载到内存中,游戏引擎从那里开始处理数据。有少数例外,例如MMORPG可能会在数据库上运行,但单人游戏通常不起作用。

Databases are used in neither of these schemes, as the purpose of databases is to provide the ability to dynamically query data structures, what the game however needs isn't a way to query individual pieces, but just a way to statically store them. When a savegame is loaded, it is loaded completly into memory and from there on the game engine does its thing with the data. There are a handful of exceptions, such as MMORPGs which might work on a database, but single player games generally don't.

数据的实际存储方式取决于游戏。最常见的似乎是简单的二进制数据格式,因为在磁盘空间方面它们比XML更好。在较旧的游戏中,那些二进制格式经常会在游戏过程中原始存储一些内存,因此它们没有经过深思熟虑的结构,并且在发行了补丁或其他版本的游戏时经常会崩溃,在某些现代版本中游戏仍然如此。 XML也可以使用,也可以使用任何其他基于文本的文件格式。

How the data is actually stored depends on the game. Most common seem to be simple binary data formats, as they are much better in terms of disk space than XML. In older games those binary formats where often raw dumps of a pieces of memory of the games process, so they didn't have any well thought out structure and often broke when a patch or a different version of a game got released, in some modern games that's still the case. XML can be used as too, as well as any other text based file format.

在很大程度上,这更多的是游戏设计问题,而不是编程问题一个可以保存的游戏可以极大地改变其玩法。但是,仅保存级别编号和一些统计信息的简单方法却易于实现,因为只需几行代码。尽管第二个需要大多数类的序列化,但是对于复杂的游戏而言,这可能是一个棘手的问题,并导致许多细微的错误。

In large part this is more a game design issue than a programming one, as they way a game can be saved can drastically change how its played. The simple way, where you just save the level number and some stats, is however a lot easier to implement, as its just a few lines of of code. While the second one requires serialization of most of your classes, which for a complex game can be quite a tricky issue and lead to many subtle bugs.

这篇关于游戏如何处理保存的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆