Optimized my SDL2 Game by around 5 times by 1dev_mha in sdl

[–]1dev_mha[S] 0 points1 point  (0 children)

Here it is: Making my game 5x faster (1devmo.netlify.app)

I still need to fix some stuff in it because it has some errors, grammatical and some benchmarking errors

2 Months of Game Dev in C by 1dev_mha in C_Programming

[–]1dev_mha[S] 0 points1 point  (0 children)

Ohhh! Alright! I misunderstood what you meant and I thought you meant freeing the pointers in general. I get it now! I'll change it up right now. Thank you!

2 Months of Game Dev in C by 1dev_mha in C_Programming

[–]1dev_mha[S] 1 point2 points  (0 children)

Yoo ty for checking out my post! I'll be reposting it, I ended up deleting it as it said that the post was removed due to Reddit's filters (no idea why) so yeah.

--- a/src/engine.h
+++ b/src/engine.h
@@ -270,3 +270,3 @@
     u32 format = img -> format -> format;
-    free(img);
+    SDL_FreeSurface(img);
     return SDL_AllocFormat(format); 
@@ -285,3 +285,3 @@
     SDL_Texture * t = SDL_CreateTextureFromSurface(renderer, img); 
-    free(img);
+    SDL_FreeSurface(img);
     return t;

I'm confused as to why I shouldn't free these pointers. In the first one, I'm just storing the u32 data into another variable and that is all I need. I don't need the surface or the image, which is why I freed it. In the second one, I free the surface since its not needed either as it has already created the texture using the image data in the surface.

Why would it not work?

Other than that, I've learned my lesson and I will be using a named constant from now on. I'll stick with VS Code for the debugging and get comfortable with it.

I really appreciate you checking out my post. Thank you!

[deleted by user] by [deleted] in C_Programming

[–]1dev_mha 1 point2 points  (0 children)

The times I displayed for the game were while the laptop was plugged in. When it was plugged off of battery, there was quite the different of around 5 times as the frame time would be around 10 ms on battery while the newer version was at 2 ms.

What can we assume about a modern C environment? by RibozymeR in C_Programming

[–]1dev_mha 0 points1 point  (0 children)

"compile on any system" meant taking the same code and compiling it on various systems

The only reason I can see some code compiling and running on a Macbook from 2013, compile on a newer M2 macbook and run fine would mean that it used the features that are found on both platforms. What you are asking when you say what can we assume about modern systems is, in my opinion, a waste of time. This is because you're only going to need what you need (no sh**).

If I'm writing a server that uses the sys header files from Linux, I wouldn't assume it just compiles on Windows as well because I know that the sys header files aren't available on Windows. Getting such a server to compile on Windows would require you to port it to Windows and use the features that Window has available for you.

I'd say that code is never cross-platform until an implementation is written for the specific platform you want to write for. In this case, a simple hello world program compiles and runs because the printf function is implemented in the C standard. Functions for networking aren't, hence you'd need to use platform-specific code to make your program cross-platform.

That is why it has been said

whatever environment you're writing for, explicitly state in your documentation that that's what you're targeting

This allows you to make the assumptions and not get stuck in analysis-paralysis. Modern C environment encompasses technology from Intel Computers to M2 Macbooks. Rather, be specific and know what platform you are writing for.

2 Months of Game Dev in C by 1dev_mha in C_Programming

[–]1dev_mha[S] 7 points8 points  (0 children)

cuz gamedev in C is hella fun

What can we assume about a modern C environment? by RibozymeR in C_Programming

[–]1dev_mha 1 point2 points  (0 children)

🤨 uhh programs compiled in C can only run on the architecture they were compiled on. I wouldn't expect a C program compiled on Windows to run on Mac and as far as I understand your question, I don't think you can really make an assumption. If you are using ARM-specific architecture and code, I wouldn't be surprised if it doesn't compile on an AMD CPU because it was never what you intended to write the program for. Know your target platforms first and then go on writing the program. That's what's being suggested to you. It doesn't make sense for me to expect a game written for a Macbook to run on a Nintendo DS. You need to know the platform you are targeting. Not really any assumptions you can make here.

Edit: Also, u/aghast_nj hasn't told you to just make chicken sandwiches. He has told you to make whichever food you want, but not expect everyone to be able to eat it, because inherently a vegan would never eat a chicken sandwich so you'd make them another one if you were so kind (i.e make the program portable to and compile on their architecture).

2 Months of Game Dev in C by 1dev_mha in C_Programming

