• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=Dienes;45453367]Remove the "cin >> str;" line, it is what consumes the first word.[/QUOTE] thanks! can't believe that slipped my mind :v:
What's up with this python code? [code] def Fibonacci(n): if(n <= 0): return 0 if(n > 0 and n < 3): return 1 result = 0 preOldResult = 1 oldResult = 1 for x in range(2, n): result = preOldResult + oldResult preOldResult = oldResult oldResult = result return result print(Fibonacci(100000000)) [/code] It works, it's just slow, very slow, C# did it in 374ms (same method, different syntax) Lua did it just a bit faster then C#, what's up with Python? It takes so long to calculate the value, I removed the time module aswell, I left it on overnight with the time module and it still didn't calculate.
Try doing it without recursion, recursion is weird in Python I think.
[QUOTE=reevezy67;45454455]Try doing it without recursion, recursion is weird in Python I think.[/QUOTE] Hmm, I'm doing a major science assignment, so I'm trying to keep everything controlled, and the main thing would be keeping the method the same, I already have done the tests on other languages, and averaged it, I really don't want to go at a different method and have to re-do everything, it turns out I tried it a while ago and managed to get 141 seconds, which is way too long for something like this. Thanks anyway, I'll be sure to add that recursion is messed up in Python in the diary log. I'll just leave it saying it did 141 seconds. It's really odd though.
I've got some trouble with character movement on my 2D game. For example, my character moves at a speed of 50 pixels per second and I encounter an obstacle which is 20 pixels wide, my character just clips through the object (my collision detection checks weather the character is within the object). I'm kinda puzzled on how to solve this issue.
[QUOTE=Edvinas;45456233]I've got some trouble with character movement on my 2D game. For example, my character moves at a speed of 50 pixels per second and I encounter an obstacle which is 20 pixels wide, my character just clips through the object (my collision detection checks weather the character is within the object). I'm kinda puzzled on how to solve this issue.[/QUOTE] You could send a short ray from last position to new position and check if it hits something, if it does hit, adjust the movement to hit the object. A trace that short shouldn't take long, also you can adjust the step till you find a good balance.
[QUOTE=Fantym420;45456564]You could send a short ray from last position to new position and check if it hits something, if it does hit, adjust the movement to hit the object. A trace that short shouldn't take long, also you can adjust the step till you find a good balance.[/QUOTE] By short ray you mean update the objects position by one pixel many times till it reaches 50 and see if it hits something?
[QUOTE=Edvinas;45457715]By short ray you mean update the objects position by one pixel many times till it reaches 50 and see if it hits something?[/QUOTE] No, I mean trace a line (single pixel) from center of your character, to what will be the center of the character in 50 units. If that trace goes inside an obstacle then your character will hit. You can do all this before your character moves, you can also check every two pixels (or three, etc.), so there'd be less points in the line , and if you hit something exit the trace immediately. If you need width testing you can use two points, but you don't need to update the character position till after you check the path. This is just an idea, you can probably find more ways to do collision detection of fast moving objects on Google. I found this over at Stack Exchange, It's a similar problem to yours. [url]http://gamedev.stackexchange.com/questions/18604/how-do-i-handle-collision-detection-so-fast-objects-are-not-allowed-to-pass-thro[/url]
For some reason GCM gives me a 401 when I try to send a request from my server but it works fine when doing it on my local machine. I set the ip for the server key to 0.0.0.0/0 so that shouldn't be an issue. Do an of you guys know what's happening? [code]data = dumps({ "registration_ids": registration_ids, "data": message.as_dict(), }) headers = { 'Authorization': 'key=%s' % google_api_key, 'Content-Type': 'application/json', } req = urllib2.Request('https://android.googleapis.com/gcm/send', data, headers) urllib2.urlopen(req).read()[/code]
Is the correct behaviour for a* searching? The bit I'm concerned about is the path chosen in the rectangle on the right: the path tends towards the end goal rather than from entrance of the rectangle to exit of the rectangle. I presume this is because of the distance heuristic, making the node search favour the nodes closer to the end goal thus pulling the path off course a little bit [IMG]https://dl.dropboxusercontent.com/u/10518681/Screenshots/2014-07-22_13-31-58.png[/IMG] Thanks
It is right. You are obviously using manhattan distance. Try to use euclidean distance and research what a tie-breaker is (related to A*)
Thanks very much! I wondered before if the Manhattan distance approach would actually affect it, I hadn't considered it would cause that problem: [IMG]https://dl.dropboxusercontent.com/u/10518681/Screenshots/2014-07-22_14-09-29.png[/IMG] Seems much more as I had expected, thanks. Thinking about it, it makes sense that the scales of the heuristic and the cost must be the same - something I'd not even considered. I'll look into tie-breaking, thanks for the suggestion.
Oh and if you want to get a _perfect_ path and don't mind enormous extra CPU-Cost you can do a post-processing step called stringpulling. You take the last point and do a "trace" (raycast) to the first point of your route. If it succeeds your remove all points in between. If not you test from the last point to the second point, and so on until you've reached the n-1st point. Then you do the same for the n-1st point... The most important part is that you always go backwards, otherwise might miss some paths (in 3d, not 100% sure if it also happens in 2D) edit: I think there's a way to reduce the cost, but what I've described is the naive way. I think D*,Dual-A* or some other crazy variation of A* will work with less cost and produce even better paths.
Interesting technique. In this case, the absolutely optimal path isn't actually critical - more of an aesthetic. It's just nice to see AI taking the path you'd instinctively take Thanks for your help and suggestions
Trying to fix a problem with my game-loop but came a little unstuck. When you drag or re-size the game window, the processing stops which is fine. The stopwatch keeping track of elapsed time however, doesn't. Which means when you release the mouse the physics freaks out trying to lerp over however long you were messing around with the window. I thought, ok...stop the timer when the window is sized or moved. I found the windows messages WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE which are called [i]once[/i] on entering or exiting the modal size/move loop respectively; Seems good. However, if you click on the title bar but release within approximately half a second or so, the timer doesn't stop (the message obviously isn't posted yet). Anyone know a better solution? (Although, given the rarity of such an action, and as its only half a second, the jumping isn't that bad)
[QUOTE=Lemmingz95;45466253]Trying to fix a problem with my game-loop but came a little unstuck. When you drag or re-size the game window, the processing stops which is fine. The stopwatch keeping track of elapsed time however, doesn't. Which means when you release the mouse the physics freaks out trying to lerp over however long you were messing around with the window. I thought, ok...stop the timer when the window is sized or moved. I found the windows messages WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE which are called [i]once[/i] on entering or exiting the modal size/move loop respectively; Seems good. However, if you click on the title bar but release within approximately half a second or so, the timer doesn't stop (the message obviously isn't posted yet). Anyone know a better solution? (Although, given the rarity of such an action, and as its only half a second, the jumping isn't that bad)[/QUOTE] You could check for large time steps and then throw out that calculation, or could keep track of the average time step and use that if the current step is too large.
[QUOTE=Lemmingz95;45466253]Trying to fix a problem with my game-loop but came a little unstuck. When you drag or re-size the game window, the processing stops which is fine. The stopwatch keeping track of elapsed time however, doesn't. Which means when you release the mouse the physics freaks out trying to lerp over however long you were messing around with the window. I thought, ok...stop the timer when the window is sized or moved. I found the windows messages WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE which are called [I]once[/I] on entering or exiting the modal size/move loop respectively; Seems good. However, if you click on the title bar but release within approximately half a second or so, the timer doesn't stop (the message obviously isn't posted yet). Anyone know a better solution? (Although, given the rarity of such an action, and as its only half a second, the jumping isn't that bad)[/QUOTE] If you aren't calculating the frame time or anything using that stopwatch then just start the stopwatch on start of processing and stop at end of processing to keep it in synch. If the processing function doesn't run then the stopwatch won't continue measuring time.
Has anyone made something like a sword collision for weapons in Source? I want to add a katana blade melee weapon to Source 2007, but I'm not sure how to go about putting collisions on bonemerged things and stuff. Has anyone done anything like that already? And if not, does anyone know a good, efficient method for it?
I'm having a go at writing a basic physics engine in C#/XNA 4.0. There are two types of entity, AABB and Circle, which inherit from PhysicsEntity. I am looking for a 'nice' way of comparing any combination of those two entity types (AABB vs AABB, AABB vs Circle, Circle vs AABB & Circle vs Circle). So far I've thought about: Sorting the pair of PhysicsEntities, but these pairs are generated when a new PhysicsEntity is created or destroyed, so i'd rather not sort a potentially relatively large list every couple of frames. Having a case select based on their type, but from what I can tell that is not allowed. Having a big mess of if statements, but that is going to nasty to extend when more derivatives of PhysicsEntity are added. Storing the two entities as dynamic and having public abstract CompareTo(Circle _circle) & public abstract CompareTo(AABB _aabb) in PhysicsEntity, but that means you have to implement Circle vs AABB in one class, and then re-implement it as AABB vs Circle in the other class. This would save having to re-implement the whole code again in reverse [CODE]class Circle { public bool CompareTo(AABB) { AABB.CompareTo(Circle); } }[/CODE] but it still seems a bit cumbersome to me. Once there are more derivatives of PhysicsEntity the problem only gets worse too, because you end up with more duplicate code, or more methods calling methods. What would be ideal would be some way of having a method that accepts two arguments in either order, like this: [CODE]class Comparator { public static bool Compare(AABB first, AABB second) { first.Position + some maths, second.position + some maths etc } public static bool Compare(( AABB aabb, Circle circle ) or ( Circle circle, AABB aabb )) { aabb.position + some maths, circle.position + some maths etc } public static bool Compare(Circle first, Circle second) { first.Position + some maths, second.position + some maths etc } }[/CODE] I'm relatively new to programming anything at all complicated, so this may actually be part of .NET already, or there may be a way to do it with spooky LINQ stuff, whatever that is. I've only get a a few hundred lines of code at this point, so if you guys know of a good way of doing it that is completely different i'm all ears for that too.
I can't figure out how to shorten this string how I want it to? I've been trying to read up on how to use string.format but it doesn't tell me what I can understand. I'm trying to shorten this number[thumb]http://i.imgur.com/4NZtcyE.png[/thumb] to something like 14.66 instead of all of the extra numbers at the end. I have this [code]love.graphics.printf(string.format("%f", power_last_time),0,gheight/2-360,gwidth,"center")[/code]. I don't know really what else to do. I was going to try and use string.len and then remove the extra characters but there doesn't seem to be a thing to do that.
To get length of string you use # operator, for example #("ABC") would return true, but don't use that. Format with %.2f instead with %f [editline]23rd July 2014[/editline] # also returns length of tables. [editline]23rd July 2014[/editline] Anything with __len metamethod
[QUOTE=All0utWar;45478787]I can't figure out how to shorten this string how I want it to? I've been trying to read up on how to use string.format but it doesn't tell me what I can understand. I'm trying to shorten this number[thumb]http://i.imgur.com/4NZtcyE.png[/thumb] to something like 14.66 instead of all of the extra numbers at the end. I have this [code]love.graphics.printf(string.format("%f", power_last_time),0,gheight/2-360,gwidth,"center")[/code]. I don't know really what else to do. I was going to try and use string.len and then remove the extra characters but there doesn't seem to be a thing to do that.[/QUOTE] Do %f.2 for 2 decimals after the decimal point. Equivalently, %f.6 should produce your current output.
[QUOTE=esalaka;45478961]Do %f.2 for 2 decimals after the decimal point. Equivalently, %f.6 should produce your current output.[/QUOTE] It's not %f.2 it's %.2f (unless löve works differently, i don't see why it should) [img]http://i.imgur.com/5OdqVb1.png[/img]
[QUOTE=cartman300;45479119]It's not %f.2 it's %.2f (unless löve works differently, i don't see why it should) [img]http://i.imgur.com/5OdqVb1.png[/img][/QUOTE] Fuck, yeah, you're correct.
[QUOTE=AnonTakesOver;45454385]What's up with this python code? [code] def Fibonacci(n): if(n <= 0): return 0 if(n > 0 and n < 3): return 1 result = 0 preOldResult = 1 oldResult = 1 for x in range(2, n): result = preOldResult + oldResult preOldResult = oldResult oldResult = result return result print(Fibonacci(100000000)) [/code] It works, it's just slow, very slow, C# did it in 374ms (same method, different syntax) Lua did it just a bit faster then C#, what's up with Python? It takes so long to calculate the value, I removed the time module aswell, I left it on overnight with the time module and it still didn't calculate.[/QUOTE] Are you using Python 2? Because in that version range(2,100000000) will actually construct a 100 million element list before it starts iterating over it. Use Python 3 or xrange.
In a C I have this struct representing a rational number and an array of the struct [code] struct rational { int num; int denom; }; struct rational rat[] = {{16,8},{64,4}}; [/code] I want to sort through the array and sort it, but I'm having trouble figuring out the size of the array. [code] int n = sizeof(a); [/code] Gives me 4 which kind of makes sense, but I thought it would be 2. [code] int n = sizeof(a) / sizeof(a[0]); [/code] Gives me 0, which I don't even understand. Eventually I want to do some comparisons like [code] a[0].num / a[0].denom > a[1].num / a[1].denom [/code] is something like that even possible?
I'm really struggling on finding good articles on game state manager implementations (c++). Pretty much this entire week I was trying to make one myself, taking bits from other sources and adding a bit of changes, though I've scrapped the code way too many times as it didn't work in the end. I'd skip this part, though adding the manager later would be even more difficult as I add content to the game. Any suggestions on good articles I should follow? I'm reading SFML Game Development book at the momet and it is pretty much my main source, though I don't understand a lot of things in the game structure chapter, which shows how to implement states. It uses really wild ways to implement them without explaining what things do, just slapping code in my face :v: This is my current attempt (following this article: [url]http://gamedevgeek.com/tutorials/managing-game-states-in-c/[/url]) [url]https://dl.dropboxusercontent.com/u/38084031/C%2B%2B/StateTest.rar[/url]
[QUOTE=wlitsots;45487287]Eventually I want to do some comparisons like [code] a[0].num / a[0].denom > a[1].num / a[1].denom [/code] is something like that even possible?[/QUOTE] It is, but those division operations will obviously only produce integer values. There is a method for calculating integer division with remainder in C, however: [url=http://linux.die.net/man/3/div]div(int numerator, int denominator)[/url]
I have some questions about move semantics. Lets say I have two instances of a class that contains a vector. I want to move the vector of one of these instances to the other. Is this possible? If so, why? Wouldn't the classes become non-contiguous in terms of their memory? Or do vectors(and other containers) work in such a way that they only contain certain pointers to whatever memory they are managing?
[QUOTE=WTF Nuke;45489205]I have some questions about move semantics. Lets say I have two instances of a class that contains a vector. I want to move the vector of one of these instances to the other. Is this possible? If so, why? Wouldn't the classes become non-contiguous in terms of their memory? Or do vectors(and other containers) work in such a way that they only contain certain pointers to whatever memory they are managing?[/QUOTE] You can definitely copy the values from one instance to the other, creating an independent copy while overriding one instance. Depending on the language and use case you also may be able to change references to point to the same instance, which doesn't touch the original data (but one copy may be deleted due to going out of scope).
Sorry, you need to Log In to post a reply to this thread.