保存/加载 iPhone 游戏数据的最佳方式

发布于 2024-07-09 16:44:25 字数 279 浏览 12 评论 0原文

我正在开发一款益智游戏,游戏引擎拥有复杂的对象层次结构,从游戏演员到矢量再到过渡动画。 根据游戏状态,它们的总数可能从 10 到 1000(在极端情况下)。 我一直在推迟这个时刻,直到我必须致力于保存和加载所有这些混乱的事情,因为我在这方面没有经验,但现在我担心的时刻即将到来。

为此使用 NSKeyedArchiver 是个好主意吗? 它的概念看起来很强大。 这样我就可以重建对象状态,但这是否包括已保存对象之间的指针? 它的性能表现如何? 应用程序终止时系统是否有时间将所有这些对象保存在磁盘上?

I'm working on a puzzle game, the game engine holds a complex hierarchy of objects, from game actors to vectors to transition animations. Depending on the game state, they might add up from 10 to 1000 (in extreme cases). I've been delaying the moment until I'd have to work on the saving and loading of all that mess, as I have no experience on this, but now the moment I was fearing is about to arrive.

Is it a good idea to use NSKeyedArchiver for this? Its concept seems powerful. That way I could rebuild the objects states, but does that include the pointers between saved objects? And how does it behave performance-wise? Will the system have time to save all these objects on disk on app termination?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是年少的欢喜 2024-07-16 16:44:25

NSKeyedArchiver 非常强大,但它不会让您保留对象之间的链接(除非您在解档后自己添加它们)。 如果您可以/需要以原子方式存储整个数据集,那么 NSKeyedArchiver 可能是最佳选择,但如果有比父子关系更复杂的东西,您将需要进行一些“重新水合作用”。

我们有一个复杂的数据对象层次结构,我们将它们存储到 SQLite 数据库中,并在提取它们时重新连接它们。

NSKeyedArchiver is quite powerful, but it will not let you retain linkages between objects (unless you add them yourself post-unarchiving). If you can/need to store your entire data set atomically, then NSKeyedArchiver is probably the way to go, but there will be some 're-hydration' involved on your part if there's anything more complex then parent-child relationships.

We have a complex hierarchy of data objects, we store them out to an SQLite database, and re-hook them up when we extract them.

如日中天 2024-07-16 16:44:25

我选择了 NSKeyedArchiver,它确实维护对象之间的引用。 请参阅此处:归档互连对象的简单方法

I went for NSKeyedArchiver, which does maintain references between objects. See here: Easy way to archive interlinked objects

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文