用 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可算是一个简 ...
随机推荐
- Android 学习笔记一 自定义按钮背景图
入门学到的一些组件都是比较规矩的,但在实际应用中,我们需要更多特色的组件,例如一个简单的Button,所以我们必须要自定义它的属性. 遇到的问题:用两张图片来代替按钮,分别表示点击前后 解决方法:用I ...
- 聚沙成塔-linux 常用命令
批量更改文件后缀名 find . -depth -name "*.scss" -exec sh -c 'mv "$1" "${1%.scss}.les ...
- Programming In Scala笔记-第八章、函数与闭包
当程序的代码量增大时,就需要对各功能模块进行分割,这些分割的小模块就是本文中接下来会进行分析的函数.接下来的部分会讲解包括函数嵌套,函数字面量,以及函数值等概念. 一.方法 一会函数一会方法的,是不是 ...
- HDFS基本原理及数据存取实战
---------------------------------------------------------------------------------------------------- ...
- Compile C++ code in Matlab with OpenCV support
Provides a function named as "mex_opencv(src)" The code function mex_opencv(src) ARC = 'x6 ...
- Android安全升级的7.0: Nougat
Tamic http://www.jianshu.com/users/3bbb1ddf4fd5/latest_articles 今年夏天以来,Google做了多种增强的安全性在Android的7.0N ...
- BASH如何获得某个目录下的某类文件的文件名
假设某个目录下有一堆以jpeg为后缀的文件名,我们需要在另一个目录中获得他们的文件名,并输出. 可以联合使用ls,awk,sed等命令来完成. 方法一: 使用ls列出目录下以.jpeg为结尾的文件,然 ...
- 20ViewPager demo1,2:接收ViewPager展示View的使用
Demo1 MainActivity .JAVA package com.qf.day20_viewpager_demo1; import java.util.ArrayList; import ja ...
- qsort函数应用大全
七种qsort排序方法 <本文中排序都是采用的从小到大排序> 一.对int类型数组排序 int num[100]; Sample: int cmp ( const void *a , c ...
- Android事件分发回传机制
转载本博客,请注明出处:点击打开链接 http://blog.csdn.net/qq_32059827/article/details/52489026 之前以一个爷爷给孙子分馒头的故事,初探了安 ...