Skip to content

Commit

Permalink
Sounds, reverb, fixed image size and position
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudMracek committed Nov 30, 2022
1 parent 630bbb3 commit aa55200
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ psn00bsdk_add_executable(horror STATIC
src/texture.c
src/input.c
src/collision.c
src/sound.c
)

psn00bsdk_target_incbin(horror PRIVATE bandwidth_face textures/bandwidth_face.tim)
psn00bsdk_target_incbin(horror PRIVATE duch textures/duch.tim)

psn00bsdk_target_incbin(horror PRIVATE steps sounds/steps.vag)

foreach(TEXTURE ${TEXTURES})
get_filename_component(BARENAME ${TEXTURE} NAME)
string(REGEX REPLACE "\\.[^.]*$" "" TEXTURE_NAME ${BARENAME})
Expand Down
Binary file added sounds/steps.vag
Binary file not shown.
2 changes: 2 additions & 0 deletions src/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ int isPlayerOnMesh(VECTOR* playerPos) {
int isOn = 0;
for(int i = 0; i < collider_faces; i++) {

// This is not consistent. We need to calculate this. Will do it in game setup. For now we do it every frame ¯\_(ツ)_/¯

SVECTOR topLeft = collider_vertices[collider_vertex_indices[i].v0];
SVECTOR bottomRight = collider_vertices[collider_vertex_indices[i].v0];
if(collider_vertices[collider_vertex_indices[i].v0].vx <= topLeft.vx && collider_vertices[collider_vertex_indices[i].v0].vz >= topLeft.vz) {
Expand Down
128 changes: 87 additions & 41 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,77 @@ void initDisplay(void)
{
ResetGraph(0);

// Setup DB 0
SetDefDispEnv(&db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES);
SetDefDrawEnv(&db[0].draw, 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES);
if (GetVideoMode() == MODE_NTSC)
{
SetDefDispEnv(&db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES_NTSC);
SetDefDrawEnv(&db[0].draw, 0, SCREEN_YRES_NTSC, SCREEN_XRES, SCREEN_YRES_NTSC);
}
else
{
SetDefDispEnv(&db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES_PAL);
SetDefDrawEnv(&db[0].draw, 0, SCREEN_YRES_PAL, SCREEN_XRES, SCREEN_YRES_PAL);
db[0].disp.screen.y = 20;
db[0].disp.screen.h = 256;
}

setRGB0(&db[0].draw, 0, 0, 0);
db[0].draw.isbg = 1;
db[0].draw.dtd = 1;

// Setup DB 1
SetDefDispEnv(&db[1].disp, 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES);
SetDefDrawEnv(&db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES);
if (GetVideoMode() == MODE_NTSC)
{
SetDefDispEnv(&db[1].disp, 0, SCREEN_YRES_NTSC, SCREEN_XRES, SCREEN_YRES_NTSC);
SetDefDrawEnv(&db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES_NTSC);
}
else
{
SetDefDispEnv(&db[1].disp, 0, SCREEN_YRES_PAL, SCREEN_XRES, SCREEN_YRES_PAL);
SetDefDrawEnv(&db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES_PAL);
db[1].disp.screen.y = 20;
db[1].disp.screen.h = 256;
}

setRGB0(&db[1].draw, 0, 0, 0);
db[1].draw.isbg = 1;
db[1].draw.dtd = 1;

setRECT(&screen_clip, 0, 0, SCREEN_XRES, SCREEN_YRES);

InitGeom();
gte_SetGeomOffset(CENTERX, CENTERY);
if (GetVideoMode() == MODE_NTSC)
{
setRECT(&screen_clip, 0, 0, SCREEN_XRES, SCREEN_YRES_NTSC);
InitGeom();
gte_SetGeomOffset(CENTERX, CENTERY_NTSC);
}
else
{
setRECT(&screen_clip, 0, 0, SCREEN_XRES, SCREEN_YRES_PAL);
InitGeom();
gte_SetGeomOffset(CENTERX, CENTERY_PAL);
}
gte_SetGeomScreen(CENTERX);

/*
// Setup DB 0
SetDefDispEnv(&db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES);
SetDefDrawEnv(&db[0].draw, 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES);
setRGB0(&db[0].draw, 0, 0, 0);
db[0].draw.isbg = 1;
db[0].draw.dtd = 1;
// Setup DB 1
SetDefDispEnv(&db[1].disp, 0, SCREEN_YRES, SCREEN_XRES, SCREEN_YRES);
SetDefDrawEnv(&db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES);
setRGB0(&db[1].draw, 0, 0, 0);
db[1].draw.isbg = 1;
db[1].draw.dtd = 1;
setRECT(&screen_clip, 0, 0, SCREEN_XRES, SCREEN_YRES);
gte_SetGeomOffset(CENTERX, CENTERY);
gte_SetGeomScreen(CENTERX);
*/
gte_SetBackColor(0, 0, 0);

#ifdef LOAD_FONT
Expand Down Expand Up @@ -127,7 +176,6 @@ void sortObject(OBJECT *obj)
v_dir.vy = l_point.vy - obj->pos.vy - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v2].vy;
v_dir.vz = l_point.vz - obj->pos.vz - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v2].vz;


gte_ldv3(&obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v0],
&obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v1],
&obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v2]);
Expand All @@ -142,7 +190,7 @@ void sortObject(OBJECT *obj)
// Skip drawing this quad if the first 3 vertices are aligned (p = 0)
// or in counterclockwise (p < 0) order.

