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

📄 ivu_active_value.cxx

📁 hl2 source code. Do not use it illegal.
💻 CXX
📖 第 1 页 / 共 2 页
字号:
    if(this->last_update == this->change_meter) return; // already valid
    this->last_update = this->change_meter;

    IVP_DOUBLE time = time_mod->give_double_value();
    IVP_DOUBLE new_val = IVP_Inline_Math::sind(time * frequence + time_shift) * amplitude + null_level;

    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Sine::print()
{
    printf("Sine[F %g, A %g, N %g, ts %g](", frequence, amplitude, null_level, time_shift);
    time_mod->print();
    printf(")");
    return 0; // for debugger
}

///////////////////

IVP_U_Active_Square::IVP_U_Active_Square(const char *i_name,
			   IVP_U_Active_Float *i_time_mod,
			   IVP_DOUBLE i_freq,
			   IVP_DOUBLE i_low_val,
			   IVP_DOUBLE i_high_val
                          ) : IVP_U_Active_Float(i_name)
{
    this->time_mod = i_time_mod;

    time_mod->add_dependency(this);

    this->frequence = i_freq;
    this->low_val = i_low_val;
    this->high_val = i_high_val;
}

IVP_U_Active_Square::~IVP_U_Active_Square()
{
    time_mod->remove_dependency(this);
	return;
}

void IVP_U_Active_Square::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE time = time_mod->give_double_value();
    int h = (int)(time * frequence) & 1;
    IVP_DOUBLE new_val = (h) ? high_val : low_val;
    
    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Square::print()
{
    printf("Square[F %g, L %g, H %g](", frequence, low_val, high_val);
    time_mod->print();
    printf(")");
    return 0; // f db
}

/////////////////

IVP_U_Active_Pulse::IVP_U_Active_Pulse(const char *i_name,
				   IVP_U_Active_Float *i_time_mod,
				   IVP_DOUBLE freq,
				   int i_m1,
				   int i_m2,
				   IVP_DOUBLE i_low_val,
				   IVP_DOUBLE i_high_val
                                   ) : IVP_U_Active_Float(i_name)
{
    this->time_mod = i_time_mod;

    time_mod->add_dependency(this);

    this->frequence = freq;
    this->low_val = i_low_val;
    this->high_val = i_high_val;
    this->m1 = i_m1;
    this->m2 = i_m2;

    this->active_float_changed(this);
}

IVP_U_Active_Pulse::~IVP_U_Active_Pulse()
{
    time_mod->remove_dependency(this);
	return;
}

void IVP_U_Active_Pulse::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE time = time_mod->give_double_value();
    int val = (int)(time * frequence * m2) % m2;
    IVP_DOUBLE new_val = (val < m1) ? high_val : low_val;
    
    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Pulse::print()
{
    printf("Pulse[F %g, L %g, H %g, %d:%d](", frequence, low_val, high_val, m1, m2);
    time_mod->print();
    printf(")");
    return 0; // f db
}

/***** MIXER ***********************************/
/***** MIXER ***********************************/
/***** MIXER ***********************************/

IVP_U_Active_Add::IVP_U_Active_Add(const char *i_name,
		     IVP_U_Active_Float *i_mod0,
		     IVP_U_Active_Float *i_mod1) : IVP_U_Active_Float(i_name)
{
    this->mod0 = i_mod0;
    this->mod1 = i_mod1;

    mod0->add_dependency(this);
    mod1->add_dependency(this);
    
    this->active_float_changed(this);
}

IVP_U_Active_Add::~IVP_U_Active_Add()
{
    mod0->remove_dependency(this);
    mod1->remove_dependency(this);
	return;
}

