One method for implementation of a Game State structure in Dark Basic Pro is to construct a User Defined Data type for a Game State.
The data type for the Game State would store function pointers to functions for handling;
initialization of the Game State, cleanup of the Game State, and rendering.
An example project is attached.
Note: This example requires two third party plugins.
The links are in the main file of the project.
Edit: Here is a code snippet from the attached project
///Game State Setup
type t_GameState
name as string
fnPtrRender as dword
fnPtrSetup as dword
fnPtrCleanup as dword
endtype
///Create a new Game State and push it onto the Game State Stack
function CreateNewGameState(strGameStateName as string, strRenderFn as string, strSetupFn as string, strCleanUpFn as string)
Local fnptrRender as dword
fnptrRender = get ptr to function(strRenderFn)
Local fnptrSetup as dword
fnptrSetup = get ptr to function(strSetupFn)
Local fnptrCleanup as dword
fnptrCleanup = get ptr to function(strCleanUpFn)
if function ptr is valid(fnPtrRender) and function ptr is valid(fnptrSetup) and function ptr is valid(fnptrCleanup)
array insert at bottom GameStates()
GameStates().name = strGameStateName
GameStates().fnPtrRender = fnPtrRender
GameStates().fnPtrCleanup = fnptrCleanup
GameStates().fnPtrSetup = fnptrSetup
else
exitfunction FALSE
endif
//Create all objects for Game State
//and push Game State onto the Game State stack
call function ptr GameStates().fnPtrSetup
endfunction TRUE
///Initialize Global variables for handling Game States
function GameStateSetup()
global dim GameStates() as t_GameState
endfunction
///Load DBPro objects
///and Initialize Global Arrays used in Game State 1
function GameState1Setup()
global dim GameState1Objs() as integer
local Cube1 as integer : Cube1 = reserve free object()
make object box Cube1,32,32,32
array insert at bottom GameState1Objs()
GameState1Objs() = Cube1
bGameState1 = TRUE
endfunction
///Cleanup DBPro Objects and Global Arrays used in Game State 1
function GameState1CleanUp()
for i = 0 to get array count(GameState1Objs(),1)
delete object GameState1Objs(i)
next i
remove from stack GameStates()
endfunction
///Render Loop for Game State 1
function GameState1Render()
d3d_starttext
d3d_Text 1,desktop width()/2-(d3d_gettextwidth(1,"Press #2 to Switch to Game State Two" )/2),80,0,"Press #2 to Switch to Game State Two"
d3d_endtext
yrotate object GameState1Objs(0),hitimer()*0.02
endfunction
///Load DBPro objects
///and Initialize Global Arrays used in Game State 2
function GameState2Setup()
global dim GameState2Objs() as integer
local Cube1 as integer : Cube1 = reserve free object()
make object sphere Cube1, 32
array insert at bottom GameState2Objs()
GameState2Objs() = Cube1
bGameState1 = FALSE
endfunction
///Cleanup DBPro Objects and Global Arrays used in Game State 2
function GameState2CleanUp()
for i = 0 to get array count(GameState2Objs(),1)
delete object GameState2Objs(i)
next i
remove from stack GameStates()
endfunction
///Render Loop for Game State 2
function GameState2Render()
d3d_starttext
d3d_Text 1,desktop width()/2-(d3d_gettextwidth(1,"Press #1 to Switch to Game State One" )/2),80,0,"Press #1 to Switch to Game State One"
d3d_endtext
zrotate object GameState2Objs(0),hitimer()*0.02
endfunction
]
[img]

[/img]





[ic:coffee
WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.