From a255dbc032d15a4f5024bc60baa19c45ebceecc6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 9 Feb 2011 16:01:17 +0000 Subject: added sv_collisionmargin Cvar and applied the value to mesh collisions, added seconds parameter to sys::get_datetime(), added con_timestamps Cvar, enabled console timestamps on the dedicated server by default. --- src/client/infowidget.cc | 4 ++-- src/core/application.cc | 11 +++++++++ src/core/cvar.cc | 3 +++ src/core/cvar.h | 3 ++- src/core/entity.cc | 9 ++++---- src/dedicated/console.cc | 22 +++++++++++++++--- src/render/screenshot.cc | 4 ++-- src/sys/consoleinterface.cc | 55 +++++++++++++++++++++++++++++++++++++++++++-- src/sys/consoleinterface.h | 12 ++++++++++ src/sys/sys.cc | 4 +++- src/sys/sys.h | 2 +- 11 files changed, 112 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc index 393734c..ed118a8 100644 --- a/src/client/infowidget.cc +++ b/src/client/infowidget.cc @@ -47,11 +47,11 @@ void DevInfoWidget::draw() std::ostringstream textstream; const core::Entity *target = targets::current(); - textstream << "^Ncore ^B"; + textstream << "^Nuptime ^B"; time_to_stream(textstream, core::application()->time()); textstream << '\n'; if (core::game()) { - textstream << "^Ntime ^B"; + textstream << "^Ntime ^B"; time_to_stream(textstream, core::game()->time()); } textstream << '\n'; diff --git a/src/core/application.cc b/src/core/application.cc index 5c7e4e7..c731833 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -133,6 +133,9 @@ void Application::init(int count, char **arguments) Cvar::sv_keepalive = Cvar::get("sv_keepalive", "120", core::Cvar::Archive); Cvar::sv_keepalive->set_info("[int] number of seconds to keep dynamic objects alive"); + + Cvar::sv_collisionmargin = Cvar::get("sv_collisionmargin", 1.0f / 64.0f, core::Cvar::Archive); + Cvar::sv_collisionmargin->set_info("[float] margin for mesh collisions"); // network settings Cvar::net_host = Cvar::get("net_host", "0.0.0.0", Cvar::Archive); @@ -164,6 +167,14 @@ void Application::init(int count, char **arguments) Cvar::con_ansi->set_info("[bool] console ANSI colors"); sys::set_ansi(Cvar::con_ansi->value()); + if (Cvar::sv_dedicated->value()) { + Cvar::con_timestamps = Cvar::get("con_timestamps", "1", Cvar::Archive); + } else { + Cvar::con_timestamps = Cvar::get("con_timestamps", "0", Cvar::Archive); + } + Cvar::con_timestamps->set_info("[bool] enable console timestamps"); + sys::set_console_timestamps(Cvar::con_timestamps->value()); + #ifdef _WIN32 // Initialize win32 socket library WSADATA wsa_data; diff --git a/src/core/cvar.cc b/src/core/cvar.cc index 66da4d4..609778a 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -18,6 +18,8 @@ namespace core { Cvar *Cvar::con_ansi = 0; +Cvar *Cvar::con_timestamps = 0; + Cvar *Cvar::sv_dedicated = 0; Cvar *Cvar::sv_private = 0; Cvar *Cvar::sv_framerate = 0; @@ -25,6 +27,7 @@ Cvar *Cvar::sv_name = 0; Cvar *Cvar::sv_description = 0; Cvar *Cvar::sv_password = 0; Cvar *Cvar::sv_keepalive = 0; +Cvar *Cvar::sv_collisionmargin = 0; Cvar *Cvar::net_host = 0; Cvar *Cvar::net_port = 0; diff --git a/src/core/cvar.h b/src/core/cvar.h index ffc11bf..864d751 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -156,9 +156,10 @@ public: static Cvar *sv_description; // server description static Cvar *sv_password; // server rcon password static Cvar *sv_keepalive; // entity keepalive timeout + static Cvar *sv_collisionmargin; // bullet collision margin static Cvar *con_ansi; // console ANSI colors - + static Cvar *con_timestamps;// console timestamps static Cvar *net_host; // network server ip (default binds to all interfaces) static Cvar *net_port; // network port diff --git a/src/core/entity.cc b/src/core/entity.cc index 7aa72fa..ebe4938 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -515,8 +515,7 @@ void Entity::reset() btVector3 modelscalevec(modelscale, modelscale, modelscale); meshshape->setLocalScaling(modelscalevec); - //meshshape->setMargin(0.0f); - //meshshape->updateBound(); + meshshape->setMargin(Cvar::sv_collisionmargin->value()); entity_collision_shape = meshshape; // con_debug << " " << label() << " attached collision mesh: " << model()->collisionmesh()->size() << " triangles" << std::endl; @@ -609,7 +608,7 @@ void EntityDynamic::reset() btVector3 modelscalevec(modelscale, modelscale, modelscale); meshshape->setLocalScaling(modelscalevec); - //meshshape->setMargin(0.0f); + meshshape->setMargin(Cvar::sv_collisionmargin->value()); meshshape->updateBound(); entity_collision_shape = meshshape; @@ -1027,10 +1026,10 @@ void EntityControlable::reset() btVector3 modelscalevec(modelscale, modelscale, modelscale); meshshape->setLocalScaling(modelscalevec); - //meshshape->setMargin(0.0f); + meshshape->setMargin(Cvar::sv_collisionmargin->value()); meshshape->updateBound(); - entity_collision_shape = meshshape; + entity_collision_shape = meshshape; } else { // use bounding box entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale)); diff --git a/src/dedicated/console.cc b/src/dedicated/console.cc index c2b71c0..b1629fd 100644 --- a/src/dedicated/console.cc +++ b/src/dedicated/console.cc @@ -206,10 +206,26 @@ void Console::draw_status() if (core::game()) { attroff(A_BOLD); color_set(2, NULL); - int minutes = (int) floorf(core::game()->time() / 60.0f); - int seconds = (int) floorf(core::game()->time() - (float) minutes * 60.0f); + std::stringstream status; - status << "time " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; + + // system time + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; + sys::get_datetime(year, month, day, hour, min, sec); + + status << std::setw(4) << std::setfill('0') << year << "-" + << std::setw(2) << std::setfill('0') << month << "-" + << std::setw(2) << std::setfill('0') << day << " " + << std::setw(2) << hour << ":" + << std::setw(2) << min << ":" + << std::setw(2) << sec << " " + << std::setw(2) << " "; + + // uptime + int uptime_minutes = (int) floorf(core::game()->time() / 60.0f); + int uptime_seconds = (int) floorf(core::game()->time() - (float) uptime_minutes * 60.0f); + status << "uptime " << std::setfill(' ') << std::setw(3) << uptime_minutes << ":" << std::setfill('0') << std::setw(2) << uptime_seconds; + mvaddnstr(0, 1, status.str().c_str(), status.str().size()); } } diff --git a/src/render/screenshot.cc b/src/render/screenshot.cc index 7b40156..f75cbe8 100644 --- a/src/render/screenshot.cc +++ b/src/render/screenshot.cc @@ -68,10 +68,10 @@ void Screenshot::save() // check if the date has changed since the previous screenshot; std::stringstream filenamestr; - int day, month, year, hour, min; + int day, month, year, hour, min, sec; int date_serial; - sys::get_datetime(year, month, day, hour, min); + sys::get_datetime(year, month, day, hour, min, sec); date_serial = (day - 1) + (month - 1) * 31 + (year - 2000) * 31 * 12; if (current_date != date_serial) { current_number = 0; diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc index 45f678d..ce82047 100644 --- a/src/sys/consoleinterface.cc +++ b/src/sys/consoleinterface.cc @@ -4,6 +4,7 @@ the terms of the GNU General Public License version 2 */ +#include #include "sys/consoleinterface.h" namespace sys @@ -15,6 +16,20 @@ const size_t DEFAULT_LOGSIZE = 2048; bool con_ansicolor = false; +bool con_timestamps = false; + +bool beginofline = true; + +bool console_timestamps() +{ + return con_timestamps; +} + +void set_console_timestamps(const bool timestamps) +{ + con_timestamps = timestamps; +} + bool ansi() { return con_ansicolor; @@ -29,6 +44,13 @@ void set_ansi(const bool ansi) } } +void fallback_print_timestamp() +{ + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; + get_datetime(year, month, day, hour, min, sec); + std::cout << year << "-" << month << "-" << day << " " << hour << ":" << min << ":" << sec << " "; +} + void fallback_print(const std::string &text) { bool is_color_code = false; @@ -40,6 +62,7 @@ void fallback_print(const std::string &text) if ((*c) == '\n') { std::cout << std::endl; + beginofline = true; } else if ((*c) == '^') { @@ -109,11 +132,19 @@ void fallback_print(const std::string &text) std::cout << "\033[" << ansi_bold << ";" << ansi_color << "m"; c++; } else { + if (beginofline && con_timestamps) { + fallback_print_timestamp(); + } std::cout << *c; + beginofline = false; } } else { + if (beginofline && con_timestamps) { + fallback_print_timestamp(); + } std::cout << *c; + beginofline = false; } c++; @@ -127,9 +158,29 @@ int ConsoleBuffer::overflow(int c) if (c == Traits::eof()) return Traits::not_eof(c); - if (c == '\n') { + if (c == '\n') { if (ConsoleInterface::instance()) { - ConsoleInterface::instance()->event_text(con_buffer); + /* + * In the rcon case, the remote console will handle the timestamps + */ + if (con_timestamps && !ConsoleInterface::instance()->rcon()) { + std::ostringstream str; + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; + get_datetime(year, month, day, hour, min, sec); + + str << "^B" + << std::setw(4) << std::setfill('0') << year << "-" + << std::setw(2) << std::setfill('0') << month << "-" + << std::setw(2) << std::setfill('0') << day << " " + << std::setw(2) << hour << ":" + << std::setw(2) << min << ":" + << std::setw(2) << sec << " " + << std::setw(2) << con_buffer; + + ConsoleInterface::instance()->event_text(str.str()); + } else { + ConsoleInterface::instance()->event_text(con_buffer); + } } else { fallback_print(con_buffer); std::cout << std::endl; diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h index a7fde2e..b2dc5d6 100644 --- a/src/sys/consoleinterface.h +++ b/src/sys/consoleinterface.h @@ -20,12 +20,24 @@ namespace sys { +/// true if console timestamps are enabled +bool console_timestamps(); + +/// enable or disable consle timestamps +void set_console_timestamps(const bool timestamps); + /// true if ANSI colors are enabled bool ansi(); /// enable or disable ANSI colors void set_ansi(bool enable = true); +#ifdef HAVE_DEBUG_MESSAGES + +/// enable or disable debug messages + +#endif + /* -- ConsoleBuffer ------------------------------------------------ */ typedef std::char_traits Traits; diff --git a/src/sys/sys.cc b/src/sys/sys.cc index f4e915d..39700b9 100644 --- a/src/sys/sys.cc +++ b/src/sys/sys.cc @@ -180,7 +180,7 @@ void sleep(float seconds) #endif } -void get_datetime(int &year, int & month, int & day, int & hours, int & minutes) +void get_datetime(int &year, int & month, int & day, int & hours, int & minutes, int &seconds) { #ifndef _WIN32 struct ::tm localtime; @@ -193,6 +193,7 @@ void get_datetime(int &year, int & month, int & day, int & hours, int & minutes) hours = localtime.tm_hour; minutes = localtime.tm_min; + seconds = localtime.tm_sec; #else SYSTEMTIME localtime; ::GetLocalTime(&localtime); @@ -203,6 +204,7 @@ void get_datetime(int &year, int & month, int & day, int & hours, int & minutes) hours = localtime.wHour; minutes = localtime.wMinute; + seconds = localtime.wSecond; #endif } diff --git a/src/sys/sys.h b/src/sys/sys.h index 3d94bcb..99c9291 100644 --- a/src/sys/sys.h +++ b/src/sys/sys.h @@ -46,7 +46,7 @@ void sleep(float seconds); unsigned long time(); /// get the current system date and time -void get_datetime(int &year, int & month, int & day, int & hours, int & minutes); +void get_datetime(int &year, int & month, int & day, int & hours, int & minutes, int &seconds); } #include "sys/consoleinterface.h" -- cgit v1.2.3