Skip to content

Commit

Permalink
ASM implemented with timeline queue -
Browse files Browse the repository at this point in the history
  • Loading branch information
synaptek committed Apr 26, 2017
1 parent 43fa5fb commit d0a7876
Show file tree
Hide file tree
Showing 28 changed files with 1,181 additions and 494 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.minimap.enabled": true
}
405 changes: 215 additions & 190 deletions app/src/main/assets/tutors/add_subtract/animator_graph.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"xprize_effect": {"type": "SOUNDMAP", "language": "LANG_EFFECT", "path": "cmu/xprize/global"},
"default": {"type": "SOUNDMAP", "language": "LANG_AUTO", "path": "cmu/xprize/arithmetic"},
"xprize": {"type": "SOUNDMAP", "language": "LANG_AUTO", "path": "cmu/xprize/global"},
"shapes": {"type": "SOUNDMAP", "language": "LANG_AUTO", "path": "cmu/xprize/arithmetic"},
"chimes": {"type": "SOUNDMAP", "language": "LANG_EFFECT", "path": "chimes"}
},

Expand Down
35 changes: 19 additions & 16 deletions app/src/main/java/cmu/xprize/robotutor/tutorengine/CSceneGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class CSceneGraph {
private boolean mDisabled = false;

// State fields
private scene_graph _graph;
private scene_graph _sceneGraph;
private HashMap<String, Integer> _pFeatures;
private ArrayList<scene_graph> _dataStack = new ArrayList<>();

Expand Down Expand Up @@ -89,6 +89,9 @@ public CSceneGraph(CTutor tutor, TScope tutorScope, ITutorGraph tutorGraph) {
*/
public void onDestroy() {

if(_sceneGraph != null) {
_sceneGraph.onDestroy();
}
}


Expand All @@ -97,8 +100,8 @@ public void onDestroy() {
*/
public void pushGraph() {

if(_graph != null) {
_dataStack.add(_graph);
if(_sceneGraph != null) {
_dataStack.add(_sceneGraph);
}
}

Expand All @@ -112,7 +115,7 @@ public boolean popGraph() {
int popIndex = _dataStack.size()-1;

if(popIndex >= 0) {
_graph = _dataStack.get(popIndex);
_sceneGraph = _dataStack.get(popIndex);
_dataStack.remove(popIndex);

popped = true;
Expand Down Expand Up @@ -169,9 +172,9 @@ public void run() {
mGraphName = _target;

try {
_graph = (scene_graph) mScope.mapSymbol(mGraphName);
_sceneGraph = (scene_graph) mScope.mapSymbol(mGraphName);

Log.d(TAG, "Processing Enter Scene: " + _graph.name + " - mapType: " + _graph.type );
Log.d(TAG, "Processing Enter Scene: " + _sceneGraph.name + " - mapType: " + _sceneGraph.type );

} catch (Exception e) {

Expand All @@ -188,7 +191,7 @@ public void run() {
//
if(_dataStack.size() > 0) {

_graph.cancelNode();
_sceneGraph.cancelNode();
popGraph();
}

Expand All @@ -199,14 +202,14 @@ public void run() {
pushGraph();

try {
_graph = (scene_graph) mScope.mapSymbol(mGraphName);
_graph.resetNode();
_sceneGraph = (scene_graph) mScope.mapSymbol(mGraphName);
_sceneGraph.resetNode();

Log.d(TAG, "Processing call graph: " + _graph.name + " - mapType: " + _graph.type );
Log.d(TAG, "Processing call graph: " + _sceneGraph.name + " - mapType: " + _sceneGraph.type );

// Seek the graph to the root node and execute it
//
if(_graph != null) {
if(_sceneGraph != null) {
post(this, TCONST.NEXT_NODE);
}

Expand All @@ -232,7 +235,7 @@ public void run() {

case TCONST.NEXT_NODE:

String sceneState = _graph.applyNode();
String sceneState = _sceneGraph.applyNode();

switch (sceneState) {

Expand Down Expand Up @@ -263,7 +266,7 @@ public void run() {

case TCONST.CANCEL_NODE:

switch (_graph.cancelNode()) {
switch (_sceneGraph.cancelNode()) {

// TCONST.NEXTSCENE is used to end the current scene and step through to the
// next scene in the TutorGraph.
Expand All @@ -284,12 +287,12 @@ public void run() {


case TCONST.PLAY:
_graph.play();
_sceneGraph.play();
break;


case TCONST.STOP:
_graph.stop();
_sceneGraph.stop();
break;


Expand All @@ -303,7 +306,7 @@ public void run() {
break;

case TCONST.GOTO_NODE:
_graph.gotoNode(_target);
_sceneGraph.gotoNode(_target);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void onDestroy() {
if(scene.children != null) {
Iterator<?> tObjects = scene.children.entrySet().iterator();

// Perform component levelFolder cleanup first
// Perform component level Folder cleanup first
//
while(tObjects.hasNext() ) {
Map.Entry entry = (Map.Entry) tObjects.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import android.util.Log;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import cmu.xprize.robotutor.tutorengine.ILoadableObject2;
import cmu.xprize.comp_logging.CErrorManager;
Expand Down Expand Up @@ -52,7 +54,7 @@ public class scene_graph extends scene_node implements ILoadableObject2 {
public HashMap subgraphMap;
public HashMap queueMap;

static private final String TAG = "tutor_node";
static private final String TAG = "scene_graph";


/**
Expand All @@ -63,6 +65,26 @@ public scene_graph() {
}


/**
* When scene is complete we need to ensure all the moduleQueues are shutdown so delayed
* actions do not occur after destruction.
*/
public void onDestroy() {

// Walk the scene_graphqueues to teminate them gracefully
//
Iterator<?> tObjects = queueMap.entrySet().iterator();

while(tObjects.hasNext() ) {
Map.Entry entry = (Map.Entry) tObjects.next();

scene_graphqueue sceneQueue = (scene_graphqueue)entry.getValue();

sceneQueue.cancelNode();
}
}


/**
* Increments the scenegraph polymorphically
* potentially called recursively if currNode is a subgraph.
Expand Down Expand Up @@ -122,6 +144,10 @@ public String applyNode() {
//
Log.d(TAG, "Processing Node: " + _currNode.name + " - start State: " + _nodeState + " - mapType: " + _currNode.maptype + " - mapName: " + _currNode.mapname);

// if(_currNode.name.equals("INTRO_STATE")) {
// Log.d(TAG, "Processing Node: " + _currNode.name);
// }

_nodeState = _currNode.applyNode();

Log.d(TAG, "Processing Node: " + _currNode.name + " - end State: " + _nodeState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ public String cancelNode() {

// If queue is in progress cancel operations.
//
Log.d(TAG, "Processing Terminate on: " + name );
terminateQueue();

// If there is an active node e.g. audioqueue - kill it off
//
if(_nextAction != null) {

terminateQueue();
_nextAction.cancelNode();
_nextAction = null;
}

return TCONST.NONE;
Expand All @@ -59,9 +64,9 @@ public String cancelNode() {
@Override
public String applyNode() {

post(TCONST.APPLY_NODE);
_qDisabled = false;

_moduleState = TCONST.READY;
post(TCONST.APPLY_NODE);

return _moduleState;
}
Expand Down Expand Up @@ -130,9 +135,12 @@ public void run() {

terminateQueue();
_nextAction.cancelNode();
}

_qDisabled = false;
// Restart queue
//
_qDisabled = false;
_nextAction = null;
}

// If the node is completed and reusable then reset
//
Expand Down Expand Up @@ -189,7 +197,10 @@ public void run() {
}
}
else {
// RESET the nextAction so it will restart
//
preExit();
_nextAction = null;
}
}
catch(Exception e) {
Expand Down Expand Up @@ -221,6 +232,7 @@ private void terminateQueue() {
// disable the input queue permenantly in prep for destruction
//
_qDisabled = true;

flushQueue();
}

Expand All @@ -234,8 +246,11 @@ public void flushQueue() {
Iterator<?> tObjects = queueMap.entrySet().iterator();

while(tObjects.hasNext() ) {

Map.Entry entry = (Map.Entry) tObjects.next();

Log.d(TAG, "Removing Post: " + entry.getKey());

mainHandler.removeCallbacks((scene_graphqueue.Queue)(entry.getValue()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public void onDestroy() {
//
super.onDestroy();
mTutorScene.onDestroy();

// Allow the ask component to relesase drawable resources.
//
SaskActivity.onDestroy();
}

@Override
Expand Down
Loading

0 comments on commit d0a7876

Please sign in to comment.