Bunch of highly awaited gamedev functionalities

Post bugreports for the Windows version here
FlameofChange
New User
New User
Posts: 7
Joined: Sun Jun 09, 2024 8:03 am

Bunch of highly awaited gamedev functionalities

Post by FlameofChange »

Hello there, I'm making a fighting game called Hand2Hand (check out on steam) ; and I won't post a link since I got nuked at least twice on this forum ahah ; and with no saves of this topic so I'm rewriting everything... by hand (lol).
Anyway, during more than 4.5 years of gamedev I encountered a bunch of roadblocks and annoying things to get around...
Take them as a broad list of very awaited suggestions, which can be very welcomed by other gamedevs.
The order is arbitrary ; other suggestions might pile up during discussion.

1 - Flip sprite horizontally
Right now, there's 3 ways of doing that :
1) Loading 2 versions of the sprite in memory, one normal and one flipped ; very annoying when your game need A LOT of sprites to be displayed
2) Loading the normal sprite, copying it, and flip column by column the second sprite ; very costly in the runtime
3) Using TransformSprite by inverting the x coordinates of each point, but It doesn't work in DirectX because the sprite is counted as flipped upside down and is not even displayed !!!

So my suggestion is to add one of these functions :
☼ A very fast FlipSprite(spriteId.i, mode.i) ; mode being #PB_2dSprite_Flip_Horizontal | #PB_2dSprite_Flip_Vertical | #PB_Absolute | #PB_Relative.
☼ Fix the mentioned TransformSprite DirectX bug, unless it is bound to the graphic engine...

2 - [Bug] TransformSprite resets any RotateSprite
It is self explainatory - unless intentional. Tested in OpenGL
Do a rotation, then transform sprite and tadaaah the rotation is reset !

3 - Precise inputs
Right now, as I understood, the mouse/keyboard/joystick state is taken directly from what is currently pushed or not ; however in a game the inputs might come between 2 frames, which is very annoying when the game lag or has a low framerate.
I know it is possible to do it by catching windows event and "manually" retrieve all inputs ; but to push Purebasic as a user-friendly gamedev langage it would be important to update the system, or suggest other functions to have a precise input.
In other words, for example, ExamineKeyboard would instead loop every pending window events and treat them as inputs ; instead of just scanning what's currently pushed.
Another crusty detail is when the game window is streamed on Discord for example and the focus is elsewhere, all inputs aren't cleaned so it crashes the game.

4 - ElapsedMiliseconds precise (with float value)
The problem of that function is it is not very precise for high FPS values ; which is important for modern games.
Right now I have to do this workaround but it only works for Windows (thanks @Nemerod !)

Code: Select all

Macro ElapsedPicoSeconds()
	PeekQ($7FFE0014)
EndMacro

#H2H_PICOSECONDS2MILLISECONDS=1000*10.0

