mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Minor cleanup, merge the two game background drawing functions
This commit is contained in:
1 parent
dd19523204
commit
a342e8c9dc
4 files changed
+24
-46
No files matched your search
+15
-14
@@ -1,3 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "Common/GPU/thin3d.h"
|
||||
#include "Common/Data/Text/I18n.h"
|
||||
@@ -31,12 +32,12 @@ static Draw::Texture *bgTexture;
|
||||
class Animation {
|
||||
public:
|
||||
virtual ~Animation() = default;
|
||||
virtual void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) = 0;
|
||||
virtual void Draw(UIContext &dc, double t, float alpha, Lin::Vec3 focus) = 0;
|
||||
};
|
||||
|
||||
class MovingBackground : public Animation {
|
||||
public:
|
||||
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
|
||||
void Draw(UIContext &dc, double t, float alpha, Lin::Vec3 focus) override {
|
||||
if (!bgTexture)
|
||||
return;
|
||||
|
||||
@@ -44,9 +45,9 @@ public:
|
||||
dc.GetDrawContext()->BindTexture(0, bgTexture);
|
||||
Bounds bounds = dc.GetBounds();
|
||||
|
||||
x = std::min(std::max(x / bounds.w, 0.0f), 1.0f) * XFAC;
|
||||
y = std::min(std::max(y / bounds.h, 0.0f), 1.0f) * YFAC;
|
||||
z = 1.0f + std::max(XFAC, YFAC) + (z - 1.0f) * ZFAC;
|
||||
const float x = std::min(std::max(focus.x / bounds.w, 0.0f), 1.0f) * XFAC;
|
||||
const float y = std::min(std::max(focus.y / bounds.h, 0.0f), 1.0f) * YFAC;
|
||||
const float z = 1.0f + std::max(XFAC, YFAC) + (focus.z - 1.0f) * ZFAC;
|
||||
|
||||
lastX_ = abs(x - lastX_) > 0.001f ? x * XSPEED + lastX_ * (1.0f - XSPEED) : x;
|
||||
lastY_ = abs(y - lastY_) > 0.001f ? y * YSPEED + lastY_ * (1.0f - YSPEED) : y;
|
||||
@@ -78,7 +79,7 @@ private:
|
||||
|
||||
class WaveAnimation : public Animation {
|
||||
public:
|
||||
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
|
||||
void Draw(UIContext &dc, double t, float alpha, Lin::Vec3 focus) override {
|
||||
const uint32_t color = colorAlpha(0xFFFFFFFF, alpha * 0.2f);
|
||||
const float speed = 1.0;
|
||||
|
||||
@@ -117,7 +118,7 @@ public:
|
||||
this->is_colored = is_colored;
|
||||
}
|
||||
|
||||
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
|
||||
void Draw(UIContext &dc, double t, float alpha, Lin::Vec3 focus) override {
|
||||
float xres = dc.GetBounds().w;
|
||||
float yres = dc.GetBounds().h;
|
||||
|
||||
@@ -172,7 +173,7 @@ const ImageID FloatingSymbolsAnimation::SYMBOLS[4] = {
|
||||
|
||||
class RecentGamesAnimation : public Animation {
|
||||
public:
|
||||
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
|
||||
void Draw(UIContext &dc, double t, float alpha, Lin::Vec3 focus) override {
|
||||
if (lastIndex_ == nextIndex_) {
|
||||
CheckNext(dc, t);
|
||||
} else if (t > nextT_) {
|
||||
@@ -257,7 +258,7 @@ private:
|
||||
|
||||
class BouncingIconAnimation : public Animation {
|
||||
public:
|
||||
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
|
||||
void Draw(UIContext &dc, double t, float alpha, Lin::Vec3 focus) override {
|
||||
dc.Flush();
|
||||
dc.Begin();
|
||||
|
||||
@@ -379,7 +380,7 @@ void UIBackgroundShutdown() {
|
||||
g_CurBackgroundAnimation = BackgroundAnimation::OFF;
|
||||
}
|
||||
|
||||
void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
|
||||
void DrawBackground(UIContext &dc, float alpha, Lin::Vec3 focus) {
|
||||
if (!bgTextureInited) {
|
||||
UIBackgroundInit(dc);
|
||||
bgTextureInited = true;
|
||||
@@ -440,7 +441,7 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
|
||||
#endif
|
||||
|
||||
if (g_Animation) {
|
||||
g_Animation->Draw(dc, t, alpha, x, y, z);
|
||||
g_Animation->Draw(dc, t, alpha, focus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,7 +455,7 @@ enum class BackgroundFillMode {
|
||||
FitToScreen = 2,
|
||||
};
|
||||
|
||||
void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z) {
|
||||
void DrawGameBackground(UIContext &dc, const Path &gamePath, Lin::Vec3 focus, float alpha) {
|
||||
using namespace Draw;
|
||||
using namespace UI;
|
||||
dc.Flush();
|
||||
@@ -467,7 +468,7 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, f
|
||||
GameInfoTex *pic = (ginfo && ginfo->Ready(GameInfoFlags::PIC1)) ? ginfo->GetPIC1() : nullptr;
|
||||
if (pic && pic->texture) {
|
||||
dc.GetDrawContext()->BindTexture(0, pic->texture);
|
||||
uint32_t color = whiteAlpha(ease((time_now_d() - pic->timeLoaded) * 3)) & 0xFFc0c0c0;
|
||||
uint32_t color = whiteAlpha(std::clamp(ease((time_now_d() - pic->timeLoaded) * 3.0f) * alpha, 0.0f, 1.0f)) & 0xFFc0c0c0;
|
||||
|
||||
// TODO: Make this configurable?
|
||||
const BackgroundFillMode mode = BackgroundFillMode::CropToScreen;
|
||||
@@ -504,7 +505,7 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, f
|
||||
dc.Flush();
|
||||
dc.RebindTexture();
|
||||
} else {
|
||||
::DrawBackground(dc, 1.0f, x, y, z);
|
||||
::DrawBackground(dc, 1.0f, focus);
|
||||
dc.RebindTexture();
|
||||
dc.Flush();
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/Math/lin/vec3.h"
|
||||
|
||||
class UIContext;
|
||||
|
||||
@@ -8,7 +9,7 @@ extern Path boot_filename;
|
||||
|
||||
void UIBackgroundInit(UIContext &dc);
|
||||
void UIBackgroundShutdown();
|
||||
void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z);
|
||||
void DrawBackground(UIContext &dc, float alpha, float x, float y, float z);
|
||||
void DrawGameBackground(UIContext &dc, const Path &gamePath, Lin::Vec3 focus, float alpha);
|
||||
void DrawBackground(UIContext &dc, float alpha, Lin::Vec3 focus);
|
||||
|
||||
uint32_t GetBackgroundColorWithAlpha(const UIContext &dc);
|
||||
+2
-26
@@ -64,6 +64,7 @@
|
||||
#include "UI/Store.h"
|
||||
#include "UI/UploadScreen.h"
|
||||
#include "UI/InstallZipScreen.h"
|
||||
#include "UI/Background.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/Loaders.h"
|
||||
#include "Common/Data/Text/I18n.h"
|
||||
@@ -1542,32 +1543,7 @@ void MainScreen::DrawBackground(UIContext &dc) {
|
||||
}
|
||||
|
||||
bool MainScreen::DrawBackgroundFor(UIContext &dc, const Path &gamePath, float progress) {
|
||||
dc.Flush();
|
||||
|
||||
std::shared_ptr<GameInfo> ginfo;
|
||||
if (!gamePath.empty()) {
|
||||
ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath, GameInfoFlags::PIC1);
|
||||
// Loading texture data may bind a texture.
|
||||
dc.RebindTexture();
|
||||
|
||||
// Let's not bother if there's no picture.
|
||||
if (!ginfo->Ready(GameInfoFlags::PIC1) || !ginfo->pic1.texture) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pic = ginfo->GetPIC1();
|
||||
Draw::Texture *texture = pic ? pic->texture : nullptr;
|
||||
|
||||
uint32_t color = whiteAlpha(ease(progress)) & 0xFFc0c0c0;
|
||||
if (texture) {
|
||||
dc.GetDrawContext()->BindTexture(0, texture);
|
||||
dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, color);
|
||||
dc.Flush();
|
||||
dc.RebindTexture();
|
||||
}
|
||||
::DrawGameBackground(dc, gamePath, Lin::Vec3(0.f, 0.f, 0.f), progress);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -109,13 +109,13 @@ ScreenRenderFlags BackgroundScreen::render(ScreenRenderMode mode) {
|
||||
uiContext->PushTransform({ translation_, scale_, alpha_ });
|
||||
|
||||
uiContext->Begin();
|
||||
float x, y, z;
|
||||
screenManager()->getFocusPosition(x, y, z);
|
||||
Lin::Vec3 focus;
|
||||
screenManager()->getFocusPosition(focus.x, focus.y, focus.z);
|
||||
|
||||
if (!gamePath_.empty()) {
|
||||
::DrawGameBackground(*uiContext, gamePath_, x, y, z);
|
||||
::DrawGameBackground(*uiContext, gamePath_, focus, 1.0f);
|
||||
} else {
|
||||
::DrawBackground(*uiContext, 1.0f, x, y, z);
|
||||
::DrawBackground(*uiContext, 1.0f, focus);
|
||||
}
|
||||
|
||||
uiContext->Flush();
|
||||
|
||||
Reference in new issue
Block a user