source-academy / modules

Modules that can be imported by programs in Source Academy, an online experiential environment for computational thinking
Apache License 2.0
8 stars 28 forks source link

Robot Simulator (Part 1) #300

Closed JoelChanZhiYang closed 5 months ago

JoelChanZhiYang commented 5 months ago

Description

The robot simulator has far too much code for reviewers to handle so it is split into 2 sections. This section exclude everything ev3. The section includes the initialization of the simulation, setting up of the physics engine and render engine. It can also render static cuboids.

This looks like a big PR but about half the code is tests. So only about 1000 lines of actual code

Type of change

Creation of the simulation set up

Please delete options that are not relevant.

How Has This Been Tested?

import {
  createCustomPhysics,
  createPhysics,
  createRenderer,
  init_simulation,
  createCuboid,
  createTimer,
  createWorld,
  createWall,
  createFloor,
  addControllerToWorld,
  createRobotConsole,
  saveToContext
} from "robot_simulation";

init_simulation(() => {
    const physics = createPhysics();
    const renderer = createRenderer();
    const timer = createTimer();
    const robot_console = createRobotConsole();

    const world = createWorld(physics, renderer, timer, robot_console);

    const floor = createFloor(physics, renderer);
    addControllerToWorld(floor, world);

    const wall = createWall(physics, renderer);
    addControllerToWorld(wall, world);

    saveToContext("world", world);

    return world;
});

Checklist: