Пример #1
0
  static void showScript(String fname) {
    try {
      ESParser parser = new ESParser(fname);
      Script script = parser.parse();

      PrintWriter pw = new PrintWriter(System.out, true);
      pw.println("------------------ script AST:");
      script.dump(pw);

      pw.println("------------------ generated CG sequence:");

      StringSetGenerator p = new StringSetGenerator();
      script.process(p);

      LinkedHashMap<String, ArrayList<CG>> sections = p.getSections();
      for (Map.Entry<String, ArrayList<CG>> e : sections.entrySet()) {
        ArrayList<CG> queue = e.getValue();
        System.out.println(e.getKey() + " {");
        for (CG cg : queue) {
          System.out.print("  ");
          System.out.println(cg);
        }
        System.out.println("}");
        System.out.println();
      }

      /**
       * this only shows the last section List<CG> queue = p.getCGQueue(); for (CG cg : queue) {
       * System.out.println(cg); }
       */
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
Пример #2
0
 @Override
 protected void process(int entityId) {
   ScriptComponent sc = mScript.get(entityId);
   // add pending scripts
   for (Script script : sc.add) {
     world.inject(script, false);
     script.world = world;
     script.inserted(entityId);
     sc.scripts.add(script);
   }
   // removed pending scripts
   sc.add.clear();
   for (Script script : sc.remove) {
     if (sc.scripts.removeValue(script, true)) {
       script.removed(entityId);
     }
   }
   sc.remove.clear();
   // process active scripts
   Iterator<Script> it = sc.scripts.iterator();
   while (it.hasNext()) {
     Script next = it.next();
     next.process(entityId);
     if (next.remove) {
       it.remove();
       next.removed(entityId);
     }
   }
 }
  public static void runScript(Script script, int scriptType) {
    if (scriptType == SHUTDOWN_SCRIPT) {
      try {
        script.process();
      } catch (Exception e) {
        System.out.println(e.getMessage());
      }
    } else {
      // Create a new Thread
      ScriptThread scriptThread = new ScriptThread(script, scriptType);

      // Run the Thread
      scriptThread.start();
    }
  }