找回密码
 register

QQ登录

只需一步,快速开始

查看: 1477|回复: 0

[游戏教程] 四、武侠世界2源码分析:状态机

[复制链接]

[游戏教程] 四、武侠世界2源码分析:状态机

[复制链接]
  • 打卡等级:热心大叔
  • 打卡总天数:94
  • 打卡月天数:17
  • 打卡总奖励:94
  • 最近打卡:2025-01-18 01:28:20
Waylee

主题

0

回帖

1万

积分

仙帝

积分
12364
Waylee 2023-6-14 19:14 | 显示全部楼层 |阅读模式

马上注册,查看网站隐藏内容!!

您需要 登录 才可以下载或查看,没有账号?register

×
游戏的处理流程,参考 Analysis\architecture\《wx2 状态机.doc》.

类名描述
CGamePro_Login服务器选择、账号输入
CGamePro_CharSel选择角色
CGamePro_CharCreate创建角色
CGamePro_Enter等待进入场景流程 发送进入场景的请求, 设置场景摄像机, 进入场景
CGamePro_Main主循环
CGamePro_ChangeScene切换服务器流程,链接到服务器

角色的创建、进入游戏、返回到帐号输入界面
22.jpg
23.jpg

Index类名描述
1CGamePro_Main主游戏循环
2CGameProcedure当前激活的流程
3CGamePro_ChangeScene切换服务器流程
4CGamePro_CharCreate人物创建流程
5CGamePro_CharSel人物选择流程
6CGamePro_Enter等待进入场景流程
7CGamePro_Login登录游戏循环
8CGameProduce_Login未给出描述

24.jpg

25.jpg


4.1 登录流程
登录流程对应选择服务器 UI 和输入账号 UI

非 GameServer,单机模式(Game_EnterDirect=TRUE),看起来怎么像是链接 GameServer,估计是调试时候修改成这样。到脚本:Event: "GAMELOGIN_OPEN_COUNT_INPUT" ,Window fuction: LoginLogOn_OnEventEnvironment(name:LoginLogOn,lua_name:LoginLogOn_Env,file:LogOn.lua)

4.1.1 输入账号


事件处理: GE_GAMELOGIN_OPEN_COUNT_INPUT 消息后,即显示登录 UI.
if( event == "GAMELOGIN_OPEN_COUNT_INPUT" ) then
this:Show();
LogOn_LogonID_Active();
LogOn_PassWord:SetText("");
LogOn_ID:SetText("");
return;
end


事件
<Event Name="Clicked" Function="LogOn_CheckAccount();" />
GameProduceLogin:CheckAccount(strName, strPassword);
<Event Name="Clicked" Function="LogOn_ExitToSelectServer();" />
GameProduceLogin:ExitToSelectServer();
<Event Name="Clicked" Function="LogOn_RequisitionID();" />
PushEvent("OPEN_REGISTRATION")
<Event Name="Clicked" Function="LogOn_ExitGame();" />
QuitApplication();




26.jpg


4.1.1.1 账号错误提示
PushEvent( GE_GAMELOGIN_SHOW_SYSTEM_INFO, “输入密码错误”);

27.jpg


4.1.1.2 正在连接服务器提示
在输入账号界面的屏幕下方显示背景透明文字。

STRING strTemp = "";
strTemp = NOCOLORMSGFUNC("produce_login_Info_Connecting_Server");
PushEvent( GE_GAMELOGIN_SHOW_SYSTEM_INFO_NO_BUTTON, strTemp.c_str());


28.jpg


4.1.1.3 与服务器断开链接提示
网络断开时,网络 tick 会发送 GE_NET_CLOSE 消息。
PushEvent(GE_NET_CLOSE, strTemp.c_str());
此消息将弹出 messagebox_self 对话框,不管确定还是取消,都将触发全局脚本函数
“QuitApplication();”
其直接调用注册到的 C++函数
Lua_QuitApplication

INT Lua_QuitApplication(LuaPlus::LuaState* state)
{
PostMessage(g_hMainWnd, WM_CLOSE, 0XC0DE, 0XC0DE);
return 0;
}


messagebox_self.layout.xml.layout

29.jpg

4.1.2 选择服务器(非 GameServer,Game_EnterDirect=FALSE)

