用 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可算是一个简 ...
随机推荐
- python学习之路网络编程篇(第四篇)
python学习之路网络编程篇(第四篇) 内容待补充
- Rstudio-server 重新登录载入session的问题
Rstudio-server 非常好用,但是免费版的也有一些问题,一个是只能支持在一个客户端的登录,另一个就是每次登录都要导入之前session的问题,对于第二个问题的解决方案,我们可以进入到~/.r ...
- Docker常见仓库Nginx
Nginx 基本信息 Nginx 是开源的高效的 Web 服务器实现,支持 HTTP.HTTPS.SMTP.POP3.IMAP 等协议. 该仓库提供了 Nginx 1.0 ~ 1.7 各个版本的镜像. ...
- Android的四大组件及应用安装安全问题(4)
Android的四大组件及组件间通信 如果想对四大组件有深入的了解,那永远不要停留在一些条条干干的SDK API的认识,需要了解他的通讯,他的复用,他的边界问题,这样才会对四大组件有透明的认识. 四大 ...
- sql group句子
rollup SELECT employee_id,department_id,job_id,SUM(salary) FROM employees WHERE department_id <60 ...
- EBS值集,弹性域常用表
值集 select * from fnd_flex_value_sets select * from fnd_flex_values select * from fnd_flex_valu ...
- FFmpeg源代码简单分析:av_find_decoder()和av_find_encoder()
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- 2.0、Android Studio编写你的应用
Android Studio包含了每个开发阶段的各种工具,但是最重要就是编写代码. 高效编码 接下来的是能够帮助你高效编程的方法. 使用Lint快速修复 Android Studio提供一个叫Lint ...
- API创建/更新员工薪水
DECLARE lb_inv_next_sal_date_warning BOOLEAN; lb_proposed_salary_warning BOOLEAN; lb_approved_warnin ...
- 最详细的制作正式版10.11 OS X El Capitan 安装U盘的方法
原帖地址:http://bbs.feng.com/read-htm-tid-10036487.html 一.准备工作: 1.准备一个 8GB 或以上容量的 U 盘,确保里面的数据已经妥善备份好(该过程 ...