开发者

Doctrine 2 schema for Game Saves

开发者 https://www.devze.com 2023-04-12 06:54 出处:网络
I\'m looking for a sensible object relationship design for storing variations on default data for a given player in a single player game (save data stored for all players online).

I'm looking for a sensible object relationship design for storing variations on default data for a given player in a single player game (save data stored for all players online).

I'm working on a web开发者_Go百科 game in which there is a tree of 'nodes' representing rooms and objects within them.

Players can move these objects around so I need to save a node state specific to that player.

A common game operation would be getting a node's children. (e.g: all the objects in a room).

In the past I've used two tables and COALESCE

node: id, parent_id, ... node_specific data ... (default settings and parent)

node_state: id, player_id, node_id, parent_id (parent override)

SELECT * FROM node LEFT JOIN node_state ON (node_state.player_id = $player_id
AND node.id = node_state.node_id)
WHERE COALESCE(node_state.parent_id, node.parent_id) = {$node_id}
OR COALESCE(node_state.parent_id, node.parent_id) = 0

This stores the difference between the default tree and the player's and extracts it for that player with Coalesce.

Using Doctrine2 I can do this with a repository method, Native SQL and result set mapping but surely there is a better way?

How do other people handle saving game states for multiple players? Would it make more sense to clone the whole tree for each player? (certainly would make working with Doctrine 2 easier)

0

精彩评论

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

关注公众号