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)//news.quelsolaar.com/#post81