|
I've been playing around with some game development concepts and have designed a small, crappy engine that I like to tinker around in. Yesterday I decided to start adding in some rudimentary 2D collision detection and I got it working decently with circles last night before going to bed. However, I'm not particularly happy with how the system works and I'm hoping someone can help me out. I have a base class called hull, which is an abstract class that declares a function call ResolveIntersection, like so: code:
code:
code:
Also does any of this leave anyone with a sour taste in their mouth, is there a better way I could be setting up this collision poo poo? I was thinking I could avoid all of this run time type checking junk by having a list dedicated to each hull type but then every time I add a new hull type I would have to go back and add functions to all the other hulls for that specific type. I'm hoping to extend this stuff into 3 dimensions later so I'm eventually going to have several different hull types. Paiz fucked around with this message at 06:52 on Oct 10, 2009 |
![]() |
|
![]()
|
# ? Jun 11, 2024 05:50 |
|
pseudorandom name posted:The backtrace is a listing of called functions on the stack, in reverse order. The memory map is the layout of memory in your program, which can sometimes be useful for finding problems. Thanks, I fixed the problem as well as those that you mentioned. Would you mind expanding on conc though? I'm not sure what you mean.
|
![]() |
|
teen bear posted:Thanks, I fixed the problem as well as those that you mentioned. Would you mind expanding on conc though? I'm not sure what you mean. You literally never do anything with the variable conc except declare it.
|
![]() |
|
Paiz posted:Also does any of this leave anyone with a sour taste in their mouth, is there a better way I could be setting up this collision poo poo? I was thinking I could avoid all of this run time type checking junk by having a list dedicated to each hull type but then every time I add a new hull type I would have to go back and add functions to all the other hulls for that specific type. I'm hoping to extend this stuff into 3 dimensions later so I'm eventually going to have several different hull types. I can just about guarantee that you don't need multiple hull types in practice. Just write an algorithm that handles convex polygon/-hedron collision and one that does bounding boxes and leave it at that. Also blah blah something about visitor patterns here. Also also if you have to ask whether RTTI is bad performance-wise for your code, it doesn't matter; if your code can't handle the overhead, you'd know already. (EDIT: boost::variant has a visit function that could probably work for multiple dispatch though I never bothered when i did something similar because it didn't matter in the end). Oh, finally. Stop parameterizing templates on the type of vector element. That's just silly. You're going to use floats because that's what graphics APIs like. And frankly you almost certainly don't need the extra precision that a couple is going to give you. Avenging Dentist fucked around with this message at 08:31 on Oct 10, 2009 |
![]() |
|
Avenging Dentist posted:You literally never do anything with the variable conc except declare it. Forgot that was there. Thanks for your help on these questions that seem very obvious now
|
![]() |
|
So, I have an insertion sort and I need to sort files with 10, 100 etc to 1,000,000 using a number of different sorting algorithms. Anyways, the insertion sort does 100,000 along with the rest of the smaller ones without problem and yet the sort for 1,000,000 does not seem to work. I have even let it sit for over an hour at one point. My merge and quick sort work fine with a 1,000,000. So, any clue on what could be causing it to not work? Here is the code I am using at this moment. void insertionSort (vector<int>& vector) { int j, val; for(int i= 1; i < vector.size(); i++){ val = vector[i]; j = i - 1; while((j >= 0) && vector[j] > val){ vector[j + 1] = vector[j]; j = j - 1; } vector [j + 1] = val; } }
|
![]() |
|
How long did the insertion sort of 100,000 take
|
![]() |
|
Why not just load the problem up in a debugger and set some breakpoints instead of asking people to do your homework? (An act which is frowned upon.)
|
![]() |
|
What I'm trying to is so incredibly simple that I feel like I'm missing something huge by not getting it - hopefully just syntax with respect to arrays, though. I'm trying to align two strings in a manner that represents DNA. Given seq1 = ATCTGAT seq2 = TGCATA where each letter-to-letter comparison is given a "score" and matching letters are worth 1 and each mismatch and gap is worth 0, and you're trying to align them in a manner which maximizes the score, it should output numMatches = 4 matchLocs1 = [2 3 6 7] matchLocs2 = [1 3 4 5] seq1aligned = 'AT-CTGAT-' seq2aligned = '-TGC--ATA' We're encouraged to use arrays instead of vectors, and vectors should make this easier probably. I did this to help gauge where the exact matches were: code:
code:
This is how it's supposed to be scored, and C++ throws a complete shitfit whenever I try to do this. It gives me this error for the last line in the above code: quote:incompatible types in assignment of `int' to `int[((unsigned int)((int)len2))]' The max function is doing nothing more than taking in 3 integers as parameters code:
code:
![]()
|
![]() |
|
Given int M[len1][len2], "M[i,j]" is not a thing, nor is "M(i,j)". You want "M[i][j]".
|
![]() |
|
Hahaha gently caress, I kept on referencing algorithms which had it written that way so it didn't stand out to me as strange in my program. Thank you ![]()
|
![]() |
|
Bacon55555 posted:So, I have an insertion sort and I need to sort files with 10, 100 etc to 1,000,000 using a number of different sorting algorithms. Anyways, the insertion sort does 100,000 along with the rest of the smaller ones without problem and yet the sort for 1,000,000 does not seem to work. I have even let it sit for over an hour at one point. My merge and quick sort work fine with a 1,000,000. So, any clue on what could be causing it to not work? Here is the code I am using at this moment. You skipped your computational complexity class, didn't you?
|
![]() |
|
Another stupidly simple thing I'm missing arises: I have a 2D array whose dimensions are dependent on user input, and I need to make a recursive function to retrieve information from that array in a certain way after a bunch of other computations - yet C++ won't let you pass multidimensional arrays through parameters without having an integer for the second parameter. It won't accept integer variables, just integers. I can't make the array a global variable since its parameters won't be known before the user inputs them. What can I do to remedy this? If this helps, it's this from my last post code:
|
![]() |
|
Zakalwe posted:You skipped your computational complexity class, didn't you? That said, Bacon55555, fill in these blanks for me: (107) ** 2 = ______________ (107) * log2(107) = _______________ edit: Here's the punchline: runtime of insertion sort is O(n^2), mergesort is O(n * lg(n))... $ bc -l bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. a = ((10^7)^2) b = ((10^7) * l(10^7)) a 100000000000000 b 161180956.50958319788120000000 a/b 620420.68843321689664469853 l(a/b)/l(10) 5.79268627128627995842 So the insertion sort is 620420 times slower -- almost six orders of magnitude slower -- than a merge or quicksort. This is why nobody ever uses insertion sort in the real world. Dijkstracula fucked around with this message at 23:18 on Oct 10, 2009 |
![]() |
|
That was probably the point of the assignment btw
|
![]() |
|
Whilst farting I posted:C++ won't let you pass multidimensional arrays through parameters without having an integer for the second parameter. It won't accept integer variables, just integers. Yes it will. (No I am not telling you how because that's the wrong solution to your problem.) Whilst farting I posted:
That shouldn't compile in the first place unless you happen to be using some weird amalgamation of C++ and C99. There are lots of solutions to your problem though, such as passing the stride of the matrix into your function, making a matrix class, using boost:mult_array, using an array of pointers-to-arrays (don't do this one).
|
![]() |
|
Is it possible to pad strings with anything other than spaces using printf?
|
![]() |
|
teen bear posted:Is it possible to pad strings with anything other than spaces using printf? No.
|
![]() |
|
Avenging Dentist posted:Yes it will. (No I am not telling you how because that's the wrong solution to your problem.) ![]() quote:That shouldn't compile in the first place unless you happen to be using some weird amalgamation of C++ and C99. I've hardcoded seq1 and seq2 into the program, if that helps to explain it - and I'm using this to compile it http://www.bloodshed.net/devcpp.html quote:There are lots of solutions to your problem though, such as passing the stride of the matrix into your function, making a matrix class, using boost:mult_array, using an array of pointers-to-arrays (don't do this one). What do you mean by passing the stride of the matrix? I can find information about all the other methods, but not this.
|
![]() |
|
I have a random question about const correctness. Lets say i have a class that is a singleton. code:
code:
Is this just really unsafe?
|
![]() |
|
UberJumper posted:I have a random question about const correctness. The "const" qualifier internal just makes the "this" pointer const. Foo::GetInstance is a static method and does not need the "this" pointer at all, so it is unaffected by the "const" modifier.
|
![]() |
|
litghost posted:The "const" qualifier internal just makes the "this" pointer const. Foo::GetInstance is a static method and does not need the "this" pointer at all, so it is unaffected by the "const" modifier. Can this lead to problems? Since wont this essentially be unsafe since the compiler thinks that nothing will change in this class during optimization? I am looking at like 45 classes right now and its littered all over with them.
|
![]() |
|
Whilst farting I posted:I've hardcoded seq1 and seq2 into the program, if that helps to explain it - and I'm using this to compile it No that does not explain it. You're probably using GCC's weird amalgamation of C99 and C++. Whilst farting I posted:http://www.bloodshed.net/devcpp.html This is the shittiest IDE in the world. Seriously, just use Visual Studio or your favorite editor + gcc. (poo poo, even Eclipse is better.) Whilst farting I posted:What do you mean by passing the stride of the matrix? I can find information about all the other methods, but not this. http://en.wikipedia.org/wiki/Stride_of_an_array
|
![]() |
|
UberJumper posted:Can this lead to problems? Since wont this essentially be unsafe since the compiler thinks that nothing will change in this class during optimization? I am looking at like 45 classes right now and its littered all over with them. It leads to problems because you've just negated the solitary benefit of a singleton: that you can (relatively) easily change your code to use multiple instances of the singleton when your design changes. What you've done is basically make a global with slightly more awkward syntax. A more important question is: why would you create a const member function that indirectly calls insert on one of its members? That's the opposite of const.
|
![]() |
|
UberJumper posted:Can this lead to problems? Since wont this essentially be unsafe since the compiler thinks that nothing will change in this class during optimization? I am looking at like 45 classes right now and its littered all over with them. This is a pretty common misconception, but compilers can't optimize around constness in c++ because, as you've demonstrated, they can't really know that you won't modify the object in a const method call. You can obtain a pointer to a member or have one passed into the method, and then there's the existence of const_cast and the mutable keyword...
|
![]() |
|
Avenging Dentist posted:(poo poo, even Eclipse is better.) Eclipse/CDT is a decent IDE. The GDB integration is good, the indexer works well for the "intellisense" style and the programmable for matter is very configurable. On top of that you get the benefit of other Eclipse plugins such as Remote System Explorer and Subclipse. For grinding out simple code I use vim, but I turn to Eclipse/CDT for anything serious. I know it has a stigma of "LOL Java", but it really is a decent IDE.
|
![]() |
|
![]() ![]() I've just started learning basic systems programming (forks, pipes etc) and have hit a wall with implementing pipes. I have two programs 'parent' and 'child'. Parent is launched from the command line, and is supposed to spawn three instances of 'child', and create a loop of pipes between them (parent send messages to child 1, child 1 to child 2 etc). Currently, the parent will fork three times, and the three forked processes will use the exec system call to run child. Now I have my four programs, but I don't know how to set the pipes up between them, as when I call exec the 'child' program has no knowledge of any of 'parent's variables. Is there a simple way of doing this? Also, I know this is not strictly C programming, but it's being written in C so I figured this would be as good a place as any to ask.
|
![]() |
|
Extremely vague assistance: man dup2
|
![]() |
|
Joe Kickass posted:as when I call exec the 'child' program has no knowledge of any of 'parent's variables. Is there a simple way of doing this? code:
That on its own doesn't do you much good because, as you point out yourself, how does the child know it's supposed to be reading from fd=42? so the other neat trick is where dup2() comes in: most unix programs will by default get their input/output from 3 standard file descriptors: stdin(fd=0), stdout(fd=1) and stderr(fd=2). The dup2() system call lets you replace one of these standard file descriptors with your own file descriptor e.g. code:
Pipes are bit more complicated because it's all bidirectional and you can chain them arbitrarily but the same general stuff applies, call dup2() so that the read end of one pipe is duplicated to stdin and the write end of the next pipe in the chain is duplicated to stdout, then fork/exec.
|
![]() |
|
Avenging Dentist posted:This is the shittiest IDE in the world. Seriously, just use Visual Studio or your favorite editor + gcc. (poo poo, even Eclipse is better.) Why? I really like the package manager. Some options are on by default that I have to turn off before I can use it but it's what I use on windows.
|
![]() |
|
Mata posted:Why? I really like the package manager. Some options are on by default that I have to turn off before I can use it but it's what I use on windows. Dev-C++ is like Visual Studio 6 only with less features and a worse interface.
|
![]() |
|
Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here?code:
|
![]() |
|
Alman posted:Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here? We would have to see how you're declaring and initializing maxHeap.
|
![]() |
|
Adhemar posted:We would have to see how you're declaring and initializing maxHeap. code:
|
![]() |
|
Alman posted:Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here?
|
![]() |
|
Standish posted:Run your program in a debugger, get a stack trace and dump the local variables? Nobody wants to debug your program by inspection, especially when you're providing it one post at a time. I wasn't sure what kind of information was necessary. I suppose I should have had the foresight to know that you all would have needed to see how the arrays were initialized, but I don't think there's anything else necessary. Anyway, while running the debugger I found my problem. I was dyslexic and read the wrong function, it was my deleteMax that was throwing the error. And the issue was that I was creating a temporary DualPointer struct without using "new" - I had forgotten to change it in deleteMax when I detected the error earlier on in deleteMin. I appreciate the help, five stars edit: I have having a related problem, though. If I try to scale up the array size to, say, 25,000, I get a segfault when trying to initialize the arrays. Why is that? torb main fucked around with this message at 21:23 on Oct 14, 2009 |
![]() |
|
Alman posted:Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here? Looking at the code, I get the impression you're allocating your arrays as size+1, and indexing them with [1..size]... Please tell me I'm wrong.
|
![]() |
|
Vinterstum posted:Looking at the code, I get the impression you're allocating your arrays as size+1, and indexing them with [1..size]...
|
![]() |
|
Avenging Dentist posted:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html I've never seen any good reason not to use the STL. About the only reason that makes sense is that the compiler doesn't support it correctly, although this shouldn't be a problem with newer systems. If you don't like the default allocators you can write your own. The STL is pretty drat fast if you have a good optimizing compiler with optimization enabled. C++0x will also have features further reducing the speed penalties for using the STL. Honestly, I'd trust using an implementation of the STL & Boost before some EA library.
|
![]() |
|
![]()
|
# ? Jun 11, 2024 05:50 |
|
Actually EASTL fills a niche well. STL allocators are an abomination and have a rather poor interface. Note that they discussed the compiler(s) issue a number of times.
|
![]() |