Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu 3D Game Programming All in One- P13 docx
MIỄN PHÍ
Số trang
30
Kích thước
1.2 MB
Định dạng
PDF
Lượt xem
1811

Tài liệu 3D Game Programming All in One- P13 docx

Nội dung xem thử

Mô tả chi tiết

// First see if there is a callback installed that doesn't have a type;

// if so, that callback is always executed when a message arrives.

for (%i = 0; (%func = $MSGCB["", %i]) !$= ""; %i++) {

call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9,

%a10);

}

// Next look for a callback for this particular type of ServerMessage.

if (%tag !$= "") {

for (%i = 0; (%func = $MSGCB[%tag, %i]) !$= ""; %i++) {

call(%func, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9,

%a10);

}

}

}

function AddMessageCallback(%msgType, %func)

{

for (%i = 0; (%afunc = $MSGCB[%msgType, %i]) !$= ""; %i++) {

// If it already exists as a callback for this type,

// nothing to do.

if (%afunc $= %func) {

return;

}

}

// Set it up.

$MSGCB[%msgType, %i] = %func;

}

function DefaultMessageCallback(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7,

%a8, %a9, %a10)

{

OnServerMessage(detag(%msgString));

}

AddMessageCallback("", DefaultMessageCallback);

The first function, ClientCmdChatMessage, is for chat messages only and is invoked on the

client when the server uses the CommandToClient function with the message type ChatMessage.

Refer back to the server-side message module if you need to. The first parameter (%sender)

is the GameConnection object handle of the player that sent the chat message. The second

parameter (%voice) is an Audio Voice identifier string. Parameter three (%pitch) will also be

covered in the audio chapter later. Finally, the fourth parameter (%msgString) contains the

Selected Common Code Client Modules 267

Team LRN

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

actual chat message in a tagged string. The rest of the parameters are not actually acted on

so can be safely ignored for now. The parameters are passed on to the pseudo-handler

OnChatMessage. It's called a pseudo-handler because the function that calls OnChatMessage is

not really calling out from the engine. However, it is useful to treat this operation as if a

callback message and handler were involved for conceptual reasons.

The next function, ClientCmdServerMessage, is used to deal with game event descriptions,

which may or may not include text messages. These can be sent using the message func￾tions in the server-side Message module. Those functions use CommandToClient with the

type ServerMessage, which invokes the function described next.

For ServerMessage messages, the client can install callbacks that will be run according to

the type of the message.

Obviously, ClientCmdServerMessage is more involved. After it uses the GetWord function to

extract the message type as the first text word from the string %msgType, it iterates through

the message callback array ($MSGCB) looking for any untyped callback functions and exe￾cutes them all. It then goes through the array again, looking for registered callback func￾tions with the same message type as the incoming message, executing any that it finds.

The next function, addMessageCallback, is used to register callback functions in the $MSGCB

message callback array. This is not complex; addMessageCallback merely steps through the

array looking for the function to be registered. If it isn't there, addMessageCallback stores a

handle to the function in the next available slot.

The last function, DefaultMessageCallback, is supplied in order to provide an untyped mes￾sage to be registered. The registration takes place with the line after the function definition.

A Final Word

The common code base includes a ton of functions and methods. We have only touched

on about half of them here. I aimed to show you the most important modules and their

contents, and I think that's been accomplished nicely. For your browsing pleasure, Table

7.2 contains a reference to find all the functions in all common code modules.

268 Chapter 7 ■ Common Scripts

Team LRN

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

A Final Word 269

Table 7.2 Common Code Functions

Module Function

common/main.cs InitCommon

InitBaseClient

InitBaseServer

DisplayHelp

ParseArgs

OnStart

OnExit

common/client/actionMap.cs ActionMap::copyBind

ActionMap::blockBind

common/client/audio.cs OpenALInit

OpenALShutdown

common/client/canvas.cs InitCanvas

ResetCanvas

common/client/cursor.cs CursorOff

CursorOn

GuiCanvas::checkCursor

GuiCanvas::setContent

GuiCanvas::pushDialog

GuiCanvas::popDialog

GuiCanvas::popLayer

common/client/help.cs HelpDlg::onWake

HelpFileList::onSelect

GetHelp

ContextHelp

GuiControl::getHelpPage

GuiMLTextCtrl::onURL

common/client/message.cs ClientCmdChatMessage

ClientCmdServerMessage

AddMessageCallback

DefaultMessageCallback

common/client/messageBox.cs MessageCallback

MBSetText

MessageBoxOK

MessageBoxOKDlg::onSleep

MessageBoxOKCancel

MessageBoxOKCancelDlg::onSleep

MessageBoxYesNo

MessageBoxYesNoDlg::onSleep

MessagePopup

CloseMessagePopup continued

Team LRN

Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

Tải ngay đi em, còn do dự, trời tối mất!