Damage Flash + Blackout = Timed ColorOut
by DALO · 06/23/2008 (7:26 am) · 2 comments
Step 0: BACK UP YOU FILES BEFORE YOU TRY THIS, JUST IN CASE.........
============================================================
============================================================
Step 1: gameConnection.h
============================================================
============================================================
// add these in the class anywhere under public:
// timer stuff for colors
F32 mColorOut;
S32 mColorOutTimeMS;
S32 mColorOutStartTimeMS;
bool mFadeToColor;
// colors
F32 mColorOutRed;
F32 mColorOutGreen;
F32 mColorOutBlue;
// functions
F32 getColorOut(){ return mColorOut;}
void setColorOut(F32 red, F32 green, F32 blue, bool fadeToBlack, S32 timeMS);
F32 getColorOutRed(){ return mColorOutRed; }
F32 getColorOutGreen(){ return mColorOutGreen; }
F32 getColorOutBlue(){ return mColorOutBlue; }
Step 2: gameConnection.cc
============================================================
============================================================
Add this in the GameConnection::GameConnection() constructor
============================================================
//colorout timer variables
mColorOut = 0.0;
mColorOutTimeMS = 0;
mColorOutStartTimeMS = 0;
mFadeToColor = false;
// the colors
mColorOutRed = 0.0;
mColorOutGreen = 0.0;
mColorOutBlue = 0.0;
Find GameConnection::readPacket function
============================================================
// look for:
mDamageFlash = 0;
mWhiteOut = 0;
// and add underneath:
mColorOut = mColorOutRed = mColorOutGreen = mColorOutBlue = 0;
// then under:
if(bstream->readFlag())
mWhiteOut = bstream->readFloat(7) * 1.5;
// add
if(bstream->readFlag())
mColorOut = bstream->readFloat(7);
if(bstream->readFlag())
mColorOutRed = bstream->readFloat(7);
if(bstream->readFlag())
mColorOutGreen = bstream->readFloat(7);
if(bstream->readFlag())
mColorOutBlue = bstream->readFloat(7);
Find GameConnection::writePacket function
============================================================
//look for:
F32 whiteOut = mControlObject->getWhiteOut();
// and add underneath:
F32 colorOut = mControlObject->getColorOut();
F32 colorRed = mControlObject->getColorOutRed();
F32 colorGreen = mControlObject->getColorOutGreen();
F32 colorBlue = mControlObject->getColorOutBlue();
// change
if(bstream->writeFlag(flash != 0 || whiteOut != 0))
// to this
if(bstream->writeFlag(flash != 0 || colorOut != 0 || whiteOut != 0))
// then under:
if(bstream->writeFlag(whiteOut != 0))
bstream->writeFloat(whiteOut/1.5, 7);
// add
if(bstream->writeFlag(colorOut != 0))
bstream->writeFloat(colorOut, 7);
if(bstream->writeFlag(colorRed != 0))
bstream->writeFloat(colorRed, 7);
if(bstream->writeFlag(colorGreen != 0))
bstream->writeFloat(colorGreen, 7);
if(bstream->writeFlag(colorBlue != 0))
bstream->writeFloat(colorBlue, 7);
Step 3: shapeBase.h
============================================================
============================================================
// add these in the class anywhere under protected
F32 mColorOutRed;
F32 mColorOutGreen;
F32 mColorOutBlue;
F32 mColorOut;
S32 mColorOutTimeMS;
S32 mColorOutStartTimeMS;
bool mFadeToColor;
// find
virtual F32 getDamageFlash() const;
// and add underneath:
virtual F32 getColorOutRed() const;
virtual F32 getColorOutGreen() const;
virtual F32 getColorOutBlue() const;
virtual void setColorOut(const F32 red, const F32 green, const F32 blue, bool fack, S32 me);
virtual F32 getColorOut();
Step 4: shapeBase.cc
============================================================
============================================================
Add this in the ShapeBase::ShapeBase() constructor *not* the ShapeBaseData::ShapeBaseData()
============================================================
mDamageFlash = 0.0;
mWhiteOut = 0.0;
mColorOut = 0.0;
mFadeToColor = false;
mColorOutRed = 0.0;
mColorOutGreen = 0.0;
mColorOutBlue = 0.0;
mColorOut = 0.0;
mColorOutTimeMS = 0;
mColorOutStartTimeMS = 0;
Find this function: F32 ShapeBase::getDamageFlash() const
============================================================
// and add these functions below it:
//--------------------------------------
void ShapeBase::setColorOut(const F32 red, const F32 green, const F32 blue, bool fadeToColor, S32 timeMS){
this->mColorOutRed = red;
if(this->mColorOutRed > 1.f)
this->mColorOutRed = 1.0;
if(this->mColorOutRed < 0)
this->mColorOutRed = 0;
this->mColorOutGreen = green;
if(this->mColorOutGreen > 1.f)
this->mColorOutGreen = 1.0;
if(this->mColorOutGreen < 0)
this->mColorOutGreen = 0;
this->mColorOutBlue = blue;
if(this->mColorOutBlue > 1.f)
this->mColorOutBlue = 1.0;
if(this->mColorOutBlue < 0)
this->mColorOutBlue = 0;
this->mFadeToColor = fadeToColor;
this->mColorOutStartTimeMS = Sim::getCurrentTime();
this->mColorOutTimeMS = timeMS;
//if timeMS <= 0 set the value instantly
if (this->mColorOutTimeMS <= 0){
this->mColorOut = (this->mFadeToColor ? 1.0f : 0.0f);
}
}
//--------------------------------------
F32 ShapeBase::getColorOut() {
S32 curTime = Sim::getCurrentTime();
//see if we're in the middle of a Color out
if (curTime < this->mColorOutStartTimeMS + this->mColorOutTimeMS){
S32 elapsedTime = curTime - this->mColorOutStartTimeMS;
F32 timePercent = F32(elapsedTime) / F32(this->mColorOutTimeMS);
this->mColorOut = (this->mFadeToColor ? timePercent : 1.0f - timePercent);
}
else
this->mColorOut = (this->mFadeToColor ? 1.0f : 0.0f);
//return the Colorout time
return this->mColorOut;
}
//--------------------------------------
F32 ShapeBase::getColorOutRed() const{
return mColorOutRed;
}
F32 ShapeBase::getColorOutGreen() const{
return mColorOutGreen;
}
F32 ShapeBase::getColorOutBlue() const{
return mColorOutBlue;
}
// next we need the console function, this is how the scripts are going to start the effect
// so somewhere amongst the console functions, place this in there
//=====================================================================================
ConsoleMethod( ShapeBase, setColorOut, void, 4, 7, "(bool doFade, int timeMS)"){
object->setColorOut(dAtof(argv[2]), dAtof(argv[3]), dAtof(argv[4]), dAtob(argv[5]), dAtoi(argv[6]));
return;
}
Step 5: game.cc
============================================================
============================================================
// find this function: void GameRenderFilters and then look for:
F32 blackOut = 0.0f;
// add underneath
F32 colorOut = 0.0f;
// find
blackOut = connection->getBlackOut();
// add underneath
colorOut = connection->getColorOut();
// you should then see this:
ShapeBase* psb = dynamic_cast(camq.object);
if (psb != NULL) {
// add this underneath
if (colorOut > 0.0f) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(connection->getColorOutRed(), connection->getColorOutGreen(), connection->getColorOutBlue(), (colorOut > 1.0f ? 1.0f : colorOut));
glBegin(GL_TRIANGLE_FAN);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glDisable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
// below you should see this:
if (damageFlash > 0.0f) {
....
....
}
Step 6: the scripts.......
============================================================
============================================================
// anywhere in the script, server side, you can simply have your bot/player call
// the effect like this:
%obj.setColorOut(0.7, 0.7, 1.0, false, 1000);
// %obj is my player
// the first 3 parameters are the colors
// the false is for full blown color fading out true if you want color to fade in
// the 1000 is time in milliseconds
Step 7: a maybe......?
============================================================
============================================================
I'm not sure if these are needed or not but I added them:
in gameTSCtrl.cc find: GameTSCtrl::onRender(....)
============================================================
// and change this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f);
// to this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f) || (con->getColorOut() >= 1.f);
// and if you have AFX
in afxTSCtrl.cc find: afxTSCtrl::onRender(....)
============================================================
// and change this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f);
// to this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f) || (con->getColorOut() >= 1.f);
Step 8: recompile and test.......
============================================================
============================================================
// done
Here's a video to show the effect, once the player walks into the portal warp the effect occurs.....
Right Click and save as to download
============================================================
============================================================
Step 1: gameConnection.h
============================================================
============================================================
// add these in the class anywhere under public:
// timer stuff for colors
F32 mColorOut;
S32 mColorOutTimeMS;
S32 mColorOutStartTimeMS;
bool mFadeToColor;
// colors
F32 mColorOutRed;
F32 mColorOutGreen;
F32 mColorOutBlue;
// functions
F32 getColorOut(){ return mColorOut;}
void setColorOut(F32 red, F32 green, F32 blue, bool fadeToBlack, S32 timeMS);
F32 getColorOutRed(){ return mColorOutRed; }
F32 getColorOutGreen(){ return mColorOutGreen; }
F32 getColorOutBlue(){ return mColorOutBlue; }
Step 2: gameConnection.cc
============================================================
============================================================
Add this in the GameConnection::GameConnection() constructor
============================================================
//colorout timer variables
mColorOut = 0.0;
mColorOutTimeMS = 0;
mColorOutStartTimeMS = 0;
mFadeToColor = false;
// the colors
mColorOutRed = 0.0;
mColorOutGreen = 0.0;
mColorOutBlue = 0.0;
Find GameConnection::readPacket function
============================================================
// look for:
mDamageFlash = 0;
mWhiteOut = 0;
// and add underneath:
mColorOut = mColorOutRed = mColorOutGreen = mColorOutBlue = 0;
// then under:
if(bstream->readFlag())
mWhiteOut = bstream->readFloat(7) * 1.5;
// add
if(bstream->readFlag())
mColorOut = bstream->readFloat(7);
if(bstream->readFlag())
mColorOutRed = bstream->readFloat(7);
if(bstream->readFlag())
mColorOutGreen = bstream->readFloat(7);
if(bstream->readFlag())
mColorOutBlue = bstream->readFloat(7);
Find GameConnection::writePacket function
============================================================
//look for:
F32 whiteOut = mControlObject->getWhiteOut();
// and add underneath:
F32 colorOut = mControlObject->getColorOut();
F32 colorRed = mControlObject->getColorOutRed();
F32 colorGreen = mControlObject->getColorOutGreen();
F32 colorBlue = mControlObject->getColorOutBlue();
// change
if(bstream->writeFlag(flash != 0 || whiteOut != 0))
// to this
if(bstream->writeFlag(flash != 0 || colorOut != 0 || whiteOut != 0))
// then under:
if(bstream->writeFlag(whiteOut != 0))
bstream->writeFloat(whiteOut/1.5, 7);
// add
if(bstream->writeFlag(colorOut != 0))
bstream->writeFloat(colorOut, 7);
if(bstream->writeFlag(colorRed != 0))
bstream->writeFloat(colorRed, 7);
if(bstream->writeFlag(colorGreen != 0))
bstream->writeFloat(colorGreen, 7);
if(bstream->writeFlag(colorBlue != 0))
bstream->writeFloat(colorBlue, 7);
Step 3: shapeBase.h
============================================================
============================================================
// add these in the class anywhere under protected
F32 mColorOutRed;
F32 mColorOutGreen;
F32 mColorOutBlue;
F32 mColorOut;
S32 mColorOutTimeMS;
S32 mColorOutStartTimeMS;
bool mFadeToColor;
// find
virtual F32 getDamageFlash() const;
// and add underneath:
virtual F32 getColorOutRed() const;
virtual F32 getColorOutGreen() const;
virtual F32 getColorOutBlue() const;
virtual void setColorOut(const F32 red, const F32 green, const F32 blue, bool fack, S32 me);
virtual F32 getColorOut();
Step 4: shapeBase.cc
============================================================
============================================================
Add this in the ShapeBase::ShapeBase() constructor *not* the ShapeBaseData::ShapeBaseData()
============================================================
mDamageFlash = 0.0;
mWhiteOut = 0.0;
mColorOut = 0.0;
mFadeToColor = false;
mColorOutRed = 0.0;
mColorOutGreen = 0.0;
mColorOutBlue = 0.0;
mColorOut = 0.0;
mColorOutTimeMS = 0;
mColorOutStartTimeMS = 0;
Find this function: F32 ShapeBase::getDamageFlash() const
============================================================
// and add these functions below it:
//--------------------------------------
void ShapeBase::setColorOut(const F32 red, const F32 green, const F32 blue, bool fadeToColor, S32 timeMS){
this->mColorOutRed = red;
if(this->mColorOutRed > 1.f)
this->mColorOutRed = 1.0;
if(this->mColorOutRed < 0)
this->mColorOutRed = 0;
this->mColorOutGreen = green;
if(this->mColorOutGreen > 1.f)
this->mColorOutGreen = 1.0;
if(this->mColorOutGreen < 0)
this->mColorOutGreen = 0;
this->mColorOutBlue = blue;
if(this->mColorOutBlue > 1.f)
this->mColorOutBlue = 1.0;
if(this->mColorOutBlue < 0)
this->mColorOutBlue = 0;
this->mFadeToColor = fadeToColor;
this->mColorOutStartTimeMS = Sim::getCurrentTime();
this->mColorOutTimeMS = timeMS;
//if timeMS <= 0 set the value instantly
if (this->mColorOutTimeMS <= 0){
this->mColorOut = (this->mFadeToColor ? 1.0f : 0.0f);
}
}
//--------------------------------------
F32 ShapeBase::getColorOut() {
S32 curTime = Sim::getCurrentTime();
//see if we're in the middle of a Color out
if (curTime < this->mColorOutStartTimeMS + this->mColorOutTimeMS){
S32 elapsedTime = curTime - this->mColorOutStartTimeMS;
F32 timePercent = F32(elapsedTime) / F32(this->mColorOutTimeMS);
this->mColorOut = (this->mFadeToColor ? timePercent : 1.0f - timePercent);
}
else
this->mColorOut = (this->mFadeToColor ? 1.0f : 0.0f);
//return the Colorout time
return this->mColorOut;
}
//--------------------------------------
F32 ShapeBase::getColorOutRed() const{
return mColorOutRed;
}
F32 ShapeBase::getColorOutGreen() const{
return mColorOutGreen;
}
F32 ShapeBase::getColorOutBlue() const{
return mColorOutBlue;
}
// next we need the console function, this is how the scripts are going to start the effect
// so somewhere amongst the console functions, place this in there
//=====================================================================================
ConsoleMethod( ShapeBase, setColorOut, void, 4, 7, "(bool doFade, int timeMS)"){
object->setColorOut(dAtof(argv[2]), dAtof(argv[3]), dAtof(argv[4]), dAtob(argv[5]), dAtoi(argv[6]));
return;
}
Step 5: game.cc
============================================================
============================================================
// find this function: void GameRenderFilters and then look for:
F32 blackOut = 0.0f;
// add underneath
F32 colorOut = 0.0f;
// find
blackOut = connection->getBlackOut();
// add underneath
colorOut = connection->getColorOut();
// you should then see this:
ShapeBase* psb = dynamic_cast
if (psb != NULL) {
// add this underneath
if (colorOut > 0.0f) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(connection->getColorOutRed(), connection->getColorOutGreen(), connection->getColorOutBlue(), (colorOut > 1.0f ? 1.0f : colorOut));
glBegin(GL_TRIANGLE_FAN);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glDisable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
// below you should see this:
if (damageFlash > 0.0f) {
....
....
}
Step 6: the scripts.......
============================================================
============================================================
// anywhere in the script, server side, you can simply have your bot/player call
// the effect like this:
%obj.setColorOut(0.7, 0.7, 1.0, false, 1000);
// %obj is my player
// the first 3 parameters are the colors
// the false is for full blown color fading out true if you want color to fade in
// the 1000 is time in milliseconds
Step 7: a maybe......?
============================================================
============================================================
I'm not sure if these are needed or not but I added them:
in gameTSCtrl.cc find: GameTSCtrl::onRender(....)
============================================================
// and change this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f);
// to this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f) || (con->getColorOut() >= 1.f);
// and if you have AFX
in afxTSCtrl.cc find: afxTSCtrl::onRender(....)
============================================================
// and change this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f);
// to this:
bool skipRender = !con || (con->getWhiteOut() >= 1.f) || (con->getDamageFlash() >= 1.f) || (con->getBlackOut() >= 1.f) || (con->getColorOut() >= 1.f);
Step 8: recompile and test.......
============================================================
============================================================
// done
Here's a video to show the effect, once the player walks into the portal warp the effect occurs.....
Right Click and save as to download
About the author
#2
Hey Dalo did you get everything working from my resource? Sorry I haven't been around much to answer you back.
06/23/2008 (3:19 pm)
hehe nice!Hey Dalo did you get everything working from my resource? Sorry I haven't been around much to answer you back.

Torque Owner Nathan Kent