Skip to content

Commit

Permalink
#368 underwater room caustics ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Dec 31, 2021
1 parent bff01aa commit a5f1d13
Show file tree
Hide file tree
Showing 16 changed files with 582 additions and 237 deletions.
47 changes: 47 additions & 0 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,55 @@ EWRAM_DATA Settings gSettings;
EWRAM_DATA int32 gCurTrack;
EWRAM_DATA int32 gAnimTexFrame;

int32 gLightAmbient;
int32 gRandTable[MAX_RAND_TABLE];
int32 gCaustics[MAX_CAUSTICS];
int32 gCausticsFrame;

EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];

#ifdef __GBA__
#include "TRACKS_IMA.h"
#include "TITLE_PKD.h"
#include "GYM_PKD.h"
#include "LEVEL1_PKD.h"
#include "LEVEL2_PKD.h"

#define LEVEL_INFO(name, title, track, secrets) { #name, name##_PKD, title, track, secrets }
#else
#define LEVEL_INFO(name, title, track, secrets) { #name, NULL, title, track, secrets }
#endif

const LevelInfo gLevelInfo[LVL_MAX] = {
// TR1
LEVEL_INFO( TITLE , STR_EMPTY , TRACK_TR1_TITLE , 0 ),
LEVEL_INFO( GYM , STR_TR1_GYM , TRACK_NONE , 0 ),
LEVEL_INFO( LEVEL1 , STR_TR1_LEVEL1 , TRACK_TR1_CAVES , 3 ),
LEVEL_INFO( LEVEL2 , STR_TR1_LEVEL2 , TRACK_TR1_CAVES , 3 ),
//LEVEL_INFO( LEVEL3A , STR_TR1_LEVEL3A , TRACK_TR1_CAVES , 5 ),
//LEVEL_INFO( LEVEL3B , STR_TR1_LEVEL3B , TRACK_TR1_CAVES , 3 ),
//LEVEL_INFO( CUT1 , STR_EMPTY , TRACK_TR1_CUT_1 , 0 ),
//LEVEL_INFO( LEVEL4 , STR_TR1_LEVEL4 , TRACK_TR1_WIND , 4 ),
//LEVEL_INFO( LEVEL5 , STR_TR1_LEVEL5 , TRACK_TR1_WIND , 3 ),
//LEVEL_INFO( LEVEL6 , STR_TR1_LEVEL6 , TRACK_TR1_WIND , 3 ),
//LEVEL_INFO( LEVEL7A , STR_TR1_LEVEL7A , TRACK_TR1_CISTERN , 3 ),
//LEVEL_INFO( LEVEL7B , STR_TR1_LEVEL7B , TRACK_TR1_CISTERN , 2 ),
//LEVEL_INFO( CUT2 , STR_EMPTY , TRACK_TR1_CUT_2 , 0 ),
//LEVEL_INFO( LEVEL8A , STR_TR1_LEVEL8A , TRACK_TR1_WIND , 3 ),
//LEVEL_INFO( LEVEL8B , STR_TR1_LEVEL8B , TRACK_TR1_WIND , 3 ),
//LEVEL_INFO( LEVEL8C , STR_TR1_LEVEL8C , TRACK_TR1_WIND , 1 ),
//LEVEL_INFO( LEVEL10A , STR_TR1_LEVEL10A , TRACK_TR1_CISTERN , 3 ),
//LEVEL_INFO( CUT3 , STR_EMPTY , TRACK_TR1_CUT_3 , 0 ),
//LEVEL_INFO( LEVEL10B , STR_TR1_LEVEL10B , TRACK_TR1_PYRAMID , 3 ),
//LEVEL_INFO( CUT4 , STR_EMPTY , TRACK_TR1_CUT_4 , 0 ),
//LEVEL_INFO( LEVEL10C , STR_TR1_LEVEL10C , TRACK_TR1_PYRAMID , 3 ),
//LEVEL_INFO( EGYPT , STR_TR1_EGYPT , TRACK_TR1_WIND , 3 ),
//LEVEL_INFO( CAT , STR_TR1_CAT , TRACK_TR1_WIND , 4 ),
//LEVEL_INFO( END , STR_TR1_END , TRACK_TR1_WIND , 2 )
};

LevelID gLevelID = LVL_TR1_GYM;

#ifdef PROFILING
uint32 gCounters[CNT_MAX];
#endif
Expand Down
131 changes: 131 additions & 0 deletions src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,132 @@ struct IMA_STATE
}
#endif

