added everything

This commit is contained in:
Metario
2017-04-17 06:17:10 -06:00
commit 9c6ff74f19
6121 changed files with 1625704 additions and 0 deletions

View File

@ -0,0 +1,192 @@
#include "gui/shiny/guiEffectCanvas.h"
#include "dgl/dgl.h"
#include "util/safeDelete.h"
IMPLEMENT_CONOBJECT(GuiEffectCanvas);
//------------------------------------------------------------------------------
// An effect
namespace EffectCanvasEffects
{
void FN_CDECL spiralInitFn( const int x, const int y, const Point2I &resolution,
const F32 maxX, const F32 maxY, Point2F *outVec )
{
outVec->x += 0.01;
//outVec->x -= 0.5f;
//outVec->y -= 0.5f;
//F32 d = mSqrt( ( x - resolution.x / 2.f ) * ( x - resolution.x / 2.f ) +
// ( y - resolution.y / 2.f ) * ( y - resolution.y / 2.f ) );
//F32 c = mCos( d * M_PI / 64.f ) * 0.5f;
//F32 s = mSin( d * M_PI / 64.f ) * 0.5f;
//outVec->x = c * outVec->x - s * outVec->y;
//outVec->y = s * outVec->x + c * outVec->y;
//outVec->x += 0.5f;
//outVec->y += 0.5f;
}
};
//------------------------------------------------------------------------------
ConsoleFunction( createEffectCanvas, bool, 2, 2, "(string windowTitle)"
"Create the game window/canvas, with the specified window title.")
{
AssertISV(!Canvas, "createEffectCanvas: canvas has already been instantiated");
#if !defined(TORQUE_OS_MAC) // macs can only run one instance in general.
#if !defined(TORQUE_DEBUG) && !defined(INTERNAL_RELEASE)
if(!Platform::excludeOtherInstances("TorqueTest"))
return false;
#endif
#endif
Platform::initWindow(Point2I(800, 600), argv[1]);
// create the canvas, and add it to the manager
Canvas = new GuiEffectCanvas();
Canvas->registerObject("Canvas"); // automatically adds to GuiGroup
return true;
}
//------------------------------------------------------------------------------
GuiEffectCanvas::GuiEffectCanvas()
{
mStartEffect = false;
mEffectInProgress = false;
mVisualizeField = false;
mUpdateFeedbackTexture = false;
mVectorField = new VectorField( Point2I( 16, 12 ) );
mClearColor.set( 1.f, 0.f, 0.f, 1.0f );
mLastSize = mBounds.extent;
}
//------------------------------------------------------------------------------
GuiEffectCanvas::~GuiEffectCanvas()
{
SAFE_DELETE( mVectorField );
}
//------------------------------------------------------------------------------
void GuiEffectCanvas::renderFrame( bool preRenderOnly, bool bufferSwap /* = true */ )
{
// With this canvas, always re-draw the whole thing if an effect is in progress
if( mEffectInProgress )
{
resetUpdateRegions();
}
// Render normally.
Parent::renderFrame( preRenderOnly, false );
// Check for resize (renderFrame does this)
if( Platform::getWindowSize() != mLastSize )
{
canvasResized();
mLastSize = Platform::getWindowSize();
}
// Check to see if the effect should be started
if( mStartEffect )
{
// Sweet, don't do this again until next time
mStartEffect = false;
// Grab the frame
mFeedbackTexture.update();
// And we are in business!
mEffectInProgress = true;
}
// Check to see if we are going
if( mEffectInProgress )
{
// Do some vooodooo!
glDisable( GL_LIGHTING );
glEnable( GL_TEXTURE_2D );
glEnable( GL_BLEND );
// Bind the feedback texture
glBindTexture( GL_TEXTURE_2D, mFeedbackTexture.getTextureHandle().getGLName() );
// Set up some tex parameters
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, (F32 *)&mClearColor );
// Set up the blend parameters
glBlendColorEXT( mClearColor.red, mClearColor.green, mClearColor.blue, mClearColor.alpha );
glBlendFunc( GL_CONSTANT_COLOR_EXT, GL_ZERO );
glGetFloatv( GL_BLEND_COLOR_EXT, (F32 *)&mClearColor );
// Render the current field
mVectorField->renderField( true );
glDisable( GL_TEXTURE_2D );
}
// Check to see if we should update the feedback texture
if( mUpdateFeedbackTexture )
{
mFeedbackTexture.update();
mUpdateFeedbackTexture = false;
}
// Debug visualization
if( mVisualizeField )
mVectorField->visualizeField();
// Now swap the buffers
swapBuffers();
}
//------------------------------------------------------------------------------
void GuiEffectCanvas::processTick()
{
if( mEffectInProgress )
{
// Check to see if we are done
if( mEffectTickCount++ > 100 )
mEffectInProgress = false;
else
mUpdateFeedbackTexture = true;
}
}
//------------------------------------------------------------------------------
void GuiEffectCanvas::canvasResized()
{
// Do NOT call parent here
mFeedbackTexture.setUpdateRect( mBounds );
TextureObject *obj = (TextureObject *)mFeedbackTexture.getTextureHandle();
F32 maxX = F32(obj->bitmapWidth) / F32(obj->texWidth);
F32 maxY = F32(obj->bitmapHeight) / F32(obj->texHeight);
mVectorField->initVectorField( maxX, maxY, VectorField::Flip_None, &EffectCanvasEffects::spiralInitFn );
}
//------------------------------------------------------------------------------
void GuiEffectCanvas::setContentControl(GuiControl *gui)
{
Parent::setContentControl( gui );
//mStartEffect = true;
mEffectTickCount = 0;
}
//------------------------------------------------------------------------------

View File

@ -0,0 +1,49 @@
#ifndef _GUIEFFECTCANVAS_H_
#define _GUIEFFECTCANVAS_H_
#include "gui/core/guiCanvas.h"
#include "core/iTickable.h"
#include "dgl/gVectorField.h"
#include "dgl/gDynamicTexture.h"
class GuiEffectCanvas : public GuiCanvas, public virtual ITickable
{
typedef GuiCanvas Parent;
protected:
bool mEffectInProgress;
bool mVisualizeField;
bool mUpdateFeedbackTexture;
bool mStartEffect;
U32 mEffectTickCount;
VectorField *mVectorField;
DynamicTexture mFeedbackTexture;
ColorF mClearColor;
Point2I mLastSize;
public:
DECLARE_CONOBJECT(GuiEffectCanvas);
GuiEffectCanvas();
~GuiEffectCanvas();
// Change rendering to support the effects
virtual void renderFrame( bool preRenderOnly, bool bufferSwap = true );
// To adjust the vector field
virtual void canvasResized();
// This will start the effect!
virtual void setContentControl(GuiControl *gui);
// ITickable stuff
virtual void processTick();
virtual void interpolateTick( F32 delta ) {};
virtual void advanceTime( F32 timeDelta ) {};
};
#endif

120
engine/gui/shiny/guiTheoraCtrl.cc Executable file
View File

@ -0,0 +1,120 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#include "gui/core/guiControl.h"
#include "gui/shiny/guiTheoraCtrl.h"
#include "console/consoleTypes.h"
#include "dgl/dgl.h"
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiTheoraCtrl);
GuiTheoraCtrl::GuiTheoraCtrl()
{
mFilename = StringTable->insert("");
mDone = false;
mStopOnSleep = false;
mBackgroundColor.set(0,0,0);
}
//----------------------------------------------------------------------------
GuiTheoraCtrl::~GuiTheoraCtrl()
{
}
void GuiTheoraCtrl::initPersistFields()
{
Parent::initPersistFields();
addGroup("Playback");
addField("theoraFile", TypeFilename, Offset(mFilename, GuiTheoraCtrl));
addField("done", TypeBool, Offset(mDone, GuiTheoraCtrl));
addField("stopOnSleep", TypeBool, Offset(mStopOnSleep, GuiTheoraCtrl));
addField("backgroundColor", TypeColorI,Offset(mBackgroundColor, GuiTheoraCtrl));
endGroup("Playback");
}
ConsoleMethod( GuiTheoraCtrl, setFile, void, 3, 3, "(string filename) Set an Ogg Theora file to play.")
{
object->setFile(argv[2]);
}
ConsoleMethod( GuiTheoraCtrl, stop, void, 2, 2, "() Stop playback.")
{
object->stop();
}
ConsoleMethod( GuiTheoraCtrl, getCurrentTime, F32, 2, 2, "() Return the time elapsed in playback, in seconds.")
{
return object->getCurrentTime();
}
void GuiTheoraCtrl::setFile(const char* szFilename)
{
mDone = false;
if(szFilename && szFilename[0])
mTheoraTexture.setFile(szFilename, true);
}
void GuiTheoraCtrl::stop()
{
mTheoraTexture.stop();
mDone = true;
}
//----------------------------------------------------------------------------
bool GuiTheoraCtrl::onWake()
{
if (!Parent::onWake()) return false;
if(mTheoraTexture.isReady())
return true;
setFile(mFilename);
return true;
}
//----------------------------------------------------------------------------
void GuiTheoraCtrl::onSleep()
{
Parent::onSleep();
if(mStopOnSleep)
stop();
}
//----------------------------------------------------------------------------
void GuiTheoraCtrl::onRender(Point2I offset, const RectI &updateRect)
{
const RectI rect(offset, mBounds.extent);
if(mTheoraTexture.isReady() && mTheoraTexture.isPlaying())
{
mTheoraTexture.refresh();
dglClearBitmapModulation();
dglDrawBitmapStretch(mTheoraTexture, rect);
}
else
{
if(mTheoraTexture.isReady())
mDone = true;
dglDrawRectFill(rect, mBackgroundColor); // black rect
}
renderChildControls(offset, updateRect);
}
//----------------------------------------------------------------------------
void GuiTheoraCtrl::inspectPostApply()
{
stop();
setFile(mFilename);
}

