Thursday, October 04, 2007

Practice makes perfect

Practice is realy the way to make something perfect. I have rewitten the object storage so many times improving over the previous when I hit a wall since it was easier to rewrite the entire code, then patch the previous design. I did not expect to write over 20 times the same object storage but I guess thats what I needed... Pratice. And yes, I have done it again... I have rewritten the code again but wait... here's why: 1. Objects only understood streams While it was nice on design, it did not work out in usage. I had to make alot of wrapper functions that would take a structure and break it down into values and it required alot of the same code to get to the data. It felt like alot of the code was just to talk between C and my object storage. 2. The alpha was recieved well, but it was hacked a bit together I sent an alpha to some of my Windows Live (MSN) users (zhamilton1@yahoo.co.uk if you want to join) and while it showed of windoing, it was very fixed and very quickly I found the problems when trying to do something simple as making a button class. The whole idea of the object storage was to make things easier not harder. Thanks to the users who tested the alpha. But dont worry, this post is already after I have written the new object storage and I am very near the alpha demo stage that I was on the previous version. I have already used the new design and its so much nicer. Let's say I have the windows structure MSG. And I want to send it to all listeners so they can act on the message. Before hand I would have to break the parameters into a string and then each listener had to repack the structure. Alot of work for nothing. The new code is like this (without error checking): object Core, Message; MSG * WinEvent; /* Retrieves the event core */ Core = EventCore(); /* Creates a message object */ Message = ObjectNew(Core, 0); /* Add the windows message structure to the object */ ObjectAdd(Message, MSG); /* Retrieve the windows message structure from the object */ WinEvent = ObjectCast(Message, MSG); /* Fill the win32 message */ if(!GetMessage( WinEvent, NULL, 0, 0 )) { return false; /* exit the application */ } /* Send the message to all event core listeners */ ObjectSend(Core, Method_EventDispatch, Message); When a listener recieves the message it just does this: MSG * WinEvent; WinEvent = ObjectCast(Message, MSG); You can see that the code is readable and clean. I will get back to the previous status of the moving windows and buttons and I will give some of you a version for feedback. Thanks

No comments: