1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-21 04:11:53 +02:00

fix black inventory background on android; hiding touch controls for current game state;

This commit is contained in:
XProger
2018-07-31 05:45:18 +03:00
parent 1773dd90c9
commit cee28bd1c1
7 changed files with 87 additions and 59 deletions

View File

@@ -718,13 +718,9 @@ struct WaterCache {
int w, h; int w, h;
getTargetSize(w, h); getTargetSize(w, h);
// get refraction texture // get refraction texture
if (!refract || w != refract->origWidth || h != refract->origHeight) { if (!refract || w > refract->origWidth || h > refract->origHeight) {
delete refract; delete refract;
refract = new Texture(w, h, FMT_RGBA, OPT_TARGET); refract = new Texture(w, h, FMT_RGBA, OPT_TARGET);
Core::setTarget(refract, RT_CLEAR_COLOR | RT_STORE_COLOR);
Core::validateRenderState();
Core::setTarget(NULL, RT_STORE_COLOR);
Core::validateRenderState();
} }
Core::copyTarget(refract, 0, 0, int(Core::viewportDef.x), int(Core::viewportDef.y), w, h); // copy framebuffer into refraction texture Core::copyTarget(refract, 0, 0, int(Core::viewportDef.x), int(Core::viewportDef.y), w, h); // copy framebuffer into refraction texture
} }

View File

@@ -948,11 +948,11 @@ namespace Core {
} }
void endFrame() { void endFrame() {
GAPI::endFrame();
if (active.target != defaultTarget) { if (active.target != defaultTarget) {
GAPI::setTarget(NULL, 0); GAPI::setTarget(NULL, 0);
validateRenderState(); validateRenderState();
} }
GAPI::endFrame();
Core::stats.stop(); Core::stats.stop();
} }

View File

@@ -56,13 +56,15 @@ namespace Input {
} }
} hmd; } hmd;
enum TouchButton { bNone, bWeapon, bWalk, bAction, bJump, bInventory, bMAX }; enum TouchButton { bMove, bWeapon, bWalk, bAction, bJump, bInventory, bMAX };
enum TouchZone { zMove, zLook, zButton, zMAX }; enum TouchZone { zMove, zLook, zButton, zMAX };
float touchTimerVis, touchTimerTap; float touchTimerVis, touchTimerTap;
InputKey touchKey[zMAX]; InputKey touchKey[zMAX];
TouchButton btn; TouchButton btn;
vec2 btnPos[bMAX]; vec2 btnPos[bMAX];
bool btnEnable[bMAX];
float btnRadius; float btnRadius;
bool doubleTap; bool doubleTap;
@@ -170,6 +172,7 @@ namespace Input {
touchTimerTap = 0.0f; touchTimerTap = 0.0f;
doubleTap = false; doubleTap = false;
touchKey[zMove] = touchKey[zLook] = touchKey[zButton] = ikNone; touchKey[zMove] = touchKey[zLook] = touchKey[zButton] = ikNone;
memset(btnEnable, 1, sizeof(btnEnable));
} }
bool checkTouchZone(TouchZone zone) { bool checkTouchZone(TouchZone zone) {
@@ -195,17 +198,21 @@ namespace Input {
dir = delta; dir = delta;
} }
void setState(int playerIndex, ControlKey key, bool down) {
if (down && !state[playerIndex][key])
lastState[playerIndex] = key;
state[playerIndex][key] = down;
}
void update() { void update() {
bool newState[MAX_PLAYERS][cMAX];
for (int j = 0; j < COUNT(Core::settings.controls); j++) { for (int j = 0; j < COUNT(Core::settings.controls); j++) {
lastState[j] = cMAX; lastState[j] = cMAX;
Core::Settings::Controls &ctrl = Core::settings.controls[j]; Core::Settings::Controls &ctrl = Core::settings.controls[j];
for (int i = 0; i < cMAX; i++) { for (int i = 0; i < cMAX; i++) {
KeySet &c = ctrl.keys[i]; KeySet &c = ctrl.keys[i];
bool active = (c.key != ikNone && down[c.key]) || (c.joy != jkNone && joy[ctrl.joyIndex].down[c.joy]); newState[j][i] = (c.key != ikNone && down[c.key]) || (c.joy != jkNone && joy[ctrl.joyIndex].down[c.joy]);
if (active && !state[j][i])
lastState[j] = ControlKey(i);
state[j][i] = active;
} }
} }
@@ -237,13 +244,11 @@ namespace Input {
if (checkTouchZone(zMove)) if (checkTouchZone(zMove))
joy.L = vec2(0.0f); joy.L = vec2(0.0f);
if (checkTouchZone(zLook)) { if (checkTouchZone(zLook))
joy.L = vec2(0.0f); joy.L = vec2(0.0f);
state[0][cLook] = false;
}
if (checkTouchZone(zButton)) if (checkTouchZone(zButton))
btn = bNone; btn = bMove; // no active buttons == bNone
if (doubleTap) if (doubleTap)
doubleTap = false; doubleTap = false;
@@ -268,12 +273,11 @@ namespace Input {
} else } else
touchTimerTap = 0.3f; touchTimerTap = 0.3f;
} }
if (zone == zLook)
state[0][cLook] = true;
} }
} }
newState[0][cLook] |= touchKey[zLook] != ikNone;
// set active touches as gamepad controls // set active touches as gamepad controls
getTouchDir(touchKey[zMove], joy.L); getTouchDir(touchKey[zMove], joy.L);
getTouchDir(touchKey[zLook], joy.R); getTouchDir(touchKey[zLook], joy.R);
@@ -283,26 +287,31 @@ namespace Input {
btn = bMAX; btn = bMAX;
float minDist = btnRadius * 8.0f; float minDist = btnRadius * 8.0f;
for (int i = 0; i < bMAX; i++) { for (int i = 0; i < bMAX; i++)
float d = (pos - btnPos[i]).length(); if (btnEnable[i]) {
if (d < minDist) { float d = (pos - btnPos[i]).length();
minDist = d; if (d < minDist) {
btn = TouchButton(i); minDist = d;
btn = TouchButton(i);
}
} }
}
switch (btn) { switch (btn) {
case bWeapon : state[0][cWeapon] = true; break; case bWeapon : newState[0][cWeapon ] = true; break;
case bWalk : state[0][cWalk] = true; break; case bWalk : newState[0][cWalk ] = true; break;
case bAction : state[0][cAction] = true; break; case bAction : newState[0][cAction ] = true; break;
case bJump : state[0][cJump] = true; break; case bJump : newState[0][cJump ] = true; break;
case bInventory : state[0][cInventory] = true; break; case bInventory : newState[0][cInventory] = true; break;
default : ; default : ;
} }
} }
if (doubleTap) if (doubleTap)
state[0][cRoll] = true; newState[0][cRoll] = true;
for (int j = 0; j < COUNT(Core::settings.controls); j++)
for (int i = 0; i < cMAX; i++)
setState(j, ControlKey(i), newState[j][i]);
} }
} }

