diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index f833bd0bb..9c5072610 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -76,20 +76,20 @@ void EditorLoadingScreen::Load() sprite = wiSprite("../logo/logo_small.png"); sprite.anim.opa = 0.02f; sprite.anim.repeatable = true; - sprite.effects.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth()*0.5f, wiRenderer::GetDevice()->GetScreenHeight()*0.5f - font.textHeight(), 0); - sprite.effects.siz = XMFLOAT2(128, 128); - sprite.effects.pivot = XMFLOAT2(0.5f, 1.0f); - sprite.effects.quality = QUALITY_BILINEAR; - sprite.effects.blendFlag = BLENDMODE_ALPHA; + sprite.params.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth()*0.5f, wiRenderer::GetDevice()->GetScreenHeight()*0.5f - font.textHeight(), 0); + sprite.params.siz = XMFLOAT2(128, 128); + sprite.params.pivot = XMFLOAT2(0.5f, 1.0f); + sprite.params.quality = QUALITY_BILINEAR; + sprite.params.blendFlag = BLENDMODE_ALPHA; addSprite(&sprite); __super::Load(); } void EditorLoadingScreen::Compose() { - font.props.posX = (int)(wiRenderer::GetDevice()->GetScreenWidth()*0.5f); - font.props.posY = (int)(wiRenderer::GetDevice()->GetScreenHeight()*0.5f); - sprite.effects.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth()*0.5f, wiRenderer::GetDevice()->GetScreenHeight()*0.5f - font.textHeight(), 0); + font.params.posX = (int)(wiRenderer::GetDevice()->GetScreenWidth()*0.5f); + font.params.posY = (int)(wiRenderer::GetDevice()->GetScreenHeight()*0.5f); + sprite.params.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth()*0.5f, wiRenderer::GetDevice()->GetScreenHeight()*0.5f - font.textHeight(), 0); __super::Compose(); } diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 087560994..406348222 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -105,6 +105,7 @@ TestsRenderer::TestsRenderer() testSelector->AddItem("Job System Test"); testSelector->AddItem("Font Test"); testSelector->AddItem("Volumetric Test"); + testSelector->AddItem("Sprite Test"); testSelector->SetMaxVisibleItemCount(100); testSelector->OnSelect([=](wiEventArgs args) { @@ -130,9 +131,9 @@ TestsRenderer::TestsRenderer() { static wiSprite sprite; sprite = wiSprite("images/HelloWorld.png"); - sprite.effects.pos = XMFLOAT3(screenW / 2, screenH / 2, 0); - sprite.effects.siz = XMFLOAT2(200, 100); - sprite.effects.pivot = XMFLOAT2(0.5f, 0.5f); + sprite.params.pos = XMFLOAT3(screenW / 2, screenH / 2, 0); + sprite.params.siz = XMFLOAT2(200, 100); + sprite.params.pivot = XMFLOAT2(0.5f, 0.5f); sprite.anim.rot = XM_PI / 400.0f; this->addSprite(&sprite); break; @@ -179,6 +180,9 @@ TestsRenderer::TestsRenderer() wiRenderer::SetTemporalAAEnabled(true); wiRenderer::LoadModel("../models/volumetric_test.wiscene", XMMatrixTranslation(0, 0, 4)); break; + case 13: + RunSpriteTest(); + break; default: assert(0); break; @@ -233,11 +237,11 @@ void TestsRenderer::RunJobSystemTest() static wiFont font; font = wiFont(ss.str()); - font.props.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2; - font.props.posY = wiRenderer::GetDevice()->GetScreenHeight() / 2; - font.props.h_align = WIFALIGN_CENTER; - font.props.v_align = WIFALIGN_CENTER; - font.props.size = 24; + font.params.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2; + font.params.posY = wiRenderer::GetDevice()->GetScreenHeight() / 2; + font.params.h_align = WIFALIGN_CENTER; + font.params.v_align = WIFALIGN_CENTER; + font.params.size = 24; this->addFont(&font); } void TestsRenderer::RunFontTest() @@ -248,35 +252,35 @@ void TestsRenderer::RunFontTest() font.SetText("This is Arial, size 32 wiFont"); font_upscaled.SetText("This is Arial, size 14 wiFont, but upscaled to 32"); - font.props.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2; - font.props.posY = wiRenderer::GetDevice()->GetScreenHeight() / 6; - font.props.size = 32; + font.params.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2; + font.params.posY = wiRenderer::GetDevice()->GetScreenHeight() / 6; + font.params.size = 32; - font_upscaled.props = font.props; - font_upscaled.props.posY += font.textHeight() + 10; + font_upscaled.params = font.params; + font_upscaled.params.posY += font.textHeight() + 10; font.style = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf"); font_upscaled.style = wiFont::AddFontStyle(wiFont::GetFontPath() + "arial.ttf"); - font_upscaled.props.size = 14; - font_upscaled.props.scaling = 32.0f / 14.0f; + font_upscaled.params.size = 14; + font_upscaled.params.scaling = 32.0f / 14.0f; addFont(&font); addFont(&font_upscaled); static wiFont font_aligned; font_aligned = font; - font_aligned.props.posY += font.textHeight() * 2; - font_aligned.props.size = 38; - font_aligned.props.shadowColor = wiColor::Red(); - font_aligned.props.h_align = WIFALIGN_CENTER; + font_aligned.params.posY += font.textHeight() * 2; + font_aligned.params.size = 38; + font_aligned.params.shadowColor = wiColor::Red(); + font_aligned.params.h_align = WIFALIGN_CENTER; font_aligned.SetText("Center aligned, red shadow, bigger"); addFont(&font_aligned); static wiFont font_aligned2; font_aligned2 = font_aligned; - font_aligned2.props.posY += font_aligned.textHeight() + 10; - font_aligned2.props.shadowColor = wiColor::Purple(); - font_aligned2.props.h_align = WIFALIGN_RIGHT; + font_aligned2.params.posY += font_aligned.textHeight() + 10; + font_aligned2.params.shadowColor = wiColor::Purple(); + font_aligned2.params.h_align = WIFALIGN_RIGHT; font_aligned2.SetText("Right aligned, purple shadow"); addFont(&font_aligned2); @@ -293,11 +297,34 @@ void TestsRenderer::RunFontTest() } static wiFont font_japanese; font_japanese = font_aligned2; - font_japanese.props.posY += font_aligned2.textHeight(); + font_japanese.params.posY += font_aligned2.textHeight(); font_japanese.style = wiFont::AddFontStyle("yumin.ttf"); - font_japanese.props.shadowColor = wiColor::Transparent(); - font_japanese.props.h_align = WIFALIGN_CENTER; - font_japanese.props.size = 34; + font_japanese.params.shadowColor = wiColor::Transparent(); + font_japanese.params.h_align = WIFALIGN_CENTER; + font_japanese.params.size = 34; font_japanese.SetText(ss.str()); addFont(&font_japanese); + + static wiFont font_colored; + font_colored.params.color = wiColor::Cyan(); + font_colored.params.h_align = WIFALIGN_CENTER; + font_colored.params.v_align = WIFALIGN_TOP; + font_colored.params.size = 26; + font_colored.params.posX = wiRenderer::GetDevice()->GetScreenWidth() / 2; + font_colored.params.posY = font_japanese.params.posY + font_japanese.textHeight(); + font_colored.SetText("Colored font"); + addFont(&font_colored); +} +void TestsRenderer::RunSpriteTest() +{ + static wiSprite sprite("images/effect.png"); + sprite.params.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth() * 0.5f, wiRenderer::GetDevice()->GetScreenHeight() * 0.5f, 0); + sprite.params.siz = XMFLOAT2(200, 200); + sprite.params.pivot = XMFLOAT2(0.5f, 0.5f); + sprite.params.enableDrawRect(XMFLOAT4(0, 0, 128, 128)); + sprite.params.sampleFlag = SAMPLEMODE_WRAP; + sprite.anim.drawRecAnim.frameCount = 8; + sprite.anim.drawRecAnim.jumpX = 1; + sprite.anim.drawRecAnim.onFrameChangeWait = 4; + addSprite(&sprite); } diff --git a/Tests/Tests.h b/Tests/Tests.h index 9a4e07a89..c0b843c7b 100644 --- a/Tests/Tests.h +++ b/Tests/Tests.h @@ -20,5 +20,6 @@ public: void RunJobSystemTest(); void RunFontTest(); + void RunSpriteTest(); }; diff --git a/Tests/images/effect.png b/Tests/images/effect.png new file mode 100644 index 000000000..433a0f010 Binary files /dev/null and b/Tests/images/effect.png differ diff --git a/WickedEngine/RenderPath2D.cpp b/WickedEngine/RenderPath2D.cpp index 289852e0b..f8d252872 100644 --- a/WickedEngine/RenderPath2D.cpp +++ b/WickedEngine/RenderPath2D.cpp @@ -130,7 +130,7 @@ void RenderPath2D::Render() void RenderPath2D::Compose() { wiImageParams fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); - fx.presentFullScreen = true; + fx.enableFullScreen(); fx.blendFlag = BLENDMODE_PREMULTIPLIED; wiImage::Draw(rtFinal.GetTexture(), fx, GRAPHICSTHREAD_IMMEDIATE); diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index 2d08de9b3..d5e7610b3 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -312,7 +312,7 @@ void RenderPath3D::RenderShadows(GRAPHICSTHREAD threadID) void RenderPath3D::RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& shadedSceneRT, GRAPHICSTHREAD threadID) { wiImageParams fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); - fx.hdr = true; + fx.enableHDR(); wiRenderer::GetDevice()->EventBegin("Downsample Depth Buffer", threadID); { @@ -391,7 +391,7 @@ void RenderPath3D::RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& wiRenderer::GetDevice()->EventBegin("Refraction Target", threadID); fx.blendFlag = BLENDMODE_OPAQUE; fx.quality = QUALITY_NEAREST; - fx.presentFullScreen = true; + fx.enableFullScreen(); wiImage::Draw(shadedSceneRT.GetTextureResolvedMSAA(threadID), fx, threadID); wiRenderer::GetDevice()->EventEnd(threadID); } @@ -407,7 +407,7 @@ void RenderPath3D::RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& wiRenderer::DrawLightVisualizers(wiRenderer::GetCamera(), threadID); - fx.presentFullScreen = true; + fx.enableFullScreen(); if (getEmittedParticlesEnabled()) { wiRenderer::GetDevice()->EventBegin("Contribute Emitters", threadID); @@ -469,7 +469,7 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg wiProfiler::BeginRange("Post Processing", wiProfiler::DOMAIN_GPU, threadID); wiImageParams fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); - fx.hdr = true; + fx.enableHDR(); if (wiRenderer::GetTemporalAAEnabled() && !wiRenderer::GetTemporalAADebugEnabled()) { @@ -480,7 +480,7 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg int history = 1 - current; rtTemporalAA[current].Set(threadID); { wiRenderer::BindGBufferTextures(mainRT.GetTextureResolvedMSAA(threadID, 0), mainRT.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.process.setTemporalAAResolve(); fx.setMaskMap(rtTemporalAA[history].GetTexture()); wiImage::Draw(shadedSceneRT.GetTextureResolvedMSAA(threadID), fx, threadID); @@ -489,10 +489,10 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg wiRenderer::GetDevice()->UnbindResources(TEXSLOT_GBUFFER0, 1, threadID); wiRenderer::GetDevice()->UnbindResources(TEXSLOT_ONDEMAND0, 1, threadID); shadedSceneRT.Set(threadID, nullptr, false, 0); { - fx.presentFullScreen = true; + fx.enableFullScreen(); fx.quality = QUALITY_NEAREST; wiImage::Draw(rtTemporalAA[current].GetTexture(), fx, threadID); - fx.presentFullScreen = false; + fx.disableFullScreen(); } wiProfiler::EndRange(threadID); wiRenderer::GetDevice()->EventEnd(threadID); @@ -502,7 +502,7 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg { wiRenderer::GetDevice()->EventBegin("Bloom", threadID); fx.process.clear(); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.quality = QUALITY_BILINEAR; rtBloom[0].Set(threadID); // separate bright parts { @@ -532,10 +532,10 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg shadedSceneRT.Set(threadID, false, 0); { // add to the scene fx.blendFlag = BLENDMODE_ADDITIVE; - fx.presentFullScreen = true; + fx.enableFullScreen(); fx.process.clear(); wiImage::Draw(rtBloom.back().GetTexture(), fx, threadID); - fx.presentFullScreen = false; + fx.disableFullScreen(); } wiRenderer::GetDevice()->EventEnd(threadID); } @@ -545,13 +545,13 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg rtMotionBlur.Set(threadID); fx.process.setMotionBlur(); fx.blendFlag = BLENDMODE_OPAQUE; - fx.presentFullScreen = false; + fx.disableFullScreen(); wiImage::Draw(shadedSceneRT.GetTextureResolvedMSAA(threadID), fx, threadID); fx.process.clear(); wiRenderer::GetDevice()->EventEnd(threadID); } - fx.hdr = false; + fx.disableHDR(); wiRenderer::GetDevice()->EventBegin("Tone Mapping", threadID); fx.blendFlag = BLENDMODE_OPAQUE; @@ -626,7 +626,7 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg } else { - fx.presentFullScreen = true; + fx.enableFullScreen(); } if (getDepthOfFieldEnabled()) wiImage::Draw(rtDof[2].GetTexture(), fx, threadID); @@ -647,7 +647,7 @@ void RenderPath3D::RenderColorGradedComposition() if (getStereogramEnabled()) { wiRenderer::GetDevice()->EventBegin("Stereogram", GRAPHICSTHREAD_IMMEDIATE); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.process.clear(); fx.process.setStereogram(); wiImage::Draw(wiTextureHelper::getRandom64x64(), fx, GRAPHICSTHREAD_IMMEDIATE); @@ -671,7 +671,7 @@ void RenderPath3D::RenderColorGradedComposition() else { wiRenderer::GetDevice()->EventBegin("Composition", GRAPHICSTHREAD_IMMEDIATE); - fx.presentFullScreen = true; + fx.enableFullScreen(); } if (getSharpenFilterEnabled()) diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp index 8d6324914..d689e7eb0 100644 --- a/WickedEngine/RenderPath3D_Deferred.cpp +++ b/WickedEngine/RenderPath3D_Deferred.cpp @@ -224,8 +224,8 @@ void RenderPath3D_Deferred::RenderScene(GRAPHICSTHREAD threadID) fx.blendFlag = BLENDMODE_OPAQUE; fx.stencilRef = 0; fx.stencilComp = STENCILMODE_DISABLED; - fx.presentFullScreen = true; - fx.hdr = true; + fx.enableFullScreen(); + fx.enableHDR(); wiImage::Draw(rtLight.GetTexture(0), fx, threadID); fx.stencilRef = STENCILREF_SKIN; fx.stencilComp = STENCILMODE_LESS; @@ -249,7 +249,7 @@ void RenderPath3D_Deferred::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventBegin("SSR", threadID); rtSSR.Activate(threadID); { fx.process.clear(); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.process.setSSR(); fx.setMaskMap(nullptr); wiImage::Draw(rtDeferred.GetTexture(), fx, threadID); diff --git a/WickedEngine/RenderPath3D_Forward.cpp b/WickedEngine/RenderPath3D_Forward.cpp index 12f1307ff..36c7cd4b0 100644 --- a/WickedEngine/RenderPath3D_Forward.cpp +++ b/WickedEngine/RenderPath3D_Forward.cpp @@ -151,7 +151,7 @@ void RenderPath3D_Forward::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventBegin("SSR", threadID); rtSSR.Activate(threadID); { fx.process.clear(); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.process.setSSR(); fx.setMaskMap(nullptr); wiImage::Draw(rtMain.GetTexture(), fx, threadID); diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp index a15775400..d253cdc50 100644 --- a/WickedEngine/RenderPath3D_PathTracing.cpp +++ b/WickedEngine/RenderPath3D_PathTracing.cpp @@ -146,7 +146,7 @@ void RenderPath3D_PathTracing::RenderScene(GRAPHICSTHREAD threadID) wiImageParams fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); - fx.hdr = true; + fx.enableHDR(); // Accumulate with moving averaged blending: diff --git a/WickedEngine/RenderPath3D_TiledDeferred.cpp b/WickedEngine/RenderPath3D_TiledDeferred.cpp index fa741c4ef..bdc062d67 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred.cpp +++ b/WickedEngine/RenderPath3D_TiledDeferred.cpp @@ -152,8 +152,8 @@ void RenderPath3D_TiledDeferred::RenderScene(GRAPHICSTHREAD threadID) fx.blendFlag = BLENDMODE_OPAQUE; fx.stencilRef = 0; fx.stencilComp = STENCILMODE_DISABLED; - fx.presentFullScreen = true; - fx.hdr = true; + fx.enableFullScreen(); + fx.enableHDR(); wiImage::Draw(static_cast(wiRenderer::GetTexture(TEXTYPE_2D_TILEDDEFERRED_DIFFUSEUAV)), fx, threadID); fx.stencilRef = STENCILREF_SKIN; fx.stencilComp = STENCILMODE_LESS; @@ -178,7 +178,7 @@ void RenderPath3D_TiledDeferred::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventBegin("SSR", threadID); rtSSR.Activate(threadID); { fx.process.clear(); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.process.setSSR(); fx.setMaskMap(nullptr); wiImage::Draw(rtDeferred.GetTexture(), fx, threadID); diff --git a/WickedEngine/RenderPath3D_TiledForward.cpp b/WickedEngine/RenderPath3D_TiledForward.cpp index c147aac97..30a599fea 100644 --- a/WickedEngine/RenderPath3D_TiledForward.cpp +++ b/WickedEngine/RenderPath3D_TiledForward.cpp @@ -101,7 +101,7 @@ void RenderPath3D_TiledForward::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->EventBegin("SSR", threadID); rtSSR.Activate(threadID); { fx.process.clear(); - fx.presentFullScreen = false; + fx.disableFullScreen(); fx.process.setSSR(); fx.setMaskMap(nullptr); wiImage::Draw(rtMain.GetTexture(), fx, threadID); diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 71bd4f925..ca34ff439 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -95,8 +95,8 @@ namespace wiBackLog fx.opacity = wiMath::Lerp(1, 0, -pos / wiRenderer::GetDevice()->GetScreenHeight()); wiImage::Draw(backgroundTex, fx, GRAPHICSTHREAD_IMMEDIATE); font.SetText(getText()); - font.props.posX = 50; - font.props.posY = (int)pos + (int)scroll; + font.params.posX = 50; + font.params.posY = (int)pos + (int)scroll; font.Draw(GRAPHICSTHREAD_IMMEDIATE); wiFont(inputArea.str().c_str(), wiFontParams(10, wiRenderer::GetDevice()->GetScreenHeight() - 10, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_BOTTOM)).Draw(GRAPHICSTHREAD_IMMEDIATE); } @@ -186,11 +186,11 @@ namespace wiBackLog } void setFontSize(int value) { - font.props.size = value; + font.params.size = value; } void setFontRowspacing(int value) { - font.props.spacingY = value; + font.params.spacingY = value; } bool isActive() { return state == IDLE; } diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index babd7b8dc..957b13235 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -22,9 +22,9 @@ using namespace wiGraphicsTypes; using namespace wiRectPacker; #define MAX_TEXT 10000 -#define WHITESPACE_SIZE (int((props.size + props.spacingX) * props.scaling * 0.3f)) +#define WHITESPACE_SIZE (int((params.size + params.spacingX) * params.scaling * 0.3f)) #define TAB_SIZE (WHITESPACE_SIZE * 4) -#define LINEBREAK_SIZE (int((props.size + props.spacingY) * props.scaling)) +#define LINEBREAK_SIZE (int((params.size + params.spacingY) * params.scaling)) namespace wiFont_Internal { @@ -100,7 +100,7 @@ namespace wiFont_Internal XMHALF2 Tex; }; - int WriteVertices(volatile FontVertex* vertexList, const std::wstring& text, wiFontParams props, int style) + int WriteVertices(volatile FontVertex* vertexList, const std::wstring& text, wiFontParams params, int style) { int quadCount = 0; @@ -108,7 +108,7 @@ namespace wiFont_Internal int16_t pos = 0; for (auto& code : text) { - const int32_t hash = glyphhash(code, style, props.size); + const int32_t hash = glyphhash(code, style, params.size); if (glyph_lookup.count(hash) == 0) { @@ -135,10 +135,10 @@ namespace wiFont_Internal else { const Glyph& glyph = glyph_lookup.at(hash); - const int16_t glyphWidth = int16_t(glyph.width * props.scaling); - const int16_t glyphHeight = int16_t(glyph.height * props.scaling); - const int16_t glyphOffsetX = int16_t(glyph.x * props.scaling); - const int16_t glyphOffsetY = int16_t(glyph.y * props.scaling); + const int16_t glyphWidth = int16_t(glyph.width * params.scaling); + const int16_t glyphHeight = int16_t(glyph.height * params.scaling); + const int16_t glyphOffsetX = int16_t(glyph.x * params.scaling); + const int16_t glyphOffsetY = int16_t(glyph.y * params.scaling); const size_t vertexID = quadCount * 4; @@ -165,7 +165,7 @@ namespace wiFont_Internal vertexList[vertexID + 3].Tex.x = glyph.tc_right; vertexList[vertexID + 3].Tex.y = glyph.tc_bottom; - pos += int16_t((glyph.width + props.spacingX) * props.scaling); + pos += int16_t((glyph.width + params.spacingX) * params.scaling); quadCount++; } @@ -179,11 +179,11 @@ namespace wiFont_Internal using namespace wiFont_Internal; -wiFont::wiFont(const std::string& text, wiFontParams props, int style) : props(props), style(style) +wiFont::wiFont(const std::string& text, wiFontParams params, int style) : params(params), style(style) { SetText(text); } -wiFont::wiFont(const std::wstring& text, wiFontParams props, int style) : props(props), style(style) +wiFont::wiFont(const std::wstring& text, wiFontParams params, int style) : params(params), style(style) { SetText(text); } @@ -496,15 +496,15 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) return; } - wiFontParams newProps = props; + wiFontParams newProps = params; - if (props.h_align == WIFALIGN_CENTER) + if (params.h_align == WIFALIGN_CENTER) newProps.posX -= textWidth() / 2; - else if (props.h_align == WIFALIGN_RIGHT) + else if (params.h_align == WIFALIGN_RIGHT) newProps.posX -= textWidth(); - if (props.v_align == WIFALIGN_CENTER) + if (params.v_align == WIFALIGN_CENTER) newProps.posY -= textHeight() / 2; - else if (props.v_align == WIFALIGN_BOTTOM) + else if (params.v_align == WIFALIGN_BOTTOM) newProps.posY -= textHeight(); @@ -579,7 +579,7 @@ int wiFont::textWidth() int currentLineWidth = 0; for (auto& code : text) { - const int32_t hash = glyphhash(code, style, props.size); + const int32_t hash = glyphhash(code, style, params.size); if (glyph_lookup.count(hash) == 0) { @@ -602,7 +602,7 @@ int wiFont::textWidth() else { const Glyph& glyph = glyph_lookup.at(hash); - currentLineWidth += int((glyph.width + props.spacingX) * props.scaling); + currentLineWidth += int((glyph.width + params.spacingX) * params.scaling); } maxWidth = max(maxWidth, currentLineWidth); } diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index a77e844dc..f0593d3b3 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -49,11 +49,11 @@ public: static int AddFontStyle(const std::string& fontName); std::wstring text; - wiFontParams props; + wiFontParams params; int style; - wiFont(const std::string& text = "", wiFontParams props = wiFontParams(), int style = 0); - wiFont(const std::wstring& text, wiFontParams props = wiFontParams(), int style = 0); + wiFont(const std::string& text = "", wiFontParams params = wiFontParams(), int style = 0); + wiFont(const std::wstring& text, wiFontParams params = wiFontParams(), int style = 0); ~wiFont(); void Draw(GRAPHICSTHREAD threadID); diff --git a/WickedEngine/wiFont_BindLua.cpp b/WickedEngine/wiFont_BindLua.cpp index 18edf9675..a98548d2c 100644 --- a/WickedEngine/wiFont_BindLua.cpp +++ b/WickedEngine/wiFont_BindLua.cpp @@ -79,7 +79,7 @@ int wiFont_BindLua::SetSize(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - font->props.size = wiLua::SGetInt(L, 1); + font->params.size = wiLua::SGetInt(L, 1); } else wiLua::SError(L, "SetSize(int size) not enough arguments!"); @@ -93,8 +93,8 @@ int wiFont_BindLua::SetPos(lua_State* L) Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font->props.posX = (int)XMVectorGetX(param->vector); - font->props.posY = (int)XMVectorGetY(param->vector); + font->params.posX = (int)XMVectorGetX(param->vector); + font->params.posY = (int)XMVectorGetY(param->vector); } else wiLua::SError(L, "SetPos(Vector pos) argument is not a vector!"); @@ -111,8 +111,8 @@ int wiFont_BindLua::SetSpacing(lua_State* L) Vector_BindLua* param = Luna::lightcheck(L, 1); if (param != nullptr) { - font->props.spacingX = (int)XMVectorGetX(param->vector); - font->props.spacingY = (int)XMVectorGetY(param->vector); + font->params.spacingX = (int)XMVectorGetX(param->vector); + font->params.spacingY = (int)XMVectorGetY(param->vector); } else wiLua::SError(L, "SetSpacing(Vector spacing) argument is not a vector!"); @@ -126,10 +126,10 @@ int wiFont_BindLua::SetAlign(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - font->props.h_align = (wiFontAlign)wiLua::SGetInt(L, 1); + font->params.h_align = (wiFontAlign)wiLua::SGetInt(L, 1); if (argc > 1) { - font->props.v_align = (wiFontAlign)wiLua::SGetInt(L, 2); + font->params.v_align = (wiFontAlign)wiLua::SGetInt(L, 2); } } else @@ -144,23 +144,23 @@ int wiFont_BindLua::GetText(lua_State* L) } int wiFont_BindLua::GetSize(lua_State* L) { - wiLua::SSetInt(L, font->props.size); + wiLua::SSetInt(L, font->params.size); return 1; } int wiFont_BindLua::GetPos(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMVectorSet((float)font->props.posX, (float)font->props.posY, 0, 0))); + Luna::push(L, new Vector_BindLua(XMVectorSet((float)font->params.posX, (float)font->params.posY, 0, 0))); return 1; } int wiFont_BindLua::GetSpacing(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMVectorSet((float)font->props.spacingX, (float)font->props.spacingY, 0, 0))); + Luna::push(L, new Vector_BindLua(XMVectorSet((float)font->params.spacingX, (float)font->params.spacingY, 0, 0))); return 1; } int wiFont_BindLua::GetAlign(lua_State* L) { - wiLua::SSetInt(L, font->props.h_align); - wiLua::SSetInt(L, font->props.v_align); + wiLua::SSetInt(L, font->params.h_align); + wiLua::SSetInt(L, font->params.v_align); return 2; } diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 579064864..1bce33d69 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -96,16 +96,16 @@ namespace wiImage device->BindSampler(PS, wiRenderer::GetSampler(SSLOT_ANISO_CLAMP), SSLOT_ONDEMAND0, threadID); } - if (params.presentFullScreen) + if (params.isFullScreenEnabled()) { - device->BindGraphicsPSO(&imagePSO[IMAGE_SHADER_FULLSCREEN][params.blendFlag][params.stencilComp][params.hdr], threadID); + device->BindGraphicsPSO(&imagePSO[IMAGE_SHADER_FULLSCREEN][params.blendFlag][params.stencilComp][params.isHDREnabled()], threadID); device->Draw(3, 0, threadID); device->EventEnd(threadID); return; } - if (!params.process.isActive()) // not post process, ust regular image + if (!params.process.isActive()) // not post process, just regular image { ImageCB cb; if (params.typeFlag == SCREEN) @@ -151,24 +151,39 @@ namespace wiImage )); } - // todo: params.drawRec -> texmuladd! - cb.xTexMulAdd = XMFLOAT4(1, 1, params.texOffset.x, params.texOffset.y); + const TextureDesc& desc = texture->GetDesc(); + const float inv_width = 1.0f / float(desc.Width); + const float inv_height = 1.0f / float(desc.Height); + + if (params.isDrawRectEnabled()) + { + cb.xTexMulAdd.x = params.drawRect.z * inv_width; // drawRec.width: mul + cb.xTexMulAdd.y = params.drawRect.w * inv_height; // drawRec.heigh: mul + cb.xTexMulAdd.z = params.drawRect.x * inv_width; // drawRec.x: add + cb.xTexMulAdd.w = params.drawRect.y * inv_height; // drawRec.y: add + } + else + { + cb.xTexMulAdd = XMFLOAT4(1, 1, 0, 0); // disabled draw rect + } + cb.xTexMulAdd.z += params.texOffset.x * inv_width; // texOffset.x: add + cb.xTexMulAdd.w += params.texOffset.y * inv_height; // texOffset.y: add cb.xColor = params.col; - cb.xColor.x *= 1 - params.fade; - cb.xColor.y *= 1 - params.fade; - cb.xColor.z *= 1 - params.fade; + const float darken = 1 - params.fade; + cb.xColor.x *= darken; + cb.xColor.y *= darken; + cb.xColor.z *= darken; cb.xColor.w *= params.opacity; cb.xPivot = params.pivot; - cb.xMirror = params.mirror; - cb.xPivot = params.pivot; + cb.xMirror = params.isMirrorEnabled() ? 1 : 0; cb.xMipLevel = params.mipLevel; device->UpdateBuffer(&constantBuffer, &cb, threadID); // Determine relevant image rendering pixel shader: IMAGE_SHADER targetShader; - bool NormalmapSeparate = params.extractNormalMap; + bool NormalmapSeparate = params.isExtractNormalMapEnabled(); bool Mask = params.maskMap != nullptr; bool Distort = params.distortionMap != nullptr; if (NormalmapSeparate) @@ -198,7 +213,7 @@ namespace wiImage } } - device->BindGraphicsPSO(&imagePSO[targetShader][params.blendFlag][params.stencilComp][params.hdr], threadID); + device->BindGraphicsPSO(&imagePSO[targetShader][params.blendFlag][params.stencilComp][params.isHDREnabled()], threadID); fullScreenEffect = false; } diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 00b7128bb..66f733336 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -48,25 +48,32 @@ enum ImageType struct wiImageParams { + enum FLAGS + { + EMPTY = 0, + DRAWRECT = 1 << 0, + MIRROR = 1 << 1, + EXTRACT_NORMALMAP = 1 << 2, + HDR = 1 << 3, + FULLSCREEN = 1 << 4, + }; + uint32_t _flags = EMPTY; + XMFLOAT3 pos; - float rotation; XMFLOAT2 siz; XMFLOAT2 scale; XMFLOAT4 col; - XMFLOAT4 drawRec; + XMFLOAT4 drawRect; XMFLOAT4 lookAt; //(x,y,z) : direction, (w) :isenabled? XMFLOAT2 texOffset; XMFLOAT2 pivot; // (0,0) : upperleft, (0.5,0.5) : center, (1,1) : bottomright + float rotation; float mipLevel; float fade; float opacity; + UINT stencilRef; STENCILMODE stencilComp; - bool mirror; // horizontal mirroring - bool extractNormalMap; - bool hdr; // is it rendered to HDR render target? - bool presentFullScreen; // don't set anything, just fill the whole screen - BLENDMODE blendFlag; ImageType typeFlag; SAMPLEMODE sampleFlag; @@ -152,23 +159,20 @@ struct wiImageParams void init() { + _flags = EMPTY; pos = XMFLOAT3(0, 0, 0); siz = XMFLOAT2(1, 1); col = XMFLOAT4(1, 1, 1, 1); scale = XMFLOAT2(1, 1); - drawRec = XMFLOAT4(0, 0, 0, 0); + drawRect = XMFLOAT4(0, 0, 0, 0); texOffset = XMFLOAT2(0, 0); lookAt = XMFLOAT4(0, 0, 0, 0); pivot = XMFLOAT2(0, 0); - mirror = false; fade = rotation = 0.0f; opacity = 1.0f; - extractNormalMap = false; - hdr = false; mipLevel = 0.f; stencilRef = 0; stencilComp = STENCILMODE_DISABLED; - presentFullScreen = false; blendFlag = BLENDMODE_ALPHA; typeFlag = SCREEN; sampleFlag = SAMPLEMODE_MIRROR; @@ -178,6 +182,34 @@ struct wiImageParams refractionSource = nullptr; } + constexpr bool isDrawRectEnabled() const { return _flags & DRAWRECT; } + constexpr bool isMirrorEnabled() const { return _flags & MIRROR; } + constexpr bool isExtractNormalMapEnabled() const { return _flags & EXTRACT_NORMALMAP; } + constexpr bool isHDREnabled() const { return _flags & HDR; } + constexpr bool isFullScreenEnabled() const { return _flags & FULLSCREEN; } + + // enables draw rectangle (cutout texture outside draw rectangle) + void enableDrawRect(const XMFLOAT4& rect) { _flags |= DRAWRECT; drawRect = rect; } + // mirror the image horizontally + void enableMirror() { _flags |= MIRROR; } + // enable normal map extraction shader that will perform texcolor * 2 - 1 (preferably onto a signed render target) + void enableExtractNormalMap() { _flags |= EXTRACT_NORMALMAP; } + // enable HDR blending to float render target + void enableHDR() { _flags |= HDR; } + // enable full screen override. It just draws texture onto the full screen, disabling any other setup except sampler and stencil) + void enableFullScreen() { _flags |= FULLSCREEN; } + + // disable draw rectangle (whole texture will be drawn, no cutout) + void disableDrawRect() { _flags &= ~DRAWRECT; } + // disable mirroring + void disableMirror() { _flags &= ~MIRROR; } + // disable normal map extraction shader + void disableExtractNormalMap() { _flags &= ~EXTRACT_NORMALMAP; } + // if you want to render onto normalized render target + void disableHDR() { _flags &= ~HDR; } + // disable full screen override + void disableFullScreen() { _flags &= ~FULLSCREEN; } + wiImageParams() { init(); diff --git a/WickedEngine/wiImageParams_BindLua.cpp b/WickedEngine/wiImageParams_BindLua.cpp index c1d6ce2c8..27c3d704c 100644 --- a/WickedEngine/wiImageParams_BindLua.cpp +++ b/WickedEngine/wiImageParams_BindLua.cpp @@ -24,38 +24,38 @@ Luna::PropertyType wiImageParams_BindLua::properties[] = }; -wiImageParams_BindLua::wiImageParams_BindLua(const wiImageParams& effects) :effects(effects) +wiImageParams_BindLua::wiImageParams_BindLua(const wiImageParams& params) :params(params) { } int wiImageParams_BindLua::GetPos(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMLoadFloat3(&effects.pos))); + Luna::push(L, new Vector_BindLua(XMLoadFloat3(¶ms.pos))); return 1; } int wiImageParams_BindLua::GetSize(lua_State* L) { - Luna::push(L, new Vector_BindLua(XMLoadFloat2(&effects.siz))); + Luna::push(L, new Vector_BindLua(XMLoadFloat2(¶ms.siz))); return 1; } int wiImageParams_BindLua::GetOpacity(lua_State* L) { - wiLua::SSetFloat(L, effects.opacity); + wiLua::SSetFloat(L, params.opacity); return 1; } int wiImageParams_BindLua::GetFade(lua_State* L) { - wiLua::SSetFloat(L, effects.fade); + wiLua::SSetFloat(L, params.fade); return 1; } int wiImageParams_BindLua::GetRotation(lua_State* L) { - wiLua::SSetFloat(L, effects.rotation); + wiLua::SSetFloat(L, params.rotation); return 1; } int wiImageParams_BindLua::GetMipLevel(lua_State* L) { - wiLua::SSetFloat(L, effects.mipLevel); + wiLua::SSetFloat(L, params.mipLevel); return 1; } @@ -67,7 +67,7 @@ int wiImageParams_BindLua::SetPos(lua_State* L) Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat3(&effects.pos, vector->vector); + XMStoreFloat3(¶ms.pos, vector->vector); } } else @@ -84,7 +84,7 @@ int wiImageParams_BindLua::SetSize(lua_State* L) Vector_BindLua* vector = Luna::lightcheck(L, 1); if (vector != nullptr) { - XMStoreFloat2(&effects.siz, vector->vector); + XMStoreFloat2(¶ms.siz, vector->vector); } } else @@ -98,7 +98,7 @@ int wiImageParams_BindLua::SetOpacity(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - effects.opacity = wiLua::SGetFloat(L, 1); + params.opacity = wiLua::SGetFloat(L, 1); } else { @@ -111,7 +111,7 @@ int wiImageParams_BindLua::SetFade(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - effects.fade = wiLua::SGetFloat(L, 1); + params.fade = wiLua::SGetFloat(L, 1); } else { @@ -124,7 +124,7 @@ int wiImageParams_BindLua::SetRotation(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - effects.rotation = wiLua::SGetFloat(L, 1); + params.rotation = wiLua::SGetFloat(L, 1); } else { @@ -137,7 +137,7 @@ int wiImageParams_BindLua::SetMipLevel(lua_State* L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - effects.mipLevel = wiLua::SGetFloat(L, 1); + params.mipLevel = wiLua::SGetFloat(L, 1); } else { @@ -170,7 +170,7 @@ wiImageParams_BindLua::wiImageParams_BindLua(lua_State *L) } } } - effects = wiImageParams(x, y, w, h); + params = wiImageParams(x, y, w, h); } wiImageParams_BindLua::~wiImageParams_BindLua() diff --git a/WickedEngine/wiImageParams_BindLua.h b/WickedEngine/wiImageParams_BindLua.h index e54497aaf..d5d9fb70b 100644 --- a/WickedEngine/wiImageParams_BindLua.h +++ b/WickedEngine/wiImageParams_BindLua.h @@ -6,13 +6,13 @@ class wiImageParams_BindLua { public: - wiImageParams effects; + wiImageParams params; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - wiImageParams_BindLua(const wiImageParams& effects); + wiImageParams_BindLua(const wiImageParams& params); wiImageParams_BindLua(lua_State *L); ~wiImageParams_BindLua(); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 57bc2e2dd..410b3e600 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -4131,20 +4131,20 @@ void PutWaterRipple(const std::string& image, const XMFLOAT3& pos) img->anim.fad=0.01f; img->anim.scaleX=0.2f; img->anim.scaleY=0.2f; - img->effects.pos=pos; - img->effects.rotation=(wiRandom::getRandom(0,1000)*0.001f)*2*3.1415f; - img->effects.siz=XMFLOAT2(1,1); - img->effects.typeFlag=WORLD; - img->effects.quality=QUALITY_ANISOTROPIC; - img->effects.pivot = XMFLOAT2(0.5f, 0.5f); - img->effects.lookAt=waterPlane; - img->effects.lookAt.w=1; + img->params.pos=pos; + img->params.rotation=(wiRandom::getRandom(0,1000)*0.001f)*2*3.1415f; + img->params.siz=XMFLOAT2(1,1); + img->params.typeFlag=WORLD; + img->params.quality=QUALITY_ANISOTROPIC; + img->params.pivot = XMFLOAT2(0.5f, 0.5f); + img->params.lookAt=waterPlane; + img->params.lookAt.w=1; waterRipples.push_back(img); } void ManageWaterRipples(){ while( !waterRipples.empty() && - (waterRipples.front()->effects.opacity <= 0 + FLT_EPSILON || waterRipples.front()->effects.fade==1) + (waterRipples.front()->params.opacity <= 0 + FLT_EPSILON || waterRipples.front()->params.fade==1) ) waterRipples.pop_front(); } diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index ee7992f7a..e6bee273e 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -25,106 +25,116 @@ wiSprite::wiSprite(const std::string& newTexture, wiResourceManager* contentHold Init(); CreateReference(newTexture,"",""); } -void wiSprite::Init(){ +void wiSprite::Init() +{ if (ContentHolder == nullptr) { ContentHolder = &wiResourceManager::GetGlobal(); } - texture=""; - mask=""; - normal=""; - name=""; - texturePointer=maskPointer=normalPointer=nullptr; + texture = ""; + mask = ""; + normal = ""; + name = ""; + texturePointer = maskPointer = normalPointer = nullptr; } -void wiSprite::CreateReference(const std::string& newTexture, const std::string& newMask, const std::string& newNormal){ - if(newTexture.length()) { +void wiSprite::CreateReference(const std::string& newTexture, const std::string& newMask, const std::string& newNormal) +{ + if (newTexture.length()) + { texture = newTexture; texturePointer = (Texture2D*)ContentHolder->add(newTexture); } - if(newMask.length()) { + if (newMask.length()) + { maskPointer = (Texture2D*)ContentHolder->add(newMask); - effects.setMaskMap( maskPointer ); + params.setMaskMap(maskPointer); mask = newMask; } - if(newNormal.length()) { + if (newNormal.length()) + { normalPointer = (Texture2D*)ContentHolder->add(newNormal); - //effects.setNormalMap( normalPointer ); normal = newNormal; } } -void wiSprite::CleanUp(){ +void wiSprite::CleanUp() +{ ContentHolder->del(texture); ContentHolder->del(normal); ContentHolder->del(mask); } -void wiSprite::Draw(Texture2D* refracRes, GRAPHICSTHREAD threadID){ - if(effects.opacity>0 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE) ){ - effects.setRefractionSource(refracRes); - wiImage::Draw(texturePointer,effects,threadID); +void wiSprite::Draw(Texture2D* refracRes, GRAPHICSTHREAD threadID) +{ + if(params.opacity>0 && ((params.blendFlag==BLENDMODE_ADDITIVE && params.fade<1) || params.blendFlag!=BLENDMODE_ADDITIVE) ) + { + params.setRefractionSource(refracRes); + wiImage::Draw(texturePointer,params,threadID); } } -void wiSprite::Draw(GRAPHICSTHREAD threadID){ +void wiSprite::Draw(GRAPHICSTHREAD threadID) +{ wiSprite::Draw(nullptr, threadID); } -void wiSprite::DrawNormal(GRAPHICSTHREAD threadID){ - if(normalPointer && effects.opacity>0 && ((effects.blendFlag==BLENDMODE_ADDITIVE && effects.fade<1) || effects.blendFlag!=BLENDMODE_ADDITIVE)){ - //effects.setRefractionMap(refracRes); - - wiImageParams effectsMod(effects); +void wiSprite::DrawNormal(GRAPHICSTHREAD threadID) +{ + if(normalPointer && params.opacity>0 && ((params.blendFlag==BLENDMODE_ADDITIVE && params.fade<1) || params.blendFlag!=BLENDMODE_ADDITIVE)) + { + wiImageParams effectsMod(params); effectsMod.blendFlag=BLENDMODE_ADDITIVE; - effectsMod.extractNormalMap=true; + effectsMod.enableExtractNormalMap(); wiImage::Draw(normalPointer,effectsMod,threadID); } } -void wiSprite::Update(float gameSpeed){ - effects.pos.x+=anim.vel.x*gameSpeed; - effects.pos.y+=anim.vel.y*gameSpeed; - effects.pos.z+=anim.vel.z*gameSpeed; - effects.rotation+=anim.rot*gameSpeed; - effects.scale.x+=anim.scaleX*gameSpeed; - effects.scale.y+=anim.scaleY*gameSpeed; - effects.opacity+=anim.opa*gameSpeed; - if(effects.opacity>=1) { - if(anim.repeatable) {effects.opacity=0.99f; anim.opa*=-1;} - else effects.opacity=1; - } - else if(effects.opacity<=0){ - if(anim.repeatable) {effects.opacity=0.01f; anim.opa*=-1;} - else effects.opacity=0; - } - effects.fade+=anim.fad*gameSpeed; - if(effects.fade>=1) { - if(anim.repeatable) {effects.fade=0.99f; anim.fad*=-1;} - else effects.fade=1; - } - else if(effects.fade<=0){ - if(anim.repeatable) {effects.fade=0.01f; anim.fad*=-1;} - else effects.fade=0; - } - - effects.texOffset.x+=anim.movingTexAnim.speedX*gameSpeed; - effects.texOffset.y+=anim.movingTexAnim.speedY*gameSpeed; - - if(anim.drawRecAnim.elapsedFrames>=anim.drawRecAnim.onFrameChangeWait){ - effects.drawRec.x+=effects.drawRec.z*anim.drawRecAnim.jumpX; - effects.drawRec.y+=effects.drawRec.w*anim.drawRecAnim.jumpY; +void wiSprite::Update(float gameSpeed) +{ + params.pos.x += anim.vel.x*gameSpeed; + params.pos.y += anim.vel.y*gameSpeed; + params.pos.z += anim.vel.z*gameSpeed; + params.rotation += anim.rot*gameSpeed; + params.scale.x += anim.scaleX*gameSpeed; + params.scale.y += anim.scaleY*gameSpeed; + params.opacity += anim.opa*gameSpeed; + if (params.opacity >= 1) { + if (anim.repeatable) { params.opacity = 0.99f; anim.opa *= -1; } + else params.opacity = 1; + } + else if (params.opacity <= 0) { + if (anim.repeatable) { params.opacity = 0.01f; anim.opa *= -1; } + else params.opacity = 0; + } + params.fade += anim.fad*gameSpeed; + if (params.fade >= 1) { + if (anim.repeatable) { params.fade = 0.99f; anim.fad *= -1; } + else params.fade = 1; + } + else if (params.fade <= 0) { + if (anim.repeatable) { params.fade = 0.01f; anim.fad *= -1; } + else params.fade = 0; + } - if(anim.drawRecAnim.currentFrame>=anim.drawRecAnim.frameCount){ - effects.drawRec.z-=anim.drawRecAnim.sizX*anim.drawRecAnim.frameCount; - effects.drawRec.w-=anim.drawRecAnim.sizY*anim.drawRecAnim.frameCount; - anim.drawRecAnim.currentFrame=0; + params.texOffset.x += anim.movingTexAnim.speedX*gameSpeed; + params.texOffset.y += anim.movingTexAnim.speedY*gameSpeed; + + if (anim.drawRecAnim.elapsedFrames >= anim.drawRecAnim.onFrameChangeWait) { + params.drawRect.x += params.drawRect.z*anim.drawRecAnim.jumpX; + params.drawRect.y += params.drawRect.w*anim.drawRecAnim.jumpY; + + if (anim.drawRecAnim.currentFrame >= anim.drawRecAnim.frameCount) { + params.drawRect.z -= anim.drawRecAnim.sizX*anim.drawRecAnim.frameCount; + params.drawRect.w -= anim.drawRecAnim.sizY*anim.drawRecAnim.frameCount; + anim.drawRecAnim.currentFrame = 0; } - else{ - effects.drawRec.z+=anim.drawRecAnim.sizX; - effects.drawRec.w+=anim.drawRecAnim.sizY; + else { + params.drawRect.z += anim.drawRecAnim.sizX; + params.drawRect.w += anim.drawRecAnim.sizY; anim.drawRecAnim.currentFrame++; } - anim.drawRecAnim.elapsedFrames=0; + anim.drawRecAnim.elapsedFrames = 0; } - else anim.drawRecAnim.elapsedFrames+=gameSpeed; + else anim.drawRecAnim.elapsedFrames += gameSpeed; } -void wiSprite::Update(){ +void wiSprite::Update() +{ Update(1); } diff --git a/WickedEngine/wiSprite.h b/WickedEngine/wiSprite.h index 7c2221aad..45fd18995 100644 --- a/WickedEngine/wiSprite.h +++ b/WickedEngine/wiSprite.h @@ -27,7 +27,7 @@ public: std::string name; - wiImageParams effects; + wiImageParams params; struct Anim{ struct MovingTexData{ diff --git a/WickedEngine/wiSprite_BindLua.cpp b/WickedEngine/wiSprite_BindLua.cpp index 61cbf668e..1110766c9 100644 --- a/WickedEngine/wiSprite_BindLua.cpp +++ b/WickedEngine/wiSprite_BindLua.cpp @@ -57,10 +57,10 @@ int wiSprite_BindLua::SetParams(lua_State *L) int argc = wiLua::SGetArgCount(L); if (argc > 0) { - wiImageParams_BindLua* effects = Luna::check(L, 1); - if (effects != nullptr) + wiImageParams_BindLua* params = Luna::check(L, 1); + if (params != nullptr) { - sprite->effects = effects->effects; + sprite->params = params->params; } } else @@ -76,7 +76,7 @@ int wiSprite_BindLua::GetParams(lua_State *L) wiLua::SError(L, "GetParams() sprite is null!"); return 0; } - Luna::push(L, new wiImageParams_BindLua(sprite->effects)); + Luna::push(L, new wiImageParams_BindLua(sprite->params)); return 1; } int wiSprite_BindLua::SetAnim(lua_State *L) diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 8d6779e75..fe022cc07 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 23; // minor bug fixes, alterations, refactors, updates - const int revision = 1; + const int revision = 2; long GetVersion() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 9a69898b3..7aabf313e 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -115,7 +115,7 @@ void wiWidget::RenderTooltip(wiGUI* gui) if (tooltipPos.x > wiRenderer::GetDevice()->GetScreenWidth() - textWidth) { tooltipPos.x -= textWidth + 10; - tooltipFont.props.posX = (int)tooltipPos.x; + tooltipFont.params.posX = (int)tooltipPos.x; } static const float _border = 2; @@ -127,8 +127,8 @@ void wiWidget::RenderTooltip(wiGUI* gui) if (!scriptTip.empty()) { tooltipFont.SetText(scriptTip); - tooltipFont.props.posY += (int)(fontHeight / 2); - tooltipFont.props.color = wiColor(25, 25, 25, 110); + tooltipFont.params.posY += (int)(fontHeight / 2); + tooltipFont.params.color = wiColor(25, 25, 25, 110); tooltipFont.Draw(gui->GetGraphicsThread()); } }