用 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可算是一个简 ...
随机推荐
- 吐槽:【计算机网络与通信】.张元.高清文字版.pdf
看了这本书的pdf,发现了一处错误,瞬间就不想再看了.新下载了谢希仁老师的<计算机网络>.
- 深入理解Oracle中的随机函数
--Oracle中取随机值的函数 .dbms_random包 dbms_random包提供了一系列的随机值获取函数以及相关存储过程.下面详细讲解常用的函数和过程. ()dbms_random.rand ...
- 干货!一次kafka卡顿事故排查过程
由于一次功能上线后,导致某数据量急剧下滑,给我们紧张的呢!排查过程也是个学习过程(这其中有大部分是领导们的功劳,不过分享给大家应该也不犯法吧,ᐓ) 1. 确认问题的真实性? 被数据部门告知,某数据量下 ...
- 实例演示如何在spring4.2.2中集成hibernate5.0.2并创建sessionFactory
本文地址:http://blog.csdn.net/sushengmiyan/article/details/49388209 文章作者:苏生米沿 本文目的:使用spring4.2.2集成hibern ...
- Ajax原理学习
一.AJAX 简介 AJAX即"Asynchronous Javascript And XML"(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. A ...
- 【SSH系列】Hibernate映射 -- 继承映射
开篇前言 在前面的博文中,小编介绍了hibernate中的映射,一对一,一对多,多对多,单向,双向等,今天这篇博文,小编主要来介绍一下hibernate中的继承映射,小伙伴都知道在C#中,如果想要实现 ...
- github pages + Hexo + 域名绑定搭建个人博客增强版
概述 前面我们用github pages + Hexo 搭建了一个简单版的个人博客系统,但是里面的内容单调,很多功能不够完善,所以我们需要对yelle 的主题进行优化和完善.基本搭建请访问:http: ...
- 国内外主流BI工具介绍和点评
商业智能的应用在国外已广为普及,并且开始不断探索大数据和云技术.而国内,商业智能BI工具在这几年才开始慢慢被接受,企业开始有意识地建立一体化数据分析平台,为经营决策提供分析. 从国内企业使用情况来看, ...
- python学习资料整理
[1] The Python Tutorial [2] Numpy Quick Start Tutorial [3] Python-OpenCV [4] http://www.learnpython. ...
- Android View框架总结(二)View焦点
请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52263256 前言:View框架写到第六篇,发现前面第二篇竟然没有, ...