From f5fb2fdf763e9b109f2e4a2a8eabdd976b29a622 Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Wed, 24 Sep 2014 08:08:42 +1000 Subject: [PATCH] Improved code style in ribbon files. --- Engine/source/T3D/fx/ribbon.cpp | 44 +++++++++++-------- Engine/source/T3D/fx/ribbon.h | 67 ++++++++++++++++++----------- Engine/source/T3D/fx/ribbonNode.cpp | 2 +- Engine/source/T3D/fx/ribbonNode.h | 5 +-- 4 files changed, 68 insertions(+), 50 deletions(-) diff --git a/Engine/source/T3D/fx/ribbon.cpp b/Engine/source/T3D/fx/ribbon.cpp index d035c3491..49150711e 100644 --- a/Engine/source/T3D/fx/ribbon.cpp +++ b/Engine/source/T3D/fx/ribbon.cpp @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC +// Copyright (c) 2014 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 @@ -47,7 +47,7 @@ IMPLEMENT_CO_NETOBJECT_V1(Ribbon); // RibbonData::RibbonData() { - for (U8 i = 0; i < RIBBON_NUM_FIELDS; i++) { + for (U8 i = 0; i < NumFields; i++) { mSizes[i] = 0.0f; mColours[i].set(0.0f, 0.0f, 0.0f, 1.0f); mTimes[i] = -1.0f; @@ -70,32 +70,38 @@ void RibbonData::initPersistFields() { Parent::initPersistFields(); - addField("size", TypeF32, Offset(mSizes, RibbonData), RIBBON_NUM_FIELDS, + addGroup("Ribbon"); + + addField("size", TypeF32, Offset(mSizes, RibbonData), NumFields, "The size of the ribbon at the specified keyframe."); - addField("color", TypeColorF, Offset(mColours, RibbonData), RIBBON_NUM_FIELDS, + addField("color", TypeColorF, Offset(mColours, RibbonData), NumFields, "The colour of the ribbon at the specified keyframe."); - addField("position", TypeF32, Offset(mTimes, RibbonData), RIBBON_NUM_FIELDS, + addField("position", TypeF32, Offset(mTimes, RibbonData), NumFields, "The position of the keyframe along the lifetime of the ribbon."); - addField("RibbonLength", TypeS32, Offset(mRibbonLength, RibbonData), + + addField("ribbonLength", TypeS32, Offset(mRibbonLength, RibbonData), "The amount of segments the Ribbon can maximally have in length."); - addField("UseFadeOut", TypeBool, Offset(mUseFadeOut, RibbonData), - "If true, the ribbon will fade away after deletion."); - addField("RibbonMaterial", TypeString, Offset(mMatName, RibbonData), - "The material the ribbon uses for rendering."); - addField("fadeAwayStep", TypeF32, Offset(mFadeAwayStep, RibbonData), - "How much to fade the ribbon with each update, after deletion."); addField("segmentsPerUpdate", TypeS32, Offset(segmentsPerUpdate, RibbonData), "How many segments to add each update."); - addField("tileScale", TypeF32, Offset(mTileScale, RibbonData), + addField("skipAmount", TypeS32, Offset(mSegmentSkipAmount, RibbonData), + "The amount of segments to skip each update."); + + addField("useFadeOut", TypeBool, Offset(mUseFadeOut, RibbonData), + "If true, the ribbon will fade away after deletion."); + addField("fadeAwayStep", TypeF32, Offset(mFadeAwayStep, RibbonData), + "How much to fade the ribbon with each update, after deletion."); + addField("ribbonMaterial", TypeString, Offset(mMatName, RibbonData), + "The material the ribbon uses for rendering."); + addField("tileScale", TypeF32, Offset(mTileScale, RibbonData), "How much to scale each 'tile' with, where 1 means the material is stretched" "across the whole ribbon. (If TexcoordsRelativeToDistance is true, this is in meters.)"); addField("fixedTexcoords", TypeBool, Offset(mFixedTexcoords, RibbonData), "If true, this prevents 'floating' texture coordinates."); - addField("skipAmount", TypeS32, Offset(mSegmentSkipAmount, RibbonData), - "The amount of segments to skip each update."); - addField("TexcoordsRelativeToDistance", TypeBool, Offset(mTexcoordsRelativeToDistance, RibbonData), + addField("texcoordsRelativeToDistance", TypeBool, Offset(mTexcoordsRelativeToDistance, RibbonData), "If true, texture coordinates are scaled relative to distance, this prevents" "'stretched' textures."); + + endGroup("Ribbon"); } @@ -122,7 +128,7 @@ void RibbonData::packData(BitStream* stream) { Parent::packData(stream); - for (U8 i = 0; i < RIBBON_NUM_FIELDS; i++) { + for (U8 i = 0; i < NumFields; i++) { stream->write(mSizes[i]); stream->write(mColours[i]); stream->write(mTimes[i]); @@ -142,7 +148,7 @@ void RibbonData::unpackData(BitStream* stream) { Parent::unpackData(stream); - for (U8 i = 0; i < RIBBON_NUM_FIELDS; i++) { + for (U8 i = 0; i < NumFields; i++) { stream->read(&mSizes[i]); stream->read(&mColours[i]); stream->read(&mTimes[i]); @@ -558,7 +564,7 @@ void Ribbon::createBuffers(SceneRenderState *state, GFXVertexBufferHandlemSizes[0]; ColorF tColor = mDataBlock->mColours[0]; - for (U8 j = 0; j < RIBBON_NUM_FIELDS-1; j++) { + for (U8 j = 0; j < RibbonData::NumFields-1; j++) { F32 curPosition = mDataBlock->mTimes[j]; F32 curRadius = mDataBlock->mSizes[j]; diff --git a/Engine/source/T3D/fx/ribbon.h b/Engine/source/T3D/fx/ribbon.h index ce115d461..10ca8d40b 100644 --- a/Engine/source/T3D/fx/ribbon.h +++ b/Engine/source/T3D/fx/ribbon.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC +// Copyright (c) 2014 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 @@ -38,8 +38,6 @@ #include "materials/materialParameters.h" #include "math/util/matrixSet.h" -#define RIBBON_NUM_FIELDS 4 - //-------------------------------------------------------------------------- class RibbonData : public GameBaseData { @@ -50,19 +48,26 @@ protected: public: - U32 mRibbonLength; ///< The amount of segments that will make up the ribbon. - F32 mSizes[RIBBON_NUM_FIELDS]; ///< The radius for each keyframe. - ColorF mColours[RIBBON_NUM_FIELDS]; ///< The colour of the ribbon for each keyframe. - F32 mTimes[RIBBON_NUM_FIELDS]; ///< The relative time for each keyframe. - StringTableEntry mMatName; ///< The material for the ribbon. - bool mUseFadeOut; ///< If true, the ribbon will fade away after deletion. - F32 mFadeAwayStep; ///< How quickly the ribbons is faded away after deletion. - S32 segmentsPerUpdate; ///< Amount of segments to add each update. - F32 mTileScale; ///< A scalar to scale the texcoord. - bool mFixedTexcoords; ///< If true, texcoords will stay the same over the lifetime for each segment. - bool mTexcoordsRelativeToDistance; ///< If true, texcoords will not be stretched if the distance between 2 segments are long. + enum Constants + { + NumFields = 4 + }; + + F32 mSizes[NumFields]; ///< The radius for each keyframe. + ColorF mColours[NumFields]; ///< The colour of the ribbon for each keyframe. + F32 mTimes[NumFields]; ///< The relative time for each keyframe. + + U32 mRibbonLength; ///< The amount of segments that will make up the ribbon. + S32 segmentsPerUpdate; ///< Amount of segments to add each update. S32 mSegmentSkipAmount; ///< The amount of segments to skip each time segments are added. + bool mUseFadeOut; ///< If true, the ribbon will fade away after deletion. + F32 mFadeAwayStep; ///< How quickly the ribbons is faded away after deletion. + StringTableEntry mMatName; ///< The material for the ribbon. + F32 mTileScale; ///< A scalar to scale the texcoord. + bool mFixedTexcoords; ///< If true, texcoords will stay the same over the lifetime for each segment. + bool mTexcoordsRelativeToDistance; ///< If true, texcoords will not be stretched if the distance between 2 segments are long. + RibbonData(); void packData(BitStream*); @@ -77,21 +82,25 @@ public: class Ribbon : public GameBase { typedef GameBase Parent; + RibbonData* mDataBlock; + + bool mDeleteOnEnd; ///< If true, the ribbon should delete itself as soon as the last segment is deleted + bool mUseFadeOut; ///< If true, the ribbon will fade away upon deletion + F32 mFadeAwayStep; ///< How quickly the ribbons is faded away after deletion. + F32 mFadeOut; + F32 mTravelledDistance; ///< How far the ribbon has travelled in it's lifetime. + Vector mSegmentPoints; ///< The points in space where the ribbon has spawned segments. + U32 mSegmentOffset; + U32 mSegmentIdx; + + bool mUpdateBuffers; ///< If true, the vertex buffers need to be updated. BaseMatInstance *mRibbonMat; MaterialParameterHandle* mRadiusSC; MaterialParameterHandle* mRibbonProjSC; GFXPrimitiveBufferHandle primBuffer; GFXVertexBufferHandle verts; - bool mUpdateBuffers; ///< If true, the vertex buffers need to be updated. - bool mDeleteOnEnd; ///< If true, the ribbon should delete itself as soon as the last segment is deleted - bool mUseFadeOut; ///< If true, the ribbon will fade away upon deletion - F32 mFadeAwayStep; ///< How quickly the ribbons is faded away after deletion. - F32 mFadeOut; - U32 mSegmentOffset; - U32 mSegmentIdx; - F32 mTravelledDistance; ///< How far the ribbon has travelled in it's lifetime. protected: @@ -102,10 +111,11 @@ protected: // Rendering void prepRenderImage(SceneRenderState *state); + void setShaderParams(); ///Checks to see if ribbon is too long U32 checkRibbonDistance(S32 segments); - void setShaderParams(); + /// Construct the vertex and primitive buffers void createBuffers(SceneRenderState *state, GFXVertexBufferHandle &verts, GFXPrimitiveBufferHandle &pb, U32 segments); @@ -116,11 +126,16 @@ public: DECLARE_CONOBJECT(Ribbon); static void initPersistFields(); bool onNewDataBlock(GameBaseData*,bool); - void addSegmentPoint(Point3F &point, MatrixF &mat); ///< Used to add another segment to the ribbon. - void clearSegments() { mSegmentPoints.clear(); } ///< Delete all segments. - void deleteOnEnd(); ///< Delete the ribbon when all segments have been deleted. void onRemove(); + /// Used to add another segment to the ribbon. + void addSegmentPoint(Point3F &point, MatrixF &mat); + + /// Delete all segments. + void clearSegments() { mSegmentPoints.clear(); } + + /// Delete the ribbon when all segments have been deleted. + void deleteOnEnd(); }; #endif // _H_RIBBON diff --git a/Engine/source/T3D/fx/ribbonNode.cpp b/Engine/source/T3D/fx/ribbonNode.cpp index 0343fc5b3..2582fbe6f 100644 --- a/Engine/source/T3D/fx/ribbonNode.cpp +++ b/Engine/source/T3D/fx/ribbonNode.cpp @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC +// Copyright (c) 2014 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 diff --git a/Engine/source/T3D/fx/ribbonNode.h b/Engine/source/T3D/fx/ribbonNode.h index 62b1158e4..cdd86ef33 100644 --- a/Engine/source/T3D/fx/ribbonNode.h +++ b/Engine/source/T3D/fx/ribbonNode.h @@ -1,5 +1,5 @@ //----------------------------------------------------------------------------- -// Copyright (c) 2012 GarageGames, LLC +// Copyright (c) 2014 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 @@ -37,12 +37,9 @@ class RibbonNodeData : public GameBaseData { typedef GameBaseData Parent; - //-------------------------------------- Console set variables public: F32 timeMultiple; - //-------------------------------------- load set variables - public: RibbonNodeData(); ~RibbonNodeData();