anchor.diff:  %% API
   %% --------------------------------------------------------------------------------------------------------------------
   
  -init(Entity) ->
  -	InitialEntity = entity_physical:init(Entity),
  +init(InitialEntity) ->
  +	Entity = case dict:find(physical, InitialEntity#entity.state) of
  +		{ok, _} ->
  +			entity_physical:init(InitialEntity);
  +		error ->
  +			% The initial entity had no 'physical' key; set up a default with randomized values.
  +			EntWithNoInitialPhysical = entity_physical:init(InitialEntity),
  +			InitialState = EntWithNoInitialPhysical#entity.state,
  +			InitialPhysical = dict:fetch(physical, InitialState),
  +
  +			% Set up default physical state with random position/orientation
  +			DefaultPhysical = pre_physics_rk4:update_from_proplist(
  +				InitialPhysical,
  +				[
  +					{position,
  +						{
  +							random:uniform() * 200 - 100,
  +							random:uniform() * 200 + 600,
  +							random:uniform() * 20
  +						}
  +					},
  +					{orientation,
  +						quaternion:from_axis_angle(
  +							vector:unit({
  +								random:uniform(),
  +								random:uniform(),
  +								random:uniform()
  +							}),
  +							random:uniform() * math:pi()
  +						)
  +					}
  +				]
  +			),
  +
  +			EntWithNoInitialPhysical#entity{
  +				state = dict:store(physical, DefaultPhysical, InitialState)
  +			}
  +	end,
   
   	% -------------------------------------------------------------------------
   
  -	% Set up initial physical state
  -	InitialPhysical = dict:fetch(physical, InitialEntity#entity.state),
  -
  -	% Set up default physical state with random position/orientation
  -	DefaultPhysical = dict:from_list([
  -		{
  -			position, {
  -				random:uniform() * 200 - 100,
  -				random:uniform() * 200 + 600,
  -				random:uniform() * 20
  -			}
  -		},
  -		{
  -			orientation, quaternion:from_axis_angle(
  -				vector:unit({
  -					random:uniform(),
  -					random:uniform(),
  -					random:uniform()
  -				}),
  -				random:uniform() * math:pi()
  -			)
  -		}
  -	]),
  -
  -	% Merge our initial physical state dict with our default values, prefering our initials where there's
  -	% conflicts.
  -	Physical = dict:merge(fun(_Key, InitialVal, _DefaultVal) ->
  -		InitialVal
  -	end, InitialPhysical, DefaultPhysical),
  -
  -	% -------------------------------------------------------------------------
  -
   	% Set up ship state
  -	InitialShip = case dict:find(ship, InitialEntity#entity.state) of
  +	InitialShip = case dict:find(ship, Entity#entity.state) of
   		{ok, Value} ->
   			Value;
   		error ->
  
positive.code: 	% -------------------------------------------------------------------------
  
  	% Set up our initial state
  	InitialState = InitialEntity#entity.state,
  	State1 = dict:store(physical, Physical, InitialState),
  	State2 = dict:store(ship, Ship, State1),
  
  	InitialEntity#entity{
  		state = State2
  	}.
  
  
negative.code: 	},
  
  	% Update physical state
  	NewPhysical = pre_physics_rk4:update_from_proplist(Physical, [
  		{force_relative, Force},
  		{torque_relative, Torque}
  	]),
  
  	% Update entity state
  	Entity#entity{
  		state = dict:store(physical, NewPhysical, Entity#entity.state)
  	}.
  
  
  