if(p >= 0)
if (p >= 0)
continue;

gte_stsxy3(&pol4->x0, &pol4->x1, &pol4->x2);
Expand All @@ -155,27 +203,25 @@ void sortObject(OBJECT *obj)
gte_avsz4();
gte_stotz(&p);

if( (p>>2) >= OT_LEN )
continue;

if ((p >> 2) >= OT_LEN)
continue;

gte_stsxy(&pol4->x3);

setRGB0(pol4, 255, 255, 255);
gte_ldrgb(&pol4->r0);

gte_ldv0(&obj->mesh.normal_data[(obj->mesh.normal_indices[i]).v0]);


v_dir.vx = l_point.vx - obj->pos.vx - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v0].vx;
v_dir.vy = l_point.vy - obj->pos.vy - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v0].vy;
v_dir.vz = l_point.vz - obj->pos.vz - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v0].vz;

intensity = 4096*4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);
intensity = 4096 * 4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);

if (intensity < 0)
intensity = 0;
Expand All @@ -198,11 +244,11 @@ void sortObject(OBJECT *obj)
v_dir.vy = l_point.vy - obj->pos.vy - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v1].vy;
v_dir.vz = l_point.vz - obj->pos.vz - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v1].vz;

intensity = 4096*4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);
intensity = 4096 * 4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);

if (intensity < 0)
intensity = 0;
Expand All @@ -228,11 +274,11 @@ void sortObject(OBJECT *obj)
v_dir.vy = l_point.vy - obj->pos.vy - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v2].vy;
v_dir.vz = l_point.vz - obj->pos.vz - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v2].vz;

intensity = 4096*4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);
intensity = 4096 * 4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);

if (intensity < 0)
intensity = 0;
Expand All @@ -258,11 +304,11 @@ void sortObject(OBJECT *obj)
v_dir.vy = l_point.vy - obj->pos.vy - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v3].vy;
v_dir.vz = l_point.vz - obj->pos.vz - obj->mesh.vertex_data[obj->mesh.vertex_indices[i].v3].vz;

intensity = 4096*4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);
intensity = 4096 * 4 - ((
(v_dir.vx * v_dir.vx) +
(v_dir.vy * v_dir.vy) +
(v_dir.vz * v_dir.vz)) >>
7);

if (intensity < 0)
intensity = 0;
Expand All @@ -285,10 +331,10 @@ void sortObject(OBJECT *obj)
gte_nccs();

setUV4(pol4,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v0].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v0].vy ,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v1].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v1].vy ,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v2].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v2].vy ,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v3].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v3].vy );
obj->mesh.uv_data[obj->mesh.uv_indices[i].v0].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v0].vy,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v1].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v1].vy,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v2].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v2].vy,
obj->mesh.uv_data[obj->mesh.uv_indices[i].v3].vx, obj->texture.texture_size - 1 - obj->mesh.uv_data[obj->mesh.uv_indices[i].v3].vy);

pol4->tpage =
getTPage(obj->texture.tim.mode, 0, obj->texture.tim.prect->x, obj->texture.tim.prect->y);
Expand All @@ -299,7 +345,7 @@ void sortObject(OBJECT *obj)
addPrim(&(db[db_active].ot)[p >> 2], pol4);

