|
91 | 91 | \noindent Additionally, these have been already set up in the \verb|Main| class, so the simulation can be run by simply running |
92 | 92 | the \verb|main()| method under it. Since the parameters of the simulation is read from the JSON file, it is necessary |
93 | 93 | to have the \verb|simulation_data.json| file in the root directory of the project (the place where the \verb|Main.java| |
94 | | - file can be found). |
| 94 | + file can be found), but this is already provided in the Jar file in the submission. Finally, the simulation uses an |
| 95 | + external package called \href{https://github.com/google/gson/}{Gson} to read the |
| 96 | + JSON file, and which is why the package is bundled in the Jar file in the submission. |
95 | 97 |
|
96 | 98 | \section{Tasks Lists and Implementation Details} |
97 | 99 |
|
|
218 | 220 |
|
219 | 221 | \noindent \textbf{Quadtree Optimisation: } While not a visible feature, due to its complexity, it is worth discussing. |
220 | 222 | A quadtree is utilised to store entities, instead of a list. This is done to efficiently handle entity proximity checks. Each frame, |
221 | | - entities are added to the quadtree, and when they need to find nearby entities they query the tree. This is is a major upgrade |
| 223 | + entities are added to the quadtree, and when they need to find nearby entities, they query the tree. This is is a major upgrade |
222 | 224 | to the naïve approach of $O(n^2)$ time-complexity, where every entity checks its distance to every other entity (1000 entities means |
223 | 225 | 1,000,000 calls, 60 times a second). Using the quadtree for every entity has an average complexity of $O(n \log n)$, since the |
224 | 226 | quadtree organises entities by proximity. Overall, this greatly improves performance, making the experience of the simulation |
|
232 | 234 | \section{Code Quality Considerations} |
233 | 235 |
|
234 | 236 | \subsection{Coupling and Responsibility-Driven Design} |
235 | | - \noindent Coupling is minimized by separating all major functions into different classes. The class structure of the |
| 237 | + \noindent Coupling is minimised by separating all major functions into different classes. The class structure of the |
236 | 238 | program starts with the \verb|Engine| class. The \verb|Engine| controls the main loop of the simulation, combining the actual |
237 | 239 | simulation and the graphics together. |
238 | 240 |
|
|
241 | 243 | internal logic, meaning it has minimal coupling. |
242 | 244 |
|
243 | 245 | \noindent Graphics are handled by the \verb|Display| and the \verb|RenderPanel| classes. The \verb|RenderPanel| class |
244 | | - extends the \verb|JPanel| class and is responsible for rendering the simulation, and since it has low coupling it is |
| 246 | + extends the \verb|JPanel| class and is responsible for rendering the simulation, and since it has low coupling, it is |
245 | 247 | easy to change the \verb|RenderPanel| class to render the simulation on different mediums — a web browser, for example. |
246 | 248 | Furthermore, the simulation is controlled by the |
247 | 249 | \verb|Simulator| class. All entities are stored in a \verb|Field| class, which is created by a \verb|FieldBuilder| class to |
|
277 | 279 | for the \verb|Environment| class are also created, the \verb|WeatherController| and the \verb|TimeController|. |
278 | 280 | This massively increases cohesion as the different operations |
279 | 281 | are split into different relevant sections, making the code much easier to understand. This also has the added benefit of making |
280 | | - the \verb|Animal| and \verb|Environment| classes quite small, and improves responsibility driven design. |
| 282 | + the \verb|Animal| and \verb|Environment| classes quite small, and improves responsibility driven design and code readability. |
281 | 283 |
|
282 | 284 | \noindent The structure of \verb|Entity| and its subclasses also lends itself to high cohesion — its extremely clear what an |
283 | | - \verb|Animal| should do, and what a \verb|Predator| and \verb|Prey| does differently while also inhreintly being subclasses of |
| 285 | + \verb|Animal| should do, and what a \verb|Predator| and \verb|Prey| does differently while also inherintly being subclasses of |
284 | 286 | \verb|Animal|. This once again decreases code duplication and increases the cohesion of the code base. |
285 | 287 |
|
286 | 288 | \noindent |
|
0 commit comments