An idea I just had.
Displaying 1-3 of 3 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Feyr

I was starting work on my windowing system, and the first class I built was a Rectangle, which I plan to use to pass dimensions around with (since WindowNew(int x, int y, int w, int h) is rather messy, especially if you need more arguments.) My first thought was that it would still be annoying to remember to free the temporary rects I'm passing into my window class.

So my idea was to combine my ClassBuilder with the scheduling lib I released yesterday, and do this:

Class:TempRectangle
Inherit:Rectangle
Comment: Deletes itself after the current VC execution has finished.

Init:int TempRectangleNew(int X, int Y, int W, int H)
InitCode:
EventSetupOnce(0, 'TempRectangleDispose', this);
EndCode

Code:
void TempRectangleDispose() {
Log('Auto-freeing temporary rectangle.');
TempRectangleFree(EventData);
}
EndCode


This gives me a Rectangle (that I can use all the Rectangle* functions I defined, like RectangleIntersect() and RectangleGetOverlap()) that will be deleted as soon as the current VC execution thread is finished. I wrote a little test to see if it was working properly; instantiating a few temporary rectangles, waiting for 10 seconds in a loop, doing a map transition, waiting a further 10 seconds, and then allowing things to stop so the events could be processed. The log file shows that the temporary rectangles were deleted after the map startup script finished executing, which was what I intended.

Obviously it's not something you'd want to use all the time, but I think it will be a useful technique for some of you...now if only I could think of a good way to recreate the auto_ptr class from C++'s STL. ;P

Posted on 2004-10-11 02:29:36

Gayo

you're scary

Posted on 2004-10-11 02:40:08

mastercain

You think everyone is scary :D

Posted on 2004-10-11 02:58:37


Displaying 1-3 of 3 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.