Skip to content

Instantly share code, notes, and snippets.

@twof
Created November 25, 2023 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twof/45007af80d18fd4545daf338f7108d92 to your computer and use it in GitHub Desktop.
Save twof/45007af80d18fd4545daf338f7108d92 to your computer and use it in GitHub Desktop.

Everything that happens in tick_ship

  • Check if there is a crash message
    • If there is
      • Show debug text on screen
      • Play ship explosion animation
  • The gas usage count is reset
  • Previously the WASM instance had a portion of it's memory sectioned off to store ship state
  • // TODO: I'm not super clear on what select_submemory does, but I assume that means we're operating on the ship's state from here on out
  • generate_system_state is called. state is passed to the function and updated by the function.
  • Write state to the ship's system state slice of memory
  • tick_ship is called. I think it might be in shared/ai/src/tick.rs
  • If there's a runtime error
    • Check the gas count, if it has run out, then throw an error
    • Read the ship's panic buffer from memory
      • If it's empty, also throw the out-of-gas error
      • If not, throw an error with the message from the panic buffer
    • If we haven't returned by this point, throw the runtime error directly
  • Calculate the gas usage and display it as debug text
  • Read read a SystemState into state, getting the values update by running the user's ship tick
  • apply_system_state
  • Have the sim emit debug text and lines

Everything that happens in generate_system_state

When I say "set", what's really happening is that that data is being passed from the simulator to the user's ship.

  • Set ship class
  • Set ship's position
  • Set ship's velocity
  • Set ship's heading
  • Set ship's angular velocity
  • If the ship has a radar
    • Set ship's radar heading, width, min distance, and max distance
    • If there is a scan result
      • Set all the relevant data
    • Otherwise set that there is no scan result
  • Otherwise if there is a static target
    • Set all the relevant data into the same memory as if it was a radar result
  • Set static ship stats like max acceleration, health, and fuel
  • Go through each radio channel
    • If received data on that channel
      • Set the message received
    • Otherwise set no message received on that channel
    • Clear the sent message
  • Set the current tick
  • Set the remaining reload ticks for each gun (I think?)

Everything that happens in apply_system_state

  • Run the acceleration calculation and apply it to the sim
  • Reset acceleration to 0
  • Run the torque calculation and apply it to the sim
  • Reset torque to 0
  • If any weapons are firing, get their heading and the firing state and apply it to the sim
  • Reset all weapons' firing states
  • If the ship has a radar, set its heading and the rest of its settings in the sim
  • Apply abilities abilities that have been activated to the sim
  • Explode if the command has been set
  • Set the sent message if there is one on each radio channel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment