Skip to content
Permalink
Browse files

Main: Controller - add static ::create() member to Function & Value

this pattern is more terse and more safe as it enforces shared_ptr
usage.
Also this allows us to exposing creation to wrappers.
  • Loading branch information...
paroj committed Dec 4, 2018
1 parent de29edc commit 52d1512013e281e15720864b1b2dd95ae8b80552
@@ -9,6 +9,7 @@
#include "OgreTrays.h"
#include "OgreAdvancedRenderControls.h"
#include "OgreUnifiedHighLevelGpuProgram.h"
#include "OgrePredefinedControllers.h"
%}

%include std_string.i
@@ -15,6 +15,7 @@
#include "OgreScriptCompiler.h"
#include "OgreConfigDialog.h"
#include "OgreFileSystemLayer.h"
#include "OgrePredefinedControllers.h"
%}

%include std_shared_ptr.i
@@ -307,7 +308,11 @@ SHARED_PTR(StringInterface);
%include "OgreHighLevelGpuProgram.h"
%include "OgreScriptCompiler.h"
%include "OgreTextureUnitState.h"
%template(ControllerReal) Ogre::Controller<Ogre::Real>;
%template(ControllerValueRealPtr) Ogre::SharedPtr<Ogre::ControllerValue<Ogre::Real> >;
%template(ControllerFunctionPtr) Ogre::SharedPtr<Ogre::ControllerFunction<Ogre::Real> >;
%include "OgreControllerManager.h"
%include "OgrePredefinedControllers.h"
SHARED_PTR(Compositor);
%include "OgreCompositor.h"
%ignore Ogre::CompositionTechnique::getNumTextureDefinitions;
@@ -78,8 +78,7 @@ namespace Ogre {
public:
/** Constructor.
@param
deltaInput If true, signifies that the input will be a delta value such that the function should
add it to an internal counter before calculating the output.
deltaInput If true, function will add input values together and wrap at 1.0 before evaluating
*/
ControllerFunction(bool deltaInput)
{
@@ -57,7 +57,11 @@ namespace Ogre {
Real mFrameDelay;

public:
/// @deprecated use create()
FrameTimeControllerValue();

static ControllerValueRealPtr create() { return std::make_shared<FrameTimeControllerValue>(); }

bool frameEnded(const FrameEvent &evt);
bool frameStarted(const FrameEvent &evt);
Real getValue(void) const;
@@ -78,8 +82,14 @@ namespace Ogre {
protected:
TextureUnitState* mTextureLayer;
public:
/// @deprecated use create()
TextureFrameControllerValue(TextureUnitState* t);

static ControllerValueRealPtr create(TextureUnitState* t)
{
return std::make_shared<TextureFrameControllerValue>(t);
}

/** Gets the frame number as a parametric value in the range [0,1]
*/
Real getValue(void) const;
@@ -105,6 +115,10 @@ namespace Ogre {
bool mRotate;
TextureUnitState* mTextureLayer;
public:
/// @deprecated use create
TexCoordModifierControllerValue(TextureUnitState* t, bool translateU = false, bool translateV = false,
bool scaleU = false, bool scaleV = false, bool rotate = false );

/** Constructor.
@param
t TextureUnitState to apply the modification to.
@@ -119,8 +133,11 @@ namespace Ogre {
@param
rotate If true, the texture will be rotated by the modification.
*/
TexCoordModifierControllerValue(TextureUnitState* t, bool translateU = false, bool translateV = false,
bool scaleU = false, bool scaleV = false, bool rotate = false );
static ControllerValueRealPtr create(TextureUnitState* t, bool translateU = false, bool translateV = false,
bool scaleU = false, bool scaleV = false, bool rotate = false)
{
return std::make_shared<TexCoordModifierControllerValue>(t, translateU, translateV, scaleU, scaleV, rotate);
}

Real getValue(void) const;
void setValue(Real value);
@@ -136,7 +153,7 @@ namespace Ogre {
need to use named parameters, retrieve the index from the param
object before setting this controller up.
@note
Retrieving a value from the program parameters is not currently
Retrieving a value from the program parameters is not currently
supported, therefore do not use this controller value as a source,
only as a target.
*/
@@ -148,16 +165,19 @@ namespace Ogre {
/// The index of the parameter to be read or set
size_t mParamIndex;
public:
/// @deprecated use create()
FloatGpuParameterControllerValue(GpuProgramParametersSharedPtr params, size_t index);

/** Constructor.
@param
params The parameters object to access
@param
index The index of the parameter to be set
*/
FloatGpuParameterControllerValue(GpuProgramParametersSharedPtr params,
size_t index );

~FloatGpuParameterControllerValue() {}
static ControllerValueRealPtr create(GpuProgramParametersSharedPtr params, size_t index)
{
return std::make_shared<FloatGpuParameterControllerValue>(params, index);
}

Real getValue(void) const;
void setValue(Real value);
@@ -173,15 +193,15 @@ namespace Ogre {
class _OgreExport PassthroughControllerFunction : public ControllerFunction<Real>
{
public:
/** Constructor.
@param
deltaInput If true, signifies that the input will be a delta value such that the function should
add it to an internal counter before calculating the output.
*/
/// @deprecated use create()
PassthroughControllerFunction(bool deltaInput = false);

/** Overridden function.
*/
/// @copydoc ControllerFunction::ControllerFunction
static ControllerFunctionRealPtr create(bool deltaInput = false)
{
return std::make_shared<PassthroughControllerFunction>(deltaInput);
}

Real calculate(Real source);
};

@@ -193,16 +213,20 @@ namespace Ogre {
Real mSeqTime;
Real mTime;
public:
/// @deprecated use create()
AnimationControllerFunction(Real sequenceTime, Real timeOffset = 0.0f);

/** Constructor.
@param
sequenceTime The amount of time in seconds it takes to loop through the whole animation sequence.
@param
timeOffset The offset in seconds at which to start (default is start at 0)
*/
AnimationControllerFunction(Real sequenceTime, Real timeOffset = 0.0f);
static ControllerFunctionRealPtr create(Real sequenceTime, Real timeOffset = 0.0f)
{
return std::make_shared<AnimationControllerFunction>(sequenceTime, timeOffset);
}

/** Overridden function.
*/
Real calculate(Real source);

/** Set the time value manually. */
@@ -219,19 +243,22 @@ namespace Ogre {
protected:
Real mScale;
public:
/// @deprecated use create()
ScaleControllerFunction(Real scalefactor, bool deltaInput);

/** Constructor, requires a scale factor.
@param
scalefactor The multiplier applied to the input to produce the output.
@param
deltaInput If true, signifies that the input will be a delta value such that the function should
add it to an internal counter before calculating the output.
*/
ScaleControllerFunction(Real scalefactor, bool deltaInput);
static ControllerFunctionRealPtr create(Real scalefactor, bool deltaInput = false)
{
return std::make_shared<ScaleControllerFunction>(scalefactor, deltaInput);
}

/** Overridden method.
*/
Real calculate(Real source);

};

//-----------------------------------------------------------------------
@@ -261,6 +288,9 @@ namespace Ogre {
Real getAdjustedInput(Real input);

public:
/// @deprecated use create()
WaveformControllerFunction(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5);

/** Default constructor, requires at least a wave type, other parameters can be defaulted unless required.
@param wType the shape of the wave
@param base the base value of the output from the wave
@@ -273,12 +303,12 @@ namespace Ogre {
@param
dutyCycle Used in PWM mode to specify the pulse width.
*/
WaveformControllerFunction(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5);
static ControllerFunctionRealPtr create(WaveformType wType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1, bool deltaInput = true, Real dutyCycle = 0.5)
{
return std::make_shared<WaveformControllerFunction>(wType, base, frequency, phase, amplitude, deltaInput, dutyCycle);
}

/** Overridden function.
*/
Real calculate(Real source);

};

//-----------------------------------------------------------------------
@@ -289,6 +319,9 @@ namespace Ogre {
std::vector<Real> mKeys;
std::vector<Real> mValues;
public:
/// @deprecated use create()
LinearControllerFunction(const std::vector<Real>& keys, const std::vector<Real>& values, Real frequency = 1, bool deltaInput = true);

/** Constructor, requires keys and values of the function to interpolate
@param
keys the x-values of the function sampling points. Value range is [0,1]. Must include at least the keys 0 and 1.
@@ -300,10 +333,11 @@ namespace Ogre {
@remarks
there must be the same amount of keys and values
*/
LinearControllerFunction(const std::vector<Real>& keys, const std::vector<Real>& values, Real frequency = 1, bool deltaInput = true);
static ControllerFunctionRealPtr create(const std::vector<Real>& keys, const std::vector<Real>& values, Real frequency = 1, bool deltaInput = true)
{
return std::make_shared<LinearControllerFunction>(keys, values, frequency, deltaInput);
}

/** Overridden function.
*/
Real calculate(Real source);
};
//-----------------------------------------------------------------------
@@ -108,10 +108,8 @@ namespace Ogre {
//-----------------------------------------------------------------------
Controller<Real>* ControllerManager::createTextureAnimator(TextureUnitState* layer, Real sequenceTime)
{
SharedPtr< ControllerValue<Real> > texVal(OGRE_NEW TextureFrameControllerValue(layer));
SharedPtr< ControllerFunction<Real> > animFunc(OGRE_NEW AnimationControllerFunction(sequenceTime));

return createController(mFrameTimeController, texVal, animFunc);
return createController(mFrameTimeController, TextureFrameControllerValue::create(layer),
AnimationControllerFunction::create(sequenceTime));
}
//-----------------------------------------------------------------------
Controller<Real>* ControllerManager::createTextureUVScroller(TextureUnitState* layer, Real speed)
@@ -121,10 +119,9 @@ namespace Ogre {
if (speed != 0)
{
// We do both scrolls with a single controller
SharedPtr< ControllerValue<Real> > val(OGRE_NEW TexCoordModifierControllerValue(layer, true, true));
// Create function: use -speed since we're altering texture coords so they have reverse effect
SharedPtr< ControllerFunction<Real> > func(OGRE_NEW ScaleControllerFunction(-speed, true));
ret = createController(mFrameTimeController, val, func);
ret = createController(mFrameTimeController, TexCoordModifierControllerValue::create(layer, true, true),
ScaleControllerFunction::create(-speed, true));
}

return ret;
@@ -136,10 +133,9 @@ namespace Ogre {

if (uSpeed != 0)
{
SharedPtr< ControllerValue<Real> > uVal(OGRE_NEW TexCoordModifierControllerValue(layer, true));
// Create function: use -speed since we're altering texture coords so they have reverse effect
SharedPtr< ControllerFunction<Real> > uFunc(OGRE_NEW ScaleControllerFunction(-uSpeed, true));
ret = createController(mFrameTimeController, uVal, uFunc);
ret = createController(mFrameTimeController, TexCoordModifierControllerValue::create(layer, true),
ScaleControllerFunction::create(-uSpeed, true));
}

return ret;
@@ -152,10 +148,9 @@ namespace Ogre {
if (vSpeed != 0)
{
// Set up a second controller for v scroll
SharedPtr< ControllerValue<Real> > vVal(OGRE_NEW TexCoordModifierControllerValue(layer, false, true));
// Create function: use -speed since we're altering texture coords so they have reverse effect
SharedPtr< ControllerFunction<Real> > vFunc(OGRE_NEW ScaleControllerFunction(-vSpeed, true));
ret = createController(mFrameTimeController, vVal, vFunc);
ret = createController(mFrameTimeController, TexCoordModifierControllerValue::create(layer, false, true),
ScaleControllerFunction::create(-vSpeed, true));
}

return ret;
@@ -164,56 +159,51 @@ namespace Ogre {
Controller<Real>* ControllerManager::createTextureRotater(TextureUnitState* layer, Real speed)
{
// Target value is texture coord rotation
SharedPtr< ControllerValue<Real> > val(OGRE_NEW TexCoordModifierControllerValue(layer, false, false, false, false, true));
// Function is simple scale (seconds * speed)
// Use -speed since altering texture coords has the reverse visible effect
SharedPtr< ControllerFunction<Real> > func(OGRE_NEW ScaleControllerFunction(-speed, true));
return createController(mFrameTimeController, val, func);

return createController(mFrameTimeController,
TexCoordModifierControllerValue::create(layer, false, false, false, false, true),
ScaleControllerFunction::create(-speed, true));
}
//-----------------------------------------------------------------------
Controller<Real>* ControllerManager::createTextureWaveTransformer(TextureUnitState* layer,
TextureUnitState::TextureTransformType ttype, WaveformType waveType, Real base, Real frequency, Real phase, Real amplitude)
{
SharedPtr< ControllerValue<Real> > val;
ControllerValueRealPtr val;

switch (ttype)
{
case TextureUnitState::TT_TRANSLATE_U:
// Target value is a u scroll
val.reset(OGRE_NEW TexCoordModifierControllerValue(layer, true));
val = TexCoordModifierControllerValue::create(layer, true);
break;
case TextureUnitState::TT_TRANSLATE_V:
// Target value is a v scroll
val.reset(OGRE_NEW TexCoordModifierControllerValue(layer, false, true));
val = TexCoordModifierControllerValue::create(layer, false, true);
break;
case TextureUnitState::TT_SCALE_U:
// Target value is a u scale
val.reset(OGRE_NEW TexCoordModifierControllerValue(layer, false, false, true));
val = TexCoordModifierControllerValue::create(layer, false, false, true);
break;
case TextureUnitState::TT_SCALE_V:
// Target value is a v scale
val.reset(OGRE_NEW TexCoordModifierControllerValue(layer, false, false, false, true));
val = TexCoordModifierControllerValue::create(layer, false, false, false, true);
break;
case TextureUnitState::TT_ROTATE:
// Target value is texture coord rotation
val.reset(OGRE_NEW TexCoordModifierControllerValue(layer, false, false, false, false, true));
val = TexCoordModifierControllerValue::create(layer, false, false, false, false, true);
break;
}
// Create new wave function for alterations
SharedPtr< ControllerFunction<Real> > func(OGRE_NEW WaveformControllerFunction(waveType, base, frequency, phase, amplitude, true));

return createController(mFrameTimeController, val, func);
return createController(mFrameTimeController, val,
WaveformControllerFunction::create(waveType, base, frequency, phase, amplitude, true));
}
//-----------------------------------------------------------------------
Controller<Real>* ControllerManager::createGpuProgramTimerParam(
GpuProgramParametersSharedPtr params, size_t paramIndex, Real timeFactor)
{
SharedPtr< ControllerValue<Real> > val(OGRE_NEW FloatGpuParameterControllerValue(params, paramIndex));
SharedPtr< ControllerFunction<Real> > func(OGRE_NEW ScaleControllerFunction(timeFactor, true));

return createController(mFrameTimeController, val, func);

return createController(mFrameTimeController, FloatGpuParameterControllerValue::create(params, paramIndex),
ScaleControllerFunction::create(timeFactor, true));
}
//-----------------------------------------------------------------------
void ControllerManager::destroyController(Controller<Real>* controller)

0 comments on commit 52d1512

Please sign in to comment.
You can’t perform that action at this time.