Streamline initialization and splash screen code

Should be much less chance of beachballs on OSX
This commit is contained in:
2015-09-25 17:31:57 -04:00
parent fbe80b22dd
commit 3b647f33b2
9 changed files with 135 additions and 146 deletions

View File

@@ -194,80 +194,6 @@ void adjust_window_mode() {
showMenuBar();
}
// TODO: Move to boe.startup.cpp
void plop_fancy_startup() {
sf::Texture pict_to_draw;
sf::Event event;
rectangle whole_window,from_rect;
rectangle logo_from = {0,0,350,350};
rectangle intro_from = {0,0,480,640};
if(display_mode != 5) {
hideMenuBar();
}
// for(i = 0;i < 8; i++)
// OffsetRect(&trim_rects[i],61,37);
win_to_rects[5].offset(TEXT_WIN_UL_X,TEXT_WIN_UL_Y);
win_to_rects[2].offset(PC_WIN_UL_X,PC_WIN_UL_Y);
win_to_rects[3].offset(ITEM_WIN_UL_X,ITEM_WIN_UL_Y);
whole_window = rectangle(mainPtr);
logo_from.offset((whole_window.right - logo_from.right) / 2,(whole_window.bottom - logo_from.bottom) / 2);
pict_to_draw.loadFromImage(*ResMgr::get<ImageRsrc>("spidlogo"));
from_rect = rectangle(pict_to_draw);
// TODO: Looping 10 times here is a bit of a hack; fix it
for(int k = 0; k < 10; k++) {
make_cursor_watch();
mainPtr.clear(sf::Color::Black);
rect_draw_some_item(pict_to_draw, from_rect, mainPtr, logo_from);
mainPtr.display();
mainPtr.pollEvent(event);
if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved)
make_cursor_watch();
}
play_sound(95); // Was originally negative, meaning async
// Do bulk of graphics loading!!!
Set_up_win();
init_startup();
int delay = 220;
if(show_startup_splash){
intro_from.offset((whole_window.right - intro_from.right) / 2,(whole_window.bottom - intro_from.bottom) / 2);
for(int k = 0; k < 5; k++) {
mainPtr.clear(sf::Color::Black);
pict_to_draw.loadFromImage(*ResMgr::get<ImageRsrc>("startsplash"));
from_rect = rectangle(pict_to_draw);
rect_draw_some_item(pict_to_draw, from_rect, mainPtr, intro_from);
mainPtr.display();
mainPtr.pollEvent(event);
if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved)
make_cursor_watch();
}
} else delay = 60;
delay = time_in_ticks(delay).asMilliseconds();
sf::Clock timer;
if(show_startup_splash) play_sound(-22);
make_cursor_sword();
while(timer.getElapsedTime().asMilliseconds() < delay) {
if(mainPtr.pollEvent(event)) {
if(event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::KeyPressed)
break;
}
}
if(display_mode != 5) {
showMenuBar();
mainPtr.setMouseCursorVisible(true);
}
}
void init_startup() {
startup_loaded = true;
startup_gworld.loadFromImage(*ResMgr::get<ImageRsrc>("startup"));
@@ -275,11 +201,6 @@ void init_startup() {
anim_mess.loadFromImage(*ResMgr::get<ImageRsrc>("startanim"));
}
void init_animation() {}
void next_animation_step() {}
void draw_startup(short but_type) {
rectangle to_rect;
rectangle r1 = {-1000,-1000,5,1000},r2 = {-1000,-1000,1000,5},r3 = {418,-1000,2000,1000},
@@ -552,11 +473,11 @@ void Set_up_win () {
rectangle pc_rect = {0,0,216,113};
rectangle r;
// TODO: I think this is a relic of the Exile III demo screen at the main menu; we don't actually need to load it until the function below
loadImageToRenderTexture(terrain_screen_gworld, "terscreen");
win_to_rects[5].offset(TEXT_WIN_UL_X,TEXT_WIN_UL_Y);
win_to_rects[2].offset(PC_WIN_UL_X,PC_WIN_UL_Y);
win_to_rects[3].offset(ITEM_WIN_UL_X,ITEM_WIN_UL_Y);
// Create and initialize map gworld
if(!map_gworld.create(map_rect.width(), map_rect.height())) {
play_sound(2,3);
exit(1);
@@ -572,6 +493,7 @@ void load_main_screen() {
return;
invenbtn_gworld.loadFromImage(*ResMgr::get<ImageRsrc>("invenbtns"));
loadImageToRenderTexture(terrain_screen_gworld, "terscreen");
loadImageToRenderTexture(pc_stats_gworld, "statarea");
loadImageToRenderTexture(item_stats_gworld, "inventory");
loadImageToRenderTexture(text_area_gworld, "transcript");

View File

@@ -19,11 +19,8 @@ enum {
};
void adjust_window_mode();
void plop_fancy_startup();
void init_startup();
void reload_startup();
void init_animation();
void next_animation_step() ;
void draw_startup(short but_type);
void draw_anim();
void place_anim();

View File

@@ -106,45 +106,21 @@ short store_current_pc = 0;
sf::Clock animTimer;
static void init_boe(int, char*[]);
int main(int argc, char* argv[]) {
#if 0
void debug_oldstructs();
debug_oldstructs();
#endif
try{
init_directories(argv[0]);
init_menubar(); // Do this first of all because otherwise a default File and Window menu will be seen
sync_prefs();
cUniverse::print_result = iLiving::print_result = add_string_to_buf;
cPlayer::give_help = give_help;
init_graph_tool();
init_snd_tool();
init_fileio();
init_buf();
check_for_intel();
set_up_apple_events(argc, argv);
make_cursor_watch();
Initialize();
plop_fancy_startup();
init_screen_locs();
cDialog::init();
flushingInput = true;
init_spell_menus();
mainPtr.display();
init_boe(argc, argv);
if(!game_run_before)
cChoiceDlog("welcome").show();
else if(give_intro_hint)
tip_of_day();
game_run_before = true;
init_mini_map();
finished_init = true;
if(ae_loading) {
@@ -171,36 +147,62 @@ int main(int argc, char* argv[]) {
}
}
void Initialize(void) {
// To make the Random sequences truly random, we need to make the seed start
// at a different number. An easy way to do this is to put the current time
// and date into the seed. Since it is always incrementing the starting seed
// will always be different. Don't for each call of Random, or the sequence
// will no longer be random. Only needed once, here in the init.
srand(time(nullptr));
static void init_sbar(std::shared_ptr<cScrollbar>& sbar, rectangle rect, int max, int pgSz, int start = 0) {
sbar.reset(new cScrollbar(mainPtr));
sbar->setBounds(rect);
sbar->setMaximum(max);
sbar->setPosition(start);
sbar->setPageSize(pgSz);
sbar->hide();
}
static void init_btn(std::shared_ptr<cButton>& btn, eBtnType type) {
btn.reset(new cButton(mainPtr));
btn->setBtnType(type);
btn->hide();
}
void init_boe(int argc, char* argv[]) {
init_directories(argv[0]);
init_menubar(); // Do this first of all because otherwise a default File and Window menu will be seen
sync_prefs();
load_prefs();
text_sbar.reset(new cScrollbar(mainPtr));
text_sbar->setBounds(sbar_rect);
text_sbar->setMaximum(58);
text_sbar->setPosition(58);
text_sbar->setPageSize(11);
item_sbar.reset(new cScrollbar(mainPtr));
item_sbar->setBounds(item_sbar_rect);
item_sbar->setMaximum(16);
item_sbar->setPageSize(8);
shop_sbar.reset(new cScrollbar(mainPtr));
shop_sbar->setBounds(shop_sbar_rect);
shop_sbar->setMaximum(16);
shop_sbar->setPageSize(8);
shop_sbar->hide();
done_btn.reset(new cButton(mainPtr));
done_btn->setBtnType(BTN_DONE);
done_btn->hide();
help_btn.reset(new cButton(mainPtr));
help_btn->setBtnType(BTN_HELP);
help_btn->hide();
init_graph_tool();
init_snd_tool();
adjust_window_mode();
// If we don't do this now it'll flash white to start with
mainPtr.clear(sf::Color::Black);
mainPtr.display();
make_cursor_watch();
boost::thread init_thread([]() {
init_buf();
check_for_intel();
srand(time(nullptr));
init_sbar(text_sbar, sbar_rect, 58, 11, 58);
init_sbar(item_sbar, item_sbar_rect, 16, 8);
init_sbar(shop_sbar, shop_sbar_rect, 16, 8);
init_btn(done_btn, BTN_DONE);
init_btn(help_btn, BTN_HELP);
init_screen_locs();
Set_up_win();
init_startup();
cDialog::init();
flushingInput = true;
});
show_logo();
if(show_startup_splash)
plop_fancy_startup();
init_thread.join();
cUniverse::print_result = iLiving::print_result = add_string_to_buf;
cPlayer::give_help = give_help;
set_up_apple_events(argc, argv);
init_fileio();
init_spell_menus();
init_mini_map();
redraw_screen(REFRESH_NONE);
showMenuBar();
}
void Handle_One_Event() {

View File

@@ -2,7 +2,6 @@
#include <SFML/Graphics.hpp>
int main(int argc, char* argv[]);
void Initialize(void);
void Handle_One_Event();
void Handle_Update();
void Mouse_Pressed();
@@ -13,3 +12,7 @@ void move_sound(ter_num_t ter,short step);
void incidental_noises(bool on_surface);
void pause(short length);
bool handle_startup_press(location the_point);
void draw_splash(const sf::Texture& splash, rectangle dest_rect);
void handle_splash_events();
void show_logo();
void plop_fancy_startup();

View File

@@ -18,6 +18,7 @@
#include "winutil.hpp"
#include "boe.menus.hpp"
#include "mathutil.hpp"
#include "restypes.hpp"
#include <vector>
using std::vector;
@@ -130,6 +131,69 @@ bool handle_startup_press(location the_point) {
return false;
}
extern int display_mode;
extern bool show_startup_splash;
void draw_splash(const sf::Texture& splash, rectangle dest_rect) {
rectangle from_rect = rectangle(splash);
mainPtr.clear(sf::Color::Black);
rect_draw_some_item(splash, from_rect, mainPtr, dest_rect);
mainPtr.display();
}
void handle_splash_events() {
extern sf::Event event;
if(!mainPtr.pollEvent(event)) return;
if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved)
make_cursor_watch();
}
void show_logo() {
sf::Texture pict_to_draw;
rectangle whole_window,from_rect;
rectangle logo_from = {0,0,350,350};
if(display_mode != 5)
hideMenuBar();
whole_window = rectangle(mainPtr);
logo_from.offset((whole_window.right - logo_from.right) / 2,(whole_window.bottom - logo_from.bottom) / 2);
pict_to_draw.loadFromImage(*ResMgr::get<ImageRsrc>("spidlogo"));
from_rect = rectangle(pict_to_draw);
play_sound(-95);
// TODO: Looping 10 times here is a bit of a hack; fix it
while(sound_going(95)) {
draw_splash(pict_to_draw, logo_from);
handle_splash_events();
}
if(!show_startup_splash) {
int delay = time_in_ticks(60).asMilliseconds();
sf::Clock timer;
while(timer.getElapsedTime().asMilliseconds() < delay)
handle_splash_events();
}
}
void plop_fancy_startup() {
sf::Texture pict_to_draw;
rectangle whole_window,from_rect;
rectangle intro_from = {0,0,480,640};
whole_window = rectangle(mainPtr);
int delay = time_in_ticks(220).asMilliseconds();
intro_from.offset((whole_window.right - intro_from.right) / 2,(whole_window.bottom - intro_from.bottom) / 2);
pict_to_draw.loadFromImage(*ResMgr::get<ImageRsrc>("startsplash"));
play_sound(-22);
sf::Clock timer;
while(timer.getElapsedTime().asMilliseconds() < delay) {
draw_splash(pict_to_draw, intro_from);
handle_splash_events();
}
}
/*
void start_game () {
init_party(0);

View File

@@ -80,8 +80,8 @@ rectangle rectunion(rectangle one, rectangle two) {
rectangle::rectangle() : top(0), left(0), right(0), bottom(0) {}
rectangle::rectangle(location tl, location br) : top(tl.y), left(tl.x), right(br.x), bottom(br.y) {}
rectangle::rectangle(int t, int l, int b, int r) : top(t), left(l), right(r), bottom(b) {}
rectangle::rectangle(sf::Texture& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {}
rectangle::rectangle(sf::RenderTarget& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {}
rectangle::rectangle(const sf::Texture& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {}
rectangle::rectangle(const sf::RenderTarget& texture) : top(0), left(0), right(texture.getSize().x), bottom(texture.getSize().y) {}
bool rectangle::contains(location p){
if(p.y >= top && p.y <= bottom && p.x >= left && p.x <= right)

View File

@@ -54,8 +54,8 @@ struct rectangle {
rectangle();
rectangle(location tl, location br);
rectangle(int t, int l, int b, int r);
explicit rectangle(sf::Texture& texture);
explicit rectangle(sf::RenderTarget& texture);
explicit rectangle(const sf::Texture& texture);
explicit rectangle(const sf::RenderTarget& texture);
template<typename T>
rectangle(sf::Rect<T> other) : rectangle(other.top, other.left, other.top + other.height, other.left + other.width) {}
template<typename T>

View File

@@ -38,7 +38,7 @@ std::unordered_map<int,int> sound_delay = {
};
short store_last_sound_played;
static bool sound_going(snd_num_t which_s) {
bool sound_going(snd_num_t which_s) {
short i;
for(i = 0; i < 4; i++)

View File

@@ -15,6 +15,7 @@ const int NUM_SOUNDS = 100;
typedef unsigned short snd_num_t;
void init_snd_tool();
bool sound_going(snd_num_t which_s);
void play_sound(short which, short how_many_times = 1);
void one_sound(short which);