Skip to content

Commit

Permalink
#407 32X support, initial commit, cinematic cutscenes
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Feb 23, 2022
1 parent 28ac8e9 commit fe8826d
Show file tree
Hide file tree
Showing 21 changed files with 4,251 additions and 55 deletions.
63 changes: 63 additions & 0 deletions src/fixed/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,69 @@
#define CAM_ANGLE_COMBAT ANGLE(-10)
#define CAM_ANGLE_MAX ANGLE(85)

void Camera::initCinematic()
{
switch (gLevelID)
{
case LVL_TR1_CUT_1:
gCinematicCamera.view.pos.x = 36668;
gCinematicCamera.view.pos.z = 63180;
gCinematicCamera.targetAngle.y = -ANGLE(128);
break;
case LVL_TR1_CUT_2:
gCinematicCamera.view.pos.x = 51962;
gCinematicCamera.view.pos.z = 53760;
gCinematicCamera.targetAngle.y = ANGLE_90 - 4;
break;
case LVL_TR1_CUT_3:
gCinematicCamera.targetAngle.y = ANGLE_90;
//level.flip();
break;
case LVL_TR1_CUT_4:
gCinematicCamera.targetAngle.y = ANGLE_90;
break;
default:
ASSERT(false);
break;
}
}

void Camera::updateCinematic()
{
const CameraFrame &frame = level.cameraFrames[timer++];

int32 px = frame.pos.x;
int32 py = frame.pos.y;
int32 pz = frame.pos.z;

int32 dx = frame.target.x - px;
int32 dy = frame.target.y - py;
int32 dz = frame.target.z - pz;

anglesFromVector(dx, dy, dz, angle.x, angle.y);

int32 s, c;
sincos(targetAngle.y, s, c);

X_ROTXY(pz, px, s, c);

px += view.pos.x;
py += view.pos.y;
pz += view.pos.z;

matrixSetView(_vec3i(px, py, pz), angle.x, angle.y + targetAngle.y);

Room* nextRoom = view.room->getRoom(px, py, pz);
if (nextRoom) {
view.room = nextRoom;
}

if (timer >= level.cameraFramesCount) {
timer = level.cameraFramesCount - 1;
nextLevel(LevelID(gLevelID + 1));
}
}

void Camera::init(ItemObj* lara)
{
ASSERT(lara->extraL);
Expand Down
17 changes: 11 additions & 6 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vec3i gCameraViewPos;
Matrix gMatrixStack[MAX_MATRICES];
Matrix* gMatrixPtr = gMatrixStack;

EWRAM_DATA Sphere gSpheres[2][MAX_SPHERES];
EWRAM_DATA Sphere gSpheres[2][MAX_SPHERES]; // EWRAM 1k

const FloorData* gLastFloorData;
FloorData gLastFloorSlant;
Expand Down Expand Up @@ -45,7 +45,7 @@ EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];
#ifdef __3DO__ // TODO fix the title scren on 3DO
EWRAM_DATA LevelID gLevelID = LVL_TR1_1;
#else
EWRAM_DATA LevelID gLevelID = LVL_TR1_TITLE;
EWRAM_DATA LevelID gLevelID = LVL_TR1_1;
#endif

const LevelInfo gLevelInfo[LVL_MAX] = {
Expand Down Expand Up @@ -1144,7 +1144,7 @@ X_INLINE int16 lerpAngleSlow(int16 a, int16 b, int32 mul, int32 div)
void matrixPush_c()
{
ASSERT(gMatrixPtr - gMatrixStack < MAX_MATRICES);
memcpy(gMatrixPtr + 1, gMatrixPtr, sizeof(Matrix));
gMatrixPtr[1] = gMatrixPtr[0];
gMatrixPtr++;
}

Expand Down Expand Up @@ -1556,7 +1556,8 @@ void palSet(const uint16* palette, int32 gamma, int32 bright)

if (gamma || bright)
{
uint16 tmp[256];
uint16* tmp = (uint16*)&gSpheres;

if (gamma) {
palGamma(pal, tmp, gamma);
pal = tmp;
Expand All @@ -1574,9 +1575,11 @@ void palSet(const uint16* palette, int32 gamma, int32 bright)
void dmaFill(void* dst, uint8 value, uint32 count)
{
ASSERT((count & 3) == 0);
#ifdef __GBA__
#if defined(__GBA__)
vu32 v = value;
dma3_fill(dst, v, count);
#elif defined(__32X__)
fast_memset(dst, value, count >> 2);
#else
memset(dst, value, count);
#endif
Expand All @@ -1586,8 +1589,10 @@ void dmaFill(void* dst, uint8 value, uint32 count)
void dmaCopy(const void* src, void* dst, uint32 size)
{
ASSERT((size & 3) == 0);
#ifdef __GBA__
#if defined(__GBA__)
dma3_cpy(dst, src, size);
#elif defined(__32X__)
fast_memcpy(dst, src, size >> 2);
#else
memcpy(dst, src, size);
#endif
Expand Down
127 changes: 90 additions & 37 deletions src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,64 @@

#if defined(_WIN32)
#define MODE4
//#define MODE13
#define USE_DIV_TABLE

#define MODE4
#define FRAME_WIDTH 240
#define FRAME_HEIGHT 160

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#elif defined(__GBA__)
#define MODE4
#define USE_DIV_TABLE
#define ROM_READ
#define USE_ASM
#define ALIGNED_LIGHTMAP

#define MODE4
#define FRAME_WIDTH 240
#define FRAME_HEIGHT 160

#include <tonc.h>
#elif defined(__NDS__)
#define MODEHW
#define USE_DIV_TABLE

#define MODEHW
#define FRAME_WIDTH 256
#define FRAME_HEIGHT 192

#include <nds.h>
#include <fat.h>
#include <filesystem.h>
#elif defined(__TNS__)
#define MODE13
#define USE_DIV_TABLE

#define MODE13
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 240

#include <os.h>
#elif defined(__DOS__)
#define MODE13
#define USE_DIV_TABLE

#define MODE13
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 200

#include <stdlib.h>
#include <stddef.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#elif defined(__3DO__)
#define MODEHW
#define USE_DIV_TABLE // 4k of DRAM
#define CPU_BIG_ENDIAN
#define USE_ASM

#define MODEHW
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 240

#include <displayutils.h>
#include <debug.h>
#include <nodes.h>
Expand All @@ -69,6 +87,16 @@
#include <celutils.h>
#include <timerutils.h>
#include <hardware.h>
#elif defined(__32X__)
#define USE_DIV_TABLE
#define CPU_BIG_ENDIAN
#define ROM_READ

#define MODE13
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 224

#include "32x.h"
#else
#error unsupported platform
#endif
Expand All @@ -81,30 +109,8 @@

#include <math.h>
#include <limits.h>
#include <new>

#if defined(MODEHW)
#if defined(__3DO__)
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 240
#elif defined(__NDS__)
#define FRAME_WIDTH 256
#define FRAME_HEIGHT 192
#endif
#elif defined(MODE4)
#define VRAM_WIDTH 120 // in shorts (240 bytes)
#define FRAME_WIDTH 240
#define FRAME_HEIGHT 160
#elif defined(MODE13)
#define VRAM_WIDTH 160 // in shorts (320 bytes)
#define FRAME_WIDTH 320

#if defined(__TNS__)
#define FRAME_HEIGHT 240 // MODE X?
#else
#define FRAME_HEIGHT 200
#endif
#endif
#define VRAM_WIDTH (FRAME_WIDTH/2) // in shorts

// Optimization flags =========================================================
#ifdef __GBA__
Expand Down Expand Up @@ -143,6 +149,23 @@
#define FAST_HITMASK
#endif

#ifdef __32X__
// hide dead enemies after a while to reduce the number of polygons on the screen
#define HIDE_CORPSES (30*10) // 10 sec
// replace trap flor geometry by two flat quads in the static state
#define LOD_TRAP_FLOOR
// disable some plants environment to reduce overdraw of transparent geometry
#define NO_STATIC_MESH_PLANTS
// use IWRAM_CODE section that faster for matrix interpolation (GBA only)
#define IWRAM_MATRIX_LERP
// the maximum of active enemies
#define MAX_ENEMIES 3
// visibility distance
#define VIEW_DIST (1024 * 10)
// skip collideSpheres for enemies
#define FAST_HITMASK
#endif

#ifndef NAV_STEPS
#define NAV_STEPS 5
#endif
Expand Down Expand Up @@ -190,16 +213,24 @@ typedef unsigned int uint32;
typedef uint16 divTableInt;
#endif

#if defined(__3DO__)
//#include <new>
inline void* operator new(size_t, void *ptr)
{
return ptr;
}

#if defined(__3DO__) || defined(__32X__)
X_INLINE int32 abs(int32 x) {
return (x >= 0) ? x : -x;
}
#endif

#if defined(__GBA__) || defined(__NDS__)
#if defined(__GBA__) || defined(__NDS__) || defined(__32X__)
#define int2str(x,str) itoa(x, str, 10)
#elif defined(__3DO__)
#define int2str(x,str) sprintf(str, "%d", x)
#elif defined(__TNS__)
#define int2str(x,str) __itoa(x, str, 10)
#else
#define int2str(x,str) _itoa(x, str, 10)
#endif
Expand Down Expand Up @@ -436,7 +467,7 @@ extern int32 fps;
#define MAX_TEXTURES 1536
#define MAX_SPRITES 180
#define MAX_FACES 1920
#define MAX_ROOM_LIST 16
#define MAX_ROOM_LIST 32
#define MAX_PORTALS 16
#define MAX_CAUSTICS 32
#define MAX_RAND_TABLE 32
Expand Down Expand Up @@ -521,10 +552,11 @@ enum InputKey {
IK_C = (1 << 6),
IK_X = (1 << 7),
IK_Y = (1 << 8),
IK_L = (1 << 9),
IK_R = (1 << 10),
IK_START = (1 << 11),
IK_SELECT = (1 << 12)
IK_Z = (1 << 9),
IK_L = (1 << 10),
IK_R = (1 << 11),
IK_START = (1 << 12),
IK_SELECT = (1 << 13)
};

// action keys (ItemObj::input)
Expand Down Expand Up @@ -1322,6 +1354,9 @@ struct Camera {
bool lastFixed;
bool center;

void initCinematic();
void updateCinematic();

void init(ItemObj* lara);
Location getLocationForAngle(int32 angle, int32 distH, int32 distV);
void clip(Location &loc);
Expand Down Expand Up @@ -1517,6 +1552,8 @@ struct ExtraInfoLara

extern ExtraInfoLara playersExtra[MAX_PLAYERS];

#define gCinematicCamera playersExtra[0].camera

struct Enemy;

enum EnemyMood
Expand Down Expand Up @@ -1993,6 +2030,14 @@ struct Box
uint16 overlap;
};

struct CameraFrame
{
vec3s target;
vec3s pos;
int16 fov;
int16 roll;
};

struct Level
{
uint32 magic;
Expand Down Expand Up @@ -2037,7 +2082,7 @@ struct Level
const uint16* zones[2][ZONE_MAX];
const int16* animTexData;
const ItemObjInfo* itemsInfo;
uint32 cameraFrames;
const CameraFrame* cameraFrames;
const uint16* soundMap;
const SoundInfo* soundsInfo;
const uint8* soundData;
Expand Down Expand Up @@ -2645,6 +2690,13 @@ vec3i boxPushOut(const AABBi &a, const AABBi &b);
void flush_c();
#endif

#ifdef __32X__ // TODO
#undef matrixPush
#define matrixPush matrixPush_asm

extern "C" void matrixPush_asm();
#endif

#define matrixPop() gMatrixPtr--

X_INLINE vec3i matrixGetDir(const Matrix &m)
Expand Down Expand Up @@ -2678,6 +2730,7 @@ void drawText(int32 x, int32 y, const char* text, TextAlign align);
void drawModel(const ItemObj* item);
void drawItem(const ItemObj* item);
void drawRooms(Camera* camera);
void drawCinematicRooms();
void drawHUD(Lara* lara);
void drawNodesLerp(const ItemObj* item, const AnimFrame* frameA, const AnimFrame* frameB, int32 frameDelta, int32 frameRate);

Expand Down
Loading

0 comments on commit fe8826d

Please sign in to comment.