/src/main/scala/it/unibo/ScafiAlchemistSupport.scala

https://bitbucket.org/metaphori/experiment-spawn · Scala · 42 lines · 21 code · 4 blank · 17 comment · 2 complexity · 9e4498e6cbcd7b85e53713aa04650c23 MD5 · raw file

  1. package it.unibo
  2. import it.unibo.alchemist.model.scafi.ScafiIncarnationForAlchemist._
  3. import it.unibo.alchemist.implementation.nodes.NodeManager
  4. import it.unibo.alchemist.model.interfaces.Time
  5. import it.unibo.scafi.PlatformDependentConstants
  6. import it.unibo.alchemist.model.interfaces.Environment
  7. /*
  8. * Copyright (C) 2016-2017, Roberto Casadei, Mirko Viroli, and contributors.
  9. * See the LICENCE.txt file distributed with this work for additional
  10. * information regarding copyright ownership.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. trait ScafiAlchemistSupport { self: AggregateProgram with StandardSensors =>
  25. def env = sense[NodeManager]("manager")
  26. def currTime: Double = sense[Time]("time").toDouble()
  27. def dt(whenNan: Double = Double.NaN): Double = {
  28. val dt = sense[Time]("dt").toDouble()
  29. if(dt.isNaN) whenNan else dt
  30. }
  31. def nextRandom: Double = sense[()=>java.lang.Double]("random")().toDouble
  32. def environment = sense[Environment[Any]]("env")
  33. import sun.reflect.Reflection.getCallerClass
  34. override def aggregate[T](f: => T): T =
  35. vm.nest(FunCall[T](vm.index, getCallerClass(PlatformDependentConstants.StackTracePosition).getName()))(true) {
  36. f
  37. }
  38. }