Wednesday, November 28, 2012

Multi treading in Excalibur

So what was done, the old event loop looked like this, the problem whit this code was that, the program did not wait for signals, it was busy looping due the clock that needed to be redrawn every 1secund, but I was not able to slow it down because that, will cause the events to be not read at correct time, there was a small delay of 0.1 sec in the loop.


 

After rewriting the code, the main event loop, waits for events before checking, it does not do anything unless something happens.

Membar is only triggered every 2 seconds, because we don't need instant update of memory, nor do we want that.

the Clock loop is only updated every 1 seconds.

  
Well so now Excalibur is Multicore ready, allowing Excalibur to wait on many cores at once.

Of cause it more to it then what I written her, most important is the Mutx protection.


Saturday, November 24, 2012

Dividing the code.

As it is written in the readme Excalibur was a a BlitzBasic program, typically for basic programs is that every thing is written in as one large source file, (not true for all modern basic programs).

One thing I have done for every version of Excalibur is to split the code up, I will explain it.

A typical basic program looks like this, you have every thing mixed, its complicated to find what your looking for, when every thing is mixed, and also in C there is ways you can speed up complication time by dividing the code in separate .c files.


When the content is split up it looks some thing like this:


As you can see now is easy, now is easy to find what your looking for, but when code is split up the compiler won't find what in the other files until linking. The source won't compile or the compiler will complain about incorrect declarations, to solve this problems you most create .h file that defines the functions whit in the *.c files.

This all well, blitz basic does not know about threads or task, every thing run from start to end, whit nothing running parallel, this is bad, in Excalibur you have a clock it has to update for every second, a good program should only do stuff when something happens, the program should wake up when its signaled to do something, then event routine should check what messages has been revised and act on this, well because clock interfered whit this it was no use checking for signals, and so main loop was running and wasting CPU cycles when noting new head happened, due to being single threaded.

I worked on this and by moving the code out of main application, I have made it easy to handle it all whit the clock.c file, I added a clock_proc function that should be spawned as own sub task, so that all rendering of clock was done in parallel whit main program, whit out interfering whit event loop in the main application, some extra work was need to prevent the code from rendering when window was closed, and allow it render when window was reopened, by using Mutex I fixed it so that variable whit clock.c was set on or off to allow rendering, the main event loop in clock.c was also mutex protected to so that only when variable was not being changed, it was allowed to render.

So way did I go trow all this trouble for just a CPU parentage? Well because Excalibur is a start menu, and its always there, you might need that percentage for your video player so it does not skip frames, or your music, or maybe you playing a game, I don't know but if every one wasted CPU cycles then there wont by any left for your applications.

Saturday, November 3, 2012

Its all about the details

Well some work on my hobby, its all about the details.

I'm going back to basic's I know many people like it simple, and are not so interested in all PNG images fancy bling bling, so going back to old colors and styles.

I was looking at workbench prefs and style called XEN, this where you have depth border and you have normal 3d border inside, to make it look like button or fame is not above but inside.

I liked this effect, and so I looked at ways to added it to borders.


Also some work on the selector box has been done, it was not correctly rendered, one pixel wrong there not rendered correct when scroll bar was inside the menu.

I have also worked on the prefs, I have rearrange, the visual effects, so they are nicely grouped by menu and toolbar.
I have also fund a few bugs, they are gone.