Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-08-30 20:48:06 +0000
committerStijn Buys <ingar@osirion.org>2008-08-30 20:48:06 +0000
commit57837b0236bdebd7a1032245c64b1bc459f96d62 (patch)
treed9731122b3d28a3de206aec772af3bcbdeeb66b0 /src/server
parent084dd555366c326b7ee18515bcb282a8f4eb394a (diff)
dedicated server ncurses console updates
Diffstat (limited to 'src/server')
-rw-r--r--src/server/console.cc79
-rw-r--r--src/server/console.h2
2 files changed, 71 insertions, 10 deletions
diff --git a/src/server/console.cc b/src/server/console.cc
index c4e63e3..0fe874e 100644
--- a/src/server/console.cc
+++ b/src/server/console.cc
@@ -6,6 +6,10 @@
#include <iostream>
#include <queue>
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <cmath>
#include "server/console.h"
#include "core/core.h"
@@ -22,7 +26,7 @@ bool console_initialized = false;
bool console_updated = false;
const size_t MAXHISTOLINES = 512;
-
+float prev_time = 0;
Console server_console;
#ifdef HAVE_CURSES
@@ -42,7 +46,7 @@ void Console::init()
noecho(); // don't show typed characters
keypad(stdwin, TRUE); // enable special keys
nodelay(stdwin, TRUE); // non-blocking input
- curs_set(1); // disable cursor
+ curs_set(1); // enable cursor
if (has_colors() == TRUE) {
start_color();
@@ -199,6 +203,18 @@ void Console::draw_background()
mvaddnstr(0, y, versionstr.c_str(), stdwin->_maxx - 1);
}
+void Console::draw_status()
+{
+ if (core::game()) {
+ attroff(A_BOLD);
+ color_set(2, NULL);
+ int minutes = (int) floorf(core::game()->serverframetime() / 60.0f);
+ int seconds = (int) floorf( core::game()->serverframetime() - (float) minutes* 60.0f);
+ std::stringstream status;
+ status << "time " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
+ mvaddnstr(0, 2, status.str().c_str(), status.str().size());
+ }
+}
void Console::draw_text()
{
int w = stdwin->_maxx;
@@ -210,7 +226,7 @@ void Console::draw_text()
std::deque<std::string> lines;
int console_scroll = 0;
- int height = stdwin->_maxy - 2;
+ int height = stdwin->_maxy - 1;
int width = stdwin->_maxx - 1;
int bottom = (int) consoleinterface_text.size() - console_scroll;
int current_line = 0;
@@ -336,8 +352,6 @@ void Console::draw_input()
// fill the remainder with spaces
for (int i=1 + (*history_pos).size(); i < stdwin->_maxx; i++)
addch(' ');
- // move the cursor to input position
- move(stdwin->_maxy, 1 + (*history_pos).size());
}
void Console::draw()
@@ -346,8 +360,10 @@ void Console::draw()
return;
draw_background();
+ draw_status();
draw_text();
draw_input();
+ move(stdwin->_maxy, 1 + input_pos);
wrefresh(stdwin);
console_updated = false;
@@ -356,6 +372,8 @@ void Console::draw()
void Console::frame(float seconds)
{
+ std::deque<std::string>::reverse_iterator upit;
+
flush();
if (!console_initialized)
@@ -378,11 +396,41 @@ void Console::frame(float seconds)
input_updated = true;
break;
} else if (key == KEY_LEFT) {
- } else if (key == KEY_HOME) {
+ if (input_pos > 0) {
+ input_pos--;
+ }
+ input_updated = true;
+ break;
} else if (key == KEY_RIGHT) {
+ if (input_pos < (*history_pos).size()) {
+ input_pos++;
+ }
+ input_updated = true;
+ break;
+ } else if (key == KEY_HOME) {
+ input_pos = 0;
+ input_updated = true;
+ break;
} else if (key == KEY_END) {
+ input_pos = (*history_pos).size();
+ input_updated = true;
+ break;
} else if (key == KEY_UP) {
- } else if (key == KEY_DOWN) {
+ upit = history_pos;
+ ++upit;
+ if (upit != history.rend()) {
+ history_pos = upit;
+ input_pos = (*history_pos).size();
+ input_updated = true;
+ }
+ break;
+ } else if (key == KEY_DOWN) {
+ if (history_pos != history.rbegin()) {
+ --history_pos;
+ input_pos = (*history_pos).size();
+ input_updated = true;
+ }
+ break;
} else if (key == KEY_ENTER || key == '\n') {
if ((*history_pos).size()) {
// store input into history
@@ -397,7 +445,7 @@ void Console::frame(float seconds)
history.push_back("");
history_pos = history.rbegin();
input_pos = 0;
- input_updated = true;
+ console_updated = true;
}
break;
} else if (key == KEY_PPAGE) {
@@ -416,8 +464,19 @@ void Console::frame(float seconds)
if (console_updated) {
draw();
- } else if (input_updated) {
- draw_input();
+ } else {
+ if (input_updated) {
+ draw_input();
+ }
+ if (roundf(core::game()->serverframetime()) != prev_time) {
+ draw_status();
+ prev_time = roundf(core::game()->serverframetime());
+ input_updated = true;
+ }
+ if (input_updated) {
+ // move the cursor to input position
+ move(stdwin->_maxy, 1 + input_pos);
+ }
}
}
#endif // HAVE_CURSES
diff --git a/src/server/console.h b/src/server/console.h
index b96f593..9cfe604 100644
--- a/src/server/console.h
+++ b/src/server/console.h
@@ -30,6 +30,8 @@ protected:
void draw();
/// clear and draw background (ncurses)
void draw_background();
+ /// draw status
+ void draw_status();
/// draw the console text (ncurses)
void draw_text();
/// draw the console input (ncurses)