Members

255

164 Neutral

• Rank
Member
1. Windows GUI frustration...

I can completely understand your frustration. I went through the same thing building a very basic tile editor using Win 32. With all the work your going through you should maybe look at writing your own. I've had some pretty decent success rolling out everything I need for a game or editor just using OpenGL or DirectX. But that really does depend on what kind of functionality your looking for. Also I had a lot of conflicts with DirectX and Win32, so in my case it was better to just build them. The current editor i'm using at work was built with WTL, although its not really supported anymore it does seem to allow for a lot more options. http://wtl.sourceforge.net/ Adam
2. Permutations and combinations

Quote:Original post by Antheus Quote:Say I have a value of 12 and up to a 4 digit number Let 12 be m, and let 4 be n. What are the maximum values for m and n? Quote:find all the combinations Find? Or just count how many there are? If it's find, then the algorithm will inevitably be around n^m, since all possible results need to be printed. The maximum value for m would 180 ( 9 * 20 digits ). The maximum value for n would 20 in my algorithm. The count part is fairly complex so i'll do my best to explain. In the example above lets take 9111. I need to first find 9111 and then count the number of combinations it could possibly have. So in this example it would be 4!/3! since there are only 2 unique numbers one with 3 and the other with one digit. So really the second part of my algorithm is very simple, sort, and calculate the number of permutations. Its finding all the numbers to calculate the permutations that I was afraid was going to be exponential time. Maybe theres another way to approach this. I've tried these. -I started with a 0 - 9^20 approach that just calculates the sum and compares to something else to see if its correct. This didn't even get 1% done in one day. -So then I thought maybe working in reverse with taking the max sum and working down, finding all the possible numbers etc. This isn't seeming possible. Thanks Adam
3. Permutations and combinations

I've been working on a fairly complex algorithm, but ran into a part that i'm having trouble finding a solution for every situation in a reasonable time. Let me start with a smaller version of the problem. Say I have a value of 12 and up to a 4 digit number. I need to find all the combinations of digits that sum up to the value. The numbers i'm working with are much larger like 10^20 but this serves the purpose. I started with a top down approach to filling the number ( more greedy ). My idea is it would go like this for the value 12 9300, 9210, 9111 8400, 8310, 8220, 8211 7500, 7410, 7320, 7311, 7221 6600, 6510, 6420, 6411, 6330, 6321, 6222 5520, 5511 I'm not worried about the differences in numbers 3900, 9300, just that that somewhere in the number are digits 3 and 9. The only problem is my algorithm is basically O( n * n * n * n ) where n is the number of digits. In pseudo code the simpliest solution is a = 9 -> 5 b = 9 -> 0 c = 9 -> 0 d = 9 -> 0 if( a + b + c + d == 12 && NotAlreadyFound ) //Found One So in this brute force method is pretty much 9^n where is the number of digits. There are some ways to improve this method, but it doesn't get it to the O(n) or maybe even O(n^2) time I need. Does anyone have suggestions on how to approach this. Thanks Adam [Edited by - adam23 on May 29, 2010 10:50:47 AM]
4. Binary Heap Insertion

Quote:Original post by Zahlman The array-based implementations are binary trees. It's just that the child pointers are implicit. The implementation takes advantage of the fact that the tree will always be "full" to make this work, setting a mathematical relationship between the index of the parent and the indices of its children. That is an excellent point, and I do appreciate the array based implementations. I did some research on how different implementations were done before starting the tree version, and I have to say the array based method does seem very useful. I do understand the principal of the array based versions being binary tree's where indexing is used to find their children, I guess I worded my response incorrectly. With that said, say i'm building a priority queue to handle pathfinding in a game. I've found that I need more flexibility than a fixed size array that needs to keep doing full copies when it runs low on memory. I'm sure in the end i'll go back to the array based implementation as performing a sort on it is much easier than the tree version, but I really wanted to give this one a try.
5. Binary Heap Insertion

I updated my Heap with the new insertion and it makes a huge difference, theres probably some more optimizations I can do, but here's what I have so far. //! Returns first empty location Leaf< T >* GetFirstEmptySlot( ) { //Determine the path to take in the tree //First find the most significant bit and remove it unsigned int nMask = 1 << 31; while( ( m_nCount & nMask ) == 0 ) { nMask = nMask >> 1; } //Now remove the bit nMask >>= 1; //Traverse down the tree until a parent is found Leaf< T >* pNewParent = m_pRoot; while( nMask > 1 ) { //0 Go Left, else go right if( ( nMask & m_nCount ) == 0 ) { pNewParent = pNewParent->m_pLeft; } else { pNewParent = pNewParent->m_pRight; } nMask >>= 1; } return pNewParent; }
6. VS VS VS VS 10 10 10 Crrrrrrrrrshhhhhh

Mine doesn't crash at all, but it leaves console windows open that can never be closed when the line system( "pause" ) executes. Adam
7. C++ base member access control

I understand the problem with Visual Studio, but I'm wondering why use that method rather than this one? struct Base { protected: void func(int n) {} }; struct Derived : Base { public: template<class T> void func(T const& p) { Base::func(20); } }; Making the base class's function protected seems to give you everything your looking for.
8. Binary Heap Insertion

