private async Task RunBasicTest(string path, Version version, bool inProcess, TargetPlatform target) { var engine = EngineProvider.Get(version, path, null, inProcess, target, true); await engine.Initialize(null, _ct); await engine.Execute(_basicTestScript, _ct); var pyObj = await engine.LoadScript(_basicTestScript, _ct); const string param = "dummy"; var resHello = await engine.InvokeMethod(pyObj, "hello", new object[] { param }, _ct); Assert.Equal("Hello " + param, engine.Convert(resHello, typeof(string))); var resFib = await engine.InvokeMethod(pyObj, "fib", new object[] { 10 }, _ct); Assert.Equal(55, engine.Convert(resFib, typeof(int))); var resArray = await engine.InvokeMethod(pyObj, "arr", new object[] { 10, 10 }, _ct); Assert.Equal(10, ((int[])engine.Convert(resArray, typeof(int[]))).Length); var resNoParam = await engine.InvokeMethod(pyObj, "no_param", null, _ct); Assert.Equal("no_param", engine.Convert(resNoParam, typeof(string))); await engine.Release(); }
private async Task RunTypesTest(string path, Version version, bool inProcess, TargetPlatform target) { // init engine var engine = EngineProvider.Get(version, path, null, inProcess, target, true); await engine.Initialize(null, _ct); // load test script var pyScript = await engine.LoadScript(_typeTestScript, _ct); foreach (var typeInfo in _types) { var element = typeInfo.Value; object array = Array.CreateInstance(typeInfo.Key, 10); // invoke with simple type var resObj = await engine.InvokeMethod(pyScript, "dummy", new[] { element }, _ct); var simpleType = engine.Convert(resObj, typeInfo.Key); Assert.True(typeInfo.Key == simpleType.GetType()); // invoke with array type resObj = await engine.InvokeMethod(pyScript, "dummy", new[] { array }, _ct); var arrayType = engine.Convert(resObj, array.GetType()); Assert.True(array.GetType() == arrayType.GetType()); } await engine.Release(); }
public static void Update(ref BulletPhysicsComponent bpc) { foreach (var entry in _flippers) { PhyFlipper phyFlipper = entry.Value; phyFlipper._FlipperUpdate(ref bpc); // debug var dbg = EngineProvider <IDebugUI> .Get(); bool isChanged = false; float sa = phyFlipper._startAngle * 180.0f / Mathf.PI; float se = phyFlipper._endAngle * 180.0f / Mathf.PI; isChanged |= dbg.GetProperty(phyFlipper.dbgPropStartAngle, ref sa); isChanged |= dbg.GetProperty(phyFlipper.dbgPropEndAngle, ref se); if (isChanged) { phyFlipper._startAngle = sa * Mathf.PI / 180.0f; phyFlipper._endAngle = se * Mathf.PI / 180.0f; HingeConstraint hinge = (HingeConstraint)phyFlipper._constraint; if (phyFlipper.RotationDirection == 1) { hinge.SetLimit(phyFlipper._startAngle, phyFlipper._endAngle, 0.0f); } else { hinge.SetLimit(phyFlipper._endAngle, phyFlipper._startAngle, 0.0f); } } } }
protected virtual void Start() { if (EngineProvider <IDebugUI> .Exists) { EngineProvider <IDebugUI> .Get().Init(this); } }
protected void UpdatePhysics(float deltaTime) { _RemoveVPXPhysicSystems(); currentTime += (double)deltaTime; var td = currentTime - simulationTime; double stepTime = 1.0 / (double)stepsPerSecond; int steps = (int)(td * stepsPerSecond); if (steps > 0) { while (steps > 0) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int executedSteps = World.StepSimulation((float)stepTime, 1, (float)stepTime); _UpdateGameObjects(); simulationTime += stepTime * executedSteps; _physicsFrame += executedSteps; --steps; if (EngineProvider <IDebugUI> .Exists) { EngineProvider <IDebugUI> .Get().OnPhysicsUpdate(simulationTime, 1, (float)stopwatch.Elapsed.TotalMilliseconds); } } } PhyGate.dbg(entityManager); }
public BallApi CreateBall(Player player, IBallCreationPosition ballCreator, float radius, float mass) { // calculate mass and scale var m = player.TableToWorld; var localPos = ballCreator.GetBallCreationPosition(_table).ToUnityFloat3(); var localVel = ballCreator.GetBallCreationVelocity(_table).ToUnityFloat3(); localPos.z += radius; //float4x4 model = player.TableToWorld * Matrix4x4.TRS(localPos, Quaternion.identity, new float3(radius)); var worldPos = m.MultiplyPoint(localPos); var scale3 = new Vector3( m.GetColumn(0).magnitude, m.GetColumn(1).magnitude, m.GetColumn(2).magnitude ); var scale = (scale3.x + scale3.y + scale3.z) / 3.0f; // scale is only scale (without radiusfloat now, not vector. var material = BallMaterial.CreateMaterial(); var mesh = GetSphereMesh(); // create ball entity EngineProvider<IPhysicsEngine>.Get() .BallCreate(mesh, material, worldPos, localPos, localVel, scale, mass, radius); return null; }
public void ShouldFailIfNoneSet() { Action act = () => EngineProvider <ITestEngine> .Get(); act.Should().Throw <InvalidOperationException>() .WithMessage("Must select VisualPinball.Engine.Test.Common.ITestEngine engine before retrieving!"); }
public void ManualBallRoller() { float3 p; if (_debugUI.VPE.GetClickCoords(out p)) { EngineProvider <IPhysicsEngine> .Get().BallManualRoll(_lastCreatedBallEntityForManualBallRoller, p); } }
public void AutomaticVersionDetection(string path, Version version) { Skip.IfNot(ValidateRuntime(path)); var target = X64Engines.Any(x => x[0].Equals(path) && x[1].Equals(version)) ? TargetPlatform.x64 : TargetPlatform.x86; var engine = EngineProvider.Get(Version.Auto, path, null, true, target, true); Assert.Equal(engine.Version, version); }
static public void SliderFloat(string label, DebugFlipperSliderParam param, float min, float max) { var engine = EngineProvider <IPhysicsEngine> .Get(); float val = engine.GetFlipperDebugValue(param); if (ImGui.SliderFloat(label, ref val, min, max)) { engine.SetFlipperDebugValue(param, val); } }
protected void Awake() { EngineProvider <IPhysicsEngine> .Set(physicsEngineId); EngineProvider <IPhysicsEngine> .Get().Init(this); if (!string.IsNullOrEmpty(debugUiId)) { EngineProvider <IDebugUI> .Set(debugUiId); } }
public void Initialize(string path, Version version, string workingFolder) { try { _engine = EngineProvider.Get(version, path); _engine.Initialize(workingFolder, _ct).Wait(); } catch (Exception ex) { ExceptionDispatchInfo.Capture(ex.InnerException ?? ex).Throw(); } }
void _AddDebugProperties() { var dbg = EngineProvider <IDebugUI> .Get(); if (dbgFlippersRoot == -1) { dbgFlippersRoot = dbg.AddProperty(-1, "Flippers Props", this); } dbgThisFlipper = dbg.AddProperty(dbgFlippersRoot, base.name, this); dbgPropStartAngle = dbg.AddProperty(dbgThisFlipper, "Start Angle", _startAngle * 180.0f / Mathf.PI); dbgPropEndAngle = dbg.AddProperty(dbgThisFlipper, "End Angle", _endAngle * 180.0f / Mathf.PI); }
private async Task RunUnicodeTests(string path, Version version, bool inProcess, TargetPlatform target) { // init engine var engine = EngineProvider.Get(version, path, null, inProcess, target, true); await engine.Initialize(null, _ct); // load test script var pyScript = await engine.LoadScript(_unicodeTestScript, _ct); var resNoParam = await engine.InvokeMethod(pyScript, "test", null, _ct); Assert.Equal("´©Ãˆ§‰©ù¨ëéüÇïçâèàêÉîôû", engine.Convert(resNoParam, typeof(string))); await engine.Release(); }
public void RegisterFlipper(Flipper flipper, Entity entity, GameObject go) { var flipperApi = new FlipperApi(flipper, entity, this); _tableApi.Flippers[flipper.Name] = flipperApi; _initializables.Add(flipperApi); _hittables[entity] = flipperApi; _rotatables[entity] = flipperApi; _collidables[entity] = flipperApi; if (EngineProvider <IDebugUI> .Exists) { EngineProvider <IDebugUI> .Get().OnRegisterFlipper(entity, flipper.Name); } }
private void AddGetToDebugWindow() { var dbg = EngineProvider<IDebugUI>.Get(); if (dbg != null) { if (dbgGate == -1) dbgGate = dbg.AddProperty(-1, "Gates", this); int me = dbg.AddProperty(dbgGate, base.name, this); dbgSa = dbg.AddProperty(me, "start angle", _startAngle.ToDeg()); dbgEa = dbg.AddProperty(me, "end angle", _endAngle.ToDeg()); dbgDamping = dbg.AddProperty(me, "damping", body.AngularDamping); dbgHa = dbg.AddProperty(me, "angle", 0.0f); } }
public void ShouldProvideIfSet() { EngineProvider <ITestEngine> .Set("VisualPinball.Engine.Test.Common.TestEngine1"); var engine = EngineProvider <ITestEngine> .Get(); engine.Should().NotBeNull(); engine.Name.Should().Be("Engine 1"); EngineProvider <ITestEngine> .Set("VisualPinball.Engine.Test.Common.TestEngine2"); engine = EngineProvider <ITestEngine> .Get(); engine.Should().NotBeNull(); engine.Name.Should().Be("Engine 2"); }
protected override void OnUpdate() { _simulationTime.Restart(); var sim = World.GetExistingSystem <VisualPinballSimulationSystemGroup>(); _staticCounts = PhysicsConstants.StaticCnts; var dTime = sim.PhysicsDiffTime; var numSteps = 0; while (dTime > 0) { HitTime = (float)dTime; ApplyFlipperTime(); ClearContacts(); _dynamicBroadPhaseSystem.Update(); _staticBroadPhaseSystem.Update(); _staticNarrowPhaseSystem.Update(); _dynamicNarrowPhaseSystem.Update(); ApplyStaticTime(); _displacementSystemGroup.Update(); _dynamicCollisionSystem.Update(); _staticCollisionSystem.Update(); _contactSystem.Update(); ClearContacts(); _ballSpinHackSystem.Update(); dTime -= HitTime; SwapBallCollisionHandling = !SwapBallCollisionHandling; ++numSteps; } // debug ui update if (EngineProvider <IDebugUI> .Exists) { PhysicsEngine.UpdateDebugFlipperStates(); PhysicsEngine.PushPendingCreateBallNotifications(); EngineProvider <IDebugUI> .Get().OnPhysicsUpdate(sim.CurrentPhysicsTime, numSteps, (float)_simulationTime.Elapsed.TotalMilliseconds); } }
protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken) { string path = Path.Get(context); if (!path.IsNullOrEmpty() && !Directory.Exists(path)) { throw new DirectoryNotFoundException(string.Format(Resources.InvalidPathException, path)); } cancellationToken.ThrowIfCancellationRequested(); _pythonEngine = EngineProvider.Get(Version, path, !Isolated, TargetPlatform, ShowConsole); var workingFolder = WorkingFolder.Get(context); if (!workingFolder.IsNullOrEmpty()) { var dir = new DirectoryInfo(workingFolder); if (!dir.Exists) { throw new DirectoryNotFoundException(Resources.WorkingFolderPathInvalid); } workingFolder = dir.FullName; //we need to pass an absolute path to the python host } try { await _pythonEngine.Initialize(workingFolder, cancellationToken); } catch (Exception e) { Trace.TraceError($"Error initializing Python engine: {e.ToString()}"); Cleanup(); throw new InvalidOperationException(Resources.PythonInitializeException, e); } cancellationToken.ThrowIfCancellationRequested(); return(ctx => { ctx.ScheduleAction(Body, _pythonEngine, OnCompleted, OnFaulted); }); }
public static void dbg(EntityManager entityManager) { var dbg = EngineProvider<IDebugUI>.Get(); if (dbg == null) return; foreach (var gate in _gates) { bool isLimitChanged = false; float sa = 0, ea = 0, damping = 0; isLimitChanged |= dbg.GetProperty(gate.dbgSa, ref sa); isLimitChanged |= dbg.GetProperty(gate.dbgEa, ref ea); if (isLimitChanged) gate._constraint.SetLimit(sa.ToRad(), ea.ToRad(), 0); if (dbg.GetProperty(gate.dbgDamping, ref damping)) gate.body.SetDamping(damping, damping); float ha = gate._constraint.HingeAngle.ToDeg(); dbg.SetProperty(gate.dbgHa, ha); // we don't read it... only display } }
private void Awake() { var tableComponent = gameObject.GetComponent <TableAuthoring>(); var engineComponent = GetComponent <IGameEngineAuthoring>(); Table = tableComponent.CreateTable(tableComponent.Data); BallManager = new BallManager(Table, TableToWorld); _inputManager = new InputManager(); if (engineComponent != null) { GameEngine = engineComponent.GameEngine; } EngineProvider <IPhysicsEngine> .Set(physicsEngineId); EngineProvider <IPhysicsEngine> .Get().Init(tableComponent, BallManager); if (!string.IsNullOrEmpty(debugUiId)) { EngineProvider <IDebugUI> .Set(debugUiId); } }
/// <summary> /// Disables the flipper's solenoid, making the flipper rotate back to /// its resting position. /// </summary> public void RotateToStart() { EngineProvider <IPhysicsEngine> .Get().FlipperRotateToStart(Entity); }
protected override async Task <Action <NativeActivityContext> > ExecuteAsync(NativeActivityContext context, CancellationToken cancellationToken) { string path = Path.Get(context); string libraryPath = LibraryPath.Get(context); if (!path.IsNullOrEmpty() && !Directory.Exists(path)) { throw new DirectoryNotFoundException(string.Format(Resources.InvalidPathException, path)); } cancellationToken.ThrowIfCancellationRequested(); _pythonEngine = EngineProvider.Get(Version, path, libraryPath, !Isolated, TargetPlatform, ShowConsole); var workingFolder = WorkingFolder.Get(context); if (!workingFolder.IsNullOrEmpty()) { var dir = new DirectoryInfo(workingFolder); if (!dir.Exists) { throw new DirectoryNotFoundException(Resources.WorkingFolderPathInvalid); } workingFolder = dir.FullName; //we need to pass an absolute path to the python host } var operationTimeout = OperationTimeout.Get(context); if (operationTimeout == 0) { operationTimeout = 3600; //default to 1h for no values provided. } try { await _pythonEngine.Initialize(workingFolder, cancellationToken, operationTimeout); } catch (Exception e) { Trace.TraceError($"Error initializing Python engine: {e.ToString()}"); try { Cleanup(); } catch (Exception) { } if (Version != Version.Auto) { Version autodetected = Version.Auto; EngineProvider.Autodetect(path, out autodetected); if (autodetected != Version.Auto && autodetected != Version) { throw new InvalidOperationException(string.Format(Resources.InvalidVersionException, Version.ToFriendlyString(), autodetected.ToFriendlyString())); } } throw new InvalidOperationException(Resources.PythonInitializeException, e); } cancellationToken.ThrowIfCancellationRequested(); return(ctx => { ctx.ScheduleAction(Body, _pythonEngine, OnCompleted, OnFaulted); }); }