Commit graph

131 commits

Author SHA1 Message Date
Robert Müller a743962b84 Pass CImageInfo by reference to IGraphics::LoadPng
For consistency with other graphics functions using `CImageInfo`.
2024-04-12 17:23:41 +02:00
Robert Müller 8f7055f694 Change PNG in function names to Png
- `LoadPNG` -> `LoadPng`
- `SavePNG` -> `SavePng`
- `LoadSkinPNG` -> `LoadSkinPng`
2024-04-12 17:23:18 +02:00
Robert Müller 2b8af7f40f Pass arguments as CImageInfo to graphics functions
Pass `CImageInfo` arguments to various graphics and text render functions instead of passing the components (data pointer, width, height, format/pixel size) of the image info separately.

Pass texture/file name to loading functions when available to improve error/warning messages.
2024-03-27 21:12:02 +01:00
Robert Müller 8218dbb6f8 Add CImageInfo::DataSize convenience function
To calculate the size of the image data based on its width, height and pixel size.
2024-03-27 21:12:02 +01:00
Robert Müller 11aba0e38d Replace IGraphics::FreePNG with CImageInfo::Free
The engine graphics do not need to be involved with freeing image data.

The `Free` function now also ensures that all other member variables are cleared when freeing the image data.
2024-03-16 20:55:22 +01:00
Robert Müller b67263107d Use uint8_t * consistently for raw image data
Previously, usage of `void *`, `unsigned char *` and `uint8_t *` was mixed in various places for pointers to raw image data and the pointers ended up being cast to `uint8_t *` at some point anyway. Now only `uint8_t *` is used consistently, which improves type safety and readability. Casts to `uint8_t *` are now only necessary when using `malloc` or when reading data from a map.
2024-03-09 13:31:53 +01:00
heinrich5991 17402cc43f Rename all variables for strict camel-casing of abbreviations
This is the strict version, ID → Id, UI → Ui, except DDNet which stays
DDNet.

This would fix #7750.

Done using a naive rename script (for bash, use `shopt -s globstar`):

```fish
sed -i \
	-e 's/\([a-z]_\?\)ID/\1Id/g' \
	-e 's/\([^ ]\)\<UI\>/\1Ui/g' \
	-e 's/UI()/Ui()/g' \
	-e 's/\<CUI\>/CUi/g' \
	-e 's/\([\ta-z.(&]\|[,=|] \)ID\>/\1Id/g' \
	-e 's/\<ID\>\([^ ").]\)/Id\1/g' \
	-e 's/\<ID\([0-9]\)/Id\1/g' \
	-e 's/\<ID\>\( [<=>:+*/-]\)/Id\1/g' \
	-e 's/int ID/int Id/g' \
	-e 's/\([a-z]_\?\)GPU/\1Gpu/g' \
	-e 's/\([a-z]_\?\)IP/\1Ip/g' \
	-e 's/\([a-z]_\?\)CID/\1Cid/g' \
	-e 's/\([a-z]_\?\)MySQL/\1Mysql/g' \
	-e 's/MySql/Mysql/g' \
	-e 's/\([a-xz]_\?\)SQL/\1Sql/g' \
	-e 's/DPMode/DpMode/g' \
	-e 's/TTWGraphics/TTwGraphics/g' \
	\
	-e 's/Ipointer/IPointer/g' \
	-e 's/\.vendorId/.vendorID/g' \
	-e 's/\.windowId/.windowID/g' \
	-e 's/SDL_GetWindowFromId/SDL_GetWindowFromID/g' \
	-e 's/SDL_AudioDeviceId/SDL_AudioDeviceID/g' \
	-e 's/SDL_JoystickId/SDL_JoystickID/g' \
	-e 's/SDL_JoystickInstanceId/SDL_JoystickInstanceID/g' \
	-e 's/AVCodecId/AVCodecID/g' \
	src/**/*.cpp src/**/*.h {datasrc,scripts}/**/*.py
git checkout -- src/engine/external
```

I like this option because it presents clear rules.

Still needs fixups because of the naive replacement, I'd do this if we
want this merged.
2024-03-05 15:44:09 +01:00
Peakies e8809f11a3 rename Modes 2024-02-09 23:01:09 +03:30
Peakies d40038c679 remove unnecessary variables and loop 2024-02-07 02:31:06 +03:30
Robert Müller 9c66a6a147 Remove unused parameter of SetWindowParams function
The `bool AllowResizing` parameter is only passed to other `SetWindowParams` functions but never used in the end, as whether or not resizing is allowed is separately determined based on the value of the `int FullscreenMode` parameter.
2024-01-23 17:49:55 +01:00
Dennis Felsing 8dee975d66
Merge pull request #7744 from Robyt3/Editor-Color-Palette-Pipette
Add color palette and pipette to editor
2024-01-13 22:55:16 +00:00
Robert Müller abc7b602b2 Avoid copying texture memory when possible
Add separate `IGraphics::LoadTextureRawMove` function with non-`const` `void *pData` argument in addition to existing `LoadTextureRaw` function with `const void *pData` argument. The former function takes ownership of the data and avoids copying the texture data into an additional buffer, if the texture data is already in RGBA format. Non-RGBA texture data always needs to be converted and therefore also copied.

The `LoadTextureRaw` function is split into smaller functions to share common code with the `LoadTextureRawMove` function. Alternatively to this, a flag `TEXLOAD_MOVE_DATA` could have been added to the existing `LoadTextureRaw` function, which would have required the use of `const_cast` to free the texture data.
2024-01-03 23:03:04 +01:00
Robert Müller f5e7fa24d6 Add color palette and pipette to editor
Add color palette with up to 8 colors to editor toolbar. The palette colors work like regular color picker buttons, so they open a color picker popup on click and the value can be copied and pasted with Ctrl+Right click and Ctrl+Left click respectively. Less palette colors are shown when not enough space is available (with 5:4 resolutions).

Add color pipette which allows selecting any color displayed on the screen. Selecting a color with the pipette adds the new color to the palette and shifts the other colors to the right. The selected color is also copied to the clipboard immediately. The hotkey Ctrl+Shift+C is added to toggle the color pipette, which allows using the color pipette in popups and dialogs.

The implement this, the function `IGraphics::ReadPixel` and the command `SCommand_TrySwapAndReadPixel` are added to read a specified pixel's color from the backbuffer. Like the screenshot command, this command also requires a swap operation to be performed before the correct pixel color can be read with the Vulkan backend. The `ReadPixel` function therefore accepts a pointer to a `ColorRGBA` that will be filled after the next swap operation.

Closes #7430.
2023-12-30 13:17:30 +01:00
Robert Müller c31f82a9e9 Refactor graphics SetColor functions
Reduce duplicate code.

Replace `clampf` function with `NormalizeColorComponent` function that convert color component from `float` to `unsigned char`.

Use `size_t` instead of `int`.
2023-12-23 17:56:52 +01:00
heinrich5991 05af24a052 Make less headers depend on <base/system.h>
Move a couple of trivial type definitions to `<base/types.h>` instead.
2023-12-11 23:52:23 +01:00
Robert Müller 5aa9003180 Remove unused ver parameter of MACRO_INTERFACE 2023-11-28 21:46:03 +01:00
Robert Müller 0427dfff2e Use bool instead of int 2023-11-20 21:58:29 +01:00
Jupeyy 639a8c3c8b Switch to a fragment shader solution for border tile rendering 2023-11-04 14:51:39 +01:00
Robert Müller 82ba8e0bb8 Add CTextureHandle::IsNullTexture, rename InvalidTexture
Rename `InvalidTexture` to `NullTexture` to avoid confusion because the null texture is not invalid. The function `CTextureHandle::IsNullTexture` is added to make it easier to check the result of using `IGraphics::LoadTexture`, which returns the null texture on error instead of an invalid texture handle. An assertion is added to ensure that `IsNullTexture` works correctly.
2023-11-04 12:54:08 +01:00
Alexander Akulich b6470e5a43 Use client 'six' data structs for client 'seven' data 2023-10-06 18:14:38 +03:00
Robert Müller dde45f7a40 Add CImageInfo::PixelSize function, use enum EImageFormat
Use `enum EImageFormat` type for image format literals and variables.

Add `PixelSize` function to get the number of bytes/color channels per pixel for a specified image format.

Remove unused store format argument of texture loading functions. All textures are automatically being stored as RGBA, so the argument was unused. Also remove the therefore unused `FORMAT_AUTO`.

Rename variables consistently to `PixelSize` and use `size_t`, instead of mixing different names like `BPP` and `ColorChannelCount`.

Validate image format loaded from maps using `CImageInfo::ImageFormatFromInt`. Add `FORMAT_ERROR` to represent invalid formats.

Remove redundant `PixelSize` parameter from graphics backends and commands, which can be derived from the texture format.

Fix memory leak when RGB image data is being converted to RGBA format when saving map in editor.
2023-09-03 20:40:28 +02:00
marmare314 12d0608dfd let CEditorImage inherit CEditorComponent 2023-09-01 18:57:35 +02:00
Robert Müller c695fd750e Remove inverted round rectangle corner drawing
Rectangles with inverted round corners (`IGraphics::CORNER_I*`) are currently not used anywhere and also only supported when using `Draw4`.

They also feel clunky to use due to the inverted corners being drawn outside of the specified rectangle area.
2023-07-27 23:29:37 +02:00
Robert Müller 58927cdc8d Use size_t more in engine graphics 2023-07-20 21:58:17 +02:00
heinrich5991 9c0c7550ba Don't support loading RGB images ingame
They're essentially unused and not supporting them ingame probably
allows to keep that part of the map format unused.

See https://github.com/ddnet/ddnet/pull/5737#issuecomment-1538284956 or
https://github.com/teeworlds/teeworlds/issues/2812.
2023-07-16 15:26:00 +02:00
Robert Müller abfafa314a Add IGraphics::GetScreenName
To get the screen name for each screen index.
2023-06-08 12:52:34 +02:00
Jupeyy 70d48140f0 Show GPU info (if available) in assert 2023-05-27 09:51:22 +02:00
Robert Müller c841c7ad05 Destroy window before showing popup if graphics initialized
Work around SDL bug that prevents message popup from being closed.
2023-05-07 21:20:47 +02:00
bors[bot] 5107b38d04
Merge #6324 #6345
6324: Optimize client ids map update r=def- a=0xfaulty

I have launched support for 128 players in testing mode on my server, it's means it's time for another step in this direction here. Perhaps not all changes will be clear, I am ready to answer/discuss them as usual. Let me know if I forgot or didn't take anything into account.

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


6345: Set constant and uniform names for the server and client CMake targets r=def- a=Kaffeine

This MR set the server and client CMake target names to `game-server` and `game-client` which are uniform with other targets such as `engine-gfx`, `engine-shared`, and `game-shared`.

Set uniform names for the targets to:
1. Avoid long rebuilds on the target _executable_ name changed
2. Provide the same name for different executables and/or different setup (use-cases are `cmake --build . --target game-server` and various CMake target lookups in IDEs)

Those changes are necessary but not enough to allow CI for custom app name on all platforms.

Personally this 'll allow me switch to between DDNet and Infclass branches faster and without breaking the targets configuration (e.g. with that patchset I can have `game-client` as an active target in both branches), and also reduces the conflicts in `CMakeLists.txt`.
Easier to switch between the forks => easier to contribute.

Co-authored-by: Valentin Bashkirov <valenteen3d@ya.ru>
Co-authored-by: Valentin Bashkirov <v.bashkirov@dev.tassta.com>
Co-authored-by: Alexander Akulich <akulichalexander@gmail.com>
2023-03-05 16:53:37 +00:00
Robert Müller a76fb9b99a Replace all usages of C standard headers with C++ headers 2023-03-01 19:26:51 +01:00
Jupeyy 9530077588 Only call onresize events if actual size changed
clearify difference between resize and window property change for resolution list
2023-02-25 16:02:38 +01:00
Alexander Akulich bb5f0f8894 Cleanup unused or not defined functions 2023-02-18 20:05:52 +03:00
Robert Müller 3280f1824f Reset graphics container indices after deletion
Reduce duplicate code and improve correctness by passing indices of quad, buffer and text containers by reference and always setting them to `-1` after they are deleted.

Also check if index is `-1` before trying to delete it to reduce duplicate code when calling the methods.
2023-02-15 21:05:15 +01:00
Learath f91a3069c3 Let CKernel clean-up. Use unused CSound::Shutdown 2022-09-16 16:50:19 +02:00
Robert Müller 3b1ef5642b Refactor DrawRect* methods:
- use `CORNER_*` constants and add missing constants
- fix array variable names
- use `size_t`
- extract duplicate computation into constant
- use `ColorRGBA` instead of `vec4`
2022-08-12 17:42:05 +02:00
Robert Müller 2a21cd6eab Move all DrawRect* methods from CRenderTools to IGraphics
As the methods do not depend on any game components they are moved to the engine graphics interface.
2022-08-12 17:42:05 +02:00
Robert Müller 7b20009980 Move CUI::CORNER_* enum to IGraphics::CORNER_*
Entirely automatic replacement in preparation for moving rect drawing methods from `CRenderTools` to `IGraphics`.
2022-08-12 17:42:04 +02:00
Robert Müller 9ad097da4d Refactor DrawCircle:
- improve argument names
- remove duplicate computation by adding `SegmentsAngle`
- rename variable `Array` to `aItems`
- use `std::size` and `size_t`
- remove unnecessary temporary variables
2022-08-12 17:42:03 +02:00
Robert Müller 237fdc76db Move CRenderTools::DrawCircle to IGraphics::DrawCircle
As this method does not depend on any game components it is be moved to the engine graphics interface.
2022-08-12 17:42:03 +02:00
heinrich5991 994324b059 Warn about pnglite-incompatible PNGs on load
This allows a larger range of PNGs to be loaded while still maintaining
backward compatibility with older clients by annoying the user.

This warning can be enabled by the `warn-pnglite-incompatible-images`
key in the https://info2.ddnet.tw/info JSON, if the key is not there or
the JSON hasn't been obtained yet, the warning is disabled. Since the
JSON is cached across restarts, it'll be effective for initially loaded
images from the second start.
2022-07-14 18:22:46 +02:00
Chairn a69dc599a9 Huge variable naming format
Fix pointer and pointer array variable naming

Huge renaming to match our rules

Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)[^a]\w+\[
            (?!(return|delete)\b)\b\w+ (?!(m_|ms_|g_|gs_|s_))[^a]\w+\[

Further format static variables

Format almost all pointer names accordingly

Used regex: (?!(return)\b)\b\w+
\*(?!(m_p|p|s_p|m_ap|s_ap|g_p|g_ap|ap|gs_ap|ms_ap|gs_p|ms_p))\w+\b[^:\(p]

clang-format

Fix CI fail

Fix misnamed non pointer as pointer and non array as array

Used regex: (?!(return|delete)\b)\b\w+ (m_|ms_|g_|gs_|s_)p\w+\b
            (?!return\b)\b\w+ (ms_|m_|g_|gs_|s_)a\w+\b[^\[]

clang-format

Revert to SCREAMING_SNAKE_CASE and reinstate dead code
2022-07-08 18:01:29 +02:00
Chairn 2e8c5b3914 Split screen pos in independent variable. Format function declaration 2022-07-07 04:51:17 +02:00
Chairn 32318a7c90 Reworked color system
Removed duplicate structs. Replaced 4 floats array with appropriate
struct where applicable
2022-07-06 11:39:51 +02:00
Chairn 27da8391dc Replace 2 floats array with vec2 where it makes sense 2022-07-06 11:39:43 +02:00
Chairn c9345e7d32 More vector naming format 2022-06-15 19:37:37 +02:00
ChillerDragon 3667061b68 Use nullptr in generated and editor
-Wzero-as-null-pointer-constant
2022-06-13 18:28:13 +02:00
Chairn 01edaec628 Format vector variables names (fixes #5209) 2022-06-11 21:38:49 +02:00
Jupeyy b8da817716 Return the quad offset of the first added quad, when adding new quads 2022-04-28 16:50:18 +02:00
Jupeyy b23e60c077 Allow onfly FSAA change under Vulkan 2022-04-26 21:09:55 +02:00
bors[bot] fdcb1576bd
Merge #4946 #4993 #4998 #4999
4946: Better forced viewport handling r=def- a=Jupeyy

For #4939

For the performance warnings refering `vkCmdClearAttachments` ignore them, because this function is only called when:
- clear color is changed(open/close editor, switch between entities) to directly flush a clear with the new color
- ~~a viewport is used that is "worse" than 5:4 (I don't really want to switch to non renderpass clear completly, since it *can* improve performance -- https://community.arm.com/arm-community-blogs/b/graphics-gaming-and-vr-blog/posts/vulkan-samples "Therefore, avoid using LOAD_OP_LOAD and vkCmdClearAttachments and use LOAD_OP_CLEAR or LOAD_OP_DONT_CARE whenever possible.")~~
thinking about it, maybe i can also drop this call now, since its dynamic viewport anyway

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


4993: Unselect text after ctrl-u r=Jupeyy a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


4998: Refactor tooltips and add some more r=def- a=edg-l

Refactored tooltips so they render last, otherwise stuff rendered after the call is overlapped.

Also renamed "Alpha" to "Opacity" which is more clear to non-devs.

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


4999: Respect GPU type better r=def- a=Jupeyy

fixes #4994

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
Co-authored-by: def <dennis@felsin9.de>
Co-authored-by: Edgar Luque <git@edgarluque.com>
2022-04-18 08:06:49 +00:00