void IVP_U_Active_Add::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE new_val = mod0->give_double_value() + mod1->give_double_value();
    
    if(new_val != this->give_double_value()){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Add::print()
{
    mod0->print();
    printf(" + ");
    mod1->print();
    
    return 0; // for debugger
}

///////////////////////

IVP_U_Active_Sub::IVP_U_Active_Sub(const char *i_name,
		     IVP_U_Active_Float *i_mod0,
		     IVP_U_Active_Float *i_mod1) : IVP_U_Active_Float(i_name)
{

    this->mod0 = i_mod0;
    this->mod1 = i_mod1;

    mod0->add_dependency(this);
    mod1->add_dependency(this);
    
    this->active_float_changed(this);
}

IVP_U_Active_Sub::~IVP_U_Active_Sub()
{
    mod0->remove_dependency(this);
    mod1->remove_dependency(this);
	return;
}

void IVP_U_Active_Sub::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE new_val = mod0->give_double_value() - mod1->give_double_value();
    
    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Sub::print()
{
    mod0->print();
    printf(" - ");
    mod1->print();
    
    return 0; // for debugger
}

///////////////////////


IVP_U_Active_Add_Multiple::IVP_U_Active_Add_Multiple(const char *i_name,
				       IVP_U_Active_Float *i_mod0,
				       IVP_U_Active_Float *i_mod1,
				       IVP_DOUBLE i_factor) : IVP_U_Active_Float(i_name)
{
    this->mod0 = i_mod0;
    this->mod1 = i_mod1;

    this->factor = i_factor;

    mod0->add_dependency(this);
    mod1->add_dependency(this);

    this->active_float_changed((IVP_U_Active_Float *)this);
}

IVP_U_Active_Add_Multiple::~IVP_U_Active_Add_Multiple()
{
    mod0->remove_dependency(this);
    mod1->remove_dependency(this);
	return;
}

void IVP_U_Active_Add_Multiple::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE new_val = mod0->give_double_value() + factor * mod1->give_double_value();
    
    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Add_Multiple::print()
{
    printf("(");
    mod0->print();
    printf(")");

    printf(" + %g * (", factor);
    mod1->print();
    printf(")");
    
    return 0; // f db
}

////////////////////

IVP_U_Active_Mult::IVP_U_Active_Mult(const char *i_name,
		       IVP_U_Active_Float *i_mod0,
		       IVP_U_Active_Float *i_mod1) : IVP_U_Active_Float(i_name)
{
    this->mod0 = i_mod0;
    this->mod1 = i_mod1;

    mod0->add_dependency(this);
    mod1->add_dependency(this);

    this->active_float_changed((IVP_U_Active_Float *)this);
}

IVP_U_Active_Mult::~IVP_U_Active_Mult()
{
    mod0->remove_dependency(this);
    mod1->remove_dependency(this);
	return;
}

void IVP_U_Active_Mult::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE new_val = mod0->give_double_value() * mod1->give_double_value();
    
    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Mult::print()
{
    printf("(");
    mod0->print();
    printf(")");

    printf(" * ");

    printf("(");
    mod1->print();
    printf(")");
    
    return 0; // f db
}

/**** FILTER **************************/
/**** FILTER **************************/
/**** FILTER **************************/

IVP_U_Active_Limit::IVP_U_Active_Limit(const char *i_name,
			 IVP_U_Active_Float *i_mod,
			 IVP_DOUBLE i_low_val,
			 IVP_DOUBLE i_high_val) : IVP_U_Active_Float(i_name)
{
    this->mod = i_mod;

    
    this->low_val = i_low_val;
    this->high_val = i_high_val;

    mod->add_dependency(this);

    this->active_float_changed((IVP_U_Active_Float *)this);
}

IVP_U_Active_Limit::~IVP_U_Active_Limit()
{
    mod->remove_dependency(this);
	return;
}

void IVP_U_Active_Limit::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == change_meter) return; // already valid
    last_update = change_meter;
    
    IVP_DOUBLE new_val = mod->give_double_value();
    if (new_val < low_val) new_val = low_val;
    if (new_val > high_val) new_val = high_val;
    
    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Limit::print()
{
    printf("Limit[%g, %g](", low_val, high_val);
    mod->print();
    printf(")");
    return 0; // for debugger
}

/********** LOGICS ****************/
/********** LOGICS ****************/
/********** LOGICS ****************/


IVP_U_Active_Test_Range::IVP_U_Active_Test_Range(const char *i_name,
			 IVP_U_Active_Float *i_mod_test,
			 IVP_U_Active_Float *i_mod_low_val,
			 IVP_U_Active_Float *i_mod_high_val ) : IVP_U_Active_Int(i_name)
{

    this->mod_test = i_mod_test;
    
    this->mod_low_val = i_mod_low_val;
    
    this->mod_high_val = i_mod_high_val;
    
    mod_test->add_dependency(this);
    mod_low_val->add_dependency(this);
    mod_high_val->add_dependency(this);

    this->active_float_changed((IVP_U_Active_Float *)this);
}

IVP_U_Active_Test_Range::~IVP_U_Active_Test_Range()
{
    mod_test->remove_dependency(this);
    mod_low_val->remove_dependency(this);
    mod_high_val->remove_dependency(this);
	return;
}

void IVP_U_Active_Test_Range::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == IVP_U_Active_Float::change_meter) return; // already valid
    last_update = IVP_U_Active_Float::change_meter;

    IVP_DOUBLE cmp_val = mod_test->give_double_value();
    IVP_DOUBLE low_val = mod_low_val->give_double_value();
    IVP_DOUBLE high_val = mod_high_val->give_double_value();
    int new_val = ((cmp_val>=low_val)&&(cmp_val<=high_val)) ? 1 : 0;
    if(new_val != this->int_value){
	this->int_value = new_val;
	this->update_derived();
    }
}

int IVP_U_Active_Test_Range::print()
{
    printf("TestRange[");
    mod_low_val->print();
    printf(", ");
    mod_high_val->print();
    printf("](");
    mod_test->print();
    printf(")");
    return 0; // fdb
}

////////////////
    
IVP_U_Active_Switch::IVP_U_Active_Switch(const char *i_name,
		       IVP_U_Active_Int *i_mod_cond,
		       IVP_U_Active_Float *i_mod_true,
		       IVP_U_Active_Float *i_mod_false ) : IVP_U_Active_Float(i_name)
{
    this->mod_cond = i_mod_cond;
    
    this->mod_true = i_mod_true;    
    this->mod_false = i_mod_false;
    
    mod_cond->add_dependency(this);
    mod_true->add_dependency(this);
    mod_false->add_dependency(this);

    this->active_float_changed(this);
}

IVP_U_Active_Switch::~IVP_U_Active_Switch()
{
    mod_cond->remove_dependency(this);
    mod_true->remove_dependency(this);
    mod_false->remove_dependency(this);
	return;
}

void IVP_U_Active_Switch::active_float_changed(IVP_U_Active_Float *)
{
    if(last_update == IVP_U_Active_Float::change_meter) return; // already valid
    last_update = IVP_U_Active_Float::change_meter;

    IVP_DOUBLE new_val;
    IVP_DOUBLE cond_val = mod_cond->give_int_value();
    if(cond_val){
	new_val = mod_true->give_double_value();
    }else{
	new_val = mod_false->give_double_value();
    }

    if(new_val != this->double_value){
	this->double_value = new_val;
	this->update_derived();
    }
}

void IVP_U_Active_Switch::active_int_changed(IVP_U_Active_Int *){
    active_float_changed(NULL);

}

int IVP_U_Active_Switch::print()
{
    printf("Cond[");
    mod_true->print();
    printf(", ");
    mod_false->print();
    printf("](");
    mod_cond->print();
    printf(")");
    return 0; // fdb
}



⌨️ 快捷键说明

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