// a separate path with waits, just in case I forget to remove sleep() for the next lab. public void waitUpdateOptionValue( String modelName, String optionName, String oldOptVal, String newOptVal) { System.out.println( "Demonstrating Thread named " + Thread.currentThread().getName() + " and Setting " + oldOptVal + " to " + newOptVal); int setIndex; _autoModel = _autoModelGroup.get(modelName); if (_autoModel != null) { setIndex = _autoModel.findOptionSetIndex(optionName); if (setIndex != -1) { if (_autoModel.updateOptionName2(setIndex, oldOptVal, newOptVal)) { System.out.println(newOptVal + " set and updateOptionName2 exited."); } else { System.out.println(newOptVal + " NOT set but updateOptionName2 exited."); } } } System.out.println(Thread.currentThread().getName() + " done."); }
private void countdown() { t = new Thread() { public void run() { long time = System.currentTimeMillis(); long timeNow = System.currentTimeMillis(); while ((time + 1000) > timeNow) { timeNow = System.currentTimeMillis(); counterN = (int) (1000 - (timeNow - time)) / 100; } countdownF = false; startTime = System.currentTimeMillis(); } }; if (countdownF) { t.start(); } else { t = null; } }
private void animate() { r = new Thread() { public void run() { while (true) { if (!countdownF) { countdown(); if (!onePlayerAlive) { if (highscore < score) { highscore = score; highscoreL.setText(String.valueOf(highscore)); } if (musicCB.isSelected()) { mp3.stop(); } break; } timeElapse = 1 + System.currentTimeMillis() - startTime; programLoopCounter++; if (programLoopCounter % 100 == 0) { float loopPerSec = (float) programLoopCounter / timeElapse; programSpeedAdjust = (0.3f) / loopPerSec; } if ((timeElapse > timeCircle) && (ballN < 20)) { timeCircle = timeElapse + timeDifficulty1; ballN++; distance++; spawnIncrease = true; } score = (int) timeElapse * multiplier; if (timeElapse > timeLast) { level++; levelSetup(); } if (timeElapse > timeCircleSwitch) { timeCircleSwitch = timeElapse + 10000; deleteIf( new EnemyPredicate() { public boolean satisfiedBy(Enemy e) { return e.getClass().equals(EnemyTypes.Circle.class); } }); if (iter++ % 2 == 0) { spawnMonsters(); } ballN = 1; distance = defaultDistance; circular = !circular; } deleteIf( new EnemyPredicate() { public boolean satisfiedBy(Enemy e) { return e.getClass().equals(EnemyTypes.Shrapnel.class) && (((EnemyTypes.Shrapnel) e).getBounces() > 1); } }); deleteIf( new EnemyPredicate() { public boolean satisfiedBy(Enemy e) { return e.getClass().equals(EnemyTypes.Bomb.class) && (((EnemyTypes.Bomb) e).isMortal()); } }); movePlayers(); } try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { repaint(); } }); } catch (Exception e) { } } back.setVisible(true); setCursor(Cursor.getDefaultCursor()); } }; r.start(); }
/** Update or add a sprite to the client side game. */ public void addPacket(HacktendoPacket Packet) { while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff. try { Thread.sleep(5); } catch (Exception e) { e.printStackTrace(); } } do { Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID())); boolean setRenderType = false; if (S == null) { S = new Sprite(this); setRenderType = true; S.setParameter("destroy", new TypeBoolean(false)); S.setParameter("globalID", new TypeInteger(Packet.getID())); S.setParameter("id", new TypeInteger(Packet.getID())); Sprites.put(new Integer(Packet.getID()), S); S.setOffscreenProcessing(false); } S.setScriptID(Packet.getScriptID()); S.setImageID(Packet.getImage()); if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side. S.setX(Packet.getX()); S.setY(Packet.getY()); S.setZ(Packet.getZ()); S.setParameter("xTarget", new TypeInteger(Packet.getTargetX())); S.setParameter("yTarget", new TypeInteger(Packet.getTargetY())); S.setParameter("newTarget", new TypeBoolean(true)); } if (Packet.getExplodeSprite()) S.explode(); if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true)); S.setFrame(Packet.getFrame()); S.setXRotation(Packet.getXRotation()); S.setYRotation(Packet.getYRotation()); S.setZRotation(Packet.getZRotation()); S.setWidth(Packet.getWidth()); S.setHeight(Packet.getHeight()); S.setDepth(Packet.getDepth()); S.setZOffset(Packet.getZOffset() * -1); if (setRenderType) S.setRenderType(Packet.getRenderType()); } while (Packet.next() > 0); // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID} if (Packet.getReferenceArray() != null) { for (int i = 0; i < Packet.getReferenceArray().size(); i++) { Object O[] = (Object[]) Packet.getReferenceArray().get(i); Sprite S = (Sprite) Sprites.get((Integer) O[0]); System.out.println("ID: " + O[0]); if (S != null) { String ip = (String) O[1]; String name = (String) O[2]; boolean npc = (Boolean) O[3]; S.setParameter("ip", new TypeString(ip)); S.setParameter("name", new TypeString(name)); S.setParameter("npc", new TypeBoolean(npc)); if (S.getScriptID() == SPRITE_SCRIPT) { S.setOffscreenProcessing(true); S.setAutoCollide(true); Sprite S2 = (Sprite) Sprites.get((Integer) O[4]); S.setParameter("body", new TypeInteger(S2.getSpriteID())); } if (ip.equals(MyHacker.getIP())) { if (S.getScriptID() == SPRITE_SCRIPT) { playerSprite = S; } playerID = S.getSpriteID(); System.out.println( "We are setting the player to equal : " + S.getSpriteID() + " This Is Sprite ID: " + O[0]); HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID())); } } } } }
/** * Return the expected commit success/failure for the current thread. * * @returns true if the current thread should succeed in its commit, false otherwise. */ public static boolean getCommitStatus() { Object key = TxBB.CommitStatusKey + Thread.currentThread().getName(); Object result = TxBB.getBB().getSharedMap().get(key); if (result instanceof Boolean) return ((Boolean) result).booleanValue(); else throw new TestException("Unknown value " + result + " for TxBB sharedMap key " + key); }
/** * Write to the blackboard the expected commit success/failure for the current thread. * * @param expectCommitStatus True if we expect the current thread to successfully commit, false * otherwise. */ public static void recordCommitStatus(boolean expectCommitStatus) { Object key = TxBB.CommitStatusKey + Thread.currentThread().getName(); TxBB.getBB().getSharedMap().put(key, new Boolean(expectCommitStatus)); Log.getLogWriter().info("Written to TxBB: " + key + ", " + expectCommitStatus); }
/** * Convenience method for obtaining the key created for the opList serial tests may put this key * on the BB for other threads to use for opList access */ public static String getOpListKey() { return OpListKey + Thread.currentThread().getName(); }
/** Convenience method for reading the list of operations for the current client thread. */ public static OpList getOpList() { Object key = OpListKey + Thread.currentThread().getName(); OpList opList = (OpList) (TxBB.getBB().getSharedMap().get(key)); Log.getLogWriter().info("TxBB read from shared map key " + key + ", value " + opList); return opList; }
/** Convenience method for writing a list of operations for the current client thread. */ public static void putOpList(OpList opList) { Object key = OpListKey + Thread.currentThread().getName(); TxBB.getBB().getSharedMap().put(key, opList); Log.getLogWriter().info("TxBB put into shared map key " + key + ", value " + opList); }