Danh mục

3D Game Programming All in One- P13

Số trang: 30      Loại file: pdf      Dung lượng: 1.16 MB      Lượt xem: 16      Lượt tải: 0    
Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

3D Game Programming All in One- P13: During the past several years while working on the Tubettiland “Online Campaign” softwareand more recently while working on the Tubettiworld game, I figure I’ve receivedmore than a hundred queries from people of all ages about how to get started makinggames. There were queries from 40-year-olds and 13-year-olds and every age in between.Most e-mails were from guys I would estimate to be in their late teens or early 20s.
Nội dung trích xuất từ tài liệu:
3D Game Programming All in One- P13 Selected Common Code Client Modules 267 // First see if there is a callback installed that doesnt 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 theclient 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 secondparameter (%voice) is an Audio Voice identifier string. Parameter three (%pitch) will also becovered in the audio chapter later. Finally, the fourth parameter (%msgString) contains the Team LRN268 Chapter 7 ■ Common Scripts 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. Its 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 isnt 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 thats been accomplished nicely. For your browsing pleasure, Table 7.2 contains a reference to find all the functions in all common code modules. Team LRN A Final Word 269Table 7.2 Common Code FunctionsModule Functioncommon/main.cs InitCommon InitBaseClient InitBaseServer DisplayHelp ParseArgs OnStart OnExitcommon/client/actionMap.cs ActionMap::copyBind ActionMap::blockBindcommon/client/audio.cs OpenALInit OpenALShutdowncommon/client/canvas.cs InitCanvas ResetCanvascom ...

Tài liệu được xem nhiều: