Efficient hitboxes?

I’m making an RPG.
There are two things I’d like to accomplish:
1.) I really want my game to be relatively light on RAM
2.) I want to keep my game code concise and readable.
Is there any way in which I can create an efficient hitbox system that differs per room?
for instance, creating a series of hitboxes to accompany each room, like this:

I’d load the hitboxes (not the room) as a png and place it under the actual rendered objects to provide a guide for the player collision detection. Unfortunately, I can’t find a good way to make the hitboxes accurate to the png edges/alpha without creating a seemingly unnecessarily large amount of lines of code listing each collision box.
Does anyone have a way to shorten this process?
I’d also like to figure out how to create a good textbox/dialogue system without loading every single line of text at the start of the game into a million different SDL_TTF objects.

Thanks for reading my essay, and sorry if I sound stupid.

Just have a list of hitboxes as rectangles and check the player’s position against them. And when the player goes to a different room, free the hitboxes for the previous room and load in the ones for the current room.

And by all means, do not load every line of dialog as a separate object.

How experienced with programming are you?

1.) I don’t want to do this, as it will turn half my code into a list of points/dimensions. I have thought about using regex files for each room tho.
2.) I won’t, I was asking about how I could avoid this, like some kind of function that modifies a single object.
3.) I’m pretty well rounded in C++ but am new to SDL2

  1. Huh? Load the hit boxes for the current room from a file into a vector, then iterate through it.
  2. Same idea as #1. Only render the text for the current conversation. Perhaps use something like stb_ttf that lets you render the text dynamically instead of having to create static textures like SDL_TTF does. Even with SDL_TTF though, render the text for the current conversation and then destroy it when the conversation is finished.
  3. I don’t mean to sound snobby or come across like a jerk, but neither of these are hard problems, except maybe for beginners.

Yeah I did come across that idea while thinking today. I actually have a regex parser at the ready, I could just turn that into a function that pushes back into vector(s?) until the EOF and clear it every time I enter a new room
I’ll do some research on sdb_ttf too.
okeg, problem solved, thanks. c:

Additionally, I fixed my text problem easily by doing this:
1.) Created one text object
2.) Make a void function with the parameters (int x, int y, std::string dialogue) that loads the text into said object and renders it to the given position.
3.) Use that function in my main loop
idk why I didn’t think of this earlier

“Hitboxes” specifically refers to boxes, ie the rectangles that @sjr recommended. They’re extremely efficient, at the cost of not being particularly precise if the things you’re trying to hit-test against are not perfectly rectangular.

Using a graphic to determine hits is called masking. It’s a different technique from hitboxes. It’s far more precise, but less efficient both in terms of memory and CPU usage.

If you can spare the memory, a good “best of both worlds” approach to doing precise hit testing with minimal CPU usage is to generate a mask, and also a hit box big enough to encompass the entire mask. Test to see if something hits the box (super cheap), and when you get a hit, only then do you test against the mask (more expensive but now rare.)

How big is this game as in how many rooms do you have ?
Could you just store all these rects on the heap using an unordered_map ?

The key will be the ID of the room and the vector will hold all collisions in the room.
Then you can do an SDL_HasIntersection on the player and each rect in the vector to check for collision.

Depending how you switch rooms etc, maybe you can get away with loading from file without hindering gameplay.