aboutsummaryrefslogtreecommitdiff
path: root/src/genericobject.cpp
Commit message (Collapse)AuthorAge
* Add Lua methods 'set_rotation()' and 'get_rotation()' (#7395)CoderForTheBetter2018-11-28
| | | | * Adds Lua methods 'set_rotation()' and 'get_rotation'. Also changed some method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
* Fix animation frame_speed and blend loosing precision due to incorrec… (#6357)sapier2017-09-01
| | | | | * Fix animation frame_speed and blend loosing precision due to incorrect data type Add lua function set_animation_frame_speed to update the frame speed without resetting the animation to start
* Modernize various filesLoic Blot2017-08-18
| | | | | | | | | * range-based for loops * emplace_back instead of push_back * code style * C++ headers instead of C headers * Default operators * empty stl function
* Fix various copy instead of const ref reported by cppcheck (part 3) (#5616)Loïc Blot2017-04-20
| | | | * Also remove 2 non declared but defined functions * Make some functions around const ref changes const
* Sneak: Add option for old move codeparamat2017-04-17
| | | | | | Temporary option for the old move code for specific old sneak behaviour. Enabled by setting the added 'new move' physics override to false. By default 'new move' is true.
* Prevent attached models from disappearing during parent reload (#4128)Foghrye42016-10-08
|
* Change i++ to ++iDavid Jones2015-08-25
|
* Fix some issues with animations, and allow non-looped animations to be definedMirceaKitsune2015-06-22
|
* Generic CAO cleanups and renames for clarificationest312015-06-20
| | | | | | | | * Use enum for GENERIC_CMD_* * Rename m_attachements to attachement_parent_ids (public member and clearer name) * Rename GENERIC_CMD_SET_ATTACHMENT to GENERIC_CMD_ATTACH_TO * USHRT_MAX + 1 buffer sizes to prevent overflows as @kahrl suggested * Remove unneccessary m_id from GenericCAO (shadowing protected superclass member for no reason) as @kahrl suggested
* Generalize core.get/set_nametag_color into core.get/set_nametag_attributesTeTpaAka2015-05-15
|
* Add get and set functions for the nametag colorTeTpaAka2015-05-15
|
* Add sneak and sneak_glitch to set_physics_override()PilzAdam2013-12-03
|
* Allow modifying movement speed, jump height and gravity per-player via the ↵MirceaKitsune2013-04-05
| | | | Lua API.
* Update Copyright YearsSfan52013-02-24
|
* Change Minetest-c55 to MinetestPilzAdam2013-02-24
|
* Fix Taoki's messed up generic object command idsPerttu Ahola2012-11-29
|
* A bunch of fixesMirceaKitsune2012-11-25
| | | | | | | | | | | | No longer hide players who are dead. With models, a death animation should be used instead Some changes requested by celeron55 Rename a lot of things in the code, and use better lua api function names Minor code corrections Bump protocol version up, since the models / animations / attachments code creates new client<->server messages
* Send animations, bone overrides and attachments in entity initialization. ↵MirceaKitsune2012-11-25
| | | | | | | | | | | | | | | | | | | | Clients no longer have to be near an object when an animation or attachment is set to see the changes, and newly connected clients (or a client that simply renders the object for the first time) will get all of those settings. Therefore, the lua script no longer needs to run every X seconds either, just once per entity. Finish fixing the material color code. But it won't work until MineTest has dynamic lighting... another day another feature. Extra checks for the bone positioning / rotation code Many checks and consistency improvements to the client attachment code Make a separate function for checking if a client object is attached. A more in-depth change will be needed here to fix reading of invalid pointers Use a different method of fetching the parent. Fixes the mass segmentation faults when rendering an attachment (some still happen though) Major change to how attachments are handled. Fix the last segmentaton fault, which was due to the parent becoming invalid while being refreshed / removed which would bause the child to remain attached to nothing. Parents remove their children when being deleted themselves and add them back when re-added. Attachments are stored inside a 2D a vector which easily allows both a child to find their parent and a parent to find its children. Remove attachment list entry when an object is being permanently removed. Also avoid duplicate entries in this list when re-attaching the same object The "big code comments" can now go away. Client attachments almost work properly, and I know what else needs to be done
* Complete the attachment framework.MirceaKitsune2012-11-25
| | | | | | | | | | | | The child ID can now be checked against the parent ID in content_cao.cpp so the parent can be detected. Actual attachment code to come Divide attachment system between server attachments and client attachments, neither coded right now. As explained in the code comment: // Attachments need to be handled on both the server and client. // If we attach only on the server, models (which are client-side) // can't be read so we don't know the origin and orientation of bones. // If we attach only on the client, the real position of attachments is // not updated and you can't click them for example.
* Framework for the attachment system, new object property which allows ↵MirceaKitsune2012-11-25
| | | | | | | | | | | | | | changing the color and alpha of mesh materials New object property which allows changing the color and alpha of mesh materials. Due to the current lighting systems it doesn't work yet, but the full implementation is there Framework for the attachment system, with no actual functionality yet Send bone and player object to the setAttachment function in content_sao.cpp, but we need a way to translate it there and send it to the client I will also want position and rotation offsets to be possible to apply to attachments Network object ID from server to client. This will be used to identify the parent client-side and know what to attach to
* Get the new animation framework properly workingMirceaKitsune2012-11-25
| | | | | | Store start and end frames as v2f Also move bone animations to their own function instead of object properties
* Joint positioning and rotation code, and fix a problem related to their lua APIMirceaKitsune2012-11-25
| | | | Attempt to move the animation system to a more correct implementation, rather than using object properties. Incomplete and breaks functionality
* Properly and efficiently use split utility headersPerttu Ahola2012-06-17
|
* Switch the license to be LGPLv2/later, with small parts still remaining as ↵Perttu Ahola2012-06-05
| | | | GPLv2/later, by agreement of major contributors
* Fix dropped nodeitem visualsPerttu Ahola2012-04-04
|
* ObjectPropertiesPerttu Ahola2012-03-30
|
* Use GenericCAO in place of LuaEntityCAO and PlayerCAOPerttu Ahola2012-03-29
opt">(25); getmaxyx(stdscr, m_rows, m_cols); m_can_draw_text = reformat_backend(&m_chat_backend, m_rows, m_cols); } void TerminalChatConsole::deInitOfCurses() { endwin(); } void *TerminalChatConsole::run() { BEGIN_DEBUG_EXCEPTION_HANDLER std::cout << "========================" << std::endl; std::cout << "Begin log output over terminal" << " (no stdout/stderr backlog during that)" << std::endl; // Make the loggers to stdout/stderr shut up. // Go over our own loggers instead. LogLevelMask err_mask = g_logger.removeOutput(&stderr_output); LogLevelMask out_mask = g_logger.removeOutput(&stdout_output); g_logger.addOutput(&m_log_output); // Inform the server of our nick m_chat_interface->command_queue.push_back( new ChatEventNick(CET_NICK_ADD, m_nick)); { // Ensures that curses is deinitialized even on an exception being thrown CursesInitHelper helper(this); while (!stopRequested()) { int ch = getch(); if (stopRequested()) break; step(ch); } } if (m_kill_requested) *m_kill_requested = true; g_logger.removeOutput(&m_log_output); g_logger.addOutputMasked(&stderr_output, err_mask); g_logger.addOutputMasked(&stdout_output, out_mask); std::cout << "End log output over terminal" << " (no stdout/stderr backlog during that)" << std::endl; std::cout << "========================" << std::endl; END_DEBUG_EXCEPTION_HANDLER return NULL; } void TerminalChatConsole::typeChatMessage(const std::wstring &msg) { // Discard empty line if (msg.empty()) return; // Send to server m_chat_interface->command_queue.push_back( new ChatEventChat(m_nick, msg)); // Print if its a command (gets eaten by server otherwise) if (msg[0] == L'/') { m_chat_backend.addMessage(L"", (std::wstring)L"Issued command: " + msg); } } void TerminalChatConsole::handleInput(int ch, bool &complete_redraw_needed) { ChatPrompt &prompt = m_chat_backend.getPrompt(); // Helpful if you want to collect key codes that aren't documented /*if (ch != ERR) { m_chat_backend.addMessage(L"", (std::wstring)L"Pressed key " + utf8_to_wide( std::string(keyname(ch)) + " (code " + itos(ch) + ")")); complete_redraw_needed = true; }//*/ // All the key codes below are compatible to xterm // Only add new ones if you have tried them there, // to ensure compatibility with not just xterm but the wide // range of terminals that are compatible to xterm. switch (ch) { case ERR: // no input break; case 27: // ESC // Toggle ESC mode m_esc_mode = !m_esc_mode; break; case KEY_PPAGE: m_chat_backend.scrollPageUp(); complete_redraw_needed = true; break; case KEY_NPAGE: m_chat_backend.scrollPageDown(); complete_redraw_needed = true; break; case KEY_ENTER: case '\r': case '\n': { prompt.addToHistory(prompt.getLine()); typeChatMessage(prompt.replace(L"")); break; } case KEY_UP: prompt.historyPrev(); break; case KEY_DOWN: prompt.historyNext(); break; case KEY_LEFT: // Left pressed // move character to the left prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_CHARACTER); break; case 545: // Ctrl-Left pressed // move word to the left prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_WORD); break; case KEY_RIGHT: // Right pressed // move character to the right prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_CHARACTER); break; case 560: // Ctrl-Right pressed // move word to the right prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_WORD); break; case KEY_HOME: // Home pressed // move to beginning of line prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_LINE); break; case KEY_END: // End pressed // move to end of line prompt.cursorOperation( ChatPrompt::CURSOROP_MOVE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_LINE); break; case KEY_BACKSPACE: case '\b': case 127: // Backspace pressed // delete character to the left prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_CHARACTER); break; case KEY_DC: // Delete pressed // delete character to the right prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_CHARACTER); break; case 519: // Ctrl-Delete pressed // delete word to the right prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_WORD); break; case 21: // Ctrl-U pressed // kill line to left end prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_LEFT, ChatPrompt::CURSOROP_SCOPE_LINE); break; case 11: // Ctrl-K pressed // kill line to right end prompt.cursorOperation( ChatPrompt::CURSOROP_DELETE, ChatPrompt::CURSOROP_DIR_RIGHT, ChatPrompt::CURSOROP_SCOPE_LINE); break; case KEY_TAB: // Tab pressed // Nick completion prompt.nickCompletion(m_nicks, false); break; default: // Add character to the prompt, // assuming UTF-8. if (IS_UTF8_MULTB_START(ch)) { m_pending_utf8_bytes.append(1, (char)ch); m_utf8_bytes_to_wait += UTF8_MULTB_START_LEN(ch) - 1; } else if (m_utf8_bytes_to_wait != 0) { m_pending_utf8_bytes.append(1, (char)ch); m_utf8_bytes_to_wait--; if (m_utf8_bytes_to_wait == 0) { std::wstring w = utf8_to_wide(m_pending_utf8_bytes); m_pending_utf8_bytes = ""; // hopefully only one char in the wstring... for (size_t i = 0; i < w.size(); i++) { prompt.input(w.c_str()[i]); } } } else if (IS_ASCII_PRINTABLE_CHAR(ch)) { prompt.input(ch); } else { // Silently ignore characters we don't handle //warningstream << "Pressed invalid character '" // << keyname(ch) << "' (code " << itos(ch) << ")" << std::endl; } break; } } void TerminalChatConsole::step(int ch) { bool complete_redraw_needed = false; // empty queues while (!m_chat_interface->outgoing_queue.empty()) { ChatEvent *evt = m_chat_interface->outgoing_queue.pop_frontNoEx(); switch (evt->type) { case CET_NICK_REMOVE: m_nicks.remove(((ChatEventNick *)evt)->nick); break; case CET_NICK_ADD: m_nicks.push_back(((ChatEventNick *)evt)->nick); break; case CET_CHAT: complete_redraw_needed = true; // This is only used for direct replies from commands // or for lua's print() functionality m_chat_backend.addMessage(L"", ((ChatEventChat *)evt)->evt_msg); break; case CET_TIME_INFO: ChatEventTimeInfo *tevt = (ChatEventTimeInfo *)evt; m_game_time = tevt->game_time; m_time_of_day = tevt->time; }; delete evt; } while (!m_log_output.queue.empty()) { complete_redraw_needed = true; std::pair<LogLevel, std::string> p = m_log_output.queue.pop_frontNoEx(); if (p.first > m_log_level) continue; std::wstring error_message = utf8_to_wide(Logger::getLevelLabel(p.first)); if (!g_settings->getBool("disable_escape_sequences")) { error_message = std::wstring(L"\x1b(c@red)").append(error_message) .append(L"\x1b(c@white)"); } m_chat_backend.addMessage(error_message, utf8_to_wide(p.second)); } // handle input if (!m_esc_mode) { handleInput(ch, complete_redraw_needed); } else { switch (ch) { case ERR: // no input break; case 27: // ESC // Toggle ESC mode m_esc_mode = !m_esc_mode; break; case 'L': m_log_level--; m_log_level = MYMAX(m_log_level, LL_NONE + 1); // LL_NONE isn't accessible break; case 'l': m_log_level++; m_log_level = MYMIN(m_log_level, LL_MAX - 1); break; } } // was there a resize? int xn, yn; getmaxyx(stdscr, yn, xn); if (xn != m_cols || yn != m_rows) { m_cols = xn; m_rows = yn; m_can_draw_text = reformat_backend(&m_chat_backend, m_rows, m_cols); complete_redraw_needed = true; } // draw title move(0, 0); clrtoeol(); addstr(PROJECT_NAME_C); addstr(" "); addstr(g_version_hash); u32 minutes = m_time_of_day % 1000; u32 hours = m_time_of_day / 1000; minutes = (float)minutes / 1000 * 60; if (m_game_time) printw(" | Game %d Time of day %02d:%02d ", m_game_time, hours, minutes); // draw text if (complete_redraw_needed && m_can_draw_text) draw_text(); // draw prompt if (!m_esc_mode) { // normal prompt ChatPrompt& prompt = m_chat_backend.getPrompt(); std::string prompt_text = wide_to_utf8(prompt.getVisiblePortion()); move(m_rows - 1, 0); clrtoeol(); addstr(prompt_text.c_str()); // Draw cursor s32 cursor_pos = prompt.getVisibleCursorPosition(); if (cursor_pos >= 0) { move(m_rows - 1, cursor_pos); } } else { // esc prompt move(m_rows - 1, 0); clrtoeol(); printw("[ESC] Toggle ESC mode |" " [CTRL+C] Shut down |" " (L) in-, (l) decrease loglevel %s", Logger::getLevelLabel((LogLevel) m_log_level).c_str()); } refresh(); } void TerminalChatConsole::draw_text() { ChatBuffer& buf = m_chat_backend.getConsoleBuffer(); for (u32 row = 0; row < buf.getRows(); row++) { move_for_backend(row, 0); clrtoeol(); const ChatFormattedLine& line = buf.getFormattedLine(row); if (line.fragments.empty()) continue; for (const ChatFormattedFragment &fragment : line.fragments) { addstr(wide_to_utf8(fragment.text.getString()).c_str()); } } } void TerminalChatConsole::stopAndWaitforThread() { clearKillStatus(); stop(); wait(); } #endif