Module-ified core structure.

This commit is contained in:
Areloch 2018-09-02 03:53:13 -05:00
parent bfc140a6fa
commit ee2ba2111f
430 changed files with 39903 additions and 1 deletions

View file

@ -0,0 +1,145 @@
function CoreModule::onCreate(%this)
{
// ----------------------------------------------------------------------------
// Initialize core sub system functionality such as audio, the Canvas, PostFX,
// rendermanager, light managers, etc.
//
// Note that not all of these need to be initialized before the client, although
// the audio should and the canvas definitely needs to be. I've put things here
// to distinguish between the purpose and functionality of the various client
// scripts. Game specific script isn't needed until we reach the shell menus
// and start a game or connect to a server. We get the various subsystems ready
// to go, and then use initClient() to handle the rest of the startup sequence.
//
// If this is too convoluted we can reduce this complexity after futher testing
// to find exactly which subsystems should be readied before kicking things off.
// ----------------------------------------------------------------------------
ModuleDatabase.LoadExplicit( "Core_Rendering" );
ModuleDatabase.LoadExplicit( "Core_Utility" );
ModuleDatabase.LoadExplicit( "Core_GUI" );
ModuleDatabase.LoadExplicit( "CoreModule" );
ModuleDatabase.LoadExplicit( "Core_Lighting" );
ModuleDatabase.LoadExplicit( "Core_SFX" );
ModuleDatabase.LoadExplicit( "Core_PostFX" );
ModuleDatabase.LoadExplicit( "Core_VR" );
ModuleDatabase.LoadExplicit( "Core_VR" );
ModuleDatabase.LoadExplicit( "Core_ClientServer" );
%prefPath = getPrefpath();
if ( isFile( %prefPath @ "/clientPrefs.cs" ) )
exec( %prefPath @ "/clientPrefs.cs" );
else
exec("data/defaults.cs");
%der = $pref::Video::displayDevice;
//We need to hook the missing/warn material stuff early, so do it here
/*$Core::MissingTexturePath = "core/images/missingTexture";
$Core::UnAvailableTexturePath = "core/images/unavailable";
$Core::WarningTexturePath = "core/images/warnMat";
$Core::CommonShaderPath = "core/shaders";
/*%classList = enumerateConsoleClasses( "Component" );
foreach$( %componentClass in %classList )
{
echo("Native Component of type: " @ %componentClass);
}*/
//exec("./helperFunctions.cs");
// We need some of the default GUI profiles in order to get the canvas and
// other aspects of the GUI system ready.
//exec("./profiles.cs");
//This is a bit of a shortcut, but we'll load the client's default settings to ensure all the prefs get initialized correctly
// Initialization of the various subsystems requires some of the preferences
// to be loaded... so do that first.
/*exec("./globals.cs");
exec("./canvas.cs");
exec("./cursor.cs");
exec("./renderManager.cs");
exec("./lighting.cs");
exec("./audio.cs");
exec("./sfx/audioAmbience.cs");
exec("./sfx/audioData.cs");
exec("./sfx/audioDescriptions.cs");
exec("./sfx/audioEnvironments.cs");
exec("./sfx/audioStates.cs");
exec("./parseArgs.cs");
// Materials and Shaders for rendering various object types
exec("./gfxData/commonMaterialData.cs");
exec("./gfxData/shaders.cs");
exec("./gfxData/terrainBlock.cs");
exec("./gfxData/water.cs");
exec("./gfxData/scatterSky.cs");
exec("./gfxData/clouds.cs");
// Initialize all core post effects.
exec("./postFx.cs");
//VR stuff
exec("./oculusVR.cs");*/
// Seed the random number generator.
setRandomSeed();
// Parse the command line arguments
echo("\n--------- Parsing Arguments ---------");
parseArgs();
// The canvas needs to be initialized before any gui scripts are run since
// some of the controls assume that the canvas exists at load time.
createCanvas($appName);
//load canvas
//exec("./console/main.cs");
ModuleDatabase.LoadExplicit( "Core_Console" );
// Init the physics plugin.
physicsInit();
sfxStartup();
// Set up networking.
setNetPort(0);
// Start processing file change events.
startFileChangeNotifications();
// If we have editors, initialize them here as well
if (isToolBuild())
{
if(isFile("tools/main.cs") && !$isDedicated)
exec("tools/main.cs");
ModuleDatabase.scanModules( "tools", false );
ModuleDatabase.LoadGroup( "Tools" );
}
}
function CoreModule::onDestroy(%this)
{
}
//-----------------------------------------------------------------------------
// Called when the engine is shutting down.
function onExit()
{
// Stop file change events.
stopFileChangeNotifications();
ModuleDatabase.UnloadExplicit( "Game" );
}

View file

@ -0,0 +1,19 @@
<ModuleDefinition
ModuleId="CoreModule"
VersionId="1"
Description="Module that implements the core engine-level setup for the game."
ScriptFile="Core.cs"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core">
<DeclaredAssets
canSave="true"
canSaveDynamicFields="true"
Extension="asset.taml"
Recurse="true" />
<AutoloadAssets
canSave="true"
canSaveDynamicFields="true"
AssetType="ComponentAsset"
Recurse="true" />
</ModuleDefinition>

View file

@ -0,0 +1,112 @@
// The general flow of a gane - server's creation, loading and hosting clients, and then destruction is as follows:
// First, a client will always create a server in the event that they want to host a single player
// game. Torque3D treats even single player connections as a soft multiplayer game, with some stuff
// in the networking short-circuited to sidestep around lag and packet transmission times.
// initServer() is called, loading the default server scripts.
// After that, if this is a dedicated server session, initDedicated() is called, otherwise initClient is called
// to prep a playable client session.
// When a local game is started - a listen server - via calling StartGame() a server is created and then the client is
// connected to it via createAndConnectToLocalServer().
function Core_ClientServer::create( %this )
{
echo("\n--------- Initializing Directory: scripts ---------");
exec( "./scripts/client/client.cs" );
exec( "./scripts/server/server.cs" );
$Game::MissionGroup = "MissionGroup";
initServer();
%dbList = new ArrayObject(DatablockFilesList);
// Start up in either client, or dedicated server mode
if ($Server::Dedicated)
{
initDedicated();
}
else
{
initClient();
}
}
function Core_ClientServer::destroy( %this )
{
// Ensure that we are disconnected and/or the server is destroyed.
// This prevents crashes due to the SceneGraph being deleted before
// the objects it contains.
if ($Server::Dedicated)
destroyServer();
else
disconnect();
// Destroy the physics plugin.
//physicsDestroy();
sfxShutdown();
echo("Exporting client prefs");
%prefPath = getPrefpath();
export("$pref::*", %prefPath @ "/clientPrefs.cs", false);
echo("Exporting server prefs");
export("$Pref::Server::*", %prefPath @ "/serverPrefs.cs", false);
BanList::Export(%prefPath @ "/banlist.cs");
}
//-----------------------------------------------------------------------------
function StartGame( %mission, %hostingType )
{
if( %mission $= "" )
{
%id = CL_levelList.getSelectedId();
%mission = getField(CL_levelList.getRowTextById(%id), 1);
//error("Cannot start a level with no level selected!");
}
if (%hostingType !$= "")
{
%serverType = %hostingType;
}
else
{
if ($pref::HostMultiPlayer)
%serverType = "MultiPlayer";
else
%serverType = "SinglePlayer";
}
// Show the loading screen immediately.
if ( isObject( LoadingGui ) )
{
Canvas.setContent("LoadingGui");
LoadingProgress.setValue(1);
LoadingProgressTxt.setValue("LOADING MISSION FILE");
Canvas.repaint();
}
createAndConnectToLocalServer( %serverType, %mission );
}
function JoinGame( %serverIndex )
{
// The server info index is stored in the row along with the
// rest of displayed info.
if( setServerInfo( %serverIndex ) )
{
Canvas.setContent("LoadingGui");
LoadingProgress.setValue(1);
LoadingProgressTxt.setValue("WAITING FOR SERVER");
Canvas.repaint();
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connect($ServerInfo::Address);
}
}

View file

@ -0,0 +1,9 @@
<ModuleDefinition
ModuleId="Core_ClientServer"
VersionId="1"
Description="Default module for the game."
ScriptFile="Core_ClientServer.cs"
CreateFunction="create"
DestroyFunction="destroy"
Group="Core">
</ModuleDefinition>

View file

@ -0,0 +1,29 @@
function initClient()
{
echo("\n--------- Initializing " @ $appName @ ": Client Scripts ---------");
// Make sure this variable reflects the correct state.
$Server::Dedicated = false;
// Game information used to query the master server
$Client::GameTypeQuery = $appName;
$Client::MissionTypeQuery = "Any";
exec( "./message.cs" );
exec( "./connectionToServer.cs" );
exec( "./levelDownload.cs" );
exec( "./levelLoad.cs" );
//load prefs
%prefPath = getPrefpath();
if ( isFile( %prefPath @ "/clientPrefs.cs" ) )
exec( %prefPath @ "/clientPrefs.cs" );
else
exec( "data/defaults.cs" );
loadMaterials();
// Copy saved script prefs into C++ code.
setDefaultFov( $pref::Player::defaultFov );
setZoomSpeed( $pref::Player::zoomSpeed );
}

View file

@ -0,0 +1,130 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Functions dealing with connecting to a server
//----------------------------------------------------------------------------
// GameConnection client callbacks
//----------------------------------------------------------------------------
// Called on the new connection object after connect() succeeds.
function GameConnection::onConnectionAccepted(%this)
{
// Startup the physX world on the client before any
// datablocks and objects are ghosted over.
physicsInitWorld( "client" );
}
function GameConnection::initialControlSet(%this)
{
echo ("*** Initial Control Object");
// The first control object has been set by the server
// and we are now ready to go.
// first check if the editor is active
if (!isToolBuild() || !isMethod("Editor", "checkActiveLoadDone") || !Editor::checkActiveLoadDone())
{
if (Canvas.getContent() != PlayGui.getId())
Canvas.setContent(PlayGui);
}
}
function GameConnection::onControlObjectChange(%this)
{
echo ("*** Control Object Changed");
// Reset the current FOV to match the new object
// and turn off any current zoom.
resetCurrentFOV();
turnOffZoom();
}
function GameConnection::onConnectionError(%this, %msg)
{
// General connection error, usually raised by ghosted objects
// initialization problems, such as missing files. We'll display
// the server's connection error message.
disconnectedCleanup();
MessageBoxOK( "DISCONNECT", $ServerConnectionErrorMessage @ " (" @ %msg @ ")" );
}
//-----------------------------------------------------------------------------
// Server connection error
//-----------------------------------------------------------------------------
addMessageCallback( 'MsgConnectionError', handleConnectionErrorMessage );
function handleConnectionErrorMessage(%msgType, %msgString, %msgError)
{
// On connect the server transmits a message to display if there
// are any problems with the connection. Most connection errors
// are game version differences, so hopefully the server message
// will tell us where to get the latest version of the game.
$ServerConnectionErrorMessage = %msgError;
}
//-----------------------------------------------------------------------------
// Disconnect
//-----------------------------------------------------------------------------
function disconnect()
{
// We need to stop the client side simulation
// else physics resources will not cleanup properly.
physicsStopSimulation( "client" );
// Delete the connection if it's still there.
if (isObject(ServerConnection))
ServerConnection.delete();
disconnectedCleanup();
// Call destroyServer in case we're hosting
destroyServer();
}
function disconnectedCleanup()
{
// End mission, if it's running.
if( $Client::missionRunning )
clientEndMission();
// Disable mission lighting if it's going, this is here
// in case we're disconnected while the mission is loading.
$lightingMission = false;
$sceneLighting::terminateLighting = true;
// Back to the launch screen
if (isObject( MainMenuGui ))
Canvas.setContent( MainMenuGui );
// Before we destroy the client physics world
// make sure all ServerConnection objects are deleted.
if(isObject(ServerConnection))
{
ServerConnection.deleteAllObjects();
}
// We can now delete the client physics simulation.
physicsDestroyWorld( "client" );
}

View file

@ -0,0 +1,185 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Mission Loading
// The client portion of the client/server mission loading process
//-----------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Loading Phases:
// Phase 1: Transmit Datablocks
// Transmit targets
// Phase 2: Transmit Ghost Objects
// Phase 3: Start Game
//
// The server invokes the client MissionStartPhase[1-3] function to request
// permission to start each phase. When a client is ready for a phase,
// it responds with MissionStartPhase[1-3]Ack.
//----------------------------------------------------------------------------
// Phase 1
//----------------------------------------------------------------------------
function clientCmdMissionStartPhase1(%seq, %missionName)
{
// These need to come after the cls.
echo ("*** New Mission: " @ %missionName);
echo ("*** Phase 1: Download Datablocks & Targets");
//Prep the postFX stuff
// Load the post effect presets for this mission.
%path = filePath( %missionName ) @ "/" @ fileBase( %missionName ) @ $PostFXManager::fileExtension;
if ( isScriptFile( %path ) )
{
postFXManager::loadPresetHandler( %path );
}
else
{
PostFXManager::settingsApplyDefaultPreset();
}
onMissionDownloadPhase("LOADING DATABLOCKS");
commandToServer('MissionStartPhase1Ack', %seq);
}
function onDataBlockObjectReceived(%index, %total)
{
onMissionDownloadProgress(%index / %total);
}
//----------------------------------------------------------------------------
// Phase 2
//----------------------------------------------------------------------------
function clientCmdMissionStartPhase2(%seq,%missionName)
{
onPhaseComplete();
echo ("*** Phase 2: Download Ghost Objects");
onMissionDownloadPhase("LOADING OBJECTS");
commandToServer('MissionStartPhase2Ack', %seq);
}
function onGhostAlwaysStarted(%ghostCount)
{
$ghostCount = %ghostCount;
$ghostsRecvd = 0;
}
function onGhostAlwaysObjectReceived()
{
$ghostsRecvd++;
onMissionDownloadProgress($ghostsRecvd / $ghostCount);
}
//----------------------------------------------------------------------------
// Phase 3
//----------------------------------------------------------------------------
function clientCmdMissionStartPhase3(%seq,%missionName)
{
onPhaseComplete();
StartClientReplication();
StartFoliageReplication();
// Load the static mission decals.
if(isFile(%missionName @ ".decals"))
decalManagerLoad( %missionName @ ".decals" );
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", ""))
{
echo("Lighting mission....");
schedule(1, 0, "updateLightingProgress");
onMissionDownloadPhase("LIGHTING MISSION");
$lightingMission = true;
}
}
function updateLightingProgress()
{
onMissionDownloadProgress($SceneLighting::lightingProgress);
if ($lightingMission)
$lightingProgressThread = schedule(1, 0, "updateLightingProgress");
}
function sceneLightingComplete()
{
echo("Mission lighting done");
$lightingMission = false;
onPhaseComplete("STARTING MISSION");
// The is also the end of the mission load cycle.
commandToServer('MissionStartPhase3Ack', $MSeq);
}
//----------------------------------------------------------------------------
// Helper functions
//----------------------------------------------------------------------------
function connect(%server)
{
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connect(%server);
}
function onMissionDownloadPhase(%phase)
{
if ( !isObject( LoadingProgress ) )
return;
LoadingProgress.setValue(0);
LoadingProgressTxt.setValue(%phase);
Canvas.repaint();
}
function onMissionDownloadProgress(%progress)
{
if ( !isObject( LoadingProgress ) )
return;
LoadingProgress.setValue(%progress);
Canvas.repaint(33);
}
function onPhaseComplete(%text)
{
if ( !isObject( LoadingProgress ) )
return;
if(%text !$= "")
LoadingProgressTxt.setValue(%text);
LoadingProgress.setValue( 1 );
Canvas.repaint();
}

View file

@ -0,0 +1,92 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Whether the local client is currently running a mission.
$Client::missionRunning = false;
// Sequence number for currently running mission.
$Client::missionSeq = -1;
// Called when mission is started.
function clientStartMission()
{
// The client recieves a mission start right before
// being dropped into the game.
physicsStartSimulation( "client" );
// Start game audio effects channels.
AudioChannelEffects.play();
// Create client mission cleanup group.
new SimGroup( ClientMissionCleanup );
// Done.
$Client::missionRunning = true;
}
// Called when mission is ended (either through disconnect or
// mission end client command).
function clientEndMission()
{
// Stop physics simulation on client.
physicsStopSimulation( "client" );
// Stop game audio effects channels.
AudioChannelEffects.stop();
// Delete all the decals.
decalManagerClear();
// Delete client mission cleanup group.
if( isObject( ClientMissionCleanup ) )
ClientMissionCleanup.delete();
clearClientPaths();
// Done.
$Client::missionRunning = false;
}
//----------------------------------------------------------------------------
// Mission start / end events sent from the server
//----------------------------------------------------------------------------
function clientCmdMissionStart(%seq)
{
clientStartMission();
$Client::missionSeq = %seq;
}
function clientCmdMissionEnd( %seq )
{
if( $Client::missionRunning && $Client::missionSeq == %seq )
{
clientEndMission();
$Client::missionSeq = -1;
}
}

View file

@ -0,0 +1,94 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Functions that process commands sent from the server.
// Game event descriptions, which may or may not include text messages, can be
// sent using the message* functions in core/scripts/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 can be overridden by the game
function onServerMessage(%a, %b, %c, %d, %e, %f, %g, %h, %i)
{
echo("onServerMessage: ");
if(%a !$= "") echo(" +- a: " @ %a);
if(%b !$= "") echo(" +- b: " @ %b);
if(%c !$= "") echo(" +- c: " @ %c);
if(%d !$= "") echo(" +- d: " @ %d);
if(%e !$= "") echo(" +- e: " @ %e);
if(%f !$= "") echo(" +- f: " @ %f);
if(%g !$= "") echo(" +- g: " @ %g);
if(%h !$= "") echo(" +- h: " @ %h);
if(%i !$= "") echo(" +- i: " @ %i);
}
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);

View file

@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ServerPlay2D(%profile)
{
// Play the given sound profile on every client.
// The sounds will be transmitted as an event, not attached to any object.
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
ClientGroup.getObject(%idx).play2D(%profile);
}
function ServerPlay3D(%profile,%transform)
{
// Play the given sound profile at the given position on every client
// The sound will be transmitted as an event, not attached to any object.
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
ClientGroup.getObject(%idx).play3D(%profile,%transform);
}

View file

@ -0,0 +1,35 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Misc. server commands avialable to clients
//-----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Debug commands
//----------------------------------------------------------------------------
function serverCmdNetSimulateLag( %client, %msDelay, %packetLossPercent )
{
if ( %client.isAdmin )
%client.setSimulatedNetParams( %packetLossPercent / 100.0, %msDelay );
}

View file

