SDLAda does use controlled types, at the moment, but I’m considering removing them to make the binding easier to deal with. They may move or I may extract the thinner bindings to a lower level project. That’s for v3.
Remember SDL is a C library and Ada does map it well and wraps it in part/total and it seems that lazy foo is wrapping it C++.
Just create a function which takes a texture for now:
procedure Render (T : in out Texture; X, Y : Natural)
or something like that.
Or you could do what lazy foo is doing and create higher level wrappers which only exposes what you need. This is what game engines do anyway.
Hi Luke,
I have another question. The part of the tutorial I’m doing now uses SDL_RenderCopyEx to render with rotation and flipping. The SDL documentation states that leaving the source and destination rectangles set to NULL will make it use the entire texture or the entire rendering target (and the centre of rotation also can be nullified to set the center automatically), but I can’t see how could we leave the fields set to null in Ada. I’ve tried with Null_Rectangle but of course it’s not the same. I’ve just created explicitely the rectangles and centre point like this to make it work:
procedure Render
(Renderer : in out SDL.Video.Renderers.Renderer;
Texture : in out SDL.Video.Textures.Texture;
X : SDL.Dimension;
Y : SDL.Dimension;
Angle : Long_Float;
Flip_Type : SDL.Video.Renderers.Renderer_Flip) is
use type Interfaces.C.int;
From_Rectangle : constant SDL.Video.Rectangles.Rectangle :=
(0,
0,
Texture.Get_Size.Width,
Texture.Get_Size.Height);
To_Rectangle : constant SDL.Video.Rectangles.Rectangle :=
(X,
Y,
Texture.Get_Size.Width,
Texture.Get_Size.Height);
Center_Point : constant SDL.Video.Rectangles.Point :=
(Texture.Get_Size.Width / 2,
Texture.Get_Size.Height / 2);
begin
Renderer.Copy (Texture,
From_Rectangle,
To_Rectangle,
Angle,
Center_Point,
Flip_Type);
end Render;
Can we make it simpler with a way to leave the fields set to a null value?
I’m no expert on it and I cannot find SDL_RenderCopyEx in the repo (I’m guessing it is generated on build), but if the binding uses in out for the source and destination, you could make a second function that has an identical binding but replaces in out with access. You could use the existing bindiing and just copy paste that and modify it.
Additionally you could wrap that function in a version of SDL_RenderCopyEx that doesn’t have source/target parameters at all and have that function call your new binding internally while passing the nulls.
I might be missing something, but for SDL_RenderCopyEx there is only one Copy function, with the angle and flip type parameters. The other Copy functions are all using SDL_RenderCopy.
I think we probably need to have a similar overload for SDL_RenderCopyEx as there is for SDL_RenderCopy. Maybe I can do that.
Hi again Luke,
I have another thing I’d like to discuss if you like. I’ve got to the gamepads and joysticks part of the Lazy foo tutorial and so far so good: I was perfectly able to implement the code in the tutorial in much the same way as the original c++ is implemented, using just a 0 value for creating the joystick controller and then checking the Which field of the axis motion event against 0.
Now, the thing is, I wanted to look more deeply into it as handling it like that seems a bit sloppy to me. Checking the SDL documentation the Which field is an SDL_JoystickID:
In the binding SDL_Joystick_IDs are defined as an Instance:
-- SDL_Joystick_ID = instance ID.
type Instances is range 0 .. 2 ** 31 - 1 with
Convention => C,
Size => 32;
So I tried adding an additional step to get the joysticks’ ID after creating the controller to use it when handling the events, but in the binding the Which field is defined as an IDs:
type Axis_Events is
record
Event_Type : Event_Types; -- Will be set to Axis_Motion.
Time_Stamp : Time_Stamps;
Which : IDs;
Axis : Axes;
Padding_1 : Padding_8;
Padding_2 : Padding_8;
Padding_3 : Padding_8;
Value : Axes_Values;
Padding_4 : Padding_16;
end record with
Convention => C;
With IDs defined as:
type IDs is range -2 ** 31 .. 2 ** 31 - 1 with
Convention => C,
Size => 32;
Which produces an invalid operand types for operator “=” error.
IDs and Instances are not compatible. What would be the corret way to handle this?
Thanks a lot, as usual!
I’ve been in reinstall gentoo hell for the last few days, so everything’s still not sorted and won’t be for a while. Also, this area is one which isn’t finished, can’t remember apart from haptic stuff what’s missing. I also need to go back and read about it.
It’s not a big deal, I could get past it with a simple type cast:
when SDL.Events.Joysticks.Axis_Motion =>
if Event.Joystick_Axis.Which = IDs (Joystick_Instance) then
From doing a search on the SDL include files, it seems that all the joystick and controller event structs have an SDL_JoystickID “which” member so it looks like an opportunity to maybe simplify things a little bit there.
Hmm… SDL_JoystickID which members do seem to be consistently asociated with a joystick instance id in all the event structs in the header file. Anyway! I’ll keep a note for later, moving on to the next tutorial steps now.
Can you add this an issue on GH? Also, make notes of other stuff you come across and mentioning them here, we can discuss and see if they need issues too. Ta.