Quote:Original post by iMalc Here's the trick to filling the tree one level at a time: Take the count of how many items are in the tree prior to the insertion and add one Examine this number in binary, finding the leftmost bit that is a one Skip the leading one bit Repeat the following until you have processed the least significant bit: - if this bit is a zero, go down the tree to the left - if this bit is a one, go down the tree to the right - move along to the next bit You should now be at the point where you want to insert the new node So, imagine a tree with 10 items in it already: 1 / \. / \. 2 3 / \ / \. 4 5 6 7 / \ / 8 9 10(the dots are so that it doesn't screw up the diagram) Also note that the numbers shown are not in heap-order, they're just showing the order that items were inserted. You want to insert the 11th item. 11 in binary is 1011 Remove the leading 1, giving 011 That means go left(0) then right(1), then right(1). Stop and insert the 11th item there. Out of curiosity, why are you implementing a heap using a tree data structure rather than an array? I'm really excited to give this one a try, I've never heard of this insertion approach before Thanks! To be honest I've seen a lot of array based implementations of Binary heaps, but not many binary tree based implementations, so I wanted to see the comparisons when using a "binary tree heap" vs an "array heap" when used in a priority queue. Also one of the limitations I always disliked about the array based implementations is needing to grow the array, and using a binary tree fixes that. I guess call it curiosity more than anything. Thanks again for all the suggestions! Adam
9. Binary Heap Insertion

Quote:Original post by Sneftel A binary heap is filled from the left. Maintain a pointer to the "last" element, that is, the one with the highest depth such that no equal-depth cousin is to the right of it. To move right from there, just walk up parent links until you're at a left child, then move to the parent, then the right child, then to left children until you hit a leaf. Amortized cost of traversing in this manner is O(1). Very cool thanks, this is very similar to an idea that I had late last night, but in my solution it still required an expensive calculation to jump from the far right of the tree to the far left of the tree. I think my solution is figuring out when the tree is filled and doing a quick linear traversal along the far left side, instead of the more complicated check every node approach I was trying to make work.
10. Binary Heap Insertion

So I've been banging my head on a quick way to implement insert for a binary heap data structure built with a binary tree. The problem comes in finding the best possible insertion point to then peculate the node up into its position. Heres the algorithm i'm running now for insert which is way to slow. //! Insert a new item into the heap void Insert( T data ) { Leaf<T>* pNewNode = GetNewLeaf( data ); Leaf< T >* pBestParent = NULL; if( m_pRoot == NULL ) { m_pRoot = pNewNode; } else { int nDepth = 0; pBestParent = GetPositionInTree( m_pRoot, nDepth ); //See which side to insert the node on if( pBestParent->m_pLeft == NULL ) pBestParent->m_pLeft = pNewNode; else pBestParent->m_pRight = pNewNode; pNewNode->m_pParent = pBestParent; printf( "Depth = %d \n", nDepth ); } //Now time to heapify if( pBestParent != NULL ) HeapifyUp( pBestParent ); } And here is what the recursive call looks like //! Helper returns the best parent for this new node Leaf< T >* GetPositionInTree( Leaf< T >* pLeaf, int& nDepth ) { //Simple check if there is a left and right keep recurring if( pLeaf->m_pLeft != NULL && pLeaf->m_pRight != NULL ) { nDepth++; int nLeftDepth = nDepth; int nRightDepth = nDepth; Leaf< T >* pBestLeft = GetPositionInTree( pLeaf->m_pLeft, nLeftDepth ); Leaf< T >* pBestRight = GetPositionInTree( pLeaf->m_pRight, nRightDepth ); if( nLeftDepth > nRightDepth ) { nDepth = nRightDepth; return pBestRight; } else { nDepth = nLeftDepth; return pBestLeft; } } //No children this is the best parent return pLeaf; } The time to move the node into place is really fast, but I'd like to move my insertion speed to more of a rate of O(1) instead of 0(n) like it is now. So my question is does anyone know of a way I can improve this? Or is there a better way to perform insertion when using a binary tree for holding the data instead of an array? Thanks Adam
11. Generating tangents

I was wondering if anyone knew of a good algorithm for taking a DirectX vertex buffer filled with data, and a DirectX index buffer filled with data, to calculate the tangent of each vert. I am not using DirectX format meshes. The triangles are triangle strips. Basically I want to use this to do normal mapping. Thanks Adam
12. Using RegisterWindowEx

wow, yup thats all I was missing, thanks for catching that.
13. Using RegisterWindowEx

I'm building a tool that needs quite a few free floating child windows. I'm not an expert at Win32 but from the little bits of documentation i've found I need to use WS_EX_TOOLWINDOW window type. So i'm doing this. WNDCLASSEX wc; wc.cbSize = sizeof( WNDCLASSEX ); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = TestCallback; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hInstance; wc.hIcon = ::LoadIcon(0, IDI_APPLICATION); wc.hCursor = ::LoadCursor(0, IDC_ARROW); wc.hbrBackground = (HBRUSH)::GetStockObject(LTGRAY_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = "TestToolWindow"; if( RegisterClassEx( &wc ) == 0 ) { DWORD error = GetLastError( ); Logging::Instance( )->Printf( "Failed to register window, ERROR: %d", error ); } For some reason RegisterClassEx fails with error code 87 ( The classic Invalid Paramter ). Now if I use all the same settings and switch it over to the non ex versions it works fine and I can open all the windows I want. According to the docs they should be identical minus a few extra options. At the time this fails I do already have a main window open and updating. This window uses a DirectX device for rendering. Any ideas? Thanks Adam