created fademanager + small updates

This commit is contained in:
turanszkij
2015-12-10 22:24:47 +01:00
parent 2b588d3cb4
commit 2f1cca7462
16 changed files with 226 additions and 32 deletions
+29 -6
View File
@@ -27,17 +27,18 @@ The documentation completion is still pending....
6. Ray
7. AABB
8. Emitter
8. Renderable Components
8. MainComponent
9. RenderableComponent
1. Renderable2DComponent
2. Renderable3DComponent
1. ForwardRenderableComponent
2. DeferredRenderableComponent
4. LoadingScreenComponent
9. Network
10. Network
1. Server
2. Client
10. Input Handling
11. ResourceManager
11. Input Handling
12. ResourceManager
## Introduction and usage
Scripting in Wicked Engine is powered by Lua, meaning that the user can make use of the
@@ -320,7 +321,21 @@ Emitter particlesystem.
- Burst(float amount)
- IsValid() : bool value
### Renderable Components
### MainComponent
The main component which holds information and manages the running of the current program.
- [outer]main : MainComponent
- [void-constructor]MainComponent()
- GetContent() : Resource? result
- GetActiveComponent() : RenderableComponent? result
- SetActiveComponent(RenderableComponent component, opt int fadeFrames,fadeColorR,fadeColorG)
- SetFrameSkip(bool enabled)
- SetInfoDisplay(bool active)
- SetWatermarkDisplay(bool active)
- SetFPSDisplay(bool active)
- SetCPUDisplay(bool active)
- SetColorGradePaletteDisplay(bool active)
### RenderableComponent
A RenderableComponent describes a scene wich can render itself.
- [constructor]RenderableComponent()
- GetContent() : Resource result
@@ -351,7 +366,8 @@ It can hold Sprites and Fonts and can sort them by layers, update and render the
- SetFontOrder(Font font, int order)
#### Renderable3DComponent
A 3D scene can either be rendered by a Forward or Deferred render path.
A 3D scene can either be rendered by a Forward or Deferred render path.
It inherits functions from Renderable2DComponent, so it can render a 2D overlay.
- [void-constructor]Renderable3DComponent()
- SetSSAOEnabled(bool value)
- SetSSREnabled(bool value)
@@ -376,26 +392,32 @@ A 3D scene can either be rendered by a Forward or Deferred render path.
##### ForwardRenderableComponent
It renders the scene contained by the Renderer in a forward render path. The component does not hold the scene information,
only the effects to render the scene. The scene is managed and ultimately rendered by the Renderer.
It inherits functions from Renderable3DComponent.
- [constructor]ForwardRenderableComponent()
##### DeferredRenderableComponent
It renders the scene contained by the Renderer in a deferred render path. The component does not hold the scene information,
only the effects to render the scene. The scene is managed and ultimately rendered by the Renderer.
It inherits functions from Renderable3DComponent.
- [constructor]DeferredRenderableComponent()
#### LoadingScreenComponent
It is a Renderable2DComponent but one that internally manages resource loading and can display information about the process.
It inherits functions from Renderable2DComponent.
- [constructor]LoadingScreenComponent()
- AddLoadingComponent(RenderableComponent component)
### Network
Here are the network communication features.
- TODO
#### Server
A TCP host to which clients can connect and communicate with each other or the server.
- TODO
#### Client
A TCP client which provides features to communicate with other clients over the internet or local area network connection.
- TODO
### Input Handling
These provide functions to check the state of the input devices.
@@ -428,6 +450,7 @@ These provide functions to check the state of the input devices.
### ResourceManager
Stores and manages resources such as textures, sounds and shaders.
- [outer]globalResources : Resource
- [void-constructor]Resource()
- Get(string name)
- Add(string name)
+42 -4
View File
@@ -23,6 +23,9 @@ MainComponent::MainComponent()
infoDisplay = InfoDisplayer();
colorGradingPaletteDisplayEnabled = false;
fadeManager.Clear();
fadeToComponent = nullptr;
}
@@ -36,17 +39,39 @@ void MainComponent::Initialize()
wiLua::GetGlobal()->RegisterObject(MainComponent_BindLua::className, "main", new MainComponent_BindLua(this));
}
void MainComponent::activateComponent(RenderableComponent* component)
void MainComponent::onActivateComponent()
{
if (fadeToComponent == nullptr)
{
return;
}
activeComponent->Stop();
fadeToComponent->Start();
activeComponent = fadeToComponent;
fadeToComponent = nullptr;
}
void MainComponent::activateComponent(RenderableComponent* component, int fadeFrames, const wiColor& fadeColor)
{
if (component == nullptr)
{
return;
}
activeComponent->Stop();
component->Start();
fadeToComponent = component;
activeComponent = component;
if (fadeFrames > 0)
{
// Fade
fadeManager.Clear();
fadeManager.Start(fadeFrames, fadeColor, bind(&MainComponent::onActivateComponent, this));
}
else
{
// No fade
fadeManager.Clear();
onActivateComponent();
}
}
void MainComponent::run()
@@ -99,6 +124,9 @@ void MainComponent::Update()
wiLua::GetGlobal()->Update();
getActiveComponent()->Update();
fadeManager.Update();
}
void MainComponent::Render()
@@ -112,6 +140,16 @@ void MainComponent::Compose()
{
getActiveComponent()->Compose();
if (fadeManager.IsActive())
{
// display fade rect
static wiImageEffects fx;
fx.siz.x = (float)wiRenderer::GetScreenWidth();
fx.siz.y = (float)wiRenderer::GetScreenHeight();
fx.opacity = fadeManager.opacity;
wiImage::Draw(wiTextureHelper::getInstance()->getColor(fadeManager.color), fx);
}
// Draw the information display
if (infoDisplay.active)
{
+8 -1
View File
@@ -2,9 +2,12 @@
#include "CommonInclude.h"
#include "wiResourceManager.h"
#include "wiCVars.h"
#include "wiColor.h"
#include "wiFadeManager.h"
class RenderableComponent;
class MainComponent
{
private:
@@ -13,6 +16,10 @@ private:
int targetFrameRate;
double targetFrameRateInv;
int applicationControlLostThreshold;
wiFadeManager fadeManager;
RenderableComponent* fadeToComponent;
void onActivateComponent();
public:
MainComponent();
~MainComponent();
@@ -22,7 +29,7 @@ public:
void run();
void activateComponent(RenderableComponent* component);
void activateComponent(RenderableComponent* component, int fadeFrames = 0, const wiColor& fadeColor = wiColor(0,0,0,255));
RenderableComponent* getActiveComponent(){ return activeComponent; }
wiCVars Props;
+26 -7
View File
@@ -118,51 +118,70 @@ int MainComponent_BindLua::SetActiveComponent(lua_State *L)
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
int fadeFrames = 0;
wiColor fadeColor = wiColor(0, 0, 0, 255);
if (argc > 1)
{
fadeFrames = wiLua::SGetInt(L, 2);
if (argc > 2)
{
fadeColor.r = wiLua::SGetInt(L, 3);
if (argc > 3)
{
fadeColor.g = wiLua::SGetInt(L, 4);
if (argc > 4)
{
fadeColor.b = wiLua::SGetInt(L, 5);
}
}
}
}
ForwardRenderableComponent_BindLua* compFwd3D = Luna<ForwardRenderableComponent_BindLua>::lightcheck(L, 1);
if (compFwd3D != nullptr)
{
component->activateComponent(compFwd3D->component);
component->activateComponent(compFwd3D->component, fadeFrames, fadeColor);
return 0;
}
DeferredRenderableComponent_BindLua* compDef3D = Luna<DeferredRenderableComponent_BindLua>::lightcheck(L, 1);
if (compDef3D != nullptr)
{
component->activateComponent(compDef3D->component);
component->activateComponent(compDef3D->component, fadeFrames, fadeColor);
return 0;
}
Renderable3DComponent_BindLua* comp3D = Luna<Renderable3DComponent_BindLua>::lightcheck(L, 1);
if (comp3D != nullptr)
{
component->activateComponent(comp3D->component);
component->activateComponent(comp3D->component, fadeFrames, fadeColor);
return 0;
}
LoadingScreenComponent_BindLua* compLoad = Luna<LoadingScreenComponent_BindLua>::lightcheck(L, 1);
if (compLoad != nullptr)
{
component->activateComponent(compLoad->component);
component->activateComponent(compLoad->component, fadeFrames, fadeColor);
return 0;
}
Renderable2DComponent_BindLua* comp2D = Luna<Renderable2DComponent_BindLua>::lightcheck(L, 1);
if (comp2D != nullptr)
{
component->activateComponent(comp2D->component);
component->activateComponent(comp2D->component, fadeFrames, fadeColor);
return 0;
}
RenderableComponent_BindLua* comp = Luna<RenderableComponent_BindLua>::lightcheck(L, 1);
if (comp != nullptr)
{
component->activateComponent(comp->component);
component->activateComponent(comp->component, fadeFrames, fadeColor);
return 0;
}
}
else
{
wiLua::SError(L, "SetActiveComponent(RenderableComponent component) not enought arguments!");
wiLua::SError(L, "SetActiveComponent(RenderableComponent component, opt int fadeFrames,fadeColorR,fadeColorG) not enought arguments!");
return 0;
}
return 0;
+2
View File
@@ -450,6 +450,7 @@
<ClCompile Include="wiDepthTarget.cpp" />
<ClCompile Include="wiDirectInput.cpp" />
<ClCompile Include="wiEmittedParticle.cpp" />
<ClCompile Include="wiFadeManager.cpp" />
<ClCompile Include="wiFont.cpp" />
<ClCompile Include="ForwardRenderableComponent.cpp" />
<ClCompile Include="wiFont_BindLua.cpp" />
@@ -510,6 +511,7 @@
<ClInclude Include="Texture_BindLua.h" />
<ClInclude Include="Vector_BindLua.h" />
<ClInclude Include="wiBackLog_BindLua.h" />
<ClInclude Include="wiFadeManager.h" />
<ClInclude Include="wiFont_BindLua.h" />
<ClInclude Include="wiImageEffects_BindLua.h" />
<ClInclude Include="wiInputManager_BindLua.h" />
@@ -797,6 +797,9 @@
<ClCompile Include="wiNetwork_BindLua.cpp">
<Filter>Lua Bindings</Filter>
</ClCompile>
<ClCompile Include="wiFadeManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="typelib.h">
@@ -1771,6 +1774,9 @@
<ClInclude Include="wiNetwork_BindLua.h">
<Filter>Lua Bindings</Filter>
</ClInclude>
<ClInclude Include="wiFadeManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\io_export_wicked_wi_bin.py" />
+2 -2
View File
@@ -22,7 +22,7 @@ float4 main(VertextoPixel PSIn) : SV_TARGET
float2 distortionCo;
distortionCo.x = PSIn.dis.x/PSIn.dis.w/2.0f + 0.5f;
distortionCo.y = -PSIn.dis.y/PSIn.dis.w/2.0f + 0.5f;
float2 distort = normalize(float3(xNormalMap.SampleLevel(Sampler, PSIn.tex, PSIn.mip).rg, 1))*0.04f*(1 - xMaskFadOpaDis.z);
float2 distort = normalize(float3(xNormalMap.SampleLevel(Sampler, PSIn.tex, PSIn.mip).rg, 1))*0.04f*xMaskFadOpaDis.z;
PSIn.tex.xy=distortionCo+distort;
}
@@ -34,7 +34,7 @@ float4 main(VertextoPixel PSIn) : SV_TARGET
color.rgb*=1-xMaskFadOpaDis.y;
color.a-=xMaskFadOpaDis.z;
color.a*=xMaskFadOpaDis.z;
color.a=saturate(color.a);
+1 -1
View File
@@ -66,7 +66,7 @@ void wiBackLog::Draw(){
//wiImage::BatchBegin();
wiImageEffects fx = wiImageEffects((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT);
fx.pos=XMFLOAT3(0,pos,0);
fx.opacity = wiMath::Lerp(0, 1, pos / wiRenderer::RENDERHEIGHT);
fx.opacity = wiMath::Lerp(1, 0, pos / wiRenderer::RENDERHEIGHT);
wiImage::Draw(backgroundTex, fx);
font.SetText(getText());
font.props.posY = pos - wiRenderer::RENDERHEIGHT + 75 + scroll;
+47
View File
@@ -0,0 +1,47 @@
#include "wiFadeManager.h"
void wiFadeManager::Clear()
{
opacity = 0;
frame = 0;
state = FADE_FINISHED;
color = wiColor(0, 0, 0, 1);
}
void wiFadeManager::Update()
{
if (!IsActive())
return;
opacity = wiMath::Lerp(0.0f, 1.0f, (float)frame / (float)targetFrames);
if (state == FADE_IN)
{
frame++;
if (frame >= targetFrames)
{
state = FADE_MID;
opacity = 1.0f;
}
}
else if (state == FADE_OUT)
{
frame--;
if (frame <= 0)
{
state = FADE_FINISHED;
opacity = 0.0f;
}
}
else if (state == FADE_MID)
{
state = FADE_OUT;
opacity = 1.0f;
onFade();
}
else if (state == FADE_FINISHED)
{
opacity = 0.0f;
}
}
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include "CommonInclude.h"
#include "wiColor.h"
#include "wiTimer.h"
#include "wiMath.h"
class wiFadeManager
{
public:
float opacity;
int frame, targetFrames;
enum FADE_STATE
{
FADE_IN, // no fade -> faded
FADE_MID, // completely faded
FADE_OUT, // faded -> no fade
FADE_FINISHED,
} state;
wiColor color;
function<void()> onFade;
wiFadeManager()
{
Clear();
}
void Clear();
void Start(int targetFrames, const wiColor& color, function<void()> onFadeFunction)
{
this->targetFrames = targetFrames;
this->color = color;
frame = 0;
state = FADE_IN;
onFade = onFadeFunction;
}
void Update();
bool IsFaded()
{
return state == FADE_MID;
}
bool IsActive()
{
return state != FADE_FINISHED;
}
};
+2 -1
View File
@@ -105,7 +105,8 @@ public:
sunPos = XMFLOAT2(0, 0);
lookAt = XMFLOAT4(0, 0, 0, 0);
mirror = 1.0f;
blur = blurDir = fade = opacity = rotation = 0.0f;
blur = blurDir = fade = rotation = 0.0f;
opacity = 1.0f;
extractNormalMap = false;
mipLevel = 0.f;
stencilRef = 0;
+4 -4
View File
@@ -46,11 +46,11 @@ void wiLensFlare::Draw(ID3D11ShaderResourceView* depthMap, ID3D11DeviceContext*
wiRenderer::BindVS(vertexShader,context);
wiRenderer::BindGS(geometryShader,context);
ConstantBuffer cb;
cb.mSunPos = lightPos / XMVectorSet((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT, 1, 1);
cb.mScreen = XMFLOAT4((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT, 0, 0);
static thread_local ConstantBuffer* cb = new ConstantBuffer;
(*cb).mSunPos = lightPos / XMVectorSet((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT, 1, 1);
(*cb).mScreen = XMFLOAT4((float)wiRenderer::RENDERWIDTH, (float)wiRenderer::RENDERHEIGHT, 0, 0);
wiRenderer::UpdateBuffer(constantBuffer,&cb,context);
wiRenderer::UpdateBuffer(constantBuffer,cb,context);
//context->RSSetState(rasterizerState);
+3 -1
View File
@@ -15,10 +15,12 @@ private:
static ID3D11DepthStencilState* depthStencilState;
static ID3D11BlendState* blendState;
struct ConstantBuffer
GFX_STRUCT ConstantBuffer
{
XMVECTOR mSunPos;
XMFLOAT4 mScreen;
ALIGN_16
};
static void LoadShaders();
+2 -2
View File
@@ -60,7 +60,7 @@ void wiSprite::CleanUp(){
}
void wiSprite::Draw(ID3D11ShaderResourceView* refracRes, ID3D11DeviceContext* context){
if(effects.opacity<1 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE) ){
if(effects.opacity>0 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE) ){
effects.setRefractionMap(refracRes);
wiImage::Draw(texturePointer,effects,context);
}
@@ -69,7 +69,7 @@ void wiSprite::Draw(){
wiSprite::Draw(NULL,wiRenderer::getImmediateContext());
}
void wiSprite::DrawNormal(ID3D11DeviceContext* context){
if(normalPointer && effects.opacity<1 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE)){
if(normalPointer && effects.opacity>0 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE)){
//effects.setRefractionMap(refracRes);
wiImageEffects effectsMod(effects);
+2 -1
View File
@@ -57,7 +57,8 @@ public:
Anim(){
repeatable=false;
vel=XMFLOAT3(0,0,0);
rot=scaleX=scaleY=opa=fad=0;
rot=scaleX=scaleY=fad=0;
opa = 1;
movingTexAnim=MovingTexData();
drawRecAnim=DrawRecData();
}
+4 -2
View File
@@ -15,7 +15,9 @@ public:
static void Start();
static double TotalTime();
void record(); //start recording
double elapsed(); //elapsed time since record()
//start recording
void record();
//elapsed time since record()
double elapsed();
};