Skip to content

Commit

Permalink
ET units / Lighting gun improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Apr 24, 2024
1 parent 125a368 commit 9397701
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 129 deletions.
48 changes: 30 additions & 18 deletions Source/Render/src/lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@

LightingParameters::LightingParameters()
{
generate_time=0.1f;
generate_time=0.100f; //How often generate new pattern
texture_name="RESOURCE\\Effect\\freeze.tga";
strip_width_begin=5;
strip_width_time=15;
strip_length=40;
fade_time=0.5f;
lighting_amplitude=40;
strip_width_begin=2.5f;
strip_width_time=5.0f;
strip_length=30.0f; //How long each segment will be
fade_time=0.150f;
min_amplitude=4.0f; //The min width that the arc pattern will have from the line center
max_amplitude=8.0f; //The max width that the arc pattern will have from the line center
}

cLighting::cLighting()
:cIUnkClass(0)
{
time=0;
scaler=1.0f;
pTexture=GetTexLibrary()->GetElement(param.texture_name.c_str());
}

Expand Down Expand Up @@ -61,7 +63,7 @@ void cLighting::Draw(cCamera *pCamera)
void cLighting::OneLight::Draw(cCamera *pCamera,cLighting* parent)
{
/*
sColor4c color(255,255,255);
sColor4c color(255,255,255, 255);
for(int i=1;i<position.size();i++)
{
Vect3f& n0=position[i-1];
Expand Down Expand Up @@ -117,7 +119,9 @@ void cLighting::OneLight::Draw(cCamera *pCamera,cLighting* parent)
gb_RenderDevice->SetWorldMat4f(nullptr);
DrawBuffer* db = gb_RenderDevice->GetDrawBuffer(sVertexXYZDT1::fmt, PT_TRIANGLESTRIP);

float size=parent->param.strip_width_begin+time*parent->param.strip_width_time;
float scale = max(1.0f, parent->scaler * 0.5f);
float size = parent->param.strip_width_begin * scale;
size += time * parent->param.strip_width_time * scale;
sVertexXYZDT1 *vb = db->LockTriangleStripSteps<sVertexXYZDT1>(strip_list.size());
for (size_t i = 0; i < strip_list.size(); ++i) {
const OneStrip& p = strip_list[i];
Expand Down Expand Up @@ -161,11 +165,12 @@ void cLighting::Animate(float dt)
}
}

void cLighting::Init(Vect3f pos_begin_, std::vector<Vect3f>& pos_end_)
void cLighting::Init(Vect3f pos_begin_, std::vector<Vect3f>& pos_end_, float scaler_)
{
global_pos.set(Mat3f::ID,pos_begin);
pos_begin=pos_begin_;
pos_end=pos_end_;
scaler=scaler_;
xassert(!pos_end.empty());
}

Expand Down Expand Up @@ -203,12 +208,13 @@ void cLighting::OneLight::Generate(Vect3f pos_begin_,Vect3f pos_end_,cCamera *pC
std::vector<float> pos(size+2);
pos[0]=pos[pos.size()-1]=0;

float amplitude=parent->param.lighting_amplitude;
for(int i=2;i<=size;i*=2)
{
GenerateInterpolate(pos,i,amplitude);
amplitude*=0.5f;
}
float min_amp=parent->param.min_amplitude * parent->scaler;
float max_amp=min(min_amp * parent->scaler, parent->param.max_amplitude);
for(int i=2;i<=size;i*=2) {
GenerateInterpolate(pos,i,min_amp,max_amp);
min_amp *= 0.5f;
max_amp *= 0.75f;
}

Vect3f tangent=pos_end-pos_begin;
tangent.Normalize();
Expand All @@ -231,14 +237,20 @@ void cLighting::OneLight::Generate(Vect3f pos_begin_,Vect3f pos_end_,cCamera *pC
BuildStrip(pCamera,parent);
}

void cLighting::OneLight::GenerateInterpolate(std::vector<float>& pos,int size,float amplitude)
void cLighting::OneLight::GenerateInterpolate(std::vector<float>& pos,int size,float min_amp, float max_amp)
{

RandomGenerator& r=xm_random_generator;
std::vector<float> p(size);\
int i;
for(i=0;i<size;i++)
p[i]=r.frnd(amplitude);
for (i=0;i<size;i++) {
float a = r.frnd(max_amp);
if (a < 0) {
p[i] = min(-min_amp, a);
} else {
p[i] = max(min_amp, a);
}
}

for(i=1;i<pos.size()-1;i++)
{
Expand Down
8 changes: 5 additions & 3 deletions Source/Render/src/lighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ struct LightingParameters
float strip_width_time;
float strip_length;
float fade_time;
float lighting_amplitude;
float min_amplitude;
float max_amplitude;
LightingParameters();
};

Expand All @@ -17,7 +18,7 @@ class cLighting:public cIUnkClass
public:
cLighting();
~cLighting();
void Init(Vect3f pos_begin, std::vector<Vect3f>& pos_end);
void Init(Vect3f pos_begin, std::vector<Vect3f>& pos_end,float scaler);
void SetParameters(LightingParameters& param_);

virtual void PreDraw(cCamera *UCamera);
Expand All @@ -31,6 +32,7 @@ class cLighting:public cIUnkClass
protected:
void Generate(Vect3f pos_begin,Vect3f pos_end,cCamera *pCamera);
float time;
float scaler;
MatXf global_pos;
Vect3f pos_begin;
std::vector<Vect3f> pos_end;
Expand All @@ -56,7 +58,7 @@ class cLighting:public cIUnkClass
void Generate(Vect3f pos_begin,Vect3f pos_end,cCamera *pCamera,cLighting* parent);
void Draw(cCamera *pCamera,cLighting* parent);
void Animate(float dt);
void GenerateInterpolate(std::vector<float>& pos,int size,float amplitude);
void GenerateInterpolate(std::vector<float>& pos,int size,float min_amp, float max_amp);
float get(std::vector<float>& p,float t);

void BuildStrip(cCamera *pCamera,cLighting* parent);
Expand Down
14 changes: 11 additions & 3 deletions Source/Units/IronLegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ void terUnitLegionary::AvatarQuant()

avatar()->Show();
realAvatar()->setSight(SightFactor);
realAvatar()->setHeal(HealFactor);
realAvatar()->setFreeze(FreezeFactor);
realAvatar()->setHot(HotFactor);

float maxFactor = 1.0f;
//Conductors have electro effect in mesh that becomes red when hot, mitigate this
const AttributeLegionary* attrs = attr();
if (attrs && attrs->ID == UNIT_ATTRIBUTE_CONDUCTOR) {
maxFactor = 0.5f;
}

realAvatar()->setHeal(min(HealFactor, maxFactor));
realAvatar()->setFreeze(min(FreezeFactor, maxFactor));
realAvatar()->setHot(min(HotFactor, maxFactor));

if(MoveSoundPoint){
MoveSoundPoint->setVolume(SpeedFactor);
Expand Down
20 changes: 13 additions & 7 deletions Source/Units/RealUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ void terUnitReal::Quant()
if(HotCount > 0){
HotCount--;
HotFactor = 1.0f;
}
else
average(HotFactor,0, 0.3f);
} else {
average(HotFactor, 0, 0.3f);
}

if(weapon_)
weapon_->quant();
Expand Down Expand Up @@ -933,8 +933,13 @@ bool terUnitReal::fireRequest(const Vect3f* targetPosition, terUnitBase* targetU
buf < "G ";
if(fire_status & LEGION_FIRE_STATUS_FRIENDLY_FIRE)
buf < "ff ";
if(fire_status & LEGION_FIRE_STATUS_RELOAD_AMMO)
buf < "R ";
if(fire_status & LEGION_FIRE_STATUS_RELOAD_AMMO) {
if (weapon_->isLoaded()) {
buf < "Rl ";
} else {
buf < "R ";
}
}
if(fire_status & LEGION_FIRE_STATUS_DISTANCE)
buf < "D ";
if(fire_status & LEGION_FIRE_STATUS_FIELD_OBSTACLE)
Expand Down Expand Up @@ -1223,8 +1228,9 @@ void terUnitReal::freeZeroLayer()
void terUnitReal::handleLaserHit()
{
terEffectControllerList::iterator it = find(effectControllers_.begin(),effectControllers_.end(),EFFECT_ID_LASER_HIT);
if(it != effectControllers_.end())
it->createEffect(this);
if (it != effectControllers_.end()) {
it->createEffect(this);
}
}

void terUnitReal::fireStop()
Expand Down
Loading

0 comments on commit 9397701

Please sign in to comment.