Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:02:01+00:00 2026-05-29T22:02:01+00:00

I don’t really have any problems with the way I’m rendering now, but I

  • 0

I don’t really have any problems with the way I’m rendering now, but I don’t feel like it’s a very good way of handling rendering. I’m using SDL.

It boils down to this I have some abstract class

class Renderable

With two functions.

virtual void update() = 0;
virtual void doRender(SDL_Surface* surface) = 0;

I have another class

class RenderManager

With 1 std::vector

std::vector<Renderable*> _world;

and 2 std::queue

std::queue<Renderable*> _addQueue;
std::queue<Renderable*> _delQueue;

The two queues hold the renderables that need to be added in the next tick and the ones that need to be removed. Doing everything in one shot gave me problems and now that I think about it, it makes sense (at least the way I did it).

Renderables can add and remove themselves from the RenderManager statically.

Here’s more or less the function handling everything.

void renderAll() {
    std::vector<Renderable*>::iterator begin, end;
    begin = _world.begin();
    end = _world.end();

    for (;begin != end; ++begin) {
        (*begin)->update();
        (*begin)->doRender(_mainWindow); // _mainWindow is the screen of course
    }

    begin = world.begin();

    if (_delQueue.size() > 0) {
        for (unsigned int i = 0; i < _delQueue.size(); i++) {
            std::vector<Renderable*>::iterator del;
            del = std::find(begin, end, _delQueue.front());

            if (del != end) {
                delete *del;
                _world.erase(del);
            }
            _delQueue.pop();
        }
    }

    if (_addQueue.size() > 0) {
        for (unsigned int i = 0; i < _addQueue.size(); i++) {
            Renderable* front = _addQueue.front();

            // _placement is a property of Renderable calculated by RenderManager
            // where they can choose the level they want to be rendered on.
            _world.insert(begin + front->_placement, front);
            _addQueue.pop();
        }
    }
}

I’m kinda sorta newish to C++, but I think I know my way around it on an average scale at least. I’m even newer to SDL, but it seems pretty simple and easy to learn. I’m concerned because I have 3 big loops together. I tried one shotting it but I was having problems with _world resizing during the loop causing massive amounts of destruction. But I’m not claiming I did it right! 🙂

I was thinking maybe something involving threads?

EDIT:

Ahh, sorry for the ambiguity. By “cleaner” I mean more efficient. Also there is no “problem” with my approach, I just feel there’s a more efficient way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:02:02+00:00Added an answer on May 29, 2026 at 10:02 pm

    Firstly, I’d say don’t fix something which isn’t broken. Are you experiencing performance issues? Unless you’re adding and removing ‘renderables’ in huge quantities every frame, I can’t see a huge problem with what you have. Of course, in terms of an overall application it could be a clumsy design, but you haven’t stated what sort of application this is for, so it’s hard, if not impossible to judge.

    However, I can guess and say that because you’re using SDL, there’s a chance you’re developing a game. Personally I’ve always rendered game objects by having a render method for each active object and use an object manager to cycle through pointers to each object every tick and call this render method. Because constantly removing an item from the middle of a vector can cause slowdowns due to internal copying of memory (vectors guarantee contiguous memory), you could have a flag in every object which is set when it is meant to be removed, and periodically the object manager performs ‘garbage collection’, removing all objects with this flag set at the same time, hence reducing the amount of copying that needs to be done. In the mean time before garbage collection occurs, the manager simply ignores the flagged object, not calling its render method each tick – it’s as if it has gone. It’s actually not too dissimilar to what you have here with your queue system, in fact if game objects are derived from your ‘renderable’ class it could be deemed the same.

    By the way is there any reason you’re querying the queue sizes before accessing their elements? If size() is 0, the for loops won’t operate anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't ask why, but is there any way to suppress a failed linking error?
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't overthink this - there's a very commonly used term and I ... have
Don't ask why but I have the requirement to draw a border around certain
DON'T ASK WHY but... I have a regex that needs to be case insensitive
I don't know if this has been asked before, but what i'd like to
I don't like Jackson. I want to use ajax but with Google Gson. So
I don't have any experience in updating a Rails app and when I google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.