@ -0,0 +1,178 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// This script function is called before a client connection
// is accepted. Returning "" will accept the connection,
// anything else will be sent back as an error to the client.
// All the connect args are passed also to onConnectRequest
//
function GameConnection::onConnectRequest( %client, %netAddress, %name )
{
echo("Connect request from: " @ %netAddress);
if($Server::PlayerCount >= $pref::Server::MaxPlayers)
return "CR_SERVERFULL";
return "";
}
//-----------------------------------------------------------------------------
// This script function is the first called on a client accept
function GameConnection::onConnect( %this, %clientData )
{
// Send down the connection error info, the client is responsible for
// displaying this message if a connection error occurs.
messageClient(%this, 'MsgConnectionError', "", $Pref::Server::ConnectionError);
// Send mission information to the client
sendLoadInfoToClient(%this);
// Simulated client lag for testing...
// %client.setSimulatedNetParams(0.1, 30);
// Get the client's unique id:
// %authInfo = %client.getAuthInfo();
// %client.guid = getField(%authInfo, 3);
%this.guid = 0;
addToServerGuidList(%this.guid);
// Set admin status
if (%this.getAddress() $= "local")
{
%this.isAdmin = true;
%this.isSuperAdmin = true;
}
else
{
%this.isAdmin = false;
%this.isSuperAdmin = false;
}
echo("CADD: "@ %this @" "@ %this.getAddress());
// If the mission is running, go ahead download it to the client
if ($missionRunning)
{
%this.loadMission();
}
else if ($Server::LoadFailMsg !$= "")
{
messageClient(%this, 'MsgLoadFailed', $Server::LoadFailMsg);
}
%this.connectData = %clientData;
$Server::PlayerCount++;
}
//-----------------------------------------------------------------------------
// A player's name could be obtained from the auth server, but for
// now we use the one passed from the client.
// %realName = getField( %authInfo, 0 );
//
function GameConnection::setPlayerName(%client,%name)
{
%client.sendGuid = 0;
// Minimum length requirements
%name = trim( strToPlayerName( %name ) );
if ( strlen( %name ) < 3 )
%name = "Poser";
// Make sure the alias is unique, we'll hit something eventually
if (!isNameUnique(%name))
{
%isUnique = false;
for (%suffix = 1; !%isUnique; %suffix++) {
%nameTry = %name @ "." @ %suffix;
%isUnique = isNameUnique(%nameTry);
}
%name = %nameTry;
}
// Tag the name with the "smurf" color:
%client.nameBase = %name;
%client.playerName = addTaggedString("\cp\c8" @ %name @ "\co");
}
function isNameUnique(%name)
{
%count = ClientGroup.getCount();
for ( %i = 0; %i < %count; %i++ )
{
%test = ClientGroup.getObject( %i );
%rawName = stripChars( detag( getTaggedString( %test.playerName ) ), "\cp\co\c6\c7\c8\c9" );
if ( strcmp( %name, %rawName ) == 0 )
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// This function is called when a client drops for any reason
//
function GameConnection::onDrop(%client, %reason)
{
%entityIds = parseMissionGroupForIds("Entity", "");
%entityCount = getWordCount(%entityIds);
for(%i=0; %i < %entityCount; %i++)
{
%entity = getWord(%entityIds, %i);
for(%e=0; %e < %entity.getCount(); %e++)
{
%child = %entity.getObject(%e);
if(%child.getClassName() $= "Entity")
%entityIds = %entityIds SPC %child.getID();
}
%entity.notify("onClientDisconnect", %client);
}
if($missionRunning)
theLevelInfo.onClientLeaveGame();
removeFromServerGuidList( %client.guid );
$Server::PlayerCount--;
}
//-----------------------------------------------------------------------------
function GameConnection::startMission(%this)
{
// Inform the client the mission starting
commandToClient(%this, 'MissionStart', $missionSequence);
}
function GameConnection::endMission(%this)
{
// Inform the client the mission is done. Note that if this is
// called as part of the server destruction routine, the client will
// actually never see this comment since the client connection will
// be destroyed before another round of command processing occurs.
// In this case, the client will only see the disconnect from the server
// and should manually trigger a mission cleanup.
commandToClient(%this, 'MissionEnd', $missionSequence);
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//Firstly, set up our standard server prefs
// List of master servers to query, each one is tried in order
// until one responds
$Pref::Server::RegionMask = 2;
$pref::Master[0] = "2:master.garagegames.com:28002";
// Information about the server
$Pref::Server::Name = "Torque 3D Server";
$Pref::Server::Info = "This is a Torque 3D server.";
// The connection error message is transmitted to the client immediatly
// on connection, if any further error occures during the connection
// process, such as network traffic mismatch, or missing files, this error
// message is display. This message should be replaced with information
// usefull to the client, such as the url or ftp address of where the
// latest version of the game can be obtained.
$Pref::Server::ConnectionError =
"You do not have the correct version of "@$appName@" or "@
"the related art needed to play on this server, please contact "@
"the server administrator.";
// The network port is also defined by the client, this value
// overrides pref::net::port for dedicated servers
$Pref::Server::Port = 28000;
// If the password is set, clients must provide it in order
// to connect to the server
$Pref::Server::Password = "";
// Password for admin clients
$Pref::Server::AdminPassword = "";
// Misc server settings.
$Pref::Server::MaxPlayers = 64;
$Pref::Server::TimeLimit = 20; // In minutes
$Pref::Server::KickBanTime = 300; // specified in seconds
$Pref::Server::BanTime = 1800; // specified in seconds
$Pref::Server::FloodProtectionEnabled = 1;
$Pref::Server::MaxChatLen = 120;

View file

@ -0,0 +1,41 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function kick(%client)
{
messageAll( 'MsgAdminForce', '\c2The Admin has kicked %1.', %client.playerName);
if (!%client.isAIControlled())
BanList::add(%client.guid, %client.getAddress(), $Pref::Server::KickBanTime);
%client.delete("You have been kicked from this server");
}
function ban(%client)
{
messageAll('MsgAdminForce', '\c2The Admin has banned %1.', %client.playerName);
if (!%client.isAIControlled())
BanList::add(%client.guid, %client.getAddress(), $Pref::Server::BanTime);
%client.delete("You have been banned from this server");
}

View file

@ -0,0 +1,187 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Mission Loading
// The server portion of the client/server mission loading process
//-----------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Loading Phases:
// Phase 1: Transmit Datablocks
// Transmit targets
// Phase 2: Transmit Ghost Objects
// Phase 3: Start Game
//
// The server invokes the client MissionStartPhase[1-3] function to request
// permission to start each phase. When a client is ready for a phase,
// it responds with MissionStartPhase[1-3]Ack.
//----------------------------------------------------------------------------
// Phase 1
//----------------------------------------------------------------------------
function GameConnection::loadMission(%this)
{
// Send over the information that will display the server info
// when we learn it got there, we'll send the data blocks
%this.currentPhase = 0;
if (%this.isAIControlled())
{
// Cut to the chase...
theLevelInfo.onEnterGame(%this);
}
else
{
commandToClient(%this, 'MissionStartPhase1', $missionSequence, $Server::MissionFile);
echo("*** Sending mission load to client: " @ $Server::MissionFile);
}
}
function serverCmdMissionStartPhase1Ack(%client, %seq)
{
// Make sure to ignore calls from a previous mission load
if (%seq != $missionSequence || !$MissionRunning || %client.currentPhase != 0)
return;
%client.currentPhase = 1;
// Start with the CRC
%client.setMissionCRC( $missionCRC );
// Send over the datablocks...
// OnDataBlocksDone will get called when have confirmation
// that they've all been received.
%client.transmitDataBlocks($missionSequence);
}
function GameConnection::onDataBlocksDone( %this, %missionSequence )
{
// Make sure to ignore calls from a previous mission load
if (%missionSequence != $missionSequence || %this.currentPhase != 1)
return;
%this.currentPhase = 1.5;
// On to the next phase
commandToClient(%this, 'MissionStartPhase2', $missionSequence, $Server::MissionFile);
}
//----------------------------------------------------------------------------
// Phase 2
//----------------------------------------------------------------------------
function serverCmdMissionStartPhase2Ack(%client, %seq)
{
// Make sure to ignore calls from a previous mission load
if (%seq != $missionSequence || !$MissionRunning || %client.currentPhase != 1.5)
return;
%client.currentPhase = 2;
// Update mod paths, this needs to get there before the objects.
%client.transmitPaths();
// Start ghosting objects to the client
%client.activateGhosting();
}
function GameConnection::clientWantsGhostAlwaysRetry(%client)
{
if($MissionRunning)
%client.activateGhosting();
}
function GameConnection::onGhostAlwaysFailed(%client)
{
}
function GameConnection::onGhostAlwaysObjectsReceived(%client)
{
// Ready for next phase.
commandToClient(%client, 'MissionStartPhase3', $missionSequence, $Server::MissionFile);
}
//----------------------------------------------------------------------------
// Phase 3
//----------------------------------------------------------------------------
function serverCmdMissionStartPhase3Ack(%client, %seq)
{
// Make sure to ignore calls from a previous mission load
if(%seq != $missionSequence || !$MissionRunning || %client.currentPhase != 2)
return;
%client.currentPhase = 3;
// Server is ready to drop into the game
%entityIds = parseMissionGroupForIds("Entity", "");
%entityCount = getWordCount(%entityIds);
for(%i=0; %i < %entityCount; %i++)
{
%entity = getWord(%entityIds, %i);
for(%e=0; %e < %entity.getCount(); %e++)
{
%child = %entity.getObject(%e);
if(%child.getCLassName() $= "Entity")
%entityIds = %entityIds SPC %child.getID();
}
%entity.notify("onClientConnect", %client);
}
//Have any special game-play handling here
if(theLevelInfo.isMethod("onClientEnterGame"))
{
theLevelInfo.onClientEnterGame(%client);
}
else
{
//No Game mode class for the level info, so just spawn a default camera
// Set the control object to the default camera
if (!isObject(%client.camera))
{
if(!isObject(Observer))
{
datablock CameraData(Observer)
{
mode = "Observer";
};
}
//if (isDefined("$Game::DefaultCameraClass"))
%client.camera = spawnObject("Camera", Observer);
}
// If we have a camera then set up some properties
if (isObject(%client.camera))
{
MissionCleanup.add( %this.camera );
%client.camera.scopeToClient(%client);
%client.setControlObject(%client.camera);
%client.camera.setTransform("0 0 1 0 0 0 0");
}
}
%client.startMission();
}

View file

@ -0,0 +1,197 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Loading info is text displayed on the client side while the mission
// is being loaded. This information is extracted from the mission file
// and sent to each the client as it joins.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// clearLoadInfo
//
// Clears the mission info stored
//------------------------------------------------------------------------------
function clearLoadInfo()
{
if (isObject(theLevelInfo))
theLevelInfo.delete();
}
//------------------------------------------------------------------------------
// buildLoadInfo
//
// Extract the map description from the .mis file
//------------------------------------------------------------------------------
function buildLoadInfo( %mission )
{
clearLoadInfo();
%infoObject = "";
%file = new FileObject();
if ( %file.openForRead( %mission ) ) {
%inInfoBlock = false;
while ( !%file.isEOF() ) {
%line = %file.readLine();
%line = trim( %line );
if( %line $= "new ScriptObject(MissionInfo) {" )
%inInfoBlock = true;
else if( %line $= "new LevelInfo(theLevelInfo) {" )
%inInfoBlock = true;
else if( %inInfoBlock && %line $= "};" ) {
%inInfoBlock = false;
%infoObject = %infoObject @ %line;
break;
}
if( %inInfoBlock )
%infoObject = %infoObject @ %line @ " ";
}
%file.close();
}
else
error("Level file " @ %mission @ " not found.");
// Will create the object "MissionInfo"
eval( %infoObject );
%file.delete();
}
//------------------------------------------------------------------------------
// dumpLoadInfo
//
// Echo the mission information to the console
//------------------------------------------------------------------------------
function dumpLoadInfo()
{
echo( "Level Name: " @ theLevelInfo.name );
echo( "Level Description:" );
for( %i = 0; theLevelInfo.desc[%i] !$= ""; %i++ )
echo (" " @ theLevelInfo.desc[%i]);
}
//------------------------------------------------------------------------------
// sendLoadInfoToClient
//
// Sends mission description to the client
//------------------------------------------------------------------------------
function sendLoadInfoToClient( %client )
{
messageClient( %client, 'MsgLoadInfo', "", theLevelInfo.levelName );
// Send Mission Description a line at a time
for( %i = 0; theLevelInfo.desc[%i] !$= ""; %i++ )
messageClient( %client, 'MsgLoadDescripition', "", theLevelInfo.desc[%i] );
messageClient( %client, 'MsgLoadInfoDone' );
}
// A function used in order to easily parse the MissionGroup for classes . I'm pretty
// sure at this point the function can be easily modified to search the any group as well.
function parseMissionGroup( %className, %childGroup )
{
if( getWordCount( %childGroup ) == 0)
%currentGroup = "MissionGroup";
else
%currentGroup = %childGroup;
for(%i = 0; %i < (%currentGroup).getCount(); %i++)
{
if( (%currentGroup).getObject(%i).getClassName() $= %className )
return true;
if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" )
{
if( parseMissionGroup( %className, (%currentGroup).getObject(%i).getId() ) )
return true;
}
}
}
//
function parseMissionGroupForIds( %className, %childGroup )
{
if( getWordCount( %childGroup ) == 0)
%currentGroup = $Game::MissionGroup;
else
%currentGroup = %childGroup;
for(%i = 0; %i < (%currentGroup).getCount(); %i++)
{
if( (%currentGroup).getObject(%i).getClassName() $= %className )
%classIds = %classIds @ (%currentGroup).getObject(%i).getId() @ " ";
if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" )
%classIds = %classIds @ parseMissionGroupForIds( %className, (%currentGroup).getObject(%i).getId());
}
return %classIds;
}
function getLevelInfo( %missionFile )
{
clearLoadInfo();
%file = new FileObject();
%LevelInfoObject = "";
if ( %file.openForRead( %missionFile ) ) {
%inInfoBlock = false;
while ( !%file.isEOF() ) {
%line = %file.readLine();
%line = trim( %line );
if( %line $= "new ScriptObject(LevelInfo) {" )
%inInfoBlock = true;
else if( %line $= "new LevelInfo(theLevelInfo) {" )
%inInfoBlock = true;
else if( %inInfoBlock && %line $= "};" ) {
%inInfoBlock = false;
%LevelInfoObject = %LevelInfoObject @ %line;
break;
}
if( %inInfoBlock )
%LevelInfoObject = %LevelInfoObject @ %line @ " ";
}
%file.close();
}
%file.delete();
if( %LevelInfoObject !$= "" )
{
%LevelInfoObject = "%LevelInfoObject = " @ %LevelInfoObject;
eval( %LevelInfoObject );
return %LevelInfoObject;
}
// Didn't find our LevelInfo
return 0;
}

View file

@ -0,0 +1,181 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Mission Loading
// The server portion of the client/server mission loading process
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Server mission loading
//-----------------------------------------------------------------------------
// On every mission load except the first, there is a pause after
// the initial mission info is downloaded to the client.
$MissionLoadPause = 5000;
//-----------------------------------------------------------------------------
//This is the first call made by the server to kick the loading process off
function loadMission( %missionName, %isFirstMission )
{
endMission();
echo("*** LOADING MISSION: " @ %missionName);
echo("*** Stage 1 load");
// increment the mission sequence (used for ghost sequencing)
$missionSequence++;
$missionRunning = false;
$Server::MissionFile = %missionName;
$Server::LoadFailMsg = "";
// Extract mission info from the mission file,
// including the display name and stuff to send
// to the client.
buildLoadInfo( %missionName );
// Download mission info to the clients
%count = ClientGroup.getCount();
for( %cl = 0; %cl < %count; %cl++ )
{
%client = ClientGroup.getObject( %cl );
if (!%client.isAIControlled())
sendLoadInfoToClient(%client);
}
// Now that we've sent the LevelInfo to the clients
// clear it so that it won't conflict with the actual
// LevelInfo loaded in the level
clearLoadInfo();
// if this isn't the first mission, allow some time for the server
// to transmit information to the clients:
if( %isFirstMission || $Server::ServerType $= "SinglePlayer" )
loadMissionStage2();
else
schedule( $MissionLoadPause, ServerGroup, loadMissionStage2 );
}
//-----------------------------------------------------------------------------
function loadMissionStage2()
{
echo("*** Stage 2 load");
// Create the mission group off the ServerGroup
$instantGroup = ServerGroup;
// Make sure the mission exists
%file = $Server::MissionFile;
if( !isFile( %file ) )
{
$Server::LoadFailMsg = "Could not find mission \"" @ %file @ "\"";
}
else
{
// Calculate the mission CRC. The CRC is used by the clients
// to caching mission lighting.
$missionCRC = getFileCRC( %file );
// Exec the mission. The MissionGroup (loaded components) is added to the ServerGroup
exec(%file);
if( !isObject(MissionGroup) )
{
$Server::LoadFailMsg = "No 'MissionGroup' found in mission \"" @ %file @ "\".";
}
}
if( $Server::LoadFailMsg !$= "" )
{
// Inform clients that are already connected
for (%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
messageClient(ClientGroup.getObject(%clientIndex), 'MsgLoadFailed', $Server::LoadFailMsg);
return;
}
// Set mission name.
if( isObject( theLevelInfo ) )
$Server::MissionName = theLevelInfo.levelName;
// Mission cleanup group. This is where run time components will reside. The MissionCleanup
// group will be added to the ServerGroup.
new SimGroup( MissionCleanup );
// Make the MissionCleanup group the place where all new objects will automatically be added.
$instantGroup = MissionCleanup;
// Construct MOD paths
pathOnMissionLoadDone();
// Mission loading done...
echo("*** Mission loaded");
// Start all the clients in the mission
$missionRunning = true;
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ )
ClientGroup.getObject(%clientIndex).loadMission();
// Go ahead and launch the game
if(TheLevelInfo.isMethod("onMissionStart"))
TheLevelInfo.onMissionStart();
}
function endMission()
{
if (!isObject( MissionGroup ))
return;
echo("*** ENDING MISSION");
// Inform the game code we're done.
TheLevelInfo.onMissionEnded();
// Inform the clients
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
// clear ghosts and paths from all clients
%cl = ClientGroup.getObject( %clientIndex );
%cl.endMission();
%cl.resetGhosting();
%cl.clearPaths();
}
// Delete everything
MissionGroup.delete();
MissionCleanup.delete();
clearServerPaths();
}
function resetMission()
{
echo("*** MISSION RESET");
// Remove any temporary mission objects
MissionCleanup.delete();
$instantGroup = ServerGroup;
new SimGroup( MissionCleanup );
$instantGroup = MissionCleanup;
clearServerPaths();
//
TheLevelInfo.onMissionReset();
}

View file

@ -0,0 +1,50 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
commandToClient(%client, 'ServerMessage', %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}
function messageAll(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
%count = ClientGroup.getCount();
for(%cl = 0; %cl < %count; %cl++)
{
%client = ClientGroup.getObject(%cl);
messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}
}
function messageAllExcept(%client, %team, %msgtype, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
//can exclude a client, a team or both. A -1 value in either field will ignore that exclusion, so
//messageAllExcept(-1, -1, $Mesblah, 'Blah!'); will message everyone (since there shouldn't be a client -1 or client on team -1).
%count = ClientGroup.getCount();
for(%cl= 0; %cl < %count; %cl++)
{
%recipient = ClientGroup.getObject(%cl);
if((%recipient != %client) && (%recipient.team != %team))
messageClient(%recipient, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}
}

View file

@ -0,0 +1,303 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
function initServer()
{
echo("\n--------- Initializing " @ $appName @ ": Server Scripts ---------");
//load prefs
//Force-load the defaults just so we don't have any mistakes
exec( "./defaults.cs" );
//Then, if the user has saved preferences, we load those over-top the defaults
%prefPath = getPrefpath();
if ( isFile( %prefPath @ "/serverPrefs.cs" ) )
exec( %prefPath @ "/serverPrefs.cs" );
exec( "./audio.cs" );
exec( "./commands.cs" );
exec( "./kickban.cs" );
exec( "./message.cs" );
exec( "./levelDownload.cs" );
exec( "./levelLoad.cs" );
exec( "./levelInfo.cs" );
exec( "./connectionToClient.cs" );
// Server::Status is returned in the Game Info Query and represents the
// current status of the server. This string sould be very short.
$Server::Status = "Unknown";
// Turn on testing/debug script functions
$Server::TestCheats = false;
// Specify where the mission files are.
$Server::MissionFileSpec = "data/levels/*.mis";
}
//-----------------------------------------------------------------------------
function initDedicated()
{
enableWinConsole(true);
echo("\n--------- Starting Dedicated Server ---------");
// Make sure this variable reflects the correct state.
$Server::Dedicated = true;
// The server isn't started unless a mission has been specified.
if ($missionArg !$= "") {
createServer("MultiPlayer", $missionArg);
}
else
echo("No mission specified (use -mission filename)");
}
/// Attempt to find an open port to initialize the server with
function portInit(%port)
{
%failCount = 0;
while(%failCount < 10 && !setNetPort(%port))
{
echo("Port init failed on port " @ %port @ " trying next port.");
%port++; %failCount++;
}
}
/// Create a server of the given type, load the given level, and then
/// create a local client connection to the server.
//
/// @return true if successful.
function createAndConnectToLocalServer( %serverType, %level )
{
if( !createServer( %serverType, %level ) )
return false;
%conn = new GameConnection( ServerConnection );
RootGroup.add( ServerConnection );
%conn.setConnectArgs( $pref::Player::Name );
%conn.setJoinPassword( $Client::Password );
%result = %conn.connectLocal();
if( %result !$= "" )
{
%conn.delete();
destroyServer();
MessageBoxOK("Error starting local server!", "There was an error when trying to connect to the local server.");
if(isObject(MainMenuGui))
Canvas.setContent(MainMenuGui);
return false;
}
return true;
}
/// Create a server with either a "SinglePlayer" or "MultiPlayer" type
/// Specify the level to load on the server
function createServer(%serverType, %level)
{
// Increase the server session number. This is used to make sure we're
// working with the server session we think we are.
$Server::Session++;
if (%level $= "")
{
error("createServer(): level name unspecified");
return false;
}
// Make sure our level name is relative so that it can send
// across the network correctly
%level = makeRelativePath(%level, getWorkingDirectory());
destroyServer();
$missionSequence = 0;
$Server::PlayerCount = 0;
$Server::ServerType = %serverType;
$Server::LoadFailMsg = "";
$Physics::isSinglePlayer = true;
// Setup for multi-player, the network must have been
// initialized before now.
if (%serverType $= "MultiPlayer")
{
$Physics::isSinglePlayer = false;
echo("Starting multiplayer mode");
// Make sure the network port is set to the correct pref.
portInit($Pref::Server::Port);
allowConnections(true);
if ($pref::Net::DisplayOnMaster !$= "Never" )
schedule(0,0,startHeartbeat);
}
// Let the game initialize some things now that the
// the server has been created
onServerCreated();
loadMission(%level, true);
$Game::running = true;
return true;
}
function onServerCreated()
{
// Server::GameType is sent to the master server.
// This variable should uniquely identify your game and/or mod.
$Server::GameType = $appName;
// Server::MissionType sent to the master server. Clients can
// filter servers based on mission type.
// $Server::MissionType = "Deathmatch";
// GameStartTime is the sim time the game started. Used to calculated
// game elapsed time.
$Game::StartTime = 0;
// Create the server physics world.
physicsInitWorld( "server" );
physicsStartSimulation("server");
%cnt = DatablockFilesList.count();
loadDatablockFiles( DatablockFilesList, true );
%cnt = DatablockFilesList.count();
// Keep track of when the game started
$Game::StartTime = $Sim::Time;
}
/// Shut down the server
function destroyServer()
{
$Server::ServerType = "";
$Server::Running = false;
allowConnections(false);
stopHeartbeat();
$missionRunning = false;
// End any running levels and shut down the physics sim
onServerDestroyed();
//physicsDestroy();
// Delete all the server objects
if (isObject(ServerGroup))
ServerGroup.delete();
// Delete all the connections:
while (ClientGroup.getCount())
{
%client = ClientGroup.getObject(0);
%client.delete();
}
$Server::GuidList = "";
// Delete all the data blocks...
deleteDataBlocks();
// Save any server settings
%prefPath = getPrefpath();
echo( "Exporting server prefs..." );
export( "$Pref::Server::*", %prefPath@"/serverPrefs.cs", false );
BanList::Export(%prefPath@"/banlist.cs");
// Increase the server session number. This is used to make sure we're
// working with the server session we think we are.
$Server::Session++;
}
function onServerDestroyed()
{
physicsStopSimulation("server");
if (!isObject( MissionGroup ))
return;
echo("*** ENDING MISSION");
// Inform the game code we're done.
if(TheLevelInfo.isMethod("onMissionEnded"))
TheLevelInfo.onMissionEnded();
// Inform the clients
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
// clear ghosts and paths from all clients
%cl = ClientGroup.getObject( %clientIndex );
%cl.endMission();
%cl.resetGhosting();
%cl.clearPaths();
}
// Delete everything
MissionGroup.delete();
MissionCleanup.delete();
clearServerPaths();
}
/// Guid list maintenance functions
function addToServerGuidList( %guid )
{
%count = getFieldCount( $Server::GuidList );
for ( %i = 0; %i < %count; %i++ )
{
if ( getField( $Server::GuidList, %i ) == %guid )
return;
}
$Server::GuidList = $Server::GuidList $= "" ? %guid : $Server::GuidList TAB %guid;
}
function removeFromServerGuidList( %guid )
{
%count = getFieldCount( $Server::GuidList );
for ( %i = 0; %i < %count; %i++ )
{
if ( getField( $Server::GuidList, %i ) == %guid )
{
$Server::GuidList = removeField( $Server::GuidList, %i );
return;
}
}
}
/// When the server is queried for information, the value of this function is
/// returned as the status field of the query packet. This information is
/// accessible as the ServerInfo::State variable.
function onServerInfoQuery()
{
return "Doing Ok";
}

View file

@ -0,0 +1,8 @@
function Core_Components::onCreate(%this)
{
}
function Core_Components::onDestroy(%this)
{
}

View file

@ -0,0 +1,14 @@
<ModuleDefinition
ModuleId="Core_Components"
VersionId="1"
Description="Module that implements the core engine-level setup for the game."
ScriptFile="Core_Components.cs"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core">
<DeclaredAssets
canSave="true"
canSaveDynamicFields="true"
Extension="asset.taml"
Recurse="true" />
</ModuleDefinition>

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="RigidBodyComponentAsset"
componentClass="RigidBodyComponent"
friendlyName="Rigid Body"
componentType="Physics"
description="Allows an entity to have rigid body physics." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="AnimationComponentAsset"
componentClass="AnimationComponent"
friendlyName="animation"
componentType="animation"
description="Allows a mesh component to be animated." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="CameraOrbiterComponentAsset"
componentClass="CameraOrbiterComponent"
friendlyName="Camera Orbiter"
componentType="Game"
description="Acts as a boon arm for a camera component." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="ShapeCollisionComponentAsset"
componentClass="ShapeCollisionComponent"
friendlyName="Shape Collision"
componentType="Collision"
description="Enables an entity to collide with things with bounds, collision or visible meshes" />

View file

@ -0,0 +1,9 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="CameraComponentAsset"
componentClass="CameraComponent"
friendlyName="Camera"
componentType="Game"
description="Allows the component owner to operate as a camera."
scriptFile="core/components/components/game/camera.cs" />

View file

@ -0,0 +1,185 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
function CameraComponent::onAdd(%this)
{
%this.addComponentField(clientOwner, "The client that views this camera", "int", "1", "");
%test = %this.clientOwner;
%barf = ClientGroup.getCount();
%clientID = %this.getClientID();
if(%clientID && !isObject(%clientID.camera))
{
%this.scopeToClient(%clientID);
%this.setDirty();
%clientID.setCameraObject(%this.owner);
%clientID.setControlCameraFov(%this.FOV);
%clientID.camera = %this.owner;
}
%res = $pref::Video::mode;
%derp = 0;
}
function CameraComponent::onRemove(%this)
{
%clientID = %this.getClientID();
if(%clientID)
%clientID.clearCameraObject();
}
function CameraComponent::onInspectorUpdate(%this)
{
//if(%this.clientOwner)
//%this.clientOwner.setCameraObject(%this.owner);
}
function CameraComponent::getClientID(%this)
{
return ClientGroup.getObject(%this.clientOwner-1);
}
function CameraComponent::isClientCamera(%this, %client)
{
%clientID = ClientGroup.getObject(%this.clientOwner-1);
if(%client.getID() == %clientID)
return true;
else
return false;
}
function CameraComponent::onClientConnect(%this, %client)
{
//if(%this.isClientCamera(%client) && !isObject(%client.camera))
//{
%this.scopeToClient(%client);
%this.setDirty();
%client.setCameraObject(%this.owner);
%client.setControlCameraFov(%this.FOV);
%client.camera = %this.owner;
//}
//else
//{
// echo("CONNECTED CLIENT IS NOT CAMERA OWNER!");
//}
}
function CameraComponent::onClientDisconnect(%this, %client)
{
Parent::onClientDisconnect(%this, %client);
if(isClientCamera(%client)){
%this.clearScopeToClient(%client);
%client.clearCameraObject();
}
}
///
///
///
function VRCameraComponent::onAdd(%this)
{
%this.addComponentField(clientOwner, "The client that views this camera", "int", "1", "");
%test = %this.clientOwner;
%barf = ClientGroup.getCount();
%clientID = %this.getClientID();
if(%clientID && !isObject(%clientID.camera))
{
%this.scopeToClient(%clientID);
%this.setDirty();
%clientID.setCameraObject(%this.owner);
%clientID.setControlCameraFov(%this.FOV);
%clientID.camera = %this.owner;
}
%res = $pref::Video::mode;
%derp = 0;
}
function VRCameraComponent::onRemove(%this)
{
%clientID = %this.getClientID();
if(%clientID)
%clientID.clearCameraObject();
}
function CameraComponent::onInspectorUpdate(%this)
{
//if(%this.clientOwner)
//%this.clientOwner.setCameraObject(%this.owner);
}
function VRCameraComponent::getClientID(%this)
{
return ClientGroup.getObject(%this.clientOwner-1);
}
function VRCameraComponent::isClientCamera(%this, %client)
{
%clientID = ClientGroup.getObject(%this.clientOwner-1);
if(%client.getID() == %clientID)
return true;
else
return false;
}
function VRCameraComponent::onClientConnect(%this, %client)
{
//if(%this.isClientCamera(%client) && !isObject(%client.camera))
//{
%this.scopeToClient(%client);
%this.setDirty();
%client.setCameraObject(%this.owner);
%client.setControlCameraFov(%this.FOV);
%client.camera = %this.owner;
//}
//else
//{
// echo("CONNECTED CLIENT IS NOT CAMERA OWNER!");
//}
}
function VRCameraComponent::onClientDisconnect(%this, %client)
{
Parent::onClientDisconnect(%this, %client);
if(isClientCamera(%client)){
%this.clearScopeToClient(%client);
%client.clearCameraObject();
}
}

View file

@ -0,0 +1,10 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="ControlObjectComponentAsset"
componentName="ControlObjectComponent"
componentClass="Component"
friendlyName="Control Object"
componentType="Game"
description="Allows the component owner to be controlled by a client."
scriptFile="core/components/components/game/controlObject.cs" />

View file

@ -0,0 +1,89 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//registerComponent("ControlObjectComponent", "Component", "Control Object", "Game", false, "Allows the behavior owner to operate as a camera.");
function ControlObjectComponent::onAdd(%this)
{
%this.addComponentField(clientOwner, "The shape to use for rendering", "int", "1", "");
%clientID = %this.getClientID();
if(%clientID && !isObject(%clientID.getControlObject()))
%clientID.setControlObject(%this.owner);
}
function ControlObjectComponent::onRemove(%this)
{
%clientID = %this.getClientID();
if(%clientID)
%clientID.setControlObject(0);
}
function ControlObjectComponent::onClientConnect(%this, %client)
{
if(%this.isControlClient(%client) && !isObject(%client.getControlObject()))
%client.setControlObject(%this.owner);
}
function ControlObjectComponent::onClientDisconnect(%this, %client)
{
if(%this.isControlClient(%client))
%client.setControlObject(0);
}
function ControlObjectComponent::getClientID(%this)
{
return ClientGroup.getObject(%this.clientOwner-1);
}
function ControlObjectComponent::isControlClient(%this, %client)
{
%clientID = ClientGroup.getObject(%this.clientOwner-1);
if(%client.getID() == %clientID)
return true;
else
return false;
}
function ControlObjectComponent::onInspectorUpdate(%this, %field)
{
%clientID = %this.getClientID();
if(%clientID && !isObject(%clientID.getControlObject()))
%clientID.setControlObject(%this.owner);
}
function switchControlObject(%client, %newControlEntity)
{
if(!isObject(%client) || !isObject(%newControlEntity))
return error("SwitchControlObject: No client or target controller!");
%control = %newControlEntity.getComponent(ControlObjectComponent);
if(!isObject(%control))
return error("SwitchControlObject: Target controller has no conrol object behavior!");
%client.setControlObject(%newControlEntity);
}

View file

@ -0,0 +1,10 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="ItemRotationComponentAsset"
componentName="ItemRotationComponent"
componentClass="Component"
friendlyName="Item Rotation"
componentType="Game"
description="Rotates the entity around an axis, like an item pickup."
scriptFile="core/components/components/game/itemRotate.cs" />

View file

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//registerComponent("ItemRotationComponent", "Component", "Item Rotation", "Game", false, "Rotates the entity around the z axis, like an item pickup.");
function ItemRotationComponent::onAdd(%this)
{
%this.addComponentField(rotationsPerMinute, "Number of rotations per minute", "float", "5", "");
%this.addComponentField(forward, "Rotate forward or backwards", "bool", "1", "");
%this.addComponentField(horizontal, "Rotate horizontal or verticle, true for horizontal", "bool", "1", "");
}
function ItemRotationComponent::Update(%this)
{
%tickRate = 0.032;
//Rotations per second is calculated based on a standard update tick being 32ms. So we scale by the tick speed, then add that to our rotation to
//get a nice rotation speed.
if(%this.horizontal)
{
if(%this.forward)
%this.owner.rotation.z += ( ( 360 * %this.rotationsPerMinute ) / 60 ) * %tickRate;
else
%this.owner.rotation.z -= ( ( 360 * %this.rotationsPerMinute ) / 60 ) * %tickRate;
}
else
{
%this.owner.rotation.x += ( ( 360 * %this.rotationsPerMinute ) / 60 ) * %tickRate;
}
}

View file

@ -0,0 +1,10 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="PlayerSpawnerComponentAsset"
componentName="PlayerSpawner"
componentClass="Component"
friendlyName="Player Spawner"
componentType="Game"
description="When a client connects, it spawns a player object for them and attaches them to it."
scriptFile="core/components/components/game/playerSpawner.cs" />

View file

@ -0,0 +1,78 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//registerComponent("PlayerSpawner", "Component",
// "Player Spawner", "Game", false, "When a client connects, it spawns a player object for them and attaches them to it");
function PlayerSpawner::onAdd(%this)
{
%this.clientCount = 1;
%this.friendlyName = "Player Spawner";
%this.componentType = "Spawner";
%this.addComponentField("GameObjectName", "The name of the game object we spawn for the players", "gameObject", "PlayerObject");
}
function PlayerSpawner::onClientConnect(%this, %client)
{
%playerObj = spawnGameObject(%this.GameObjectName, false);
if(!isObject(%playerObj))
return;
%playerObj.position = %this.owner.position;
%playerObj.notify("onClientConnect", %client);
switchControlObject(%client, %playerObj);
switchCamera(%client, %playerObj);
%client.player = %playerObj;
%client.camera = %playerObj;
%inventory = %playerObj.getComponent(InventoryController);
if(isObject(%inventory))
{
for(%i=0; %i<5; %i++)
{
%arrow = spawnGameObject(ArrowProjectile, false);
%inventory.addItem(%arrow);
}
}
%playerObj.position = %this.owner.position;
%playerObj.rotation = "0 0 0";
%this.clientCount++;
}
function PlayerSpawner::onClientDisConnect(%this, %client)
{
}
function PlayerSpawner::getClientID(%this)
{
return ClientGroup.getObject(%this.clientOwner-1);
}

View file

@ -0,0 +1,9 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="FPSControlsComponentAsset"
componentName="FPSControls"
componentClass="Component"
friendlyName="FPS Controls"
componentType="Input"
description="First Person Shooter-type controls." />

View file

@ -0,0 +1,247 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//registerComponent("FPSControls", "Component", "FPS Controls", "Input", false, "First Person Shooter-type controls");
function FPSControls::onAdd(%this)
{
//
%this.beginGroup("Keys");
%this.addComponentField(forwardKey, "Key to bind to vertical thrust", keybind, "keyboard w");
%this.addComponentField(backKey, "Key to bind to vertical thrust", keybind, "keyboard s");
%this.addComponentField(leftKey, "Key to bind to horizontal thrust", keybind, "keyboard a");
%this.addComponentField(rightKey, "Key to bind to horizontal thrust", keybind, "keyboard d");
%this.addComponentField(jump, "Key to bind to horizontal thrust", keybind, "keyboard space");
%this.endGroup();
%this.beginGroup("Mouse");
%this.addComponentField(pitchAxis, "Key to bind to horizontal thrust", keybind, "mouse yaxis");
%this.addComponentField(yawAxis, "Key to bind to horizontal thrust", keybind, "mouse xaxis");
%this.endGroup();
%this.addComponentField(moveSpeed, "Horizontal thrust force", float, 300.0);
%this.addComponentField(jumpStrength, "Vertical thrust force", float, 3.0);
//
%control = %this.owner.getComponent( ControlObjectComponent );
if(!%control)
return echo("SPECTATOR CONTROLS: No Control Object behavior!");
//%this.Physics = %this.owner.getComponent( PlayerPhysicsComponent );
//%this.Animation = %this.owner.getComponent( AnimationComponent );
//%this.Camera = %this.owner.getComponent( MountedCameraComponent );
//%this.Animation.playThread(0, "look");
%this.setupControls(%control.getClientID());
}
function FPSControls::onRemove(%this)
{
Parent::onBehaviorRemove(%this);
commandToClient(%control.clientOwnerID, 'removeInput', %this.forwardKey);
commandToClient(%control.clientOwnerID, 'removeInput', %this.backKey);
commandToClient(%control.clientOwnerID, 'removeInput', %this.leftKey);
commandToClient(%control.clientOwnerID, 'removeInput', %this.rightKey);
commandToClient(%control.clientOwnerID, 'removeInput', %this.pitchAxis);
commandToClient(%control.clientOwnerID, 'removeInput', %this.yawAxis);
}
function FPSControls::onBehaviorFieldUpdate(%this, %field)
{
%controller = %this.owner.getBehavior( ControlObjectBehavior );
commandToClient(%controller.clientOwnerID, 'updateInput', %this.getFieldValue(%field), %field);
}
function FPSControls::onClientConnect(%this, %client)
{
%this.setupControls(%client);
}
function FPSControls::setupControls(%this, %client)
{
%control = %this.owner.getComponent( ControlObjectComponent );
if(!%control.isControlClient(%client))
{
echo("FPS CONTROLS: Client Did Not Match");
return;
}
%inputCommand = "FPSControls";
%test = %this.forwardKey;
/*SetInput(%client, %this.forwardKey.x, %this.forwardKey.y, %inputCommand@"_forwardKey");
SetInput(%client, %this.backKey.x, %this.backKey.y, %inputCommand@"_backKey");
SetInput(%client, %this.leftKey.x, %this.leftKey.y, %inputCommand@"_leftKey");
SetInput(%client, %this.rightKey.x, %this.rightKey.y, %inputCommand@"_rightKey");
SetInput(%client, %this.jump.x, %this.jump.y, %inputCommand@"_jump");
SetInput(%client, %this.pitchAxis.x, %this.pitchAxis.y, %inputCommand@"_pitchAxis");
SetInput(%client, %this.yawAxis.x, %this.yawAxis.y, %inputCommand@"_yawAxis");*/
SetInput(%client, "keyboard", "w", %inputCommand@"_forwardKey");
SetInput(%client, "keyboard", "s", %inputCommand@"_backKey");
SetInput(%client, "keyboard", "a", %inputCommand@"_leftKey");
SetInput(%client, "keyboard", "d", %inputCommand@"_rightKey");
SetInput(%client, "keyboard", "space", %inputCommand@"_jump");
SetInput(%client, "mouse", "yaxis", %inputCommand@"_pitchAxis");
SetInput(%client, "mouse", "xaxis", %inputCommand@"_yawAxis");
SetInput(%client, "keyboard", "f", %inputCommand@"_flashlight");
}
function FPSControls::onMoveTrigger(%this, %triggerID)
{
//check if our jump trigger was pressed!
if(%triggerID == 2)
{
%this.owner.applyImpulse("0 0 0", "0 0 " @ %this.jumpStrength);
}
}
function FPSControls::Update(%this)
{
return;
%moveVector = %this.owner.getMoveVector();
%moveRotation = %this.owner.getMoveRotation();
%this.Physics.moveVector = "0 0 0";
if(%moveVector.x != 0)
{
%fv = VectorNormalize(%this.owner.getRightVector());
%forMove = VectorScale(%fv, (%moveVector.x));// * (%this.moveSpeed * 0.032)));
//%this.Physics.velocity = VectorAdd(%this.Physics.velocity, %forMove);
%this.Physics.moveVector = VectorAdd(%this.Physics.moveVector, %forMove);
//if(%forMove > 0)
// %this.Animation.playThread(1, "run");
}
/*else
{
%fv = VectorNormalize(%this.owner.getRightVector());
%forMove = VectorScale(%fv, (%moveVector.x * (%this.moveSpeed * 0.032)));
if(%forMove <= 0)
%this.Animation.stopThread(1);
}*/
if(%moveVector.y != 0)
{
%fv = VectorNormalize(%this.owner.getForwardVector());
%forMove = VectorScale(%fv, (%moveVector.y));// * (%this.moveSpeed * 0.032)));
//%this.Physics.velocity = VectorAdd(%this.Physics.velocity, %forMove);
%this.Physics.moveVector = VectorAdd(%this.Physics.moveVector, %forMove);
//if(VectorLen(%this.Physics.velocity) < 2)
// %this.Physics.velocity = VectorAdd(%this.Physics.velocity, %forMove);
}
/*if(%moveVector.z)
{
%fv = VectorNormalize(%this.owner.getUpVector());
%forMove = VectorScale(%fv, (%moveVector.z * (%this.moveSpeed * 0.032)));
%this.Physics.velocity = VectorAdd(%this.Physics.velocity, %forMove);
}*/
if(%moveRotation.x != 0)
{
%look = mRadToDeg(%moveRotation.x) / 180;
//%this.Animation.setThreadPos(0, %look);
%this.owner.getComponent( MountedCameraComponent ).rotationOffset.x += mRadToDeg(%moveRotation.x);
//%this.Camera.rotationOffset.x += mRadToDeg(%moveRotation.x);
}
// %this.owner.rotation.x += mRadToDeg(%moveRotation.x);
if(%moveRotation.z != 0)
{
%zrot = mRadToDeg(%moveRotation.z);
%this.owner.getComponent( MountedCameraComponent ).rotationOffset.z += %zrot;
//%this.owner.rotation.z += %zrot;
}
}
//
function FPSControls_forwardKey(%val)
{
$mvForwardAction = %val;
}
function FPSControls_backKey(%val)
{
$mvBackwardAction = %val;
}
function FPSControls_leftKey(%val)
{
$mvLeftAction = %val;
}
function FPSControls_rightKey(%val)
{
$mvRightAction = %val;
}
function FPSControls_yawAxis(%val)
{
$mvYaw += getMouseAdjustAmount(%val);
}
function FPSControls_pitchAxis(%val)
{
$mvPitch += getMouseAdjustAmount(%val);
}
function FPSControls_jump(%val)
{
$mvTriggerCount2++;
}
function FPSControls_flashLight(%val)
{
$mvTriggerCount3++;
}

View file

@ -0,0 +1,82 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
function SetInput(%client, %device, %key, %command, %bindMap, %behav)
{
commandToClient(%client, 'SetInput', %device, %key, %command, %bindMap, %behav);
}
function RemoveInput(%client, %device, %key, %command, %bindMap)
{
commandToClient(%client, 'removeInput', %device, %key, %command, %bindMap);
}
function clientCmdSetInput(%device, %key, %command, %bindMap, %behav)
{
//if we're requesting a custom bind map, set that up
if(%bindMap $= "")
%bindMap = moveMap;
if (!isObject(%bindMap)){
new ActionMap(moveMap);
moveMap.push();
}
//get our local
//%localID = ServerConnection.resolveGhostID(%behav);
//%tmpl = %localID.getTemplate();
//%tmpl.insantiateNamespace(%tmpl.getName());
//first, check if we have an existing command
%oldBind = %bindMap.getBinding(%command);
if(%oldBind !$= "")
%bindMap.unbind(getField(%oldBind, 0), getField(%oldBind, 1));
//now, set the requested bind
%bindMap.bind(%device, %key, %command);
}
function clientCmdRemoveSpecCtrlInput(%device, %key, %bindMap)
{
//if we're requesting a custom bind map, set that up
if(%bindMap $= "")
%bindMap = moveMap;
if (!isObject(%bindMap))
return;
%bindMap.unbind(%device, %key);
}
function clientCmdSetupClientBehavior(%bhvrGstID)
{
%localID = ServerConnection.resolveGhostID(%bhvrGstID);
%tmpl = %localID.getTemplate();
%tmpl.insantiateNamespace(%tmpl.getName());
}
function getMouseAdjustAmount(%val)
{
// based on a default camera FOV of 90'
return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
}

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="MeshComponentAsset"
componentClass="MeshComponent"
friendlyName="mesh"
componentType="Render"
description="Enables an entity to render a shape." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="PlayerControllerComponentAsset"
componentClass="PlayerControllerComponent"
friendlyName="Player Controller"
componentType="Game"
description="Enables an entity to move like a player object." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="SoundComponentAsset"
componentClass="SoundComponent"
friendlyName="Sound(Component)"
componentType="sound"
description="Stores up to 4 sounds for playback." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="StateMachineComponentAsset"
componentClass="StateMachineComponent"
friendlyName="State Machine"
componentType="Game"
description="Enables a state machine on the entity." />

View file

@ -0,0 +1,8 @@
<ComponentAsset
canSave="true"
canSaveDynamicFields="true"
AssetName="TriggerComponentAsset"
componentClass="TriggerComponent"
friendlyName="Trigger Component"
componentType="Collision"
description="Enables callback and event behaviors on collision with the entity." />

View file

@ -0,0 +1,12 @@
function Core_Console::onCreate(%this)
{
exec("./scripts/profiles.cs");
exec("./scripts/console.cs");
exec("./guis/console.gui");
}
function Core_Console::onDestroy(%this)
{
}

View file

@ -0,0 +1,10 @@
<ModuleDefinition
ModuleId="Core_Console"
VersionId="1"
Description="Module that implements the core engine-level setup for the game."
ScriptFile="Core_Console.cs"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core"
Dependencies="Core_GUI=1">
</ModuleDefinition>

View file

@ -0,0 +1,191 @@
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(ConsoleDlg) {
position = "0 0";
extent = "1024 768";
minExtent = "8 8";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
helpTag = "0";
new GuiConsoleEditCtrl(ConsoleEntry) {
useSiblingScroller = "1";
historySize = "40";
tabComplete = "0";
sinkAllKeyEvents = "1";
password = "0";
passwordMask = "*";
maxLength = "255";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "0 750";
extent = "1024 18";
minExtent = "8 8";
horizSizing = "width";
vertSizing = "top";
profile = "ConsoleTextEditProfile";
visible = "1";
active = "1";
altCommand = "ConsoleEntry::eval();";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiContainer() {
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "1 728";
extent = "1024 22";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "top";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiBitmapCtrl() {
bitmap = "data/ui/art/hudfill.png";
color = "255 255 255 255";
wrap = "0";
position = "0 0";
extent = "1024 22";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiCheckBoxCtrl(ConsoleDlgErrorFilterBtn) {
text = "Errors";
groupNum = "-1";
buttonType = "ToggleButton";
useMouseEvents = "0";
position = "2 2";
extent = "113 20";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiCheckBoxProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiCheckBoxCtrl(ConsoleDlgWarnFilterBtn) {
text = "Warnings";
groupNum = "-1";
buttonType = "ToggleButton";
useMouseEvents = "0";
position = "119 2";
extent = "113 20";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiCheckBoxProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiCheckBoxCtrl(ConsoleDlgNormalFilterBtn) {
text = "Normal Messages";
groupNum = "-1";
buttonType = "ToggleButton";
useMouseEvents = "0";
position = "236 2";
extent = "113 20";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiCheckBoxProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
};
new GuiScrollCtrl() {
willFirstRespond = "1";
hScrollBar = "alwaysOn";
vScrollBar = "alwaysOn";
lockHorizScroll = "0";
lockVertScroll = "0";
constantThumbHeight = "0";
childMargin = "0 0";
mouseWheelScrollSpeed = "-1";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "0 0";
extent = "1024 730";
minExtent = "8 8";
horizSizing = "width";
vertSizing = "height";
profile = "ConsoleScrollProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
internalName = "Scroll";
canSave = "1";
canSaveDynamicFields = "0";
new GuiConsole(ConsoleMessageLogView) {
position = "1 1";
extent = "622 324";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiConsoleProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
};
};
//--- OBJECT WRITE END ---

View file

@ -0,0 +1,137 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
GlobalActionMap.bind("keyboard", "tilde", "toggleConsole");
function ConsoleEntry::eval()
{
%text = trim(ConsoleEntry.getValue());
if(%text $= "")
return;
// If it's missing a trailing () and it's not a variable,
// append the parentheses.
if(strpos(%text, "(") == -1 && !isDefined(%text)) {
if(strpos(%text, "=") == -1 && strpos(%text, " ") == -1) {
if(strpos(%text, "{") == -1 && strpos(%text, "}") == -1) {
%text = %text @ "()";
}
}
}
// Append a semicolon if need be.
%pos = strlen(%text) - 1;
if(strpos(%text, ";", %pos) == -1 && strpos(%text, "}") == -1) {
%text = %text @ ";";
}
// Turn off warnings for assigning from void
// and evaluate the snippet.
if(!isDefined("$Con::warnVoidAssignment"))
%oldWarnVoidAssignment = true;
else
%oldWarnVoidAssignment = $Con::warnVoidAssignment;
$Con::warnVoidAssignment = false;
echo("==>" @ %text);
if( !startsWith(%text, "function ")
&& !startsWith(%text, "datablock ")
&& !startsWith(%text, "foreach(")
&& !startsWith(%text, "foreach$(")
&& !startsWith(%text, "if(")
&& !startsWith(%text, "while(")
&& !startsWith(%text, "for(")
&& !startsWith(%text, "switch(")
&& !startsWith(%text, "switch$("))
eval("%result = " @ %text);
else
eval(%text);
$Con::warnVoidAssignment = %oldWarnVoidAssignment;
ConsoleEntry.setValue("");
// Echo result.
if(%result !$= "")
echo(%result);
}
function ToggleConsole(%make)
{
if (%make) {
if (ConsoleDlg.isAwake()) {
// Deactivate the console.
Canvas.popDialog(ConsoleDlg);
} else {
Canvas.pushDialog(ConsoleDlg, 99);
}
}
}
function ConsoleDlg::hideWindow(%this)
{
%this-->Scroll.setVisible(false);
}
function ConsoleDlg::showWindow(%this)
{
%this-->Scroll.setVisible(true);
}
function ConsoleDlg::onWake(%this)
{
ConsoleDlgErrorFilterBtn.setStateOn(ConsoleMessageLogView.getErrorFilter());
ConsoleDlgWarnFilterBtn.setStateOn(ConsoleMessageLogView.getWarnFilter());
ConsoleDlgNormalFilterBtn.setStateOn(ConsoleMessageLogView.getNormalFilter());
ConsoleMessageLogView.refresh();
}
function ConsoleDlg::setAlpha( %this, %alpha)
{
if (%alpha $= "")
ConsoleScrollProfile.fillColor = $ConsoleDefaultFillColor;
else
ConsoleScrollProfile.fillColor = getWords($ConsoleDefaultFillColor, 0, 2) SPC %alpha * 255.0;
}
function ConsoleDlgErrorFilterBtn::onClick(%this)
{
ConsoleMessageLogView.toggleErrorFilter();
}
function ConsoleDlgWarnFilterBtn::onClick(%this)
{
ConsoleMessageLogView.toggleWarnFilter();
}
function ConsoleDlgNormalFilterBtn::onClick(%this)
{
ConsoleMessageLogView.toggleNormalFilter();
}
function ConsoleMessageLogView::onNewMessage(%this, %errorCount, %warnCount, %normalCount)
{
ConsoleDlgErrorFilterBtn.setText("(" @ %errorCount @ ") Errors");
ConsoleDlgWarnFilterBtn.setText("(" @ %warnCount @ ") Warnings");
ConsoleDlgNormalFilterBtn.setText("(" @ %normalCount @ ") Messages");
}

View file

@ -0,0 +1,70 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
if(!isObject(GuiConsoleProfile))
new GuiControlProfile(GuiConsoleProfile)
{
fontType = ($platform $= "macos") ? "Monaco" : "Lucida Console";
fontSize = ($platform $= "macos") ? 13 : 12;
fontColor = "255 255 255";
fontColorHL = "0 255 255";
fontColorNA = "255 0 0";
fontColors[6] = "100 100 100";
fontColors[7] = "100 100 0";
fontColors[8] = "0 0 100";
fontColors[9] = "0 100 0";
category = "Core";
};
if(!isObject(GuiConsoleTextProfile))
new GuiControlProfile(GuiConsoleTextProfile)
{
fontColor = "0 0 0";
autoSizeWidth = true;
autoSizeHeight = true;
textOffset = "2 2";
opaque = true;
fillColor = "255 255 255";
border = true;
borderThickness = 1;
borderColor = "0 0 0";
category = "Core";
};
if(!isObject(ConsoleScrollProfile))
new GuiControlProfile(ConsoleScrollProfile : GuiScrollProfile)
{
opaque = true;
fillColor = "0 0 0 175";
border = 1;
//borderThickness = 0;
borderColor = "0 0 0";
category = "Core";
};
if(!isObject(ConsoleTextEditProfile))
new GuiControlProfile(ConsoleTextEditProfile : GuiTextEditProfile)
{
fillColor = "242 241 240 255";
fillColorHL = "255 255 255";
category = "Core";
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,11 @@
function Core_GUI::onCreate(%this)
{
exec("./scripts/profiles.cs");
exec("./scripts/canvas.cs");
exec("./scripts/cursor.cs");
}
function Core_GUI::onDestroy(%this)
{
}

View file

@ -0,0 +1,10 @@
<ModuleDefinition
ModuleId="Core_GUI"
VersionId="1"
Description="Module that implements the core engine-level setup for the game."
ScriptFile="Core_GUI.cs"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core"
Dependencies="Core_Rendering=1">
</ModuleDefinition>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -0,0 +1,162 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
function createCanvas(%windowTitle)
{
if ($isDedicated)
{
GFXInit::createNullDevice();
return true;
}
// Create the Canvas
$GameCanvas = new GuiCanvas(Canvas)
{
displayWindow = $platform !$= "windows";
};
// Set the window title
if (isObject(Canvas))
{
Canvas.setWindowTitle(%windowTitle @ " - " @ $pref::Video::displayDevice);
configureCanvas();
}
else
{
error("Canvas creation failed. Shutting down.");
quit();
}
}
// Constants for referencing video resolution preferences
$WORD::RES_X = 0;
$WORD::RES_Y = 1;
$WORD::FULLSCREEN = 2;
$WORD::BITDEPTH = 3;
$WORD::REFRESH = 4;
$WORD::AA = 5;
function configureCanvas()
{
// Setup a good default if we don't have one already.
if ($pref::Video::Resolution $= "")
$pref::Video::Resolution = "800 600";
if ($pref::Video::FullScreen $= "")
$pref::Video::FullScreen = false;
if ($pref::Video::BitDepth $= "")
$pref::Video::BitDepth = "32";
if ($pref::Video::RefreshRate $= "")
$pref::Video::RefreshRate = "60";
if ($pref::Video::AA $= "")
$pref::Video::AA = "4";
%resX = $pref::Video::Resolution.x;
%resY = $pref::Video::Resolution.y;
%fs = $pref::Video::FullScreen;
%bpp = $pref::Video::BitDepth;
%rate = $pref::Video::RefreshRate;
%aa = $pref::Video::AA;
if($cliFullscreen !$= "") {
%fs = $cliFullscreen;
$cliFullscreen = "";
}
echo("--------------");
echo("Attempting to set resolution to \"" @ %resX SPC %resY SPC %fs SPC %bpp SPC %rate SPC %aa @ "\"");
%deskRes = getDesktopResolution();
%deskResX = getWord(%deskRes, $WORD::RES_X);
%deskResY = getWord(%deskRes, $WORD::RES_Y);
%deskResBPP = getWord(%deskRes, 2);
// We shouldn't be getting this any more but just in case...
if (%bpp $= "Default")
%bpp = %deskResBPP;
// Make sure we are running at a valid resolution
if (%fs $= "0" || %fs $= "false")
{
// Windowed mode has to use the same bit depth as the desktop
%bpp = %deskResBPP;
// Windowed mode also has to run at a smaller resolution than the desktop
if ((%resX >= %deskResX) || (%resY >= %deskResY))
{
warn("Warning: The requested windowed resolution is equal to or larger than the current desktop resolution. Attempting to find a better resolution");
%resCount = Canvas.getModeCount();
for (%i = (%resCount - 1); %i >= 0; %i--)
{
%testRes = Canvas.getMode(%i);
%testResX = getWord(%testRes, $WORD::RES_X);
%testResY = getWord(%testRes, $WORD::RES_Y);
%testBPP = getWord(%testRes, $WORD::BITDEPTH);
if (%testBPP != %bpp)
continue;
if ((%testResX < %deskResX) && (%testResY < %deskResY))
{
// This will work as our new resolution
%resX = %testResX;
%resY = %testResY;
warn("Warning: Switching to \"" @ %resX SPC %resY SPC %bpp @ "\"");
break;
}
}
}
}
$pref::Video::Resolution = %resX SPC %resY;
$pref::Video::FullScreen = %fs;
$pref::Video::BitDepth = %bpp;
$pref::Video::RefreshRate = %rate;
$pref::Video::AA = %aa;
if (%fs == 1 || %fs $= "true")
%fsLabel = "Yes";
else
%fsLabel = "No";
echo("Accepted Mode: " NL
"--Resolution : " @ %resX SPC %resY NL
"--Full Screen : " @ %fsLabel NL
"--Bits Per Pixel : " @ %bpp NL
"--Refresh Rate : " @ %rate NL
"--AA TypeXLevel : " @ %aa NL
"--------------");
// Actually set the new video mode
Canvas.setVideoMode(%resX, %resY, %fs, %bpp, %rate, %aa);
commandToServer('setClientAspectRatio', %resX, %resY);
// AA piggybacks on the AA setting in $pref::Video::mode.
// We need to parse the setting between AA modes, and then it's level
// It's formatted as AATypexAALevel
// So, FXAAx4 or MLAAx2
if ( isObject( FXAA_PostEffect ) )
FXAA_PostEffect.isEnabled = ( %aa > 0 ) ? true : false;
}

View file

@ -0,0 +1,102 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// Cursor toggle functions.
//---------------------------------------------------------------------------------------------
$cursorControlled = true;
function showCursor()
{
if ($cursorControlled)
lockMouse(false);
Canvas.cursorOn();
}
function hideCursor()
{
if ($cursorControlled)
lockMouse(true);
Canvas.cursorOff();
}
//---------------------------------------------------------------------------------------------
// 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 - usually the in game interface.
//---------------------------------------------------------------------------------------------
package CanvasCursorPackage
{
//---------------------------------------------------------------------------------------------
// checkCursor
// The checkCursor method iterates through all the root controls on the canvas checking each
// ones noCursor property. If the noCursor property exists as anything other than false or an
// empty string on every control, the cursor will be hidden.
//---------------------------------------------------------------------------------------------
function GuiCanvas::checkCursor(%this)
{
%count = %this.getCount();
for(%i = 0; %i < %count; %i++)
{
%control = %this.getObject(%i);
if ((%control.noCursor $= "") || !%control.noCursor)
{
showCursor();
return;
}
}
// If we get here, every control requested a hidden cursor, so we oblige.
hideCursor();
}
//---------------------------------------------------------------------------------------------
// The following functions override the GuiCanvas defaults that involve changing the content
// of the Canvas. Basically, all we are doing is adding a call to checkCursor to each one.
//---------------------------------------------------------------------------------------------
function GuiCanvas::setContent(%this, %ctrl)
{
Parent::setContent(%this, %ctrl);
%this.checkCursor();
}
function GuiCanvas::pushDialog(%this, %ctrl, %layer, %center)
{
Parent::pushDialog(%this, %ctrl, %layer, %center);
%this.checkCursor();
}
function GuiCanvas::popDialog(%this, %ctrl)
{
Parent::popDialog(%this, %ctrl);
%this.checkCursor();
}
function GuiCanvas::popLayer(%this, %layer)
{
Parent::popLayer(%this, %layer);
%this.checkCursor();
}
};
activatePackage(CanvasCursorPackage);

View file

@ -0,0 +1,226 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Set font cache path if it doesn't already exist.
if($Gui::fontCacheDirectory $= "")
{
$Gui::fontCacheDirectory = expandFilename("./fonts");
}
// ----------------------------------------------------------------------------
// GuiDefaultProfile is a special profile that all other profiles inherit
// defaults from. It must exist.
// ----------------------------------------------------------------------------
if(!isObject(GuiDefaultProfile))
new GuiControlProfile (GuiDefaultProfile)
{
tab = false;
canKeyFocus = false;
hasBitmapArray = false;
mouseOverSelected = false;
// fill color
opaque = false;
fillColor = "242 241 240";
fillColorHL ="228 228 235";
fillColorSEL = "98 100 137";
fillColorNA = "255 255 255 ";
// border color
border = 0;
borderColor = "100 100 100";
borderColorHL = "50 50 50 50";
borderColorNA = "75 75 75";
// font
fontType = "Arial";
fontSize = 14;
fontCharset = ANSI;
fontColor = "0 0 0";
fontColorHL = "0 0 0";
fontColorNA = "0 0 0";
fontColorSEL= "255 255 255";
// bitmap information
bitmap = "";
bitmapBase = "";
textOffset = "0 0";
// used by guiTextControl
modal = true;
justify = "left";
autoSizeWidth = false;
autoSizeHeight = false;
returnTab = false;
numbersOnly = false;
cursorColor = "0 0 0 255";
};
if(!isObject(GuiToolTipProfile))
new GuiControlProfile (GuiToolTipProfile)
{
// fill color
fillColor = "239 237 222";
// border color
borderColor = "138 134 122";
// font
fontType = "Arial";
fontSize = 14;
fontColor = "0 0 0";
category = "Core";
};
if(!isObject(GuiWindowProfile))
new GuiControlProfile (GuiWindowProfile)
{
opaque = false;
border = 2;
fillColor = "242 241 240";
fillColorHL = "221 221 221";
fillColorNA = "200 200 200";
fontColor = "50 50 50";
fontColorHL = "0 0 0";
bevelColorHL = "255 255 255";
bevelColorLL = "0 0 0";
text = "untitled";
bitmap = "core/gui/images/window";
textOffset = "8 4";
hasBitmapArray = true;
justify = "left";
category = "Core";
};
if(!isObject(GuiTextEditProfile))
new GuiControlProfile(GuiTextEditProfile)
{
opaque = true;
bitmap = "core/gui/images/textEdit";
hasBitmapArray = true;
border = -2;
fillColor = "242 241 240 0";
fillColorHL = "255 255 255";
fontColor = "0 0 0";
fontColorHL = "255 255 255";
fontColorSEL = "98 100 137";
fontColorNA = "200 200 200";
textOffset = "4 2";
autoSizeWidth = false;
autoSizeHeight = true;
justify = "left";
tab = true;
canKeyFocus = true;
category = "Core";
};
if(!isObject(GuiScrollProfile))
new GuiControlProfile(GuiScrollProfile)
{
opaque = true;
fillcolor = "255 255 255";
fontColor = "0 0 0";
fontColorHL = "150 150 150";
border = true;
bitmap = "core/gui/images/scrollBar";
hasBitmapArray = true;
category = "Core";
};
if(!isObject(GuiOverlayProfile))
new GuiControlProfile(GuiOverlayProfile)
{
opaque = true;
fontColor = "0 0 0";
fontColorHL = "255 255 255";
fillColor = "0 0 0 100";
category = "Core";
};
if(!isObject(GuiCheckBoxProfile))
new GuiControlProfile(GuiCheckBoxProfile)
{
opaque = false;
fillColor = "232 232 232";
border = false;
borderColor = "100 100 100";
fontSize = 14;
fontColor = "20 20 20";
fontColorHL = "80 80 80";
fontColorNA = "200 200 200";
fixedExtent = true;
justify = "left";
bitmap = "core/gui/images/checkbox";
hasBitmapArray = true;
category = "Tools";
};
if( !isObject( GuiProgressProfile ) )
new GuiControlProfile( GuiProgressProfile )
{
opaque = false;
fillColor = "0 162 255 200";
border = true;
borderColor = "50 50 50 200";
category = "Core";
};
if( !isObject( GuiProgressBitmapProfile ) )
new GuiControlProfile( GuiProgressBitmapProfile )
{
border = false;
hasBitmapArray = true;
bitmap = "core/gui/images/loadingbar";
category = "Core";
};
if( !isObject( GuiProgressTextProfile ) )
new GuiControlProfile( GuiProgressTextProfile )
{
fontSize = "14";
fontType = "Arial";
fontColor = "0 0 0";
justify = "center";
category = "Core";
};
if( !isObject( GuiButtonProfile ) )
new GuiControlProfile( GuiButtonProfile )
{
opaque = true;
border = true;
fontColor = "50 50 50";
fontColorHL = "0 0 0";
fontColorNA = "200 200 200";
//fontColorSEL ="0 0 0";
fixedExtent = false;
justify = "center";
canKeyFocus = false;
bitmap = "core/gui/images/button";
hasBitmapArray = false;
category = "Core";
};

View file

@ -0,0 +1,20 @@
function Core_Lighting::onCreate(%this)
{
exec("./scripts/lighting.cs");
//Advanced/Deferred
exec("./scripts/advancedLighting_Shaders.cs");
exec("./scripts/deferredShading.cs");
exec("./scripts/advancedLighting_Init.cs");
//Basic/Forward
exec("./scripts/basicLighting_shadowFilter.cs");
exec("./scripts/shadowMaps_Init.cs");
exec("./scripts/basicLighting_Init.cs");
}
function Core_Lighting::onDestroy(%this)
{
}

View file

@ -0,0 +1,9 @@
<ModuleDefinition
ModuleId="Core_Lighting"
VersionId="1"
Description="Module that implements the core engine-level setup for the game."
ScriptFile="Core_Lighting.cs"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core">
</ModuleDefinition>

View file

@ -0,0 +1,68 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// Default Prefs
/*
$pref::LightManager::sgAtlasMaxDynamicLights = "16";
$pref::LightManager::sgDynamicShadowDetailSize = "0";
$pref::LightManager::sgDynamicShadowQuality = "0";
$pref::LightManager::sgLightingProfileAllowShadows = "1";
$pref::LightManager::sgLightingProfileQuality = "0";
$pref::LightManager::sgMaxBestLights = "10";
$pref::LightManager::sgMultipleDynamicShadows = "1";
$pref::LightManager::sgShowCacheStats = "0";
$pref::LightManager::sgUseBloom = "";
$pref::LightManager::sgUseDRLHighDynamicRange = "0";
$pref::LightManager::sgUseDynamicRangeLighting = "0";
$pref::LightManager::sgUseDynamicShadows = "1";
$pref::LightManager::sgUseToneMapping = "";
*/
//exec( "./shaders.cs" );
//exec( "./deferredShading.cs" );
function onActivateAdvancedLM()
{
// Enable the offscreen target so that AL will work
// with MSAA back buffers and for HDR rendering.
AL_FormatToken.enable();
// Activate Deferred Shading
AL_DeferredShading.enable();
}
function onDeactivateAdvancedLM()
{
// Disable the offscreen render target.
AL_FormatToken.disable();
// Deactivate Deferred Shading
AL_DeferredShading.disable();
}
function setAdvancedLighting()
{
setLightManager( "Advanced Lighting" );
}

View file

@ -0,0 +1,276 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
// Vector Light State
new GFXStateBlockData( AL_VectorLightState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendOne;
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
zDefined = true;
zEnable = false;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
mSamplerNames[0] = "deferredBuffer";
samplerStates[1] = SamplerClampPoint; // Shadow Map (Do not change this to linear, as all cards can not filter equally.)
mSamplerNames[1] = "shadowMap";
samplerStates[2] = SamplerClampPoint; // Shadow Map (Do not change this to linear, as all cards can not filter equally.)
mSamplerNames[2] = "dynamicShadowMap";
samplerStates[3] = SamplerClampLinear; // SSAO Mask
mSamplerNames[3] = "ssaoMask";
samplerStates[4] = SamplerWrapPoint; // Random Direction Map
cullDefined = true;
cullMode = GFXCullNone;
stencilDefined = true;
stencilEnable = true;
stencilFailOp = GFXStencilOpKeep;
stencilZFailOp = GFXStencilOpKeep;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpLess;
stencilRef = 0;
};
// Vector Light Material
new ShaderData( AL_VectorLightShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/farFrustumQuadV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/vectorLightP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/farFrustumQuadV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/vectorLightP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$shadowMap";
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$ssaoMask";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
new CustomMaterial( AL_VectorLightMaterial )
{
shader = AL_VectorLightShader;
stateBlock = AL_VectorLightState;
sampler["deferredBuffer"] = "#deferred";
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["ssaoMask"] = "#ssaoMask";
sampler["lightBuffer"] = "#lightinfo";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
target = "lightinfo";
pixVersion = 3.0;
};
//------------------------------------------------------------------------------
// Convex-geometry light states
new GFXStateBlockData( AL_ConvexLightState )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendOne;
blendDest = GFXBlendOne;
blendOp = GFXBlendOpAdd;
zDefined = true;
zEnable = true;
zWriteEnable = false;
zFunc = GFXCmpGreaterEqual;
samplersDefined = true;
samplerStates[0] = SamplerClampPoint; // G-buffer
mSamplerNames[0] = "deferredBuffer";
samplerStates[1] = SamplerClampPoint; // Shadow Map (Do not use linear, these are perspective projections)
mSamplerNames[1] = "shadowMap";
samplerStates[2] = SamplerClampPoint; // Shadow Map (Do not use linear, these are perspective projections)
mSamplerNames[2] = "dynamicShadowMap";
samplerStates[3] = SamplerClampLinear; // Cookie Map
samplerStates[4] = SamplerWrapPoint; // Random Direction Map
cullDefined = true;
cullMode = GFXCullCW;
stencilDefined = true;
stencilEnable = true;
stencilFailOp = GFXStencilOpKeep;
stencilZFailOp = GFXStencilOpKeep;
stencilPassOp = GFXStencilOpKeep;
stencilFunc = GFXCmpLess;
stencilRef = 0;
};
// Point Light Material
new ShaderData( AL_PointLightShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/pointLightP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/pointLightP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$shadowMap";
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$cookieMap";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
new CustomMaterial( AL_PointLightMaterial )
{
shader = AL_PointLightShader;
stateBlock = AL_ConvexLightState;
sampler["deferredBuffer"] = "#deferred";
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["cookieMap"] = "$dynamiclightmask";
sampler["lightBuffer"] = "#lightinfo";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
target = "lightinfo";
pixVersion = 3.0;
};
// Spot Light Material
new ShaderData( AL_SpotLightShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/spotLightP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/spotLightP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$shadowMap";
samplerNames[2] = "$dynamicShadowMap";
samplerNames[3] = "$cookieMap";
samplerNames[4] = "$gTapRotationTex";
samplerNames[5] = "$lightBuffer";
samplerNames[6] = "$colorBuffer";
samplerNames[7] = "$matInfoBuffer";
pixVersion = 3.0;
};
new CustomMaterial( AL_SpotLightMaterial )
{
shader = AL_SpotLightShader;
stateBlock = AL_ConvexLightState;
sampler["deferredBuffer"] = "#deferred";
sampler["shadowMap"] = "$dynamiclight";
sampler["dynamicShadowMap"] = "$dynamicShadowMap";
sampler["cookieMap"] = "$dynamiclightmask";
sampler["lightBuffer"] = "#lightinfo";
sampler["colorBuffer"] = "#color";
sampler["matInfoBuffer"] = "#matinfo";
target = "lightinfo";
pixVersion = 3.0;
};
/// This material is used for generating deferred
/// materials for objects that do not have materials.
new Material( AL_DefaultDeferredMaterial )
{
// We need something in the first pass else it
// won't create a proper material instance.
//
// We use color here because some objects may not
// have texture coords in their vertex format...
// for example like terrain.
//
diffuseColor[0] = "1 1 1 1";
};
/// This material is used for generating shadow
/// materials for objects that do not have materials.
new Material( AL_DefaultShadowMaterial )
{
// We need something in the first pass else it
// won't create a proper material instance.
//
// We use color here because some objects may not
// have texture coords in their vertex format...
// for example like terrain.
//
diffuseColor[0] = "1 1 1 1";
// This is here mostly for terrain which uses
// this material to create its shadow material.
//
// At sunset/sunrise the sun is looking thru
// backsides of the terrain which often are not
// closed. By changing the material to be double
// sided we avoid holes in the shadowed geometry.
//
doubleSided = true;
};
// Particle System Point Light Material
new ShaderData( AL_ParticlePointLightShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/particlePointLightV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/particlePointLightP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/pointLightP.glsl";
samplerNames[0] = "$deferredBuffer";
pixVersion = 3.0;
};
new CustomMaterial( AL_ParticlePointLightMaterial )
{
shader = AL_ParticlePointLightShader;
stateBlock = AL_ConvexLightState;
sampler["deferredBuffer"] = "#deferred";
target = "lightinfo";
pixVersion = 3.0;
};

View file

@ -0,0 +1,92 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//exec( "./shadowFilter.cs" );
singleton GFXStateBlockData( BL_ProjectedShadowSBData )
{
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendDestColor;
blendDest = GFXBlendZero;
zDefined = true;
zEnable = true;
zWriteEnable = false;
samplersDefined = true;
samplerStates[0] = SamplerClampLinear;
vertexColorEnable = true;
};
singleton ShaderData( BL_ProjectedShadowShaderData )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/projectedShadowV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/projectedShadowP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/gl/projectedShadowV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/gl/projectedShadowP.glsl";
samplerNames[0] = "inputTex";
pixVersion = 2.0;
};
singleton CustomMaterial( BL_ProjectedShadowMaterial )
{
sampler["inputTex"] = "$miscbuff";
shader = BL_ProjectedShadowShaderData;
stateBlock = BL_ProjectedShadowSBData;
version = 2.0;
forwardLit = true;
};
function onActivateBasicLM()
{
// If HDR is enabled... enable the special format token.
if ( $platform !$= "macos" && HDRPostFx.isEnabled )
AL_FormatToken.enable();
// Create render pass for projected shadow.
new RenderPassManager( BL_ProjectedShadowRPM );
// Create the mesh bin and add it to the manager.
%meshBin = new RenderMeshMgr();
BL_ProjectedShadowRPM.addManager( %meshBin );
// Add both to the root group so that it doesn't
// end up in the MissionCleanup instant group.
RootGroup.add( BL_ProjectedShadowRPM );
RootGroup.add( %meshBin );
}
function onDeactivateBasicLM()
{
// Delete the pass manager which also deletes the bin.
BL_ProjectedShadowRPM.delete();
}
function setBasicLighting()
{
setLightManager( "Basic Lighting" );
}

View file

@ -0,0 +1,76 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
singleton ShaderData( BL_ShadowFilterShaderV )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/basic/shadowFilterV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/basic/shadowFilterP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/lighting/basic/gl/shadowFilterV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/basic/gl/shadowFilterP.glsl";
samplerNames[0] = "$diffuseMap";
defines = "BLUR_DIR=float2(1.0,0.0)";
pixVersion = 2.0;
};
singleton ShaderData( BL_ShadowFilterShaderH : BL_ShadowFilterShaderV )
{
defines = "BLUR_DIR=float2(0.0,1.0)";
};
singleton GFXStateBlockData( BL_ShadowFilterSB : PFX_DefaultStateBlock )
{
colorWriteDefined=true;
colorWriteRed=false;
colorWriteGreen=false;
colorWriteBlue=false;
blendDefined = true;
blendEnable = true;
};
// NOTE: This is ONLY used in Basic Lighting, and
// only directly by the ProjectedShadow. It is not
// meant to be manually enabled like other PostEffects.
singleton PostEffect( BL_ShadowFilterPostFx )
{
// Blur vertically
shader = BL_ShadowFilterShaderV;
stateBlock = PFX_DefaultStateBlock;
targetClear = "PFXTargetClear_OnDraw";
targetClearColor = "0 0 0 0";
texture[0] = "$inTex";
target = "$outTex";
// Blur horizontal
new PostEffect()
{
shader = BL_ShadowFilterShaderH;
stateBlock = PFX_DefaultStateBlock;
texture[0] = "$inTex";
target = "$outTex";
};
};

View file

@ -0,0 +1,71 @@
singleton ShaderData( ClearGBufferShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/deferredClearGBufferV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/deferredClearGBufferP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/deferredClearGBufferP.glsl";
pixVersion = 2.0;
};
singleton ShaderData( DeferredColorShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFx/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/deferredColorShaderP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/deferredColorShaderP.glsl";
pixVersion = 2.0;
};
// Primary Deferred Shader
new GFXStateBlockData( AL_DeferredShadingState : PFX_DefaultStateBlock )
{
cullMode = GFXCullNone;
blendDefined = true;
blendEnable = true;
blendSrc = GFXBlendSrcAlpha;
blendDest = GFXBlendInvSrcAlpha;
samplersDefined = true;
samplerStates[0] = SamplerWrapLinear;
samplerStates[1] = SamplerWrapLinear;
samplerStates[2] = SamplerWrapLinear;
samplerStates[3] = SamplerWrapLinear;
samplerStates[4] = SamplerWrapLinear;
};
new ShaderData( AL_DeferredShader )
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/deferredShadingP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/advanced/gl/deferredShadingP.glsl";
samplerNames[0] = "colorBufferTex";
samplerNames[1] = "lightDeferredTex";
samplerNames[2] = "matInfoTex";
samplerNames[3] = "deferredTex";
pixVersion = 2.0;
};
singleton PostEffect( AL_DeferredShading )
{
renderTime = "PFXAfterBin";
renderBin = "SkyBin";
shader = AL_DeferredShader;
stateBlock = AL_DeferredShadingState;
texture[0] = "#color";
texture[1] = "#lightinfo";
texture[2] = "#matinfo";
texture[3] = "#deferred";
target = "$backBuffer";
renderPriority = 10000;
allowReflectPass = true;
};

View file

@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
function initLightingSystems(%manager)
{
echo( "\nInitializing Lighting Systems" );
// First exec the scripts for the different light managers
// in the lighting folder.
/*%pattern = "./lighting/*//*init.cs";
%file = findFirstFile( %pattern );
if ( %file $= "" )
{
// Try for DSOs next.
%pattern = "./lighting/*//*init.cs.dso";
%file = findFirstFile( %pattern );
}
while( %file !$= "" )
{
exec( %file );
%file = findNextFile( %pattern );
}*/
// Try the perfered one first.
%success = setLightManager(%manager);
// Did we completely fail to initialize a light manager?
if (!%success)
{
// If we completely failed to initialize a light
// manager then the 3d scene cannot be rendered.
quitWithErrorMessage( "Failed to set a light manager!" );
}
}
//---------------------------------------------------------------------------------------------
function onLightManagerActivate( %lmName )
{
// Call activation callbacks.
%activateNewFn = "onActivate" @ getWord( %lmName, 0 ) @ "LM";
if( isFunction( %activateNewFn ) )
eval( %activateNewFn @ "();" );
}
//---------------------------------------------------------------------------------------------
function onLightManagerDeactivate( %lmName )
{
// Call deactivation callback.
%deactivateOldFn = "onDeactivate" @ getWord( %lmName, 0 ) @ "LM";
if( isFunction( %deactivateOldFn ) )
eval( %deactivateOldFn @ "();" );
}

View file

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
new ShaderData(BlurDepthShader)
{
DXVertexShaderFile = $Core::CommonShaderPath @ "/lighting/shadowMap/boxFilterV.hlsl";
DXPixelShaderFile = $Core::CommonShaderPath @ "/lighting/shadowMap/boxFilterP.hlsl";
OGLVertexShaderFile = $Core::CommonShaderPath @ "/lighting/shadowMap/gl/boxFilterV.glsl";
OGLPixelShaderFile = $Core::CommonShaderPath @ "/lighting/shadowMap/gl/boxFilterP.glsl";
pixVersion = 2.0;
};

View file

@ -0,0 +1,33 @@
function Core_PostFX::onCreate(%this)
{
//
exec("./scripts/postFx.cs");
/*exec("./scripts/postFxManager.gui.cs");
exec("./scripts/postFxManager.gui.settings.cs");
exec("./scripts/postFxManager.persistance.cs");
exec("./scripts/default.postfxpreset.cs");
exec("./scripts/caustics.cs");
exec("./scripts/chromaticLens.cs");
exec("./scripts/dof.cs");
exec("./scripts/edgeAA.cs");
exec("./scripts/flash.cs");
exec("./scripts/fog.cs");
exec("./scripts/fxaa.cs");
exec("./scripts/GammaPostFX.cs");
exec("./scripts/glow.cs");
exec("./scripts/hdr.cs");
exec("./scripts/lightRay.cs");
exec("./scripts/MLAA.cs");
exec("./scripts/MotionBlurFx.cs");
exec("./scripts/ovrBarrelDistortion.cs");
exec("./scripts/ssao.cs");
exec("./scripts/turbulence.cs");
exec("./scripts/vignette.cs");*/
}
function Core_PostFX::onDestroy(%this)
{
}

View file

@ -0,0 +1,10 @@
<ModuleDefinition
ModuleId="Core_PostFX"
VersionId="1"
Description="Module that implements the core engine-level setup for the game."
ScriptFile="Core_PostFX.cs"
CreateFunction="onCreate"
DestroyFunction="onDestroy"
Group="Core"
Dependencies="Core_Rendering=1,Core_Lighting=1">
</ModuleDefinition>

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

View file

@ -0,0 +1,32 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
singleton Material( Empty )
{
};
singleton Material(WarningMaterial) {
detailMap[0] = "missingTexture";
diffuseColor[0] = "25 16 0";
emissive[0] = false;
translucent = false;
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Some files were not shown because too many files have changed in this diff Show more