Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Car control and physics attempt #1 #57

Merged
merged 11 commits into from
Sep 8, 2021
15 changes: 15 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Unused functions

### ToggleControls
Appears to have been a way to change the steering handling? "Original Controls", "Accelerated steering", "0.75 Accelerated", "0.5 Accelerated", "New controls". The game is hardcoded to use "0.5 Accelerated" and this function is not called from anywhere.

### DrawSomeText / DrawSomeText2
Not accessible in the retail game, but the functions still exists. Can be invoked in a very early demo build. For each of 7 fonts, it prints 15 lines of dummy text and saves a screenshot each time.

### ToggleArrow
Does a `return` at the top of the function in the retail game. Appears to have been used for debugging. Replaces the current car model with an arrow(?). Also enables debug output showing the car location and stats.

### SetFlag2 / ToggleFlying
TBA


26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,29 @@ export DETHRACE_ROOT_DIR=/path/to/carmageddon

## Build

Dethrace uses [cmake](https://cmake.org/) for generating build files.

To generate the build files (generally only required once):
```sh
mkdir build
cd build
cmake ..
```

Build:
```sh
make build
make && ./dethrace
```

### Run

After building, `build/dethrace` is created

```sh
./dethrace [args]
```


## Run tests

A subset of tests do not require `DETHRACE_ROOT_DIR`. They run via Github actions when code is committed to this repo. This allows us to keep nice and clean and avoid storing any potentially legally problematic resouces in our repo.
Expand All @@ -71,11 +90,6 @@ To run a single test
DETHRACE_TEST_ARGS="-n test_name" make test
```

## Run game
```sh
make run
```

## Changelog
[From the beginning until release](docs/CHANGELOG.md)

Expand Down
72 changes: 72 additions & 0 deletions SCRATCH
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SCRATCH

// gRender_screen = DRPixelmapAllocateSub(gBack_screen, pX_offset, pY_offset, pWidth, pHeight);
render background(sky) to gRender_screen(back screen)
render 3d scene
render foreground to gBack_screen(cockpit, headups etc)
swap buffers

render background(sky) to gRender_screen(back screen)
- harness_renderscreen
render 3d scene
- clear back screen to black
- do opengl rendering

render foreground to gBack_screen(cockpit, headups etc)
- ignore any black pixels

swap buffers

0053A250
- 0x53A43C gKey_array

005505F4 dword_5505F4 //joy?
005507C0
- 005507e0 gJoy_array
005507E0
- 005508EC gKey_mapping

005505F4 offset in cyclepollkeys to gJoy_array
- diff is 115 ints

0x550428

/ DOS

00136444 gKey_array
001363A0 gJoy_array

0x1361D4 offset in cyclepollkeys to gJoy_array
- diff is 115 ints

[DEBUG] ShiftBoundGrooveFunks bound funk 0 : 0x0
[DEBUG] ShiftBoundGrooveFunks bound funk 1 : 0x1008c897c
[DEBUG] ShiftBoundGrooveFunks bound funk 2 : 0x1008c8a04
[DEBUG] ShiftBoundGrooveFunks bound funk 3 : 0x1008c8828
[DEBUG] ShiftBoundGrooveFunks bound funk 4 : 0x1008c88b0
[DEBUG] ShiftBoundGrooveFunks bound funk 5 : 0x1008c8938
[DEBUG] ShiftBoundGrooveFunks bound funk 6 : 0x1008c89c0
[DEBUG] ShiftBoundGrooveFunks bound funk 7 : 0x1008c886c
[DEBUG] ShiftBoundGrooveFunks bound funk 8 : 0x1008c88f4
[DEBUG] ShiftBoundGrooveFunks bound funk 9 : 0x1008c8a8c
[DEBUG] ShiftBoundGrooveFunks bound funk 10 : 0x1008c8b14

[DEBUG] ShiftBoundGrooveFunks bound funk 0 : 0x0
[DEBUG] ShiftBoundGrooveFunks bound funk 1 : 0x10389837c
[DEBUG] ShiftBoundGrooveFunks bound funk 2 : 0x103898404
[DEBUG] ShiftBoundGrooveFunks bound funk 3 : 0x103898228
[DEBUG] ShiftBoundGrooveFunks bound funk 4 : 0x1038982b0
[DEBUG] ShiftBoundGrooveFunks bound funk 5 : 0x103898338
[DEBUG] ShiftBoundGrooveFunks bound funk 6 : 0x1038983c0
[DEBUG] ShiftBoundGrooveFunks bound funk 7 : 0x10389826c
[DEBUG] ShiftBoundGrooveFunks bound funk 8 : 0x1038982f4
[DEBUG] ShiftBoundGrooveFunks bound funk 9 : 0x10389848c
[DEBUG] ShiftBoundGrooveFunks bound funk 10 : 0x103898514

sometimes selfcentre is called multiple times per frame
applyphysicstocars always is within time_step

acc_force is not dropping down fast enough

ts2 8.015344638012678e-11,
acc 5.92524658203125e2, revs 1.16219453125e4 v160 2.962623291015625e2, v118 1.703537831632129e-11, speed 0.0 max_force_rear 7.437321662902832, v135 1.481311645507812e2, limit 1 ts2 3.074372708797455e-1, acc 4.121511840820312e2, revs 7.6736416015625e3 v160 2.05921875e2, v118 3.127531499558245e-6, speed 0.0 max_force_rear 7.437321662902832, v135 1.029609375e2, limit 1 ts2 3.450555503368378e-1, acc 2.825576171875e2, revs 5.08019775390625e3 v160 1.411062774658203e2, v118 3.965127234550891e-6, speed 2.803576358087277 max_force_rear 8.247367858886719, v135 7.055313873291016e1, limit 1 ts2 3.663769066333771e-1, acc 1.920951385498047e2, revs 3.416863525390625e3 v160 9.58643798828125e1, v118 4.987010015611304e-6, speed 4.356438601662044 max_force_rear 8.737387657165527, v135 4.793218994140625e1, limit 1 ts2 3.764173984527588e-1, acc 1.30189453125e2, revs 2.38487939453125e3 v160 6.490651702880859e1, v118 3.554842805897351e-6, speed 5.955295815963242 max_force_rear 9.003288269042969, v135 3.24532585144043e1, limit 1 ts2 3.783531486988068e-1, acc 8.838812255859375e1, revs 1.777574462890625e3 v160 4.40048828125e1, v118 - 5.434078630059958e-4, speed 5.955295815963242 max_force_rear 9.125821113586426, v135 2.200244140625e1, limit 1 ts2 3.753950297832489e-1, acc 6.089559936523438e1, revs 1.454000854492188e3 v160 3.026010131835938e1, v118 - 1.982751418836415e-4, speed 9.13116980073459 max_force_rear 9.149258613586426, v135 1.513005065917969e1, limit 1 ts2 3.73871237039566e-1, acc 4.246442031860352e1, revs 1.315802001953125e3 v160 2.104527473449707e1, v118 1.181649276986718e-4, speed 9.13116980073459 max_force_rear 9.113421440124512, v135 1.052263736724854e1, limit 1 ts2 3.743874132633209e-1, acc 3.010890197753906e1, revs 1.3012431640625e3 v160 1.48672571182251e1, v118 - 4.263391747372225e-5, speed 1.228963766974154e1 max_force_rear 9.094904899597168, v135 7.433628559112549, limit 1 ts2 3.726563155651093e-1, acc 2.178503227233887e1, revs 1.369130737304688e3 v160 1.07061882019043e1, v118 - 1.312031417910475e-5, speed 1.228963766974154e1 max_force_rear 9.101181030273438, v135 5.353094100952148, limit 1 ts2 3.762767016887665e-1, acc 1.618281555175781e1, revs 1.492148193359375e3 v160 7.903269290924072, v118 - 1.101096768252319e-5, speed 1.548429768039707e1 max_force_rear 9.08011531829834, v135 3.951634645462036, limit 0
12 changes: 12 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).



### July 17 2021
- 3d rendering somewhat implemented. Flat shaded, no textures, but camera, cars and track are visible in the right place!

### April 21 2021
- Actual game main loop running! Rendering, phyiscs, sound etc commented out, so all we can see is a black screen with the 2d rendering.

### March 24 2021
- Menu screens up to and including race and car selection implemented
- Fixed OpenGL crashes by moving back to single thread

### September 3 2020
- Cutscenes displayed on startup.
- Main menu renders and responds to key up and down events. Hitting "enter" on any option causes a crash
Expand Down
47 changes: 43 additions & 4 deletions src/BRSRC13/CORE/MATH/matrix34.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "matrix34.h"
#include "harness_trace.h"
#include "vector.h"
#include <math.h>

br_matrix34 mattmp1;
Expand Down Expand Up @@ -140,7 +141,31 @@ void BrMatrix34Rotate(br_matrix34* mat, br_angle r, br_vector3* a) {
br_scalar sy;
br_scalar sz;
LOG_TRACE("(%p, %d, %p)", mat, r, a);
NOT_IMPLEMENTED();

s = BR_SIN(r);
c = BR_COS(r);
t = 1.0 - c;

txy = t * a->v[0];
txz = txy * a->v[2];
txy = txy * a->v[1];
tyz = t * a->v[1] * a->v[2];

sx = s * a->v[0];
sy = s * a->v[1];
sz = s * a->v[2];

M(0, 0) = t * a->v[0] * a->v[0] + c;
M(0, 1) = txy + sz;
M(0, 2) = txz - sy;
M(1, 0) = txy - sz;
M(1, 1) = t * a->v[1] * a->v[1] + c;
M(1, 2) = tyz + sx;
M(2, 0) = txz + sy;
M(2, 1) = tyz - sx;
M(2, 2) = t * a->v[2] * a->v[2] + c;

M(3, 0) = M(3, 1) = M(3, 2) = 0.0;
}

// IDA: void __cdecl BrMatrix34Translate(br_matrix34 *mat, br_scalar dx, br_scalar dy, br_scalar dz)
Expand Down Expand Up @@ -297,7 +322,15 @@ void BrMatrix34LPInverse(br_matrix34* A, br_matrix34* B) {
// IDA: void __cdecl BrMatrix34LPNormalise(br_matrix34 *A, br_matrix34 *B)
void BrMatrix34LPNormalise(br_matrix34* A, br_matrix34* B) {
LOG_TRACE("(%p, %p)", A, B);
NOT_IMPLEMENTED();

BrVector3Normalise((br_vector3*)A->m[2], (br_vector3*)B->m[2]);
BrVector3Cross((br_vector3*)A->m[0], (br_vector3*)B->m[1], (br_vector3*)A->m[2]);
BrVector3Normalise((br_vector3*)A->m[0], (br_vector3*)A->m[0]);
BrVector3Cross((br_vector3*)A->m[1], (br_vector3*)A->m[2], (br_vector3*)A->m[0]);

A(3, 0) = B(3, 0);
A(3, 1) = B(3, 1);
A(3, 2) = B(3, 2);
}

// IDA: void __cdecl BrMatrix34RollingBall(br_matrix34 *mat, int dx, int dy, int radius)
Expand Down Expand Up @@ -441,7 +474,10 @@ void BrMatrix34PostRotateZ(br_matrix34* mat, br_angle rz) {
// IDA: void __cdecl BrMatrix34PreRotate(br_matrix34 *mat, br_angle r, br_vector3 *axis)
void BrMatrix34PreRotate(br_matrix34* mat, br_angle r, br_vector3* axis) {
LOG_TRACE("(%p, %d, %p)", mat, r, axis);
NOT_IMPLEMENTED();

BrMatrix34Rotate(&mattmp1, r, axis);
BrMatrix34Mul(&mattmp2, &mattmp1, mat);
BrMatrix34Copy(mat, &mattmp2);
}

// IDA: void __cdecl BrMatrix34PostRotate(br_matrix34 *mat, br_angle r, br_vector3 *axis)
Expand All @@ -453,7 +489,10 @@ void BrMatrix34PostRotate(br_matrix34* mat, br_angle r, br_vector3* axis) {
// IDA: void __cdecl BrMatrix34PreTranslate(br_matrix34 *mat, br_scalar x, br_scalar y, br_scalar z)
void BrMatrix34PreTranslate(br_matrix34* mat, br_scalar x, br_scalar y, br_scalar z) {
LOG_TRACE("(%p, %f, %f, %f)", mat, x, y, z);
NOT_IMPLEMENTED();

BrMatrix34Translate(&mattmp1, x, y, z);
BrMatrix34Mul(&mattmp2, &mattmp1, mat);
BrMatrix34Copy(mat, &mattmp2);
}

// IDA: void __cdecl BrMatrix34PostTranslate(br_matrix34 *mat, br_scalar x, br_scalar y, br_scalar z)
Expand Down
5 changes: 0 additions & 5 deletions src/BRSRC13/CORE/V1DB/prepmesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,8 @@ void BrModelUpdate(br_model* model, br_uint_16 flags) {
br_face* fp;
LOG_TRACE("(%p, %d)", model, flags);

LOG_DEBUG("flags %d", model->flags);
if (!(model->flags & BR_MODF_PREPREPARED)) {
LOG_DEBUG("inside confi");
if (!model->faces || !model->vertices) {
LOG_DEBUG("exit 2");
BrFailure("BrModelUpdate: model has no faces or vertices (%s)", model->identifier ? model->identifier : "<NULL>");
}
if (flags & BR_MODU_UNKNOWN) {
Expand All @@ -582,7 +579,6 @@ void BrModelUpdate(br_model* model, br_uint_16 flags) {
}
if (!model->prepared || flags & 0xFFD0) {
if (!model->faces || !model->vertices) {
LOG_DEBUG("exit 1");
return;
}
PrepareFaceNormals(model);
Expand All @@ -606,7 +602,6 @@ void BrModelUpdate(br_model* model, br_uint_16 flags) {
v11m = (v11model*)model->prepared;

if (v11m) {
LOG_DEBUG("has prepared model");
for (g = 0; g < v11m->ngroups; g++) {
//prepareEdges(&v11m->groups[g], model);
}
Expand Down
4 changes: 4 additions & 0 deletions src/BRSRC13/brender.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void BrMatrix34PreTransform(br_matrix34* mat, br_transform* xform);
void BrMatrix34PostTransform(br_matrix34* mat, br_transform* xform);
void BrMatrix34PreRotateX(br_matrix34* mat, br_angle rx);
void BrMatrix34TApplyV(br_vector3* A, br_vector3* B, br_matrix34* C);
void BrMatrix34LPNormalise(br_matrix34* A, br_matrix34* B);
void BrMatrix34PreRotate(br_matrix34* mat, br_angle r, br_vector3* axis);
void BrMatrix34Rotate(br_matrix34* mat, br_angle r, br_vector3* a);
void BrMatrix34PreTranslate(br_matrix34* mat, br_scalar x, br_scalar y, br_scalar z);

// BrMem
void BrMemFree(void* block);
Expand Down
2 changes: 1 addition & 1 deletion src/DETHRACE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
-Wno-unused-result
-Wno-error=sign-compare
-Wno-error=format-overflow
-Wno-error=unused-but-set-variable # (SelectRaceDraw::test2)
-Wno-error=unused-but-set-variable # (SelectRaceDraw::test2), etc
)
else()
target_compile_definitions(dethrace_obj PRIVATE -D_CRT_SECURE_NO_WARNINGS)
Expand Down
Loading