⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fxshapereplicator.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 3 页
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Written by Melvyn May, Started on 13th March 2002, finished 27th March 2002.
//
// "My code is written for the Torque community, so do your worst with it,
//  just don't rip-it-off and call it your own without even thanking me".
//
//  - Melv (working hard to become an associate ... hint).
//
//-----------------------------------------------------------------------------

#include "dgl/dgl.h"
#include "console/consoleTypes.h"
#include "core/bitStream.h"
#include "math/mRandom.h"
#include "math/mathIO.h"
#include "terrain/terrData.h"
#include "game/gameConnection.h"
#include "console/simBase.h"
#include "sceneGraph/sceneGraph.h"
#include "fxShapeReplicator.h"

//------------------------------------------------------------------------------
//
//  Put this in /example/common/editor/editor.cs in function [Editor::create()] (around line 66).
//
//   // Ignore Replicated fxStatic Instances.
//   EWorldEditor.ignoreObjClass("fxShapeReplicatedStatic");
//
//------------------------------------------------------------------------------
//
//  Put this in /example/common/editor/EditorGui.cs in [function Creator::init( %this )]
//
//   %Environment_Item[8] = "fxShapeReplicator";  <-- ADD THIS.
//
//------------------------------------------------------------------------------
//
//  Put the function in /example/common/editor/ObjectBuilderGui.gui [around line 458] ...
//
//  function ObjectBuilderGui::buildfxShapeReplicator(%this)
//  {
//      %this.className = "fxShapeReplicator";
//      %this.process();
//  }
//
//------------------------------------------------------------------------------
//
//  Put this in /example/common/client/missionDownload.cs in [function clientCmdMissionStartPhase3(%seq,%missionName)] (line 65)
//  after codeline 'onPhase2Complete();'.
//
//  StartClientReplication();
//
//------------------------------------------------------------------------------
//
//  Put this in /engine/console/simBase.h (around line 509) in
//
//  namespace Sim
//  {
//     DeclareNamedSet(fxReplicatorSet)  <-- ADD THIS (Note no semi-colon).
//
//------------------------------------------------------------------------------
//
//  Put this in /engine/console/simBase.cc (around line 19) in
//
//  ImplementNamedSet(fxReplicatorSet)  <-- ADD THIS
//
//------------------------------------------------------------------------------
//
//  Put this in /engine/console/simManager.cc [function void init()] (around line 269).
//
//  namespace Sim
//  {
//      InstantiateNamedSet(fxReplicatorSet);  <-- ADD THIS
//
//------------------------------------------------------------------------------

extern bool gEditingMission;

//------------------------------------------------------------------------------

IMPLEMENT_CO_NETOBJECT_V1(fxShapeReplicator);
IMPLEMENT_CO_NETOBJECT_V1(fxShapeReplicatedStatic);


//------------------------------------------------------------------------------
// Class: fxShapeReplicator
//------------------------------------------------------------------------------

fxShapeReplicator::fxShapeReplicator()
{
    // Setup NetObject.
    mTypeMask |= StaticObjectType | StaticTSObjectType | StaticRenderedObjectType;
    mAddedToScene = false;
    mNetFlags.set(Ghostable | ScopeAlways);

    // Reset Client Replication Started.
    mClientReplicationStarted = false;

    // Reset Shape Count.
    mCurrentShapeCount = 0;

    // Reset Creation Area Angle Animation.
    mCreationAreaAngle = 0;
}

//------------------------------------------------------------------------------

fxShapeReplicator::~fxShapeReplicator()
{
}

//------------------------------------------------------------------------------