enum StringID
{
STR_EMPTY,
STR_PASSPORT,
STR_COMPASS,
STR_HOME,
STR_MAP,
STR_DETAIL,
STR_SOUND,
STR_CONTROLS,
STR_GAMMA,
STR_PISTOLS,
STR_SHOTGUN,
STR_MAGNUMS,
STR_UZIS,
STR_AMMO_PISTOLS,
STR_AMMO_SHOTGUN,
STR_AMMO_MAGNUMS,
STR_AMMO_UZIS,
STR_EXPLOSIVE,
STR_MEDIKIT_SMALL,
STR_MEDIKIT_BIG,
STR_PUZZLE,
STR_PUZZLE_GOLD_IDOL,
STR_PUZZLE_GOLD_BAR,
STR_PUZZLE_COG,
STR_PUZZLE_FUSE,
STR_PUZZLE_ANKH,
STR_PUZZLE_HORUS,
STR_PUZZLE_ANUBIS,
STR_PUZZLE_SCARAB,
STR_PUZZLE_PYRAMID,
STR_LEADBAR,
STR_KEY,
STR_KEY_SILVER,
STR_KEY_RUSTY,
STR_KEY_GOLD,
STR_KEY_SAPPHIRE,
STR_KEY_NEPTUNE,
STR_KEY_ATLAS,
STR_KEY_DAMOCLES,
STR_KEY_THOR,
STR_KEY_ORNATE,
STR_SCION,
// TR1 levels
STR_TR1_GYM,
STR_TR1_LEVEL1,
STR_TR1_LEVEL2,
STR_TR1_LEVEL3A,
STR_TR1_LEVEL3B,
STR_TR1_LEVEL4,
STR_TR1_LEVEL5,
STR_TR1_LEVEL6,
STR_TR1_LEVEL7A,
STR_TR1_LEVEL7B,
STR_TR1_LEVEL8A,
STR_TR1_LEVEL8B,
STR_TR1_LEVEL8C,
STR_TR1_LEVEL10A,
STR_TR1_LEVEL10B,
STR_TR1_LEVEL10C,
STR_TR1_EGYPT,
STR_TR1_CAT,
STR_TR1_END,
STR_TR1_END2,
STR_MAX
};

enum TrackID
{
TRACK_NONE = -1,
// TR1
TRACK_TR1_TITLE = 2,
TRACK_TR1_CAVES = 5,
TRACK_TR1_SECRET = 13,
TRACK_TR1_CISTERN = 57,
TRACK_TR1_WIND = 58,
TRACK_TR1_PYRAMID = 59,
TRACK_TR1_CUT_1 = 23,
TRACK_TR1_CUT_2 = 25,
TRACK_TR1_CUT_3 = 24,
TRACK_TR1_CUT_4 = 22
};

struct LevelInfo
{
const char* name;
const void* data;
StringID title;
TrackID track;
uint8 secrets;
};

enum LevelID
{
LVL_TR1_TITLE,
LVL_TR1_GYM,
LVL_TR1_1,
LVL_TR1_2,
//LVL_TR1_3A,
//LVL_TR1_3B,
//LVL_TR1_CUT_1,
//LVL_TR1_4,
//LVL_TR1_5,
//LVL_TR1_6,
//LVL_TR1_7A,
//LVL_TR1_7B,
//LVL_TR1_CUT_2,
//LVL_TR1_8A,
//LVL_TR1_8B,
//LVL_TR1_8C,
//LVL_TR1_10A,
//LVL_TR1_CUT_3,
//LVL_TR1_10B,
//LVL_TR1_CUT_4,
//LVL_TR1_10C,
//LVL_TR1_EGYPT,
//LVL_TR1_CAT,
//LVL_TR1_END,
//LVL_TR1_END2,
LVL_MAX
};

extern const LevelInfo gLevelInfo[LVL_MAX];
extern LevelID gLevelID;

// renderer internal
extern uint32 keys;
extern RectMinMax viewport;
Expand All @@ -2067,6 +2193,11 @@ extern Settings gSettings;
extern int32 gCurTrack;
extern int32 gAnimTexFrame;

extern int32 gLightAmbient;
extern int32 gRandTable[MAX_RAND_TABLE];
extern int32 gCaustics[MAX_CAUSTICS];
extern int32 gCausticsFrame;

extern const FloorData* gLastFloorData;
extern FloorData gLastFloorSlant;