Macro ElapsedMillisecondsPrecise()
	(ElapsedPicoSeconds()/(#H2H_PICOSECONDS2MILLISECONDS))
EndMacro

Procedure.d deltaSet(stamp.d,withSlomo=#False)
  Static leftover.d=0
  
  If gamePaused
    ProcedureReturn 0
  EndIf
	
	delta.d=defaultDelta
	stamp=ElapsedMillisecondsPrecise()-stamp
	
	wait.d=currentMillisecond-stamp
	wait+Int(leftover)
	leftover-Int(leftover)
	
	If wait>0
		Delay(wait)
		delta=defaultDelta
		leftover+wait-Int(wait)
	Else
		leftover=0
		delta=stamp/defaultMillisecond
	EndIf
	
	If delta<defaultDelta/2
		delta=defaultDelta/2
	EndIf
	If delta>defaultDelta*2
		delta=defaultDelta*2
	EndIf
	If withSlomo
		delta/5
	EndIf
	ProcedureReturn delta
EndProcedure
So either make that function returns a floating number, or do a ElapsedMillisecondsPrecise() function which fetches the precise value in micro-seconds for example.
It is the reason why I cannot port the game on Linux or Mac since the Peek is elsewhere.

5 - [Bug] RotateSprite in x86 OpenGL with colored DisplayTransparentSprite
It is also quite self explanatory. I don't know why but the color filter is shifted elsewhere.
It is the single reason why I had to stop the x86 version for my game since the graphics are broken.

6 - [Bug ?] DisplayTransparentSprite color
I don't know if it is intentional or not, but when setting a color it replaces ALL pixels with that coolor code.
So to color a sprite, I have to display the sprite THEN display the same sprite with a color and transparency amount.
My suggestion is to make a mode where it applies a filter directly on the displayed sprite instead of replacing every pixel.

7 - Option to load images and sprites in memory in 8-16 bits
Loading sprites becomes quite a hassle where all of them are saved in BMP : 32bit hurts a lot and make the memory morbidly obese when having a lot of sprites to display at once.
In my game, fully loading a character can take from 512Mb to 1Gb !
And I plan to make gamemodes where there's a bunch of classes at the same time !
And loading sprites on the fly is quite expensive !

8 - Sprite Atlas support
Many old and new games does that : you put one image and one JSON file in, and the game automatically crop the atlas for the sprite you want to display.

9 - [Bug] PlaySound memory leak
It might have been fixed in the meantime, but playing sounds makes memory leaks ; and since a game can play a ton of them it makes my games crash within 5mns sometimes.
The workaround is to restart sounds we want to play, but we are limited to one channel per sound... unless loading multiple sounds in a queue but that uses memory...

10 - SpritePixelCollision support for zoomed, rotated and transformed sprites
The problem with SpritePixelCollision is it takes the shape of the sprite at load.
Even with transformations the shape is the same.
In my case I have to duplicate all collisions to make it work in flipped.

11 - 2D raycast
To check if a line crosses a collision sprite, it is quite tedious.
That's why I suggest a RayCast2D(spriteId.i,spriteX.i,spriteY.i,x1.i,y1.i,x2.i,y2.i) and RayCast2DPolar(spriteId.i,spriteX.i,spriteY.i,x.i,y.i,angle.i[,length.f]).f which returns the distance at which it collides, -1 if not found : length is by default infinite.
It won't be extremely versatile but that would make some calculations much easier.

12 - Sprite2Image
It is self explanatory.
Printing an image on a sprite is trivial, but the reverse is not since there's no DrawSprite(spriteId.i,x,y[,width,height]) in StartDrawing() bloc.
This way it would be possible to do image transformation like on sprite, at least indirectly.

13 - Advanced controller management
Right now we can only retreive the controller name and events, but it lacks the ability to switch controllers, get the type (since button placements varies...) and detect extra buttons.
There's also a bug where the Joystick 3 X is based on Joystick 1 Z for X and Joystick 2 Z for Y. Why ?????
A JoystickEvent(joystick.id,#PB_Joystick_Unplugged / #PB_Joystick_plugged) function would be useful.
Other functions can be suggested by others, as I just put some examples.

14 - Steam API support
That one is tough I know, but some games are on steam and needs some kind of online : authentication, sync, etc

15 - Threaded sprite loading
Add the option to sprite loading to be asynchronous in LoadSprite, as it is very expensive.
Like this some loading could be redirected in the background.

16 - SpritePixelCollisionPerfect
A sprite loaded with this version will have a binary bitmap to make collision compact and precise.
i.e. a 1024x1024 sprite will be saved as 1024x1024 bits.
The algorithm would only iterate the pixels which are superposed.
It would also detect more complex shapes and crop outer transparent pixels.
I don't have much performance problems right now, however I have a lot of collision sprites to save in memory...
User avatar
jacdelad
Addict
Addict
Posts: 2006
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Bunch of highly awaited gamedev functionalities

Post by jacdelad »

This post is useless...in many ways. It's half bug report, half feature requests. It doesn't make sense to put several big reports into one. All bugs need to be shown with code. All bugs need to be placed in the coding section first to be reviewed and confirmed ( the rules also say that).
And so on...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
FlameofChange
New User
New User
Posts: 7
Joined: Sun Jun 09, 2024 8:03 am

Re: Bunch of highly awaited gamedev functionalities

Post by FlameofChange »

I thought putting them all in one would avoid spam in the forum, as they are directly concerned by my projects.
Time to create demos and break it down then. I'll edit the topic once it's done.
Post Reply