88#include  " types.hpp" 
99#include  " window.hpp" 
1010
11+ /* *
12+  * @brief Abstract base for an application. Inherit from this struct to create an application and customize the 
13+  * behavior. Do not create multiple instances of this struct. 
14+  */  
1115struct  Application  : public  EventListener  {
1216private: 
1317    SdlContext context;
@@ -21,6 +25,14 @@ struct Application : public EventListener {
2125    EventDispatcher m_event_dispatcher;
2226
2327protected: 
28+     /* *
29+      * @brief Creates a new application. 
30+      * @param title The text in the window title bar. 
31+      * @param position The position where the window should spawn at. 
32+      * @param width The width of the window. 
33+      * @param height The height of the window. 
34+      * @param command_line_arguments The command line arguments. 
35+      */  
2436    Application (
2537            const  std::string& title,
2638            WindowPosition position,
@@ -33,30 +45,68 @@ struct Application : public EventListener {
3345    Application (const  Application&) = delete ;
3446    Application& operator =(const  Application&) = delete ;
3547
48+     /* *
49+      * @brief Starts the main game loop. 
50+      */  
3651    void  run ();
3752
53+     /* *
54+      * @brief Obtains the renderer for this application's window. 
55+      * @return The renderer. 
56+      */  
3857    [[nodiscard]] const  Renderer& renderer () const  {
3958        return  m_renderer;
4059    }
4160
61+     /* *
62+      * @brief Obtains the window for this application. 
63+      * @return The window. 
64+      */  
4265    [[nodiscard]] const  Window& window () const  {
4366        return  m_window;
4467    }
4568
69+     /* *
70+      * @brief Returns the elapsed time (in seconds) since the SDL2 library has been initialized. 
71+      * @return The elapsed time in seconds. 
72+      */  
4673    static  double  elapsed_time () {
4774        return  static_cast <double >(SDL_GetTicks ()) / 1000.0 ;
4875    }
4976
77+     /* *
78+      * @brief Returns the index of the current simulation step. The application tries to execute a certain number 
79+      * of simulation steps per second. This is specified in the command line arguments (passed to the constructor). 
80+      * @return The index of the current simulation step. 
81+      */  
5082    static  u64  simulation_step_index () {
5183        return  s_num_steps_simulated;
5284    }
5385
86+     /* *
87+      * @brief Implements the EventListener. If the escape key is pressed or the windows is closed, the application 
88+      * gets closed. 
89+      * @param event The SDL event to handle. 
90+      */  
5491    void  handle_event (const  SDL_Event& event) override ;
5592
5693protected: 
94+     /* *
95+      * @brief This function gets called from within the main game loop (i.e. by the run() function). Override this 
96+      * function to specify what should be done in every simulation step. 
97+      */  
5798    virtual  void  update () = 0;
99+ 
100+     /* *
101+      * @brief Clears the contents of the window with a black color. Override this function to render additional 
102+      * window contents. 
103+      */  
58104    virtual  void  render () const ;
59105
106+     /* *
107+      * @brief Returns the CommandLineArguments instance passed to this struct's constructor. 
108+      * @return The command line arguments. 
109+      */  
60110    [[nodiscard]] const  CommandLineArguments& command_line_arguments () const  {
61111        return  m_command_line_arguments;
62112    }
0 commit comments