mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Removes Entity/Component stuff from being behind an experimental flag.
This commit is contained in:
parent
efbd5fb451
commit
df9deea1a8
38 changed files with 181 additions and 737 deletions
16
Templates/BaseGame/game/core/CoreComponents.module
Normal file
16
Templates/BaseGame/game/core/CoreComponents.module
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<ModuleDefinition
|
||||
ModuleId="CoreComponentsModule"
|
||||
VersionId="1"
|
||||
Description="Module that implements the core engine-level components for the game."
|
||||
Group="Game">
|
||||
<DeclaredAssets
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
Extension="asset.taml"
|
||||
Recurse="true" />
|
||||
<AutoloadAssets
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetType="ComponentAsset"
|
||||
Recurse="true" />
|
||||
</ModuleDefinition>
|
||||
|
|
@ -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." />
|
||||
|
|
@ -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." />
|
||||
|
|
@ -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." />
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<ComponentAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="CollisionComponentAsset"
|
||||
componentClass="CollisionComponent"
|
||||
friendlyName="Collision"
|
||||
componentType="Collision"
|
||||
description="Enables an entity to collide with things." />
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<ComponentAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="CameraComponentAsset"
|
||||
componentClass="CameraComponent"
|
||||
friendlyName="Camera"
|
||||
componentType="Game"
|
||||
scriptFile="core/components/game/camera.cs"
|
||||
description="Allows the component owner to operate as a camera." />
|
||||
185
Templates/BaseGame/game/core/components/game/camera.cs
Normal file
185
Templates/BaseGame/game/core/components/game/camera.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<ComponentAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="ControlObjectComponentAsset"
|
||||
componentName="ControlObjectComponent"
|
||||
componentClass="Component"
|
||||
friendlyName="Control Object"
|
||||
componentType="Game"
|
||||
scriptFile="core/components/game/controlObject.cs"
|
||||
description="Allows the component owner to be controlled by a client." />
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<ComponentAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="ItemRotationComponentAsset"
|
||||
componentName="ItemRotationComponent"
|
||||
componentClass="Component"
|
||||
friendlyName="Item Rotation"
|
||||
componentType="Game"
|
||||
scriptFile="core/components/game/itemRotate.cs"
|
||||
description="Rotates the entity around an axis, like an item pickup." />
|
||||
49
Templates/BaseGame/game/core/components/game/itemRotate.cs
Normal file
49
Templates/BaseGame/game/core/components/game/itemRotate.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<ComponentAsset
|
||||
canSave="true"
|
||||
canSaveDynamicFields="true"
|
||||
AssetName="PlayerSpawnerComponentAsset"
|
||||
componentName="PlayerSpawner"
|
||||
componentClass="Component"
|
||||
friendlyName="Player Spawner"
|
||||
componentType="Game"
|
||||
scriptFile="core/components/game/playerSpawner.cs"
|
||||
description="When a client connects, it spawns a player object for them and attaches them to it." />
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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." />
|
||||
247
Templates/BaseGame/game/core/components/input/fpsControls.cs
Normal file
247
Templates/BaseGame/game/core/components/input/fpsControls.cs
Normal 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++;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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." />
|
||||
|
|
@ -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." />
|
||||
|
|
@ -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." />
|
||||
|
|
@ -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." />
|
||||
Loading…
Add table
Add a link
Reference in a new issue