Skip to content
Permalink
Browse files

better approach for game init (#1852)

  • Loading branch information...
time-killer-games authored and JoshDreamland committed Aug 16, 2019
1 parent a058416 commit 2bcceb42e319c79fe76c76a70b521e5626fbf9e4
@@ -23,14 +23,6 @@ int frames_count = 0;
unsigned long current_time_mcs = 0;
bool game_window_focused = true;

void initGame() {
enigma_user::window_set_sizeable(isSizeable);
enigma_user::window_set_showborder(showBorder);
enigma_user::window_set_fullscreen(isFullScreen);
enigma_user::window_set_size(windowWidth, windowHeight);
enigma_user::window_center();
}

int gameWait() {
if (enigma_user::os_is_paused()) {
if (pausedSteps < 1) {
@@ -74,12 +66,7 @@ int enigma_main(int argc, char** argv) {
// Call ENIGMA system initializers; sprites, audio, and what have you
initialize_everything();

unsigned step = 0;
while (!game_isending) {
if (step < 15) {
initGame();
step++;
}

if (!((std::string)enigma_user::room_caption).empty())
enigma_user::window_set_caption(enigma_user::room_caption);
@@ -287,8 +287,16 @@ void window_default(bool center_size) {
}

void window_center() {
window_set_position(display_get_width() / 2 - window_get_width() / 2,
display_get_height() / 2 - window_get_height() / 2);
int i = 0;
// without this while loop, the window won't be guaranteed to center
// at game init, in xlib, which is weird, but this makes it necessary.
while ((enigma::windowX != display_get_width() / 2 - window_get_width() / 2 ||
enigma::windowY != display_get_height() / 2 - window_get_height() / 2)) {
window_set_position(display_get_width() / 2 - window_get_width() / 2,
display_get_height() / 2 - window_get_height() / 2);
if (i >= 15) break;
i++;
}
}

void window_set_freezeonlosefocus(bool freeze) { enigma::freezeOnLoseFocus = freeze; }
@@ -133,6 +133,15 @@ namespace enigma
enigma_user::window_set_visible(true);
}

// resize and center window
enigma_user::window_set_size(windowWidth, windowHeight);
enigma_user::window_center();

// apply global game settings
enigma_user::window_set_sizeable(isSizeable);
enigma_user::window_set_showborder(showBorder);
enigma_user::window_set_fullscreen(isFullScreen);

return 0;
}
} //namespace enigma
@@ -232,7 +232,7 @@ namespace enigma
// In pull request 1831, it was decided to adopt GMS behavior instead of GM8.
// The window is no longer moved, centered, or resized when switching rooms.
// This is always true, even if the room sizes are different.
enigma_user::window_default(false);
enigma_user::window_default(true);
// window sized by first room, can make visible now
enigma_user::window_set_visible(true);
enigma_user::io_clear();

0 comments on commit 2bcceb4

Please sign in to comment.
You can’t perform that action at this time.