ChrisOS Research ProjectOperating systems · language systems · graphics · machine emulation
DOCUMENTATION ARCHIVEMAIN BRANCH
ChrisOS/Source reference: LIB/SIM.CC

Source reference: LIB/SIM.CC

Deterministic source record. The complete textual file is reproduced below; this page does not replace architectural interpretation in the authored chapters.

File identity

Field Value
Path LIB/SIM.CC
Lines 66
Bytes 1210
SHA-256 afea968fcc033fa2a8578cde7eba510b4d72fe27e467e5d56a8292acb8dfb503
ChrisOS revision da3df29cb397932c43d32373871fb9380e688ade

Detected syntactic dependencies

Line Include
— No preprocessor include detected.

Detected symbols

Line Symbol
4 sim_solid
12 sim_blocked
26 sim_move

Complete source

The following block is the complete textual file at the recorded revision. No lines are elided, abbreviated or paraphrased.

#ifndef SIM_CC_H
#define SIM_CC_H

int sim_solid(int id) {
    if (id == 0)
        return 0;
    if (id == 5)
        return 0;
    return 1;
}

int sim_blocked(float x, float y, float z) {
    int ix;
    int iy;
    int iz;
    ix = (int)x;
    iy = (int)y;
    iz = (int)z;
    if (sim_solid(voxel_get(ix, iy, iz)))
        return 1;
    if (sim_solid(voxel_get(ix, iy + 1, iz)))
        return 1;
    return 0;
}

void sim_move(float *x, float *y, float *z, float *vx, float *vy, float *vz) {
    float nx;
    float ny;
    float nz;
    int step;
    *vy = *vy - 0.045;
    nx = *x + *vx;
    if (sim_blocked(nx, *y, *z))
        *vx = 0.0;
    else
        *x = nx;
    nz = *z + *vz;
    if (sim_blocked(*x, *y, nz))
        *vz = 0.0;
    else
        *z = nz;
    ny = *y + *vy;
    if (sim_blocked(*x, ny, *z)) {
        if (*vy < 0.0)
            *vy = 0.0;
        else
            *vy = 0.0 - *vy * 0.2;
    } else {
        *y = ny;
    }
    if (*y < 1.0) {
        *y = 1.0;
        *vy = 0.0;
    }
    step = 0;
    while (step < 12 && sim_blocked(*x, *y, *z)) {
        *y = *y + 1.0;
        *vy = 0.0;
        step = step + 1;
    }
    *vx = *vx * 0.72;
    *vz = *vz * 0.72;
}

#endif

Role of this record

The atlas guarantees file-by-file traceability. Responsibility, invariants, ownership, concurrency, security, performance and subsystem interactions belong in authored chapters and must cite this file when applicable.

Document record ID: source-afea968fcc033fa2 Reviewed source: da3df29cb397 Class: generated-source-reference