GLBasic forum

Main forum => GLBasic - en => Topic started by: Kitty Hello on 2011-Nov-17

Title: PushState
Post by: Kitty Hello on 2011-Nov-17
Hi,

I wanted to implement a function "PUSHSTATE" that allows you to push/pop the state variables you can set with GLBasic.

I found the ones below. Did I miss something? Do you think the current directory (or any other variable) should not be bothered?

vpx, vpy, vpw, vph // viewport size (GETVIEWPORT)
smoothshading
usescreen
currentdir
font
orientation
Title: Re: PushState
Post by: bigsofty on 2011-Nov-17
So do these state variables replace their function calls?
Title: Re: PushState
Post by: MrTAToad on 2011-Nov-17
All sprite commands ?
Title: Re: PushState
Post by: Kitty Hello on 2011-Nov-17
no replace. Just...
Code (glbasic) Select

PUSHSTATE
CallFunctionThatChangesViewportOrAnything()
POPSTATE
ContinueYourWork()

Title: Re: PushState
Post by: MrTAToad on 2011-Nov-17
Is it actually needed though ?
Title: Re: PushState
Post by: Kitty Hello on 2011-Nov-17
yes. Like x_pushmartix. Its mainly for external libraries or so...
Title: Re: PushState
Post by: Slydog on 2011-Nov-17
I like the idea! 
Great for creating generic libraries.

How about 'ALPHAMODE' too?
Title: Re: PushState
Post by: Slydog on 2011-Nov-17
Ocean, you could use a custom type for doing that, such as: (untested!)
Code (glbasic) Select
TYPE TPushVariable
name$
value#
ENDTYPE

TYPE TPushStack
stack[] AS TPushVariable

FUNCTION Clear:
DIM self.stack[0]
ENDFUNCTION

FUNCTION Push: name$, value#
LOCAL pushVar AS TPushVariable
pushVar.name$ = name$
pushVar.value = value
DIMPUSH self.stack[], pushVar
ENDFUNCTION

FUNCTION Pop#: name$
LOCAL ix%
LOCAL value#
FOR ix = 0 TO LEN(self.stack[])-1
IF self.stack[ix].name$ = name$
value = self.stack[ix].value
DIMDEL self.stack[], ix
RETURN value
ENDIF
ENDIF
RETURN 0 // Not found
ENDFUNCTION

ENDTYPE
GLOBAL pushStack AS TPushStack


Usage:
Code (glbasic) Select
pushStack.Clear()
pushStack.Push("ORIENTATION", GETORIENTATION())
pushStack.Push("TIME", GETTIMERALL())
pushStack.Push("ORIENTATION", GETORIENTATION())
time = pushStack.Pop("TIME")
orientation = pushStack.Pop("ORIENTATION")
orientation = pushStack.Pop("ORIENTATION")


But it's limited to integers and floats.  Could use all strings and convert it to and from I suppose.
I would LOVE function overloading for times like this!
Title: Re: PushState
Post by: hardyx on 2011-Nov-17
Quote from: Kitty Hello on 2011-Nov-17Did I miss something? Do you think the current directory (or any other variable) should not be bothered?
settransparency
setfont

IMHO current directory must to be managed by the library, if is needed.