Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/application/StarApplication.hpp
blob: f639546f1746d7c5ac3f92292dab15f7cd964d5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once

#include "StarInputEvent.hpp"

namespace Star {

STAR_CLASS(ApplicationController);
STAR_CLASS(Renderer);
STAR_CLASS(Application);

STAR_EXCEPTION(ApplicationException, StarException);

enum class WindowMode {
  Normal,
  Maximized,
  Fullscreen,
  Borderless
};

class Application {
public:
  virtual ~Application() = default;

  // Called once on application startup, before any other methods.
  virtual void startup(StringList const& cmdLineArgs);

  // Called on application initialization, before rendering initialization.  If
  // overriden, must call base class instance.
  virtual void applicationInit(ApplicationControllerPtr appController);

  // Called immediately after application initialization on startup, and then
  // also whenever the renderer invalidated and recreated.  If overridden, must
  // call base class instance.
  virtual void renderInit(RendererPtr renderer);

  // Called when the window mode or size is changed.
  virtual void windowChanged(WindowMode windowMode, Vec2U screenSize);

  // Called before update, once for every pending event.
  virtual void processInput(InputEvent const& event);

  // Will be called at updateRate hz, or as close as possible.
  virtual void update();

  // Will be called at updateRate hz, or more or less depending on settings and
  // performance.  update() is always prioritized over render().
  virtual void render();

  // Will be called *from a different thread* to retrieve audio data (if audio
  // is playing). Default implementation simply fills the buffer with silence.
  virtual void getAudioData(int16_t* sampleData, size_t frameCount);

  // Will be called once on application shutdown, including when shutting down
  // due to an Application exception.
  virtual void shutdown();

  ApplicationControllerPtr const& appController() const;
  RendererPtr const& renderer() const;

private:
  ApplicationControllerPtr m_appController;
  RendererPtr m_renderer;
};

inline ApplicationControllerPtr const& Application::appController() const {
  return m_appController;
}

inline RendererPtr const& Application::renderer() const {
  return m_renderer;
}

}