Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 01 Mar 2006
Offline Last Active Yesterday, 09:27 PM

#5314625 Stack overflow for some inputs on the Simple Octree Project

Posted by on 11 October 2016 - 01:08 AM

You are using recursion here. Recursion is typically the wrong answer for a problem in an imperative language. It consumes variable amount of stack, and stack is a precious resource. In windows it is typically 1MB. You can use a recursion if you are sure that it doesn't consume too much stack and it decreases the complexity of the code, but that's not true here. You can use a loop here quite easily.


Other problem that I don't see a stopping condition for the recursion (even if you redesign your code to use loops this is important) if it runs too long. If you try to insert two object at the same place in an Octree it will generate infinite number of children. (Even two objects very near can result a huge amount of levels.) So you must stop at a certain cube size or when it reaches at a certain level.


#5295513 Cannot Find Symbols

Posted by on 07 June 2016 - 11:08 AM

The original code was correct. OnClickListener is an interface, you can't pass values in its anonymous class's constructor.

And your onCLick method has a capital L, that's why it can't override.


#5293509 QuadTree: design and implementation question, (n+1)th topic

Posted by on 26 May 2016 - 12:42 AM

An object itself does not have bounds. And if I attach a DirLight component to an object, what would be the AABB of the object? Or if I attach multiple components to the same object, eg. a RenderableMesh and a Collider. The Collider can be "bigger" than the actual mesh which means the two component's bounds are different. This was the reason why I decided to store the components and not the objects.

Since QuadTrees are used for collision detection (object-object, object-line, object-frustum, etc), the collision bounds should be used for placing the object in the tree. That means Collider component will give the position and size of the object that is used to place the object in the QuadTree.


Or do you want to use the tree for a different purpose?

#5293409 QuadTree: design and implementation question, (n+1)th topic

Posted by on 25 May 2016 - 12:00 PM

As I understand QuadTree, it contains object ids or references to game objects, and not components. For me putting a component into a QuadTree is like a grin without a cat. You can access any component through a game object and the appropriate container. This is an extra indirection comparing to your solution, but I don't think it's much slower, especially because it doesn't need to store so much extra data.


Of course you can put some convenience methods in the QuadTree which return components, but it should use the game object and the component containers to do that.


A small optimization is to store the AABB box besides the game object reference in the QuadTree, it might simplify code and makes it a bit faster.


For the layers it's a solution to create a QuadTree for every layer and a common QuadTree containing all the layers. But that sounds like an overkill. Here the best thing you can do is to check which is faster in your case using a single QuadTree or using separated QuadTrees.

#5289114 Data alignment on ARM processors

Posted by on 28 April 2016 - 11:34 AM

On ARM processor the alignment of data is important. It can read/write much faster at aligned positions. So 2-byte long value should be on an even address, and a 4-byte long value should be on an address dividable by 4. There are codes for unaligned read/write but they are different, longer and slower. The compiler must find out which code has to be used, and generally it does a very good job finding it out, but a few times fails.


These failed cases always contain a reinterpret_cast. In your case this is the C-style (int*) casting. That kind of casting is typically used in loading/saving data, or receiving/sending data through network. In other places it is typically just bad design, and should be avoided.


So I recommend you to concentrate all your code that uses reinterpret_cast into one or few classes, and handle the problem there.


And you can create a function for this kind of reading/writing similar to your doLittleBigEndianConversion. Like this:

float value = doLittleBigEndianConversion(doUnalignedReading(reinterpret_cast<int*>(ucharPtr + offset));

In that function just use the memcpy trick or read the data byte by byte and assemble it with |.

#5286890 Simple code for reading and writing file in UTF-16 mode

Posted by on 14 April 2016 - 11:59 AM

On Windows (but preferably everywhere else too) always use binary mode file streams, because text mode file streams may replace end of line characters:

std::wofstream OutputFileStream(L"C:\\Users\\Administrator\\Desktop\\Test\\Output.txt", std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);

#5285677 Keyboard input Windows

Posted by on 07 April 2016 - 06:33 PM

No. There is no Win32 documentation stating such thing. If you're holding a key you'll just receive multiple WM_KEYDOWN events.

No. When you press a key, a WM_KEYDOWN is sent, and when you release the key, a WM_KEYUP is sent. The WM_KEYPRESSED message repeats during the hold, but it is less useful for game input.

#5261489 Consistent handling of hotkeys in other languages

Posted by on 11 November 2015 - 02:04 AM

Virtual keys have the same physical position in every keyboard layout. So the WASD virtual keys will be on the upper left part on every keyboard. However the text on the actual keys will be different. This is ideal for game control keys, because their position is important, not the text on them. And virtual keys can handle special keys like shift, ctrl etc too.


Off course on the keyboard binding screen you have to translate the name of the virtual key based on the actual keyboard layout with the OS.


If you want to use a textual input, you shouldn't use virtual keys at all. There are many different input methods in different languages that you probably don't want handle. You should use the unicode character codes from the windows messages.


#5153624 glEnableVertexAttribArray Produces "Invalid Value" - OpenGL 3.1

Posted by on 14 May 2014 - 12:31 PM

I get an "invalid value" right after this line:


Any idea why that might be?


Because it needs the attribute index as input and not the VBO identifier.

#5118567 How would you fix this?

Posted by on 21 December 2013 - 08:05 AM

Because this is a compilation error of the precompiled source, the precompiled source is already available. Just dump the precompiled source to a file, and look at the line where the bug happens. Possibly you can find out what was the bug with this.

In the C or C++ file's Property sheet select C/C++ in the tree and then select Preprocessor. There is a switch 'Preprocess to a File'. When you switch it on, it will generate a preprocessed output, instead of compiling the file at the next build. The file will be named after your source file with a .i extension and is put in the intermediate directory where the object files are. (I think it's possible to put elsewhere with a different name, but not in the Express version.)

#5118074 Attempt at A star algorithm not working

Posted by on 19 December 2013 - 05:24 AM

Your getPoint and getNodeFromCoord functions don't always return a value. (Possibly a C heirloom that they can be compiled.) They don't return values if the coordinates you're searching for is not in the list. I assume that out of bounds coordinates are not listed, so their behavior are undefined in this case. And that might cause your problem. Please try if adding proper boundary checking in aStar and error checking in getPoint and getNodeFromCoord solve your problem or not.

#5116796 GNU C++ command line help needed

Posted by on 13 December 2013 - 07:33 PM


"What is in the /Library/Frameworks/SDL2.framework/ directory?"

Your possible answer: "yeah, does that directory take you directly to the header files."

If this is your answer for the question (not clear to me), that's a problem, because you used "/Library/Frameworks/SDL2.framework/Headers" directory for header files in your post.



"My include directory points to a folder containing a folder called SDL2, so I use #include <SDL2/SDL.h>"

But in your code there is no SDL2: "#include<SDL.h>".



"Also I link to:  -lSDL2main -lSDL2"

But in your post you are linking with this: "-lSDL2".


Also you didn't say what was the actual error message. It couldn't find the library file, or the include file? So the linking failed or the compilation?


My guess is that your problem is that you use a Macintosh framework, which is a special beast. You have to use the -framework option to link it, and possible the -F option to set the path where the frameworks are.



#5106031 cache friendly lock free concept?

Posted by on 31 October 2013 - 01:21 PM

There is a shared state in this synchronization (LockState). If you want to access it from both threads you have to synchronize these accesses. One way is to use hardware memory barriers before and after the access of the LockState. This will block the instruction and memory access reordering of the compiler and processor and synchronizes memory. The other way is to use an atomic read/write which locks the the memory bus for the time of the memory access. (This is what a CAS-cycle does.) But in the current state of the code it synchronizes the two threads only with luck.


#5106022 Opengl ?.x and what Tutorial

Posted by on 31 October 2013 - 12:40 PM

At least 3.3. In the 3.0-3.2 versions there were big changes in the structure of the OpenGL just like in DirectX 10. Since then the structure remained just expanded.

This is an OpenGL 3.3 tutorial I found some time ago: http://www.opengl-tutorial.org/


#5092235 Merge tools

Posted by on 07 September 2013 - 01:16 AM

In kdiff3 you have 3 buttons: A, B, C. A is the original and B and C is the two changed version. When you steps on the conflict with the arrow buttons, just press both B and C buttons. It will put both changed codes there. You can even press A, and all the three codes will be inserted. The order of the inserted texts is based on the order you pressed the buttons. But you can even edit the result in the lower merge window.