Expand Down
32 changes: 13 additions & 19 deletions src/fixed/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
#include "common.h"
#include "item.h"

int32 lightAmbient;

int32 randTable[MAX_RAND_TABLE];
int32 caustics[MAX_CAUSTICS];
int32 causticsFrame;

void drawInit()
{
for (int32 i = 0; i < MAX_RAND_TABLE; i++)
{
randTable[i] = (rand_draw() >> 5) - 511;
gRandTable[i] = (rand_draw() >> 5) - 511;
}

for (int32 i = 0; i < MAX_CAUSTICS; i++)
{
int16 rot = i * (ANGLE_90 * 4) / MAX_CAUSTICS;
caustics[i] = sin(rot) * 768 >> FIXED_SHIFT;
gCaustics[i] = sin(rot) * 768 >> FIXED_SHIFT;
}
}

Expand All @@ -33,12 +27,12 @@ void calcLightingDynamic(const Room* room, const vec3i &point)
{
const RoomInfo* info = room->info;

lightAmbient = (info->ambient << 5);
gLightAmbient = (info->ambient << 5);

if (!info->lightsCount)
return;

lightAmbient = 8191 - lightAmbient;
gLightAmbient = 8191 - gLightAmbient;
int32 maxLum = 0;

for (int i = 0; i < info->lightsCount; i++)
Expand All @@ -57,34 +51,34 @@ void calcLightingDynamic(const Room* room, const vec3i &point)
int32 dist = dot(d, d) >> 12;
int32 att = X_SQR(radius) >> 12;

int32 lum = (intensity * att) / (dist + att) + lightAmbient;
int32 lum = (intensity * att) / (dist + att) + gLightAmbient;

if (lum > maxLum) {
maxLum = lum;
}
}

lightAmbient = 8191 - ((maxLum + lightAmbient) >> 1);
gLightAmbient = 8191 - ((maxLum + gLightAmbient) >> 1);

Matrix &m = matrixGet();

int32 fogZ = m.e23 >> FIXED_SHIFT;
if (fogZ > FOG_MIN) {
lightAmbient += (fogZ - FOG_MIN) << FOG_SHIFT;
lightAmbient = X_MIN(lightAmbient, 8191);
gLightAmbient += (fogZ - FOG_MIN) << FOG_SHIFT;
gLightAmbient = X_MIN(gLightAmbient, 8191);
}
}

void calcLightingStatic(int32 intensity)
{
lightAmbient = intensity - 4096;
gLightAmbient = intensity - 4096;

Matrix &m = matrixGet();

int32 fogZ = m.e23 >> FIXED_SHIFT;
if (fogZ > FOG_MIN) {
lightAmbient += (fogZ - FOG_MIN) << FOG_SHIFT;
lightAmbient = X_MIN(lightAmbient, 8191);
gLightAmbient += (fogZ - FOG_MIN) << FOG_SHIFT;
gLightAmbient = X_MIN(gLightAmbient, 8191);
}
}

Expand Down Expand Up @@ -212,12 +206,12 @@ void drawFlash(const ExtraInfoLara::Arm::Flash &flash)
matrixTranslateRel(0, flash.offset, 55);
matrixRotateYXZ(-ANGLE_90, 0, flash.angle);

int32 tmp = lightAmbient;
int32 tmp = gLightAmbient;
calcLightingStatic(flash.intensity);

drawMesh(level.models[ITEM_MUZZLE_FLASH].start);

lightAmbient = tmp;
gLightAmbient = tmp;

matrixPop();
}
Expand Down
19 changes: 19 additions & 0 deletions src/fixed/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
#include "nav.h"
#include "level.h"

LevelID gNextLevel = LVL_MAX;

void nextLevel()
{
if (gLevelID == LVL_TR1_2) {
gNextLevel = LVL_TR1_GYM;
return;
}
gNextLevel = LevelID(gLevelID + 1);
}

struct Game
{
void init(const char* name)
Expand Down Expand Up @@ -152,6 +163,14 @@ struct Game
{
PROFILE(CNT_UPDATE);

if (gNextLevel != LVL_MAX)
{
gLevelID = gNextLevel;
gNextLevel = LVL_MAX;
startLevel(gLevelInfo[gLevelID].name);
frames = 1;
}

if (frames > MAX_UPDATE_FRAMES) {
frames = MAX_UPDATE_FRAMES;
}
Expand Down
Loading

0 comments on commit a5f1d13

Please sign in to comment.