将游戏世界矩阵位置保存到数据库

发布于 2024-11-05 06:21:12 字数 237 浏览 2 评论 0原文

在游戏中,我将玩家的位置和方向存储在 4×4 矩阵中。

当用户退出游戏时,我想将他们的位置和方向保存到后端数据库(SQL),以便他们下次登录时可以从该位置开始。

从 SQL Server 中的可用数据类型来看,仅将矩阵存储为某种字符串表示形式是否正确,或者是否有更好的数据类型选择?

谢谢, Adam

编辑:由于从数据库中读取数据仅在启动时发生一次,因此性能与其说是设计问题,不如说是清晰度问题。

In a game, I have players where their position and orientation is stored in a four-by-four matrix.

When a user logs out of the game, I'd like to save their position and orientation to the backend database (SQL), so that I can have them start at that position next time they log on.

From the available data types in SQL Server, is it correct to just store a matrix as some sort of string representation, or is there a better datatype choice?

Thanks,
Adam

Edit: Since reading the data from the database only happens once at startup, performance is less of a design concern than clarity.

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

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

发布评论

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

评论(1

夏花。依旧 2024-11-12 06:21:12

我会将 4x4 矩阵的每个“单元格”存储在 PlayerPosition 表或类似内容的字段中。由于整个矩阵存储在 1 个文本字段中,您必须对其进行解析才能将其从数据库中拉出,这可能比获取 4 个字段并使用这些字段填充矩阵要慢,因为数据实际上已经被解析。

这种设计将允许您在数据库中标记数据,以指示矩阵的每个字段(单元格)的含义(如果它有意义),并且还允许您根据需要对其进行查询。例如,在未来绘制玩家在世界上的位置的某种分布可能会很有用。能够主要使用 SQL(而不是主要使用额外的编程语言)来完成此操作可能非常强大。

I would store each "cell" of the 4x4 matrix in a field of a PlayerPosition table, or something similar. With the whole matrix stored in 1 text field, you will have to parse it to pull it back out of the database, and that is likely slower than grabbing the 4 fields and using those to populate the matrix because the data is effectively already parsed.

This design would allow you to label your data in the database to indicate what each field (cell) of the matrix means (if it has meaning), and also lets you query against it if you want to. For example, it might be useful, down the road, to plot some sort of distribution of where the players are in the world. To be able to do this with mostly SQL, rather than mostly an extra programming language can be quite powerful.

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