由于近来比较忙碌和有些困倦的原因,所以关于这部分的文章没有及时更新,一句话:让朋友们久等了!今天所讲的是客户端vengine(微引擎)中最后一个部分,就像上节所说,这一部分的内容比较多。可能有些朋友看了代码以及注释后,仍有不少疑惑的地方,欢迎评论留言相互讨论,如果有不好的地方,也希望大家勇于批评与指正。游戏模块,是提供给客户端最核心的部分,它将直接影响到游戏内容,如数据、渲染等。
模块game下模块action 文件item.h
/** * PAP Engine ( -- ) * $Id item.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-24 18:06:13 * @uses vengine game action item class */ #ifndef VENGINE_GAME_ACTION_ITEM_H_ #define VENGINE_GAME_ACTION_ITEM_H_ #include "vengine/config.h" namespace vengine_game { namespace action { typedef enum { kOperateTypeEmpty, //空 kOperateTypeSkill, //战斗技能 kOperateTypeItem, //物品 kOperateTypeXinfa, //心法 kOperateTypePetSkill, //宠物技能 kOperateTypeEquip, //装备 kOperateTypeChatMood, //聊天动作 kOperateTypeMouseCommandRepair, //鼠标指令--修理 kOperateTypeMouseCommandIdentify, //鼠标指令--鉴定 kOperateTypeMouseCommandAddFriend, //鼠标指令--增加好友 kOperateTypeChangeSet, //一键换装 kOperateTypeMouseCommandExchange, //交易 } operatetype_enum; class Reference; class VENGINE_API Item { public: virtual int32_t getid() const = 0; virtual const char* getname() const = 0; virtual const char* geticon() const = 0; virtual void seticon(STRING& name) = 0; virtual void set_checkstate(bool check) = 0; //添加引用 virtual void addreference(Reference* reference, bool is_menu_toolbar = false) = 0; //移除引用 virtual void removereference(Reference* reference) = 0; virtual operatetype_enum get_operatetype() const = 0; virtual const char* get_typestring() = 0; //对于战斗技能, 是技能表中的ID (DBC_SKILL_DATA) //对于生活技能,是生活技能表中的ID(DBC_LIFEABILITY_DEFINE) //对于物品,是物品表中的ID //对于心法,是心法表中的ID virtual int32_t get_defineid() const = 0; virtual int32_t getnumber() const = 0; //得到内部数据 virtual void* get_internaldata() const = 0; //得到解释 virtual const char* getdescription() const = 0; virtual int32_t get_cooldownid() const = 0; //得到所在容器的索引 virtual int32_t get_positionindex() const = 0; //激活动作 virtual void doaction() = 0; //激活子动作 virtual void do_subaction() = 0; virtual bool isvalid() const = 0; //是否有效 virtual bool isenable() const = 0; //是否激活 virtual void enable() = 0; virtual void disable() = 0; virtual bool cooldown_isover() const = 0; //检查冷却是否结束 //拖动结束 virtual void notify_dragdrop_dragged(bool destory, const char* targetname, const char* sourcename) = 0; //显示tooltips virtual void notify_tooltips_show(int32_t left, int32_t top, int32_t right, int32_t bottom) = 0; //隐藏tooltips virtual void notify_tooltips_hide() = 0; //查询逻辑属性 virtual STRING get_attributevalue(const char* name) = 0; }; }; //namespace action }; //namespace vengine_game #endif //VENGINE_GAME_ACTION_ITEM_H_
模块game下模块action 文件reference.h
/** * PAP Engine ( -- ) * $Id reference.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-24 19:17:02 * @uses vengine game action reference class */ #ifndef VENGINE_GAME_ACTION_REFERENCE_H_ #define VENGINE_GAME_ACTION_REFERENCE_H_ #include "vengine/config.h" namespace vengine_game { namespace action { //UI引用类 class VENGINE_API Reference { public: //逻辑Action消失 virtual void bedestroyed() = 0; //数据更新 virtual void update(int32_t itemid) = 0; //按钮按下 virtual void setcheck(bool check) = 0; //按钮设置成default的状态 virtual void setdefault(bool flag) = 0; //进入冷却 virtual void enter_cooldown(int32_t time, float percent) = 0; //显示字符, _char所显示的字符,0不显示 typedef enum { kCornerNumberPositionTopLeft = 0, kCornerNumberPositionTopRight, kCornerNumberPositionFootLeft, kCornerNumberPositionFootRight } cornernumber_position_enum; virtual void set_cornerchar(cornernumber_position_enum position, const char* _char) = 0; virtual void enable() = 0; virtual void disable() = 0; }; }; //namespace action }; //namespace vengine_game #endif //VENGINE_GAME_ACTION_REFERENCE_H_
模块game下模块action 文件system.h
/** * PAP Engine ( -- ) * $Id actionsystem.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-24 17:59:35 * @uses vengine game action system module */ #ifndef VENGINE_GAME_ACTIONSYSTEM_H_ #define VENGINE_GAME_ACTIONSYSTEM_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" #include "vengine/game/action/item.h" namespace vengine_game { namespace action { class VENGINE_API System : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_action_System); public: virtual Item* get(int32_t id) = 0; //当前正在显示Tootips的按钮 virtual Item* get_tooltips_focus() = 0; virtual void save() = 0; //得到缺省操作 virtual Item* getdefault() = 0; //设置缺省操作 virtual void setdefault(Item* action) = 0; virtual void set_systemkey_state(int32_t keystate, bool is_Fkey) = 0; }; } //namespace action }; //namespace vengine_game #endif //VENGINE_GAME_ACTIONSYSTEM_H_
data数据模块暂时没用,所以也就不贴出源码了
模块game下模块object 文件base.h
/** * PAP Engine ( -- ) * $Id base.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-24 19:45:21 * @uses vengine game object base class */ #ifndef VENGINE_GAME_OBJECT_BASE_H_ #define VENGINE_GAME_OBJECT_BASE_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" #include "vengine/render/entitynode.h" #include "vengine/cursor/system.h" namespace vengine_game { namespace object { typedef enum { kStatusNone = 0x0, kStatusVisiable = 0x1, //是否可见 //已经不再玩家的视野范围,如果该值维持一定时间,则会被删除 kStatusOutVisualField = 0x2, kStatusRayQuery = 0x3, //鼠标是否能选中 } status_enum; const uint8_t kExtraParamMax = 3; class VENGINE_API Base : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_object_Base); public: //根据初始化物体,并同步到渲染层 virtual void init(void*) = 0; //得到物体的ID virtual int32_t getid() const = 0; //客户端 virtual int32_t get_serverid() const = 0; //与服务器同步的ID //设置某项基本状态为enable virtual void enable(uint8_t flag) = 0; //设置某项基本状态为disable virtual void disable(uint8_t flag) = 0; virtual bool isenable(uint8_t flag) = 0; virtual bool isdisable(uint8_t flag) = 0; //是否能够被作为主目标选择 virtual bool can_beselect() const = 0; //获得渲染层指针 virtual vengine_render::EntityNode* get_renderinterface() = 0; public: typedef enum { kTripperObjectTypeNone, //非tripper物体 kTripperObjectTypeTransPort, //转送点 kTripperObjectTypeItemBox, //掉落箱子 kTripperObjectTypeResource, //生活技能中的矿物资源 kTripperObjectTypePlatform, //生活技能中的合成所需要的平台 } tripperobject_type_enum; //物体类型 virtual tripperobject_type_enum tripper_gettype() const = 0; //能否鼠标操作 virtual bool tripper_canoperate() const = 0; //获得鼠标类型 virtual vengine_cursor::type_enum tripper_getcursor_type() const = 0; //进入激活状态 virtual void tripper_active() = 0; VENGINE_KERNEL_DECLARE_LOGICAL(false); //声明该对象没有逻辑功能 }; }; //namespace object }; //namespace vengine_game #endif //VENGINE_GAME_OBJECT_BASE_H_
模块game下模块object 文件basesystem.h
/** * PAP Engine ( -- ) * $Id basesystem.h * @link-- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 11:01:41 * @uses vengine game base object system class */ #ifndef VENGINE_GAME_OBJECT_BASESYSTEM_H_ #define VENGINE_GAME_OBJECT_BASESYSTEM_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" #include "vengine/math/base.h" #include "vengine/game/object/base.h" #include "vengine/game/object/item.h" namespace vengine_game { namespace object { class VENGINE_API BaseSystem : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_object_BaseSystem); public: typedef enum { kDestroyMainTargetTypeObject, //销毁的对象 kDestroyMainTargetTypeMouseRightClick, //鼠标右键销毁 } destroy_maintarget_type_enum; public: //产生新物体,并加入数据链 virtual Base* create(const char* classname, int32_t id_fromserver, Base* parent = NULL) = 0; //销毁物体,并从数据链上拆除 virtual void destroy(Base* object) = 0; //跟据ID得到某物体 virtual Base* find(int32_t id) = 0; //获取一个SERVER OBJ对象的指针 virtual Base* findserver(int32_t id) = 0; //跟据索引来获取对象 virtual const std::vector<int32_t>& get_npc_objectid() = 0; //获得物品 virtual Item* getitem(int32_t id) = 0; //根据屏幕坐标计算选中得物体 virtual Base* get_mouseover( int32_t x, int32_t y, vengine_math::base::threefloat_vector_t& mouse_hitplan) = 0; //设置主目标对象,如果id非法,取消选中物体 virtual void set_maintarget( int32_t id, destroy_maintarget_type_enum destroytype = kDestroyMainTargetTypeObject) = 0; //取得当前选中物体 virtual Base* get_maintarget() const = 0; //关心某物体的指定事件 id-物体ID bCare-关心或者取消关心 virtual void care(int32_t id, bool care, STRING szSign) = 0; //从本地资源表中读取物品名字 virtual const char* get_local_itemname(uint32_t id_oftable) = 0; virtual void init_actoravatar() = 0; virtual void destroy_actoravatar() = 0; virtual const char* get_selfor_targetname(bool target = false) = 0; }; }; //namespace object }; //namespace vengine_game #endif //VENGINE_GAME_OBJECT_BASESYSTEM_H_
模块game下模块object 文件fakesystem.h
/** * PAP Engine ( -- ) * $Id fakesystem.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 11:31:05 * @uses vengine game fake object system class * cn: 在ui上显示的物体管理器接口 * 1. 创建/销毁在ui上显示的obj对象 * 2. 对于需要显示的fakeobject,每桢调用渲染层渲染到texture上, * 并更新到ui上 * 3. 这些object自身的逻辑操作,例如更换服装、武器等操作, * 需要更上层逻辑处理 */ #ifndef VENGINE_GAME_OBJECT_FAKESYSTEM_H_ #define VENGINE_GAME_OBJECT_FAKESYSTEM_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" namespace vengine_game { namespace object { class Base; //引用 static const char* kFakeRenderTexture = "_RenderTexture"; class VENGINE_API FakeSystem : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_object_FakeSystem); public: //创建/销毁在ui上显示的obj对象 virtual void create(const char* classname, const char* objectname, const char* cameraname) = 0; virtual void destroy(const char* name) = 0; //UI需要显示某物体 virtual void on_ui_hook(const char* windowname, const char* objectname, int32_t texturewidth, int32_t textureheight, const char* backgroundname) = 0; //UI不再需要显示某物体 virtual void on_ui_unhook(const char* windowname) = 0; //UI显示/隐藏 virtual void on_ui_shown(const char* windowname, float aspectratio) = 0; virtual void on_ui_hiden(const char* windowname) = 0; //模型旋转 virtual void rotatestart(const char* objectname, float angle) = 0; virtual void rotateend(const char* objectname) = 0; virtual STRING get_objectname(const char* windowname) = 0; }; }; //namespace object }; //namespace vengine_game #endif //VENGINE_GAME_OBJECT_FAKESYSTEM_H_
模块game下模块object 文件item.h
/** * PAP Engine ( -- ) * $Id item.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 09:38:02 * @uses vengine game item object class */ #ifndef VENGINE_GAME_OBJECT_ITEM_H_ #define VENGINE_GAME_OBJECT_ITEM_H_ #include "vengine/config.h" //引用公用类物品结构 namespace pap_common_game { namespace structs { namespace item { struct base_t; }; //namespace item }; //namespace structs }; //namespace pap_common_game //引用公用类的定义 namespace pap_common_game { namespace define { namespace type { namespace item { enum class_enum; }; //namespace item }; //namespace type }; //namespace define }; //namespace pap_common_game namespace vengine_game { namespace object { class VENGINE_API Item { public: //从服务器传来的数据标示(用于和服务器通讯) union guid_union { //合并后的ID uint64_t unionid; //服务器传来的数据 struct id_fromserver { uint16_t serverid; //服务端程序号:(例)5 uint16_t worldid; //世界号: (例)101 uint32_t serial; //物品序列号:(例)123429 } idorg; } id_; //物品规则 typedef enum { kRuleCanDrop, //是否可丢弃 kRuleCanOverlay, //是否可以重叠 kRuleCanPutShortcutBar, //是否可以放入快捷栏 kRuleCanSale, //是否可以出售 kRuleCanExchange, //是否可以交易 kRulePickBind, //是否拾取就绑定 kRuleSole, //是否唯一的 kRuleNeedCheck, //是否需要鉴定 kRuleVirtualItem, //是否为虚拟的物品 kRuleStoreBank, //是否可以放入银行 kRuleWearOut, //是否消耗 } rule_enum; //物品归属 typedef enum { kOwnerUnkown, kOwnerSelfEquip, //身上的装备 kOwnerSelfPacket, //背包中的 kOwnerSelfBank, //银行中 kOwnerSelfMount, //坐骑上 kOwnerOtherPlayerEquip, //其他玩家装备上 kOwnerBooth, //商人的货架 kOwnerSelfExchangeBox, //自己的交易盒子 kOwnerOtherExchangeBox, //别人的交易盒子 kOwnerMissionBox, //任务递交盒 kOwnerSelfStallBox, //自己的摊位盒子 kOwnerOtherStallBox, //别人的摊位盒子 kOwnerQuestVirtual, //任务的虚拟物品,只作显示 kOwnerSelfPlayerShop, //自己的商店 kOwnerOtherPlayerShop, //别人的商店 kOwnerDrop, //掉落 kOwnerTransfer, //用于传输,显示用 kOwnerMall, //商城 } owner_enum; public: //客户端ID virtual int32_t getid() const = 0; virtual void set_guid(uint16_t worldid, uint16_t serverid, uint32_t serial) = 0; virtual uint16_t get_guid(uint16_t& worldid, uint16_t& serverid, uint32_t& serial) const = 0; virtual pap_common_game::define::type::item::class_enum getclass() const = 0; virtual int32_t get_tabletype() const = 0; virtual const char* getname() const = 0; virtual const char* getdescription() const = 0; virtual const char* geticon() const = 0; //物品的详细编号,不是client用的index virtual int32_t get_particularid() const = 0; //详细解释(可能需要服务器) virtual const char* get_extradescription() = 0; //设置详细解释 virtual void set_extrainfo(pap_common_game::structs::item::base_t* item) = 0; virtual void set_extrainfo(const char* info) = 0; virtual const char* get_extrainfo() const = 0; //归属 virtual void setowner(owner_enum owner) = 0; virtual owner_enum getowner() const = 0; //设置所在索引 virtual void set_positionindex(int32_t index) = 0; virtual int32_t get_postitionindex() const = 0; virtual const char* get_drop_visualid() const = 0; virtual const char* get_drop_visualcolor() const = 0; virtual uint8_t getlevel_oftable() const = 0; virtual void setnumber(uint32_t number) = 0; virtual uint32_t getnumber() const = 0; //最大数量,暂时用于有限商品的显示 virtual void set_maxnumber(uint32_t number) = 0; virtual uint32_t get_maxnumber() const = 0; //获取叠放数量 virtual int32_t get_laynumber() const = 0; //在资源表中的位置 virtual int32_t getid_oftable() const = 0; //查询逻辑属性,一般用于脚本调用 virtual STRING get_attributevalue(const char* valuename) const = 0; //克隆详细信息 virtual void clone(const Item* srouceitem) = 0; //得到是否锁定(用于UI锁定) virtual void setlock(bool lock) = 0; virtual bool getlock() const = 0; //物品规则验证 virtual bool rule(int32_t type) = 0; virtual STRING rule_failmessage(int32_t type) = 0; //物品的二级密码保护 virtual void setprotect(bool protect) = 0; virtual bool getprotect() const = 0; public: //得到玩家使用这个物品需要的等级 virtual uint8_t get_needlevel() const = 0; //获得物品的耐久 virtual int32_t getdurability() const = 0; //获得物品的最大耐久 virtual int32_t get_durabilitymax() const = 0; //获得物品的可修理次数 virtual int32_t get_repaircount() const = 0; //获得物品的绑定信息 virtual uint8_t get_bindinfo() const = 0; //获得物品的二级绑定信息 virtual uint8_t get_secondlevel_bindinfo() const = 0; //获得绑定加成信息 virtual const char* get_bindadd_info() const = 0; virtual uint32_t get_baseprice() const = 0; //得到卖给NPC的价格 virtual uint32_t getprice() const = 0; //获得限定职业 virtual uint8_t getprofession() const = 0; //检查物品是否唯一 virtual bool checksole() const = 0; //得到物品的制作人 virtual const char* getproducer() const = 0; //得到白色属性 virtual const char* get_basewhite_attributeinfo() const = 0; //得到物品使用的目标类型 virtual uint8_t get_targettype() const = 0; //获得物品描述 virtual const char* get_typedescription() const = 0; //得到物品的第一个额外参数信息 virtual int32_t get_extraparam1() const = 0; //得到物品的第二个额外参数信息 virtual int32_t get_extraparam2() const = 0; //得到物品的第三个额外参数信息 virtual int32_t get_extraparam3() const = 0; }; }; //namespace object }; //namespace vengine_game #endif //VENGINE_GAME_OBJECT_ITEM_H_
模块game下 文件eventdefine.h
/** * PAP Engine ( -- ) * $Id eventdefine.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 15:59:14 * @uses vegine game event define id enum * cn: 时间处理定义相关 */ #ifndef VENGINE_GAME_EVENTDEFINE_H_ #define VENGINE_GAME_EVENTDEFINE_H_ #include "vengine/config.h" namespace vengine_game { namespace event_id { enum _enum { kApplicationInit, //-- 游戏主程序初始化 kSceneCutover, //-- 场景切换 /** 用户登陆{ **/ kLoginShowSystemInfoAndCloseNet, //-- 打开系统提示信息和关闭网络 kLoginShowSystemInfo, //-- 打开系统提示信息 kLoginCloseSystemInfo, //-- 关闭系统提示信息 kLoginOpenSelectServer, //-- 打开选择服务器 kLoginCloseSelectServer, //-- 关闭选择服务器 kLoginOpenAccountInput, //-- 打开账号输入界面 kLoginCloseAccountInput, //-- 关闭账号输入界面 kLoginShowSystemInfoNoButton, //-- 显示系统信息无按钮 kLoginShowSystemInfoYesOrNo, //-- 参数0, 提示的字符串 //-- 参数1, 对话框的类型 //-- 0 -- 是否退出游戏 //-- 1 -- 是否删除角色 //-- 2 -- 是否更换帐号 kLoginSelectLoginServer, //-- 选择一个login server //-- 参数0 区域索引 参数1 服务器索引 kLoginCleanAccount, //-- 清空显示的账号 kLoginSelectArea, //-- 选择大区 /** }用户登陆 **/ kUIToggleSystemFrame, //-- 切换显示系统菜单 kUICloseSecondMenu, //-- 关闭二级菜单 kUIChatAdjustMoveCtl, //-- 通知聊天窗口调整大小 kChatChangePrivateName, //-- 修改聊天中的密语对象 kChatContexMenu, //-- 聊天相关的快捷菜单 kSuperToolTip, //-- 提示框 arg0 - 显示/隐藏 1,0 // arg1 - 类型 "skill", "lifeability", "item", // "xinfa", "pet_skill" // arg2, arg3 鼠标位置 kNewDebugMessage, // -- 新的调试消息 kNetClose, // --关闭网络 kVariableChanged, // --前端变量改变了 }; }; //namespace event_id }; //namespace vengine_game #endif //VENGINE_GAME_EVENTDEFINE_H_
模块game下 文件eventsystem.h
/** * PAP Engine ( -- ) * $Id eventsystem.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 16:21:53 * @uses vengine game event system class */ #ifndef VENGINE_GAME_EVENTSYSTEM_H_ #define VENGINE_GAME_EVENTSYSTEM_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" namespace vengine_game { //引用本模块event_id namespace event_id { enum _enum; }; //namespace event_id struct event_t; typedef void (__stdcall* function_eventhandle) (const event_t* event, uint32_t ownerdata); typedef struct { typedef std::list<std::pair<function_eventhandle, uint32_t> > registerstruct; event_id::_enum id; const char* event; bool delayprocess; registerstruct listenfunction_notify; //监听方法 } eventdefine_t; struct event_t { eventdefine_t* eventdefine; std::vector<STRING> args; bool operator == (const event_t& other) { if (other.eventdefine != eventdefine) return false; if (other.args.size() != args.size()) return false; register size_t i; for (i = 0; i < args.size(); ++i) { if (other.args[i] != args[i]) return false; } return true; } }; class VENGINE_API EventSystem : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_EventSystem); public: virtual void push(vengine_game::event_id::_enum id, std::vector<STRING> param) = 0; virtual void push(event_id::_enum id) = 0; virtual void push(event_id::_enum id, int32_t arg0) = 0; virtual void push(event_id::_enum id, const char* arg0) = 0; virtual void push(event_id::_enum id, const char* arg0, const char* arg1) = 0; virtual void push(event_id::_enum id, const char* arg0, const char* arg1, int32_t arg2) = 0; virtual void push(event_id::_enum id, int32_t arg0, int32_t arg1) = 0; virtual void push(event_id::_enum id, const char* arg0, const char* arg1, int32_t arg2, int32_t arg3) = 0; virtual void push(event_id::_enum id, const char* arg0, const char* arg1, const char* arg2) = 0; //注册事件处理函数 virtual void registerhandle(const STRING& name, function_eventhandle handle, uint32_t ownerdata = NULL) = 0; //处理 virtual void processall() = 0; //取消注册事件处理函数 virtual void unregisterhandle(const STRING& name, function_eventhandle handle, uint32_t ownerdata) = 0; }; }; //namespace vengine_game #endif //VENGINE_GAME_EVENTSYSTEM_H_
模块game 文件interface.h
/** * PAP Engine ( -- ) * $Id interface.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 14:45:06 * @uses vengine game interface module * cn: 整个游戏的外部控制接口类, * 所有的外部模块需要通过这个接口来控制游戏的数据和控制 */ #ifndef VENGINE_GAME_INTERFACE_H_ #define VENGINE_GAME_INTERFACE_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" #include "vengine/math/base.h" //引用客户端的类 --不赞成使用过多这种引用 namespace object { namespace logic { class Base; }; //namespace logic }; //namespace object namespace vengine_game { //引用本模块中的类 namespace action { class Item; }; //namespace action namespace object { class Item; }; //namespace action class VENGINE_API Interface : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_Interface); public: //物体操作系列 virtual void object_selectas_maintarget(int32_t objectid, uint8_t type = 0) = 0; //显示右键菜单 virtual void object_show_contextmenu(int32_t objectid, bool showself = false) = 0; /** 主角操作系列 **/ //移动到场景中某个位置 virtual void player_moveto( const vengine_math::base::twofloat_vector_t& aimposition) = 0; virtual void player_moveto( uint16_t sceneid, const vengine_math::base::twofloat_vector_t& aimposition) = 0; //使用技能(瞬发) virtual void player_useskill(uint32_t skillid) = 0; //使用技能(对某个object) virtual void player_useskill(uint32_t skillid, int32_t objectid) = 0; //使用技能(对某个范围) virtual void player_useskill( uint32_t skillid, const vengine_math::base::twofloat_vector_t& position) = 0; //使用技能(对某个队友(GUID)) virtual void player_useskill(uint32_t skillid, const uint32_t& aim) = 0; virtual void player_useskill( uint32_t skillid, const vengine_math::base::twofloat_vector_t& position, const uint32_t& aim) = 0; //使用技能(对某个方向) virtual void player_useskill(uint32_t skillid, float& direct) = 0; //合成某配方 virtual void player_use_lifeability(uint16_t prescriptionid, uint32_t makecount) = 0; virtual void player_use_lifeability(uint16_t prescriptionid) = 0; //销毁身上的装备 virtual void player_destroyequip(const object::Item* equip) = 0; //卸载身上的装备 virtual void player_unequip(const object::Item* equip) = 0; //请求升级 virtual void player_ask_levelup() = 0; //请求洗一级属性点 virtual void player_ask_cleanbase_attributepoint() = 0; //谈话(对某个NPC) virtual void player_speak(int32_t objectid) = 0; //自动寻路 virtual void set_auto_findpath_tonpc(uint16_t sceneid, const char* npcname) = 0; //试图对某个TripperObj进行操作,如果距离过远,会走过去 virtual void tripper_objectactive(uint32_t id) = 0; //试图捡起当前盒子里的第几项 virtual void itembox_pick(object::Item* item) = 0; public: //使用包裹里的物品_通用 virtual void packet_useitem( action::Item* item, uint16_t target_serverid, const vengine_math::base::twofloat_vector_t& position) = 0; //使用包裹里的物品_对象 virtual void packet_useitem_totarget(uint16_t index, uint32_t targetid) = 0; //使用包裹里的物品_装备 virtual void packet_useequip(uint16_t index) = 0; //使用包裹里的物品_宝石 virtual void packet_usegem(uint16_t gemindex, uint16_t equipindex) = 0; virtual void packet_destroyitem(uint16_t index) = 0; //装备打孔 virtual void packet_add_equiphole() = 0; virtual void packet_equipmount() = 0; //装备坐骑 virtual void packet_callmount() = 0; //召唤坐骑 virtual void packet_recallmount() = 0; //召回坐骑 virtual void packet_destroymount() = 0; //销毁坐骑 //装备绑定 virtual void packet_equipbind() = 0; public: //给玩家身上的装备打孔 virtual void humanequip_addhole() = 0; //玩家身上的装备绑定 virtual void humanequip_bind() = 0; //合成装备 virtual void equipmerge(uint32_t productid, int32_t* grad) = 0; //改造装备 virtual void equiprework(int32_t* grad) = 0; //发送GM指令 virtual void send_gmcommand(const char* cmd) = 0; virtual void send_chatcommand(int32_t channelid, uint8_t chatype, int32_t teamid, const char* context, const char* targetname) = 0; //场景 virtual void scene_set_postfilter(const char* filtername) = 0; virtual void scene_set_lightmap_quality(int32_t quality) = 0; //设置当前激活技能 virtual void skill_setactive(action::Item* Item) = 0; virtual action::Item* skill_getactive() = 0; //恢复到缺省技能操作,用于退出修理,鉴定,等特殊鼠标命令状态 virtual void skill_cancelaction() = 0; public: virtual void booth_buyitem(action::Item* item) = 0; //物品购买 virtual void booth_sellitem(action::Item* item) = 0; //物品卖出 virtual void booth_close() = 0; //交易完成 //修理 virtual void booth_repair(bool all, uint16_t bagindex, bool is_inbag = true) = 0; //称号 virtual void title_updatecurrent(uint8_t type, int16_t data) = 0; //摊位 virtual void stall_opensale(uint32_t objectid) = 0; }; }; //namespace vengine_game #endif //VENGINE_GAME_INTERFACE_H_
模块game 文件itemtransfer_system.h
/** * PAP Engine ( -- ) * $Id itemtransfer_system.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-21 14:52:12 * @uses vengine game item transfer system * cn: 物品信息传输系统,将物品信息转换为聊天内容 */ #ifndef VENGINE_GAME_ITEMTRANSFER_SYSTEM_H_ #define VENGINE_GAME_ITEMTRANSFER_SYSTEM_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" namespace vengine_game { namespace object { //object class Item; }; typedef enum { kElementTypeInvalid = -1, //无效 kElementTypeItemInfo, //普通物品信息 kElementTypeHyperLink, //超链接 kElementTypeChannel, //频道切换 kElementTypePet, //珍兽 kElementTypeBoss, //boss } elementtype_enum; typedef enum { kElementActionRClick, //右键点击 kElementActionLClick, //左键点击 kElementActionMoveIn, //鼠标移进 kElementActionMoveOut, //鼠标移出 } elementaction_enum; class VENGINE_API ItemTransferSystem : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_ItemTransferSystem); public: struct element_t { int32_t id; int32_t type; //类型 int32_t objectid; //对象ID STRING display; //显示名称 STRING originaldisplay; //原始未更改过的字符串 STRING contents; //用于传入的字符串 int32_t usecount; //用于计数,如果这个值到0则删除这个element element_t() : type(kElementTypeInvalid) {}; virtual ~element_t() {}; bool istype(int32_t _type) { return type == _type; } virtual STRING get_displaycolor() = 0; virtual STRING get_display_prefixtext() = 0; }; public: //将一个物品转换为字符串 virtual element_t* convet_fromitem(object::Item* item) = 0; //将一个珍兽转换为字符串 virtual element_t* convert_frompet(int32_t index) = 0; //将字符串转换为物品 virtual element_t* convert_fromstring(const STRING& display, const STRING& contents) = 0; //添加一个超链接 virtual element_t* add_hyperlink(const STRING& name, const STRING& content, int32_t chatype = -1) = 0; //添加频道 virtual element_t* addchannel(int32_t type, const STRING& content) = 0; //销毁一个数据结构 virtual void removeelement(int32_t id) = 0; //处理element virtual void doelement(int32_t id, int32_t action, int32_t messageid = -1) = 0; //判断element是否存在 virtual bool is_elementexist(int32_t id) = 0; //获得element类型 virtual int32_t get_elementtype(int32_t id) = 0; //获得element显示的名称 virtual STRING get_element_displayname(int32_t id) = 0; //获得element的原始名称 virtual STRING get_element_original_displayname(int32_t id) = 0; //获得element的内容 virtual STRING get_elementcontents(int32_t id) = 0; //增加element的使用计数 virtual void add_element_usecount(int32_t id) = 0; //获得当前选中的element对象 virtual element_t* get_currentelement() = 0; virtual void reset() = 0; }; }; //namespace vengine_game #endif //VENGINE_GAME_ITEMTRANSFER_SYSTEM_H_
模块game 文件scene.h
/** * PAP Engine ( -- ) * $Id scene.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 12:01:16 * @uses vengine game scene class */ #ifndef VENGINE_GAME_SCENE_H_ #define VENGINE_GAME_SCENE_H_ #include "vengine/config.h" #include "vengine/math/base.h" /** 引用数据表结构 **/ namespace vengine_db { namespace structs { namespace scene { struct define_t; }; //namespace scene }; //namespace structs }; //namespace vengine_db namespace vengine_game { class Scene { public: //取得场景定义 virtual const vengine_db::structs::scene::define_t* getdefine() const = 0; //场景位置是否合法 virtual bool is_validposition( const vengine_math::base::twofloat_vector_t& position) = 0; //根据逻辑坐标取得地形高度,考虑行走面,如果传入坐标非法,返回false virtual bool get_mapheight( const vengine_math::base::twofloat_vector_t& position, float& height) = 0; }; }; //namespace vengine_game #endif //VENGINE_GAME_SCENE_H_
模块game 文件worldsystem.h
/** * PAP Engine ( -- ) * $Id worldsystem.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( [email protected] ) * @license * @user viticm<[email protected]/[email protected]> * @date 2014-3-25 11:52:01 * @uses vengine game world system class */ #ifndef VENGINE_GAME_WORLDSYSTEM_H_ #define VENGINE_GAME_WORLDSYSTEM_H_ #include "vengine/config.h" #include "vengine/kernel/node.h" #include "vengine/render/system.h" #include "vengine/sound/system.h" #include "vengine/game/scene.h" #include "vengine/game/object/basesystem.h" namespace vengine_game { struct mapposition_define_t { vengine_math::base::threefloat_vector_t position; uint16_t sceneid; char name[128]; uint16_t serverid; char optimizename[128]; //优化名称 bool optimize; mapposition_define_t() { optimize = false; memset(optimizename, 0, sizeof(optimizename)); } void setname(const char* name); void set_positionname(const char* name); //去掉对UTF8的设置 }; //对外提供的地形高度查询接口(使用渲染系统坐标,考虑地形和行走面) typedef bool (__stdcall* function_get_terrainheight) (float x, float z, float& y); typedef enum { kMiniMapTypeAnimy = 0, //敌人 kMiniMapTypeTeam, //队友 kMiniMapTypeFamily, //家族 kMiniMapTypeGuild, //帮会 kMiniMapTypeHomeland, //国家的 kMiniMapTypeNotHomeland, //非本国的 kMiniMapTypeGrowPoint, //生长点 kMiniMapTypeActive, //激活方向点 kMiniMapTypeScenePosition, //场景传送点 kMiniMapTypeFlash, //闪光点 kMiniMapTypeNpcNormal, //普通NPC kMiniMapTypeNpcMissionComplete, //任务NPC,完成 kMiniMapTypeNpcMissionNotComplete, //任务NPC,未完成 kMiniMapTypeNpcMissionCanAccept, //任务NPC,可接 kMiniMapTypeSelf, //自己 kMiniMapTypePet, //宠物 kMiniMapTypeNumber } minimap_type_enum; class VENGINE_API WorldSystem : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_game_WorldSystem); public: typedef enum { kStationNotEnterScene, //没有进入任何场景 kStationEnteringScene, //正在进入一个场景 kStationEnterScene, //成功进入场景 kStationAskChangeScene, //要求切换到一个新的场景(已经发送了请求切换场景的消息) } station_enum; public: //进入某个场景 virtual bool enterscene(uint16_t sceneid, int16_t citylevel, int32_t resourceid) = 0; virtual Scene* get_activescene() = 0; //取得当前状态 virtual station_enum getstation() const = 0; //对外提供的地形高度查询接口(使用渲染系统坐标,考虑地形和行走面) virtual function_get_terrainheight get_terrainheight_function() = 0; //获得当前场景的ID virtual uint16_t get_active_sceneid() const = 0; virtual std::list<mapposition_define_t>* get_objectlist_bytype(uint8_t type) = 0; virtual void set_minimap_searchrange(int32_t range) = 0; virtual void update_minimap_data() = 0; virtual void minimap_needfresh() = 0; virtual vengine_math::base::threefloat_vector_t get_selfposition() = 0; virtual int32_t get_selfdirect() = 0; virtual const char* get_scenename(uint16_t sceneid) = 0; }; }; //namespace vengine_game #endif //VENGINE_GAME_WORLDSYSTEM_H_
在这里游戏中的一些常用模块,如对象、场景、UI、数据,这些我就不在这里解释过多了,因为它们都依赖于引擎提供的接口,以后会有机会再详细同大家一起探讨和研究。
游戏中的事件系统,在这里我要特别说说,因为在天龙/武侠在这个模块上设计是比较聪明的。那么什么是事件呢,什么情况下会产生事件?事件其实就是游戏中某次操作或系统定点执行的某种动作,所谓事件就是一件事情。事件系统就是在事件产生的时候,管理该事件所需执行的动作而出现的。如界面的数据改变了,我们就需要更新界面,其中界面的数据改变了就是一个事件,而更新界面就是事件下产生的动作。
程序中常常有回调的说法,其实事件管理系统就是一种回调分发器,与回调不同的是事件管理器是集中管理,定时执行的。在这里,事件管理系统将事件的动作分为慢和快,快的在一次循环帧内一次执行完成,而慢的就有所谓的时间间隔,这样设计的好处就是使时间有了先后之分。
vengine(微引擎)的讲解结束了,游戏中的所有接口大家有些印象了吗?如果没有,则你可以从头再读一次这些文章,希望对大家有所帮助。接下来会开始讲解vgui(微GUI),结合CEGUI的界面管理的封装。