Thursday, 22 November 2012

OpenGL Bug Hell

OpenGL is one of the finest rendering API's available, the other being Direct3D.

For anyone who ever used OpenGL, this is worth reading

http://www.opengl.org/wiki/Common_Mistakes

To avoid mindless trial and error hacking ... 

Tuesday, 20 November 2012

...Busy

Well I was busy last year concentrating on a project that made heavy use of virtual memory, this year I have been busy looking at open source, moving from project to project to find inspiration, I still don't have a goal as such, however I am very interested in

Blender
FreeCAD

for all things concerned with Computer Aided Design. Blender seems to be quite difficult to learn, and as a consequence the first simple steps towards CSG were easier in FreeCAD. I would like FreeCAD to look (and feel) a lot more like Autocad, however I understand the Open Cascade API that it was built on is difficult to use, being intellectually demanding.

The other software that I have been looking at includes

WebGL
HTML5
Javascript
Android Development
Cross platform phone development

I'd still like to get my own game done on one of these platforms, I know it is almost easy now using an engine, but I bumped into the old problem of content development. I think this is why I became interested in CAD. I was certainly looking at blender for inspiration on User Interface design.

I also absolutely use Python ... I downloaded a package called Pythonxy over a month ago and set up the control systems toolbox (an achievement worth mentioning) . I am really impressed by the power of MathPlotLib combined with Scipy (scientific python package) and Numpy (numeral python package). I can actually run my old control systems studies in python and see the result plotted on screen.


Sunday, 11 November 2012

My idea, already made !

http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Main_Page

I even thought of the idea of python scripting too !

I was using Opencascade
with WxWidgets and my google efforts brought me to this!


Wednesday, 21 March 2012

Set Theory

I had a code problem that most programmers would be very familiar with. I wanted to create a set of names. The definition of set is basically a number of items where each item must be a unique element. So for example, if I add the name "Dave" twice it only stores one copy of the name. The important requirement was that the set returned the index (number) of the name in the array .. for example

0: Craig
1: Jen
2: Dave
3: Gary
4: Peter

when inserting the name "Dave" I want the number 2 to return from the function.

The easy way to perform this is to say "for each element, if name equals the new Name, return the number".

This method becomes quite slow for very large lists of names. So I wrote this class ...


class ArraySet
{
public:

string& Get(int p)
{
if( p < elems.size() )
{
return elems[p];
}
else return string("");
}

void Append(string &s)
{
elems.push_back(s);
}


vector<string> elems;
};

class TreeNode
{
public:

TreeNode()
{
parent = NULL;
left = right = NULL;
data = -1;
searchVisited = false;
}

TreeNode(TreeNode* pParent)
{
parent = pParent;
left = right = NULL;
data = -1;
searchVisited = false;
}

int data;
bool searchVisited ;

int Insert(string &s2, ArraySet &set)
{
string s1 = "";
s1 = set.Get(data);

if( s1 == s2 )
{
return data;
}
else
{
if( s1 < s2 )
{
if( right )
{
return right->Insert(s2, set);
}
else
{
right = new TreeNode(this);
set.Append(s2);
right->data = set.elems.size()-1;
return right->data;
}
}
else if( s1 > s2 )
{
if( left )
{
return left->Insert(s2, set);
}
else
{
left = new TreeNode(this);
set.Append(s2);
left->data = set.elems.size()-1;
return left->data;
}
}
}
}

void Visit(vector<int> &rmp)
{
if( left )
{
left->Visit(rmp);
}

rmp.push_back(data);

if( right )
{
right->Visit(rmp);
}
}

TreeNode* parent;
TreeNode* left;
TreeNode *right;
};

class TreeIndexedSet
{
public:

TreeIndexedSet()
{
root = NULL;
}

int InsertString(string &str)
{
if( root )
{
return root->Insert(str, m_set);
}
else
{
root = new TreeNode;
m_set.Append(str);
root->data = m_set.elems.size()-1;

return root->data;
}
}

string& LookupString(int p)
{
return m_set.Get(p);
}

void SortRemap()
{
if( m_set.elems.size() > 1000000 )
{
SortRemapIterate();
}
else
{
root->Visit(sortedRemapping);
}
}

void SortRemapIterate()
{
        TreeNode *currNode = root;

        while (true)
        {

            if (currNode == NULL)
                break;

if (currNode->left != NULL && currNode->left->searchVisited != true)
{
currNode = currNode->left;
}
            else if (currNode->right != NULL && currNode->right->searchVisited != true)
            {
currNode = currNode->right;
}
            else if (currNode->searchVisited == false)
            {
sortedRemapping.push_back(currNode->data);
                currNode->searchVisited = true;
            }
else
            {
currNode = currNode->parent;
}

        }
}

vector< int > sortedRemapping;
TreeNode* root;
ArraySet m_set;
};

Tuesday, 24 January 2012

Memory Management ...

My old post on Memory mapped files made me think about how to implement some technology that is rare in current software knowledge bases.

This lead me to delve into my memory for this website ... a strong and free memory manager is available here

http://www.paulnettle.com/

Listen to the music ...
The concept is simple ... to replace the hash table memory management system here by removing calls to malloc and to simply use a memory mapped file to map large areas of the disk to the process, the limitation is theoretically the address space of the program, but normal practical terms limits this to 2GB even for 64 bit applications (citation needed). This means technically that I can have computers use 2GB RAM and 2GB RAM for free!

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366761(v=vs.85).aspx

The function MapViewOfFile(...)
The gives access to a portion of the file in memory, so if for example I open a 2GB file then I can map a portion, say 1MB at the 1.5GB boundary, and all I have to do is supply the numbers for the offsets into the file, then I have 1MB from the 2GB data pool to read and write to. I think this explains why I need a decent memory management implementation to work with.