1.代理模式
environmentEffec中定义关于雾效,灯光等代理。通过代理,proxy 实现具体的效果
FogProxy * getFogProxy(){return &mFogProxy;};
LightProxy * getLightProxy(){return &mLightProxy;};
TrivialProxy * getTrivialProxy() {return &mTrivialProxy;}
定义FogProxy, LightProxy,SkyLayerProxy,TrivialProxy 类 以及类中的函数,实现添加雾效,光效,天空等效果.
class FogProxy
{
public:
FogProxy()
:mFogEnable(false)
, mFogFar(1000)
, mFogNear(100)
, mFogColor(ColorValue::White)
, mFogDensity(1)
{
};
~FogProxy(){};
void setFogFar(float fogfar, float alpha);;
float getFogFar()const { return mFogFar; };
void setFogNear(float fogNear, float alpha);;
float getFogNear()const { return mFogNear; };
void setFogColor(const ColorValue & color, float alpha);;
const ColorValue & getFogColor()const { return mFogColor; };
void setFogDensity(float density, float alpha);;
float getFogDensity()const { return mFogDensity; };
void setFogEnable(bool enable){mFogEnable = enable;}
bool getFogEnable()const{return mFogEnable;}
protected:
float mFogFar;
float mFogNear;
ColorValue mFogColor;
float mFogDensity;
bool mFogEnable;
};
2.命令模式
创建weathercommand,
class WeatherCommand
{
public:
WeatherCommand(){};
virtual ~WeatherCommand(){};
virtual void doCommand(EnvironmentEffect * env, float timeAlpha, float regionAlpha, float filterAlpha) = 0;
virtual const tstring & getCommandId() = 0;
virtual const tstring & getClassId() = 0;
void notifyWeather(Weather * weather){mWeather = weather;};
protected:
Weather * mWeather;
};
3.工厂模式
在类weatherCommandFactory中使用工厂模式创建,销毁天气命令。之后可以派生出各种天气命令。class WeatherCommandFactory
{
public:
WeatherCommandFactory();
~WeatherCommandFactory();
static WeatherCommand * createCommand(const tstring & str, void * param);
static void destroyCommand(WeatherCommand * command);
typedef WeatherCommand* (*Creator)(void *);
static void registerAllCommand();
static std::map<tstring , Creator> mCommandCreator;
};
其中registerAllCommand() 注册各种产生天气命令