开发者

Saving Game World Matrix Position to a Database

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 m开发者_Python百科atrix 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