Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kojack

Pages: 1 ... 18 19 [20] 21 22
286
Ok, I was slightly wrong there. SFML does allow you to query how many buttons are really on a joystick, but clamps the value to 32 max. But there's no way to query how many axes or POVs there are.

Another issue, it sets up the Direct Input format for 4 groups of analog values, each having 6 axes and 2 sliders (so 4*(6+2)=32 total). Plus there's 4 POVs. But then says there's only 8 axes possible, and returns a single POV as the 7th and 8th axes, which should be the first 2 sliders.

An example of a common device that would break this limit if fully supported: Playstation controller. A DualShock4 controller has 16 analog axes:
- left thumb x
- left thumb y
- right thumb x
- right thumb y
- left trigger
- right trigger
- touchpad finger 1 x
- touchpad finger 1 y
- touchpad finger 2 x
- touchpad finger 2 y
- IMU gyro pitch
- IMU gyro yaw
- IMU gyro roll
- IMU acceleration x
- IMU acceleration y
- IMU acceleration z

Of course DirectInput only shows the first 6, but the rest are there if you go down to the HID level like I do. :)

Anyway, you got your issue working, I'll stop ranting now. :)

287
Yay.

I guess the issue with the change is that other platforms might not support it (I don't know, I only do windows dev). It's only in the windows specific implementation that the higher number is used, maybe linux/mac/android/etc wouldn't like it.

Ideally, SFML wouldn't use one set of constants for all joystick devices, but query the devices for exact numbers.

Soon I should receive a Wooting Two Lekker Edition keyboard. It has over 100 analog axes (every key is analog). So even 32 axes can be a little limiting. :)

I haven't checked on the first poll issue. It might depend on the device as to whether it sends initial state of everything on startup or only changes. That's one thing that really annoys me with MIDI programming. There's no way in MIDI to ask a device something like "what is the value of this slider?". Instead you have to wait for the slider to move, then you get an event saying the new value. So you can't get initial state of all controls.

288
Support for 128 buttons came out in 1997 in DirectInput 5.
But we still have games like Elite Dangerous that refuse to support it.
(It's a pet hate of mine, I've got Virpil hardware with more than 32 buttons and have to use software like Joystick Gremlin and vJoy to redirect my throttle through multiple virtual 32 button devices)

Looking at the SFML joystick code, it seems at least for Windows they may have forgotten to update the counts. Currently it's set to 8 axes and 32 buttons (and 4 POVs, but they don't get a count constant).
But the setup code is using a custom format structure with 32 axes, 32 buttons and 4 POVs.
But then the setup code says the number of objects in that struct is 32 axes, 128 buttons and 4 POVs (with 96 buttons undefined) by saying the format was the same size as DIJOYSTATE2 afterall.

So by the look of it (haven't tested) changing ButtonCount to 128 and AxisCount to 32 in joystick.hpp (and recompiling SFML) should be enough. The joystick setup code is ignoring AxisCount and is hard coded to 32 anyway (just won't let you look at them due to AxisCount), while it does use ButtonCount to set up the buttons.

On a side note, since nothing dynamic is being done there (like allocating exactly the number of axes/buttons on the device by enumerating all controls), the 80+ lines of format setup could be replaced with:
result = m_device->SetDataFormat(&c_dfDIJoystick2);
(c_dfDIJoystick2 is the already set up by DirectInput 32 axis, 128 button, 4 POV format)
Unless I missed something it's doing in there.

I might test it later if I get time.

289
System / Re: sf::Thread error
« on: May 04, 2021, 04:38:16 pm »
It seems to dislike the type of mouse_pos_loop.
How exactly is mouse_pos_loop declared? Also what exactly are au and Window? Namespaces or classes?
For example a free function in a namespace is different to a member function in a class when it comes to binding them to things like threads.

290
General / Re: Random Position Problem
« on: May 04, 2021, 08:01:17 am »
Is that Init function called every time a ship is reset to the top?
Generally srand should only be called once in the entire program (at the start).

Especially if using time() to seed it. time() works in seconds, if you srand before every rand then you'll get new random values only once per second. For example, if you reset 10 ships within a second, they will all get the same X position because the srand is resetting the random sequence back to the same starting point until the result of time() changes.

The C/C++ rand is pretty crap for repeating patterns anyway (and only returns a 15 bit value).

I generally use a 128bit Xor Shift random number generator. http://en.wikipedia.org/wiki/Xorshift
But C++11 brought in a new random number system: https://www.cplusplus.com/reference/random

291
Graphics / Re: TileMap: array of sprites vs vertexArray
« on: May 03, 2021, 12:21:56 am »
Another way to go is using a tile shader.

Using just a single quad and 1 draw call, you can have a huge area with no off screen drawing. Have an atlas texture for all your tiles and an index texture to specify which tiles to use.
The colour of each pixel in the index texture is the index of a tile in the atlas.
By changing the pixels of the index texture, you can animate tiles.

292
DotNet / Re: Problem with porting from NinePatch to C#
« on: May 02, 2021, 06:27:36 am »
The vertex array used to draw the patch has all of it's colour members defaulting to (0,0,0,0), so the patch is fully transparent (ie. invisible).
After making the patch, call this:
nine9sprite.Color = Color.White;