Game_EnterDirect消息脚本Event: "GAMELOGIN_SELECT_LOGINSERVER" ,Window fuction:LoginSelectServer_OnEventEnvironment(name:LoginSelectServer,lua_name:LoginSelectServer_Env,file:SelectServer.lua )打开消息:PushEvent(GE_GAMELOGIN_OPEN_SELECT_SERVER);响应消息:

if( event == "GAMELOGIN_OPEN_SELECT_SERVER" ) then
this:Show();
return;
end


选择服务器画面AreaIndex 表示电信网通 tab 中的共 4 个区域,分别索引是 0、1、2、3.ServerIndex 表示服务器列表中的 2 个服务器,分别索引是 0、1切换 AreaIndex 中的 4 个服务器时,服务器列表中的 2 个服务器或更新。

30.jpg

<Event Name="Clicked" Function="SelectServer_Exit()" />
QuitApplication();
<Event Name="Clicked" Function="SelectServer_SelectOk()" />
GameProduceLogin:SelectLoginServer(g_iCurSelArea, g_iCurSelLoginServer);

确定后


Game_d.exe!CGamePro_Login::SelectLoginServer
Game_d.exe!SCRIPT_SANDBOX::CGameProduce_Login::SelectLoginServer
Game_d.exe!LPCD::Object_MemberDispatcher_to_LuaState<SCRIPT_SANDBOX::CGameProduce_Login>
LuaPlus_d.dll!luaD_precall
LuaPlus_d.dll!luaV_execute
LuaPlus_d.dll!luaD_call
LuaPlus_d.dll!f_call
LuaPlus_d.dll!luaD_rawrunprotected
LuaPlus_d.dll!luaD_pcall
LuaPlus_d.dll!lua_pcall
LuaPlus_d.dll!aux_do
LuaPlus_d.dll!lua_dobuffer
LuaPlus_d.dll!lua_dostring
LuaPlus_d.dll!LuaPlus::LuaState::DoString
Game_d.exe!CScriptEnvironment::DoString_WithCPPException
Game_d.exe!CScriptEnvironment::DoString_WithGenException
Game_d.exe!CScriptEnvironment::DoString
UI_CEGUI_d.dll!CUIWindowItem::FireUIEvent
UI_CEGUI_d.dll!CEGUI::CGameUIScript::executeScriptedEventHandler
CEGUIBase_d.dll!CEGUI::ScriptFunctor::operator
CEGUIBase_d.dll!CEGUI::_functorBinder<CEGUI::ScriptFunctor,bool,CEGUI::EventArgs const &>::operator
CEGUIBase_d.dll!CEGUI::SubscriberTemplate<bool,CEGUI::EventArgs const &>::operator
CEGUIBase_d.dll!CEGUI::Event::operator
CEGUIBase_d.dll!CEGUI::EventSet::fireEvent_impl
CEGUIBase_d.dll!CEGUI::EventSet::fireEvent
CEGUIBase_d.dll!CEGUI::PushButton::onClicked
CEGUIBase_d.dll!CEGUI::PushButton::onMouseButtonUp
CEGUIBase_d.dll!CEGUI::System::injectMouseButtonUp
UI_CEGUI_d.dll!CUISystem::InjectInput
Game_d.exe!CInputSystem::Tick
Game_d.exe!CGameProcedure::Tick
Game_d.exe!CGamePro_Login::Tick
Game_d.exe!CGameProcedure::TickActive
Game_d.exe!CGameProcedure::MainLoop
Game_d.exe!_tMain_With_CPPException
Game_d.exe!WinMain


GAMELOGIN_SELECT_LOGIN_SERVER 消息处理

if( event == "GAMELOGIN_SELECT_LOGIN_SERVER") then
SelectServer_SelectAreaServer(tonumber(arg0));
--AxTrace( 0,0, "自动选择一个 login server = "..tostring(arg1));
SelectServer_GetAndShowLoginServer(tonumber(arg1));
return;
end



4.1.3 服务器列表数据库
服务器地址保存在如下地址
Bin\Client\Patch\serverlist.tab


4.2 选择角色

