News

News

ComputerWorld Part 1

LovePosted by Eskil Sat, November 20, 2010 00:37:39
Lately I have found that there has been more interest in my code base and all my applications. Over the years I have ammased a great deal of code to make game and application develoment far easier, like asset management, portable platform code, text rendering, file storage, networking, performance messurment and so on. I realize this will be fairly geeky stuff for many readers, but as there are some people who are interested in just seeing how I do things and others that are interested in using some libaries, I will start publishing a series of guides to the different modules as update them. These posts will then eventiualy end up in a revamed developer section of this site.

FORGE

Forge is a set of very basic functions and definitions that are used in all Quel solaar applications. They define such basics as "TRUE" "FALSE" and "uint". Beyond uint it also defines a number of bit specific types.

Forge is assumed to be included in to all files of a project and that makes it very useful for debuging purposes. By defining F_MEMORY_DEBUG macros will replace malloc, free and realloc with debug funtions that will keep track of each allocaton, and then by calling f_debug_mem_print Forge will print out a list of all file names and lines where allocations have been made, how many allocations have been made, freed, and the ammount of memory taken up by each allocator. This is obviusly a very useful tool for tracking down memory leaks. The memory debug system also does some other useful things like over allocating every allocation with 1024 bytes and filling it with a "magic number", it then checks that this portion of the allocation remins untouched to spot if any code inadervenly over writes its allocaion. Some modern operating systems (Like Linux) clears all memory beeing alocated to zeroes, to protect against programs that migh try to allocate large chunks of memory in order to try to find passwords and other sencitive data left by applcations that previously occupied the memory. This can be a bit unfortunate, since it likely to hide some programmer misstakes like failiure to initialize values and pointers to zero. Even if you are running on an operating system that does clear the memory, this is a bug since they usualy dont clear memory that has been freed by the same application as the one allocating it. Therfore the memoy debug system in Forge clears the memory with non NULL grabage to make these misstake easier to find.

The functions f_rand, frandn and frandi are fast and resonably good functions for random number generation. They are based on formulas recomended by mataematisians for use in computer gaphis such as stochastic sampeling.

Forge contains a range of basing vector math functionality that are very similar to many of he funtions found in shading languages. Each have diffent versions for 2 or 3 components and form single and double pressision floating point units. Forge has a long range of generated functions (see f_matrix_operations.c for the code used to generate the code) for constructing 4*4 martices. To construct the 3*3 rotational matrix, you need two vectors (the third can be derived using a cross product), and one of thouse will be dominant if the two vectors arent perfectly perpendicular. There is therefor many ways of constructing a matric, since one of the X, Y and Z vectors can be the dominant and the secondary again can be any of the 3 vectors. Forge therefor defines all possible combinations form both single and double pressission floatiing point values. If the origo argument of any of theese functions is NULL the origo is assumed to be at 0, 0, 0.

f_spline, f_spline2d and f_spline3d are simple b-spline implementations, and f_wiggle, f_wiggel3d and f_wiggel3d creates infinit randomly generated curves with a 3rd degree of continuity ther motion can be described as similar to a wasp flying around a light source. They are very useful for animation and diffent types of noise funtions. Speeking of noise, there is also a fairly fast implementation of Perlin noise, in one, two and three dimentions. The noise funtions are eithe of a single frequency (of one), or multiple recursive frequencies that create a fractal brownian motion.

When engaging in image prosessing it is often good to use a different colorspace then RGB and that is why Forge offers a few conversion funtions for different color spaces. HSV (Hue, Satturation and Value) is a very common color space for color picker interfaces, but has some very bad propperties from a strict color science prespective and should therfor not be used for image prosessing. XYZ is a transformed version of RGB that scales for how diffent colors have different brighness. (R=1 G=1 B=0 Equals a yellow that appears brighter then the Purpule given by R=1 G=0 B=1) Finaly "Lab" is a color space that atempts to create a color space where movement in any direction of the same distane should apperar to yeald the same amount of change in color. Lab is a prefered color space by many to do color corrections.

Almost all math functions have a single and double presision version, but what if you want to make an application that may be compiled in to both (Like Loq Airou)? Well all these funtions are defined without their "f" and "d" postfizes using macros. By default they are defined as float but by defining the symbol F_DOUBLE_PRECISION they get redefined as double. Forge also provides the type "freal" that will be defined to float or double with the same symbol.

Forge can be downloaded here: http://www.quelsolaar.com/quel_solaar.zip

  • Comments(11)

Fill in only if you are not real





The following XHTML tags are allowed: <b>, <br/>, <em>, <i>, <strong>, <u>. CSS styles and Javascript are not permitted.
Posted by Sagan Mon, December 20, 2010 10:45:19

Hey, you mentioned text rendering in the introduction.
I am currently using ftgl to render text, and I'm unhappy with it. It just doesn't work nice with OpenGL 2.0 code.

Do you have a link to your text rendering code? Thanks.

Posted by jwurmz Sun, December 05, 2010 23:35:05

Nice work! I'm very much looking forward to the rest of your articles.

Posted by z Mon, November 22, 2010 17:58:17

LOVE

Posted by Tom Sun, November 21, 2010 16:49:46

thanks for this, I love articles like this one, please keep sharing!

Posted by David Given Sat, November 20, 2010 22:05:42

Beware of public domain; its meaning varies radically from country to country --- some countries don't have it at all (see http://stackoverflow.com/questions/219742/open-source-why-not-release-into-public-domain)!

It sounds like what you're looking for is the WTFPL: http://sam.zoy.org/wtfpl --- pity about the name, though.


Posted by stepan Sat, November 20, 2010 21:47:38

thanks for sharing. In the f_math.c the function d_sqrt is pure magic. Searching for the explanation revealed this interesting article http://www.beyond3d.com/content/articles/8/

Posted by Eskil Sat, November 20, 2010 19:14:37

Sorrry about that. I will add a license text.

I used to have my code in FreeBSD license, but that requires you to give me credit if you use the code. Credit is nice, but i would never be sue or get mad at anyone for not giving me credit, so now i have decided to simply go public domain. In that sense it has no license, but you are right, it would be good to actually publicly state that propperly. Let me know if you find any bugs, or do anything with it!

Posted by tonic Sat, November 20, 2010 14:43:02

I'm also requesting you to include a formal license for the code.


Without a license, by law one should assume that as copyright holder you're keeping all the usage rights and not licensing the code for any kind of use for others. Even if your best intentions would be the opposite.


Of course, without license your code can still be a good reference about how to do something. But in that case one can't just copy-paste relevant parts out of there or include one of your libraries as-is to some other codebase.

Posted by David Given Sat, November 20, 2010 13:08:53

Thanks very much for that --- it looks useful (I think I can use it in a project right now, actually).

However... there doesn't seem to be a license attached. I assume the intention is that people can do whatever they like with it, but unless you actually include a formal license in the package we can't! New BSD or MIT are good choices for do-whatever-you-like licenses; see http://www.opensource.org/licenses/category for details.

Posted by Sam Sat, November 20, 2010 11:10:48

Thanks for the information!

I'm saving this for future reference!

Posted by RobertoGracia Sat, November 20, 2010 01:07:10

Many thanks for sharing. This is a great help to us self-taught