View File

@@ -468,7 +468,7 @@ struct Inventory {
inv->titleTimer = 0.0f; inv->titleTimer = 0.0f;
return; return;
} }
inv->titleTimer = 3.0f; inv->titleTimer = inv->game->getLevel()->isTitle() ? 0.0f : 3.0f;
inv->background[0] = Texture::Load(*stream); inv->background[0] = Texture::Load(*stream);
delete stream; delete stream;

View File

@@ -776,7 +776,6 @@ struct Lara : Character {
if (dozy) return true; if (dozy) return true;
return wpnCurrent != Weapon::EMPTY return wpnCurrent != Weapon::EMPTY
&& emptyHands()
&& animation.index != ANIM_CLIMB_3 && animation.index != ANIM_CLIMB_3
&& animation.index != ANIM_CLIMB_2 && animation.index != ANIM_CLIMB_2
&& state != STATE_DEATH && state != STATE_DEATH

View File

@@ -50,6 +50,9 @@ struct Level : IGame {
bool lastTitle; bool lastTitle;
bool isEnded; bool isEnded;
bool needRedrawTitleBG;
bool needRedrawReflections;
bool needRenderGame;
TR::Effect::Type effect; TR::Effect::Type effect;
float effectTimer; float effectTimer;
@@ -279,12 +282,8 @@ struct Level : IGame {
waterCache = Core::settings.detail.water > Core::Settings::LOW ? new WaterCache(this) : NULL; waterCache = Core::settings.detail.water > Core::Settings::LOW ? new WaterCache(this) : NULL;
} }
if (redraw && inventory->active && !level.isTitle()) { if (redraw && inventory->active && !level.isTitle())
Core::reset(); needRedrawTitleBG = true;
Core::beginFrame();
inventory->prepareBackground();
Core::endFrame();
}
} }
virtual TR::Level* getLevel() { virtual TR::Level* getLevel() {
@@ -715,6 +714,9 @@ struct Level : IGame {
waterCache = NULL; waterCache = NULL;
zoneCache = NULL; zoneCache = NULL;
needRedrawTitleBG = false;
needRedrawReflections = true;
if (!(lastTitle = level.isTitle())) { if (!(lastTitle = level.isTitle())) {
ASSERT(players[0] != NULL); ASSERT(players[0] != NULL);
player = players[0]; player = players[0];
@@ -724,9 +726,12 @@ struct Level : IGame {
ambientCache = Core::settings.detail.lighting > Core::Settings::MEDIUM ? new AmbientCache(this) : NULL; ambientCache = Core::settings.detail.lighting > Core::Settings::MEDIUM ? new AmbientCache(this) : NULL;
waterCache = Core::settings.detail.water > Core::Settings::LOW ? new WaterCache(this) : NULL; waterCache = Core::settings.detail.water > Core::Settings::LOW ? new WaterCache(this) : NULL;
initShadow(); if (ambientCache) { // at first calculate ambient cube for Lara
AmbientCache::Cube cube;
ambientCache->getAmbient(players[0]->getRoomIndex(), players[0]->pos, cube); // add to queue
}
initReflections(); initShadow();
for (int i = 0; i < level.soundSourcesCount; i++) { for (int i = 0; i < level.soundSourcesCount; i++) {
TR::SoundSource &src = level.soundSources[i]; TR::SoundSource &src = level.soundSources[i];
@@ -1287,8 +1292,6 @@ struct Level : IGame {
} }
void initReflections() { void initReflections() {
Core::reset();
Core::beginFrame();
for (int i = 0; i < level.entitiesBaseCount; i++) { for (int i = 0; i < level.entitiesBaseCount; i++) {
TR::Entity &e = level.entities[i]; TR::Entity &e = level.entities[i];
if (e.type == TR::Entity::CRYSTAL) { if (e.type == TR::Entity::CRYSTAL) {
@@ -1297,7 +1300,6 @@ struct Level : IGame {
c->environment->generateMipMap(); c->environment->generateMipMap();
} }
} }
Core::endFrame();
} }
void setMainLight(Controller *controller) { void setMainLight(Controller *controller) {
@@ -1526,6 +1528,18 @@ struct Level : IGame {
} }
void update() { void update() {
bool invRing = inventory->phaseRing != 0.0f && inventory->phaseRing != 1.0f;
if (inventory->video || inventory->titleTimer >= 1.0f || level.isCutsceneLevel() || invRing) {
memset(Input::btnEnable, 0, sizeof(Input::btnEnable));
Input::btnEnable[Input::bInventory] = !invRing;
} else
memset(Input::btnEnable, 1, sizeof(Input::btnEnable));
Input::btnEnable[Input::bWeapon] &= players[0] && players[0]->canDrawWeapon();
if (inventory->isActive())
Input::btnEnable[Input::bWalk] = Input::btnEnable[Input::bJump] = Input::btnEnable[Input::bWeapon] = false;
if (inventory->video) { if (inventory->video) {
inventory->update(); inventory->update();
return; return;
@@ -2467,6 +2481,16 @@ struct Level : IGame {
return; return;
} }
needRenderGame = !inventory->video && !level.isTitle() && ((inventory->phaseRing < 1.0f && inventory->titleTimer <= 1.0f) || needRedrawTitleBG);
if (!needRenderGame)
return;
if (needRedrawReflections) {
initReflections();
needRedrawReflections = false;
}
if (ambientCache) if (ambientCache)
ambientCache->processQueue(); ambientCache->processQueue();
@@ -2662,11 +2686,12 @@ struct Level : IGame {
void render() { void render() {
bool title = inventory->isActive() || level.isTitle(); bool title = inventory->isActive() || level.isTitle();
bool copyBg = title && lastTitle != title; bool copyBg = title && (lastTitle != title || needRedrawTitleBG);
lastTitle = title; lastTitle = title;
needRedrawTitleBG = false;
if (isEnded) { if (isEnded) {
Core::setTarget(NULL, RT_CLEAR_COLOR); Core::setTarget(NULL, RT_CLEAR_COLOR | RT_STORE_COLOR);
UI::begin(); UI::begin();
UI::updateAspect(float(Core::width) / float(Core::height)); UI::updateAspect(float(Core::width) / float(Core::height));
UI::textOut(vec2(0, 480 - 16), STR_LOADING, UI::aCenter, UI::width); UI::textOut(vec2(0, 480 - 16), STR_LOADING, UI::aCenter, UI::width);
@@ -2678,12 +2703,8 @@ struct Level : IGame {
inventory->prepareBackground(); inventory->prepareBackground();
} }
if (!level.isTitle()) { if (needRenderGame)
if (inventory->phaseRing < 1.0f && inventory->titleTimer <= 1.0f) { renderGame(true);
renderGame(true);
title = false;
}
}
renderInventory(); renderInventory();
} }

View File

@@ -499,16 +499,19 @@ namespace UI {
float offset = Core::height * 0.25f; float offset = Core::height * 0.25f;
vec2 pos = vec2(offset, Core::height - offset); if (Input::btnEnable[Input::bMove]) {
if (Input::down[Input::touchKey[Input::zMove]]) { vec2 pos = vec2(offset * 0.7f, Core::height - offset * 0.7f) + vec2(-cosf(-PI * 3.0f / 4.0f), sinf(-PI * 3.0f / 4.0f)) * offset;
Input::Touch &t = Input::touch[Input::touchKey[Input::zMove] - ikTouchA]; if (Input::down[Input::touchKey[Input::zMove]]) {
renderControl(t.pos, Input::btnRadius, true); Input::Touch &t = Input::touch[Input::touchKey[Input::zMove] - ikTouchA];
pos = t.start; renderControl(t.pos, Input::btnRadius, true);
pos = t.start;
}
renderControl(pos, Input::btnRadius, false);
} }
renderControl(pos, Input::btnRadius, false);
for (int i = Input::bWeapon; i < Input::bMAX; i++) for (int i = Input::bWeapon; i < Input::bMAX; i++)
renderControl(Input::btnPos[i], Input::btnRadius, Input::btn == i); if (Input::btnEnable[i])
renderControl(Input::btnPos[i], Input::btnRadius, Input::btn == i);
Core::setCullMode(cmFront); Core::setCullMode(cmFront);
Core::setBlendMode(bmNone); Core::setBlendMode(bmNone);