However this won't work yet, because there's a bug in the Color property setter. This is the current code:
        public Color Color
        {
            get
            {
                return m_vertices[0].Color;
            }
            set
            {
                foreach (Vertex vertex in m_vertices)
                {
                    Vertex tempvex = vertex;
                    tempvex.Color = value;
                }
            }
        }
The foreach loop goes over every vertex, but assigns the colour to a temp vertex, not the actual vertex array.
C# doesn't like foreach loops that modify values (if Vertex was a class, it would be ok, but as a struct, the foreach variable "vertex" is read only). So we need to change it to a normal loop like this:
        public Color Color
        {
            get
            {
                return m_vertices[0].Color;
            }
            set
            {
                for(int i=0;i<m_vertices.Length;++i)
                {
                    m_vertices[i].Color = value;
                }
            }
        }

After both of those changes, it's rendering.

293
DotNet / Re: How to use RenderWindow.SetIcon in sfml.NET
« on: May 02, 2021, 05:57:05 am »
SetIcon takes a width, a height and a byte array. Looking at the C++ header (where there's comments on how it works), the data it takes is RGBA pixels.
The Image class can load image files and provides a byte array of the pixels in RGBA. So you can make an icon like this:
Image image = new Image("icon.png");
window.SetIcon(image.Size.X, image.Size.Y, image.Pixels);
 

294
Feature requests / Re: Adding VertexArray[i].setTexture
« on: May 01, 2021, 03:17:54 am »
With some work, as long as you don't mind losing the ability to colour your vertices, it could be modified so that the vertex colour is used to select the correct tile, rather than using a lookup texture. Then at runtime changing the colour of the vertex would select the desired tile.
If there aren't too many tiles (less than 257) then the alpha channel could be used for selecting them, while RGB is used for colouring. (Assuming transparent vertices weren't required)

295
General / Re: SFML Setup with Visual Studio
« on: April 29, 2021, 12:46:56 pm »
Awesome! :)

296
General / Re: SFML Setup with Visual Studio
« on: April 29, 2021, 03:39:57 am »
Ok, getting close now.
If we look at the first error:
sfml-window-s-d.lib(InputImpl.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function "public: static bool __cdecl sf::priv::InputImpl::isKeyPressed(enum sf::Keyboard::Key)" (?isKeyPressed@InputImpl@priv@sf@@SA_NW4Key@Keyboard@3@@Z)

It's saying that the isKeyPressed function in sfml-windows-s-d can't find a function called __imp__GetAsyncKeyState@4.
GetAsyncKeyState is a windows sdk function. Checking it at https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate says it comes in user32.lib.
All the following errors look like they are user32.lib (or similar windows sdk lib) related too.

So for some reason your project isn't linking user32.lib. Usually it should be inherited in the linker settings:


My first guess would be your project is trying to use the wrong windows sdk.
Try right clicking on the project in the solution explorer and selecting Retarget Projects. Then choose one of the SDKs in the combo box and hit Ok.

297
Graphics / Re: Viewporting the Viewport?
« on: April 28, 2021, 08:07:56 am »
Another way would be use a render texture of the desired size. You can scroll it around using a view, then render it onto the screen where the viewport was. You could then also render it into another render texture that is also scrolling, etc.
(Could also save a bit on rendering by only redrawing into the render textures if something changed)

298
General / Re: SFML Setup with Visual Studio
« on: April 28, 2021, 07:15:13 am »
I tried breaking one of my older projects (I haven't used static sfml for a while) to see the errors it gave, it's probably not the static thing as I said previously. When the static flag is missing, the files on the left of the linker error line would be your files. But in this case it's sfml's window library on the left, so that means sfml is trying to find something (in another library?) that's missing.

But I can't see what it's looking for, could you post a complete linker error line? The bit you posted doesn't show the part of the error message that says what is missing.
(Preferably a few (or all) of the errors, in case there's a few different things missing)

299
General / Re: SFML Setup with Visual Studio
« on: April 27, 2021, 11:16:37 pm »
It sounds like you have SFML_STATIC defined for release builds, but not for debug builds.
Go into project properties / C++ / Preprocessor / Preprocessor Definitions and make sure SFML_STATIC is there for debug builds.

300
Network / Re: My Issue with TcpListener listen() method
« on: April 27, 2021, 06:21:25 pm »
A little more detail.
On windows, some initialisation code needs to be called to start Winsock.
In SFML, this is done in the SocketInitializer struct. It's created as a variable in SocketImpl.cpp as the file scope variable globalInitializer, it's constructor does the Winsock startup.

The problem is C++ has no defined order that static/file-scope variables are created. https://en.cppreference.com/w/cpp/language/siof  (Static Initialisation Order Fiasco)
So there's two file scope variables being made: globalInitializer (that sets up Winsock) and c (your class that needs Winsock), but there's no way to know which will be constructed first. If c is created before globalInitializer, it will fail.

In your second style, c is constructed in main. The main function is started after all static/file-scope variables have been built, so globalInitializer has definitely gotten to do its work first.

(To be accurate, the order is defined when they are all in the same cpp file. But when they are in different cpp files as is the case here, order is indeterminate)

Pages: 1 ... 18 19 [20] 21 22