Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 30 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
30
Dung lượng
1,16 MB
Nội dung
// 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 inall common code modules.
Chapter 7
■
Common Scripts268
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.
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
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
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 so
that 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, when
you will want to tweak or adjust something in the common code, or add your own set of
features, and that's certainly reasonable. You will find that the features you want to reuse
are best added to the common code.
As you saw, much of the critical server-side common code is related to issues that deal
with 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 more
artistic, 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
Moving Right Along 273
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
This page intentionally left blank
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
275
Introduction to
Textures
chapter 8
3
D computer games are intensely visual. In this chapter we begin to explore the cre-
ative process behind the textures that give 3D objects their pizzazz.
Using Textures
Textures are probably the unsung heroes of 3D gaming. It is difficult to overstate the
importance of textures. One of the most important uses of textures in a game is in creat-
ing and sustaining the ambience, or the look and feel of a game.
Textures also can be used to create apparent properties of objects, properties that the
object 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. Figure
8.1 shows a castle with towers and walls that appear to be made of blocks of stone. The
stone 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 appear-
ance of the wooden boards in the steps and other structures. The texture gives not only
the appearance of wood but the structure of individually nailed planks and boards. This
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. Figure
8.2 shows a mountainside scene with bare granite rock and icefalls. Again, textures were
created 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
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
encounter on an isolated and barren
mountain crag.
Textures appear in many guises in a
game. In Figure 8.3 two different tex-
tures are used to define the water near
the shoreline. A foamy texture is used
for the areas that splash against rock
and sand, and a more wavelike texture
is used for the deep water. In this
application the water block is a
dynamic object that has moving
waves. It ebbs and flows and splashes
against the shore. The water textures
are distorted and twisted in real time
to match the motion of the waves.
Another area in a game where textures
are used to enhance the ambience of a
game is when they are used to define
the appearance of the sky. Figure 8.4
shows cloud textures being used in a
skybox. The skybox is basically the
inside of a big six-sided box that sur-
rounds your scene. By applying spe-
cially distorted and treated textures to
the skybox, we can create the appear-
ance of an all-enveloping 360-degree
sky above the horizon.
We can use textures to enhance the
appearance of other objects in a scene.
For example, in Figure 8.5 we see a
number of coniferous trees on a hill-
side. By designing the ground texture
that occupies the terrain location of
the trees appropriately, we can achieve
the forest look we want without need-
ing to completely cover every inch of
ground with the tree objects. This is
helpful because the fewer objects we
need 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.
Team LRN
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
[...]... converting file types, because that was about all it could do Nowadays, though, it is a fully featured image processing and image generation tool, with scanner support, special effects 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 from the CD Installing Paint Shop Pro If you want to install only... object, allowing a certain amount of the obscured objects or layers to show through Saving Layers You can save images that contain raster, mask, and adjustment layers in either the PSPIMAGE format or Photoshop's PSD format Both formats retain all the layer information for these two types of layers However, images containing vector layers must be saved in the PSPIMAGE format to retain the vector information... Figure 8.16 Initial sidewalk texture Working with Files We want to get those images saved without any further ado, but first I want to show you something You're going to launch the fps demo game that comes with the Torque Engine Figure 8.17 Highlight/Midtone/Shadow dialog box Launching the fps Demo Game 1 Leave Paint Shop Pro running and task switch (Alt+Tab) to the Windows desktop 2 Using the Windows Explorer,... separate item with information about its relative position in the image, its starting and ending points, and width, color, and curve information This makes the vector format useful for things like logos, text fonts, and line drawings Team LRN Paint Shop Pro An image in vector format does not depend on the resolution It can be resized without losing detail because it is stored as a set of instructions, not... Torque Engine with appropriate nighttime lighting parameters set I think by now you have a pretty good idea why I say that textures are the unsung heroes of 3D gaming They really make a huge difference by conveying not only the obvious visual information, but also the subtle clues and feelings that can turn a good game into a great experience Figure 8.9 Distant objects Team LRN Paint Shop Pro Paint Shop... image If you later decide to increase its size, you enlarge each pixel, which lowers the image quality A vector image is composed of procedural and mathematical instructions for drawing the image As you encountered in Chapter 3, a vector is basically a line that has definite magnitude and direction Vector objects in Paint Shop Pro are defined in a similar fashion Each object in a vector image is stored...Using Textures basically decoration—the more objects that will be available for us to use in other ways One of the most amazing uses of textures is when defining technological items Take the Tommy gun in Figure 8.6, for instance There are only about a dozen objects in that model, and most of them are cubes, with a couple of cylinders tossed in, as well as two or three irregular shapes Yet by using... some of our game images Not all of them, but a few So the rule of thumb will be to use JPG for all images except when we need to specify an alpha channel—then we use PNG Finally, here is an important workflow tip Save all of your original image creations in the Paint Shop Pro native format: PSPIMAGE When you create and save your images in PSPIMAGE format, it's a lot like having the original source... want the line to begin 2 Press and hold the Shift key 3 Click the image where you want to end the line (right-click to use the background color) 4 You can continue adding line segments of either color by clicking the mouse button 5 Release the Shift key to end the line Paint Brush Tool Options The Tool Options palette for the Paint Brush will appear in the upper toolbar when you select the Paint Brush... brush painting to a specific area, use the Selection tool or the Freehand Selection tool to make a selection before painting Then the brushwork will only be applied within the selected area This is a handy technique to avoid "overspray" with the Air Brush Freestyle Airbrush Painting Freestyle airbrush painting is a technique where there are no restrictions on brush movement To paint something in a freestyle . need to install Paint Shop Pro, if you haven't already run the Full Install from
the CD.
Installing Paint Shop Pro
If you want to install only Paint Shop. FpsMetricsCallback
TerrainMetricsCallback
VideoMetricsCallback
InteriorMetricsCallback
TextureMetricsCallback
WaterMetricsCallback
TimeMetricsCallback
VehicleMetricsCallback
AudioMetricsCallback
DebugMetricsCallback
Metrics
common/client/mission.cs