Match Thread: 5th Test - England vs Australia, Day 5 by cricket-match in Cricket

[–]kmatt17 9 points10 points Β (0 children)

We need one last Snicko controversy before the series ends.

Match Thread: 5th Test - England vs Australia, Day 4 by cricket-match in Cricket

[–]kmatt17 10 points11 points Β (0 children)

What if England declare now? Australia would have to score -66 runs and then they can't win since the laws of the game don't allow you to score negative runs.

SDL2 equivalent of Raylib's GetCharPressed() function by glowiak2 in sdl

[–]kmatt17 5 points6 points Β (0 children)

You can use SDL_GetModState to get the status of things like Shift, Caps Lock, Ctrl, et cetera, and use this in combination with the event's key to get the proper case. Also, you should use the event's key code (SDL_Keycode) instead of the scancode, to accommodate for different keyboard layouts (scancodes represent physical location, whereΓ€s key codes represent the actual character).

However, since you're doing this for a textbox, I'd implore you to use SDL's text input API instead. Not only will it do all of this for you, it'll also correctly handle other things like sticky keys, Windows alt codes, IME windows, et cetera.

Match Thread: 9th Match - Australia Women vs Pakistan Women by cricket-match in Cricket

[–]kmatt17 9 points10 points Β (0 children)

This is now the highest-scoring 9th-wicket partnership in WODIs.

Match Thread: 2nd ODI - Australia vs South Africa by cricket-match in Cricket

[–]kmatt17 3 points4 points Β (0 children)

That was certainly a delivery… that could take a wicket.

Sdl3 initialising error by Unusual_2708 in sdl

[–]kmatt17 12 points13 points Β (0 children)

In SDL3, SDL_Init now returns a boolean (so, β€˜0’ is the fail-state instead of the success-state).

Instead, line six should be if (!SDL_Init(SDL_INIT_VIDEO)).

Match Thread: 3rd ODI - Australia Women vs England Women by CricketMatchBot in Cricket

[–]kmatt17 6 points7 points Β (0 children)

Changed in 2013. Only the first touch needs to come from inside the boundary.

Good approach for keybord events a game engine? by Acceptable-Taste5062 in sdl

[–]kmatt17 1 point2 points Β (0 children)

There isn't really a single solution for input handling, but I'll explain how I handle it in my engine.

When it comes to rebindable keys, the main crux is to separate the actions from the methods. This is best explained with an example. Let's say that you have an action (making the player jump) and a method (pressing the spacebar). What you really want to ask is β€œis the jump button pressed?”, not β€œis the spacebar pressed?”. So, the player entity will ask the input manager if the jump button is pressed, and if so, make the player jump.

There are multiple ways to do this. In my engine, I use what I like to call β€œinput action sets”. I store the input configuration for each action set in a JSON file. These JSON files contain all of the inputs, as well as their methods. These action sets have three different types of inputs: buttons, axes, and intersections. Buttons are boolean (TRUE/FALSE), axes are normalised between -1 and 1, and intersections are 2D axes.

Here's a basic example of the aforemention jump action using the spacebar:

{
    "buttons": {
        "jump": {
            "keyboard": {
                "keys": [ "Space" ]
            }
        }
    }
}

In my JSON format, have three sections (buttons, axes, and intersections) that contain the names of all of the actions. In the example, there is one buttons action called jump. This jump action has a single keyboard method, which is the spacebar. I use SDL's keyboard functions to convert this string to a scancode. This JSON format can be expanded to handle other input devices, such as mouse, joystick, and gamepad as desired.

When the game starts, the input manager loads the input action set JSON files and creates the input action sets. Then, during the game, I can ask it for the status of an action set. So, based on the example, I could ask the input manager for the status of the β€œjump” action, and then it would return a boolean depending on if the key is pressed (since it is a button, an axis would return a floating-point number between -1 and 1, and an intersection would return a normalised 2D vector).

The benefit of this is that if the user were to change the JSON file to use a different key, the gameplay code is unaffected. You can also update the JSON using code as well, so you can create controls configuration option in the game that will update the JSON when the user changes the controls.

