您的位置:首页 > 运维架构 > 网站架构

MMORPG大型游戏设计与开发(客户端架构 part4 of vegine)

2014-08-03 15:00 615 查看

昨天是七夕,祝大家都过的快乐,希望这句迟到的问候不会造成大家心中的困扰。这一节讲到了前端比较重要的模块,性能以及调试异常模块。一个应用的性能往往是最核心的部分,就像人身体的各个器官一样,一小部分也不能马虎,否则你得到的只是你想象不到的苦果。在这里,我们封装了性能采集,调试输出、变量打印,以及异常收集。希望大家会对这方面有所了解与进步。


结构



CODE

ax模块,文件profile.h

/**
* PAP Engine ( -- )
* $Id profile.h
* @link -- for the canonical source repository
* @copyright Copyright (c) 2013-2014 viticm( viticm@126.com )
* @license
* @user viticm<viticm@126.com/viticm.ti@gmail.com>
* @date 2014-3-16 11:56:11
* @uses the ax profile module, just for system performance
*/
#ifndef VENGINE_CAPABILITY_AX_PROFILE_H_
#define VENGINE_CAPABILITY_AX_PROFILE_H_

#include "vengine/config.h"

namespace vengine_capatility {

namespace ax {

namespace profile {

VENGINE_API void samplingbegin();
VENGINE_API void samplingend();
VENGINE_API void pushnode(const char* name, const char* parent = NULL);
VENGINE_API void popnode(const char* name);
VENGINE_API void report();

struct autosampling_t {
autosampling_t();
~autosampling_t();
};

}; //namespace profile

}; //namespace ax

}; //namespace vengine_capatility


ax模块,文件trace.h

/**
* PAP Engine ( -- )
* $Id trace.h
* @link -- for the canonical source repository
* @copyright Copyright (c) 2013-2014 viticm( viticm@126.com )
* @license
* @user viticm<viticm@126.com/viticm.ti@gmail.com>
* @date 2014-3-16 17:43:42
* @uses vengine capability ax trace module
*/
#ifndef VENGINE_CAPABILITY_AX_TRACE_H_
#define VENGINE_CAPABILITY_AX_TRACE_H_

#include "vengine/config.h"

#define AXTRACE_WND_INVALID ((uint8_t)-1)

namespace vengine_capability {

namespace ax {

typedef enum {
kValueInt8,
kValueUint8,
kValueInt16,
kValueUint16,
kValueInt32,
kValueUint32,
kValueInt64,
kValueUint64,
kValueFloat32,
kValueDouble64,
kValueString
} value_enum;

VENGINE_API void trace(uint8_t winnumber,
uint8_t typenumber,
const char* format,
...);
VENGINE_API void var(uint8_t winnumber,
uint8_t typenumber,
value_enum variabletype,
const char* valuename,
void* value);

}; //namespace ax

}; //namespace vengine_capability

#endif //VENGINE_CAPABILITY_AX_TRACE_H_


文件debuger.h

/**
* PAP Engine ( --)
* $Id debuger.h
* @link -- for the canonical source repository
* @copyright Copyright (c) 2013-2014 viticm( viticm@126.com )
* @license
* @user viticm<viticm@126.com/viticm.ti@gmail.com>
* @date 2014-3-26 10:34:10
* @uses vengine capability debuger module
*/
#ifndef VENGINE_CAPABILITY_DEBUGER_H_
#define VENGINE_CAPABILITY_DEBUGER_H_

#include "vengine/config.h"
#include "vengine/kernel/node.h"

namespace vengine_capability {

class Debuger : public vengine_kernel::Node {

VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_capability_Debuger);

public:
virtual void infotrack_reset(int32_t width, int32_t height) = 0;
virtual void infotrack_addpoint(int32_t x, int32_t y) = 0;

};

}; //namespace vengine_capability

#endif //VENGINE_CAPABILITY_DEBUGER_H_


文件profile.h

/**
* PAP Engine ( -- )
* $Id profile.h
* @link -- for the canonical source repository
* @copyright Copyright (c) 2013-2014 viticm( viticm@126.com )
* @license
* @user viticm<viticm@126.com/viticm.ti@gmail.com>
* @date 2014-3-19 13:42:44
* @uses vengine capability profile module
*/
#ifndef VENGINE_CAPABILITY_PROFILE_H_
#define VENGINE_CAPABILITY_PROFILE_H_

#include <hash_set>
#include <hash_map>
#include "vengine/config.h"

namespace vengine_capability {

namespace profile {

struct treenode_t;

//堆栈中的节点(用于push/pop)
struct VENGINE_API stacknode_t {
STRING name; //名称
LARGE_INTEGER starttime;
treenode_t* treenode; //树形节点指针
stacknode_t(const char* _name = NULL, const char* extensionname = NULL);
};

//堆栈
struct stack_t {
stack_t() {};
enum {
kStackNumberMax = 256,
};
//节点堆
stacknode_t stacknode_list[kStackNumberMax];
//栈顶指针,初始为0
uint16_t topindex;
#ifdef __SGI_STL_PORT
typedef std::hash_set<STRING> hash_nameset;
#else
typedef stdext::hash_set<STRING> hash_nameset;
#endif
hash_nameset hashname;
};

//tree node, 用于统计
struct treenode_t {
#ifdef __SGI_STL_PORT
typedef std::hash_map<STRING, treenode_t*> hash_treenode;
#else
typedef stdext::hash_map<STRING, treenode_t*> hash_treenode;
#endif
STRING name;
uint32_t invokecount; //运行(调用)次数
hash_treenode childmap;
treenode_t* parentnode;
LARGE_INTEGER totaltime; //占用时间
~treenode_t();
};

//节点树
struct tree_t {
treenode_t rootnode;
treenode_t* currentnode;
};

//节点树函数指针
typedef void (__stdcall* function_dump)(const tree_t* nodetree);

extern "C" {
VENGINE_API void pushnode(const char* name, const char* extensionname = NULL);
VENGINE_API void popnode(const char* name = NULL);
VENGINE_API void dumpstack(function_dump function); //查询节点信息
};

void tick(); //for vengine time system

}; //namespace profile

}; //namespace vengine_capability

#endif //VENGINE_CAPABILITY_PROFILE_H_


SIMPLE

  ax::trace 输出信息



  ax::var 变量输出,学习过PHP的应该知道有一个函数叫var_dump



总结

该模块封装了客户端应用的评估模块,即整个客户端的效率采集器,以及常用的调试方法。看似很多东西,其实也没有太过复杂的,输出调试借用了tracewin这个调试工具,大家可以网上找一下,用到的是windows的SendMessage接口。性能模块,封装了和异常有关的一些方法,那么我们下一节就开始讲解异常收集模块。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: