The `CGameControllerDDRace::HandleCharacterTiles` function can kill the tee if the conditions for starting the race are not satisfied when touching a start tile. In this case, no further tiles should be handled in the `CCharacter::HandleTiles` function, else the effects of those tiles being handled may incorrectly be applied after the tee has respawned.
The ddnet buttons kill and pause do not fit in anymore if there is also
a join red/blue button.
This commit fixes that by hiding the buttons if
there is not enough space anymore.
Related prior work https://github.com/ddnet/ddnet/pull/2720
We assume that `char` is `signed` in various places in the code. In particular, the `Str.StrToInts` test will fail when `char` is not `signed` and names containing special characters will be displayed incorrectly on servers.
Therefore, the compiler flag `-fsigned-char` is set unconditionally instead of only for ARM and ARM64, as we expect `char` to be `signed` on all architectures.
A static assertion is added to ensure at compile time that `char` is `signed` independently from the flag added in `CMakeLists.txt`.
This is necessary at least for ARM, ARM64, PPC, PPC64, and PPC64LE. According to some sources, `char` may also be `unsigned` by default when compiling for Android, although this could not be confirmed with the current Android NDK using Clang.
For the PowerPC architectures, Compiler Explorer can be used to confirm that `char` is not `signed` by default by checking whether the static assertion compiles (see https://godbolt.org/z/9rn5Mrf59) and that the assembly is different with the `-fsigned-char` flag (see https://godbolt.org/z/138zTj3Wa).
Closes#8386.
Fix button logic being stuck when holding mouse button on UI elements with button logic in the menus/editor, switching between menus and editor with Ctrl+Shift+E, then using a UI element with button logic in the editor/menus and switching back.
Fix value selector text mode of color picker popups being deactivated when switching between menus and editor while the color picker popup is open in both.
Only update progress spinners once per frame in `CUi::Update` to ensure consistent rotation speed. Progress spinners in menus and editor now rotate independently.
In general, all `static` non-`const` variables in `CUi` are replaced with member variables, as the `static` variables are shared between the two `CUi` instances of the menus and the editor, causing the above issues.
The percentage of received console commands was not being shown with the progress spinner because the variable `ProgressProps` was not passed to the `RenderProgressSpinner` function.
Replace the last remaining usage of the `CUi::MouseButtonReleased` function with `!MouseButton(...)`. The `pMouseSelection->m_Selecting` flag is only set to `true` when the mouse button is already pressed down, so the additional check of `MouseButtonReleased` is unnecessary in this case. In general, this function is an anti-pattern in our UI, as only checking for the mouse button to be released does not guarantee that the mouse was also pressed down over the respective UI element. The `DoButtonLogic` function or similar code should be used instead of only handling the press or release of a mouse button.
Make value selector behavior consistent with the generic button logic. Consistently check for completed mouse clicks on the value selector UI element instead of handling some mouse down and mouse up events separately. Fix text mode being activated when moving the mouse over value selectors with held down mouse button. Fix text mode being deactivated immediately when the mouse leaves text area while holding down the mouse button, which is inconvenient when selecting text. Remove unnecessary usage of `CUi::MouseButtonReleased` function.
Support double-clicking value selectors to enter text edit mode in addition to right-clicking. This feels more intuitive to use and also makes it usable without a second mouse button.
Select all text when entering text mode also in the editor, which was previously only a feature in the menus.
Fix value selector edit state being `EDITING` by default instead of `NONE` in the editor and fix maps being marked as modified immediately when a value selector text input is activated. The map will now be marked as modified only when the editing operation is completed, which should be synchonized with the undo history action being added.
Use the `CUi::ConsumeHotkey` function instead of checking the enter keys manually.
Remove unnecessary and unused `CUi::m_ValueSelectorTextMode` variable and its accessors as well as the equivalent `s_TextMode` variable in the editor. This separate flag is unnecessary as we can use the existing `s_pLastTextId` variable instead.
The `.demo` extension is supposed to be removed from the target filename when slicing demos, but anything after the last dot was being removed instead, e.g. `test.abc.def` was incorrectly replaced with `test.abc`.
Remove separate handling of UI mouse position and delta in the editor and use the UI directly for this like in the gameclient. Raw cursor movements are redirected to the UI with the `CUi::OnCursorMove` function. The editor separately updates its world positions and delta after the mouse position was changed. The mouse world position for the editor is passed to the UI with the `CUi::Update` funtion as before, whereas the world position is unused in the gameclient.
Use `vec2`s for mouse positions and deltas instead of two separate floats.
Add `IInput::ConsumeEvents` function accepting a consumer `std::function` to replace the duplicate usage of the `IInput::NumEvents`, `IInput::GetEvent` and `IInput::IsEventValid` functions.
Use an `std::vector` to store the current input events to support any number of input events per client update instead of at most 32.
Use full `uint32_t` range for input counter instead of only using the range 0..0xFFFF. If the range is artificially reduced, then this can result in inputs being handled multiple times with high refresh rates, so the increased range should add future proofing for extremely fast devices.
Split `CInput::AddEvent` function into `CInput::AddKeyEvent` and `CInput::AddTextEvent` functions for readability and to make it easier to add additional input events (i.e. touch events).
Ensure double-click state is cleared at the end of each frame to prevent the double-click from being stored when no UI element consumes it.
Move member variables from `IInput` interface to `CInput` implementation.
Remove separate `CEditor::DispatchInputEvents` function.
Currently the per tee demos are only stopped when a character dies.
But the Reset() method in the gameworld destroys characters without
killing them.
This allows to do world resets without calling gamecontext shutdown
while sv_player_demo_record is active. Which is nice for round based
game modes.
```C++
void CGameWorld::Reset()
{
// reset all entities
for(auto *pEnt : m_apFirstEntityTypes)
for(; pEnt;)
{
m_pNextTraverseEntity = pEnt->m_pNextTypeEntity;
pEnt->Reset();
pEnt = m_pNextTraverseEntity;
}
RemoveEntities();
GameServer()->m_pController->OnReset();
RemoveEntities();
m_ResetRequested = false;
GameServer()->CreateAllEntities(false);
}
```
With some languages the buffers for the scoreboard recording notification were not large enough when recording all 4 types of demos at the same time.
Reduce duplicate code. Avoid unnecessary, slow `str_format` for concatenation. Use UI functions for drawing the background and text.
Fix crash when reading a translation file that ends unexpectedly after a context line.
Make error messages about malformed translation files more detailed.
Fix incorrect line numbers in the error message because context lines were not counted.
Use `log_error` for error messages.
Ignore language file config variable being set initially in the conchain (i.e. when `GlobalTime` still returns zero) and check whether the value changed before reloading the language.
```
/home/chiller/Desktop/git/ddnet/src/base/system.cpp:1989:10: error: The 1st argument to 'connect' is < 0 but should be >= 0 [clang-analyzer-unix.StdCLibraryFunctions,-warnings-as-errors]
1989 | return connect(sock->ipv4sock, (struct sockaddr *)&addr, sizeof(addr));
| ^
```
Split the user storage location and the data folder in the app specific external storage in the folders `data` and `user` instead of writing the user setting directly to the external storage.
Remove unnecessary storage permissions. The client only accesses files in its own external storage location, hence these permissions are not necessary for Android API 19 and higher, which is always given as we only target API 19 and higher.
Only unpack changed assets when their hash in the integrity index is different instead of unpacking all assets again, so the app starts faster after updates. Avoid unpacking the entire integrity index file unless it changed, by initially reading only the first hash directly from the asset, so the app starts faster when the data is up-to-date.
Add error handling for external storage not being accessible and other I/O errors during unpacking of assets.
Add `android_main.h` header to export the `InitAndroid` function and potentially other functions in the future. The `extern "C"` and `__attribute__((visibility("default")))` attributes seem to be unnecessary, as this function is only called directly from the native code like many other functions without these attributes.
Initialize the Android storage after the loggers, so the log message are printed properly.
Add documentation for the use of `std::exit` on Android, which is used to forcefully terminate the entire process, to ensure that static variables will be initialized correctly when the app is started again after quitting. Returning from the main function is not enough, as this only results in the native thread terminating, but the Java thread will continue. Java does not support unloading libraries once they have been loaded, so all static variables will not have their expected initial values anymore when the app is started again after quitting.
Use `fs_chdir` and `fs_makedir` instead of `chdir` and `mkdir`.
Remove unnecessary `fs_is_dir` check in the `fs_chdir` function. The `SetCurrentDirectoryW` and `chdir` functions would already include such necessary checks anyway.
Assert that `GetCurrentDirectoryW` was successful instead of logging an error message. This function should only potentially fail if the current working directory was changed by another thread between the two calls, which should not happen in our code.
This would make the function `str_from_int` unnecessary, at least
user-facing.
Advantage: User doesn't have to care about `str_from_int`/`str_format`
distinction.
Disadvantage: We're adding some template programming to `system.h`,
potentially slowing all compilation.
Time score will now always be used for any game with the flag `GAMEINFOFLAG_TIMESCORE` set in the `CNetObj_GameInfoEx` object. If the flag is not set, points score is used instead.
Backwards compatibility for old demos, that were recorded without this net object and flag, is removed. For old demos, points score is always assumed now.
Closes#6700.
This reverts commit caa062c88c.
As this decreased FPS and caused the background quad to be rendered twice when using a map background in entities mode.
Always force landscape orientation to be used for the game on Android.
Hide the title bar so it is not shown when starting the game. There is also a bug with SDL currently that leads to the title bar and status bar being shown permanently after minimizing and reopening the app, which is alleviated by hiding the title bar.
Always use black color to clear the window with all graphics backends, instead of using `cl_background_color` or `cl_background_entities_color`, respectively, as the clear color. The respective map background color is rendered using a quad in `CMapLayers` instead, so this should not affect appearance of maps. This does not have any noticeable effect on FPS. Previously, the unused part of the window (when it is resized smaller than 5:4 aspect ratio), was colored using the map background color, whereas now it will be cleared black consistently.
The color parameters of the `IGraphics::Clear` function and of the `SCommand_Clear` command are removed, as we always expect the screen to be cleared black now.
The parameter `ForceClearNow` of the `IGraphics::Clear` function was already unused previously and is also removed.
Interpret fast repeated presses of the back-button (3 times within 1 second) as a quit-event, so the app can be quit cleanly and quickly without using the UI. The client settings are otherwise not saved if the app is closed by minimizing it using the home button and waiting for the OS to kill it or by discarding it in the recent apps view.
Translate the Android back-button to the escape-key, so it can be used to navigate back in menus, open/close the ingame menu, close the editor etc.
Trap the Android back button by setting the `SDL_ANDROID_TRAP_BACK_BUTTON` hint, so it can be handled in our code reliably instead of letting the system handle it.
The graphics backends only support the RGBA format with the `SCommand_Texture_Create` and `SCommand_Texture_Update` commands, so the `TexFormatToOpenGLFormat`, `TextureFormatToVulkanFormat` and `TexFormatToNewOpenGLFormat` functions and the command member variables for the format are unnecessary. The `TexFormatToNewOpenGLFormat` function was unused.
Fix edit boxes, scrollbars, value selectors and the editor sound seekbar being activated by holding the left mouse button from outside the UI element and then hovering it, which is inconsistent with the behavior of the `DoButtonLogic` function.
Use the `DoButtonLogic` function directly for the key reader buttons in the controls settings. Now, the key reader will only be activated when the left click is initiated and completed inside the key reader button. Previously, the key reader would be activated immediately when holding the left mouse button from outside and then hovering the key reader, and the key reader was already activated by the press-event, whereas now it will only be activated by the release event of the left mouse button. The active key reader UI ID is now tracked as a member variable of `CMenusKeyBinder` to avoid using static variables for this purpose.
The scrollregion scrollbar was not being deactivated if the handle is continued to be hovered after releasing it, causing the handle to become offset with the position of the click on the next activation of the handle.
The seekbar is immediately activated if the mouse button is held while moving the mouse over the seekbar, which is inconsistent with the general `DoButtonLogic` behavior. This is problematic on Android, where the first mouse button is always pressed while the mouse is being moved, causing the seekbar to steal focus immediately when hovered.
The tooltip was not shown if the seekbar is the active item, i.e. when the first mouse button is held down and the seekbar is currently updating the demo player.
Assume every server that does not have ddnet or race in its gametype to be a pvp server.
This allows spectators to follow multiple players during a fng/ctf/gctf/ictf round.
Related issue #7509
The `-1` in the size calculation for the ringbuffer allocation of chat history entries was incorrect, so the entries potentially didn't fit the zero terminator. Because `mem_copy` was used, the string was also not zero terminated explicitly.
This reverts commit f319ed239a.
Initializing these variables with junk data doesn't seem to be an
improvement over not initializing them. It hides potential Valgrind
warnings about data accesses to uninitialized memory though.
f319ed239a (r1590801501)
Nudge the initial position for explosions' smoke particles slightly towards the edge of the closest non-solid tile, if it would otherwise be inside a solid tile, so the smoke particles do not get stuck inside solid tiles on explosion events happening at the edges of tiles but slightly inside them. The physical position of the explosion event is unchanged, so this does not affect physics. The explosion sprite is still rendered at the physical position of the explosion, to preserve the apprearance.
Add additional checks to ensure that the `CVideo::Stop` function and the functions called by it will correctly stop the current video also if the video was not started successfully, i.e. if `CVideo::Start` returned `false` from any of the error branches.
In the `CVideo::Stop` function, iterate over the vectors of video and audio threads directly instead of using `m_VideoThreads` and `m_AudioThreads`, which do not reflect the actual count if the initialization failed before the threads were created.
In the `CVideo::Stop` function, only call `av_write_trailer` if the video recording was stated successfully, i.e. only if `avformat_write_header` was called successfully, as this will otherwise cause the client to crash. Closes#6375.
In the `CVideo::Stop` function, only call `avio_closep` if the format context was allocated.
In the `CVideo::FinishFrames` function, ensure that the codec has been allocated and opened, otherwise using it is not allowed.
Add assertions to the `CVideo::Start` and `Stop` functions to ensure that the same video is not started/stopped multiple times.
Crash with assertion when the size of the graphics is different from the video currently being rendered, instead of causing weirder bugs and a corrupted video file.
The wrong sampling rate was being used for video recording if the client is not restarted after changing the `snd_rate` config variable.
Ensure that the correct bit rate is used if the sample rate was adjusted because the selected value is not supposed.
Use `log_error` for all errors and consistently format all error messages.
Handle all ffmpeg errors and output the formatted ffmpeg error message when possible.
Register a log callback for ffmpeg log messages to delegate them to our logging system, to fix the log messages being interleaved with our log messages and not using the correct line breaks on Windows.
Stop video and demo immediately and show an error message popup if the video could not be started successfully.
Remove unnecessary debug output from ffmpeg.
Removed member prefix m_ used for local variables.
Removed all b, c, i hungarian notation prefixes for boolean, const and integers.
Fixed local variables using lower_snake_case instead of UpperCamelCase.
Renamed all ``float wSearch = TextRender()->TextWidth..`` to ``float SearchWidth = ..``.
When using the `remove_vote` command, the entire heap of vote options is allocated again without the entry being removed. This allocation was not considering the required alignment for `CVoteOptionServer` objects and potentially wasting space by aligning with `alignof(std::max_align_t)`. When allocating the entries with the `add_vote` command, the alignment is already specified correctly.
Relevant upstream commit:
d2924b5ad6
Closes https://github.com/ChillerDragon/ddnet/issues/7
The snap item obj_character contains a field called m_TriggeredEvents
https://chillerdragon.github.io/teeworlds-protocol/07/snap_items.html#obj_character
It is responsible for effects and sounds. Those flags are set in the gamecore.
So if the servers gamecore ticks twice and resets the flags before a snap is
sent the client misses the information. Which is not too big of a
problem since the client has his own gamecore running (prediction) which
also sets those flags. But it is still wrong and teeworlds does always
include the triggered events in the snap.
So this commit fixes it using the same approach as teeworlds.
By not resetting the triggered events until a snap was sent.
Always use the server address from the network client to reconnect to the correct server after being disconnected due to wrong password. The password popup is only shown after being disconnected, so the server address of the network client should always the address of the server which the client should reconnect to with the password. Using `ui_server_address` was causing the wrong address to be used after being redirected to another server and if the config variable is changed while the password popup is open.
Closes#8260.
Fix leak of pending future logger log messages if the future logger is not set, in particular when the `logfile` config variable is not set or the file could not be opened, by setting a logger that discards all log messages in this case.
Closes#8265.
When changing the screen width, height or refresh rate config variables to 0 or negative values, which are not allowed by the backend, automatically revert the config variables to the actual values again to ensure that the config variables stay in sync with the state of the window. This fixes the client crashing in the graphics settings when setting the screen width and height to 0 via the console, which causes a division by zero when calculating the aspect ratio.
According to the documentation, this function returns `0` on success and a negative number (error code) otherwise, which would cause an allocation of an invalid size.
The third parameter of the `op_read` function specifies the remaining size of the buffer, but we always passed the total size of the buffer without respecting the position at which the data is written into the buffer.
Set the data pointer of the sample only when the sample has been loaded successfully, so the invalid sample data is not freed again when decoding fails.