用 boost::multi_index 管理玩家
用 boost::multi_index 管理玩家
(金庆的专栏)
网游服务器上的玩家集合需要多种索引:如用ID查找,角色名查找, 用登录时分配的会话ID查找。
用boost::multi_index进行玩家的管理,可在该容器上建立多种索引。
class Player
{
public:
const PlayerId & GetId() const;
const std::string & GetName() const;
const SessionId & GetSessionId() const;
...
};
typedef boost::shared_ptr<Player> PlayerPtr;
struct tagName {};
typedef boost::multi_index::multi_index_container
<
PlayerPtr,
index_by
<
hashed_unique
<
tag<PlayerId>,
member<Player, PlayerId, &Player::GetId>
>, // hashed_unique
hashed_unique
<
tag<tagName>,
member<Player, std::string, &Player::GetName>
>, // hashed_unique
hashed_unique
<
tag<SessionId>,
member<Player, SessionId, &Player::GetSessionId>
> // hashed_unique
> // index_by
> PlayerSet;
typedef PlayerSet::index<PlayerId>::type PlayerSetById;
typedef PlayerSet::index<tagName>::type PlayerSetByName;
typedef PlayerSet::index<SessionId>::type PlayerSetBySessionId;
使用如:
PlayerSet setPlayers; PlayerSetById & rSet = setPlayers.get<PlayerId>(); PlayerSetById::const_iterator itr = rSet.find(id);
用 boost::multi_index 管理玩家的更多相关文章
- boost::multi_index 提供一种千人在线即时排行榜的设计思路
原文地址: http://www.limerence2017.com/2019/06/23/cpp01/ 做游戏或金融后台开发,经常会遇到设计开发排行榜的需求.比如玩家的充值排行,战力排行等等.而这种 ...
- boost multi_index
/** boost 多索引容器的一般使用 这里使用google 的gmock 库来验证对boost 多索引模板的使用,并验证. 这里是手敲的,可能会有一些字符敲错的情况,编译错误的放,修改一下,同时链 ...
- 使用boost::multi_index高速构建排行榜
使用boost::multi_index高速构建排行榜 前几天在boost的maillist上看到boost::multi_index将要支持ranked_index(邮件内容见附件2),这实乃我等苦 ...
- boost::multi_index 多索引容器
#include "stdafx.h" #include <string> #include <boost/multi_index_container.hpp&g ...
- boost multi_index 插入返回值
boost multi_index 对象插入函数emplace() 的返回值,是一个std::pair<iterator, bool>该pair 的first 是一个插入成功的位置,第二个 ...
- boost multi_index简单了解
#include <string> #include <iostream> #include <boost/multi_index_container.hpp> # ...
- boost:进程管理
概述 Boost.Process提供了一个灵活的C++ 进程管理框架.它允许C++ developer可以像Java和.Net程序developer那样管理进程.它还提供了管理当前执行进程上下文.创建 ...
- BOOST内存管理-intrusive_ptr
参考链接https://blog.csdn.net/harbinzju/article/details/6754646 intrusive_ptr 是shared_ptr的插入式版本.与shared_ ...
- boost asio 异步实现tcp通讯
---恢复内容开始--- asioboost 目录(?)[-] 一前言 二实现思路 通讯包数据结构 连接对象 连接管理器 服务器端的实现 对象串行化 一.前言 boost asio可算是一个简 ...
随机推荐
- MAX(字段)加0与不加0的测试
--max(字段名)中的"字段名"的数据类型是字符型的,"字段名"+ 0后,oracle会隐式的转换成数字型 --测试 )); insert into Test ...
- Android的四大组件及应用安装安全问题(4)
Android的四大组件及组件间通信 如果想对四大组件有深入的了解,那永远不要停留在一些条条干干的SDK API的认识,需要了解他的通讯,他的复用,他的边界问题,这样才会对四大组件有透明的认识. 四大 ...
- Android隐式启动Activity可能存在的坑
转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 本篇文章,对隐式启动Activity再做分析. 有些人可能会说了, ...
- Bootstrap3 栅格系统-媒体查询
在栅格系统中,我们在 Less 文件中使用以下媒体查询(media query)来创建关键的分界点阈值. /* 超小屏幕(手机,小于 768px) */ /* 没有任何媒体查询相关的代码,因为这在 B ...
- Spring Security 基础登录实例
1 新建Java Web项目 导入Jar: 2 修改web.xml <?xml version="1.0" encoding="UTF-8"?> & ...
- 使用GDB调试STL容器
GDB中print方法并不能直接打印STL容器中保存的变量,想知道STL容器保存的变量,使用如下办法: 1. 创建文件~/.gdbinit: # # STL GDB evaluators/views/ ...
- Android存储之SQLite数据库
Android存储之SQLite数据库数据库 创建数据库 package --; import android.content.Context; import android.database.sql ...
- High Executions Of Statement "delete from smon_scn_time..."
In this Document Symptoms Cause Solution APPLIES TO: Oracle Database - Enterprise Edition - Ve ...
- Android Multimedia框架总结(十五)Camera框架之Camera2补充
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52751055 前言:监于5.0之 ...
- 源码篇——Handler消息机制
Handler消息机制 Message 消息 Message.obtain() Message msg = new Message() Handler new Handler(){ handlerMe ...