A taste of my sprite system to come...
BlitzMax Forums/BlitzMax Programming/A taste of my sprite system to come...
| ||
Type ImageState Global ImageStateList:TList = CreateList() Field Alpha# Field Blend Field ClsColor_R, ClsColor_G, ClsColor_B Field Color_R, Color_G, Color_B Field Handle_X#, Handle_Y# Field ImageFont:TImageFont Field LineWidth# Field MaskColor_R, MaskColor_G, MaskColor_B Field Origin_X#, Origin_Y# Field Rotation# Field Scale_X#, Scale_Y# Field Viewport_X, Viewport_Y, Viewport_Width, Viewport_Height ' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' These methods allow you to save and restore the current image settings ' ' Each time you call the save method, the current state is placed on the stack. ' Each time you call the restore method, the last state placed on the stack is restored and removed from the stack. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Function Save() Local IS:ImageState = New ImageState IS.Alpha# = GetAlpha#() IS.Blend = GetBlend() GetClsColor(IS.ClsColor_R, IS.ClsColor_G, IS.ClsColor_B) GetColor(IS.Color_R, IS.Color_G, IS.Color_B) GetHandle(IS.Handle_X#, IS.Handle_Y#) IS.ImageFont = GetImageFont() IS.LineWidth# = GetLineWidth#() GetMaskColor(IS.MaskColor_R, IS.MaskColor_G, IS.MaskColor_B) GetOrigin(IS.Origin_X#, IS.Origin_Y#) IS.Rotation# = GetRotation#() GetScale(IS.Scale_X#, IS.Scale_Y#) GetViewport(IS.Viewport_X, IS.Viewport_Y, IS.Viewport_Width, IS.Viewport_Height) ImageStateList.AddLast(IS) End Function Function Restore() Local IS:ImageState = ImageState(ImageStateList.RemoveLast()) SetAlpha(IS.Alpha#) SetBlend(IS.Blend) SetClsColor(IS.ClsColor_R, IS.ClsColor_G, IS.ClsColor_B) SetColor(IS.Color_R, IS.Color_G, IS.Color_B) SetHandle(IS.Handle_X#, IS.Handle_Y#) SetImageFont(IS.ImageFont) SetLineWidth(IS.LineWidth#) SetMaskColor(IS.MaskColor_R, IS.MaskColor_G, IS.MaskColor_B) SetOrigin(IS.Origin_X#, IS.Origin_Y#) SetRotation(IS.Rotation#) SetScale(IS.Scale_X#, IS.Scale_Y#) SetViewport(IS.Viewport_X, IS.Viewport_Y, IS.Viewport_Width, IS.Viewport_Height) End Function End Type Graphics(640, 480) ImageState.Save() ImageState.Restore() ImageState.Save() ImageState.Save() ImageState.Restore() ImageState.Restore() ' ImageState.Restore() DrawText("Ok!", 16, 16) Flip WaitKey() I don't know why Max doesn't have a set of commands like this, since they're really useful to have! These functions save and restore the current image settings, and it does so in a robust manner which makes use of a stack so you can save the settings at the start of your function, call another function inside your function which also saves the settings and restores them, and then restore them when your function is done playing with them. They'll be used in the sprite system to ensure the system doesn't end up changing your text to black, or multiply blend or something. Just one small portion of my new object oriented sprite/sprite animation system for BlitzMax. (which is nearly complete) Use this however you like. :-) (Now I wait for someone to tell me that all I had to do was save some type somewhere in Max and restore it instead of typing all that crap!) |
| ||
Nope, Max doesn't have anything like this built in. Mark had commented on adding something like this with a lot of rejoicing afterwards, and then it was never added. |
| ||
note to self: document TData And no TMax2DGraphics does not currently extend TDataType so you couldn't have used the following friendly functions: Method ReadObject:Object( stream:TStream ) Method WriteObject( obj:Object,stream:TStream ) In regards to design, a sprite Type that extends TMax2DGraphics may save you some typing but unfortunately we seem to be missing some features in BlitzMax currently. |
| ||
You need to document a lot more than just that. |
| ||
Type TMax2DGraphics already extends TGraphics, so how would you have it extend TDataType as well? |
| ||
By having TGraphics extend TDataType. It's a very top-heavy system where unneccessary and redundant data goes unused. |
| ||
This seems crazy to me, because while TMax2DGraphics might need TGraphics and TDataType, it might not make logicial sense for TGraphics to extend TDataType, and many other types which extend TGraphics might not have any need for TDataType at all. So how would you do this better in some other object oriented language? I'm sure there must be a way or else OOP seems fundamentally flawed. |
| ||
the OO is flawed. In others you would do a double inheritance and inherit from both. But BM does not support multiple inheritance |
| ||
Or you would use interfaces, which is like multiple inheritance without the added bloat. |
| ||
if your system is supposed to act like a state stack, would it not be less confusing to use push() & pop()...save and restore seems a little confusing..not that it really matters. hmmm..will be intersting to see were you go with this :] |
| ||
would it be simpler to simply use setgraphicsdriver glmax2ddriver glpush() glpop() ? :-) |
| ||
Or you would use interfaces, which is like multiple inheritance without the added bloat. Ka-ching! would it not be less confusing to use push() & pop() Speaking of which, I wish someone would standardize ADTs. I don't care if it's push/pop, add/remove, insert/delete or save/restore. As long as it's consistent. |
| ||
"if your system is supposed to act like a state stack, would it not be less confusing to use push() & pop()...save and restore seems a little confusing..not that it really matters." Actually, I chose Save and Restore specifically because I thought PUSH and POP would be confusing. :-) If you didn't have any assembly language background, or had never heard of stacks, and you saw Push() in the code somewhere, would YOU have any idea what it did? I didn't think you would, so that's why I chose save and restore instead. Well let's have a vote then, since I'll be making this thing available to the public and I don't have a personal preference. Push and Pop? Or Save and Restore? CAST YOUR VOTE! Dreamora: Are you implying you can do that? I'm not so sure that doing something at that level is a good idea. I don't know if you'd screw up Max if you did that. There could be states it is settign we don't have access to and resetting them after behind it's back might lead to bad things. Also, that's only useful if it also works in Direct3D. Defoc: "hmmm..will be intersting to see were you go with this :]" Well it'll be done in a few days, or at least done enough to make available to the public. (There might be a few things I will add later.) So you don't have to wait too long, and you'll get to see then what it can do, cause I'll be providing a example of it in action, and listing all the methods and functions available in it. |
| ||
Push and Pop? Or Save and Restore? CAST YOUR VOTE! Actually if it's a matter of states, rather than I/O, wouldn't Store and Retrieve be better candidates? |
| ||
Hey Shawn - Push and Pull would maybe work more for noobies - (removes tongue from cheek!) IPete2. |
| ||
I'm not askign what's better for noobies, there's no doubt of that in my mind. I just want to know what syntax you guys would like to use. :-) |
| ||
Push/Pop. |
| ||
push/pop in my experience push/pop is more often for stack operations... |
| ||
Hello. PutInformationAboutGraphicsStuffInLastPositionOfProperStorageSpace() and GetLastInformationIPutIntoProperStorageSpaceAndLetMeHaveALookPlease() Goodbye. |
| ||
Push / Pop as well Save / Load indicates to me some write / read action to a stream which can be saved. |