• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Scala-Robotics-Simulator / PPS-22-srs / #108

27 Jul 2025 10:45AM UTC coverage: 74.412% (-2.0%) from 76.435%
#108

Pull #16

github

web-flow
Merge branch 'main' into feature/mvc
Pull Request #16: feat: mvc with generic state and simulation loop

0 of 31 new or added lines in 6 files covered. (0.0%)

9 existing lines in 5 files now uncovered.

253 of 340 relevant lines covered (74.41%)

10.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/scala/io/github/srs/controller/ControllerModule.scala
1
package io.github.srs.controller
2

3
import io.github.srs.model.ModelModule
4

5
/**
6
 * Module that defines the controller logic for the Scala Robotics Simulator.
7
 */
8
object ControllerModule:
9

×
10
  /**
11
   * Controller trait that defines the interface for the controller.
12
   *
13
   * @tparam S
14
   *   the type of the state, which must extend [[ModelModule.State]].
15
   */
16
  trait Controller[S <: ModelModule.State]:
NEW
17
    /**
×
18
     * Starts the controller with the initial state.
19
     *
20
     * @param initialState
21
     *   the initial state of the simulation.
22
     */
23
    def start(initialState: S): Unit
24

25
    /**
26
     * Runs the simulation loop, updating the state and rendering the view.
27
     * @param s
28
     *   the current state of the simulation.
29
     */
30
    def simulationLoop(s: S): Unit
31

32
  /**
33
   * Provider trait that defines the interface for providing a controller.
34
   * @tparam S
35
   *   the type of the state, which must extend [[ModelModule.State]].
36
   */
37
  trait Provider[S <: ModelModule.State]:
38
    val controller: Controller[S]
39

40
  /**
41
   * Defines the dependencies required by the controller module. In particular, it requires a
42
   * [[io.github.srs.view.ViewModule.Provider]] and a [[io.github.srs.model.ModelModule.Provider]].
43
   */
44
  type Requirements[S <: ModelModule.State] =
45
    io.github.srs.view.ViewModule.Provider[S] & io.github.srs.model.ModelModule.Provider[S]
46

47
  /**
48
   * Component trait that defines the interface for creating a controller.
49
   * @tparam S
50
   *   the type of the simulation state, which must extend [[ModelModule.State]].
51
   */
52
  trait Component[S <: ModelModule.State]:
NEW
53
    context: Requirements[S] =>
×
54

55
    object Controller:
NEW
56
      /**
×
57
       * Creates a controller instance.
58
       *
59
       * @return
60
       *   a [[Controller]] instance.
61
       */
62
      def apply(): Controller[S] = new ControllerImpl
UNCOV
63

×
64
      /**
65
       * Private controller implementation that delegates the simulation loop to the provided model and view.
66
       */
67
      private class ControllerImpl extends Controller[S]:
UNCOV
68

×
69
        /**
70
         * @inheritdoc
71
         */
72
        override def start(initialState: S): Unit =
73
          context.view.init()
×
NEW
74
          simulationLoop(initialState)
×
NEW
75

×
76
        /**
77
         * @inheritdoc
78
         */
79
        @annotation.tailrec
NEW
80
        override final def simulationLoop(s: S): Unit =
×
NEW
81
          val state = for
×
NEW
82
            newState <- context.model.update(s)
×
NEW
83
            _ <- Some(context.view.render(newState))
×
84
          yield newState
NEW
85

×
86
          state match
NEW
87
            case Some(ns) => simulationLoop(ns)
×
NEW
88
            case None => ()
×
NEW
89
      end ControllerImpl
×
90
    end Controller
91

92
  end Component
93

94
  /**
95
   * Interface trait that combines the provider and component traits for the controller module.
96
   *
97
   * @tparam S
98
   *   the type of the simulation state, which must extend [[ModelModule.State]].
99
   */
100
  trait Interface[S <: ModelModule.State] extends Provider[S] with Component[S]:
101
    self: Requirements[S] =>
102
end ControllerModule
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc