22 #if defined(_DEBUG) && defined(_WINDOWS)
23 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
36 Game * Game::create() {
45 m_popup_menu_state_factory(new Popup_Menu_State_Factory),
46 m_popup_pause_state_factory(new Popup_Pause_State_Factory)
47 #
if !defined(ANDROID) && !defined(NDEBUG)
48 , m_console_active(
false)
54 delete m_popup_menu_state_factory;
55 delete m_popup_pause_state_factory;
62 #if !defined(ANDROID) && !defined(NDEBUG)
64 return static_cast<Console_State &
>(get_console_instance().get());
68 #if !defined(ANDROID) && !defined(NDEBUG)
69 void Game::write_to_console(
const String &text) {
72 void Game::write_to_console(
const String & ) {
78 m_states.top().on_cover();
82 #if !defined(ANDROID) && !defined(NDEBUG)
84 get_console().set_child(m_states.top());
87 m_states.top().on_push();
100 #if !defined(ANDROID) && !defined(NDEBUG)
101 if(m_console_active) {
104 if(!m_states.empty())
105 csr.set_child(m_states.top());
114 if(!m_states.empty())
115 m_states.top().on_uncover();
183 #if !defined(ANDROID) && !defined(NDEBUG)
191 #if !defined(ANDROID) && !defined(NDEBUG)
192 if(m_console_active) {
193 gs = get_console_instance();
194 console_child = get_console().get_child();
210 void Game::perform_logic() {
212 #if !defined(ANDROID) && !defined(NDEBUG)
220 #if !defined(ANDROID) && !defined(NDEBUG)
221 if(m_console_active) {
222 gs = get_console_instance();
223 console_child = get_console().get_child();
235 void Game::prerender() {
237 #if !defined(ANDROID) && !defined(NDEBUG)
245 #if !defined(ANDROID) && !defined(NDEBUG)
246 if(m_console_active) {
247 gs = get_console_instance();
248 console_child = get_console().get_child();
262 #if !defined(ANDROID) && !defined(NDEBUG)
270 #if !defined(ANDROID) && !defined(NDEBUG)
271 if(m_console_active) {
272 gs = get_console_instance();
273 console_child = get_console().get_child();
287 bool Game::get_key_state(
const int &button)
const {
289 if(it != m_keys.end())
294 bool Game::get_mouse_button_state(
const int &button)
const {
296 if(it != m_mouse_buttons.end())
304 if(jt != m_controller_axes.end()) {
306 if(it != jt->second.end())
316 if(jt != m_controller_buttons.end()) {
318 if(it != jt->second.end())
326 #ifdef TEST_NASTY_CONDITIONS
336 const Time time_passed;
338 time_processed = time_passed;
341 if(controller_mouse.enabled && (controller_mouse.velocity.x != 0 || controller_mouse.velocity.y != 0)) {
342 Point2f adjusted_vel(controller_mouse.velocity.x + 0.5f, controller_mouse.velocity.y + 0.5f);
343 if(adjusted_vel.
x < 0.0f)
344 adjusted_vel.
x =
std::min(0.0
f, adjusted_vel.
x + controller_mouse.noise_zone.x);
346 adjusted_vel.
x =
std::max(0.0
f, adjusted_vel.
x - controller_mouse.noise_zone.x);
347 if(adjusted_vel.
y < 0.0f)
348 adjusted_vel.
y =
std::min(0.0
f, adjusted_vel.
y + controller_mouse.noise_zone.y);
350 adjusted_vel.
y =
std::max(0.0
f, adjusted_vel.
y - controller_mouse.noise_zone.y);
351 adjusted_vel.
x /= 32767.5f - controller_mouse.noise_zone.x;
352 adjusted_vel.
y /= 32767.5f - controller_mouse.noise_zone.y;
354 int xrel =
int(adjusted_vel.
x * controller_mouse.pixels_per_second.x * time_step);
355 int yrel =
int(adjusted_vel.
y * controller_mouse.pixels_per_second.y * time_step);
372 #if SDL_VERSION_ATLEAST(2,0,0)
391 #if SDL_VERSION_ATLEAST(1,3,0)
394 get_key_state(SDLK_LMETA) || get_key_state(SDLK_RMETA) || get_key_state(SDLK_LSUPER) || get_key_state(SDLK_RSUPER);
401 deactivate_console();
414 (!alt && !ctrl && gui && !shift && s.
sym ==
SDLK_q) ||
416 (!alt && ctrl && !gui && !shift && s.
sym ==
SDLK_q) ||
417 ( alt && !ctrl && !gui && !shift && s.
sym ==
SDLK_F4)))
431 if(controller_mouse.enabled &&
get_Controllers().get_controller_index(event.caxis.which) == 0 && (controller_mouse.controller_axes.x == event.caxis.axis || controller_mouse.controller_axes.y == event.caxis.axis)) {
432 if(controller_mouse.controller_axes.x == event.caxis.axis)
433 controller_mouse.velocity.x =
event.caxis.value;
435 controller_mouse.velocity.y =
event.caxis.value;
441 if(controller_mouse.enabled &&
get_Controllers().get_controller_index(event.cbutton.which) == 0 && controller_mouse.left_click == event.cbutton.button) {
457 else if(controller_mouse.enabled &&
get_Controllers().get_controller_index(event.cbutton.which) == 0 && controller_mouse.escape == event.jbutton.button) {
470 else if(controller_mouse.enabled && event.cbutton.which == 0 && (controller_mouse.scroll_down == event.jbutton.button || controller_mouse.scroll_up == event.jbutton.button)) {
478 e.
wheel.
y = controller_mouse.scroll_down ==
event.cbutton.button ? -1 : 1;
494 #ifdef TEST_NASTY_CONDITIONS
496 const Time current_time;
498 size_t step_count = 0
u;
499 while(time_used + (1 / 60.0
f) < time_passed) {
500 time_used += (1 / 60.0f);
503 time_used = time_passed;
515 if(Window::is_enabled()) {
547 void Game::push_Popup_Menu_State() {
548 push_state((*m_popup_menu_state_factory)());
551 void Game::push_Popup_Pause_State() {
552 push_state((*m_popup_pause_state_factory)());
556 assert(popup_menu_state_factory);
557 delete m_popup_menu_state_factory;
558 m_popup_menu_state_factory = popup_menu_state_factory;
562 assert(popup_pause_state_factory);
563 delete m_popup_pause_state_factory;
564 m_popup_pause_state_factory = popup_pause_state_factory;
567 void Game::calculate_fps() {
570 if(tp < ticks_passed)
572 ticks_passed = tp + 1000;
577 #if !defined(ANDROID) && !defined(NDEBUG)
578 void Game::activate_console() {
579 if(!m_states.empty())
580 get_console().set_child(m_states.top());
582 get_console().m_prompt.seek(get_console().m_prompt.get_max_seek());
584 m_console_active =
true;
587 void Game::deactivate_console() {
588 m_console_active =
false;
589 get_console().clear_child();
592 Gamestate & Game::get_console_instance() {
593 static Gamestate console_state(Gamestate(
new Console_State()));
594 return console_state;
598 bool Game::is_console_active()
const {
599 #if !defined(ANDROID) && !defined(NDEBUG)
600 return m_console_active;
float frand_lte()
Get a random floating point number in the range [0.0f, 1.0f].
Controllers & get_Controllers()
Get access to the singleton.
static const int & get_width()
Get the size of the window.
void on_event(const SDL_Event &event)
SDL_ControllerAxisEvent caxis
int32_t Sint32
A signed 32-bit integer type.
The Video Rendering Singleton.
SDL_ControllerDeviceEvent cdevice
Sound_Source_Pool & get_Sound_Source_Pool()
Get access to the singleton.
Sint32 rand_lt(const Sint32 &mod)
Get a random integer in the range [0, mod)
void detect_removed()
Fix to broken SDL device removal detection.
DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event)
Polls for currently pending events.
return Display return Display Bool Bool int int e
static void render(const Vertex_Buffer_Macrorenderer ¯orenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
The SDL keysym structure, used in key events.
void device_added(const Sint32 &index)
Register a new device.
#define NASTY_ZERO_STEP_FREQUENCY
SDL_MouseWheelEvent wheel
Game & get_Game()
Get access to the singleton.
virtual bool begin_prerender()=0
Must be called before begin_render.
static long get_time(void)
A Random Number Generator.
DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y)
Retrieve the current state of the mouse.
void update()
Redistribute hardware Sound_Sources according to the Replacement_Policy. Newer Sound_Sources are impl...
Sound & get_Sound()
Get access to the singleton.
Timer & get_Timer()
Get access to the singleton.
Sint32 get_controller_index(const Sint32 &id) const
Get the index of a given controller from the true SDL_JoystickInstanceID.
A smartpointer for a Gamestate_Base.
DECLSPEC Uint32 SDLCALL SDL_GetWindowID(SDL_Window *window)
Get the numeric ID of a window, for logging purposes.
local int destroy(gz_stream *s)
Gamestate_Zero_Initializer * g_gzi
A class to signal that the program is quitting.
const char *const * g_argv
Window & get_Window()
Get access to the singleton.
EGLSurface EGLint EGLint y
virtual bool begin_render()=0
Must be called before all rendering functions; Returns true if rendering can proceed.
DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window *window, int x, int y)
Moves the mouse to the given position within the window.
float get_seconds_since(const Time &time) const
Get the number of seconds passed between 'time' and this Time.
SDL_ControllerButtonEvent cbutton
static const int & get_height()
Get the height of the window.
int16_t Sint16
A signed 16-bit integer type.
#define NASTY_RATE_CUTOFF
SDL_MouseButtonEvent button
void write_to_log(const String &text)
virtual void end_render()=0
Must be called after all rendering functions.
uint16_t Uint16
An unsigned 16-bit integer type.
Provide a text console to process commands.
Video & get_Video()
Get access to the singleton.
A 2D Point represented with floats.
DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void)
Get the current key modifier state for the keyboard.
void update()
Update background music, as needed.