Skip to content

Commit

Permalink
Many interface grabbing bug fixes
Browse files Browse the repository at this point in the history
* Fixed grabbing something with the other hand that's already being moved around.
* Fixed action state listeners getting multiply registered.
* Made the state transitions more formal in grabber and gadget state
* Fixed various cases where grabbers would stop functioning.
* FIxed various cases where grabbables would disappear (or return to the origin) when grabbed.
  • Loading branch information
JoeLudwig committed May 23, 2020
1 parent 658ad81 commit 8fde6fb
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 135 deletions.
72 changes: 39 additions & 33 deletions packages/aardvark-react/src/aardvark_gadget_seed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ enum GadgetSeedPhase
Idle,
GrabberNearby,
WaitingForGadgetStart,
WaitingForGadgetInContainer,
WaitingForRegrab,
WaitingForRedropToFinish,
}
Expand All @@ -58,10 +57,12 @@ export class GadgetSeedContainerComponent implements EntityComponent
private entityCallback: () => void = null;
private activeContainer: ActiveInterface = null;
private childAddedCallback: () => void;
private childRemovedCallback: () => void;

constructor(childAddedCallback: () => void)
constructor( childAddedCallback: () => void, childRemovedCallback: () => void )
{
this.childAddedCallback = childAddedCallback;
this.childRemovedCallback = childRemovedCallback;
}

private updateListener()
Expand Down Expand Up @@ -89,6 +90,7 @@ export class GadgetSeedContainerComponent implements EntityComponent
this.contentsEpa = null;
this.activeContainer = null;
this.updateListener();
this.childRemovedCallback?.();
} );

this.activeContainer = activeContainer;
Expand Down Expand Up @@ -165,7 +167,7 @@ export class GadgetSeedContainerComponent implements EntityComponent
export class AvGadgetSeed extends React.Component< AvGadgetSeedProps, AvGadgetSeedState >
{
private moveableComponent = new MoveableComponent( this.onMoveableUpdate );
private containerComponent = new GadgetSeedContainerComponent( this.triggerRegrab );
private containerComponent = new GadgetSeedContainerComponent( this.onNewChild, this.onLostChild );
private refContainer = React.createRef<AvComposedEntity>();
private refSeed = React.createRef<AvComposedEntity>();

Expand Down Expand Up @@ -221,28 +223,42 @@ export class AvGadgetSeed extends React.Component< AvGadgetSeedProps, AvGadgetSe
// Our next internal state change will be driven by the gadget starting
break;

case GadgetSeedPhase.WaitingForRegrab:
switch( this.moveableComponent.state )
{
case MoveableComponentState.InContainer:
case MoveableComponentState.Idle:
case MoveableComponentState.GrabberNearby:
// we've been dropped
this.setState( { phase: GadgetSeedPhase.Idle } );
this.moveableComponent.reset();
break;

case MoveableComponentState.Grabbed:
// still waiting;
break;
}
}
}

@bind
private onNewChild()
{
console.log( "onNewChild" );
switch ( this.moveableComponent.state )
{
case MoveableComponentState.Grabbed:
console.log( `regrabbing new gadget moveable ${ endpointAddrToString( this.containerComponent.child ) }` );
this.triggerRegrab();
break;
case MoveableComponentState.GrabberNearby:
case MoveableComponentState.InContainer:
console.log( `redropping new gadget moveable ${ endpointAddrToString( this.containerComponent.child ) }` );
this.containerComponent.redrop( this.moveableComponent.parent, this.refSeed.current.globalId );
this.setState( { phase: GadgetSeedPhase.WaitingForRedropToFinish } );
break;
case MoveableComponentState.Idle:
console.log( "How did we get all the way back to idle?" );
break;
}
}

@bind
private onLostChild()
{
console.log( "lost child in container" );
switch( this.state.phase )
{
case GadgetSeedPhase.WaitingForRedropToFinish:
if( this.moveableComponent.state == MoveableComponentState.Idle )
{
this.setState( { phase: GadgetSeedPhase.Idle } );
}
case GadgetSeedPhase.WaitingForRegrab:
// we've been dropped
this.setState( { phase: GadgetSeedPhase.Idle } );
this.moveableComponent.reset();
break;
}
}
Expand All @@ -259,21 +275,11 @@ export class AvGadgetSeed extends React.Component< AvGadgetSeedProps, AvGadgetSe

if( !res.success )
{
this.setState( { phase: GadgetSeedPhase.Idle } );
throw new Error( "startGadget failed" );
}

// we should have a gadget in our container by now? Maybe?
if( this.containerComponent.child )
{
this.triggerRegrab();
}
else
{
this.setState( { phase: GadgetSeedPhase.WaitingForGadgetInContainer } );
}
}

