1. Trang chủ
  2. » Công Nghệ Thông Tin

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

30 319 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Selected Common Code Client Modules
Trường học University of Technology Sydney
Chuyên ngành Game Programming
Thể loại Học thuật
Thành phố Sydney
Định dạng
Số trang 30
Dung lượng 1,16 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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,addMess

Trang 1

// 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) {

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

Selected Common Code Client Modules 267

Trang 2

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 isnot really calling out from the engine However, it is useful to treat this operation as if acallback 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 thetype ServerMessage, which invokes the function described next

For ServerMessage messages, the client can install callbacks that will be run according tothe type of the message

Obviously,ClientCmdServerMessage is more involved After it uses the GetWord function toextract the message type as the first text word from the string %msgType, it iterates throughthe 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 thearray looking for the function to be registered If it isn't there,addMessageCallback stores ahandle to the function in the next available slot

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

mes-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 theircontents, and I think that's been accomplished nicely For your browsing pleasure, Table7.2 contains a reference to find all the functions in all common code modules

Chapter 7 ■ Common Scripts268

Trang 3

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

Trang 4

Chapter 7 ■ Common Scripts270

common/client/metrics.cs FpsMetricsCallback

TerrainMetricsCallback VideoMetricsCallback InteriorMetricsCallback TextureMetricsCallback WaterMetricsCallback TimeMetricsCallback VehicleMetricsCallback AudioMetricsCallback DebugMetricsCallback Metrics

common/client/mission.cs ClientCmdMissionStart

ClientCmdMissionEnd

common/client/missionDownload.cs ClientCmdMissionStartPhase1

OnDataBlockObjectReceived ClientCmdMissionStartPhase2 OnGhostAlwaysStarted OnGhostAlwaysObjectReceived ClientCmdMissionStartPhase3 UpdateLightingProgress SceneLightingComplete

common/client/recordings.cs RecordingsDlg::onWake

StartSelectedDemo StartDemoRecord StopDemoRecord DemoPlaybackComplete

common/client/screenshot.cs FormatImageNumber

RecordMovie MovieGrabScreen StopMovie DoScreenShot

common/server/audio.cs ServerPlay2D

ServerPlay3D

common/server/clientConnection.cs GameConnection::onConnectRequest

GameConnection::onConnect GameConnection::setPlayerName IsNameUnique

GameConnection::onDrop GameConnection::startMission GameConnection::endMission GameConnection::syncClock GameConnection::incScore

continued

Trang 5

A Final Word 271

common/server/commands.cs ServerCmdSAD

ServerCmdSADSetPassword ServerCmdTeamMessageSent ServerCmdMessageSent

common/server/game.cs OnServerCreated

OnServerDestroyed OnMissionLoaded OnMissionEnded OnMissionReset GameConnection::onClientEnterGame GameConnection::onClientLeaveGame CreateGame

DestroyGame StartGame EndGame

common/server/kickban.cs Kick

Ban

common/server/message.cs MessageClient

MessageTeam MessageTeamExcept MessageAll MessageAllExcept GameConnection::spamMessageTimeout GameConnection::spamReset

SpamAlert ChatMessageClient ChatMessageTeam ChatMessageAll

common/server/missionDownload.cs GameConnection::loadMission

ServerCmdMissionStartPhase1Ack GameConnection::onDataBlocksDone ServerCmdMissionStartPhase2Ack GameConnection::clientWantsGhostAlwaysRetry GameConnection::onGhostAlwaysFailed

GameConnection::onGhostAlwaysObjectsReceived ServerCmdMissionStartPhase3Ack

common/server/missionInfo.cs ClearLoadInfo

BuildLoadInfo DumpLoadInfo SendLoadInfoToClient LoadMission

LoadMissionStage2 EndMission ResetMission continued

Trang 6

Chapter 7 ■ Common Scripts272

common/server/missionLoad.cs LoadMission

LoadMissionStage2 EndMission ResetMission

common/server/server.cs PortInit

CreateServer DestroyServer ResetServerDefaults AddToServerGuidList RemoveFromServerGuidList OnServerInfoQuery

common/ui/ConsoleDlg.gui ConsoleEntry::eval

ToggleConsole

common/ui/GuiEditorGui.gui GuiEditorStartCreate

GuiEditorCreate GuiEditorSaveGui GuiEditorSaveGuiCallback GuiEdit

GuiEditorOpen GuiEditorContentList::onSelect GuiEditorClassPopup::onSelect GuiEditorTreeView::onSelect GuiEditorInspectApply GuiEditor::onSelect GuiEditorDeleteSelected Inspect

InspectApply InspectTreeView::onSelect Tree

GuiInspector::toggleDynamicGroupScript GuiInspector::toggleGroupScript GuiInspector::setAllGroupStateScript GuiInspector::addDynamicField InspectAddFieldDlg::doAction

common/ui/LoadFileDlg.gui FillFileList

GetLoadFilename

common/ui/SaveFileDlg.gui GetSaveFilename

DoSACallback SA_directoryList::onSelect SA_filelist::onSelect

Trang 7

One last thing to remember about the common code: As chock-full of useful and

impor-tant functionality as it is, you don't need to use it to create a game with Torque You'd be nuts to throw it away, in my humble opinion Nonetheless, you could create your own

script code base from the bottom up One thing I hope this chapter has shown you is that

a huge pile of work has already been done for you You just need to build on it

Moving Right Along

In this chapter, we took a look at the capabilities available in the common code base sothat you will gain familiarity with how Torque scripts generally work For the most part,

it is probably best to leave the common code alone There may be times, however, whenyou will want to tweak or adjust something in the common code, or add your own set offeatures, and that's certainly reasonable You will find that the features you want to reuseare best added to the common code

As you saw, much of the critical server-side common code is related to issues that dealwith loading mission files, datablocks, and other resources from the server to each client

as it connects

In a complementary fashion, the client-side common code accepts the resources being sent

by the server, and uses them to prepare to display the new game environment to the user

So, that's enough programming and code for a while In the next few chapters, we get moreartistic, dealing with visual things In the next chapter, we will take a look at textures, how

to make them and how to use them We'll also learn a new tool we can use to create them.p

Trang 8

This page intentionally left blank

Trang 9

Introduction to Textures

Textures also can be used to create apparent properties of objects, properties that theobject shape doesn't have—it just looks like it does For example, blocky shapes with jut-ting corners can appear to be smoothed by the careful application of an appropriate tex-

ture using a process called texture mapping.

Another way textures can be used is to create the illusion of substructure and detail Figure8.1 shows a castle with towers and walls that appear to be made of blocks of stone Thestone blocks are merely components of the textures applied to the tower and wall objects

There are no stone blocks actually modeled in that scene The same goes for the ance of the wooden boards in the steps and other structures The texture gives not onlythe appearance of wood but the structure of individually nailed planks and boards This

appear-is a powerful tool, using textures to define substructures and detail

This ability to create the illusion of structure can be refined and used in other ways Figure8.2 shows a mountainside scene with bare granite rock and icefalls Again, textures werecreated and applied with this appearance in mind This technique greatly reduces the need

to create 3D models for the myriad of tiny objects, nooks, and crannies you're going to

Trang 10

encounter on an isolated and barrenmountain crag.

Textures appear in many guises in agame In Figure 8.3 two different tex-tures are used to define the water nearthe shoreline A foamy texture is usedfor the areas that splash against rockand sand, and a more wavelike texture

is used for the deep water In thisapplication the water block is adynamic object that has movingwaves It ebbs and flows and splashesagainst the shore The water texturesare distorted and twisted in real time

to match the motion of the waves.Another area in a game where texturesare used to enhance the ambience of agame is when they are used to definethe appearance of the sky Figure 8.4shows cloud textures being used in a

skybox The skybox is basically the

inside of a big six-sided box that rounds your scene By applying spe-cially distorted and treated textures tothe skybox, we can create the appear-ance of an all-enveloping 360-degreesky above the horizon

sur-We can use textures to enhance theappearance of other objects in a scene.For example, in Figure 8.5 we see anumber of coniferous trees on a hill-side By designing the ground texturethat occupies the terrain location ofthe trees appropriately, we can achievethe forest look we want without need-ing to completely cover every inch ofground with the tree objects This ishelpful because the fewer objects weneed to use for such a purpose—

Chapter 8 ■ Introduction to Textures276

Figure 8.1 Structure definition through using textures.

Figure 8.3 Shoreline foam and deepwater textures.

Figure 8.2 Rock and icefalls appearance on a

mountainside

Trang 11

basically decoration—the moreobjects that will be available for us touse in other ways.

One of the most amazing uses of tures is when defining technologicalitems Take the Tommy gun in Figure8.6, for instance There are onlyabout a dozen objects in that model,and most of them are cubes, with acouple of cylinders tossed in, as well

tex-as two or three irregular shapes Yet

by using an appropriately designedtexture, we can convey much greaterdetail The weapon is easily identifi-able as a Thompson SubmachineGun, circa 1944

Following the theme of technologicaldetail, Figure 8.7 is another example

This model of a Bell 47 Helicopter

(think M*A*S*H) shows two trick

uses of textures in one model Theengine detail and the instrumentpanel dials were created using textureswe've already seen Now take a look atthe tail boom and the cockpit canopy

The tail boom looks like it is made ofseveral dozen intersecting and over-lapping metal bars; after all, you cansee right through it to the buildingsand ground in the background But it

is actually a single elongated andpinched box or cube with a single tex-ture applied! The texture utilizes thealpha channel to convey the trans-parency information to the Torquerenderer Cool, huh? Then there is thecanopy It is semitransparent or mild-

ly translucent You can obviously seeright through it, as you should whenlooking through Perspex, but you can

Figure 8.4 Clouds in a skybox using textures.

Figure 8.5 Terrain accents.

Figure 8.6 Weapon detail using textures.

Trang 12

still make out the sense of a solidglasslike surface.

Of course, technological features arenot the only things that can beenhanced through textures In Figure8.8 the brawler about to enter the tav-ern is attired in the latest stylishleather brawling jacket He is obvi-ously somewhere around 40 years ofage, judging by his classic male-pat-tern baldness, and the bat is aTubettiville slugger Okay, okay, thebat is a stretch, but if it were turnedover 180 degrees, you would be able

to see the Tubettiville logo, and thenyou could tell! Also note the use of thetexture specifying the tavern name,

named in honor of a famous Delta Force 2 player, Insomniac.

Look at the moon in Figure 8.9 Lookagain, closer Does it look familiar? Itshould, because the moon texture inthat picture is an actual photograph ofthe full moon, taken outside my housewith a digital camera and then used togenerate the moon texture The rest ofthe scene is generated using theTorque Engine with appropriatenighttime lighting parameters set

I think by now you have a pretty goodidea why I say that textures are theunsung heroes of 3D gaming Theyreally make a huge difference by con-veying not only the obvious visualinformation, but also the subtle cluesand feelings that can turn a good gameinto a great experience

Chapter 8 ■ Introduction to Textures278

Figure 8.7 Vehicle detail and structure.

Figure 8.8 Player clothing, skin, and other details.

Figure 8.9 Distant objects.

Trang 13

Paint Shop Pro

You are going to be creating your own textures as you travel through this book, and to dothat you'll need a good tool for texture and image manipulation Well, the good folks at

JASC Software have graciously allowed us to include their great image processing tool,

Paint Shop Pro, on the companion CD for you to use

I've been using Paint Shop Pro for about 10 years, I think In the early days, I only used itfor converting file types, because that was about all it could do Nowadays, though, it is afully featured image processing and image generation tool, with scanner support, specialeffects and filters, image analysis statistics, and the whole nine yards

First, you'll need to install Paint Shop Pro, if you haven't already run the Full Install fromthe CD

Installing Paint Shop Pro

If you want to install only Paint Shop Pro, do the following:

1 Browse to your CD in the \PSP folder

2 Locate the Setup.exe file and double-click it to run it

3 Click the Next button for the Welcome screen

4 Follow the various screens, and take the default options for each one, unless youknow you have a specific reason to do otherwise

tex-1 Launch Paint Shop Pro and select File, New

2 A New Image dialog box opens up Set the width and height dimensions to 128pixels (see Figure 8.10) and click OK

3 We now have a blank image to work with Choose the menu item Effects, TextureEffects, Texture, and the Texture dialog box will appear, as in Figure 8.11

4 In the visual list at the lower part of the Texture dialog box, select Woodgrain

You'll have to scroll down through the list to the bottom

Trang 14

5 Click on the color box at center-right You willget a Color dialog box, as shown in Figure 8.12.

6 Change the value in the R (for red) box to 139, inthe G (for green) box to 87, and in the B (for blue)box to 15 The H (hue), S (saturation), and L(light) boxes will automatically change to match

7 Click OK to close the Color dialog box

8 Change the other settings in the Texturedialog box to match those in Table 8.1

9 Click OK to close the Texture dialogbox

10 Now you should have a bona fidewoodgrain texture, like the one shown

in Figure 8.13, that you can use forthings like walls, planks, ladders, thewooden stock on a weapon, barrels, andwhatever else you can come up with

Chapter 8 ■ Introduction to Textures280

Figure 8.10 Creating a new blank

Intensity 50 Elevation 37

Trang 15

11 With this texture, you can ment with different image processingeffects and touchup tools in PaintShop Pro Go ahead and give it a try.

experi-Okay, that was so much fun, let's do

anoth-er This time we are going to tweak animage a bit searching for a specific look

The next texture will be a sort of wall look that you might find on a paintedcement block, or maybe a freshly pouredsidewalk, or something like that We'll call it

rough-the sidewalk texture, for convenience.

1 If it isn't still open, launch PaintShop Pro

2 Select File, New

3 Set the width and height dimensions

to 128 pixels and click OK (Takeanother look at Figure 8.10 if youneed to refresh your memory.)

4 Select the menu item Effects, TextureEffects, Texture, and the Texture dialog box will appearagain, just like before, as depicted in Figure 8.11

5 This time we'll do something a bit different from the ous image Locate the Texture frame at center-left Click on

previ-it to open a visual menu of textures, and choose Concrete

You should get a texture like the one shown in the boxes inthe dialog box in Figure 8.14

6 Click on the color box at center-right to get the Color dialogbox again

7 Using Figure 8.15 as a guide, change the value in the R box to 218, in the G box to

181, and in the B box to 110

8 Click OK to close the Color dialog box

9 Change the other settings in the Texture dialog box to match those in Table 8.1

10 Click OK to close the Texture dialog box You should get a new texture like the oneshown in Figure 8.16

Now this texture is quite a bit darker than I want it to be I'm looking for a graywith a hint of beige or tan color, so what we'll have to do is touch it up a bit First,

we want to brighten the highlights and, at the same time, darken the shadows a bit

Figure 8.12 Color dialog box for woodgrain.

Figure 8.13

Woodgrain texture

Ngày đăng: 26/01/2014, 18:20

TỪ KHÓA LIÊN QUAN