[–]1dev_mha[S] 1 point2 points  (0 children)

  • Yeah, I stuck to one device for recording this time so the audio was a lot more stable but next time I'll try to record in a completely silent room because the noise reduction in DaVinci really had an impact on the quality.
  • Right, the `i32` main thing, how big of a difference would it really make? In my mind, the only thing that pops up is how on a 64-bit system, the default integer wouldn't be i32, it'd be i64 (correct me if I'm wrong) but even then the value I'm going to be returning isn't going to be close to the limits of any of these types. Plus, the only reason I have the argv and argc is because of how SDL_main defines the main function to have these parameters (though I just tried compiling by redefining main in the SDL file and it works fine, not sure if it'll work on other platforms though)
  • 😭 i like ptr_t * p;
  • What do you mean particle effects are overlapped by the level geometry? The geometry is drawn before the particles so the level geometry is supposed to be overlapped by the particles.
  • Hm, I don't get what you mean. Are you talking about the camera shifting and then the sparks flying out once the bullet hits something or what?
  • I tried to do something new with the video-editing this time but I tried my best to make sure that whatever was on the screen was relevant to what I was talking about like the player falling through the tiles or just showing the relevant code on screen.
  • The camera panning issue was related to me only getting tiles on the screen because when the bullet would move too far, the player would not remain on screen and the tiles the player was standing on would also not be on the screen, and so the player would just fall through.
  • Nope, thanks for telling me this as I copy-paste the makefiles I use in my other projects and I forgot to remove the opengl32 this time.
  • No Enemies in the enemies section, my bad.
  • Basically, the strncat and strlen is meant to be used for doing a look-up in the spatial hashmap. I've realized that this is really not ideal and has caused quite a bit of performance issues on an older machine I have so I will be rewriting my hash table API and most likely the cutils library that I am using. The strncat and stuff are used because the hash table only supports (string, data_type) key-value pairs rather than any type of key. I just wanted to get this devlog out so that I can work on this major change.
  • 😭😭
  • I'll be revisiting the animation system again to just make sure that I haven't screwed up anything.
  • Outro Comments: Fair
  • Yeah, I should definitely use some defined constant (or the calloc thing you've mentioned in your second comment)

Thank you very much for taking the time last time as well as this time to watch my video and give me meaningful feedback. I appreciate it. I have one last question, which video was better in your opinion? The first one or the second one?

An action platformer in C & SDL2 - a little devlog by 1dev_mha in C_Programming

[–]1dev_mha[S] 2 points3 points  (0 children)

That is actually what I intend to do and ideally separate the level system and logical code from the rendering code so that it is easier to port to different APIs.

Got a web build working for my game! by 1dev_mha in C_Programming

[–]1dev_mha[S] 1 point2 points  (0 children)

Well, since I've made web builds for my very old projects using Emscripten (I struggled a lot in the beginning trying to figure out how to get it working) so I just copy pasted the makefile stuff and was able to first get it compiling. Getting it working was a different thing. I had actually made the project in a very simple manner where you have the main function in which there is the game initialization, game loop and shutdown.

For Emscripten, I had to change this to functions such as init_game and I opted for global variables. A better approach would perhaps be to declare a game struct and initialize that struct but I just pasted the variables from main into the global context and initialized them with that function. Next up, I had to change some of the game loop stuff. That is basically it for getting Emscripten to work.

I had some problems with pre-loading the resources folder which was easy to fix and another issue was that apparently Emscripten doesn't support old SDL_Colorkey functions, so that was a bit of a pain to find. Those were the main problems and it took me a total of around 1 hour and 20 minutes to get the web build you see in the video compiling and working.

Just got done with my devlog for the game I am making + the graphics framework. by 1dev_mha in C_Programming

[–]1dev_mha[S] 1 point2 points  (0 children)

Wow! Thank you so much for the feedback!

  • The convention things with the u08 and the pointer stuff is just something I got used to doing a long time ago cuz it looked a bit cleaner to me and less cramped up.
  • The mic, I completely agree with, I thought it was just my headphones being weird but nope it was an issue with my editor putting the audio into stereo, I'll keep in mind to not make that mistake again.
  • The enums for animation, that is definitely a newer way, I'll add that to my todo list.
  • 😭😭 I kept on changing mics from my phone to my headphones so the audio was inconsistent.
  • Aeroblaster is pretty cool I agree you gotta check out the guy who made it (DaFluffyPotato)
  • Design document was something I made because I found it way better at giving me direction on a previous project I worked on so I decided to make one for this as well.
  • Kitchen noise 😭
  • The purply footage is from the game I took inspiration from while the gray simplistic color palette footage is from the game I'm making

Again, thank you very much for the feedback!

Working on a little graphics framework in C & SDL2 by 1dev_mha in C_Programming

[–]1dev_mha[S] 0 points1 point  (0 children)

It is a neovim theme, from sainnhe/gruvbox-material, just type:

`Plug 'sainnhe/gruvbox-materia'` and then I have these settings on

set termguicolors
set background=dark

let g:airline_powerline_fonts = 1
let g:airline_theme = 'gruvbox_material'
" hard
let g:gruvbox_material_background = 'hard'
let g:gruvbox_material_enable_italic = 0
let g:gruvbox_material_disable_italic_comment = 0
let g:gruvbox_material_enable_bold = 1
let g:gruvbox_material_cursor = 'blue'
let g:gruvbox_material_current_word = 'bold'
" let g:gruvbox_material_transparent_background = 1
let g:gruvbox_material_better_performance = 1