View File

@ -0,0 +1,54 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _GUITHEORACTRL_H_
#define _GUITHEORACTRL_H_
#ifndef _THEORATEXTURE_H_
#include "core/theoraPlayer.h"
#endif
/// Play back a Theora video file.
class GuiTheoraCtrl : public GuiControl
{
private:
typedef GuiControl Parent;
protected:
const char* mFilename;
TheoraTexture mTheoraTexture;
public:
DECLARE_CONOBJECT(GuiTheoraCtrl);
GuiTheoraCtrl();
~GuiTheoraCtrl();
static void initPersistFields();
void inspectPostApply();
void setFile(const char *filename);
void stop();
/// If true, stop video playback when the control goes to sleep.
bool mStopOnSleep;
/// Are we done with playback?
bool mDone;
/// Our background color.
ColorI mBackgroundColor;
bool onWake();
void onSleep();
void onRender(Point2I offset, const RectI &updateRect);
F32 getCurrentTime()
{
return mTheoraTexture.getCurrentTime();
}
};
#endif

17
engine/gui/shiny/guiTickCtrl.cc Executable file
View File

@ -0,0 +1,17 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#include "gui/shiny/guiTickCtrl.h"
IMPLEMENT_CONOBJECT( GuiTickCtrl );
//------------------------------------------------------------------------------
ConsoleMethod( GuiTickCtrl, setProcessTicks, void, 2, 3, "( [tick = true] ) - This will set this object to either be processing ticks or not" )
{
if( argc == 3 )
object->setProcessTicks( dAtob( argv[2] ) );
else
object->setProcessTicks();
}

48
engine/gui/shiny/guiTickCtrl.h Executable file
View File

@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#ifndef _GUITICKCTRL_H_
#define _GUITICKCTRL_H_
#include "gui/core/guiControl.h"
#include "core/iTickable.h"
/// This Gui Control is designed to be subclassed and let people create controls
/// which want to recieve update ticks at a constant interval. This class was
/// created to be the Parent class of a control which used a DynamicTexture
/// along with a VectorField to create warping effects much like the ones found
/// in visualization displays for iTunes or Winamp. Those displays are updated
/// at the framerate frequency. This works fine for those effects, however for
/// an application of the same type of effects for things like Gui transitions
/// the framerate-driven update frequency is not desireable because it does not
/// allow the developer to be able to have any idea of a consistant user-experience.
///
/// Enter the ITickable interface. This lets the Gui control, in this case, update
/// the dynamic texture at a constant rate of once per tick, even though it gets
/// rendered every frame, thus creating a framerate-independant update frequency
/// so that the effects are at a consistant speed regardless of the specifics
/// of the system the user is on. This means that the screen-transitions will
/// occur in the same time on a machine getting 300fps in the Gui shell as a
/// machine which gets 150fps in the Gui shell.
/// @see ITickable
class GuiTickCtrl : public GuiControl, public virtual ITickable
{
typedef GuiControl Parent;
private:
protected:
// So this can be instantiated and not be a pure virtual class
virtual void interpolateTick( F32 delta ) {};
virtual void processTick() {};
virtual void advanceTime( F32 timeDelta ) {};
public:
DECLARE_CONOBJECT( GuiTickCtrl );
};
#endif