• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=conman420;31653301]Just coded an entity manager but if I create a new entity while the entity manager is running Tick() the program crashes. Anyone see why? [cpp] #include "EntityManager.h" EntityManager* Inst = NULL; EntityManager* EntityManager::Instance() { if (Inst == NULL) { Inst = new EntityManager; } return Inst; } EntityManager::EntityManager(void) { } EntityManager::~EntityManager(void) { } void EntityManager::Tick() { std::vector<BaseEntity*>::iterator i; for (i=Entities.begin(); i != Entities.end(); i++) { BaseEntity *ent = *i; ent->Think(); } } BaseEntity* EntityManager::CreateEntity(std::string ID, sf::RenderWindow *App) { BaseEntity* ent = FactoryMap[ID]->Create(App); Entities.push_back(ent); return ent; } void EntityManager::RegisterEntity(std::string Name, BaseFactory* Factory) { std::cout << "Registering: " << Name << "\n"; FactoryMap[Name] = Factory; } [/cpp][/QUOTE] I haven't worked with iterators much but could it possibly be related to you adding an entity while the loop is going through them? That's what it looks like to me.
Is it even possible to copy values from one array to another and still be able to print it? Every single time I've tried to do so, I always get garbled text and the works. EDIT: Nevermind, I got it working. Now I just need to figure out how to make endgame rules for this console hangman game no one will ever play.
[QUOTE=Chrispy_645;31643951]This is pissing me off. :v: Okay, in C#, I have a function with a graphics object. I generate a random curve using the graphics object, and call the DrawCurve() function (which then draws the curve to my bitmap). [code]for (int i = 0; i < 10; i++) { AddHorizontalPaths(cmApply, hmApply, new Pen(color, (float)rand.Next(10, 20))); // cmApply is a bitmap object // hmApply is another bitmap object }[/code] [code]static void AddHorizontalPaths(Graphics cmApply, Graphics hmApply, Pen style) { code that adds random x,y points to a fixed size array cmApply.DrawCurve(style, pt); hmApply.DrawCurve(style, pt); }[/code] However, I try to use a for loop and call my function more than once, so I can draw several curves on my bitmap instead of one, but it's not working. When I look at my bitmap (that my program outputs) it's always one curve being drawn, even though I have a for loop which is meant to draw 10 curves. I tried debugging my program and the curves my function generates is random each time, so I know the problem isn't the program drawing the exact same curve at the exact same point 10 times.[/QUOTE] Maybe you clear your canvas / bitmap with a solid color before drawing each curve ?
C++ & SDL (w/ image/ttf etc.) Three methods, one to draw a collision detection box on screen (x, y) One to draw a collision detection box on a loaded image. One to destroy any collision detection box. It's a scrub question, I know. But I'm an idiot. :3 So if anyone does answer this, please be specific.
I asked this in WAYWO but 've been ignored for now, so can someone answer this: Where can I start programming? What can I do to start?
[QUOTE=Ladowerf;31662685]I asked this in WAYWO but 've been ignored for now, so can someone answer this: Where can I start programming? What can I do to start?[/QUOTE] You need an interpreter/compiler for the language of your choice, a text editor, and a good reference. If you want suggestions on language/platform or reference material, you'll need to tell us what your goal is.
I'm very new to programming and I am making a simple game in C#, XNA and something very strange has happened. I have an int called "what" and a for loop, which looks like this: [code] for (int i = 0; i < 20; i++) { what++; } [/code] Either I have missed something or the value "what" should reach the value 19 and then stop. well, that is not happening. The value increases every frame-loop, reaching insanely high values really quickly. any ideas?
[QUOTE=Felheart;31658798]Maybe you clear your canvas / bitmap with a solid color before drawing each curve ?[/QUOTE] I tried that, hoping it would fix it but nope. If I clear the canvas with a solid colour, I still can't draw any curves... and the final bitmap which my program outputs will also be a solid colour. I'm confused as to why this doesn't work... :(
[QUOTE=Stinger21;31662823]I'm very new to programming and I am making a simple game in C#, XNA and something very strange has happened. I have an int called "what" and a for loop, which looks like this: [code] for (int i = 0; i < 20; i++) { what++; } [/code] Either I have missed something or the value "what" should reach the value 19 and then stop. well, that is not happening. The value increases every frame-loop, reaching insanely high values really quickly. any ideas?[/QUOTE] Is it that there is a space between for and (int or is that allowed in C#?
[QUOTE=Sartek;31663721]Is it that there is a space between for and (int or is that allowed in C#?[/QUOTE] What language doesn't allow a space there? [QUOTE=Stinger21;31662823]I'm very new to programming and I am making a simple game in C#, XNA and something very strange has happened. I have an int called "what" and a for loop, which looks like this: [code] for (int i = 0; i < 20; i++) { what++; } [/code] Either I have missed something or the value "what" should reach the value 19 and then stop. well, that is not happening. The value increases every frame-loop, reaching insanely high values really quickly. any ideas?[/QUOTE] I think you're leaving something out. If you have a problem with some code, post the exact code, don't paraphrase.
So I'm playing with the good old luasocket and trying to get some weather information with google's api. The socket part works fine on normal websites but whenever I try to access something google related it tells me this: [code]The requested URL /ig/api?weather=New+York was not found on this server. That's all we know.[/code] Has anyone had similar problems?
[QUOTE=The-Stone;31664413]So I'm playing with the good old luasocket and trying to get some weather information with google's api. The socket part works fine on normal websites but whenever I try to access something google related it tells me this: [code]The requested URL /ig/api?weather=New+York was not found on this server. That's all we know.[/code] Has anyone had similar problems?[/QUOTE] Are you sure you used the right domain([URL="http://www.google.com/ig/api?weather=New+York)?"]http://www.google.com/ig/api?weather=New+York[/url])?
[QUOTE=kidwithsword;31653202](SFML) If I have a RenderWindow instance declared in my main function and I have a class that is stored in its own header and source files, how can I get a pointer that is part of the class to reference the RenderWindow? I am trying to get a class object to draw a sprite to the RenderWindow without having me explicitly tell it to in the main function every time it needs to be drawn. I'd rather it automatically drew to the RenderWindow via its own draw function.[/QUOTE] You could just declare a variable like this private in the class: [cpp] sf::RenderWindow& window_; [/cpp] And then in the constructor you use an initializer list like so: [cpp] MyClass::MyClass(sf::RenderWindow window) : window_(window) { // ... } [/cpp] And then you can use it just like the other reference to it: [cpp] window_.Draw(sprite_); [/cpp]
[QUOTE=Map in a box;31664457]Are you sure you used the right domain([URL="http://www.google.com/ig/api?weather=New+York)?"]http://www.google.com/ig/api?weather=New+York[/url])?[/QUOTE] Yeah, plus it works now (forgot to set the host in the header part).
I solved the "what" problem. The for loop is within a frame loop. when the next frame starts it re-initializes the for loop's "i" value. increasing "what" 19 times each frame loop. I solved it by resetting "what" to 0 right before the for loop.
[QUOTE=Stinger21;31665169]I solved the "what" problem. The for loop is within a frame loop. when the next frame starts it re-initializes the for loop's "i" value. increasing "what" 19 times each frame loop. I solved it by resetting "what" to 0 right before the for loop.[/QUOTE] Why are you even doing it that way? Why not just use i?
I just spent an hour or two trying to get collision detection working between two squares controlled by wasd and the arrow keys. I got it working but the code was pretty messy and it was a little buggy. Just curious, what methods have you people used for collision detection in XNA? The way i did it was really not ideal.
Sorry for the repost but I've been trying to days to get this sorted and I still don't know why it's not working. I have a weird bug with my code and it must be something fairly obvious and simple but I just can't spot it. I have objects called treeControllers, which draw all the trees and things in a 800x600 area (so I can have a huge map and they only draw when you're near, quicker than having individual trees checking and whatnot). I'm trying to let the player cut down trees for wood, so I'm first looping through all the tree controllers to see which ones are active (aka ones that are drawing trees the player can see). It then loops through all the trees in each tree controller looking for which one is at the mouse position, when it finds it it destroys it (by setting [b]treeController[i].trees[j, 3][/b] to -1) and adds the wood to the inventory. The problem is, it adds 16 wood. And not at one go, over time as space is held. The tree disappears like it should so I know treeController[i].trees[j, 3] is set to -1 (meaning the tree is gone), yet for some reason it still increments up to 16, even if you stop holding space down then come back to where the tree once was and press space again. What have I done wrong? [code] if (currentKeyboardState.IsKeyDown(Keys.Space)) { loop_stop = false; for (int i = 0; i < treeController.Count; i++) //loop through each controller { if (treeController[i].Active) //if its active { for (int j = 0; j < treeController[i].treeNum; j++) //loop through every tree under that controller { if (treeController[i].trees[j, 3] != -1){ //check the tree is active //we check whether its the tree thats clicked on if (Vector2.Distance(mousePos+viewPos,new Vector2(treeController[i].trees[j, 0],treeController[i].trees[j, 1])) < (treeOrigin[treeController[i].trees[j, 2]].X)) { //remove the tree treeController[i].trees[j, 3] = -1; if (treeController[i].trees[j, 5] != -1){ //if it drops an item PickupItem(treeController[i].trees[j, 5]); //take the item } loop_stop = true; //break out of all loops break; } } } if (loop_stop) break; } } }[/code]
How much wood should be dropped? Just one? Only thing I can think of is it is somehow looping that final nested if a few times over before breaking.
Yeah, just one. Hm, I can't for the life of me work out why though, because it breaks in the same place it picks up the wood, and also sets the tree to non active so it shouldn't be able to check the same tree a second time. Also I can confirm my pickup function works fine so the issue isn't there, it actually is being called a number of times so the problem is somwhere in that code.
If all else fails throw a print or something in there to see if it is your if structure.
[QUOTE=reevezy67;31665476]I just spent an hour or two trying to get collision detection working between two squares controlled by wasd and the arrow keys. I got it working but the code was pretty messy and it was a little buggy. Just curious, what methods have you people used for collision detection in XNA? The way i did it was really not ideal.[/QUOTE] If it's just squares, you can use bounding rectangles for all of them. Before you move an object, check its future position (current pos + velocity or whatever) for intersections between other objects, and if it doesn't collide it's ok to move it. It's normally easier to prevent collisions in advance instead of fixing them after they happen. Also, if your objects are moving at any decent speed, you may need to do something to avoid tunnelling. This is where they move fast enough to pass through each other because the simulation never detects that they were touching.
Gah, according to my debugging it goes through the loops once so that's not the isse, but my pickup function is fine too. I'm starting to wonder whether my font was screwed up, but no, that's not it either. Might just resort to punching my screen and swearing a bit.
Anyone using SFML 2.0 with visual studio 2008? Whenever I move the mouse on my project the CPU maxes out and the whole thing freezes until you stop moving the mouse. This problem goes away when I am not running the .exe using visual studio and just click on it in explorer, its very annoying! Fixed it by restarting visual studio a couple of times. Very odd! Edit: It keeps doing it gah :/
[QUOTE=conman420;31671729]Anyone using SFML 2.0 with visual studio 2008? Whenever I move the mouse on my project the CPU maxes out and the whole thing freezes until you stop moving the mouse. This problem goes away when I am not running the .exe using visual studio and just click on it in explorer, its very annoying! Fixed it by restarting visual studio a couple of times. Very odd! Edit: It keeps doing it gah :/[/QUOTE] Doesn't happen to me using VS2010.
Is there an algorithm for iterating an octree with a memory complexity of O(1)? I know one exists for binary trees, but there you have to temporarily re-reference your child nodes, which I suspect could cause problems when the amount of children increases. If there isn't, is there an algorithm with a smaller memory complexity than O(n)? I've already forgotten how to do computer science. [editline]11th August 2011[/editline] Nodes do not have references to their parents.
[i]O(n)[/i] memory complexity for [i]iteration[/i]? Shouldn't it be like [i]O(log n)[/i]? Your stack only needs to be as large as the tree is deep, and any reasonable tree should be around [i]log n[/i]. Unless I've misunderstood. [editline]11th August 2011[/editline] You could make some kind of ridiculous [url=http://en.wikipedia.org/wiki/Threaded_binary_tree]threaded[/url] octree :v:
I just started using C++ and so far I have two problems that I can't solve with googling. Sometimes I see numbers like 10.f or 1,5f. usually as parameters. My guess is that's it's some short kind of way of passing it explicitly as a float but I have not found any written confirmation of that anywhere (it's still just a guess to me). My second problem involves dynamic memory. I want to create an array of dynamic memory that will hold an indefinite amount of elements. I don't mean infinite, I just want to "stack" stuff in there. It seems that is impossible and the only way to achieve the same result is to recreate the array every time except with one element extra and deleting the old one. I have no problems with implementing that if i have to but if there's a more natural way I'd like to know.
[QUOTE=ROBO_DONUT;31674856]You could make some kind of ridiculous [url=http://en.wikipedia.org/wiki/Threaded_binary_tree]threaded[/url] octree :v:[/QUOTE] Huh, threaded binary trees actually look pretty damn useful. Simple iterative traversal? YES PLEASE.
[QUOTE=TommySprat;31675033]I just started using C++ and so far I have two problems that I can't solve with googling. Sometimes I see numbers like 10.f or 1,5f. usually as parameters. My guess is that's it's some short kind of way of passing it explicitly as a float but I have not found any written confirmation of that anywhere (it's still just a guess to me).[/quote] Yeah, those suffixes specify the type. There are suffixes for integer types also. [quote=TommySprat;31675033]My second problem involves dynamic memory. I want to create an array of dynamic memory that will hold an indefinite amount of elements. I don't mean infinite, I just want to "stack" stuff in there. It seems that is impossible and the only way to achieve the same result is to recreate the array every time except with one element extra and deleting the old one. I have no problems with implementing that if i have to but if there's a more natural way I'd like to know.[/QUOTE] The C++ STL provides such containers. Look at vector, list, etc.
Sorry, you need to Log In to post a reply to this thread.