pol4++;
//if (pol4 >= (db_nextpri + PACKET_LEN))
// if (pol4 >= (db_nextpri + PACKET_LEN))
// break;
}
}
Expand Down
39 changes: 30 additions & 9 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ SVECTOR trot;

VECTOR camPosOld;

VECTOR cam_pos = {0, -600 << 12, 0};;
VECTOR cam_rot;
VECTOR cam_pos = {-350 << 12, -600 << 12, 0};
;
VECTOR cam_rot = {0, 1024 << 12, 0};

PADTYPE *pad;
uint8_t padBuffer[2][34];

int movesPrev = 1;

void initInput(void)
{
InitPAD(padBuffer[0], 34, padBuffer[1], 34);
Expand All @@ -31,8 +34,11 @@ void pollInput(int deltaTime)
tpos.vy = -cam_pos.vy >> 12;
tpos.vz = -cam_pos.vz >> 12;

int moves = 0;

VECTOR positon = getCamPosWorld();
if(!isPlayerOnMesh(&positon)) {
if (!isPlayerOnMesh(&positon))
{
cam_pos = camPosOld;
}

Expand Down Expand Up @@ -86,14 +92,15 @@ void pollInput(int deltaTime)
// Move forward
cam_pos.vx -= deltaTime * isin(trot.vy) << 4;
cam_pos.vz += deltaTime * icos(trot.vy) << 4;
moves = 1;
}
else if (!(pad->btn & PAD_CROSS))
{

// Move backward
cam_pos.vx += deltaTime * ((isin(trot.vy) * icos(trot.vx)) >> 12) << 4;
cam_pos.vy -= deltaTime * isin(trot.vx) << 4;
cam_pos.vz -= deltaTime * ((icos(trot.vy) * icos(trot.vx)) >> 12) << 4;
cam_pos.vx += deltaTime * isin(trot.vy) << 4;
cam_pos.vz -= deltaTime * icos(trot.vy) << 4;
moves = 1;
}

if (!(pad->btn & PAD_SQUARE))
Expand All @@ -102,13 +109,15 @@ void pollInput(int deltaTime)
// Slide left
cam_pos.vx -= deltaTime * icos(trot.vy) << 4;
cam_pos.vz -= deltaTime * isin(trot.vy) << 4;
moves = 1;
}
else if (!(pad->btn & PAD_CIRCLE))
{

// Slide right
cam_pos.vx += deltaTime * icos(trot.vy) << 4;
cam_pos.vz += deltaTime * isin(trot.vy) << 4;
moves = 1;
}
}

Expand All @@ -121,10 +130,12 @@ void pollInput(int deltaTime)
{

cam_pos.vx += deltaTime *
(((isin(trot.vy) * icos(trot.vx)) >> 12) * (pad->ls_y - 128)) >> 5;
(((isin(trot.vy) * icos(trot.vx)) >> 12) * (pad->ls_y - 128)) >>
5;
cam_pos.vy -= deltaTime * (isin(trot.vx) * (pad->ls_y - 128)) >> 5;
cam_pos.vz -= deltaTime *
(((icos(trot.vy) * icos(trot.vx)) >> 12) * (pad->ls_y - 128)) >> 5;
(((icos(trot.vy) * icos(trot.vx)) >> 12) * (pad->ls_y - 128)) >>
5;
}

// Strafing left and right
Expand All @@ -146,6 +157,16 @@ void pollInput(int deltaTime)
cam_rot.vy -= deltaTime * (pad->rs_x - 128) << 9;
}
}
if (moves == 1 && movesPrev == 0)
{
SpuSetKey(1, 1 << 0);
movesPrev = 1;
}
else if(moves == 0 && movesPrev == 1)
{
SpuSetKey(0, 1 << 0);
movesPrev = 0;
}
}
}

Expand All @@ -154,7 +175,7 @@ VECTOR *getCamPos(void)
return &tpos;
}

VECTOR getCamPosWorld(void)
VECTOR getCamPosWorld(void)
{
VECTOR negCamPos = {-tpos.vx, -tpos.vy, -tpos.vz};
negCamPos.vx = cam_pos.vx >> 12;
Expand Down
1 change: 1 addition & 0 deletions src/input.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <psxgte.h>
#include <psxpad.h>
#include <psxspu.h>
#include <stdio.h>

#include "collision.h"
Expand Down
Loading

0 comments on commit aa55200

Please sign in to comment.