void fxShapeReplicator::initPersistFields()
{
    // Initialise parents' persistent fields.
    Parent::initPersistFields();

    // Add out own persistent fields.
    addGroup( "Debugging" );
    addField( "HideReplications",   TypeBool,       Offset( mFieldData.mHideReplications,       fxShapeReplicator ) );
    addField( "ShowPlacementArea",  TypeBool,       Offset( mFieldData.mShowPlacementArea,      fxShapeReplicator ) );
    addField( "PlacementAreaHeight",TypeS32,        Offset( mFieldData.mPlacementBandHeight,    fxShapeReplicator ) );
    addField( "PlacementColour",    TypeColorF,     Offset( mFieldData.mPlaceAreaColour,        fxShapeReplicator ) );
    endGroup( "Debugging" );

    addGroup( "Media" );
    addField( "ShapeFile",          TypeFilename,   Offset( mFieldData.mShapeFile,              fxShapeReplicator ) );
    endGroup( "Media" );

    addGroup( "Replications" ); 
    addField( "Seed",               TypeS32,        Offset( mFieldData.mSeed,                   fxShapeReplicator ) );
    addField( "ShapeCount",         TypeS32,        Offset( mFieldData.mShapeCount,             fxShapeReplicator ) );
    addField( "ShapeRetries",       TypeS32,        Offset( mFieldData.mShapeRetries,           fxShapeReplicator ) );
    endGroup( "Replications" ); 

    addGroup( "Placement Radius" ); 
    addField( "InnerRadiusX",       TypeS32,        Offset( mFieldData.mInnerRadiusX,           fxShapeReplicator ) );
    addField( "InnerRadiusY",       TypeS32,        Offset( mFieldData.mInnerRadiusY,           fxShapeReplicator ) );
    addField( "OuterRadiusX",       TypeS32,        Offset( mFieldData.mOuterRadiusX,           fxShapeReplicator ) );
    addField( "OuterRadiusY",       TypeS32,        Offset( mFieldData.mOuterRadiusY,           fxShapeReplicator ) );
    endGroup( "Placement Radius" ); 

    addGroup( "Restraints" );
    addField( "AllowOnTerrain",     TypeBool,       Offset( mFieldData.mAllowOnTerrain,         fxShapeReplicator ) );
    addField( "AllowOnInteriors",   TypeBool,       Offset( mFieldData.mAllowOnInteriors,       fxShapeReplicator ) );
    addField( "AllowOnStatics",     TypeBool,       Offset( mFieldData.mAllowStatics,           fxShapeReplicator ) );
    addField( "AllowOnWater",       TypeBool,       Offset( mFieldData.mAllowOnWater,           fxShapeReplicator ) );
    addField( "AllowWaterSurface",  TypeBool,       Offset( mFieldData.mAllowWaterSurface,      fxShapeReplicator ) );
    addField( "AlignToTerrain",     TypeBool,       Offset( mFieldData.mAlignToTerrain,         fxShapeReplicator ) );
    addField( "Interactions",       TypeBool,       Offset( mFieldData.mInteractions,           fxShapeReplicator ) );
    addField( "AllowedTerrainSlope",TypeS32,        Offset( mFieldData.mAllowedTerrainSlope,    fxShapeReplicator ) );
    addField( "TerrainAlignment",   TypePoint3F,    Offset( mFieldData.mTerrainAlignment,       fxShapeReplicator ) );
    endGroup( "Restraints" );

    addGroup( "Object Transforms" );
    addField( "FixShapeAspect",     TypeBool,       Offset( mFieldData.mFixShapeAspect,         fxShapeReplicator ) );
    addField( "ShapeScaleMin",      TypePoint3F,    Offset( mFieldData.mShapeScaleMin,          fxShapeReplicator ) );
    addField( "ShapeScaleMax",      TypePoint3F,    Offset( mFieldData.mShapeScaleMax,          fxShapeReplicator ) );
    addField( "ShapeRotateMin",     TypePoint3F,    Offset( mFieldData.mShapeRotateMin,         fxShapeReplicator ) );
    addField( "ShapeRotateMax",     TypePoint3F,    Offset( mFieldData.mShapeRotateMax,         fxShapeReplicator ) );
    addField( "OffsetZ",            TypeS32,        Offset( mFieldData.mOffsetZ,                fxShapeReplicator ) );
    endGroup( "Object Transforms" );

}

//------------------------------------------------------------------------------

void fxShapeReplicator::CreateShapes(void)
{
    F32             HypX, HypY;
    F32             Angle;
    U32             RelocationRetry;
    Point3F         ShapePosition;
    Point3F         ShapeStart;
    Point3F         ShapeEnd;
    Point3F         ShapeScale;
    EulerF          ShapeRotation;
    QuatF           QRotation;
    bool            CollisionResult;
    RayInfo         RayEvent;
    TSShape*        pShape;
    Container*      pContainer;


    // Don't create shapes if we are hiding replications.
    if (mFieldData.mHideReplications) return;

    // Cannot continue without shapes!
    if (mFieldData.mShapeFile == "") return;

    // Check that we can position somewhere!
    if (!(  mFieldData.mAllowOnTerrain ||
            mFieldData.mAllowOnInteriors ||
            mFieldData.mAllowStatics ||
            mFieldData.mAllowOnWater))
    {
        // Problem ...
        Con::warnf(ConsoleLogEntry::General, "[%s] - Could not place object, All alloweds are off!", getName());

        // Return here.
        return;
    }

    // Check Shapes.
    AssertFatal(mCurrentShapeCount==0,"Shapes already present, this should not be possible!")

    // Check that we have a shape...
    if (!mFieldData.mShapeFile) return;

    // Set Seed.
    RandomGen.setSeed(mFieldData.mSeed);

    // Set shape vector.
    mReplicatedShapes.reserve(mFieldData.mShapeCount);

    // Add shapes.
    for (U32 idx = 0; idx < mFieldData.mShapeCount; idx++)
    {
        fxShapeReplicatedStatic*    fxStatic;

        // Create our static shape.
        fxStatic = new fxShapeReplicatedStatic();

        // Set the 'shapeName' field.
        fxStatic->setField("shapeName", mFieldData.mShapeFile);

        // Is this Replicator on the Server?
        if (isServerObject())
            // Yes, so stop it from Ghosting. (Hack, Hack, Hack!)
            fxStatic->touchNetFlags(Ghostable, false);
        else
            // No, so flag as ghost object. (Another damn Hack!)
            fxStatic->touchNetFlags(IsGhost, true);

        // Register the Object.
        if (!fxStatic->registerObject())
        {
            // Problem ...
            Con::warnf(ConsoleLogEntry::General, "[%s] - Could not load shape file '%s'!", getName(), mFieldData.mShapeFile);

            // Destroy Shape.
            delete fxStatic;

            // Destroy existing hapes.
            DestroyShapes();

            // Quit.
            return;
        }

        // Get Allocated Shape.
        pShape = fxStatic->getShape();

        // Reset Relocation Retry.
        RelocationRetry = mFieldData.mShapeRetries;

        // Find it a home ...
        do
        {

            // Calculate a random offset
            HypX   = RandomGen.randF(mFieldData.mInnerRadiusX, mFieldData.mOuterRadiusX);
            HypY   = RandomGen.randF(mFieldData.mInnerRadiusY, mFieldData.mOuterRadiusY);
            Angle   = RandomGen.randF(0, M_2PI);

            // Calculate the new random position (in local space).
            Point3F randomShapePosLocal;
            randomShapePosLocal.x = HypX * mCos(Angle);
            randomShapePosLocal.y = HypY * mSin(Angle);

            // Transform into world space coordinates
            Point3F shapePosWorld;
            MatrixF objToWorld = getRenderTransform();
            objToWorld.mulP(randomShapePosLocal, &shapePosWorld);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -