diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/auxiliary/functions.h | 6 | ||||
-rw-r--r-- | src/client/chat.cc | 15 | ||||
-rw-r--r-- | src/client/client.cc | 6 | ||||
-rw-r--r-- | src/client/console.cc | 223 | ||||
-rw-r--r-- | src/client/input.cc | 4 | ||||
-rw-r--r-- | src/client/video.cc | 4 | ||||
-rw-r--r-- | src/client/view.cc | 71 | ||||
-rw-r--r-- | src/core/Makefile.am | 2 | ||||
-rw-r--r-- | src/core/application.cc | 8 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 10 | ||||
-rw-r--r-- | src/core/gameserver.cc | 30 | ||||
-rw-r--r-- | src/core/netserver.cc | 22 | ||||
-rw-r--r-- | src/filesystem/filesystem.cc | 4 | ||||
-rw-r--r-- | src/game/game.cc | 29 | ||||
-rw-r--r-- | src/model/vertexarray.cc | 4 | ||||
-rw-r--r-- | src/render/render.cc | 18 | ||||
-rw-r--r-- | src/render/text.cc | 90 | ||||
-rw-r--r-- | src/render/text.h | 25 | ||||
-rw-r--r-- | src/render/textures.cc | 21 | ||||
-rw-r--r-- | src/render/textures.h | 13 |
20 files changed, 396 insertions, 209 deletions
diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h index 88af5c7..eff5143 100644 --- a/src/auxiliary/functions.h +++ b/src/auxiliary/functions.h @@ -23,6 +23,12 @@ inline const std::string plural(const std::string & word, size_t n) { return plu const std::string article(const char * word); inline const std::string article(const std::string & word) { return article(word.c_str()); } + +inline bool is_base_color_code(char const *c) { return ((*c == '^') && (*(c+1) >= '0') && (*(c+1) <= '9')); } + +inline bool is_core_color_code(char const *c) { return ((*c == '^') && (*(c+1) >= 'A') && (*(c+1) <= 'Z')); } + +inline bool is_color_code(char const *c) { return (is_base_color_code(c) || is_core_color_code(c)); } } #endif // __INCLUDED_AUX_FUNCTIONS_H__ diff --git a/src/client/chat.cc b/src/client/chat.cc index 0d1def6..1953390 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -79,19 +79,16 @@ void draw() while (input_pos - draw_pos > width) draw_pos += 2; - // draw the console input - gl::color(1.0f, 1.0f, 1.0f, 1.0f); - Text::draw(4 , 5 + Text::fontheight() * (MAXNOTIFYLINES+1), "say"); - gl::color(0.0f, 1.0f, .0f, 1.0f); - Text::draw(4+Text::fontwidth()*3 , 5 + Text::fontheight() * (MAXNOTIFYLINES+1), ":"); + // draw the chat input + float y = video::height * 8.0 / 10.0; - gl::color(1.0f, 1.0f, 1.0f, 1.0f); - Text::draw(4+Text::fontwidth()*5, 5 + Text::fontheight() * (MAXNOTIFYLINES+1), (*history_pos).substr(draw_pos, width)); + Text::draw(4 , y, "^Bsay^F:^B"); + Text::draw(4+Text::fontwidth()*5 , y, (*history_pos).substr(draw_pos, width)); // draw cursor if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) { - std::string cursor("_"); - Text::draw(4+Text::fontwidth()*(input_pos - draw_pos+5), 5 + Text::fontheight() * (MAXNOTIFYLINES+1) , cursor); + std::string cursor("^B_"); + Text::draw(4+Text::fontwidth()*(input_pos - draw_pos+5), y, cursor); } } diff --git a/src/client/client.cc b/src/client/client.cc index c607c64..6a4d23e 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -82,7 +82,7 @@ void Client::quit(int status) void Client::init(int count, char **arguments) { - con_print << "Initializing client..." << std::endl; + con_print << "^BInitializing client..." << std::endl; // initialize core core::Cvar::sv_dedicated = core::Cvar::set("sv_private", "0"); @@ -123,7 +123,7 @@ void Client::init(int count, char **arguments) void Client::run() { - con_print << "Running client..." << std::endl; + con_print << "^BRunning client..." << std::endl; Uint32 client_framerate = (Uint32)(1000/120); Uint32 elapsed = 0; @@ -154,7 +154,7 @@ void Client::run() void Client::shutdown() { - con_print << "Shutting down client..." << std::endl; + con_print << "^BShutting down client..." << std::endl; console::flush(); // remove engine functions diff --git a/src/client/console.cc b/src/client/console.cc index 914d32f..b60e179 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -4,8 +4,9 @@ the terms and conditions of the GNU General Public License version 2 */ -#include "filesystem/filesystem.h" +#include "auxiliary/functions.h" #include "core/core.h" +#include "filesystem/filesystem.h" #include "render/render.h" #include "render/textures.h" #include "client/console.h" @@ -65,25 +66,25 @@ size_t notify_pos = 0; std::string notify_text[MAXNOTIFYLINES]; float notify_time[MAXNOTIFYLINES]; - //--- engine functions -------------------------------------------- void func_con_toggle(std::string const &args) { + std::istringstream argstream(args); int i; if (argstream >> i) { - if (i) console_visible = true; else console_visible = false; - } else - console_visible = !console_visible; + if (i) console_visible = false; else console_visible = true; + } + toggle(); } //--- public ------------------------------------------------------ void init() { - con_print << "Initializing console..." << std::endl; + con_print << "^BInitializing console..." << std::endl; console_visible = false; @@ -103,7 +104,7 @@ void init() void shutdown() { - con_print << "Shutting down console..." << std::endl; + con_print << "^BShutting down console..." << std::endl; save_history(); @@ -117,26 +118,125 @@ void shutdown() input_pos = 0; } -void draw() +void clear_notify() +{ + for (size_t i=0; i < MAXNOTIFYLINES; i++) + notify_time[i] = 0; +} + +void draw_notify() +{ + using namespace render; + + // draw notifications + Text::setcolor('N'); + size_t width = (size_t) ((video::width - 8) / Text::fontwidth()); + size_t n = notify_pos % MAXNOTIFYLINES; + float h = 4 + 2*Text::fontheight(); + for (size_t l = 0; l < MAXNOTIFYLINES; l++) { + if (notify_text[n].size() > 2 && notify_time[n] + 4 > core::application()->time()) { + std::string linedata(notify_text[n]); + linedata += '\n'; + + std::string word; + size_t word_length = 0; + + std::string line; + size_t line_length = 0; + + const char *c = linedata.c_str(); + char pen = 'N'; + + while (*c) { + + // color code + if (aux::is_color_code(c)) { + c++; + pen = *c; + word += '^'; + word += pen; + } + + // new word, wrap if necessary + else if ((*c == '\n' ) || ( *c == ' ')) { + + if (line_length + word_length > width) { + if (line.size()) { + Text::draw(4, h, line); + h += Text::fontheight(); + line.clear(); + line += '^'; + line += pen; + line_length = 0; + } + } + + line.append(word); + line_length += word_length; + + word.clear(); + word_length = 0; + + // new line + if (*c == '\n' ) { + Text::draw(4, h, line); + h += Text::fontheight(); + line.clear(); + line_length = 0; + // new word + } else if (*c == ' ' ) { + line += ' '; + line_length++; + } + } + + // new character + else { + word += *c; + word_length++; + + if (word_length == width) { + if (line.size()) { + Text::draw(4, h, line); + h += Text::fontheight(); + line.clear(); + line += '^'; + line += pen; + line_length = 0; + } + + line.append(word); + line_length = word_length; + + word.clear(); + word_length = 0; + } + } + + c++; + } + + } + n = (n+1) % MAXNOTIFYLINES; + } +} + +void draw_console() { using namespace render; - - if(!console_visible) - return; float con_height = 0.70f; // draw version below the bottom of the console - gl::color(0.0f, 1.0f, 0.0f, 0.5f); std::string version(core::name()); version += ' '; version.append(core::version()); + gl::color(0.0f, 1.0f, 0.0f, 0.5f); Text::draw(video::width-Text::fontwidth()*(version.size()+1), video::height*con_height-Text::fontheight()-4, version); gl::disable(GL_TEXTURE_2D); // draw the transparent console background gl::color(1.0f, 1.0f, 1.0f, 0.02f); - gl::begin(gl::Quads); gl::vertex(0.0f, 0.0f, 0.0f); gl::vertex(video::width, 0.0f,0.0f); @@ -150,23 +250,10 @@ void draw() gl::enable(GL_TEXTURE_2D); - //gl::color(0.7f,0.7f,0.7f, 1.0f); - gl::color(1.0f,1.0f,1.0f, 1.0f); - size_t height = (size_t) (video::height * con_height / Text::fontheight()) -1; size_t width = (size_t) (video::width / Text::fontwidth()) -2; size_t bottom = text.size() - console_scroll; size_t current_line = 0; -/* - if (line[0] == '?') - gl::color(0.7f,0.7f,0.7f, 1.0f); - else if (line[0] == '*') - gl::color(1.0f,1.0f,0.0f, 1.0f); - else if (line[0] == '!') - gl::color(1.0f,0.0f,0.0f, 1.0f); - else - gl::color(1.0f,1.0f,1.0f, 1.0f); -*/ std::deque<std::string> lines; for (std::deque<std::string>::iterator it = text.begin(); it != text.end() && current_line < bottom; it++) { @@ -175,41 +262,75 @@ void draw() linedata += '\n'; std::string word; + size_t word_length = 0; + std::string line; + size_t line_length = 0; + const char *c = linedata.c_str(); + char pen = 'N'; while (*c) { + + // color code + if (aux::is_color_code(c)) { + c++; + pen = *c; + word += '^'; + word += pen; + } + // new word, wrap if necessary - if ((*c == '\n' ) || ( *c == ' ')) { + else if ((*c == '\n' ) || ( *c == ' ')) { - if (line.size() + word.size() > width) { + if (line_length + word_length > width) { if (line.size()) { lines.push_back(line); line.clear(); + line += '^'; + line += pen; + line_length = 0; } } line.append(word); + line_length += word_length; + word.clear(); - - // force break words longer than width - while (line.size() > width) { - lines.push_back(line.substr(0, width)); - line.erase(0, width); - } - + word_length = 0; + // new line if (*c == '\n' ) { lines.push_back(line); line.clear(); + line_length = 0; // new word } else if (*c == ' ' ) { line += ' '; + line_length++; } + } + // new character - } else { - + else { word += *c; + word_length++; + + if (word_length == width) { + if (line.size()) { + lines.push_back(line); + line.clear(); + line += '^'; + line += pen; + line_length = 0; + } + + line.append(word); + line_length = word_length; + + word.clear(); + word_length = 0; + } } c++; @@ -220,6 +341,7 @@ void draw() } float y = video::height*con_height-2*Text::fontheight()-4; + Text::setcolor('N'); for (std::deque<std::string>::reverse_iterator rit = lines.rbegin(); (y >= 4) && (rit != lines.rend()); ++rit) { Text::draw(4, y, (*rit)); y -= Text::fontheight(); @@ -228,20 +350,29 @@ void draw() // draw the console input size_t draw_pos = 0; + y = video::height*con_height - Text::fontheight() - 4; + while (input_pos - draw_pos > width) draw_pos += 2; - gl::color(0.0f, 1.0f, 0.0f, 1.0f); - Text::draw(Text::fontwidth(), video::height*con_height - Text::fontheight() - 4, (*history_pos).substr(draw_pos, width)); + Text::draw(4, y, "^B>"); + Text::draw(4+Text::fontwidth(), y , (*history_pos).substr(draw_pos, width-1)); // draw cursor if ((core::application()->time() - ::floorf(core::application()->time())) < 0.5f) { - std::string cursor("_"); - Text::draw(Text::fontwidth()*(input_pos-draw_pos+1), video::height*con_height - Text::fontheight() - 4 , cursor); + std::string cursor("^B_"); + Text::draw(4+Text::fontwidth()*(input_pos-draw_pos+1), y , cursor); } } +void draw(){ + if (visible()) + draw_console(); + else + draw_notify(); +} + void flush() { char line[MAXCMDSIZE]; @@ -279,6 +410,7 @@ void toggle() } else { SDL_WM_GrabInput(SDL_GRAB_ON); SDL_ShowCursor(SDL_DISABLE); + clear_notify(); } setkeyboardmode(console::visible()); @@ -300,6 +432,7 @@ void keypressed(int key) } core::cmd() << (*history_pos) << std::endl; + con_print << "^B>" << (*history_pos) << std::endl; (*history.rbegin()) = (*history_pos); history.push_back(""); @@ -425,22 +558,22 @@ void Console::flush() std::ostream & Console::messagestream() { - return (buffer << ". "); + return (buffer << "^N"); } std::ostream & Console::warningstream() { - return (buffer << "* "); + return (buffer << "^W"); } std::ostream & Console::errorstream() { - return (buffer << "! "); + return (buffer << "^R"); } std::ostream & Console::debugstream() { - return (buffer << "? "); + return (buffer << "^D"); } } // namespace console diff --git a/src/client/input.cc b/src/client/input.cc index 45c39a9..f40591c 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -48,7 +48,7 @@ const float thruster_offset = 0.05f; void init() { - con_print << "Initializing input..." << std::endl; + con_print << "^BInitializing input..." << std::endl; client::setkeyboardmode(false); SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); @@ -59,7 +59,7 @@ void init() void shutdown() { - con_print << "Shutting down input..." << std::endl; + con_print << "^BShutting down input..." << std::endl; // SDL_EnableUNICODE(0); } diff --git a/src/client/video.cc b/src/client/video.cc index cd25d19..2253c52 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -54,7 +54,7 @@ void reset() bool init() { - con_print << "Initializing video..." << std::endl; + con_print << "^BInitializing video..." << std::endl; // initialize cvars r_width = core::Cvar::get("r_width", width_default, core::Cvar::Archive); @@ -134,7 +134,7 @@ void frame(float seconds) void shutdown() { - con_print << "Shutting down video..." << std::endl; + con_print << "^BShutting down video..." << std::endl; view::shutdown(); diff --git a/src/client/view.cc b/src/client/view.cc index 7d11df3..0fa47d4 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -129,44 +129,36 @@ void draw_status() return; // print the status in the upper left corner - gl::color(1.0f, 1.0f, 1.0f, 1.0f); std::stringstream status; - - /* - int minutes = (int) floorf(core::application()->time() / 60.0f); - int seconds = (int) floorf(core::application()->time() - (float) minutes* 60.0f); - */ - + if (core::game()) { int minutes = (int) floorf(core::game()->clientframetime() / 60.0f); int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f); - status << "time " << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; + status << "^Ntime ^B" << std::setfill('0') << std::setw(2) << minutes << "^N:^B" << std::setfill('0') << std::setw(2) << seconds; Text::draw(4, 4, status); } // print stats if desired if (draw_stats && draw_stats->value()) { std::stringstream stats; - stats << "fps " << std::setw(6) << fps << "\n"; + stats << "^Nfps ^B" << std::setw(6) << fps << "\n"; if (core::application()->connected()) { - stats << "tris " << std::setw(5) << render::Stats::tris << "\n"; - stats << "quads " << 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"; } - stats << "tx "<< std::setw(5) << (core::Stats::network_bytes_sent >> 10) << "\n"; - stats << "rx "<< std::setw(5) << (core::Stats::network_bytes_received >> 10) << "\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()*12, video::height - Text::fontheight()*8, stats); } // draw a basic HUD if (core::localcontrol()) { - gl::color(1.0f,1.0f,1.0f, 1.0f); - status.str(""); - status << "thrust " << std::setfill(' ') << std::setw(5) << std::fixed + status << "^Nthrust ^B" << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->thrust() << " "; - status << "speed " << std::setfill(' ') << std::setw(5) << std::fixed + status << "^Nspeed ^B" << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed(); Text::draw(4, video::height - Text::fontheight() -4, status); @@ -174,48 +166,6 @@ void draw_status() } -void draw_notify() -{ - using namespace render; - - if (console::visible()) - return; - - // draw notifications - gl::color(1.0f, 1.0f, 1.0f, 1.0f); - size_t width = (size_t) ((video::width - 8) / Text::fontwidth()); - size_t n = console::notify_pos % MAXNOTIFYLINES; - float h = 4 + 2*Text::fontheight(); - for (size_t l = 0; l < MAXNOTIFYLINES; l++) { - if (console::notify_text[n].size() > 2 && console::notify_time[n] + 4 > core::application()->time()) { - std::string line(console::notify_text[n]); - - if (line[0] == '?') - gl::color(0.7f,0.7f,0.7f, 1.0f); - else if (line[0] == '*') - gl::color(1.0f,1.0f,0.0f, 1.0f); - else if (line[0] == '!') - gl::color(1.0f,0.0f,0.0f, 1.0f); - else - gl::color(1.0f,1.0f,1.0f, 1.0f); - line.erase(0,2); - - std::deque<std::string> lines; - - while (line.size() > width) { - Text::draw(4, h, line.substr(0, width)); - line.erase(0, width); - h += Text::fontheight(); - } - if (line.size()) { - Text::draw(4, h, line); - h += Text::fontheight(); - } - } - n = (n+1) % MAXNOTIFYLINES; - } -} - void draw_cursor() { if (!core::localcontrol() || console::visible()) @@ -309,11 +259,8 @@ void frame(float seconds) } // draw text elements - - // FIXME width and height should be derived from texture size Text::setfont("bitmaps/fonts/console", 12, 18); console::draw(); - draw_notify(); chat::draw(); Text::setfont("bitmaps/fonts/gui", 16, 24); diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8b99c72..fb32450 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -12,5 +12,5 @@ libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \ noinst_LTLIBRARIES = libcore.la noinst_HEADERS = application.h commandbuffer.h clientstate.h core.h cvar.h entity.h func.h \ gameconnection.h gameinterface.h gameserver.h module.h net.h \ - netclient.h netconnection.h netserver.cc player.h stats.h + netclient.h netconnection.h netserver.h player.h stats.h diff --git a/src/core/application.cc b/src/core/application.cc index be1dcac..2f8cc54 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -116,7 +116,7 @@ Application::~Application() void Application::init(int count, char **arguments) { con_debug << "Debug messages enabled\n"; - con_print << "Initializing core...\n"; + con_print << "^BInitializing core...\n"; filesystem::init(); @@ -182,7 +182,7 @@ void Application::init(int count, char **arguments) void Application::shutdown() { - con_print << "Shutting down core...\n"; + con_print << "^BShutting down core...\n"; if (connected()) disconnect(); @@ -241,7 +241,7 @@ void Application::connect(std::string const &host) application_game = new GameServer(); if (application_game->running()) { - con_print << "Connected to local game.\n"; + con_print << "^BConnected to local game.\n"; } else { delete application_game; application_game = 0; @@ -255,7 +255,7 @@ void Application::disconnect() if(application_game) { delete application_game; application_game = 0; - con_print << "Disconnected.\n"; + con_print << "^BDisconnected.\n"; } } diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 56aba16..e97a00e 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -90,7 +90,7 @@ void CommandBuffer::init() func = Func::add("set", (FuncPtr)func_set); func->set_info("[variable] [str] set variable value"); - func = Func::add("exec", (FuncPtr)exec); + func = Func::add("exec", (FuncPtr)func_exec); func->set_info("[filename] execute commands from file"); } @@ -153,7 +153,7 @@ void CommandBuffer::exec(std::string const &cmdline) } } - con_print << command << " " << cvar->str() << " " << cvar->info() << "\n"; + con_print << command << " " << cvar->str() << " ^N" << cvar->info() << "\n"; return; } @@ -161,7 +161,7 @@ void CommandBuffer::exec(std::string const &cmdline) if (connection()) connection()->forward(cmdline); else - con_print << "Unknown command '" << command << "'\n"; + con_print << "Unknown command '" << command << "^N'\n"; } void CommandBuffer::exec() @@ -252,7 +252,9 @@ void CommandBuffer::exec_file(std::string const & filename) con_warn << "Could not stream " << fn << "!\n"; return; } - + + con_debug << "Executing " << fn.c_str() << std::endl; + char line[MAXCMDSIZE]; while (ifs.getline(line, MAXCMDSIZE-1)) { if (line[0] && line[0] != '#' && line[0] != ';') diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 98823e0..11a8b13 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -30,7 +30,7 @@ GameServer *GameServer::server_instance = 0; GameServer::GameServer() : GameInterface() { - con_print << "Initializing game server...\n"; + con_print << "^BInitializing game server...\n"; server_instance = this; server_network = 0; server_time = 0; @@ -51,7 +51,7 @@ GameServer::GameServer() : GameInterface() return; } - con_print << " module '" << server_module->name() << "'\n"; + con_print << " module '^B" << server_module->name() << "^N'\n"; if ((Cvar::sv_dedicated->value() || Cvar::sv_private->value())) { server_network = new NetServer(Cvar::net_host->str(), (unsigned int) Cvar::net_port->value()); @@ -63,7 +63,7 @@ GameServer::GameServer() : GameInterface() return; } } else { - con_debug << "Network server disabled.\n"; + con_print << " network server disabled.\n"; server_network = 0; } @@ -81,7 +81,7 @@ GameServer::~GameServer() { server_running = false; - con_print << "Shutting down game server...\n"; + con_print << "^BShutting down game server...\n"; if (server_network) { delete server_network; @@ -143,13 +143,13 @@ void GameServer::say(Player *player, std::string const &message) return; // send to console - con_print <<player->name() << ": " << message << "\n"; + con_print << "^B" << player->name() << "^F:^B " << message << std::endl; // broadcast to remote clients if (server_network) { - std::string netmessage("msg public "); + std::string netmessage("msg public ^B"); netmessage.append(player->name()); - netmessage.append(": "); + netmessage.append("^F:^B "); netmessage.append(message); netmessage += '\n'; server_network->broadcast(netmessage); @@ -214,7 +214,7 @@ void GameServer::exec(Player *player, std::string const & cmdline) std::string message("Unknown command '"); message.append(command); - message.append("'"); + message.append("^N'"); send(player, message); } @@ -222,8 +222,9 @@ void GameServer::player_connect(Player *player) { player->player_id = server_maxplayerid++; - std::string message(player->name()); - message.append(" connects."); + std::string message("^B"); + message.append(player->name()); + message.append("^B connects."); broadcast(message, player); // notify the game module @@ -232,8 +233,9 @@ void GameServer::player_connect(Player *player) void GameServer::player_disconnect(Player *player) { - std::string message(player->name()); - message.append(" disconnects."); + std::string message("^B"); + message.append(player->name()); + message.append("^B disconnects."); broadcast(message, player); // notify the game module @@ -303,7 +305,7 @@ void GameServer::frame(float seconds) // transmit buffered sends server_network->transmit(); - // TODO - start server frame + // start server frame std::ostringstream framehdr; framehdr.str(""); framehdr << "frame " << server_time << "\n"; @@ -355,8 +357,6 @@ void GameServer::frame(float seconds) client->player()->player_dirty = false; } } - // TODO - end server frame - // transmit buffered sends server_network->transmit(); diff --git a/src/core/netserver.cc b/src/core/netserver.cc index e66f63d..5334c6f 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -39,7 +39,7 @@ namespace core NetServer::NetServer(std::string const host, unsigned int const port) { - con_print << "Initializing network server..." << std::endl; + con_print << "^BInitializing network server..." << std::endl; // initialize variables netserver_fd = -1; @@ -84,7 +84,7 @@ NetServer::NetServer(std::string const host, unsigned int const port) return; } - con_print << " Listening on " << inet_ntoa(netserver_addr.sin_addr) << ":" << ntohs(netserver_addr.sin_port) << std::endl; + con_print << " listening on " << inet_ntoa(netserver_addr.sin_addr) << ":" << ntohs(netserver_addr.sin_port) << std::endl; // add the listening socket to the file descriptor set FD_ZERO(&serverset); @@ -98,7 +98,7 @@ NetServer::NetServer(std::string const host, unsigned int const port) NetServer::~NetServer() { - con_print << "Shutting down network server..." << std::endl; + con_print << "^BShutting down network server..." << std::endl; std::string netmsg("disconnect\n"); @@ -140,8 +140,9 @@ void NetServer::reap() (*it)->abort(); // print a message - std::string message(client->player()->name()); - message.append(" timed out."); + std::string message("^B"); + message.append(client->player()->name()); + message.append(" ^Btimed out."); if (client->state() == NetClient::Connected) { server()->broadcast(message, client->player()); @@ -252,7 +253,6 @@ void NetServer::receive() } // remove dead connections - // FIXME timeout reap(); } @@ -365,8 +365,9 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me } else if ((client->state() == NetClient::Connected) && (client->player()->name() != oldname)) { - std::string netmsg(oldname); - netmsg.append(" renamed to "); + std::string netmsg("^B"); + netmsg.append(oldname); + netmsg.append(" ^Brenamed to "); netmsg.append(client->player()->name()); server()->broadcast(netmsg); } @@ -409,10 +410,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me // say if (command == "say") { if (message.size() > command.size()+1) { - std::ostringstream osstream; - osstream << "msg public " << client->player()->name() << " " << message.substr(command.size()+1) << "\n"; - broadcast(osstream.str()); - con_print << client->player()->name() << " " << message.substr(command.size()+1) << std::endl; + server()->say(client->player(), message.substr(command.size()+1)); } return; } diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index e0b45a9..dd694ee 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -22,7 +22,7 @@ std::string writedir = ""; void init() { - con_print << "Initializing filesystem..." << std::endl; + con_print << "^BInitializing filesystem..." << std::endl; // initialize game data locations // FIXME datadir should by set by ./configure and read from config.h @@ -56,7 +56,7 @@ void init() void shutdown() { - con_print << "Shutting down filesystem..." << std::endl; + con_print << "^BShutting down filesystem..." << std::endl; } File *open(const char *filename) diff --git a/src/game/game.cc b/src/game/game.cc index 8b70958..d2e5242 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -37,8 +37,9 @@ void func_join(core::Player *player, std::string const &args) player->player_control = new Ship(player, default_shipmodel); player->control()->entity_color = player->color(); - std::string message(player->name()); - message.append(" joins the game."); + std::string message("^B"); + message.append(player->name()); + message.append("^B joins the game."); core::server()->broadcast(message); player->player_dirty = true; @@ -50,8 +51,9 @@ void func_spectate(core::Player *player, std::string const &args) if (!player->player_control) return; - std::string message(player->name()); - message.append(" spectates."); + std::string message("^B"); + message.append(player->name()); + message.append("^B spectates."); core::server()->broadcast(message); if (player->control()) { @@ -80,7 +82,7 @@ void func_buy(core::Player *player, std::string const &args) } if (helpstr.size()) - helpstr += '|'; + helpstr.append("^N|^B"); helpstr.append((*smit)->modelname()); } @@ -94,10 +96,10 @@ void func_buy(core::Player *player, std::string const &args) player->player_control = new Ship(player, shipmodel); player->control()->entity_color = player->color(); - core::server()->broadcast(player->name() + " purchased " + aux::article(shipmodel->name())); + core::server()->broadcast("^N" + player->name() + " ^Bpurchased " + aux::article(shipmodel->name())); player->player_dirty = true; } else { - core::server()->send(player, "Usage: buy <" + helpstr + ">"); + core::server()->send(player, "Usage: buy <" + helpstr + "^N>"); } } /*----- Game ------------------------------------------------------ */ @@ -124,6 +126,8 @@ void Game::init() worldini.open("world"); if (!worldini.is_open()) { + con_error << "Could not open ini/world.ini!" << std::endl; + abort(); return; } @@ -205,9 +209,12 @@ void Game::init() // do not reuse the previous IniFile instance, some gcc versions do not like it filesystem::IniFile shipsini; shipsini.open("ships"); - if (!shipsini.is_open()) + if (!shipsini.is_open()) { + con_error << "Could not open ini/ships.ini!" << std::endl; + abort(); return; - + } + ShipModel *shipmodel = 0; default_shipmodel = 0; @@ -245,7 +252,7 @@ void Game::init() shipsini.close(); if (!default_shipmodel) { - con_error << "No default ship model\n"; + con_error << "No default ship model in ini/ships.ini!\n"; return; } @@ -258,7 +265,7 @@ void Game::init() core::Func::add("list_ship", (core::FuncPtr) func_list_ship); // add engine game variables - core::Cvar::set("g_borgcubes", "2", core::Cvar::Game); + core::Cvar::set("g_testgamevariable", "1", core::Cvar::Game); core::Cvar::set("g_name", name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly); // indicate the module is ready to run frames diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc index 420e816..d13fc0c 100644 --- a/src/model/vertexarray.cc +++ b/src/model/vertexarray.cc @@ -25,8 +25,8 @@ VertexArray::VertexArray(size_t size) vertex_normal = (float *) malloc(vertex_size * sizeof(float)); vertex_texture = (float *) malloc(vertex_size * sizeof(float)); - con_print << "Initializing vertex array..." << std::endl; - con_debug << " " << size << " Mb allocated" << std::endl; + con_print << "^BInitializing vertex array..." << std::endl; + con_print << " " << size << " Mb allocated" << std::endl; clear(); } diff --git a/src/render/render.cc b/src/render/render.cc index 8c4f0fb..e602673 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -56,13 +56,11 @@ bool texture(const char *filename, size_t id) void init() { - con_print << "Initializing renderer..." << std::endl; + con_print << "^BInitializing renderer..." << std::endl; - con_print << " renderer " << gl::renderer() << std::endl; - con_print << " vendor " << gl::vendor() << std::endl; - con_print << " version " << gl::version() << std::endl; - - Textures::init(); + con_print << " renderer ^B" << gl::renderer() << std::endl; + con_print << " vendor ^B" << gl::vendor() << std::endl; + con_print << " version ^B" << gl::version() << std::endl; // size of the vertex array in megabytes r_arraysize = core::Cvar::get("r_arraysize", 0.0f , core::Cvar::Archive); @@ -81,11 +79,17 @@ void init() r_wireframe = core::Cvar::get("r_wireframe", "0", core::Cvar::Archive); r_wireframe->set_info("[bool] render wireframe"); + + Textures::init(); + + Text::init(); } void shutdown() { - con_print << "Shutting down renderer..." << std::endl; + con_print << "^BShutting down renderer..." << std::endl; + + Text::shutdown(); Textures::shutdown(); diff --git a/src/render/text.cc b/src/render/text.cc index 668f4ec..7c1ae8e 100644 --- a/src/render/text.cc +++ b/src/render/text.cc @@ -1,18 +1,83 @@ /* render/text.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ +#include "auxiliary/functions.h" #include "render/text.h" #include "render/textures.h" #include "sys/sys.h" -namespace render { +namespace render +{ float Text::text_fontwidth = 16.0f; float Text::text_fontheight = 24.0f; +math::Color * Text::base_color[10]; +math::Color * Text::core_color[26]; + +void Text::init() +{ + // base colors + // Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7 + base_color[0] = new math::Color(0, 0, 0); + base_color[1] = new math::Color(1, 0, 0); + base_color[2] = new math::Color(0, 1, 0); + base_color[3] = new math::Color(1, 1, 0); + base_color[4] = new math::Color(0, 0, 1); + base_color[5] = new math::Color(0, 1, 1); + base_color[6] = new math::Color(1, 0, 1); + base_color[7] = new math::Color(1, 1, 1); + + for (size_t i=0; i< 26; i++) { + core_color[i] = new math::Color(.7, .7, .7); + } + + // N - normal color + core_color[(size_t)('N'-'A')]->assign(.7, .7, .7); + // D - Debug color + core_color[(size_t)('D'-'A')]->assign(.6, .6, .6); + // B - bold color + core_color[(size_t)('B'-'A')]->assign(1, 1, 1); + // W - warning color + core_color[(size_t)('W'-'A')]->assign(1, 1, 0); + // R - Error color + core_color[(size_t)('R'-'A')]->assign(1, 0, 0); + // F - Fancy color + core_color[(size_t)('F'-'A')]->assign(0, 1, 0); +} + +void Text::shutdown() +{ + for (size_t i=0; i< 7; i++) { + delete base_color[i]; + base_color[i] = 0; + } + + for (size_t i=0; i< 26; i++) { + delete core_color[i]; + core_color[i] = 0; + } +} + +void Text::setcolor(const char color) +{ + if (('A' <= color) && (color <= 'Z')) { + gl::color(*core_color[(size_t) (color - 'A')]); + } + + else if (('0' <= color) && (color <= '9')) { + gl::color(*base_color[(size_t) (color - '0')]); + } + + else { + gl::color(1, 1, 1); + } + +} + void Text::setfont(const char *texture, float width, float height) { Textures::bind(texture, false); @@ -20,6 +85,7 @@ void Text::setfont(const char *texture, float width, float height) text_fontheight = height; } + void Text::draw(float x, float y, const char ascii) { if (ascii != ' ') { @@ -28,9 +94,9 @@ void Text::draw(float x, float y, const char ascii) float frow = row * 0.0625f; float fcol = col * 0.0625f; - + gl::begin(gl::Quads); - + glTexCoord2f(fcol, frow); gl::vertex(x,y,1); @@ -52,13 +118,21 @@ void Text::draw(float x, float y, const char *text) { const char *c = text; while (*c) { - draw(x, y, *c); + if (aux::is_base_color_code(c)) { + c++; + gl::color(*base_color[ (size_t)(*c - '0')]); + } else if (aux::is_core_color_code(c)) { + c++; + gl::color(*core_color[ (size_t)(*c - 'A')]); + } else { + draw(x, y, *c); + x += text_fontwidth; + } c++; - x += text_fontwidth; } } -void Text::draw(float x, float y, std::stringstream & textstream) +void Text::draw(float x, float y, std::stringstream & textstream) { char line[MAXCMDSIZE]; while (textstream.getline(line, MAXCMDSIZE-1)) { diff --git a/src/render/text.h b/src/render/text.h index 47d88fd..5cf18ea 100644 --- a/src/render/text.h +++ b/src/render/text.h @@ -1,7 +1,7 @@ /* render/text.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_RENDER_TEXT_H__ @@ -10,10 +10,19 @@ #include <string> #include <sstream> -namespace render { +#include "math/color.h" -class Text { +namespace render +{ + +class Text +{ public: + + static void init(); + + static void shutdown(); + /// draw a text string static void draw(float x, float y, const std::string & text); @@ -31,6 +40,9 @@ public: /// set the font static void setfont(const char *texture, float width, float height); + + /// set the color + static void setcolor(const char color); /// current font width static inline float fontwidth() { return text_fontwidth; } @@ -38,6 +50,11 @@ public: /// current font height static inline float fontheight() { return text_fontheight; } + enum Color {Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7}; + + static math::Color * base_color[10]; + static math::Color * core_color[26]; + private: static float text_fontwidth; static float text_fontheight; diff --git a/src/render/textures.cc b/src/render/textures.cc index 8dac3a3..cfd627c 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -1,7 +1,7 @@ /* render/textures.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ @@ -13,7 +13,8 @@ #include "sys/sys.h" #include "core/application.h" -namespace render { +namespace render +{ std::map<std::string, size_t> Textures::registry; size_t Textures::index = 0; @@ -22,7 +23,7 @@ GLuint Textures::textures[MAXTEXTURES]; void Textures::init() { clear(); - con_print << "Loading textures..." << std::endl; + con_print << "^BLoading textures..." << std::endl; // "no texture" bitmap load("textures/common/notex"); @@ -44,7 +45,7 @@ void Textures::init() // crosshairs load("bitmaps/crosshair"); - + // light flares load("bitmaps/fx/flare00"); load("bitmaps/fx/flare01"); @@ -72,7 +73,7 @@ size_t Textures::load(std::string name, bool filter) if (it != registry.end()) return (*it).second; - // try the tga version + // try the tga version std::string filename(name); filename.append(".tga"); Image *image = TGA::load(filename.c_str()); @@ -101,7 +102,7 @@ size_t Textures::load(std::string name, bool filter) texture_type = GL_RGB; gluBuild2DMipmaps(GL_TEXTURE_2D, image->channels(), - image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data()); + image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data()); set_filter(filter); @@ -153,10 +154,10 @@ void Textures::set_filter(bool filter) { if (filter) { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - } + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } } +} diff --git a/src/render/textures.h b/src/render/textures.h index 12873ef..43e312d 100644 --- a/src/render/textures.h +++ b/src/render/textures.h @@ -1,7 +1,7 @@ /* render/textures.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_RENDER_TEXTURES_H__ @@ -12,11 +12,12 @@ #include "render/gl.h" -namespace render { +namespace render +{ const size_t MAXTEXTURES = 256; -/// Texture managment +/// Texture managment class Textures { public: @@ -27,12 +28,12 @@ public: static void shutdown(); /// Load a texture - /** Returns 0 on failure, and the texture index on success + /** Returns 0 on failure, and the texture index on success */ static size_t load(std::string name, bool filter = true); /// bind a texture for OpenGL usage - /** Returns 0 on failure, and the texture index on success + /** Returns 0 on failure, and the texture index on success */ static size_t bind(std::string name, bool filter = true); |