From 01a803bec48b1377d2714bce819fb2544eeeb44b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 11 Jan 2009 16:51:21 +0000 Subject: initial loader frame --- src/client/client.cc | 6 ++++++ src/client/client.h | 3 +++ src/client/video.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++- src/client/video.h | 6 ++++++ src/core/application.cc | 13 ++++++++---- src/core/application.h | 3 +++ src/core/netconnection.cc | 6 ++++-- 7 files changed, 80 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/client.cc b/src/client/client.cc index b897480..6611bb2 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -254,6 +254,8 @@ void Client::shutdown() void Client::notify_connect() { + video::frame_loading("Connecting..."); + view()->notify()->clear(); view()->chat()->clear(); ui::root()->hide_menu(); @@ -336,6 +338,10 @@ void Client::notify_message(const core::Message::Channel channel, const std::str con_print << message << std::endl; } +void Client::notify_loader(const std::string &message) { + video::loader_message(message.c_str()); +} + //--- engine functions -------------------------------------------- void Client::func_snd_restart(std::string const &args) diff --git a/src/client/client.h b/src/client/client.h index e98eaf4..e527b37 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -43,6 +43,9 @@ public: /// text notifications from the core virtual void notify_message(const core::Message::Channel channel, const std::string &message); + /// loading message notification + virtual void notify_loader(const std::string &message); + /// text notifications from the client void notify_message(const std::string &message); diff --git a/src/client/video.cc b/src/client/video.cc index 57efa96..892f1a6 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -50,6 +50,8 @@ int height_prev = 0; const int width_default = 1024; const int height_default = 768; +bool is_loader_frame = false; + bool init() { con_print << "^BInitializing video..." << std::endl; @@ -272,13 +274,58 @@ void set_cursor() } } +void loader_message(const char *message) +{ + if (!is_loader_frame) + return; + + frame_loading(message); +} + +void frame_loading(const char *message) +{ + using namespace render; + + is_loader_frame = true; + + // Clear the color and depth buffers. + gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + render::Camera::ortho(); + + gl::enable(GL_TEXTURE_2D); + gl::enable(GL_BLEND); + + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + render::Textures::load("bitmaps/banner"); + gl::begin(gl::Quads); + + gl::vertex(0, 0); + gl::vertex(0, render::State::height()); + gl::vertex(render::State::width(), render::State::height()); + gl::vertex(render::State::width(), 0); + gl::end(); + + + if (message) { + Text::setfont("gui", 12, 18); + Text::setcolor('N'); //set normal color + Text::draw(Text::fontwidth(), Text::fontheight(), message); + } + + gl::disable(GL_TEXTURE_2D); + gl::disable(GL_BLEND); + SDL_GL_SwapBuffers(); +} + void frame(float elapsed) { + is_loader_frame = false; + // detect fullscreen/windowed mode switch if (fullscreen != r_fullscreen->value()) restart(); - using namespace render; + using namespace render; // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -302,6 +349,7 @@ void frame(float elapsed) } gl::color(1.0f, 1.0f, 1.0f, 1.0f); + gl::disable(GL_TEXTURE_2D); gl::enable(GL_BLEND); diff --git a/src/client/video.h b/src/client/video.h index d085f03..80762ae 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -32,6 +32,12 @@ namespace video /// draw the next client video frame void frame(float elapsed); + /// draw the loader screen + void frame_loading(const char *message); + + /// update the loader screen + void loader_message(const char *message); + /// set the window caption void set_caption(); diff --git a/src/core/application.cc b/src/core/application.cc index 1cba59a..be86dd6 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -270,20 +270,19 @@ void Application::connect(std::string const &host) } if (host.size()) { + notify_connect(); application_game = new GameConnection(host); if (!application_game->running()) { delete application_game; application_game = 0; - } else { - notify_connect(); } } else { + notify_connect(); application_game = new GameServer(); if (application_game->running()) { - con_print << "^BConnected to local game.\n"; - notify_connect(); + con_print << "^BConnected to local game.\n"; } else { delete application_game; application_game = 0; @@ -444,6 +443,12 @@ void Application::notify_message(const core::Message::Channel channel, const std con_print << message << std::endl; } +void Application::notify_loader(const std::string &message) +{ + // the default implementation does nothing. + // used by the client to udpate the loader screen +} + void Application::notify_sound(const char *name) { // the default implementation does nothing. diff --git a/src/core/application.h b/src/core/application.h index 45c316f..7e41869 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -72,6 +72,9 @@ public: /// text notifications from the core to the application virtual void notify_message(const core::Message::Channel channel, const std::string &message); + /// loading message notification + virtual void notify_loader(const std::string &message); + /// connect notification virtual void notify_connect(); diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 790b037..eb9ad53 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -94,8 +94,10 @@ void NetConnection::connect(std::string const &to_host, int to_port) connection_state = Pending; game()->localplayer()->set_dirty(); - - con_print << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "..." << std::endl; + std::stringstream str; + str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "..."; + con_print << str.str() << std::endl; + application()->notify_loader(str.str()); } void NetConnection::disconnect() -- cgit v1.2.3