Event: "GAMELOGIN_CLOSE_SELECT_CHARACTOR" ,Window fuction:LoginSelectRole_OnEvent
Environment(name:LoginSelectRole,lua_name:LoginSelectRole_Env,file:SelectRole.lua
<Event Name="Clicked" Function="SelectRole_Return();" />
GameProduceLogin:ExitToAccountInput_YesNo();
<Event Name="MouseButtonUp" Function="SelectRole_TurnRight(0);" />
<Event Name="MouseLButtonDown" Function="SelectRole_TurnRight(1);" />
<Event Name="Clicked" Function="SelectRole_EnterGame();" />
GameProduceLogin:SendEnterGameMsg(g_iCurSelRole - 1);
<Event Name="Clicked" Function="SelectRole_DelRole();" />
<Event Name="Clicked" Function="SelectRole_CreateRole();" />
<Event Name="Clicked" Function="SelectRole_SelectRole(0);" />

31.jpg

4.3 创建角色

关键方法
// 创建界面模型
int CGamePro_CharCreate::CreateModel()
// 创建角色
int CGamePro_CharCreate::CreateRole()
播放动画: GameProduceLogin::PlayAnimation(id, 121);
32.jpg
创建角色
+new entity 0:type=ETYPE_ACTOR , class = CObjEntityActor
file:女主角白丁装_高模_01.obj
Event: "GAMELOGIN_OPEN_CREATE_CHARACTOR" ,Window fuction:LoginCreateRole_OnEvent
Environment(name:LoginCreateRole,lua_name:LoginCreateRole_Env,file:CreateRole.lua)
Event: "GAMELOGIN_CLOSE_SYSTEM_INFO" ,Window fuction:LoginSelectServerQuest_OnEvent
Environment(name:LoginSelectServerQuest,lua_name:LoginSelectServerQuest_Env,file:SelectServerQuest.lua)
Event: "GAMELOGIN_CLOSE_SELECT_CHARACTOR" ,Window fuction:LoginSelectRole_OnEvent
Environment(name:LoginSelectRole,lua_name:LoginSelectRole_Env,file:SelectRole.lua)
<Event Name="Clicked" Function="CreateRole_SelectGender(1);" />
<Event Name="Clicked" Function="CreateRole_BnSelFace(9);" />
<Event Name="Clicked" Function="CreateRole_BnClickFacePageDown();" />
<Event Name="Clicked" Function="CreateRole_Select_LianXing(0);" />
<Event Name="ListSelectionAccepted" Function="Select_FaSe_ComboList();" />
<Event Name="Clicked" Function="CreateRole_BnSelGuoJia(3);" />
<Event Name="Clicked" Function="CreateRole_BnClickReturnSelectRole();" />
<Event Name="MouseButtonUp" Function="CreateRole_TurnRight(0);" />
<Event Name="MouseLButtonDown" Function="CreateRole_TurnRight(1);" />
<Event Name="MouseButtonUp" Function="CreateRole_TurnLeft(0);" />
<Event Name="MouseLButtonDown" Function="CreateRole_TurnLeft(1);" />
<Event Name="MouseEnter" Function="CreateRole_Name_MouseEnter();" />
<Event Name="MouseLeave" Function="CreateRole_MouseLeave();" />
<Event Name="Clicked" Function="CreateRole_BnClickCreateRole();" />
GameProduceLogin:CreateRole( szName, g_iCurSelSex, g_iCurSelCountry-1, g_iProfession-1, iCurSelIndex);
创建角色消息
<< @CreateAvatarState::CreateRole
CLAskCreateChar msg;
>> @ LCRetCreateCharHandler::Execute
CGameProcedure::s_pEventSystem->;PushEvent( GE_GAMELOGIN_CREATE_ROLE_OK );
--> LoginSelectRole SelectRole.layout.xml SelectRole.lua
--->
---> event:GAMELOGIN_OPEN_SELECT_CHARACTOR
---> lua: SelectRole_RefreshRoleInfo()
---> GameProduceLogin:ChangeSelectRole(g_iCurSelRole-1)
E:\GameDev\projects\tlbb\source\wx2\wxsj2\trunk\Bin\Client\resource\config\char_model.tab
E:\GameDev\projects\tlbb\source\wx2\wxsj2\trunk\Bin\Client\resource\config\char_race.tab
您需要登录后才可以回帖 登录 | register

本版积分规则

雪舞知识库 | 浙ICP备15015590号-1 | 萌ICP备20232229号|浙公网安备33048102000118号 |天天打卡

GMT+8, 2025-1-20 04:48 , Processed in 0.103600 second(s), 9 queries , Redis On.

Powered by XueWu Licensed

Copyright © Tencent Cloud.

快速回复 返回顶部 返回列表