Skip to content

Commit

Permalink
Merged upstream-2022-02-19
Browse files Browse the repository at this point in the history
  • Loading branch information
histat committed Feb 22, 2022
2 parents 87bd815 + 28ac8e9 commit 78f781d
Show file tree
Hide file tree
Showing 382 changed files with 47,610 additions and 4,361 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ This is a port of OpenLara (https://github.com/XProger/OpenLara) for the Sega Dr
you can burn with [Image Burn](https://www.imgburn.com/index.php?act=download)
see release page
- require PS1 version of tomb raider disc.

16 changes: 12 additions & 4 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#define USE_SCREEN_TEX
#endif

#if defined(_GAPI_D3D8) || defined(_GAPI_D3D9) || defined(_GAPI_D3D11)
#define EARLY_CLEAR
#endif

struct ShaderCache {
enum Effect { FX_NONE = 0, FX_UNDERWATER = 1, FX_ALPHA_TEST = 2 };

Expand Down Expand Up @@ -86,8 +90,8 @@ struct ShaderCache {
void prepareSky(int fx) {
compile(Core::passSky, Shader::DEFAULT, fx, rsBase);
if (Core::support.tex3D) {
compile(Core::passSky, Shader::SKY_CLOUDS, fx, rsBase);
compile(Core::passSky, Shader::SKY_CLOUDS_AZURE, fx, rsBase);
compile(Core::passSky, Shader::SKY_CLOUDS, fx, rsBase);
compile(Core::passSky, Shader::SKY_AZURE, fx, rsBase);
}
}

Expand Down Expand Up @@ -123,7 +127,7 @@ struct ShaderCache {
if (rs & RS_DISCARD)
fx |= FX_ALPHA_TEST;

#ifndef FFP
#if !defined(FFP) && !defined(_GAPI_TA)
if (shaders[pass][type][fx])
return shaders[pass][type][fx];

Expand Down Expand Up @@ -180,7 +184,7 @@ struct ShaderCache {

Shader *getShader(Core::Pass pass, Shader::Type type, int fx) {
Shader *shader = shaders[pass][type][fx];
#ifndef FFP
#if !defined(FFP) && !defined(_GAPI_TA)
if (shader == NULL)
LOG("! NULL shader: %d %d %d\n", int(pass), int(type), int(fx));
ASSERT(shader != NULL);
Expand Down Expand Up @@ -977,6 +981,10 @@ struct WaterCache {

mat4 mProj = GAPI::ortho(0.0f, float(tex->origWidth), 0.0f, float(tex->origHeight), 0.0f, 1.0f);

#ifdef _OS_WP8
mProj.unrot90();
#endif

Core::active.shader->setParam(uViewProj, mProj);
Core::active.shader->setParam(uMaterial, vec4(1.0f));

Expand Down
75 changes: 50 additions & 25 deletions src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct Camera : ICamera {
Frustum *frustum;

float fov, aspect, znear, zfar;
vec3 lookAngle, targetAngle;
vec3 lookAngle, targetAngle, viewAngle;
mat4 mViewInv;

float timer;
Expand All @@ -69,6 +69,7 @@ struct Camera : ICamera {

spectator = false;
specTimer = 0.0f;
targetAngle = vec3(0.0f);
}

void reset() {
Expand Down Expand Up @@ -366,6 +367,8 @@ struct Camera : ICamera {
speed = CAM_SPEED_COMBAT;
}

viewAngle = vec3(0.0f);

if (mode == MODE_CUTSCENE) {
ASSERT(level->cameraFramesCount && level->cameraFrames);

Expand All @@ -386,39 +389,41 @@ struct Camera : ICamera {
}
}

if (!firstPerson) {
TR::CameraFrame *frameA = &level->cameraFrames[indexA];
TR::CameraFrame *frameB = &level->cameraFrames[indexB];
if (!spectator) {
if (!firstPerson) {
TR::CameraFrame *frameA = &level->cameraFrames[indexA];
TR::CameraFrame *frameB = &level->cameraFrames[indexB];

const float maxDelta = 512 * 512;
const float maxDelta = 512 * 512;

float dp = (vec3(frameA->pos) - vec3(frameB->pos)).length2();
float dt = (vec3(frameA->target) - vec3(frameB->target)).length2();
float dp = (vec3(frameA->pos) - vec3(frameB->pos)).length2();
float dt = (vec3(frameA->target) - vec3(frameB->target)).length2();

if (dp > maxDelta || dt > maxDelta) {
eye.pos = frameA->pos;
target.pos = frameA->target;
fov = frameA->fov / 32767.0f * 120.0f;
} else {
eye.pos = vec3(frameA->pos).lerp(frameB->pos, t);
target.pos = vec3(frameA->target).lerp(frameB->target, t);
fov = lerp(frameA->fov / 32767.0f * 120.0f, frameB->fov / 32767.0f * 120.0f, t);
}
if (dp > maxDelta || dt > maxDelta) {
eye.pos = frameA->pos;
target.pos = frameA->target;
fov = frameA->fov / 32767.0f * 120.0f;
} else {
eye.pos = vec3(frameA->pos).lerp(frameB->pos, t);
target.pos = vec3(frameA->target).lerp(frameB->target, t);
fov = lerp(frameA->fov / 32767.0f * 120.0f, frameB->fov / 32767.0f * 120.0f, t);
}

eye.pos = level->cutMatrix * eye.pos;
target.pos = level->cutMatrix * target.pos;
eye.pos = level->cutMatrix * eye.pos;
target.pos = level->cutMatrix * target.pos;

mViewInv = mat4(eye.pos, target.pos, vec3(0, -1, 0));
} else
updateFirstPerson();
mViewInv = mat4(eye.pos, target.pos, vec3(0, -1, 0));
} else
updateFirstPerson();
}
} else {
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR) {
lookAngle = vec3(0.0f);
} else {
if (mode == MODE_LOOK) {
float d = 3.0f * Core::deltaTime;

vec2 L = Input::joy[cameraIndex].L;
vec2 L = Input::joy[Core::settings.controls[cameraIndex].joyIndex].L;
L = L.normal() * max(0.0f, L.length() - INPUT_JOY_DZ_STICK) / (1.0f - INPUT_JOY_DZ_STICK);

lookAngle.x += L.y * d;
Expand All @@ -431,17 +436,28 @@ struct Camera : ICamera {

lookAngle.x = clamp(lookAngle.x, CAM_LOOK_ANGLE_XMIN, CAM_LOOK_ANGLE_XMAX);
lookAngle.y = clamp(lookAngle.y, -CAM_LOOK_ANGLE_Y, CAM_LOOK_ANGLE_Y);
} else
} else {
if (lookAngle.x != CAM_FOLLOW_ANGLE || lookAngle.y != 0.0f) {
float t = 10.0f * Core::deltaTime;
lookAngle.x = lerp(clampAngle(lookAngle.x), CAM_FOLLOW_ANGLE, t);
lookAngle.y = lerp(clampAngle(lookAngle.y), 0.0f, t);
if (fabsf(lookAngle.x - CAM_FOLLOW_ANGLE) < EPS) lookAngle.x = CAM_FOLLOW_ANGLE;
if (lookAngle.y < EPS) lookAngle.y = 0.0f;
}

if (!spectator) {
vec2 R = Input::joy[Core::settings.controls[cameraIndex].joyIndex].R;
R.x = sign(R.x) * max(0.0f, (fabsf(R.x) - INPUT_JOY_DZ_STICK) / (1.0f - INPUT_JOY_DZ_STICK));
R.y = sign(R.y) * max(0.0f, (fabsf(R.y) - INPUT_JOY_DZ_STICK) / (1.0f - INPUT_JOY_DZ_STICK));

viewAngle.x = -R.y * PI * 0.375f;
viewAngle.y = R.x * PI * 0.5f;
viewAngle.z = 0.0f;
}
}
}

targetAngle = owner->angle + lookAngle;
targetAngle = owner->angle + lookAngle + viewAngle;

targetAngle.x = clampAngle(targetAngle.x);
targetAngle.y = clampAngle(targetAngle.y);
Expand Down Expand Up @@ -503,7 +519,7 @@ struct Camera : ICamera {
if (mode == MODE_LOOK)
offset = CAM_OFFSET_LOOK;
else
offset = (mode == MODE_COMBAT ? CAM_OFFSET_COMBAT : CAM_OFFSET_FOLLOW) * cosf(targetAngle.x);
offset = (mode == MODE_COMBAT ? CAM_OFFSET_COMBAT : CAM_OFFSET_FOLLOW);

vec3 dir = vec3(targetAngle.x, targetAngle.y) * offset;
to.pos = target.pos - dir;
Expand Down Expand Up @@ -545,6 +561,7 @@ struct Camera : ICamera {
if (specJoy.down[jkL] && specJoy.down[jkR]) {
specTimer += Core::deltaTime;
if (specTimer > SPECTATOR_TIMER) {
firstPerson = false;
spectator = !spectator;
specTimer = 0.0f;
specPos = eye.pos;
Expand Down Expand Up @@ -665,6 +682,10 @@ struct Camera : ICamera {
}

void setOblique(const vec4 &clipPlane) { // http://www.terathon.com/code/oblique.html
#ifdef _OS_WP8
Core::mProj.unrot90();
#endif

vec4 p = Core::mViewInv.transpose() * clipPlane;

vec4 q;
Expand All @@ -681,6 +702,10 @@ struct Camera : ICamera {
Core::mProj.e21 = c.y;
Core::mProj.e22 = c.z + (f - 1.0f);
Core::mProj.e23 = c.w;

#ifdef _OS_WP8
Core::mProj.rot90();
#endif
}

void changeView(bool firstPerson) {
Expand Down
4 changes: 4 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ struct Character : Controller {
}

void bakeEnvironment(Texture *&environment) {
Core::beginFrame();

flags.invisible = true;
if (!environment) {
uint32 opt = OPT_CUBEMAP | OPT_TARGET;
Expand All @@ -321,6 +323,8 @@ struct Character : Controller {
environment->generateMipMap();
#endif
flags.invisible = false;

Core::endFrame();
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -1054,17 +1054,17 @@ struct Controller {
bool trace(const TR::Location &from, TR::Location &to) {
int rx, rz;

if (fabsf(to.pos.x - from.pos.x) < fabsf(to.pos.z - from.pos.z)) {
if (fabsf(to.pos.x - from.pos.x) > fabsf(to.pos.z - from.pos.z)) {
rz = traceZ(from, to);
if (!rz) return false;
rx = traceX(from, to);
if (!rx) return false;
} else {
rx = traceX(from, to);
if (!rx) return false;
rz = traceZ(from, to);
if (!rz) return false;
}
TR::Room::Sector *sector = level->getSector(to.room, to.pos);
return clipHeight(from, to, sector) && rx == 1 && rz == 1;
return !(!clipHeight(from, to, sector) || rx != 1 || rz != 1);
}

bool clipHeight(const TR::Location &from, TR::Location &to, TR::Room::Sector *sector) {
Expand Down

0 comments on commit 78f781d

Please sign in to comment.