Read both pic0 and pic1 and draw them on the pause screen.

This commit is contained in:
Henrik Rydgard 2013-04-01 12:35:02 +02:00
parent 9472de580d
commit 8aee82535b
5 changed files with 71 additions and 22 deletions

View File

@ -37,12 +37,16 @@ GameInfoCache::~GameInfoCache()
static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents)
{
PSPFileInfo info = fs->GetFileInfo(filename);
if (!info.exists)
if (!info.exists) {
contents->clear();
return false;
}
int handle = fs->OpenFile(filename, FILEACCESS_READ);
if (!handle)
if (!handle) {
contents->clear();
return false;
}
contents->resize(info.size);
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
@ -55,19 +59,32 @@ void GameInfoCache::Save()
// TODO
}
void GameInfoCache::Load()
{
void GameInfoCache::Load() {
// TODO
}
void GameInfoCache::Decimate()
{
void GameInfoCache::Decimate() {
// TODO
}
void GameInfoCache::FlushBGs()
{
// TODO
void GameInfoCache::FlushBGs() {
for (auto iter = info_.begin(); iter != info_.end(); iter++) {
lock_guard lock(iter->second->lock);
if (!iter->second->pic0TextureData.empty()) {
iter->second->pic0TextureData.clear();
}
if (iter->second->pic0Texture) {
delete iter->second->pic0Texture;
iter->second->pic0Texture = 0;
}
if (!iter->second->pic1TextureData.empty()) {
iter->second->pic1TextureData.clear();
}
if (iter->second->pic1Texture) {
delete iter->second->pic1Texture;
iter->second->pic1Texture = 0;
}
}
}
// This may run off-main-thread and we thus can't use the global
@ -91,12 +108,19 @@ GameInfo *GameInfoCache::GetInfo(const std::string &gamePath, bool wantBG) {
}
info->iconTextureData.clear();
}
if (info->bgTextureData.size()) {
info->bgTexture = new Texture();
if (info->bgTexture->LoadPNG((const u8 *)info->bgTextureData.data(), info->bgTextureData.size(), false)) {
info->timeBgWasLoaded = time_now_d();
if (info->pic0TextureData.size()) {
info->pic0Texture = new Texture();
if (info->pic0Texture->LoadPNG((const u8 *)info->pic0TextureData.data(), info->pic0TextureData.size(), false)) {
info->timePic0WasLoaded = time_now_d();
}
info->bgTextureData.clear();
info->pic0TextureData.clear();
}
if (info->pic1TextureData.size()) {
info->pic1Texture = new Texture();
if (info->pic1Texture->LoadPNG((const u8 *)info->pic1TextureData.data(), info->pic1TextureData.size(), false)) {
info->timePic1WasLoaded = time_now_d();
}
info->pic1TextureData.clear();
}
iter->second->lastAccessedTime = time_now_d();
return iter->second;
@ -138,7 +162,14 @@ again:
ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info->iconTextureData);
if (wantBG) {
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info->bgTextureData);
{
lock_guard lock(info->lock);
ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info->pic0TextureData);
}
{
lock_guard lock(info->lock);
ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info->pic1TextureData);
}
}
info_[gamePath] = info;
return info;

View File

@ -25,7 +25,7 @@
#include "Core/ELF/ParamSFO.h"
struct GameInfo {
GameInfo() : iconTexture(NULL), bgTexture(NULL) {}
GameInfo() : iconTexture(NULL), pic0Texture(NULL), pic1Texture(NULL) {}
// Hold this when reading or writing from the GameInfo.
// Don't need to hold it when just passing around the pointer,
// and obviously also not when creating it and holding the only pointer
@ -38,8 +38,10 @@ struct GameInfo {
// Pre read the data, create a texture the next time (GL thread..)
std::string iconTextureData;
Texture *iconTexture;
std::string bgTextureData;
Texture *bgTexture;
std::string pic0TextureData;
Texture *pic0Texture;
std::string pic1TextureData;
Texture *pic1Texture;
bool wantBG;
@ -48,7 +50,8 @@ struct GameInfo {
// The time at which the Icon and the BG were loaded.
// Can be useful to fade them in smoothly once they appear.
double timeIconWasLoaded;
double timeBgWasLoaded;
double timePic0WasLoaded;
double timePic1WasLoaded;
};
class GameInfoCache {

View File

@ -316,13 +316,23 @@ void PauseScreen::render() {
UIFlush();
GameInfo *ginfo = g_gameInfoCache.GetInfo(PSP_CoreParameter().fileToStart, true);
if (ginfo && ginfo->bgTexture) {
ginfo->bgTexture->Bind(0);
if (ginfo && ginfo->pic1Texture) {
ginfo->pic1Texture->Bind(0);
ui_draw2d.DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,0xFFc0c0c0);
ui_draw2d.Flush();
ctx->RebindTexture();
}
if (ginfo && ginfo->pic0Texture) {
ginfo->pic0Texture->Bind(0);
// Pic0 is drawn in the bottom right corner, overlaying pic1.
float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width();
float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height();
ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,0xFFc0c0c0);
ui_draw2d.Flush();
ctx->RebindTexture();
}
if (ginfo && ginfo->iconTexture) {
ginfo->iconTexture->Bind(0);
ui_draw2d.DrawTexRect(10,10,10+144, 10+80, 0,0,1,1,0xFFFFFFFF);

View File

@ -45,6 +45,11 @@ int XinputDevice::UpdateState(InputState &input_state) {
input_state.pad_lstick_y += left.y;
input_state.pad_rstick_x += right.x;
input_state.pad_rstick_y += right.y;
// Also convert the analog triggers.
input_state.pad_ltrigger = state.Gamepad.bLeftTrigger / 255.0f;
input_state.pad_rtrigger = state.Gamepad.bRightTrigger / 255.0f;
this->prevState = state;
this->check_delay = 0;
return 0;

2
native

@ -1 +1 @@
Subproject commit 79e14282ecf006caef6fe12d19358952741ad7fc
Subproject commit 4b0631ccc5210f95d3c70a4d9f130750cf868049