|
|
|
|
|
class PPEClassBase |
|
|
{ |
|
|
protected PPEManager m_Manager; |
|
|
protected string m_MaterialPath = ""; |
|
|
protected Material m_Material; |
|
|
|
|
|
protected ref map<int, ref array<int>> m_ParameterUpdateQueueMap; |
|
|
protected ref array<int> m_ParameterRemovalQueue; |
|
|
protected ref array<int> m_UpdatedParameters; |
|
|
|
|
|
protected ref map<int,ref PPEMatClassParameterCommandData> m_MaterialParamMapStructure; |
|
|
|
|
|
void PPEClassBase(string mat_path_override = "") |
|
|
{ |
|
|
Init(mat_path_override); |
|
|
CreateMaterial(); |
|
|
CreateDataStructure(); |
|
|
RegisterMaterialParameters(); |
|
|
} |
|
|
|
|
|
protected void Init(string mat_path_override = "") |
|
|
{ |
|
|
if (mat_path_override != "") |
|
|
{ |
|
|
m_MaterialPath = mat_path_override; |
|
|
} |
|
|
else |
|
|
{ |
|
|
m_MaterialPath = GetDefaultMaterialPath(); |
|
|
} |
|
|
m_Manager = PPEManagerStatic.GetPPEManager(); |
|
|
} |
|
|
|
|
|
protected void CreateMaterial() |
|
|
{ |
|
|
if (m_MaterialPath != "") |
|
|
m_Material = GetGame().GetWorld().GetMaterial(m_MaterialPath); |
|
|
} |
|
|
|
|
|
Material GetMaterial() |
|
|
{ |
|
|
return m_Material; |
|
|
} |
|
|
|
|
|
|
|
|
protected void CreateDataStructure() |
|
|
{ |
|
|
m_MaterialParamMapStructure = new map<int,ref PPEMatClassParameterCommandData>; |
|
|
|
|
|
m_ParameterUpdateQueueMap = new map<int, ref array<int>>; |
|
|
m_ParameterRemovalQueue = new array<int>; |
|
|
m_UpdatedParameters = new array<int>; |
|
|
} |
|
|
|
|
|
|
|
|
protected void RegisterMaterialParameters(); |
|
|
|
|
|
protected void RegisterParameterScalarBool(int idx, string parameter_name, bool default_value) |
|
|
{ |
|
|
PPETemplateDefBool p = new PPETemplateDefBool(parameter_name,default_value); |
|
|
PPEMatClassParameterBool parameter_data = new PPEMatClassParameterBool(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
protected void RegisterParameterScalarInt(int idx, string parameter_name, int default_value, int min, int max) |
|
|
{ |
|
|
PPETemplateDefInt p = new PPETemplateDefInt(parameter_name,default_value,min,max); |
|
|
|
|
|
PPEMatClassParameterInt parameter_data = new PPEMatClassParameterInt(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
|
|
|
protected void RegisterParameterScalarFloat(int idx, string parameter_name, float default_value, float min, float max) |
|
|
{ |
|
|
PPETemplateDefFloat p = new PPETemplateDefFloat(parameter_name,default_value,min,max); |
|
|
|
|
|
PPEMatClassParameterFloat parameter_data = new PPEMatClassParameterFloat(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
|
|
|
protected void RegisterParameterScalarFloatEx(int idx, string parameter_name, float default_value, float min, float max, typename type) |
|
|
{ |
|
|
PPETemplateDefFloat p = new PPETemplateDefFloat(parameter_name,default_value,min,max); |
|
|
|
|
|
PPEMatClassParameterFloat parameter_data; |
|
|
bool boo = Class.CastTo(parameter_data,type.Spawn()); |
|
|
|
|
|
parameter_data.RegisterDefaults(p); |
|
|
parameter_data.SetMaterialIndex(GetPostProcessEffectID()); |
|
|
parameter_data.SetParameterIndex(idx); |
|
|
parameter_data.SetParent(this); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
|
|
|
protected void RegisterParameterColor(int idx, string parameter_name, float r, float g, float b, float a) |
|
|
{ |
|
|
PPETemplateDefColor p = new PPETemplateDefColor(parameter_name,r,g,b,a); |
|
|
PPEMatClassParameterColor parameter_data = new PPEMatClassParameterColor(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
|
|
|
protected void RegisterParameterColorEx(int idx, string parameter_name, float r, float g, float b, float a, typename type) |
|
|
{ |
|
|
PPETemplateDefColor p = new PPETemplateDefColor(parameter_name,r,g,b,a); |
|
|
PPEMatClassParameterColor parameter_data; |
|
|
bool boo = Class.CastTo(parameter_data,type.Spawn()); |
|
|
|
|
|
parameter_data.RegisterDefaults(p); |
|
|
parameter_data.SetMaterialIndex(GetPostProcessEffectID()); |
|
|
parameter_data.SetParameterIndex(idx); |
|
|
parameter_data.SetParent(this); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
protected void RegisterParameterVector(int idx, string parameter_name, array<float> default_values) |
|
|
{ |
|
|
PPETemplateDefVector p = new PPETemplateDefVector(parameter_name,default_values); |
|
|
PPEMatClassParameterVector parameter_data = new PPEMatClassParameterVector(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
|
|
|
protected void RegisterParameterTexture(int idx, string parameter_name, string default_path) |
|
|
{ |
|
|
PPETemplateDefTexture p = new PPETemplateDefTexture(parameter_name,default_path); |
|
|
PPEMatClassParameterTexture parameter_data = new PPEMatClassParameterTexture(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
protected void RegisterParameterResource(int idx, string parameter_name, string default_path) |
|
|
{ |
|
|
PPETemplateDefResource p = new PPETemplateDefResource(parameter_name,default_path); |
|
|
PPEMatClassParameterResource parameter_data = new PPEMatClassParameterResource(GetPostProcessEffectID(),idx,this); |
|
|
parameter_data.RegisterDefaults(p); |
|
|
m_MaterialParamMapStructure.Set(idx, parameter_data); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void InsertParamValueData(PPERequestParamDataBase request_data) |
|
|
{ |
|
|
PPEMatClassParameterCommandData param_data; |
|
|
bool exists = m_MaterialParamMapStructure.Find(request_data.GetParameterID(),param_data); |
|
|
if ( !exists ) |
|
|
{ |
|
|
Error("PPEClassBase | InsertParamValueData | mat/par/req: " + GetPostProcessEffectID() + "/" + request_data.GetParameterID() + "/" + request_data.GetRequesterIDX() + " not registered in m_MaterialParamMapStructure!"); |
|
|
return; |
|
|
} |
|
|
|
|
|
request_data.SetDataActive(true); |
|
|
request_data.SetUpdatingDataValues(true); |
|
|
param_data.InsertRequestData(request_data); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RemoveRequest(int req_idx) |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void OnUpdate(float timeslice, int order) |
|
|
{ |
|
|
int parameter_idx = -1; |
|
|
|
|
|
|
|
|
if ( m_ParameterUpdateQueueMap.Contains(order) ) |
|
|
{ |
|
|
|
|
|
for ( int i = 0; i < m_ParameterUpdateQueueMap.Get(order).Count(); i++ ) |
|
|
{ |
|
|
|
|
|
Param p_values; |
|
|
bool setting_defaults = false; |
|
|
parameter_idx = m_ParameterUpdateQueueMap.Get(order).Get(i); |
|
|
m_MaterialParamMapStructure.Get(parameter_idx).Update(timeslice,p_values,setting_defaults,order); |
|
|
|
|
|
InsertUpdatedParameter(parameter_idx); |
|
|
} |
|
|
m_Manager.InsertUpdatedMaterial(GetPostProcessEffectID()); |
|
|
|
|
|
ParamUpdateQueueCleanup(order); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void SetFinalParameterValue(int parameter_idx) |
|
|
{ |
|
|
int var_type = GetParameterCommandData(parameter_idx).GetParameterVarType(); |
|
|
Param values = GetParameterCommandData(parameter_idx).GetCurrentValues(); |
|
|
|
|
|
switch (var_type) |
|
|
{ |
|
|
case PPEConstants.VAR_TYPE_BOOL: |
|
|
bool value_var_bool = Param1<bool>.Cast(values).param1; |
|
|
|
|
|
m_Material.SetParamByIndex(parameter_idx,value_var_bool); |
|
|
|
|
|
break; |
|
|
|
|
|
case PPEConstants.VAR_TYPE_INT: |
|
|
int value_var_int = Param1<int>.Cast(values).param1; |
|
|
|
|
|
m_Material.SetParamByIndex(parameter_idx,value_var_int); |
|
|
|
|
|
break; |
|
|
|
|
|
case PPEConstants.VAR_TYPE_FLOAT: |
|
|
float value_var_float = Param1<float>.Cast(values).param1; |
|
|
|
|
|
m_Material.SetParamByIndex(parameter_idx,value_var_float); |
|
|
|
|
|
break; |
|
|
|
|
|
case PPEConstants.VAR_TYPE_COLOR: |
|
|
float color[4] = {0,0,0,0}; |
|
|
color[0] = Param4<float,float,float,float>.Cast(values).param1; |
|
|
color[1] = Param4<float,float,float,float>.Cast(values).param2; |
|
|
color[2] = Param4<float,float,float,float>.Cast(values).param3; |
|
|
color[3] = Param4<float,float,float,float>.Cast(values).param4; |
|
|
|
|
|
m_Material.SetParamByIndex(parameter_idx,color); |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
void ApplyValueChanges() |
|
|
{ |
|
|
int parameter_id; |
|
|
for (int i = 0; i < m_UpdatedParameters.Count(); i++) |
|
|
{ |
|
|
parameter_id = m_UpdatedParameters.Get(i); |
|
|
SetFinalParameterValue(parameter_id); |
|
|
} |
|
|
|
|
|
m_UpdatedParameters.Clear(); |
|
|
} |
|
|
|
|
|
protected void InsertUpdatedParameter(int mat_id) |
|
|
{ |
|
|
if ( m_UpdatedParameters.Find(mat_id) == -1 ) |
|
|
m_UpdatedParameters.Insert(mat_id); |
|
|
} |
|
|
|
|
|
|
|
|
void ParamUpdateRemove(int parameter_idx) |
|
|
{ |
|
|
if ( m_ParameterRemovalQueue.Find(parameter_idx) == -1 ) |
|
|
m_ParameterRemovalQueue.Insert(parameter_idx); |
|
|
} |
|
|
|
|
|
|
|
|
void SetParameterUpdating(int order, int parameter_id) |
|
|
{ |
|
|
if ( !m_ParameterUpdateQueueMap.Contains(order) ) |
|
|
{ |
|
|
m_ParameterUpdateQueueMap.Set(order,new array<int>); |
|
|
} |
|
|
|
|
|
if ( m_ParameterUpdateQueueMap.Get(order).Find(parameter_id) == -1 ) |
|
|
{ |
|
|
m_ParameterUpdateQueueMap.Get(order).Insert(parameter_id); |
|
|
} |
|
|
} |
|
|
|
|
|
protected void ParamUpdateQueueCleanup(int order) |
|
|
{ |
|
|
|
|
|
|
|
|
for ( int i = 0; i < m_ParameterUpdateQueueMap.Get(order).Count(); i++ ) |
|
|
{ |
|
|
if ( m_ParameterRemovalQueue.Find(m_ParameterUpdateQueueMap.Get(order).Get(i)) != -1 ) |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
m_ParameterUpdateQueueMap.Get(order).Clear(); |
|
|
} |
|
|
|
|
|
|
|
|
string GetDefaultMaterialPath(); |
|
|
|
|
|
void ChangeMaterialPathUsed(string path) |
|
|
{ |
|
|
m_MaterialPath = path; |
|
|
m_Material = null; |
|
|
CreateMaterial(); |
|
|
} |
|
|
|
|
|
string GetCurrentMaterialPath() |
|
|
{ |
|
|
return m_MaterialPath; |
|
|
} |
|
|
|
|
|
|
|
|
int GetPostProcessEffectID() |
|
|
{ |
|
|
return PostProcessEffectType.None; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PPEMatClassParameterCommandData GetParameterCommandData(int parameter_idx) |
|
|
{ |
|
|
return m_MaterialParamMapStructure.Get(parameter_idx); |
|
|
} |
|
|
|
|
|
#ifdef DEVELOPER |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
void DbgPrnt(string text) |
|
|
{ |
|
|
|
|
|
} |
|
|
}; |
|
|
|