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:
@@ -718,13 +718,9 @@ struct WaterCache {
|
||||
int w, h;
|
||||
getTargetSize(w, h);
|
||||
// get refraction texture
|
||||
if (!refract || w != refract->origWidth || h != refract->origHeight) {
|
||||
if (!refract || w > refract->origWidth || h > refract->origHeight) {
|
||||
delete refract;
|
||||
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
|
||||
}
|
||||
|
@@ -948,11 +948,11 @@ namespace Core {
|
||||
}
|
||||
|
||||
void endFrame() {
|
||||
GAPI::endFrame();
|
||||
if (active.target != defaultTarget) {
|
||||
GAPI::setTarget(NULL, 0);
|
||||
validateRenderState();
|
||||
}
|
||||
GAPI::endFrame();
|
||||
Core::stats.stop();
|
||||
}
|
||||
|
||||
|
59
src/input.h
59
src/input.h
@@ -56,13 +56,15 @@ namespace Input {
|
||||
}
|
||||
} 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 };
|
||||
|
||||
float touchTimerVis, touchTimerTap;
|
||||
InputKey touchKey[zMAX];
|
||||
|
||||
TouchButton btn;
|
||||
vec2 btnPos[bMAX];
|
||||
bool btnEnable[bMAX];
|
||||
float btnRadius;
|
||||
bool doubleTap;
|
||||
|
||||
@@ -170,6 +172,7 @@ namespace Input {
|
||||
touchTimerTap = 0.0f;
|
||||
doubleTap = false;
|
||||
touchKey[zMove] = touchKey[zLook] = touchKey[zButton] = ikNone;
|
||||
memset(btnEnable, 1, sizeof(btnEnable));
|
||||
}
|
||||
|
||||
bool checkTouchZone(TouchZone zone) {
|
||||
@@ -195,17 +198,21 @@ namespace Input {
|
||||
dir = delta;
|
||||
}
|
||||
|
||||
void setState(int playerIndex, ControlKey key, bool down) {
|
||||
if (down && !state[playerIndex][key])
|
||||
lastState[playerIndex] = key;
|
||||
state[playerIndex][key] = down;
|
||||
}
|
||||
|
||||
void update() {
|
||||
bool newState[MAX_PLAYERS][cMAX];
|
||||
|
||||
for (int j = 0; j < COUNT(Core::settings.controls); j++) {
|
||||
lastState[j] = cMAX;
|
||||
|
||||
Core::Settings::Controls &ctrl = Core::settings.controls[j];
|
||||
for (int i = 0; i < cMAX; i++) {
|
||||
KeySet &c = ctrl.keys[i];
|
||||
bool active = (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;
|
||||
newState[j][i] = (c.key != ikNone && down[c.key]) || (c.joy != jkNone && joy[ctrl.joyIndex].down[c.joy]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,13 +244,11 @@ namespace Input {
|
||||
if (checkTouchZone(zMove))
|
||||
joy.L = vec2(0.0f);
|
||||
|
||||
if (checkTouchZone(zLook)) {
|
||||
if (checkTouchZone(zLook))
|
||||
joy.L = vec2(0.0f);
|
||||
state[0][cLook] = false;
|
||||
}
|
||||
|
||||
if (checkTouchZone(zButton))
|
||||
btn = bNone;
|
||||
btn = bMove; // no active buttons == bNone
|
||||
|
||||
if (doubleTap)
|
||||
doubleTap = false;
|
||||
@@ -268,12 +273,11 @@ namespace Input {
|
||||
} else
|
||||
touchTimerTap = 0.3f;
|
||||
}
|
||||
|
||||
if (zone == zLook)
|
||||
state[0][cLook] = true;
|
||||
}
|
||||
}
|
||||
|
||||
newState[0][cLook] |= touchKey[zLook] != ikNone;
|
||||
|
||||
// set active touches as gamepad controls
|
||||
getTouchDir(touchKey[zMove], joy.L);
|
||||
getTouchDir(touchKey[zLook], joy.R);
|
||||
@@ -283,26 +287,31 @@ namespace Input {
|
||||
|
||||
btn = bMAX;
|
||||
float minDist = btnRadius * 8.0f;
|
||||
for (int i = 0; i < bMAX; i++) {
|
||||
float d = (pos - btnPos[i]).length();
|
||||
if (d < minDist) {
|
||||
minDist = d;
|
||||
btn = TouchButton(i);
|
||||
for (int i = 0; i < bMAX; i++)
|
||||
if (btnEnable[i]) {
|
||||
float d = (pos - btnPos[i]).length();
|
||||
if (d < minDist) {
|
||||
minDist = d;
|
||||
btn = TouchButton(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (btn) {
|
||||
case bWeapon : state[0][cWeapon] = true; break;
|
||||
case bWalk : state[0][cWalk] = true; break;
|
||||
case bAction : state[0][cAction] = true; break;
|
||||
case bJump : state[0][cJump] = true; break;
|
||||
case bInventory : state[0][cInventory] = true; break;
|
||||
case bWeapon : newState[0][cWeapon ] = true; break;
|
||||
case bWalk : newState[0][cWalk ] = true; break;
|
||||
case bAction : newState[0][cAction ] = true; break;
|
||||
case bJump : newState[0][cJump ] = true; break;
|
||||
case bInventory : newState[0][cInventory] = true; break;
|
||||
default : ;
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -468,7 +468,7 @@ struct Inventory {
|
||||
inv->titleTimer = 0.0f;
|
||||
return;
|
||||
}
|
||||
inv->titleTimer = 3.0f;
|
||||
inv->titleTimer = inv->game->getLevel()->isTitle() ? 0.0f : 3.0f;
|
||||
|
||||
inv->background[0] = Texture::Load(*stream);
|
||||
delete stream;
|
||||
|
@@ -776,7 +776,6 @@ struct Lara : Character {
|
||||
if (dozy) return true;
|
||||
|
||||
return wpnCurrent != Weapon::EMPTY
|
||||
&& emptyHands()
|
||||
&& animation.index != ANIM_CLIMB_3
|
||||
&& animation.index != ANIM_CLIMB_2
|
||||
&& state != STATE_DEATH
|
||||
|
59
src/level.h
59
src/level.h
@@ -50,6 +50,9 @@ struct Level : IGame {
|
||||
|
||||
bool lastTitle;
|
||||
bool isEnded;
|
||||
bool needRedrawTitleBG;
|
||||
bool needRedrawReflections;
|
||||
bool needRenderGame;
|
||||
|
||||
TR::Effect::Type effect;
|
||||
float effectTimer;
|
||||
@@ -279,12 +282,8 @@ struct Level : IGame {
|
||||
waterCache = Core::settings.detail.water > Core::Settings::LOW ? new WaterCache(this) : NULL;
|
||||
}
|
||||
|
||||
if (redraw && inventory->active && !level.isTitle()) {
|
||||
Core::reset();
|
||||
Core::beginFrame();
|
||||
inventory->prepareBackground();
|
||||
Core::endFrame();
|
||||
}
|
||||
if (redraw && inventory->active && !level.isTitle())
|
||||
needRedrawTitleBG = true;
|
||||
}
|
||||
|
||||
virtual TR::Level* getLevel() {
|
||||
@@ -715,6 +714,9 @@ struct Level : IGame {
|
||||
waterCache = NULL;
|
||||
zoneCache = NULL;
|
||||
|
||||
needRedrawTitleBG = false;
|
||||
needRedrawReflections = true;
|
||||
|
||||
if (!(lastTitle = level.isTitle())) {
|
||||
ASSERT(players[0] != NULL);
|
||||
player = players[0];
|
||||
@@ -724,9 +726,12 @@ struct Level : IGame {
|
||||
ambientCache = Core::settings.detail.lighting > Core::Settings::MEDIUM ? new AmbientCache(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++) {
|
||||
TR::SoundSource &src = level.soundSources[i];
|
||||
@@ -1287,8 +1292,6 @@ struct Level : IGame {
|
||||
}
|
||||
|
||||
void initReflections() {
|
||||
Core::reset();
|
||||
Core::beginFrame();
|
||||
for (int i = 0; i < level.entitiesBaseCount; i++) {
|
||||
TR::Entity &e = level.entities[i];
|
||||
if (e.type == TR::Entity::CRYSTAL) {
|
||||
@@ -1297,7 +1300,6 @@ struct Level : IGame {
|
||||
c->environment->generateMipMap();
|
||||
}
|
||||
}
|
||||
Core::endFrame();
|
||||
}
|
||||
|
||||
void setMainLight(Controller *controller) {
|
||||
@@ -1526,6 +1528,18 @@ struct Level : IGame {
|
||||
}
|
||||
|
||||
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) {
|
||||
inventory->update();
|
||||
return;
|
||||
@@ -2467,6 +2481,16 @@ struct Level : IGame {
|
||||
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)
|
||||
ambientCache->processQueue();
|
||||
|
||||
@@ -2662,11 +2686,12 @@ struct Level : IGame {
|
||||
|
||||
void render() {
|
||||
bool title = inventory->isActive() || level.isTitle();
|
||||
bool copyBg = title && lastTitle != title;
|
||||
bool copyBg = title && (lastTitle != title || needRedrawTitleBG);
|
||||
lastTitle = title;
|
||||
needRedrawTitleBG = false;
|
||||
|
||||
if (isEnded) {
|
||||
Core::setTarget(NULL, RT_CLEAR_COLOR);
|
||||
Core::setTarget(NULL, RT_CLEAR_COLOR | RT_STORE_COLOR);
|
||||
UI::begin();
|
||||
UI::updateAspect(float(Core::width) / float(Core::height));
|
||||
UI::textOut(vec2(0, 480 - 16), STR_LOADING, UI::aCenter, UI::width);
|
||||
@@ -2678,12 +2703,8 @@ struct Level : IGame {
|
||||
inventory->prepareBackground();
|
||||
}
|
||||
|
||||
if (!level.isTitle()) {
|
||||
if (inventory->phaseRing < 1.0f && inventory->titleTimer <= 1.0f) {
|
||||
renderGame(true);
|
||||
title = false;
|
||||
}
|
||||
}
|
||||
if (needRenderGame)
|
||||
renderGame(true);
|
||||
|
||||
renderInventory();
|
||||
}
|
||||
|
17
src/ui.h
17
src/ui.h
@@ -499,16 +499,19 @@ namespace UI {
|
||||
|
||||
float offset = Core::height * 0.25f;
|
||||
|
||||
vec2 pos = vec2(offset, Core::height - offset);
|
||||
if (Input::down[Input::touchKey[Input::zMove]]) {
|
||||
Input::Touch &t = Input::touch[Input::touchKey[Input::zMove] - ikTouchA];
|
||||
renderControl(t.pos, Input::btnRadius, true);
|
||||
pos = t.start;
|
||||
if (Input::btnEnable[Input::bMove]) {
|
||||
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;
|
||||
if (Input::down[Input::touchKey[Input::zMove]]) {
|
||||
Input::Touch &t = Input::touch[Input::touchKey[Input::zMove] - ikTouchA];
|
||||
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++)
|
||||
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::setBlendMode(bmNone);
|
||||
|
Reference in New Issue
Block a user