AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Free pascal oledb4/24/2023 But I have been programming for 21 years and with Pascal since 2004. I did mention earlier in the post that multithreading could be too advanced for me. I know about that saying from the Lazyfoo tutorials. I understand the idea behind using two buffers but it feels like a waste to me when I could be making the game only render (sdl_renderpresent) when everything is ready. I only use surfaces to load bmp files (outside of the main loop) and then load those surfaces into textures only because sdl 2 does not offer any other solution I know of to apply a color key to a texture loaded from the hard drive. But in sdl 2 now I am rendering all graphics using hardware. I'm not familiar with programming for buffers except maybe when I was using sdl 1. If fpstick<1000/selfps then sdl_delay(round((1000/selfps)-fpstick)) If fpscapstate=true then fpstick:=sdl_getticks I have my own implementation of vsync in the main thread in the main loop: Uses sdl2, sdl2_image, sdl2_ttf, sdl2_mixer, sdl_gfx, crt, Like how much hp a target loses and what status effects are applied but that's so low in computational demands that I'm starting to wonder why have multithreading at all except for quicksaves. Then have the main thread render the combat graphics separately but I will have to only process variables that have no impact on the graphics at all. I was thinking I could also use an additional thread for the calculations relating to combat in the game. I will find some other use for the additional thread, for example quicksaves without interrupting gameplay. So I have no choice but to include the procedure in the main thread instead. So from what I can figure the shaking graphics (only characters are shaking, the background tiles are not) comes from the fact that the main thread is rendering the characters while the additional thread is still processing the characters coordinates when they move. However doing something not for the sake of performance like asynchronous file loading isn't a bad idea for intermediate game developers. You should not be trying to use multithreaded optimization. How operating systems handle threads and processes. ![]() If you do not know the costs of using different multithreading tools, you can end up with code that is much slower than its single threaded equivalent. The fact is that multithreading inherently adds more overhead because threads then have to be managed. Here's the important part: a poorly made multithreaded program can perform worse than single thread program. Since multicore processors launched at a consumer level in the early 00s, developers have been using this new tech to squeeze out as much performance as they can from their applications. They hear about a technology that the latest and greatest developers out there are using and they think if the use it too it will make them magically better. Premature optimization is the root of all evilĪ major problem with newbie programmers is that they want to be like the professionals without paying their dues. I tried inserting a conditional statement to only render characters once the additional thread doing calculations is done but that did not solve the issue. When I move characters around the additional thread processes their movements and new positions, the main thread renders the characters on screen and those two things happened asynchronously due to multithreading. ![]() In order to draw the graphics I need to know the position of each character. ![]() I can't think of a way to make this independent. So basically the graphics still depend on player position calculation, which is normal. My characters on screen are shaking when moving and I think it's due to the calculations and graphics not being synced. I made sure that all variables I'm using in the additional thread are not used at all in the main thread. So I moved the code for calculations, such as character positions and movement, to an additional thread and left everything else including graphics in the main thread. So I managed to get multithreading working but it turns out that I cannot use commands relating to graphics in anything other than the main thread which defeats what I wanted to use multithreading for (have one thread render half the grid and another the other half).
0 Comments
Read More
Leave a Reply. |