void SimulateScriptsUpdate()
{
	extern bool gScript_InDraw;
	gosASSERT(!gScript_InDraw);
	gScript_InDraw = true;

	bool DoneViewPort=0;
	
    // do loop
    while(true)
    {
	    if( !DoneViewPort )
	    {
		    DoneViewPort=1;
		    if( 0==Environment.disableZBuffer && 0==Priority )
		    {
			    gos_SetupViewport( 1,1.0,0,0,0.0,0.0,1.0,1.0 );			// If rendering before the game renders, clear the z buffer
		    }
		    else
		    {
			    gos_SetupViewport( 0,1.0,0,0,0.0,0.0,1.0,1.0 );
		    }
	    }

		// clear the print3d margins between each draw
		gos_TextSetRegion(0, 0, Environment.screenWidth, Environment.screenHeight);
#ifdef LAB_ONLY
		double itrTimeIN = gos_GetHiResTime();
#endif
		// real doing....

#ifdef LAB_ONLY
		double itrTimeOUT = gos_GetHiResTime();
		(*pStart)->timeInDraw = itrTimeOUT-itrTimeIN;
#endif

	}

#ifdef LAB_ONLY
// Any lines left to draw?
	FlushLineBuffer();
	// if debugging, draw mouse
	if( gEnableScriptRegions && DoneViewPort )
	{
		if( pInRegionTopmost ) {
			int nStage = 0;
			int nLastPos = 0;
			while(!DrawDebugging(pInRegionTopmost, nStage, nLastPos))
				nStage++;
		}

		DWORD width, height;
		gos_TextSetAttributes( gScriptFont3d, 0xff00ff00, 1, false, true, true, false );
		gos_TextSetPosition( ScriptMousePosition->x, ScriptMousePosition->y );
		gos_TextStringLength( &width, &height, "(%d, %d)", ScriptMousePosition->x, ScriptMousePosition->y );

		ShowSpewDrawBackground( ScriptMousePosition->x, ScriptMousePosition->y, ScriptMousePosition->x+width, ScriptMousePosition->y+ height, 0x7f000000 );
		gos_TextDraw( "(%d, %d)", ScriptMousePosition->x, ScriptMousePosition->y );
	}

	if ( gEnableScriptSpews && DoneViewPort)
		ShowScriptSpewOutput();

	if ( gEnableExpenseReport && DoneViewPort)
		ShowExpenseReport();
	if ( gEnableScriptsLoaded && DoneViewPort)
		ShowScriptsLoaded();
#endif

// Any lines left to draw?
	FlushLineBuffer();

// Set flag to signify we are done with all drawing
	gScript_InDraw = false;

	EndofFrameTextCache();
}
