What are different methods for managing data that is stored in the main loop and must be used by other systems?

  • What are different methods for managing data that is stored in the main loop and must be used by other systems? Jack

    This could probably belong on Stackoverflow but I'm not sure.

    I want to change some variables that are in my game loop from different classes, this is probably a simple question with something i'm overlooking but I can't think how to do it easily.

    The only way I can think to do is pass a pointer to whatever class I want to change it in, but that seems stupid as if I want to do something else it means passing another pointer.

    Any ideas to help me?

  • You could pass in the pointer, you could make a pointer global that you could access (or make it a singleton), you could set up an event system that changes those variables when those events get called, you could have your main loop query the objects that it owns to see what the variables should be... there are a lot of ways of doing this but without more specifics it seems like a really rudimentary programming question.

  • I will often create a class specifically made for global data, just because I love having the ease of use, it still keeps my code clean, and namely I have a lot of global data in some projects. I have a large component and entity based system though, so creating an entity and adding components for managing global data is a trivial task. As someone else stated though, it seems like an incomplete question with many varied solutions.

    If you're not already using a system that I described though, I recommend just making the pointer global.

    EDIT: And you're right, this answer is probably slightly better suited for Stack Overflow, though I didn't mind answering it.

  • Having a class change external data that is just in a loop is not good program design. if you're using classes, that data should be in its own class. If instances of other classes need access to that data, then you need to associate the 2 objects in some way, usually by passing in a reference, or by having a mediator class that communicates for you, or perhaps by some sort of messaging system. But generally speaking classes shouldn't be changing data outside of that class, they should be calling methods on other classes who change their own data.

Related questions and answers
  • components total. Or is this even feasible? How much I can accomplish with this approach? In essence I want to be able to do something like this with reasonable efficiency: moving_update(DB...I am studying entity indexed components and came up with a naive C++ implementation which just iterates over all entity "hash tables" and applies update/delete/insert functions in place. I'm having trouble maintaining a logical view of the game world (i.e. updates shouldn't be visible while iterating) and there is no attempt at maintaining spatial or temporal coherence of data. I wonder whether

  • I'm a beginner both in game developping and programming. I'm trying to learn some principle in the building of a game engine. I want to create a simple game, I'm at the point where I'm trying... stuff } the GameEngine constructor will be like this: GameEngine::GameEngine(){ hPlayer = new Player; objects.push_back(hPlayer); } The fact that I'm using a pointer is because I need... for all the objects (nextpos = pos + vel) void rotate_obj(); //rotations are the same for every objects too virtual Polygon generate_mesh() = 0; // the polygons are different } and I have 4

  • line of sight cones etc. EDIT - the naive approach would be to duplicate this code 4 times for each vector, but surely there is a better way? I don't think this is a hard thing to do, but trying to do...I want to include the drawing of other vectors of vertices in the following code, in a number of places it seems easy enough to simply add or multiply size()s of the two vectors, for instance in the first check. But then it gets a bit fuzzy simply because of a lack of understanding. Should I add them together to create a bigger buffer description and copy everything together? Or should I do

  • don't want to find out in the end that I have to rewrite everything again, as a lot of other objects will be working with these data. Sorry if it's a too subjective matter, but I need some insight. I'm... constructing a node object it's done referencing a pool of structure instances to prevent allocation for 2 equal frames. Also the lights are something that I'm not sure on how to handle as I need...well... I'm building the animation system of my game engine (the skeletal and skinned animation stuff), and I came to a point where I added so much functionality in the frame and node structures

  • in the main function * not Finally.. but i believe that te numb_coll problem has something to do with the time and framrate. When running full speed i quickly die upon entering a wall as numb_coll... #include <sstream> // gives access to rand function #include <cstdlib> //gives access to time functions #include <ctime> // mySTOPWATCH i think i'm gonna cry.... =') #include <... == true){/*do something here or i might not need it.....*/} } /* end of if(kbhit())*/ char coll; // the buffer for the collided char theScreen.check_collision(player, xMove, yMove

  • , it is probably fairly difficult to change something like this in the model without having to reanimate it. So this led me to think about a custom model format. I know the basics of what is stored, verts/polygons/etc, but I am wondering if this is something I am right in thinking I probably need to do? If so, are there any good resources on developing a custom model format? Tutorials/samples/anything would...I am using Ogre for my rendering engine, and I planned on just using the .mesh format that is setup by default with Ogre. However, I recently purchased a large number of 3d assets from a company

  • the platform. I have tried many different ways of doing this, such as trying to find the penetration depth and repositioning the player backwards by the penetration depth. Sadly, nothing I've tried seems to work correctly. Player movement ends up being very glitchy and repositions the player when I don't want it to. Part of the reason is probably because I feel like this is something so simple but I'm... want to learn on my own) or the something like the SAT (Separating Axis Theorem) if at all possible. Thank you in advance for your help! void world1Level1CollisionDetection() { for(int i; i < blocks

  • at the source code since I have not a clue to where I should begin). The reason he gave for this was because while it may be slightly slower to do things the naive way, it's not much, and in many cases... the space. Another advantage is when you do remove data, you just tell the list to remove it, and it just needs to change a few pointers, and call a destructor, which can be done pretty quickly.... And I could see a case there for using arrays rather than linked lists, because you would have to make your own (which while simple enough to do, could potentially lead to many more errors). I also

  • to use Flash, but I don't know if it scales well enough. I'm not a scripter, I want some real APIs that I can work with inside a proper IDE. Just for information, I looked at several alternatives, I'm... want to have fun, and c# is fun ;) SDL. Quite frankly, I'd still need to port to all those different SDL implementations. And I don't like OpenGL style programming, it's just plain ugly. And it needs...# bindings get dropped repeatedly. I'm not an engine enthusiast, I just want to make a game. I don't see this happening with Irrlicht. Ogre3D. Way too much work, it's just a graphics engine. Also no multiple

Data information