From: Ingo Ruhnke Date: Sun, 17 Aug 2014 18:38:27 +0000 (+0200) Subject: Added m_ prefixes to Console X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=289cdccf579ca0768bdd842b92338e0af8a1f06a;p=supertux.git Added m_ prefixes to Console --- diff --git a/src/supertux/console.cpp b/src/supertux/console.cpp index 86863903b..3a5f148d6 100644 --- a/src/supertux/console.cpp +++ b/src/supertux/console.cpp @@ -29,42 +29,32 @@ static const float FADE_SPEED = 1; Console::Console() : - history(), - history_position(history.end()), - lines(), - background(), - background2(), - vm(NULL), - vm_object(), - backgroundOffset(0), - height(0), - alpha(1.0), - offset(0), - focused(false), - font(), - fontheight(), - stayOpen(0) + m_history(), + m_history_position(m_history.end()), + m_lines(), + m_background(Surface::create("images/engine/console.png")), + m_background2(Surface::create("images/engine/console2.png")), + m_vm(NULL), + m_vm_object(), + m_backgroundOffset(0), + m_height(0), + m_alpha(1.0), + m_offset(0), + m_focused(false), + m_font(new Font(Font::FIXED, "fonts/andale12.stf", 1)), + m_stayOpen(0) { - fontheight = 8; } Console::~Console() { - if(vm != NULL) { - sq_release(scripting::global_vm, &vm_object); + if (m_vm != NULL) + { + sq_release(scripting::global_vm, &m_vm_object); } } void -Console::init_graphics() -{ - font.reset(new Font(Font::FIXED,"fonts/andale12.stf",1)); - fontheight = font->get_height(); - background = Surface::create("images/engine/console.png"); - background2 = Surface::create("images/engine/console2.png"); -} - -void Console::flush(ConsoleStreamBuffer* buffer) { if (buffer == &outputBuffer) { @@ -80,18 +70,18 @@ Console::flush(ConsoleStreamBuffer* buffer) void Console::ready_vm() { - if(vm == NULL) { - vm = scripting::global_vm; - HSQUIRRELVM new_vm = sq_newthread(vm, 16); + if(m_vm == NULL) { + m_vm = scripting::global_vm; + HSQUIRRELVM new_vm = sq_newthread(m_vm, 16); if(new_vm == NULL) - throw scripting::SquirrelError(vm, "Couldn't create new VM thread for console"); + throw scripting::SquirrelError(m_vm, "Couldn't create new VM thread for console"); // store reference to thread - sq_resetobject(&vm_object); - if(SQ_FAILED(sq_getstackobj(vm, -1, &vm_object))) - throw scripting::SquirrelError(vm, "Couldn't get vm object for console"); - sq_addref(vm, &vm_object); - sq_pop(vm, 1); + sq_resetobject(&m_vm_object); + if(SQ_FAILED(sq_getstackobj(m_vm, -1, &m_vm_object))) + throw scripting::SquirrelError(m_vm, "Couldn't get vm object for console"); + sq_addref(m_vm, &m_vm_object); + sq_pop(m_vm, 1); // create new roottable for thread sq_newtable(new_vm); @@ -101,12 +91,12 @@ Console::ready_vm() sq_setroottable(new_vm); - vm = new_vm; + m_vm = new_vm; try { std::string filename = "scripts/console.nut"; IFileStream stream(filename); - scripting::compile_and_run(vm, stream, filename); + scripting::compile_and_run(m_vm, stream, filename); } catch(std::exception& e) { log_warning << "Couldn't load console.nut: " << e.what() << std::endl; } @@ -120,26 +110,26 @@ Console::execute_script(const std::string& command) ready_vm(); - SQInteger oldtop = sq_gettop(vm); + SQInteger oldtop = sq_gettop(m_vm); try { - if(SQ_FAILED(sq_compilebuffer(vm, command.c_str(), command.length(), + if(SQ_FAILED(sq_compilebuffer(m_vm, command.c_str(), command.length(), "", SQTrue))) - throw SquirrelError(vm, "Couldn't compile command"); + throw SquirrelError(m_vm, "Couldn't compile command"); - sq_pushroottable(vm); - if(SQ_FAILED(sq_call(vm, 1, SQTrue, SQTrue))) - throw SquirrelError(vm, "Problem while executing command"); + sq_pushroottable(m_vm); + if(SQ_FAILED(sq_call(m_vm, 1, SQTrue, SQTrue))) + throw SquirrelError(m_vm, "Problem while executing command"); - if(sq_gettype(vm, -1) != OT_NULL) - addLines(squirrel2string(vm, -1)); + if(sq_gettype(m_vm, -1) != OT_NULL) + addLines(squirrel2string(m_vm, -1)); } catch(std::exception& e) { addLines(e.what()); } - SQInteger newtop = sq_gettop(vm); + SQInteger newtop = sq_gettop(m_vm); if(newtop < oldtop) { log_fatal << "Script destroyed squirrel stack..." << std::endl; } else { - sq_settop(vm, oldtop); + sq_settop(m_vm, oldtop); } } @@ -179,26 +169,26 @@ Console::enter() void Console::scroll(int numLines) { - offset += numLines; - if (offset > 0) offset = 0; + m_offset += numLines; + if (m_offset > 0) m_offset = 0; } void Console::show_history(int offset_) { - while ((offset_ > 0) && (history_position != history.end())) { - history_position++; + while ((offset_ > 0) && (m_history_position != m_history.end())) { + m_history_position++; offset_--; } - while ((offset_ < 0) && (history_position != history.begin())) { - history_position--; + while ((offset_ < 0) && (m_history_position != m_history.begin())) { + m_history_position--; offset_++; } - if (history_position == history.end()) { + if (m_history_position == m_history.end()) { inputBuffer = ""; inputBufferPosition = 0; } else { - inputBuffer = *history_position; + inputBuffer = *m_history_position; inputBufferPosition = inputBuffer.length(); } } @@ -296,19 +286,19 @@ Console::autocomplete() ready_vm(); // append all keys of the current root table to list - sq_pushroottable(vm); // push root table + sq_pushroottable(m_vm); // push root table while(true) { // check all keys (and their children) for matches - sq_insert_commands(cmds, vm, "", prefix); + sq_insert_commands(cmds, m_vm, "", prefix); // cycle through parent(delegate) table - SQInteger oldtop = sq_gettop(vm); - if(SQ_FAILED(sq_getdelegate(vm, -1)) || oldtop == sq_gettop(vm)) { + SQInteger oldtop = sq_gettop(m_vm); + if(SQ_FAILED(sq_getdelegate(m_vm, -1)) || oldtop == sq_gettop(m_vm)) { break; } - sq_remove(vm, -2); // remove old table + sq_remove(m_vm, -2); // remove old table } - sq_pop(vm, 1); // remove table + sq_pop(m_vm, 1); // remove table // depending on number of hits, show matches or autocomplete if (cmds.empty()) addLines("No known command starts with \""+prefix+"\""); @@ -353,24 +343,24 @@ Console::addLine(std::string s) std::string overflow; unsigned int line_count = 0; do { - lines.push_front(Font::wrap_to_chars(s, 99, &overflow)); + m_lines.push_front(Font::wrap_to_chars(s, 99, &overflow)); line_count++; s = overflow; } while (s.length() > 0); // trim scrollback buffer - while (lines.size() >= 1000) - lines.pop_back(); + while (m_lines.size() >= 1000) + m_lines.pop_back(); // increase console height if necessary - if ((stayOpen > 0) && (height < 64)) { - if(height < 4) - height = 4; - height += fontheight * line_count; + if ((m_stayOpen > 0) && (m_height < 64)) { + if(m_height < 4) + m_height = 4; + m_height += m_font->get_height() * line_count; } // reset console to full opacity - alpha = 1.0; + m_alpha = 1.0; } void @@ -380,8 +370,8 @@ Console::parse(std::string s) if (s.length() == 0) return; // add line to history - history.push_back(s); - history_position = history.end(); + m_history.push_back(s); + m_history_position = m_history.end(); // split line into list of args std::vector args; @@ -419,7 +409,7 @@ Console::consoleCommand(std::string /*command*/, std::vector /*argu bool Console::hasFocus() { - return focused; + return m_focused; } void @@ -428,25 +418,25 @@ Console::show() if(!g_config->console_enabled) return; - focused = true; - height = 256; - alpha = 1.0; + m_focused = true; + m_height = 256; + m_alpha = 1.0; // SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // Useless in SDL2 : if you want to disable repeat, then you need to check if the key was repeated and ignore it. } void Console::open() { - if(stayOpen < 2) - stayOpen += 1.5; + if(m_stayOpen < 2) + m_stayOpen += 1.5; } void Console::hide() { - focused = false; - height = 0; - stayOpen = 0; + m_focused = false; + m_height = 0; + m_stayOpen = 0; // clear input buffer inputBuffer = ""; @@ -468,15 +458,15 @@ Console::toggle() void Console::update(float elapsed_time) { - if(stayOpen > 0) { - stayOpen -= elapsed_time; - if(stayOpen < 0) - stayOpen = 0; - } else if(!focused && height > 0) { - alpha -= elapsed_time * FADE_SPEED; - if(alpha < 0) { - alpha = 0; - height = 0; + if(m_stayOpen > 0) { + m_stayOpen -= elapsed_time; + if(m_stayOpen < 0) + m_stayOpen = 0; + } else if(!m_focused && m_height > 0) { + m_alpha -= elapsed_time * FADE_SPEED; + if(m_alpha < 0) { + m_alpha = 0; + m_height = 0; } } } @@ -484,40 +474,51 @@ Console::update(float elapsed_time) void Console::draw(DrawingContext& context) { - if (height == 0) + if (m_height == 0) return; int layer = LAYER_GUI + 1; context.push_transform(); - context.set_alpha(alpha); - context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer); - context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer); - for (int x = (SCREEN_WIDTH/2 - background->get_width()/2 - (static_cast(ceilf((float)SCREEN_WIDTH / (float)background->get_width()) - 1) * background->get_width())); x < SCREEN_WIDTH; x+=background->get_width()) { - context.draw_surface(background, Vector(x, height - background->get_height()), layer); + context.set_alpha(m_alpha); + context.draw_surface(m_background2, + Vector(SCREEN_WIDTH/2 - m_background->get_width()/2 - m_background->get_width() + m_backgroundOffset, + m_height - m_background->get_height()), + layer); + context.draw_surface(m_background2, + Vector(SCREEN_WIDTH/2 - m_background->get_width()/2 + m_backgroundOffset, + m_height - m_background->get_height()), + layer); + for (int x = (SCREEN_WIDTH/2 - m_background->get_width()/2 + - (static_cast(ceilf((float)SCREEN_WIDTH / + (float)m_background->get_width()) - 1) * m_background->get_width())); + x < SCREEN_WIDTH; + x += m_background->get_width()) + { + context.draw_surface(m_background, Vector(x, m_height - m_background->get_height()), layer); } - backgroundOffset+=10; - if (backgroundOffset > (int)background->get_width()) backgroundOffset -= (int)background->get_width(); + m_backgroundOffset+=10; + if (m_backgroundOffset > (int)m_background->get_width()) m_backgroundOffset -= (int)m_background->get_width(); int lineNo = 0; - if (focused) { + if (m_focused) { lineNo++; - float py = height-4-1 * font->get_height(); - context.draw_text(font, "> "+inputBuffer, Vector(4, py), ALIGN_LEFT, layer); + float py = m_height-4-1 * m_font->get_height(); + context.draw_text(m_font, "> "+inputBuffer, Vector(4, py), ALIGN_LEFT, layer); if (SDL_GetTicks() % 1000 < 750) { int cursor_px = 2 + inputBufferPosition; - context.draw_text(font, "_", Vector(4 + (cursor_px * font->get_text_width("X")), py), ALIGN_LEFT, layer); + context.draw_text(m_font, "_", Vector(4 + (cursor_px * m_font->get_text_width("X")), py), ALIGN_LEFT, layer); } } - int skipLines = -offset; - for (std::list::iterator i = lines.begin(); i != lines.end(); i++) { + int skipLines = -m_offset; + for (std::list::iterator i = m_lines.begin(); i != m_lines.end(); i++) { if (skipLines-- > 0) continue; lineNo++; - float py = height - 4 - lineNo*font->get_height(); - if (py < -font->get_height()) break; - context.draw_text(font, *i, Vector(4, py), ALIGN_LEFT, layer); + float py = m_height - 4 - lineNo * m_font->get_height(); + if (py < -m_font->get_height()) break; + context.draw_text(m_font, *i, Vector(4, py), ALIGN_LEFT, layer); } context.pop_transform(); } diff --git a/src/supertux/console.hpp b/src/supertux/console.hpp index e8599cac2..27f774d6d 100644 --- a/src/supertux/console.hpp +++ b/src/supertux/console.hpp @@ -40,8 +40,6 @@ public: static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */ - void init_graphics(); - void input(char c); /**< add character to inputBuffer */ void backspace(); /**< delete character left of inputBufferPosition */ void eraseChar(); /**< delete character at inputBufferPosition */ @@ -62,25 +60,24 @@ public: bool hasFocus(); /**< true if characters should be sent to the console instead of their normal target */ private: - std::list history; /**< command history. New lines get added to back. */ - std::list::iterator history_position; /**< item of command history that is currently displayed */ - std::list lines; /**< backbuffer of lines sent to the console. New lines get added to front. */ + std::list m_history; /**< command history. New lines get added to back. */ + std::list::iterator m_history_position; /**< item of command history that is currently displayed */ + std::list m_lines; /**< backbuffer of lines sent to the console. New lines get added to front. */ - SurfacePtr background; /**< console background image */ - SurfacePtr background2; /**< second, moving console background image */ + SurfacePtr m_background; /**< console background image */ + SurfacePtr m_background2; /**< second, moving console background image */ - HSQUIRRELVM vm; /**< squirrel thread for the console (with custom roottable) */ - HSQOBJECT vm_object; + HSQUIRRELVM m_vm; /**< squirrel thread for the console (with custom roottable) */ + HSQOBJECT m_vm_object; - int backgroundOffset; /**< current offset of scrolling background image */ - float height; /**< height of the console in px */ - float alpha; - int offset; /**< decrease to scroll text up */ - bool focused; /**< true if console has input focus */ - FontPtr font; - float fontheight; /**< height of the font (this is a separate var, because the font could not be initialized yet but is needed in the addLine message */ + int m_backgroundOffset; /**< current offset of scrolling background image */ + float m_height; /**< height of the console in px */ + float m_alpha; + int m_offset; /**< decrease to scroll text up */ + bool m_focused; /**< true if console has input focus */ + FontPtr m_font; - float stayOpen; + float m_stayOpen; static int inputBufferPosition; /**< position in inputBuffer before which to append new characters */ static std::string inputBuffer; /**< string used for keyboard input */ diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 1be3a0a9b..9e82c3d6e 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -309,7 +309,7 @@ Main::run(int argc, char** argv) } init_sdl(); - Console console; + //ConsoleBuffer console_buffer; timelog("controller"); InputManager input_manager; @@ -327,7 +327,7 @@ Main::run(int argc, char** argv) sound_manager.enable_sound(g_config->sound_enabled); sound_manager.enable_music(g_config->music_enabled); - Console::current()->init_graphics(); + Console console; timelog("scripting"); scripting::init_squirrel(g_config->enable_script_debugger);