@bind
private triggerRegrab()
{
this.moveableComponent.triggerRegrab( this.containerComponent.child, k_seedFromGadget );
Expand Down
40 changes: 26 additions & 14 deletions packages/aardvark-react/src/component_moveable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum GrabRequestType
DropYourself = "drop_yourself",
DropComplete = "drop_complete",
SetGrabber = "set_grabber",
ReleaseMe = "release_me",
RequestRegrab = "request_regrab",
}

Expand All @@ -49,9 +50,9 @@ export class MoveableComponent implements EntityComponent
private entityCallback: () => void = null;
private ownerCallback: () => void = null;

private activeGrab: ActiveInterface = null;
private activeGrabs = new Set<ActiveInterface>();
private activeContainer: ActiveInterface = null;
private grabber: EndpointAddr = null;
private grabber: ActiveInterface = null;
private wasEverDropped: boolean = false;
private droppedIntoInitialParent: boolean = false;
private initialInterface:InitialInterfaceLock = null;
Expand Down Expand Up @@ -82,7 +83,7 @@ export class MoveableComponent implements EntityComponent
{
return MoveableComponentState.Grabbed;
}
else if( this.activeGrab )
else if( this.activeGrabs.size > 0 )
{
return MoveableComponentState.GrabberNearby;
}
Expand All @@ -101,7 +102,7 @@ export class MoveableComponent implements EntityComponent
{
activeGrab.onEnded(() =>
{
this.activeGrab = null;
this.activeGrabs.delete( activeGrab );
this.updateListener();
} );

Expand All @@ -111,22 +112,32 @@ export class MoveableComponent implements EntityComponent
switch( event.type )
{
case GrabRequestType.SetGrabber:
this.grabber = this.activeGrab.peer;

this.activeContainer?.sendEvent( { state: "Moving" } );
this.activeContainer?.unlock();

this.updateListener();
if( this.grabber == activeGrab )
{
console.log( `SetGrabber from ${endpointAddrToString( activeGrab.peer ) }, which was already our grabber` );
}
else
{
let release: GrabRequest = { type: GrabRequestType.ReleaseMe };
this.grabber?.sendEvent( release );

this.grabber = activeGrab;

this.activeContainer?.sendEvent( { state: "Moving" } );
this.activeContainer?.unlock();

this.updateListener();
}
break;

case GrabRequestType.DropYourself:
await this.dropIntoContainer( true );
this.activeGrab.sendEvent( { type: GrabRequestType.DropComplete } as GrabRequest );
activeGrab.sendEvent( { type: GrabRequestType.DropComplete } as GrabRequest );
break;
}
} );

this.activeGrab = activeGrab;
this.activeGrabs.add( activeGrab );
this.updateListener();
}

Expand All @@ -152,7 +163,7 @@ export class MoveableComponent implements EntityComponent
newMoveable: replacementMoveable,
oldMoveableFromNewMoveable,
}
this.activeGrab?.sendEvent( e );
this.grabber?.sendEvent( e );
}

@bind
Expand Down Expand Up @@ -221,7 +232,7 @@ export class MoveableComponent implements EntityComponent
if( this.grabber )
{
// if we're currently grabbed, that's our parent
return this.grabber;
return this.grabber.peer;
}
else if( this.wasEverDropped )
{
Expand Down Expand Up @@ -257,6 +268,7 @@ export class MoveableComponent implements EntityComponent
public reset()
{
this.activeContainer?.unlock();
this.activeContainer?.sendEvent( { state: "Moving" } );
this.wasEverDropped = false;
this.grabber = null;
this.updateListener();
Expand Down
5 changes: 5 additions & 0 deletions packages/aardvark-react/src/math_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export function nodeTransformFromMat4( m: mat4 ) : AvNodeTransform

export function nodeTransformToMat4( transform: AvNodeTransform ): mat4
{
if( !transform )
{
return mat4.identity;
}

let vTrans: vec3;
if ( transform.position )
{
Expand Down
4 changes: 2 additions & 2 deletions websrc/default_hands/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
],
"aardvark":
{
"browserWidth": 16,
"browserHeight": 16,
"browserWidth": 512,
"browserHeight": 512,
"permissions" : [ "scenegraph" ]
}
}
7 changes: 6 additions & 1 deletion websrc/default_hands/src/default_hands.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
body, html
{
background-color: transparent;
background-color: #FFFFFFAA;
width: 100%;
height: 100%;
overflow: hidden;
}

div
{
font-size: large;
}

.FullPage
{
width: 100%;
Expand Down
Loading

0 comments on commit 8fde6fb

Please sign in to comment.