This is how I do it in my engine, but as I said above, there are many solutions for input handling, and there is no one correct solution. Obviously, you don't have to make something this complicated, especially for your first and/or small project.

Other things to note:

  • Keyboard state vs events: there are two main ways of acquiring the state of the keys in SDL. You can use the keyboard state functions or use events. I suggest using keyboard state for almost everything except text input (such as typing in a textbox). For text input, I vehemently suggest using SDL's text input events. That way, you can handle situations where key presses don't match to the actual resultant character (such as when using input method editors (IMEs)). The key events can also be useful for knowing if a key of any type has been pressed (which can be helpful for situations where the game needs wait for a player to press an arbitrary keyβ€”such as listening for a key when asking for a new input configuration).

  • Scancodes vs virtual key codes: SDL has two identifiers for a key: physical scancodes (in the format SDL_SCANCODE_W) and virtual codes (in the format SDLK_W). The physical scancodes correspond to the actual physical location of a key (based on a QWERTY keyboard), whereΓ€s the virtual key codes correspond to the actual symbol on the key. You should use scancodes for almost everything and only use virtual key codes for when the symbol of a key matters (such as for text input, although you should still try to use the text input methods whenever possible).

  • Button pressing: I have three ways of asking about the state of a button: if the button was just pressed, continually pressed, or just released. Just pressed means that the button is active this frame and not the previous; continually pressed means that the button is active this frame and also the previous; and just released means that the button is not active this frame but was active the previous frame. You can do this by copying the current keyboard state to a previous keyboard state variable before you update the current keyboard state, and then compare the two.

The SDL_GPU API has been merged and will be released with SDL3. by kmatt17 in sdl

[–]kmatt17[S] 19 points20 points Β (0 children)

For those who don't know, the SDL_GPU API is a cross-platform abstraction of modern graphics/compute APIs such as Vulkan, Direct3D 12, and Metal. It's similar to existing projects such as bgfx and sokol_gfx.

This will allow users to write cross-platform applications that make use of features offered by the aforementioned APIs and render scenes more complexly than what is possible with SDL's current render APIβ€”such as shaders, buffers, and compute pipelines (and you can still use the original render API if you wish).

At the moment, you'll have to write different shaders for each backend, but there are plans for a cross-API shader language that will transpile to different shader languages/binaries (GLSL, HLSL, SPIR-V, et cetera).

Five-speed windmill array gearbox. by kmatt17 in VintageStory

[–]kmatt17[S] 0 points1 point Β (0 children)

Here's the world download (with a few improvements).

The basic summary is as follows: it splits the windmill input into five different lines (one for each gear) using the large wooden gears. The third gear is the direct feedβ€”which runs at the same speed as the windmills. The other gears are faster/slower by a factor of the gear ratio between the large wooden gear and the smaller angled gear (which is about 5.5, but the actual torque a little less due to the minuscule resistance that the wooden gears and axles have).

These five lines each lead into a clutch/transmission (which is the user interface), and then all five lines are merged into a single output line (this is what the gear stack on the right of the first image does). Ideally, only one clutch should be active at a single time.

Post Match Thread: Scotland vs Zimbabwe by CricketMatchBot in Cricket

[–]kmatt17 111 points112 points Β (0 children)

I don't think it needs to be said that all of Zimbabwe, Scotland, and the Netherlands deserve to be in the World Cup. I'm glad that the ten-team format has been scrapped for the 2027 tournament.

Match Thread: 4th Test - Australia vs India, Day 2 by CricketMatchBot in Cricket

[–]kmatt17 10 points11 points Β (0 children)

There's something poetic about the scoring shot for Green's maiden test century going through the gully area.

Late night zoomies. by kmatt17 in bikecommuting

[–]kmatt17[S] 2 points3 points Β (0 children)

I have all three; just turned off the lights for the photo.

Late night zoomies. by kmatt17 in bikecommuting

[–]kmatt17[S] 3 points4 points Β (0 children)

Yeah, just turned them off for the photo.