Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 4, 2024
1 parent 1f0c73d commit 89c047f
Show file tree
Hide file tree
Showing 123 changed files with 4,759 additions and 2,880 deletions.
4 changes: 4 additions & 0 deletions ios/CCIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
9A4D0C642BDD168800E1695D /* TouchUI.c in Sources */ = {isa = PBXBuildFile; fileRef = 9A4D0C632BDD168800E1695D /* TouchUI.c */; };
9A57ECEE2BCD1408006A89F0 /* AudioBackend.c in Sources */ = {isa = PBXBuildFile; fileRef = 9A57ECED2BCD1408006A89F0 /* AudioBackend.c */; };
9A57ECF02BCD1413006A89F0 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 9A57ECEF2BCD1412006A89F0 /* main.c */; };
9A62ADF5286D906F00E5E3DE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9A62ADF4286D906F00E5E3DE /* Assets.xcassets */; };
Expand Down Expand Up @@ -92,6 +93,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
9A4D0C632BDD168800E1695D /* TouchUI.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = TouchUI.c; sourceTree = "<group>"; };
9A57ECED2BCD1408006A89F0 /* AudioBackend.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = AudioBackend.c; sourceTree = "<group>"; };
9A57ECEF2BCD1412006A89F0 /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
9A62ADF4286D906F00E5E3DE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ClassiCube/Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -210,6 +212,7 @@
9A89D37727F802F500FF3F80 /* src */ = {
isa = PBXGroup;
children = (
9A4D0C632BDD168800E1695D /* TouchUI.c */,
9A57ECEF2BCD1412006A89F0 /* main.c */,
9A57ECED2BCD1408006A89F0 /* AudioBackend.c */,
9A7401DA2B7384060040E575 /* SSL.c */,
Expand Down Expand Up @@ -429,6 +432,7 @@
9A89D56227F802F600FF3F80 /* _ftbase.c in Sources */,
9A89D56B27F802F600FF3F80 /* Server.c in Sources */,
9A89D50027F802F600FF3F80 /* _truetype.c in Sources */,
9A4D0C642BDD168800E1695D /* TouchUI.c in Sources */,
9AC5433E2AE2649F0086C85F /* SystemFonts.c in Sources */,
9A89D57F27F802F600FF3F80 /* LWeb.c in Sources */,
9A89D56627F802F600FF3F80 /* Drawer2D.c in Sources */,
Expand Down
11 changes: 8 additions & 3 deletions src/AudioBackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void Audio_Close(struct AudioContext* ctx) {
ctx->sampleRate = 0;
}

static float Log10(float volume) { return Math_Log(volume) / Math_Log(10); }
static float Log10(float volume) { return Math_Log2(volume) / Math_Log2(10); }

static void UpdateVolume(struct AudioContext* ctx) {
/* Object doesn't exist until Audio_SetFormat is called */
Expand Down Expand Up @@ -1305,6 +1305,7 @@ void Audio_FreeChunks(void** chunks, int numChunks) {
*#########################################################################################################################*/
#include <kos.h>
/* TODO needs way more testing, especially with sounds */
static cc_bool valid_handles[SND_STREAM_MAX];

struct AudioBuffer {
int available;
Expand All @@ -1325,8 +1326,10 @@ cc_bool AudioBackend_Init(void) {

void AudioBackend_Tick(void) {
// TODO is this really threadsafe with music? should this be done in Audio_Poll instead?
for (int i = 0; i < SND_STREAM_MAX; i++)
snd_stream_poll(i);
for (int i = 0; i < SND_STREAM_MAX; i++)
{
if (valid_handles[i]) snd_stream_poll(i);
}
}

void AudioBackend_Free(void) {
Expand Down Expand Up @@ -1367,13 +1370,15 @@ cc_result Audio_Init(struct AudioContext* ctx, int buffers) {

ctx->count = buffers;
ctx->bufHead = 0;
valid_handles[ctx->hnd] = true;
return 0;
}

void Audio_Close(struct AudioContext* ctx) {
if (ctx->count) {
snd_stream_stop(ctx->hnd);
snd_stream_destroy(ctx->hnd);
valid_handles[ctx->hnd] = false;
}

ctx->hnd = SND_STREAM_INVALID;
Expand Down
6 changes: 4 additions & 2 deletions src/AxisLinesRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ void AxisLinesRenderer_Render(void) {
Vec3 coords[5], pos, dirVector;
int i, count;
float axisLengthScale, axisThicknessScale;
struct Entity* e;

if (!AxisLinesRenderer_Enabled) return;
/* Don't do it in a ContextRecreated handler, because we only want VB recreated if ShowAxisLines in on. */
if (!axisLines_vb) {
axisLines_vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_COLOURED, AXISLINES_NUM_VERTICES);
}
e = &Entities.CurPlayer->Base;

if (Camera.Active->isThirdPerson) {
pos = LocalPlayer_Instance.Base.Position;
pos = e->Position;
axisLengthScale = 1;
axisThicknessScale = 1;
pos.y += 0.05f;
} else {
pos = Camera.CurrentPos;
dirVector = Vec3_GetDirVector(LocalPlayer_Instance.Base.Yaw * MATH_DEG2RAD, LocalPlayer_Instance.Base.Pitch * MATH_DEG2RAD);
dirVector = Vec3_GetDirVector(e->Yaw * MATH_DEG2RAD, e->Pitch * MATH_DEG2RAD);
Vec3_Mul1(&dirVector, &dirVector, 0.5f);
Vec3_Add(&pos, &dirVector, &pos);
axisLengthScale = 1.0f / 32.0f;
Expand Down
25 changes: 13 additions & 12 deletions src/Bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ static void Png_Reconstruct(cc_uint8 type, cc_uint8 bytesPerPixel, cc_uint8* lin

/* 7.2 Scanlines */
#define PNG_Do_Grayscale(dstI, src, scale) rgb = (src) * scale; Bitmap_Set(dst[dstI], rgb, rgb, rgb, 255);
#define PNG_Do_Grayscale_8() rgb = src[0]; Bitmap_Set(*dst, rgb, rgb, rgb, 255); dst--; src -= 2;
#define PNG_Do_Grayscale_A__8() rgb = src[0]; Bitmap_Set(*dst, rgb, rgb, rgb, src[1]); dst--; src -= 1;
#define PNG_Do_Grayscale_8() rgb = src[0]; Bitmap_Set(*dst, rgb, rgb, rgb, 255); dst--; src -= 1;
#define PNG_Do_Grayscale_A__8() rgb = src[0]; Bitmap_Set(*dst, rgb, rgb, rgb, src[1]); dst--; src -= 2;
#define PNG_Do_RGB__8() Bitmap_Set(*dst, src[0], src[1], src[2], 255); dst--; src -= 3;
#define PNG_Do_RGB_A__8() Bitmap_Set(*dst, src[0], src[1], src[2], src[3]); dst++; src += 4;
#define PNG_Do_Palette__8() *dst-- = palette[*src--];
Expand Down Expand Up @@ -334,7 +334,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
cc_uint32 i;

/* idat state */
cc_uint32 begY, rowY = 0, endY;
cc_uint32 available = 0, rowY = 0;
cc_uint8 buffer[PNG_PALETTE * 3];
cc_uint32 read, bufferIdx = 0;
cc_uint32 left, bufferLen = 0;
Expand Down Expand Up @@ -461,19 +461,18 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {

if (!bmp->scan0) return PNG_ERR_NO_DATA;
if (rowY >= bmp->height) break;

begY = bufferIdx / scanlineBytes;
left = bufferLen - bufferIdx;

res = compStream.Read(&compStream, &data[bufferIdx], left, &read);
res = compStream.Read(&compStream, &data[bufferIdx], left, &read);
if (res) return res;
if (!read) break;

available += read;
bufferIdx += read;
endY = bufferIdx / scanlineBytes;

/* Process all of the scanline(s) that have been fully decompressed */
/* NOTE: Need to check height too, in case IDAT is corrupted and has extra data */
for (rowY = begY; rowY < endY && rowY < bmp->height; rowY++) {
for (; available >= scanlineBytes && rowY < bmp->height; rowY++, available -= scanlineBytes) {
cc_uint8* scanline = &data[rowY * scanlineBytes];
if (scanline[0] > PNG_FILTER_PAETH) return PNG_ERR_INVALID_SCANLINE;

Expand All @@ -489,12 +488,14 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
/* immediately into the destination colour format */
if (colorspace == PNG_COLOR_RGB_A) {
/* Prior line is no longer needed and can be overwritten now */
rowExpander(bmp->width, palette, &prior[1], Bitmap_GetRow(bmp, rowY - 1));
/* Current line is also no longer needed and can be overwritten now */
if (rowY == bmp->height - 1)
rowExpander(bmp->width, palette, &scanline[1], Bitmap_GetRow(bmp, rowY));
rowExpander(bmp->width, palette, &prior[1], Bitmap_GetRow(bmp, rowY - 1));
}
}

/* Current line is also no longer needed and can be overwritten now */
if (colorspace == PNG_COLOR_RGB_A && rowY == bmp->height - 1) {
rowExpander(bmp->width, palette, &scanline[1], Bitmap_GetRow(bmp, rowY));
}
}

/* Check if image fully decoded or not */
Expand Down
7 changes: 4 additions & 3 deletions src/Block.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ int Block_FindID(const cc_string* name) {
cc_string blockName;
int block;

for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) {
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++)
{
blockName = Block_UNSAFE_GetName(block);
if (String_CaselessEquals(&blockName, name)) return block;
}
Expand Down Expand Up @@ -604,7 +605,7 @@ static int RotateVertical(cc_string* name, int offset) {

static int RotateFence(cc_string* name, int offset) {
/* Fence type blocks */
float yaw = Math_ClampAngle(LocalPlayer_Instance.Base.Yaw);
float yaw = Math_ClampAngle(Entities.CurPlayer->Base.Yaw);

if (yaw < 45.0f || (yaw >= 135.0f && yaw < 225.0f) || yaw > 315.0f) {
AutoRotate_Insert(name, offset, "-WE");
Expand All @@ -629,7 +630,7 @@ static int RotatePillar(cc_string* name, int offset) {
}

static int RotateDirection(cc_string* name, int offset) {
float yaw = Math_ClampAngle(LocalPlayer_Instance.Base.Yaw);
float yaw = Math_ClampAngle(Entities.CurPlayer->Base.Yaw);

if (yaw >= 45.0f && yaw < 135.0f) {
AutoRotate_Insert(name, offset, "-E");
Expand Down
86 changes: 42 additions & 44 deletions src/Camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Camera_OnRawMovement(float deltaX, float deltaY) {
cam_deltaX += deltaX; cam_deltaY += deltaY;
}

void Camera_KeyLookUpdate(double delta) {
void Camera_KeyLookUpdate(float delta) {
if (Gui.InputGrab) return;
/* divide by 25 to have reasonable sensitivity for default mouse sens */
float amount = (Camera.Sensitivity / 25.0f) * (1000 * delta);
Expand All @@ -42,33 +42,32 @@ static void PerspectiveCamera_GetProjection(struct Matrix* proj) {
Gfx_CalcPerspectiveMatrix(proj, fovy, aspectRatio, (float)Game_ViewDistance);
}

static void PerspectiveCamera_GetView(struct Matrix* mat) {
static void PerspectiveCamera_GetView(struct LocalPlayer* p, struct Matrix* mat) {
Vec3 pos = Camera.CurrentPos;
Vec2 rot = Camera.Active->GetOrientation();
Vec2 rot = Camera.Active->GetOrientation(p);
Matrix_LookRot(mat, pos, rot);
Matrix_MulBy(mat, &Camera.TiltM);
}

static void PerspectiveCamera_GetPickedBlock(struct RayTracer* t) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec3 dir = Vec3_GetDirVector(p->Yaw * MATH_DEG2RAD, p->Pitch * MATH_DEG2RAD + Camera.TiltPitch);
Vec3 eyePos = Entity_GetEyePosition(p);
float reach = LocalPlayer_Instance.ReachDistance;
Picking_CalcPickedBlock(&eyePos, &dir, reach, t);
static void PerspectiveCamera_GetPickedBlock(struct LocalPlayer* p, struct RayTracer* t) {
struct Entity* e = &p->Base;
Vec3 dir = Vec3_GetDirVector(e->Yaw * MATH_DEG2RAD, e->Pitch * MATH_DEG2RAD + Camera.TiltPitch);
Vec3 eyePos = Entity_GetEyePosition(e);
Picking_CalcPickedBlock(&eyePos, &dir, p->ReachDistance, t);
}

#define CAMERA_SENSI_FACTOR (0.0002f / 3.0f * MATH_RAD2DEG)

static Vec2 PerspectiveCamera_GetMouseDelta(double delta) {
static Vec2 PerspectiveCamera_GetMouseDelta(float delta) {
float sensitivity = CAMERA_SENSI_FACTOR * Camera.Sensitivity;
static float speedX, speedY, newSpeedX, newSpeedY, accelX, accelY;
Vec2 v;

if (Camera.Smooth) {
accelX = (cam_deltaX - speedX) * 35 / Camera.Mass;
accelY = (cam_deltaY - speedY) * 35 / Camera.Mass;
newSpeedX = accelX * (float)delta + speedX;
newSpeedY = accelY * (float)delta + speedY;
newSpeedX = accelX * delta + speedX;
newSpeedY = accelY * delta + speedY;

/* High acceleration means velocity overshoots the correct position on low FPS, */
/* causing wiggling. If newSpeed has opposite sign of speed, set speed to 0 */
Expand All @@ -86,8 +85,8 @@ static Vec2 PerspectiveCamera_GetMouseDelta(double delta) {
return v;
}

static void PerspectiveCamera_UpdateMouseRotation(double delta) {
struct Entity* e = &LocalPlayer_Instance.Base;
static void PerspectiveCamera_UpdateMouseRotation(struct LocalPlayer* p, float delta) {
struct Entity* e = &p->Base;
struct LocationUpdate update;
Vec2 rot = PerspectiveCamera_GetMouseDelta(delta);

Expand All @@ -108,15 +107,14 @@ static void PerspectiveCamera_UpdateMouseRotation(double delta) {
e->VTABLE->SetLocation(e, &update);
}

static void PerspectiveCamera_UpdateMouse(double delta) {
static void PerspectiveCamera_UpdateMouse(struct LocalPlayer* p, float delta) {
if (!Gui.InputGrab && Window_Main.Focused) Window_UpdateRawMouse();

PerspectiveCamera_UpdateMouseRotation(delta);
PerspectiveCamera_UpdateMouseRotation(p, delta);
cam_deltaX = 0; cam_deltaY = 0;
}

static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
struct LocalPlayer* p = &LocalPlayer_Instance;
static void PerspectiveCamera_CalcViewBobbing(struct LocalPlayer* p, float t, float velTiltScale) {
struct Entity* e = &p->Base;

struct Matrix tiltY, velX;
Expand Down Expand Up @@ -148,23 +146,23 @@ static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
/*########################################################################################################################*
*---------------------------------------------------First person camera---------------------------------------------------*
*#########################################################################################################################*/
static Vec2 FirstPersonCamera_GetOrientation(void) {
struct Entity* p = &LocalPlayer_Instance.Base;
static Vec2 FirstPersonCamera_GetOrientation(struct LocalPlayer* p) {
struct Entity* e = &p->Base;
Vec2 v;
v.x = p->Yaw * MATH_DEG2RAD;
v.y = p->Pitch * MATH_DEG2RAD;
v.x = e->Yaw * MATH_DEG2RAD;
v.y = e->Pitch * MATH_DEG2RAD;
return v;
}

static Vec3 FirstPersonCamera_GetPosition(float t) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec3 camPos = Entity_GetEyePosition(p);
float yaw = p->Yaw * MATH_DEG2RAD;
PerspectiveCamera_CalcViewBobbing(t, 1);
static Vec3 FirstPersonCamera_GetPosition(struct LocalPlayer* p, float t) {
struct Entity* e = &p->Base;
Vec3 camPos = Entity_GetEyePosition(e);
float yaw = e->Yaw * MATH_DEG2RAD;
PerspectiveCamera_CalcViewBobbing(p, t, 1);

camPos.y += Camera.BobbingVer;
camPos.x += Camera.BobbingHor * (float)Math_Cos(yaw);
camPos.z += Camera.BobbingHor * (float)Math_Sin(yaw);
camPos.x += Camera.BobbingHor * Math_CosF(yaw);
camPos.z += Camera.BobbingHor * Math_SinF(yaw);
return camPos;
}

Expand All @@ -185,36 +183,36 @@ static struct Camera cam_FirstPerson = {
#define DEF_ZOOM 3.0f
static float dist_third = DEF_ZOOM, dist_forward = DEF_ZOOM;

static Vec2 ThirdPersonCamera_GetOrientation(void) {
struct Entity* p = &LocalPlayer_Instance.Base;
static Vec2 ThirdPersonCamera_GetOrientation(struct LocalPlayer* p) {
struct Entity* e = &p->Base;
Vec2 v;
v.x = p->Yaw * MATH_DEG2RAD;
v.y = p->Pitch * MATH_DEG2RAD;
v.x = e->Yaw * MATH_DEG2RAD;
v.y = e->Pitch * MATH_DEG2RAD;
if (cam_isForwardThird) { v.x += MATH_PI; v.y = -v.y; }

v.x += cam_rotOffset.x * MATH_DEG2RAD;
v.y += cam_rotOffset.y * MATH_DEG2RAD;
return v;
}

static float ThirdPersonCamera_GetZoom(void) {
static float ThirdPersonCamera_GetZoom(struct LocalPlayer* p) {
float dist = cam_isForwardThird ? dist_forward : dist_third;
/* Don't allow zooming out when -fly */
if (dist > DEF_ZOOM && !LocalPlayer_CheckCanZoom()) dist = DEF_ZOOM;
if (dist > DEF_ZOOM && !LocalPlayer_CheckCanZoom(p)) dist = DEF_ZOOM;
return dist;
}

static Vec3 ThirdPersonCamera_GetPosition(float t) {
struct Entity* p = &LocalPlayer_Instance.Base;
float dist = ThirdPersonCamera_GetZoom();
static Vec3 ThirdPersonCamera_GetPosition(struct LocalPlayer* p, float t) {
struct Entity* e = &p->Base;
float dist = ThirdPersonCamera_GetZoom(p);
Vec3 target, dir;
Vec2 rot;

PerspectiveCamera_CalcViewBobbing(t, dist);
target = Entity_GetEyePosition(p);
PerspectiveCamera_CalcViewBobbing(p, t, dist);
target = Entity_GetEyePosition(e);
target.y += Camera.BobbingVer;

rot = Camera.Active->GetOrientation();
rot = Camera.Active->GetOrientation(p);
dir = Vec3_GetDirVector(rot.x, rot.y);
Vec3_Negate(&dir, &dir);

Expand Down Expand Up @@ -255,21 +253,21 @@ static void OnRawMovement(void* obj, float deltaX, float deltaY) {
Camera.Active->OnRawMovement(deltaX, deltaY);
}

static void OnAxisUpdate(void* obj, int axis, float x, float y) {
static void OnAxisUpdate(void* obj, int port, int axis, float x, float y) {
if (!Input.RawMode) return;
if (Gamepad_AxisBehaviour[axis] != AXIS_BEHAVIOUR_CAMERA) return;

Camera.Active->OnRawMovement(x, y);
}

static void OnHacksChanged(void* obj) {
struct HacksComp* h = &LocalPlayer_Instance.Hacks;
struct HacksComp* h = &Entities.CurPlayer->Hacks;
/* Leave third person if not allowed anymore */
if (!h->CanUseThirdPerson || !h->Enabled) Camera_CycleActive();
}

void Camera_CycleActive(void) {
struct LocalPlayer* p = &LocalPlayer_Instance;
struct LocalPlayer* p = &LocalPlayer_Instances[0];
if (Game_ClassicMode) return;
Camera.Active = Camera.Active->next;

Expand Down
Loading

0 comments on commit 89c047f

Please sign in to comment.