Initial commit
This commit is contained in:
43
example/common/client/actionMap.cs
Executable file
43
example/common/client/actionMap.cs
Executable file
@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Utility remap functions:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function ActionMap::copyBind( %this, %otherMap, %command )
|
||||
{
|
||||
if ( !isObject( %otherMap ) )
|
||||
{
|
||||
error( "ActionMap::copyBind - \"" @ %otherMap @ "\" is not an object!" );
|
||||
return;
|
||||
}
|
||||
|
||||
%bind = %otherMap.getBinding( %command );
|
||||
if ( %bind !$= "" )
|
||||
{
|
||||
%device = getField( %bind, 0 );
|
||||
%action = getField( %bind, 1 );
|
||||
%flags = %otherMap.isInverted( %device, %action ) ? "SDI" : "SD";
|
||||
%deadZone = %otherMap.getDeadZone( %device, %action );
|
||||
%scale = %otherMap.getScale( %device, %action );
|
||||
%this.bind( %device, %action, %flags, %deadZone, %scale, %command );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function ActionMap::blockBind( %this, %otherMap, %command )
|
||||
{
|
||||
if ( !isObject( %otherMap ) )
|
||||
{
|
||||
error( "ActionMap::blockBind - \"" @ %otherMap @ "\" is not an object!" );
|
||||
return;
|
||||
}
|
||||
|
||||
%bind = %otherMap.getBinding( %command );
|
||||
if ( %bind !$= "" )
|
||||
%this.bind( getField( %bind, 0 ), getField( %bind, 1 ), "" );
|
||||
}
|
||||
|
50
example/common/client/audio.cs
Executable file
50
example/common/client/audio.cs
Executable file
@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Engine
|
||||
//
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function OpenALInit()
|
||||
{
|
||||
OpenALShutdownDriver();
|
||||
|
||||
echo("");
|
||||
echo("OpenAL Driver Init:");
|
||||
|
||||
echo ($pref::Audio::driver);
|
||||
|
||||
if($pref::Audio::driver $= "OpenAL")
|
||||
{
|
||||
if(!OpenALInitDriver())
|
||||
{
|
||||
error(" Failed to initialize driver.");
|
||||
$Audio::initFailed = true;
|
||||
} else {
|
||||
// this should go here
|
||||
echo(" Vendor: " @ alGetString("AL_VENDOR"));
|
||||
echo(" Version: " @ alGetString("AL_VERSION"));
|
||||
echo(" Renderer: " @ alGetString("AL_RENDERER"));
|
||||
echo(" Extensions: " @ alGetString("AL_EXTENSIONS"));
|
||||
|
||||
alxListenerf( AL_GAIN_LINEAR, $pref::Audio::masterVolume );
|
||||
|
||||
for (%channel=1; %channel <= 8; %channel++)
|
||||
alxSetChannelVolume(%channel, $pref::Audio::channelVolume[%channel]);
|
||||
|
||||
echo("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
function OpenALShutdown()
|
||||
{
|
||||
OpenALShutdownDriver();
|
||||
//alxStopAll();
|
||||
//AudioGui.delete();
|
||||
//sButtonDown.delete();
|
||||
//sButtonOver.delete();
|
||||
}
|
65
example/common/client/canvas.cs
Executable file
65
example/common/client/canvas.cs
Executable file
@ -0,0 +1,65 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Function to construct and initialize the default canvas window
|
||||
// used by the games
|
||||
|
||||
function initCanvas(%windowName, %effectCanvas)
|
||||
{
|
||||
videoSetGammaCorrection($pref::OpenGL::gammaCorrection);
|
||||
|
||||
if( %effectCanvas )
|
||||
%canvasCreate = createEffectCanvas( %windowName );
|
||||
else
|
||||
%canvasCreate = createCanvas( %windowName );
|
||||
|
||||
if( !%canvasCreate )
|
||||
{
|
||||
quitWithErrorMessage("Copy of Torque is already running; exiting.");
|
||||
return;
|
||||
}
|
||||
|
||||
setOpenGLTextureCompressionHint( $pref::OpenGL::compressionHint );
|
||||
setOpenGLAnisotropy( $pref::OpenGL::textureAnisotropy );
|
||||
setOpenGLMipReduction( $pref::OpenGL::mipReduction );
|
||||
setOpenGLInteriorMipReduction( $pref::OpenGL::interiorMipReduction );
|
||||
setOpenGLSkyMipReduction( $pref::OpenGL::skyMipReduction );
|
||||
|
||||
// Declare default GUI Profiles.
|
||||
exec("~/ui/defaultProfiles.cs");
|
||||
|
||||
// Common GUI's
|
||||
exec("~/ui/ConsoleDlg.gui");
|
||||
exec("~/ui/LoadFileDlg.gui");
|
||||
exec("~/ui/ColorPickerDlg.gui");
|
||||
exec("~/ui/SaveFileDlg.gui");
|
||||
exec("~/ui/MessageBoxOkDlg.gui");
|
||||
exec("~/ui/MessageBoxYesNoDlg.gui");
|
||||
exec("~/ui/MessageBoxOKCancelDlg.gui");
|
||||
exec("~/ui/MessagePopupDlg.gui");
|
||||
exec("~/ui/HelpDlg.gui");
|
||||
exec("~/ui/RecordingsDlg.gui");
|
||||
exec("~/ui/NetGraphGui.gui");
|
||||
|
||||
// Commonly used helper scripts
|
||||
exec("./metrics.cs");
|
||||
exec("./messageBox.cs");
|
||||
exec("./screenshot.cs");
|
||||
exec("./cursor.cs");
|
||||
exec("./help.cs");
|
||||
exec("./recordings.cs");
|
||||
|
||||
// Init the audio system
|
||||
OpenALInit();
|
||||
}
|
||||
|
||||
function resetCanvas()
|
||||
{
|
||||
if (isObject(Canvas))
|
||||
{
|
||||
Canvas.repaint();
|
||||
}
|
||||
}
|
98
example/common/client/cursor.cs
Executable file
98
example/common/client/cursor.cs
Executable file
@ -0,0 +1,98 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Cursor Control
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
$cursorControlled = true;
|
||||
|
||||
function cursorOff()
|
||||
{
|
||||
if ( $cursorControlled )
|
||||
lockMouse(true);
|
||||
Canvas.cursorOff();
|
||||
}
|
||||
|
||||
function cursorOn()
|
||||
{
|
||||
if ( $cursorControlled )
|
||||
lockMouse(false);
|
||||
Canvas.cursorOn();
|
||||
Canvas.setCursor(DefaultCursor);
|
||||
}
|
||||
|
||||
// In the CanvasCursor package we add some additional functionality to the
|
||||
// built-in GuiCanvas class, of which the global Canvas object is an instance.
|
||||
// In this case, the behavior we want is for the cursor to automatically display,
|
||||
// except when the only guis visible want no cursor - most notably,
|
||||
// in the case of the example, the play gui.
|
||||
// In order to override or extend an existing class, we use the script package
|
||||
// feature.
|
||||
|
||||
package CanvasCursor
|
||||
{
|
||||
|
||||
// The checkCursor method iterates through all the root controls on the canvas
|
||||
// (basically the content control and any visible dialogs). If all of them
|
||||
// have the .noCursor attribute set, the cursor is turned off, otherwise it is
|
||||
// turned on.
|
||||
|
||||
function GuiCanvas::checkCursor(%this)
|
||||
{
|
||||
%cursorShouldBeOn = false;
|
||||
for(%i = 0; %i < %this.getCount(); %i++)
|
||||
{
|
||||
%control = %this.getObject(%i);
|
||||
if(%control.noCursor == 0)
|
||||
{
|
||||
%cursorShouldBeOn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(%cursorShouldBeOn != %this.isCursorOn())
|
||||
{
|
||||
if(%cursorShouldBeOn)
|
||||
cursorOn();
|
||||
else
|
||||
cursorOff();
|
||||
}
|
||||
}
|
||||
|
||||
// below, all functions which can alter which content controls are visible
|
||||
// are extended to call the checkCursor function. For package'd functions,
|
||||
// the Parent:: call refers to the original implementation of that function,
|
||||
// or a version that was declared in a previously activated package.
|
||||
// In this case the parent calls should point to the built in versions
|
||||
// of GuiCanvas functions.
|
||||
|
||||
function GuiCanvas::setContent(%this, %ctrl)
|
||||
{
|
||||
Parent::setContent(%this, %ctrl);
|
||||
%this.checkCursor();
|
||||
}
|
||||
|
||||
function GuiCanvas::pushDialog(%this, %ctrl, %layer)
|
||||
{
|
||||
Parent::pushDialog(%this, %ctrl, %layer);
|
||||
%this.checkCursor();
|
||||
}
|
||||
|
||||
function GuiCanvas::popDialog(%this, %ctrl)
|
||||
{
|
||||
Parent::popDialog(%this, %ctrl);
|
||||
%this.checkCursor();
|
||||
}
|
||||
|
||||
function GuiCanvas::popLayer(%this, %layer)
|
||||
{
|
||||
Parent::popLayer(%this, %layer);
|
||||
%this.checkCursor();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// activate the package when the script loads.
|
||||
activatePackage(CanvasCursor);
|
74
example/common/client/help.cs
Executable file
74
example/common/client/help.cs
Executable file
@ -0,0 +1,74 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Engine
|
||||
//
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function HelpDlg::onWake(%this)
|
||||
{
|
||||
HelpFileList.entryCount = 0;
|
||||
HelpFileList.clear();
|
||||
for(%file = findFirstFile("*.hfl"); %file !$= ""; %file = findNextFile("*.hfl"))
|
||||
{
|
||||
HelpFileList.fileName[HelpFileList.entryCount] = %file;
|
||||
HelpFileList.addRow(HelpFileList.entryCount, fileBase(%file));
|
||||
HelpFileList.entryCount++;
|
||||
}
|
||||
HelpFileList.sortNumerical(0);
|
||||
for(%i = 0; %i < HelpFileList.entryCount; %i++)
|
||||
{
|
||||
%rowId = HelpFileList.getRowId(%i);
|
||||
%text = HelpFileList.getRowTextById(%rowId);
|
||||
%text = %i + 1 @ ". " @ restWords(%text);
|
||||
HelpFileList.setRowById(%rowId, %text);
|
||||
}
|
||||
HelpFileList.setSelectedRow(0);
|
||||
}
|
||||
|
||||
function HelpFileList::onSelect(%this, %row)
|
||||
{
|
||||
%fo = new FileObject();
|
||||
%fo.openForRead(%this.fileName[%row]);
|
||||
%text = "";
|
||||
while(!%fo.isEOF())
|
||||
%text = %text @ %fo.readLine() @ "\n";
|
||||
|
||||
%fo.delete();
|
||||
HelpText.setText(%text);
|
||||
}
|
||||
|
||||
function getHelp(%helpName)
|
||||
{
|
||||
Canvas.pushDialog(HelpDlg);
|
||||
if(%helpName !$= "")
|
||||
{
|
||||
%index = HelpFileList.findTextIndex(%helpName);
|
||||
HelpFileList.setSelectedRow(%index);
|
||||
}
|
||||
}
|
||||
|
||||
function contextHelp()
|
||||
{
|
||||
for(%i = 0; %i < Canvas.getCount(); %i++)
|
||||
{
|
||||
if(Canvas.getObject(%i).getName() $= HelpDlg)
|
||||
{
|
||||
Canvas.popDialog(HelpDlg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
%content = Canvas.getContent();
|
||||
%helpPage = %content.getHelpPage();
|
||||
getHelp(%helpPage);
|
||||
}
|
||||
|
||||
function GuiControl::getHelpPage(%this)
|
||||
{
|
||||
return %this.helpPage;
|
||||
}
|
||||
|
||||
function GuiMLTextCtrl::onURL(%this, %url)
|
||||
{
|
||||
gotoWebPage( %url );
|
||||
}
|
||||
|
79
example/common/client/message.cs
Executable file
79
example/common/client/message.cs
Executable file
@ -0,0 +1,79 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions that process commands sent from the server.
|
||||
|
||||
|
||||
// This function is for chat messages only; it is invoked on the client when
|
||||
// the server does a commandToClient with the tag ChatMessage. (Cf. the
|
||||
// functions chatMessage* in common/server/message.cs.)
|
||||
|
||||
// This just invokes onChatMessage, which the mod code must define.
|
||||
|
||||
function clientCmdChatMessage(%sender, %voice, %pitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
|
||||
{
|
||||
onChatMessage(detag(%msgString), %voice, %pitch);
|
||||
}
|
||||
|
||||
|
||||
// Game event descriptions, which may or may not include text messages, can be
|
||||
// sent using the message* functions in common/server/message.cs. Those
|
||||
// functions do commandToClient with the tag ServerMessage, which invokes the
|
||||
// function below.
|
||||
|
||||
// For ServerMessage messages, the client can install callbacks that will be
|
||||
// run, according to the "type" of the message.
|
||||
|
||||
function clientCmdServerMessage(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
|
||||
{
|
||||
// Get the message type; terminates at any whitespace.
|
||||
%tag = getWord(%msgType, 0);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called by the client to install a callback for a particular type of
|
||||
// ServerMessage.
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The following is the callback that will be executed for every ServerMessage,
|
||||
// because we're going to install it without a specified type. Any type-
|
||||
// specific callbacks will be executed afterward.
|
||||
|
||||
// This just invokes onServerMessage, which the mod code must define.
|
||||
|
||||
function defaultMessageCallback(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
|
||||
{
|
||||
onServerMessage(detag(%msgString));
|
||||
}
|
||||
|
||||
// Register that default message handler now.
|
||||
addMessageCallback("", defaultMessageCallback);
|
108
example/common/client/messageBox.cs
Executable file
108
example/common/client/messageBox.cs
Executable file
@ -0,0 +1,108 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function MessageCallback(%dlg,%callback)
|
||||
{
|
||||
Canvas.popDialog(%dlg);
|
||||
eval(%callback);
|
||||
}
|
||||
|
||||
// MBSetText resizes the message window, based on the change in size of the text
|
||||
// area.
|
||||
|
||||
function MBSetText(%text, %frame, %msg)
|
||||
{
|
||||
%ext = %text.getExtent();
|
||||
|
||||
%text.setText("<just:center>" @ %msg);
|
||||
%text.forceReflow();
|
||||
|
||||
%newExtent = %text.getExtent();
|
||||
|
||||
%deltaY = getWord(%newExtent, 1) - getWord(%ext, 1);
|
||||
%windowPos = %frame.getPosition();
|
||||
%windowExt = %frame.getExtent();
|
||||
|
||||
%frame.resize(getWord(%windowPos, 0), getWord(%windowPos, 1) - (%deltaY / 2), getWord(%windowExt, 0), getWord(%windowExt, 1) + %deltaY);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// MessageBox OK
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function MessageBoxOK( %title, %message, %callback )
|
||||
{
|
||||
MBOKFrame.setText( %title );
|
||||
Canvas.pushDialog( MessageBoxOKDlg );
|
||||
MBSetText(MBOKText, MBOKFrame, %message);
|
||||
MessageBoxOKDlg.callback = %callback;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function MessageBoxOKDlg::onSleep( %this )
|
||||
{
|
||||
%this.callback = "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageBox OK/Cancel dialog:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageBoxOKCancel( %title, %message, %callback, %cancelCallback )
|
||||
{
|
||||
MBOKCancelFrame.setText( %title );
|
||||
Canvas.pushDialog( MessageBoxOKCancelDlg );
|
||||
MBSetText(MBOKCancelText, MBOKCancelFrame, %message);
|
||||
MessageBoxOKCancelDlg.callback = %callback;
|
||||
MessageBoxOKCancelDlg.cancelCallback = %cancelCallback;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function MessageBoxOKCancelDlg::onSleep( %this )
|
||||
{
|
||||
%this.callback = "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageBox Yes/No dialog:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessageBoxYesNo( %title, %message, %yesCallback, %noCallback )
|
||||
{
|
||||
MBYesNoFrame.setText( %title );
|
||||
Canvas.pushDialog( MessageBoxYesNoDlg );
|
||||
MBSetText(MBYesNoText, MBYesNoFrame, %message);
|
||||
MessageBoxYesNoDlg.yesCallBack = %yesCallback;
|
||||
MessageBoxYesNoDlg.noCallback = %noCallBack;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function MessageBoxYesNoDlg::onSleep( %this )
|
||||
{
|
||||
%this.yesCallback = "";
|
||||
%this.noCallback = "";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Message popup dialog:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function MessagePopup( %title, %message, %delay )
|
||||
{
|
||||
// Currently two lines max.
|
||||
MessagePopFrame.setText( %title );
|
||||
Canvas.pushDialog( MessagePopupDlg );
|
||||
MBSetText(MessagePopText, MessagePopFrame, %message);
|
||||
if ( %delay !$= "" )
|
||||
schedule( %delay, 0, CloseMessagePopup );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
function CloseMessagePopup()
|
||||
{
|
||||
Canvas.popDialog( MessagePopupDlg );
|
||||
}
|
||||
|
157
example/common/client/metrics.cs
Executable file
157
example/common/client/metrics.cs
Executable file
@ -0,0 +1,157 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// load gui used to display various metric outputs
|
||||
exec("~/ui/FrameOverlayGui.gui");
|
||||
|
||||
|
||||
function fpsMetricsCallback()
|
||||
{
|
||||
return " FPS: " @ $fps::real @
|
||||
" mspf: " @ 1000 / $fps::real;
|
||||
}
|
||||
|
||||
function terrainMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Terrain -" @
|
||||
" L0: " @ $T2::levelZeroCount @
|
||||
" FMC: " @ $T2::fullMipCount @
|
||||
" DTC: " @ $T2::dynamicTextureCount @
|
||||
" UNU: " @ $T2::unusedTextureCount @
|
||||
" STC: " @ $T2::staticTextureCount @
|
||||
" DTSU: " @ $T2::textureSpaceUsed @
|
||||
" STSU: " @ $T2::staticTSU @
|
||||
" FRB: " @ $T2::FogRejections;
|
||||
}
|
||||
|
||||
function videoMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Video -" @
|
||||
" TC: " @ $OpenGL::triCount0 + $OpenGL::triCount1 + $OpenGL::triCount2 + $OpenGL::triCount3 @
|
||||
" PC: " @ $OpenGL::primCount0 + $OpenGL::primCount1 + $OpenGL::primCount2 + $OpenGL::primCount3 @
|
||||
" T_T: " @ $OpenGL::triCount1 @
|
||||
" T_P: " @ $OpenGL::primCount1 @
|
||||
" I_T: " @ $OpenGL::triCount2 @
|
||||
" I_P: " @ $OpenGL::primCount2 @
|
||||
" TS_T: " @ $OpenGL::triCount3 @
|
||||
" TS_P: " @ $OpenGL::primCount3 @
|
||||
" ?_T: " @ $OpenGL::triCount0 @
|
||||
" ?_P: " @ $OpenGL::primCount0;
|
||||
}
|
||||
|
||||
function interiorMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Interior --" @
|
||||
" NTL: " @ $Video::numTexelsLoaded @
|
||||
" TRP: " @ $Video::texResidentPercentage @
|
||||
" INP: " @ $Metrics::Interior::numPrimitives @
|
||||
" INT: " @ $Matrics::Interior::numTexturesUsed @
|
||||
" INO: " @ $Metrics::Interior::numInteriors;
|
||||
}
|
||||
|
||||
function textureMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Texture --"@
|
||||
" NTL: " @ $Video::numTexelsLoaded @
|
||||
" TRP: " @ $Video::texResidentPercentage @
|
||||
" TCM: " @ $Video::textureCacheMisses;
|
||||
}
|
||||
|
||||
function waterMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Water --"@
|
||||
" Tri#: " @ $T2::waterTriCount @
|
||||
" Pnt#: " @ $T2::waterPointCount @
|
||||
" Hz#: " @ $T2::waterHazePointCount;
|
||||
}
|
||||
|
||||
function timeMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Time -- " @
|
||||
" Sim Time: " @ getSimTime() @
|
||||
" Mod: " @ getSimTime() % 32;
|
||||
}
|
||||
|
||||
function vehicleMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Vehicle --"@
|
||||
" R: " @ $Vehicle::retryCount @
|
||||
" C: " @ $Vehicle::searchCount @
|
||||
" P: " @ $Vehicle::polyCount @
|
||||
" V: " @ $Vehicle::vertexCount;
|
||||
}
|
||||
|
||||
function audioMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Audio --"@
|
||||
" OH: " @ $Audio::numOpenHandles @
|
||||
" OLH: " @ $Audio::numOpenLoopingHandles @
|
||||
" AS: " @ $Audio::numActiveStreams @
|
||||
" NAS: " @ $Audio::numNullActiveStreams @
|
||||
" LAS: " @ $Audio::numActiveLoopingStreams @
|
||||
" LS: " @ $Audio::numLoopingStreams @
|
||||
" ILS: " @ $Audio::numInactiveLoopingStreams @
|
||||
" CLS: " @ $Audio::numCulledLoopingStreams;
|
||||
}
|
||||
|
||||
function debugMetricsCallback()
|
||||
{
|
||||
return fpsMetricsCallback() @
|
||||
" Debug --"@
|
||||
" NTL: " @ $Video::numTexelsLoaded @
|
||||
" TRP: " @ $Video::texResidentPercentage @
|
||||
" NP: " @ $Metrics::numPrimitives @
|
||||
" NT: " @ $Metrics::numTexturesUsed @
|
||||
" NO: " @ $Metrics::numObjectsRendered;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function metrics(%expr)
|
||||
{
|
||||
switch$(%expr)
|
||||
{
|
||||
case "audio": %cb = "audioMetricsCallback()";
|
||||
case "debug": %cb = "debugMetricsCallback()";
|
||||
case "interior":
|
||||
$fps::virtual = 0;
|
||||
$Interior::numPolys = 0;
|
||||
$Interior::numTextures = 0;
|
||||
$Interior::numTexels = 0;
|
||||
$Interior::numLightmaps = 0;
|
||||
$Interior::numLumels = 0;
|
||||
%cb = "interiorMetricsCallback()";
|
||||
|
||||
case "fps": %cb = "fpsMetricsCallback()";
|
||||
case "time": %cb = "timeMetricsCallback()";
|
||||
case "terrain": %cb = "terrainMetricsCallback()";
|
||||
case "texture":
|
||||
GLEnableMetrics(true);
|
||||
%cb = "textureMetricsCallback()";
|
||||
|
||||
case "video": %cb = "videoMetricsCallback()";
|
||||
case "vehicle": %cb = "vehicleMetricsCallback()";
|
||||
case "water": %cb = "waterMetricsCallback()";
|
||||
}
|
||||
|
||||
if (%cb !$= "")
|
||||
{
|
||||
Canvas.pushDialog(FrameOverlayGui, 1000);
|
||||
TextOverlayControl.setValue(%cb);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLEnableMetrics(false);
|
||||
Canvas.popDialog(FrameOverlayGui);
|
||||
}
|
||||
}
|
26
example/common/client/mission.cs
Executable file
26
example/common/client/mission.cs
Executable file
@ -0,0 +1,26 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Mission start / end events sent from the server
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function clientCmdMissionStart(%seq)
|
||||
{
|
||||
// The client recieves a mission start right before
|
||||
// being dropped into the game.
|
||||
}
|
||||
|
||||
function clientCmdMissionEnd(%seq)
|
||||
{
|
||||
// Recieved when the current mission is ended.
|
||||
alxStopAll();
|
||||
|
||||
// Disable mission lighting if it's going, this is here
|
||||
// in case the mission ends while we are in the process
|
||||
// of loading it.
|
||||
$lightingMission = false;
|
||||
$sceneLighting::terminateLighting = true;
|
||||
}
|
110
example/common/client/missionDownload.cs
Executable file
110
example/common/client/missionDownload.cs
Executable file
@ -0,0 +1,110 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Mission Loading
|
||||
// Server download handshaking. This produces a number of onPhaseX
|
||||
// calls so the game scripts can update the game's GUI.
|
||||
//
|
||||
// Loading Phases:
|
||||
// Phase 1: Download Datablocks
|
||||
// Phase 2: Download Ghost Objects
|
||||
// Phase 3: Scene Lighting
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Phase 1
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function clientCmdMissionStartPhase1(%seq, %missionName, %musicTrack)
|
||||
{
|
||||
// These need to come after the cls.
|
||||
echo ("*** New Mission: " @ %missionName);
|
||||
echo ("*** Phase 1: Download Datablocks & Targets");
|
||||
onMissionDownloadPhase1(%missionName, %musicTrack);
|
||||
commandToServer('MissionStartPhase1Ack', %seq);
|
||||
}
|
||||
|
||||
function onDataBlockObjectReceived(%index, %total)
|
||||
{
|
||||
onPhase1Progress(%index / %total);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Phase 2
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function clientCmdMissionStartPhase2(%seq,%missionName)
|
||||
{
|
||||
onPhase1Complete();
|
||||
echo ("*** Phase 2: Download Ghost Objects");
|
||||
purgeResources();
|
||||
onMissionDownloadPhase2(%missionName);
|
||||
commandToServer('MissionStartPhase2Ack', %seq);
|
||||
}
|
||||
|
||||
function onGhostAlwaysStarted(%ghostCount)
|
||||
{
|
||||
$ghostCount = %ghostCount;
|
||||
$ghostsRecvd = 0;
|
||||
}
|
||||
|
||||
function onGhostAlwaysObjectReceived()
|
||||
{
|
||||
$ghostsRecvd++;
|
||||
onPhase2Progress($ghostsRecvd / $ghostCount);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Phase 3
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function clientCmdMissionStartPhase3(%seq,%missionName)
|
||||
{
|
||||
onPhase2Complete();
|
||||
StartClientReplication();
|
||||
StartFoliageReplication();
|
||||
echo ("*** Phase 3: Mission Lighting");
|
||||
$MSeq = %seq;
|
||||
$Client::MissionFile = %missionName;
|
||||
|
||||
// Need to light the mission before we are ready.
|
||||
// The sceneLightingComplete function will complete the handshake
|
||||
// once the scene lighting is done.
|
||||
if (lightScene("sceneLightingComplete", ""))
|
||||
{
|
||||
error("Lighting mission....");
|
||||
schedule(1, 0, "updateLightingProgress");
|
||||
onMissionDownloadPhase3(%missionName);
|
||||
$lightingMission = true;
|
||||
}
|
||||
}
|
||||
|
||||
function updateLightingProgress()
|
||||
{
|
||||
onPhase3Progress($SceneLighting::lightingProgress);
|
||||
if ($lightingMission)
|
||||
$lightingProgressThread = schedule(1, 0, "updateLightingProgress");
|
||||
}
|
||||
|
||||
function sceneLightingComplete()
|
||||
{
|
||||
echo("Mission lighting done");
|
||||
onPhase3Complete();
|
||||
|
||||
// The is also the end of the mission load cycle.
|
||||
onMissionDownloadComplete();
|
||||
commandToServer('MissionStartPhase3Ack', $MSeq);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Helper functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function connect(%server)
|
||||
{
|
||||
%conn = new GameConnection();
|
||||
%conn.connect(%server);
|
||||
}
|
111
example/common/client/recordings.cs
Executable file
111
example/common/client/recordings.cs
Executable file
@ -0,0 +1,111 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// RecordingsGui is the main TSControl through which the a demo game recording
|
||||
// is viewed.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function recordingsDlg::onWake()
|
||||
{
|
||||
RecordingsDlgList.clear();
|
||||
%i = 0;
|
||||
%filespec = $currentMod @ "/recordings/*.rec";
|
||||
echo(%filespec);
|
||||
for(%file = findFirstFile(%filespec); %file !$= ""; %file = findNextFile(%filespec))
|
||||
{
|
||||
%fileName = fileBase(%file);
|
||||
if (strStr(%file, "/CVS/") == -1)
|
||||
{
|
||||
RecordingsDlgList.addRow(%i++, %fileName);
|
||||
}
|
||||
}
|
||||
RecordingsDlgList.sort(0);
|
||||
RecordingsDlgList.setSelectedRow(0);
|
||||
RecordingsDlgList.scrollVisible(0);
|
||||
}
|
||||
|
||||
function StartSelectedDemo()
|
||||
{
|
||||
// first unit is filename
|
||||
%sel = RecordingsDlgList.getSelectedId();
|
||||
%rowText = RecordingsDlgList.getRowTextById(%sel);
|
||||
|
||||
%file = $currentMod @ "/recordings/" @ getField(%rowText, 0) @ ".rec";
|
||||
|
||||
new GameConnection(ServerConnection);
|
||||
RootGroup.add(ServerConnection);
|
||||
|
||||
if(ServerConnection.playDemo(%file))
|
||||
{
|
||||
Canvas.setContent(PlayGui);
|
||||
Canvas.popDialog(RecordingsDlg);
|
||||
ServerConnection.prepDemoPlayback();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxOK("Playback Failed", "Demo playback failed for file '" @ %file @ "'.");
|
||||
if (isObject(ServerConnection)) {
|
||||
ServerConnection.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function startDemoRecord()
|
||||
{
|
||||
// make sure that current recording stream is stopped
|
||||
ServerConnection.stopRecording();
|
||||
|
||||
// make sure we aren't playing a demo
|
||||
if(ServerConnection.isDemoPlaying())
|
||||
return;
|
||||
|
||||
for(%i = 0; %i < 1000; %i++)
|
||||
{
|
||||
%num = %i;
|
||||
if(%num < 10)
|
||||
%num = "0" @ %num;
|
||||
if(%num < 100)
|
||||
%num = "0" @ %num;
|
||||
|
||||
%file = $currentMod @ "/recordings/demo" @ %num @ ".rec";
|
||||
if(!isfile(%file))
|
||||
break;
|
||||
}
|
||||
if(%i == 1000)
|
||||
return;
|
||||
|
||||
$DemoFileName = %file;
|
||||
|
||||
ChatHud.AddLine( "\c4Recording to file [\c2" @ $DemoFileName @ "\cr].");
|
||||
|
||||
ServerConnection.prepDemoRecord();
|
||||
ServerConnection.startRecording($DemoFileName);
|
||||
|
||||
// make sure start worked
|
||||
if(!ServerConnection.isDemoRecording())
|
||||
{
|
||||
deleteFile($DemoFileName);
|
||||
ChatHud.AddLine( "\c3 *** Failed to record to file [\c2" @ $DemoFileName @ "\cr].");
|
||||
$DemoFileName = "";
|
||||
}
|
||||
}
|
||||
|
||||
function stopDemoRecord()
|
||||
{
|
||||
// make sure we are recording
|
||||
if(ServerConnection.isDemoRecording())
|
||||
{
|
||||
ChatHud.AddLine( "\c4Recording file [\c2" @ $DemoFileName @ "\cr] finished.");
|
||||
ServerConnection.stopRecording();
|
||||
}
|
||||
}
|
||||
|
||||
function demoPlaybackComplete()
|
||||
{
|
||||
disconnect();
|
||||
Canvas.setContent("MainMenuGui");
|
||||
Canvas.pushDialog(RecordingsDlg);
|
||||
}
|
80
example/common/client/screenshot.cs
Executable file
80
example/common/client/screenshot.cs
Executable file
@ -0,0 +1,80 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Game Engine
|
||||
// Copyright (C) GarageGames.com, Inc.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
function formatImageNumber(%number)
|
||||
{
|
||||
if(%number < 10)
|
||||
%number = "0" @ %number;
|
||||
if(%number < 100)
|
||||
%number = "0" @ %number;
|
||||
if(%number < 1000)
|
||||
%number = "0" @ %number;
|
||||
if(%number < 10000)
|
||||
%number = "0" @ %number;
|
||||
return %number;
|
||||
}
|
||||
|
||||
function formatSessionNumber(%number)
|
||||
{
|
||||
if(%number < 10)
|
||||
%number = "0" @ %number;
|
||||
if(%number < 100)
|
||||
%number = "0" @ %number;
|
||||
return %number;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
function recordMovie(%movieName, %fps)
|
||||
{
|
||||
$timeAdvance = 1000 / %fps;
|
||||
$screenGrabThread = schedule($timeAdvance,0,movieGrabScreen,%movieName,0);
|
||||
}
|
||||
|
||||
function movieGrabScreen(%movieName, %frameNumber)
|
||||
{
|
||||
screenshot(%movieName @ formatImageNumber(%frameNumber) @ ".png");
|
||||
$screenGrabThread = schedule($timeAdvance, 0, movieGrabScreen, %movieName, %frameNumber + 1);
|
||||
}
|
||||
|
||||
function stopMovie()
|
||||
{
|
||||
$timeAdvance = 0;
|
||||
cancel($screenGrabThread);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------
|
||||
$screenshotNumber = 0;
|
||||
|
||||
function doScreenShot( %val )
|
||||
{
|
||||
if (%val)
|
||||
{
|
||||
if ($pref::Video::screenShotSession $= "")
|
||||
$pref::Video::screenShotSession = 0;
|
||||
if ($screenshotNumber == 0)
|
||||
$pref::Video::screenShotSession++;
|
||||
if ($pref::Video::screenShotSession > 999)
|
||||
$pref::Video::screenShotSession = 1;
|
||||
|
||||
$pref::interior::showdetailmaps = false;
|
||||
$name = "screenshot_" @ formatSessionNumber($pref::Video::screenShotSession) @ "-" @ formatImageNumber($screenshotNumber++);
|
||||
|
||||
if($pref::Video::screenShotFormat $= "JPEG")
|
||||
screenShot($name @ ".jpg", "JPEG");
|
||||
else
|
||||
if($pref::Video::screenShotFormat $= "PNG")
|
||||
screenShot($name @ ".png", "PNG");
|
||||
else
|
||||
screenShot($name @ ".png", "PNG");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// bind key to take screenshots
|
||||
GlobalActionMap.bind(keyboard, "ctrl p", doScreenShot);
|
||||
|
19
example/common/client/scriptDoc.cs
Executable file
19
example/common/client/scriptDoc.cs
Executable file
@ -0,0 +1,19 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Torque Engine
|
||||
//
|
||||
// Copyright (c) 2001 GarageGames.Com
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Writes out all script functions to a file
|
||||
function writeOutFunctions() {
|
||||
new ConsoleLogger( logger, "scriptFunctions.txt", false );
|
||||
dumpConsoleFunctions();
|
||||
logger.delete();
|
||||
}
|
||||
|
||||
// Writes out all script classes to a file
|
||||
function writeOutClasses() {
|
||||
new ConsoleLogger( logger, "scriptClasses.txt", false );
|
||||
dumpConsoleClasses();
|
||||
logger.delete();
|
||||
}
|
Reference in New Issue
Block a user