← back to davidkarpay__splat-sim

Function bodies 69 total

All specs Real LLM only Function bodies
dominantBody function · javascript · L71-L83 (13 LOC)
js/universe.js
function dominantBody(worldPos) {
  let best = TERRA;
  let bestDist = worldPos.distanceTo(TERRA.center);
  for (const body of BODIES) {
    if (body === TERRA) continue;
    const dist = worldPos.distanceTo(body.center);
    if (dist < body.soiRadius && dist < bestDist) {
      best = body;
      bestDist = dist;
    }
  }
  return best;
}
gravityVecAt function · javascript · L97-L104 (8 LOC)
js/universe.js
function gravityVecAt(worldPos) {
  const body = dominantBody(worldPos);
  _grav.copy(body.center).sub(worldPos);
  const r = _grav.length();
  if (r < body.radius * 0.5) return _gravZero.set(0, 0, 0);
  const gMag = PHYS.gravity * (body.radius * body.radius) / (r * r);
  return _grav.normalize().multiplyScalar(gMag);
}
planetGravityVec function · javascript · L107-L109 (3 LOC)
js/universe.js
function planetGravityVec(worldPos) {
  return gravityVecAt(worldPos);
}
flatToSphere function · javascript · L113-L118 (6 LOC)
js/universe.js
function flatToSphere(x, z, h) {
  const R = PLANET.radius;
  _ftsDir.set(x, R, z).normalize();
  _ftsResult.copy(PLANET.center).addScaledVector(_ftsDir, R + h);
  return _ftsResult;
}
sphereToFlat function · javascript · L120-L128 (9 LOC)
js/universe.js
function sphereToFlat(worldPos) {
  _stfFrom.copy(worldPos).sub(PLANET.center);
  _stfDir.copy(_stfFrom).normalize();
  if (_stfDir.y <= 0.01) { _stfResult.x = 0; _stfResult.z = 0; return _stfResult; }
  const scale = PLANET.radius / _stfDir.y;
  _stfResult.x = _stfDir.x * scale;
  _stfResult.z = _stfDir.z * scale;
  return _stfResult;
}
planetUp function · javascript · L130-L132 (3 LOC)
js/universe.js
function planetUp(worldPos) {
  return _puResult.copy(worldPos).sub(PLANET.center).normalize();
}
planetRadius function · javascript · L134-L136 (3 LOC)
js/universe.js
function planetRadius(worldPos) {
  return worldPos.distanceTo(PLANET.center);
}
Repobility · code-quality intelligence platform · https://repobility.com
altitudeAboveSphere function · javascript · L138-L140 (3 LOC)
js/universe.js
function altitudeAboveSphere(worldPos) {
  return planetRadius(worldPos) - PLANET.radius;
}
altitudeAGL function · javascript · L142-L147 (6 LOC)
js/universe.js
function altitudeAGL(worldPos) {
  const r = planetRadius(worldPos);
  const flat = sphereToFlat(worldPos);
  const surfaceR = PLANET.radius + terrainHeight(flat.x, flat.z);
  return r - surfaceR;
}
airDensityAtPos function · javascript · L149-L163 (15 LOC)
js/universe.js
function airDensityAtPos(worldPos) {
  const body = dominantBody(worldPos);
  if (!body.hasAtmosphere) return 0;
  const alt = worldPos.distanceTo(body.center) - body.radius;
  if (alt > body.atmosphereHeight) return 0;
  const T = 288.15 - 0.0065 * Math.min(Math.max(alt, 0), 11000);
  let rho = 1.225 * Math.pow(T / 288.15, 4.256);
  // Smooth fade in the top 20% of atmosphere (no hard cutoff)
  const fadeStart = body.atmosphereHeight * 0.8;
  if (alt > fadeStart) {
    const fade = 1 - (alt - fadeStart) / (body.atmosphereHeight - fadeStart);
    rho *= fade * fade;  // quadratic ease-out
  }
  return rho;
}
sphereRotation function · javascript · L166-L169 (4 LOC)
js/universe.js
function sphereRotation(worldPos) {
  const radial = planetUp(worldPos);
  return new THREE.Quaternion().setFromUnitVectors(_flatUp, radial);
}
fireWeapon function · javascript · L7-L45 (39 LOC)
js/weapons.js
function fireWeapon() {
  const now = performance.now();
  const w = STATE.weapons.types[STATE.weapons.current];
  if (now - STATE.lastFire < w.fireRate) return;
  if (w.ammo <= 0) return;

  STATE.lastFire = now;
  w.ammo--;
  playWeaponSound(w.name);

  const dir = new THREE.Vector3(0, 0, -1);
  dir.applyQuaternion(playerObj.quaternion);

  const pos = playerObj.position.clone();

  if (w.name === 'BOMB') {
    projectiles.push({
      pos: pos.clone(),
      vel: dir.clone().multiplyScalar(PROJ_SPEED * 0.3).add(STATE.velocity),
      type: w,
      life: 5,
      gravity: true
    });
  } else {
    projectiles.push({
      pos: pos.clone(),
      vel: dir.clone().multiplyScalar(PROJ_SPEED),
      type: w,
      life: 3,
      gravity: false
    });
  }

  // Muzzle flash
  spawnExplosion(
    pos.x + dir.x * 8, pos.y + dir.y * 8, pos.z + dir.z * 8,
    3, new THREE.Color(1, 0.8, 0.2), new THREE.Color(1, 0.4, 0.1), 5
  );
}
updateProjectiles function · javascript · L47-L66 (20 LOC)
js/weapons.js
function updateProjectiles(dt) {
  for (let i = projectiles.length - 1; i >= 0; i--) {
    const p = projectiles[i];
    p.life -= dt;
    if (p.life <= 0) { projectiles.splice(i, 1); continue; }

    // Gravity: apply toward planet center (not flat -Y)
    if (p.gravity) {
      const gravDir = planetGravityVec(p.pos);
      p.vel.add(gravDir.multiplyScalar(dt));
    }
    p.pos.add(p.vel.clone().multiplyScalar(dt));

    // Terrain collision (spherical)
    if (altitudeAGL(p.pos) < 0) {
      explodeAt(p.pos.x, p.pos.y, p.pos.z, p.type.radius, p.type.damage);
      projectiles.splice(i, 1);
    }
  }
}
explodeAt function · javascript · L68-L97 (30 LOC)
js/weapons.js
function explodeAt(x, y, z, radius, damage) {
  // Destroy terrain splats
  for (const chunk of chunks.values()) {
    chunk.destroySplatsInRadius(x, y, z, radius);
  }

  // Visual explosion
  const intensity = damage / 5;
  spawnExplosion(x, y, z, radius,
    new THREE.Color(1, 0.6, 0.1),
    new THREE.Color(1, 0.15, 0.0),
    Math.min(30 * intensity, 200)
  );
  spawnExplosion(x, y + 5, z, radius * 0.6,
    new THREE.Color(1, 0.9, 0.7),
    new THREE.Color(0.8, 0.3, 0.05),
    Math.min(15 * intensity, 80)
  );

  // Explosion sound
  playExplosionSound(x, y, z, damage);

  // Screen shake
  shakeAmount += damage * 0.15;

  // Damage flash
  const flash = document.getElementById('damage-flash');
  flash.classList.add('active');
  setTimeout(() => flash.classList.remove('active'), 150);
}
GameServer class · python · L26-L79 (54 LOC)
server.py
class GameServer(SimpleHTTPRequestHandler):
    def do_POST(self):
        if self.path == '/api/fdr':
            try:
                length = int(self.headers.get('Content-Length', 0))
                body = self.rfile.read(length)
                data = json.loads(body)

                # Generate filename from session ID and timestamp
                session_id = data.get('metadata', {}).get('sessionId', 'unknown')
                ts = datetime.now().strftime('%Y%m%d-%H%M%S')
                frames = len(data.get('frames', []))
                filename = f"fdr-{ts}-{session_id[:8]}-{frames}f.json"
                filepath = os.path.join(FDR_DIR, filename)

                with open(filepath, 'w') as f:
                    json.dump(data, f)

                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.send_header('Access-Control-Allow-Origin', '*')
                self.end_headers()
                self.wfile.wri
