Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Oct 2013
Offline Last Active Jul 27 2016 07:05 PM

#5137128 Reversing a procedural generation

Posted by TheComet on 07 March 2014 - 08:41 AM

Yet another example is MineCraft. The world is generated by a 32-bit seed, yet it is infinitely large (theoretically). Obviously, you can't reverse that back into a seed, as explained above.


I would like to point out that early versions of MineCraft used to save the differences between the original world generated by the seed and the modified world edited by the player. Alas, the longer the world existed and the more you mined, the larger the save-files became and the longer it took to apply the differences whenever you loaded the world.


I recommend saving absolute states and not relative states. You can optimize it in many ways, one way is only saving the sub-sections that are different than what was generated by the seed.

#5136834 Pathfinding avoid a list of polygon

Posted by TheComet on 06 March 2014 - 09:32 AM

As mentioned multiple times, use navigation meshes, they're your best bet.

Is there a more professional aproach to solve my problem?

The following are two libraries. Recast Navigation generates navigation meshes and Detour is a powerful pathfinder, capable of searching for paths as well as handling the movement of agents.



With that you can

  1. Automatically re-generate navigation meshes on the fly.
  2. Search paths for different sized agents.
  3. Control movement of agents using advanced flocking algorithms.

#5136350 Pathfinding avoid a list of polygon

Posted by TheComet on 04 March 2014 - 12:22 PM

Consider using A-star instead of dijkstra, it'll be a lot faster, and requires only a small modification to dijkstra's to make it work.


Secondly, don't rebuild the path every frame. Maybe space the rebuilds over 60 frames (1 second apart). You might even do it in a background thread so the main thread can continue with processing the game, and take over the newly generated graph once its ready.

#5136293 Unmaintainable code

Posted by TheComet on 04 March 2014 - 07:11 AM

I refuse to believe this is how it was programmed.


He's got to be screwing with us. Obfuscation, perhaps?

#5136291 Code lines number influenced by formatting style.

Posted by TheComet on 04 March 2014 - 07:06 AM

If you get paid by the number of lines created, or if your boss even cares about this as some kind of metric, it's time to switch job.

Or write the most inefficient, crappy code imaginable. Unroll your for-loops, replace arrays with variables having actual numbers in their names, and obviously add "hacker protection code" to impress your boss - that's far more enterprisey.


You'll become the top programmer in no time.


(warning: post contains severe sarcasm)

#5136181 Help with lighting options

Posted by TheComet on 03 March 2014 - 03:14 PM

Okay, upon closer inspection, I understand why the tangent transformation matrix is being used in the pixel shader. It's because there really isn't any other way to do it.


If you did the transformation in the vertex shader, you'd be limited to the number of texcoord channels, but by moving it to the pixel shader, you can go way over the 8-light-limit. You're just trading that off for speed, because for every single pixel on the screen you're doing light_count+1 number of transforms into tangent space.


My educated guess is that the slowdown has something to do with that transformation matrix.


The way I see it, you have two options:

  1. You could consider multipass lighting. Basically, the pixel shader is called once for every light in your scene, and you blend them all together. It's very speedy because no state changes are involved.
  2. You could optimise the crap out of the current shader, and cross your fingers in the hopes of it being a little bit faster.

If you choose number 1), I need to know something: Is it possible to use for-loops inside a technique?

#5136038 Help with lighting options

Posted by TheComet on 03 March 2014 - 03:25 AM

I see a few problems with this shader.


  • The TBN matrix is calculated and used in the pixel shader?! That makes zero sense, and is a slowdown in performance. You should never be doing transformations in pixel shaders. It's enough to do the necessary transformations in the vertex shader and pass what's really required to the pixel shader, since the rasteriser does the necessary interpolations. So: Don't pass the binormal, normal, and tangent to the pixel shader. Instead, construct your TBN matrix in the vertex shader and transform the necessary vectors required for lighting in the vertex shader, and then only output what the pixel shader needs.
  • You are unnecessarily sampling twice from the normal map. Sampling textures is an expensive operation.
  • The input datatype for your pixel shader is VS_OUTPUT. This means the rasteriser is forced to unnecessarily interpolate registers it doesn't really need (POSITION for instance).
  • On some cards, using integers for for-loops is a huge slowdown. I've observed this before on my laptop when writing a fractal shader. The solution was to use floats (you might want to consider using float16 to save space and computational power).
  • You're always allocating space for 16 lights, even though you might only be using 1. This seems inefficient to me.

You might also want to consider using a lower shader model as well. None of the commands in your shader require shader model 3.0.

#5135415 How can i convert texture formats?

Posted by TheComet on 28 February 2014 - 11:32 AM

I'm in no way a whizz in Java, but maybe this will help you:


#5135108 does a dll much differ to a lib?

Posted by TheComet on 27 February 2014 - 11:53 AM

Read this



#5134981 C++ Constructors vs. Init() Functions

Posted by TheComet on 27 February 2014 - 03:36 AM

For large/complex professional game engines, this commonly includes:

don't use the standard new/delete/malloc/free (use some engine-specific replacement / wrapper),
don't use std containers (as they will call new, and custom allocator mechanisms are broken),
don't use exceptions (as writing to satisfy the "strict exception safety" guarantee is hard in C++, there's a performance impact, and some gaming platforms may not even support them),
don't use RTTI or dynamic_cast,

and sometimes includes (these used to be common 10 years ago, but not so much today).

don't use anything in std,
don't use templates.

But that's just C without the ++, what's the point of having all of these fancy features if you can't use them? I'd also think that writing your own containers is more error prone. Then again, I was never affiliated with the gaming industry, I'm sure these decisions are for the best.

#5134728 name mangling..

Posted by TheComet on 26 February 2014 - 06:08 AM

I'm desperately trying to understand what you're trying to ask... Could you repeat that?


Are you asking why they didn't just use the function signature instead of a mangled name?

#5134409 Is there a way to make text progressively appear as typed out on screen?

Posted by TheComet on 25 February 2014 - 07:37 AM

The answer heavily depends on what your programming language is (Java I presume), and what graphics library you're using, but it basically comes down to this: Make a class to encapsulate the "target" string and all of the logic required to "type" out the string. I'd probably have a variable that counts upwards whenever some update() method is called, and use that to progressively append the next character to an output string.


This gives you a basis to also add fancy particle effects or whatever you plan on doing in the future.

#5134391 disasembly of some function

Posted by TheComet on 25 February 2014 - 05:35 AM

The @16? This is a byproduct of C++ called name mangling. In C++ you can have several functions with the same name, which only differ in the number of parameters (or in the case of methods in the classes they belong to). In order to distinguish those, the compiler adds some magic numbers and characters to the function names, usually based on

the number and type of parameters. The specifics however are different for each compiler.

This is incorrect, see my post above.

#5134388 disasembly of some function

Posted by TheComet on 25 February 2014 - 05:14 AM

I'll try and answer what I know.


i do not understand this 0040218B values (what it really stands for? some previous examples seem to suggest that it is real process memory adress where this code will be laying in 9after loading to ram) but i am not sure

On Windows, the address 0x00401000 is a pretty standard address for the main entry point of your program (if no executable packing or other obfuscation has been done). It is however not global to the system, it is relative to the starting point of your program space allocated by the underlying OS, and unsurprisingly starts at 0x00000000.


also what means @16 at the and of _MessageBoxA@16

It is a calling convention of Window's STDCALL. The function being called is always name decorated with a leading underscore, followed by an @, and then the number (in bytes) of arguments passed on the stack. This number will always be a multiple of 4 on a 32-bit aligned machine.


In your example, @16 means that 4 arguments are passed to _MessageBox on the stack. If you were to disassemble the function _MessageBox, you will find the return statement:

ret 16

which will pop the 4 arguments off the stack again before returning.


As to the other questions, I can only make educated guesses.

#5134234 C++ IDEs for Linux

Posted by TheComet on 24 February 2014 - 04:42 PM

I like Visual Studio on Windows, but I actually prefer not using an IDE on Linux.


I like VIM + CMAKE + make at console in a Linux environment, but admittedly using VIM is somewhat self-justifying as an exercise for me to learn VIM, which itself is a useful skill (its nice to know one good non-wysiwyg text editor because you're basically guaranteed to have access to it on any system you can imagine, even minimalist linux systems and often even embedded systems like routers, and/or when you SSH into a remote system). Once you configure CMAKE and generate a make file for your system, building from the shell is as simple as 'make build'. I like VIM as my non-wysiwyg editor, but some people like Emacs, its one of the great nerd holy wars.


If I wanted to be a bit easier on myself, I'd probably substitute SlickEdit in for VIM. It's got powerful shortcuts like VIM/Emacs, and is Linux/Mac/Windows cross-platform, but also offers a better wysiwyg/GUI experience than gVIM.

I've always wondered, how do you effectively debug a program on the command line? Do you really use GDB on the command line? I can't imagine doing that without an IDE to show me variable watches, stack, memory dump, and disassembly.