From e685db34cb94e4bef564da4afdaa7a18b1819c09 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 3 Aug 2008 17:58:10 +0000 Subject: documentation, extra sound warnings, network bytes/sec --- src/client/client.cc | 20 ++++++++++++++++++++ src/client/view.cc | 47 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 15 deletions(-) (limited to 'src/client') diff --git a/src/client/client.cc b/src/client/client.cc index f5da1f0..93d254e 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -30,6 +30,20 @@ Client app; //--- engine functions -------------------------------------------- +void func_snd_restart(std::string const &args) +{ + // unload entity sounds + for (core::Entity::Registry::iterator it = core::Entity::registry().begin(); it != core::Entity::registry().end(); it++) { + core::Entity *entity = (*it).second; + if (entity->state()) + entity->state()->clearsound(); + } + + audio::shutdown(); + + audio::init(); +} + void func_r_restart(std::string const &args) { video::shutdown(); @@ -111,8 +125,12 @@ void Client::init(int count, char **arguments) // add engine functions core::Func *func = 0; + func = core::Func::add("r_restart", (core::FuncPtr) func_r_restart); func->set_info("restart render subsystem"); + + func = core::Func::add("snd_restart", (core::FuncPtr) func_snd_restart); + func->set_info("restart audio subsystem"); } void Client::run() @@ -171,6 +189,8 @@ void Client::shutdown() core::Func::remove("r_restart"); + core::Func::remove("snd_restart"); + chat::shutdown(); audio::shutdown(); diff --git a/src/client/view.cc b/src/client/view.cc index f72a149..391da35 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -38,10 +38,15 @@ core::Cvar *ui_pointerhovercolor =0; namespace view { -const size_t fps_counter_size = 25; // fps is the average of 20 frames +const size_t fps_counter_size = 32; // fps is the average of 32 frames float fps_counter_time[fps_counter_size]; size_t fps_counter_index = 0; +const size_t net_counter_size = 128; +float net_counter_time[net_counter_size]; +size_t net_counter_traffic[net_counter_size]; +size_t net_counter_index; + void init() { draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive); @@ -63,6 +68,9 @@ void init() for (size_t i =0; i < fps_counter_size; i++) fps_counter_time[i] = 0.0f; + + for (size_t i = 0; i < net_counter_size; i++) + net_counter_traffic[i] = 0; } void shutdown() @@ -99,18 +107,12 @@ void draw_status() std::stringstream status; - int minutes = (int) floorf(core::application()->time() / 60.0f); - int seconds = (int) floorf(core::application()->time() - (float) minutes* 60.0f); - - status << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; - Text::draw(video::width-Text::fontwidth()*11-4, 4, status); - if (core::game()) { int minutes = (int) floorf(core::game()->clientframetime() / 60.0f); int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f); - status << "^Ngame ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; - Text::draw(video::width-Text::fontwidth()*11-4, Text::fontheight()+ 4, status); + status << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; + Text::draw(video::width-Text::fontwidth()*12-4, Text::fontheight()+ 4, status); } // print stats if desired @@ -129,15 +131,30 @@ void draw_status() } std::stringstream stats; - stats << "^Nfps ^B" << std::setw(6) << fps << "\n"; + stats << "^Nfps ^B" << std::setw(6) << fps << "\n"; + if (core::application()->connected()) { - stats << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n"; - stats << "^Nquads ^B" << std::setw(5) << render::Stats::quads << "\n"; + stats << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n"; + stats << "^Nquads ^B" << std::setw(5) << render::Stats::quads << "\n"; + + if (core::Stats::network_bytes_sent + core::Stats::network_bytes_received) { + net_counter_traffic[net_counter_index] = core::Stats::network_bytes_sent + core::Stats::network_bytes_received; + net_counter_time[net_counter_index] = core::application()->time(); + size_t index_max = net_counter_index; + + net_counter_index = (net_counter_index + 1) % net_counter_size; + size_t index_min = net_counter_index; + + float d = net_counter_time[index_max] - net_counter_time[index_min]; + if (d > 0) { + float traffic = net_counter_traffic[index_max] - net_counter_traffic[index_min]; + + stats << "^Nnet ^B" << std::setw(6) << roundf( (float) traffic / d ) << "\n"; + } + } } - stats << "^Ntx ^B"<< std::setw(5) << (core::Stats::network_bytes_sent >> 10) << "\n"; - stats << "^Nrx ^B"<< std::setw(5) << (core::Stats::network_bytes_received >> 10) << "\n"; - Text::draw(video::width-Text::fontwidth()*11-4, 4 + Text::fontheight()*2, stats); + Text::draw(video::width-Text::fontwidth()*12-4, 4 + Text::fontheight()*2, stats); } // draw a basic HUD -- cgit v1.2.3