Citation: Repobility (2026). State of AI-Generated Code. https://repobility.com/research/
do_POST method · python · L27-L59 (33 LOC)
server.py
    def do_POST(self):
        if self.path == '/api/fdr':
            try:
                length = int(self.headers.get('Content-Length', 0))
                body = self.rfile.read(length)
                data = json.loads(body)

                # Generate filename from session ID and timestamp
                session_id = data.get('metadata', {}).get('sessionId', 'unknown')
                ts = datetime.now().strftime('%Y%m%d-%H%M%S')
                frames = len(data.get('frames', []))
                filename = f"fdr-{ts}-{session_id[:8]}-{frames}f.json"
                filepath = os.path.join(FDR_DIR, filename)

                with open(filepath, 'w') as f:
                    json.dump(data, f)

                self.send_response(200)
                self.send_header('Content-Type', 'application/json')
                self.send_header('Access-Control-Allow-Origin', '*')
                self.end_headers()
                self.wfile.write(json.dumps({'ok': True, 'file': filename,
do_OPTIONS method · python · L61-L67 (7 LOC)
server.py
    def do_OPTIONS(self):
        # CORS preflight
        self.send_response(200)
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Allow-Methods', 'POST, OPTIONS')
        self.send_header('Access-Control-Allow-Headers', 'Content-Type')
        self.end_headers()
end_headers method · python · L69-L74 (6 LOC)
server.py
    def end_headers(self):
        # Prevent browser caching so updates are always picked up
        self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate')
        self.send_header('Pragma', 'no-cache')
        self.send_header('Expires', '0')
        super().end_headers()
log_message method · python · L76-L79 (4 LOC)
server.py
    def log_message(self, format, *args):
        # Suppress per-request GET logs, keep FDR logs
        if 'POST' in str(args):
            super().log_message(format, *args)
‹ prevpage 2 / 2