将游戏世界矩阵位置保存到数据库
在游戏中,我将玩家的位置和方向存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将 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.