Skip to content

Commit e97bc08

Browse files
Add pedestrians + power-ups (#118)
* Add pedestrians * Pedestrian tweaks * glrenderer: add texture tranformation support for animated pedestrians * Use Brender functions in more locations * Implement CheckPileDriverBonus * revert changes to CollideCamera2 except bugfix * fix uninitialized variable Co-authored-by: Dethrace Engineering Department <78985374+dethrace-labs@users.noreply.github.com> Co-authored-by: Dethrace Labs <carmageddon.reversing@gmail.com>
1 parent 40b326b commit e97bc08

37 files changed

+4561
-1395
lines changed

src/BRSRC13/CORE/STD/brstdlib.c

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ void* BrMemCpy(void* s1, void* s2, size_t n) {
1818
}
1919

2020
void* BrMemSet(void* s, int c, size_t n) {
21+
if (s == NULL) {
22+
// Passing a null target pointer is undefined behavior
23+
return NULL;
24+
}
2125
return memset(s, c, n);
2226
}
2327

src/BRSRC13/include/brender/br_defs.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
#define BR_ANGLE_RAD(rad) ((br_angle)((rad)*10430))
2828

2929
#define BrDegreeToRadian(d) ((br_scalar)((d) * (PI / 180.0)))
30-
#define BrDegreeToAngle(d) ((br_angle)(long)((d) * (65536.0 / 360.0))) // "d * 182.044444444"
31-
#define BrAngleToDegrees(a) ((br_angle)(long)((a) * (360.0 / 65536.0))) // "d * 0.0054931640625"
30+
31+
#define BrDegreeToAngle(d) ((br_angle)(long)((d) * (65536.0f / 360.0f))) // "d * 182.044444444"
32+
#define BrAngleToDegrees(a) ((br_angle)(long)((a) * (360.0f / 65536.0f))) // "d * 0.0054931640625"
3233

3334
#define BR_SCALAR(x) ((br_scalar)(x))
3435

src/BRSRC13/include/brender/brender.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ br_material_find_cbfn* BrMaterialFindHook(br_material_find_cbfn* hook);
6161
// BrMatrix236
6262
void BrMatrix23Copy(br_matrix23* A, br_matrix23* B);
6363
void BrMatrix23Identity(br_matrix23* mat);
64+
void BrMatrix23Mul(br_matrix23* A, br_matrix23* B, br_matrix23* C);
6465

6566
// BrMatrix34
6667
void BrMatrix34Identity(br_matrix34* mat);

src/DETHRACE/common/brucetrk.c

+36-48
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ void XZToColumnXZ(tU8* pColumn_x, tU8* pColumn_z, br_scalar pX, br_scalar pZ, tT
7272

7373
x = (pX - pTrack_spec->origin_x) / pTrack_spec->column_size_x;
7474
z = (pZ - pTrack_spec->origin_z) / pTrack_spec->column_size_z;
75-
if (x < 0.0) {
76-
x = 0.0;
75+
if (x < 0.0f) {
76+
x = 0.0f;
7777
}
78-
if (pTrack_spec->ncolumns_x <= x) {
79-
x = pTrack_spec->ncolumns_x - 1.0;
78+
if (x >= pTrack_spec->ncolumns_x) {
79+
x = pTrack_spec->ncolumns_x - 1.0f;
8080
}
81-
if (z < 0.0) {
82-
z = 0.0;
81+
if (z < 0.0f) {
82+
z = 0.0f;
8383
}
84-
if (pTrack_spec->ncolumns_z <= z) {
85-
z = pTrack_spec->ncolumns_z - 1.0;
84+
if (z >= pTrack_spec->ncolumns_z) {
85+
z = pTrack_spec->ncolumns_z - 1.0f;
8686
}
8787
*pColumn_x = x;
8888
*pColumn_z = z;
@@ -277,7 +277,7 @@ void ExtractColumns(tTrack_spec* pTrack_spec) {
277277
if (pTrack_spec->ampersand_digits <= 0) {
278278
pTrack_spec->non_car_list = NULL;
279279
} else {
280-
pTrack_spec->non_car_list = BrMemAllocate(sizeof(intptr_t) * pTrack_spec->ampersand_digits, kMem_non_car_list);
280+
pTrack_spec->non_car_list = BrMemAllocate(sizeof(br_actor*) * pTrack_spec->ampersand_digits, kMem_non_car_list);
281281
}
282282
if (unsplit) {
283283
**pTrack_spec->columns = pTrack_spec->the_actor;
@@ -407,7 +407,7 @@ void RenderTrack(br_actor* pWorld, tTrack_spec* pTrack_spec, br_actor* pCamera,
407407
static br_actor* result;
408408
LOG_TRACE("(%p, %p, %p, %p, %d)", pWorld, pTrack_spec, pCamera, pCamera_to_world, pRender_blends);
409409

410-
if (pTrack_spec->columns) {
410+
if (pTrack_spec->columns != NULL) {
411411
if (pRender_blends) {
412412
DrawColumns(1, pTrack_spec, min_x, max_x, min_z, max_z, pCamera_to_world);
413413
} else {
@@ -417,7 +417,7 @@ void RenderTrack(br_actor* pWorld, tTrack_spec* pTrack_spec, br_actor* pCamera,
417417
max_x = column_x;
418418
min_z = column_z;
419419
max_z = column_z;
420-
tan_fov_ish = sin(BrAngleToRadian(camera->field_of_view / 2)) / cos(BrAngleToRadian(camera->field_of_view / 2));
420+
tan_fov_ish = sinf(BrAngleToRadian(camera->field_of_view / 2)) / cosf(BrAngleToRadian(camera->field_of_view / 2));
421421
edge_after.v[0] = camera->aspect * tan_fov_ish;
422422
edge_after.v[1] = tan_fov_ish;
423423
edge_after.v[2] = -1.0;
@@ -426,29 +426,23 @@ void RenderTrack(br_actor* pWorld, tTrack_spec* pTrack_spec, br_actor* pCamera,
426426
edge_before.v[2] = camera->yon_z * gYon_factor * -1.0;
427427
BrMatrix34ApplyV(&edge_after, &edge_before, pCamera_to_world);
428428
XZToColumnXZ(&column_x, &column_z, pCamera_to_world->m[3][0] + edge_after.v[0], pCamera_to_world->m[3][2] + edge_after.v[2], pTrack_spec);
429-
if (column_x >= min_x) {
430-
if (column_x > max_x) {
431-
max_x = column_x;
432-
}
433-
} else {
429+
if (column_x < min_x) {
434430
min_x = column_x;
431+
} else if (column_x > max_x) {
432+
max_x = column_x;
435433
}
436-
if (column_z >= min_z) {
437-
if (column_z > max_z) {
438-
max_z = column_z;
439-
}
440-
} else {
434+
if (column_z < min_z) {
441435
min_z = column_z;
436+
} else if (column_z > max_z) {
437+
max_z = column_z;
442438
}
443439
edge_before.v[0] = -edge_before.v[0];
444440
BrMatrix34ApplyV(&edge_after, &edge_before, pCamera_to_world);
445441
XZToColumnXZ(&column_x, &column_z, pCamera_to_world->m[3][0] + edge_after.v[0], pCamera_to_world->m[3][2] + edge_after.v[2], pTrack_spec);
446-
if (column_x >= min_x) {
447-
if (column_x > max_x) {
448-
max_x = column_x;
449-
}
450-
} else {
442+
if (column_x < min_x) {
451443
min_x = column_x;
444+
} else if (column_x > max_x) {
445+
max_x = column_x;
452446
}
453447
if (column_z >= min_z) {
454448
if (column_z > max_z) {
@@ -460,44 +454,36 @@ void RenderTrack(br_actor* pWorld, tTrack_spec* pTrack_spec, br_actor* pCamera,
460454
edge_before.v[1] = -edge_before.v[1];
461455
BrMatrix34ApplyV(&edge_after, &edge_before, pCamera_to_world);
462456
XZToColumnXZ(&column_x, &column_z, pCamera_to_world->m[3][0] + edge_after.v[0], pCamera_to_world->m[3][2] + edge_after.v[2], pTrack_spec);
463-
if (column_x >= min_x) {
464-
if (column_x > max_x) {
465-
max_x = column_x;
466-
}
467-
} else {
457+
if (column_x < min_x) {
468458
min_x = column_x;
459+
} else if (column_x > max_x) {
460+
max_x = column_x;
469461
}
470-
if (column_z >= min_z) {
471-
if (column_z > max_z) {
472-
max_z = column_z;
473-
}
474-
} else {
462+
if (column_z < min_z) {
475463
min_z = column_z;
464+
} else if (column_z > max_z) {
465+
max_z = column_z;
476466
}
477467
edge_before.v[0] = -edge_before.v[0];
478468
BrMatrix34ApplyV(&edge_after, &edge_before, pCamera_to_world);
479469
XZToColumnXZ(&column_x, &column_z, pCamera_to_world->m[3][0] + edge_after.v[0], pCamera_to_world->m[3][2] + edge_after.v[2], pTrack_spec);
480-
if (column_x >= min_x) {
481-
if (column_x > max_x) {
482-
max_x = column_x;
483-
}
484-
} else {
470+
if (column_x < min_x) {
485471
min_x = column_x;
472+
} else if (column_x > max_x) {
473+
max_x = column_x;
486474
}
487-
if (column_z >= min_z) {
488-
if (column_z > max_z) {
489-
max_z = column_z;
490-
}
491-
} else {
475+
if (column_z < min_z) {
492476
min_z = column_z;
477+
} else if (column_z > max_z) {
478+
max_z = column_z;
493479
}
494-
if (min_x) {
480+
if (min_x != 0) {
495481
min_x--;
496482
}
497483
if (pTrack_spec->ncolumns_x - 1 > max_x) {
498484
max_x++;
499485
}
500-
if (min_z) {
486+
if (min_z != 0) {
501487
min_z--;
502488
}
503489
if (pTrack_spec->ncolumns_z - 1 > max_z) {
@@ -512,10 +498,12 @@ void RenderTrack(br_actor* pWorld, tTrack_spec* pTrack_spec, br_actor* pCamera,
512498

513499
// IDA: br_scalar __cdecl GetYonFactor()
514500
br_scalar GetYonFactor() {
501+
515502
return gYon_factor;
516503
}
517504

518505
// IDA: void __cdecl SetYonFactor(br_scalar pNew)
519506
void SetYonFactor(br_scalar pNew) {
507+
520508
gYon_factor = pNew;
521509
}

0 commit comments

Comments
 (0)