PushState

Previous topic - Next topic

Kitty Hello

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

bigsofty

So do these state variables replace their function calls?
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrTAToad

All sprite commands ?

Kitty Hello

no replace. Just...
Code (glbasic) Select

PUSHSTATE
CallFunctionThatChangesViewportOrAnything()
POPSTATE
ContinueYourWork()


MrTAToad

Is it actually needed though ?

Kitty Hello

yes. Like x_pushmartix. Its mainly for external libraries or so...

Slydog

I like the idea! 
Great for creating generic libraries.

How about 'ALPHAMODE' too?
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Slydog

#7
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!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

hardyx

#8
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.