protected void performNotification( long perceiverOid, long perceivedOid, boolean inRadius, boolean wasInRadius) { if (Log.loggingDebug) Log.debug( "ProximityTracker.performNotification: perceiverOid " + perceiverOid + ", perceivedOid " + perceivedOid + ", inRadius " + inRadius + ", wasInRadius " + wasInRadius); if (notifyCallback != null) { notifyCallback.notifyReactionRadius(perceivedOid, perceiverOid, inRadius, wasInRadius); notifyCallback.notifyReactionRadius(perceiverOid, perceivedOid, inRadius, wasInRadius); } else { ObjectTracker.NotifyReactionRadiusMessage nmsg = new ObjectTracker.NotifyReactionRadiusMessage( perceivedOid, perceiverOid, inRadius, wasInRadius); Engine.getAgent().sendBroadcast(nmsg); nmsg = new ObjectTracker.NotifyReactionRadiusMessage( perceiverOid, perceivedOid, inRadius, wasInRadius); Engine.getAgent().sendBroadcast(nmsg); } }
public synchronized <E> Queue<E> createCircularQueue( String name, Serializer<E> serializer, long size) { checkNameNotExists(name); if (serializer == null) serializer = getDefaultSerializer(); // long headerRecid = engine.put(0L, Serializer.LONG); // insert N Nodes empty nodes into a circle long prevRecid = 0; long firstRecid = 0; Serializer<Queues.SimpleQueue.Node> nodeSer = new Queues.SimpleQueue.NodeSerializer(serializer); for (long i = 0; i < size; i++) { Queues.SimpleQueue.Node n = new Queues.SimpleQueue.Node(prevRecid, null); prevRecid = engine.put(n, nodeSer); if (firstRecid == 0) firstRecid = prevRecid; } // update first node to point to last recid engine.update(firstRecid, new Queues.SimpleQueue.Node(prevRecid, null), nodeSer); long headRecid = engine.put(prevRecid, Serializer.LONG); long headInsertRecid = engine.put(prevRecid, Serializer.LONG); Queues.CircularQueue<E> ret = new Queues.CircularQueue<E>( engine, catPut(name + ".serializer", serializer), catPut(name + ".headRecid", headRecid), catPut(name + ".headInsertRecid", headInsertRecid), catPut(name + ".size", size)); catalog.put(name + ".type", "CircularQueue"); collections.put(name, new WeakReference<Object>(ret)); return ret; }
public Obj call(Engine engine, Obj context, Obj... args) throws ClosureTerminatedException { NullImpl thiz = ensureType(NullImpl.class, context); return thiz.getClass() != args[0].getClass() ? engine.getObjTrue() : engine.getObjFalse(); }
public static void main(String[] args) { // Starts the game Engine.start(); // Tutorial.readMap(); // Runs the game Engine.menu(); }
public void handleMessage(Message msg, int flags) { try { lock.lock(); if (activated == false) return; // return true; if (msg.getMsgType() == Behavior.MSG_TYPE_COMMAND) { Behavior.CommandMessage cmdMsg = (Behavior.CommandMessage) msg; String command = cmdMsg.getCmd(); // Remove the executor, because anything we do will // end the current execution. Engine.getExecutor().remove(this); if (Log.loggingDebug) Log.debug( "BaseBehavior.onMessage: command = " + command + "; oid = " + obj.getOid() + "; name " + obj.getName()); if (command.equals(MSG_CMD_TYPE_GOTO)) { GotoCommandMessage gotoMsg = (GotoCommandMessage) msg; Point destination = gotoMsg.getDestination(); mode = MSG_CMD_TYPE_GOTO; roamingBehavior = true; gotoSetup(destination, gotoMsg.getSpeed()); } else if (command.equals(MSG_CMD_TYPE_STOP)) { followTarget = null; pathState.clear(); obj.getWorldNode().setDir(new MVVector(0, 0, 0)); obj.updateWorldNode(); mode = MSG_CMD_TYPE_STOP; // If roamingBehavior is set, that means that we // used formerly had a roaming behavior, so send // an ArrivedEventMessage so that the other // behavior starts up again. if (roamingBehavior) { try { Engine.getAgent().sendBroadcast(new ArrivedEventMessage(obj)); } catch (Exception e) { Log.error( "BaseBehavior.onMessage: Error sending ArrivedEventMessage, error was '" + e.getMessage() + "'"); throw new RuntimeException(e); } } } else if (command.equals(BaseBehavior.MSG_CMD_TYPE_FOLLOW)) { FollowCommandMessage followMsg = (FollowCommandMessage) msg; mode = MSG_CMD_TYPE_FOLLOW; followSetup(followMsg.getTarget(), followMsg.getSpeed()); } } else if (msg.getMsgType() == WorldManagerClient.MSG_TYPE_MOB_PATH_CORRECTION) { Engine.getExecutor().remove(this); interpolatePath(); interpolatingPath = false; } // return true; } finally { lock.unlock(); } }
public void compileScript() { // // find and prepare by extension // log.info("Compiling script..."); Timer engineTimer = new Timer(); engine = EngineHelper.findByFileExtension( scriptExtension, dependencyJarFiles != null && !dependencyJarFiles.isEmpty()); if (engine == null) { throw new BlazeException( "Unable to find script engine for file extension " + scriptExtension + ". Maybe bad file extension or missing dependency?"); } log.debug("Using script engine {}", engine.getClass().getCanonicalName()); if (!engine.isInitialized()) { engine.init(context); } script = engine.compile(context); log.info("Compiled script in {} ms", engineTimer.stop().millis()); }
@Test public void testGetMultiValueConstraints() throws Exception { Engine engine = new Engine(); Field[] fields = engine.getClass().getDeclaredFields(); assertNotNull(fields); assertTrue(fields.length == 1); ReflectionHelper.setAccessibility(fields[0]); Annotation annotation = fields[0].getAnnotation(Pattern.List.class); assertNotNull(annotation); List<Annotation> multiValueConstraintAnnotations = constraintHelper.getMultiValueConstraints(annotation); assertTrue( multiValueConstraintAnnotations.size() == 2, "There should be two constraint annotations"); assertTrue( multiValueConstraintAnnotations.get(0) instanceof Pattern, "Wrong constraint annotation"); assertTrue( multiValueConstraintAnnotations.get(1) instanceof Pattern, "Wrong constraint annotation"); Order order = new Order(); fields = order.getClass().getDeclaredFields(); assertNotNull(fields); assertTrue(fields.length == 1); ReflectionHelper.setAccessibility(fields[0]); annotation = fields[0].getAnnotation(NotNull.class); assertNotNull(annotation); multiValueConstraintAnnotations = constraintHelper.getMultiValueConstraints(annotation); assertTrue( multiValueConstraintAnnotations.size() == 0, "There should be no constraint annotations"); }
@Test public void testEntityProcessorSystem() { TestEntityProcessorSystem system = new TestEntityProcessorSystem(); Engine engine = new Engine(new EngineConfig().addSystem(system)); Mask entities = new Mask(); int a, b, c; entities.set(a = engine.createEntity()); entities.set(b = engine.createEntity()); entities.set(c = engine.createEntity()); engine.update(); assertEquals(system.processedEntities.getMask(), entities); system.processedEntities.edit().clear(); engine.destroyEntity(b); entities.clear(b); engine.update(); assertEquals(system.processedEntities.getMask(), entities); system.processedEntities.edit().clear(); entities.set(b = engine.createEntity()); engine.update(); assertEquals(system.processedEntities.getMask(), entities); system.processedEntities.edit().clear(); engine.destroyEntity(a); engine.destroyEntity(b); engine.destroyEntity(c); entities.clear(a); entities.clear(b); entities.clear(c); }
@Test public void test() { Volume.Factory fab = Volume.memoryFactory(false, 0L, false); Engine e = new StoreDirect(fab); e = new EngineWrapper.ImmutabilityCheckEngine(e); List rec = new ArrayList(); rec.add("aa"); long recid = e.put(rec, Serializer.BASIC); rec.add("bb"); try { e.update(recid, rec, Serializer.BASIC); fail("should throw exception"); } catch (AssertionError ee) { assertTrue(ee.getMessage().startsWith("Record instance was modified")); } try { e.close(); fail("should throw exception"); } catch (AssertionError ee) { assertTrue(ee.getMessage().startsWith("Record instance was modified")); } }
@Test public void testVersioningIndexConflictWithFlush() { ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocument(), Lucene.STANDARD_ANALYZER, B_1, false); Engine.Index index = new Engine.Index(null, newUid("1"), doc); engine.index(index); assertThat(index.version(), equalTo(1l)); index = new Engine.Index(null, newUid("1"), doc); engine.index(index); assertThat(index.version(), equalTo(2l)); engine.flush(new Engine.Flush()); index = new Engine.Index(null, newUid("1"), doc).version(1l); try { engine.index(index); assert false; } catch (VersionConflictEngineException e) { // all is well } // future versions should not work as well index = new Engine.Index(null, newUid("1"), doc).version(3l); try { engine.index(index); assert false; } catch (VersionConflictEngineException e) { // all is well } }
public static void blinkDeathmatchScoreboard( Player client ) { // if during intermission, we must blink our header if we're the winning team (or tie) //if ( inIntermission && ((int)Game.getGameTime()%2 == 0 ) ) // blink every second if ( (int)Game.getGameTime()%2 == 0 ) // blink every second { if ( TEAM1.getCaptures() > TEAM2.getCaptures() ) client.fEntity.setPlayerStat( STAT_CTF_TEAM1_HEADER, (short)0 ); else if ( TEAM2.getCaptures() > TEAM1.getCaptures() ) client.fEntity.setPlayerStat( STAT_CTF_TEAM2_HEADER, (short)0 ); // Capture tie, check total frags else if ( TEAM1.getScore() > TEAM2.getScore() ) client.fEntity.setPlayerStat( STAT_CTF_TEAM1_HEADER, (short)0 ); else if ( TEAM2.getScore() > TEAM1.getScore() ) client.fEntity.setPlayerStat( STAT_CTF_TEAM2_HEADER, (short)0 ); else { // tie game client.fEntity.setPlayerStat( STAT_CTF_TEAM1_HEADER, (short)0 ); client.fEntity.setPlayerStat( STAT_CTF_TEAM2_HEADER, (short)0 ); } } else { // show both if not blinked client.fEntity.setPlayerStat( STAT_CTF_TEAM1_HEADER, (short)Engine.getImageIndex("ctfsb1") ); client.fEntity.setPlayerStat( STAT_CTF_TEAM2_HEADER, (short)Engine.getImageIndex("ctfsb2") ); } }
/** * Cause a general explosion in the world */ public static void explode(GameObject inflictor, GameObject attacker, NativeEntity ent, int damage, float radius) { int effect; Point3f explodeOrigin = ent.getOrigin(); if ((Engine.getPointContents(explodeOrigin) & Engine.MASK_WATER) == 0) { if (ent.getGroundEntity() != null) effect = Engine.TE_GRENADE_EXPLOSION; else effect = Engine.TE_ROCKET_EXPLOSION; } else { if (ent.getGroundEntity() != null) effect = Engine.TE_GRENADE_EXPLOSION_WATER; else effect = Engine.TE_ROCKET_EXPLOSION_WATER; } MiscUtil.radiusDamage(inflictor, attacker, damage, ent, radius, "g_splash"); Engine.writeByte(Engine.SVC_TEMP_ENTITY); Engine.writeByte(effect); Engine.writePosition(explodeOrigin); Engine.multicast(explodeOrigin, Engine.MULTICAST_PHS); }
@Test(timeout = 30000) public void testNoDeadlockIfTransportExceptionOccurs() throws InterruptedException { // NOTE: This test is EXPECTED to print a NoSuchFileException // stacktrace. It can be ignored. String loc = TestData.DATA_DIR + File.separator + Time.now(); final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db"); engine.start(); for (int i = 0; i < 1000; i++) { engine.accept(Write.add("foo", Convert.javaToThrift("bar"), i)); } FileSystem.deleteDirectory(loc); Thread a = new Thread( new Runnable() { @Override public void run() { engine.find("foo", Operator.EQUALS, Convert.javaToThrift("bar")); } }); Thread.sleep(2000); // this is an arbitrary amount. In 2 seconds, at // least one page should have transported... a.start(); a.join(); engine.stop(); Assert.assertTrue(true); // if we reach here, this means that the Engine // was able to break out of the transport // exception System.out.println("[INFO] You can ignore the NoSuchFileException stack trace above"); }
@Test public void testAbstractFactory() { CarFactory carFactory = new LuxuryCarFactory(); Engine engine = carFactory.createEngine(); engine.run(); engine.start(); }
protected void loadGameInfo() throws Exception { Engine engine = Engine.getSharedInstance(); // Singleton! GameInfo gameInfo = new HelloWorldGameInfo(); engine.pushInputController((InputController) gameInfo); gameInfo.onGameStart(); engine.setGameInfo(gameInfo); }
@Test public void testVersioningDeleteConflictWithFlush() { ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocument(), Lucene.STANDARD_ANALYZER, B_1, false); Engine.Index index = new Engine.Index(null, newUid("1"), doc); engine.index(index); assertThat(index.version(), equalTo(1l)); index = new Engine.Index(null, newUid("1"), doc); engine.index(index); assertThat(index.version(), equalTo(2l)); engine.flush(new Engine.Flush()); Engine.Delete delete = new Engine.Delete("test", "1", newUid("1")).version(1l); try { engine.delete(delete); assert false; } catch (VersionConflictEngineException e) { // all is well } // future versions should not work as well delete = new Engine.Delete("test", "1", newUid("1")).version(3l); try { engine.delete(delete); assert false; } catch (VersionConflictEngineException e) { // all is well } engine.flush(new Engine.Flush()); // now actually delete delete = new Engine.Delete("test", "1", newUid("1")).version(2l); engine.delete(delete); assertThat(delete.version(), equalTo(3l)); engine.flush(new Engine.Flush()); // now check if we can index to a delete doc with version index = new Engine.Index(null, newUid("1"), doc).version(2l); try { engine.index(index); assert false; } catch (VersionConflictEngineException e) { // all is well } // we shouldn't be able to create as well Engine.Create create = new Engine.Create(null, newUid("1"), doc).version(2l); try { engine.create(create); } catch (VersionConflictEngineException e) { // all is well } }
public Entity() { x = Math.random() * Engine.getGameWidth(); y = Math.random() * Engine.getGameHeight(); fTheta = Math.random() * Math.PI * 2; pTheta = Math.random() * Math.PI * 2; dFTheta = (Math.random() * 2 - 1) * Math.PI / 50; dPTheta = (Math.random() * 2 - 1) * Math.PI / 50; mass = 100; }
@Test public void testSimpleRecover() throws Exception { ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_1, false); engine.create(new Engine.Create(null, newUid("1"), doc)); engine.flush(new Engine.Flush()); engine.recover( new Engine.RecoveryHandler() { @Override public void phase1(SnapshotIndexCommit snapshot) throws EngineException { try { engine.flush(new Engine.Flush()); assertThat("flush is not allowed in phase 3", false, equalTo(true)); } catch (FlushNotAllowedEngineException e) { // all is well } } @Override public void phase2(Translog.Snapshot snapshot) throws EngineException { MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); try { engine.flush(new Engine.Flush()); assertThat("flush is not allowed in phase 3", false, equalTo(true)); } catch (FlushNotAllowedEngineException e) { // all is well } } @Override public void phase3(Translog.Snapshot snapshot) throws EngineException { MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); try { // we can do this here since we are on the same thread engine.flush(new Engine.Flush()); assertThat("flush is not allowed in phase 3", false, equalTo(true)); } catch (FlushNotAllowedEngineException e) { // all is well } } }); engine.flush(new Engine.Flush()); engine.close(); }
public static void main(String[] args) { // Create an engine... Engine engine = new StandardEngine(1300); // Run diagnostics on the engine... engine.acceptEngineVisitor(new EngineDiagnostics()); // Run inventory on the engine... engine.acceptEngineVisitor(new EngineInventory()); }
@Test public void testEval() throws IOException { Engine engine = new Engine(false); assertTrue(engine.eval("version").contains("ans")); InputStream stream = getClass().getResourceAsStream("version.m"); assertNotNull(stream); assertTrue(engine.eval(stream).contains("ans")); assertEquals(null, engine.eval("version", false)); engine.close(); }
/** * 指定のスロットに対するエピローグ用のレデューサーを生成する。 * * @param moduleId モジュール識別子 * @param slots 対象のスロット一覧 * @return 生成したクラス * @throws IOException 出力に失敗した場合 * @throws IllegalArgumentException 引数に{@code null}が指定された場合 */ public CompiledType emit(String moduleId, List<ResolvedSlot> slots) throws IOException { LOG.debug("\"{}\"エピローグ用のレデューサーを生成します", moduleId); Engine engine = new Engine(environment, moduleId, slots); CompilationUnit source = engine.generate(); environment.emit(source); Name packageName = source.getPackageDeclaration().getName(); SimpleName simpleName = source.getTypeDeclarations().get(0).getName(); Name name = environment.getModelFactory().newQualifiedName(packageName, simpleName); LOG.debug("エピローグ用レデューサーには{}が利用されます", name); return new CompiledType(name); }
@Test public void snapshot() { e = openEngine(); if (!e.canSnapshot()) return; long recid = e.put("a", Serializer.STRING); Engine snapshot = e.snapshot(); e.update(recid, "b", Serializer.STRING); assertEquals("a", snapshot.get(recid, Serializer.STRING)); e.close(); }
@FXML private void handleDeleteAccountAction() { if (getSelectedAccount().isPresent()) { final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT); Objects.requireNonNull(engine); if (!engine.removeAccount(getSelectedAccount().get())) { StaticUIMethods.displayError(resources.getString("Message.Error.AccountRemove")); } } }
/** * The Heads Up Display. This is used for the user to see their current status in the game. This * HUD will display the number of bullets currently, how many lives the player has, the current * level, and how many turns of invincibility the player has. */ public void setHUD() { HUD.removeAll(); JLabel HUDLives = new JLabel("Lives: " + engine.getLife()); JLabel HUDBullets = new JLabel("Bullets: " + engine.getBullets()); JLabel HUDInv = new JLabel("Turns of invincibility: " + engine.getTurns()); JLabel HUDLevel = new JLabel("Level: " + engine.getLevels()); HUD.add(HUDLives, BorderLayout.PAGE_START); HUD.add(HUDBullets, BorderLayout.SOUTH); HUD.add(HUDInv, BorderLayout.CENTER); HUD.add(HUDLevel, BorderLayout.EAST); HUD.revalidate(); }
/** * 指定のモデルに対する値を表すクラスを生成し、生成したクラスの完全限定名を返す。 * * @param model 対象のモデル * @return 生成したクラスの完全限定名 * @throws IOException クラスの生成に失敗した場合 * @throws IllegalArgumentException 引数に{@code null}が指定された場合 */ public Name emit(ShuffleModel model) throws IOException { Precondition.checkMustNotBeNull(model, "model"); // $NON-NLS-1$ LOG.debug("{}に対するシャッフル値を生成します", model.getStageBlock()); Engine engine = new Engine(environment, model); CompilationUnit source = engine.generate(); environment.emit(source); Name packageName = source.getPackageDeclaration().getName(); SimpleName simpleName = source.getTypeDeclarations().get(0).getName(); Name name = environment.getModelFactory().newQualifiedName(packageName, simpleName); LOG.debug("{}のシャッフル値には{}が利用されます", model.getStageBlock(), name); return name; }
@AfterMethod public void tearDown() throws Exception { replicaEngine.close(); storeReplica.close(); engine.close(); store.close(); if (threadPool != null) { threadPool.shutdownNow(); } }
@BeforeMethod public void setUp() throws Exception { threadPool = new ThreadPool(); store = createStore(); store.deleteContent(); storeReplica = createStoreReplica(); storeReplica.deleteContent(); engine = createEngine(store, createTranslog()); engine.start(); replicaEngine = createEngine(storeReplica, createTranslogReplica()); replicaEngine.start(); }
@Test public void testNoBufferTransportBlockingIfWritesAreWithinThreshold() { String loc = TestData.DATA_DIR + File.separator + Time.now(); final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db"); Variables.register("now", Time.now()); engine.start(); engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong()); engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong()); engine.stop(); Assert.assertFalse(engine.bufferTransportThreadHasEverPaused.get()); FileSystem.deleteDirectory(loc); }
@Test public void testVersioningNewIndex() { ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocument(), Lucene.STANDARD_ANALYZER, B_1, false); Engine.Index index = new Engine.Index(null, newUid("1"), doc); engine.index(index); assertThat(index.version(), equalTo(1l)); index = new Engine.Index(null, newUid("1"), doc).version(index.version()).origin(REPLICA); replicaEngine.index(index); assertThat(index.version(), equalTo(1l)); }
@Test public void testVersioningNewCreate() { ParsedDocument doc = testParsedDocument( "1", "1", "test", null, -1, -1, testDocument(), Lucene.STANDARD_ANALYZER, B_1, false); Engine.Create create = new Engine.Create(null, newUid("1"), doc); engine.create(create); assertThat(create.version(), equalTo(1l)); create = new Engine.Create(null, newUid("1"), doc).version(create.version()).origin(REPLICA); replicaEngine.create(create); assertThat(create.version(), equalTo(1l)); }