Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Caso extraño variable Int

Estas en el tema de Caso extraño variable Int en el foro de C/C++ en Foros del Web. Buenas! Tengo una variable int llamada FrameCount la cual, muestra un valor incorrecto al menos que haga std::cout<<FrameCount<<std::endl antes del if ((currentTime - t0Value) > ...
  #1 (permalink)  
Antiguo 16/03/2013, 08:51
 
Fecha de Ingreso: septiembre-2012
Mensajes: 38
Antigüedad: 11 años, 7 meses
Puntos: 0
Caso extraño variable Int

Buenas!
Tengo una variable int llamada FrameCount la cual, muestra un valor incorrecto al menos que haga std::cout<<FrameCount<<std::endl antes del if ((currentTime - t0Value) > theTimeInterval).

Código:

Código:
void Engine::calcFPS(double theTimeInterval)
{
	static double fps  = 0.0;          // Set the initial FPS value to 0.0
	// Get the current time in seconds since the program started (non-static, so executed every time)
	double currentTime = glfwGetTime();

	// Ensure the time interval between FPS checks is sane (low cap = 0.1s, high-cap = 10.0s)
	// Negative numbers are invalid, 10 fps checks per second at most, 1 every 10 secs at least.
	if (theTimeInterval < 0.1)
	{
		theTimeInterval = 0.1;
	}
	if (theTimeInterval > 10.0)
	{
		theTimeInterval = 10.0;
	}
    std::cout<<FrameCount<<std::endl; // Si no hago esto, la variable toma valores incorrectos
	// Calculate and display the FPS every specified time interval
	if ((currentTime - t0Value) > theTimeInterval)
	{
		// Calculate the FPS as the number of frames divided by the interval in seconds
		fps = FrameCount/(currentTime - t0Value);
        // Convert the fps value into a string using an output stringstream
        std::ostringstream stream;
        stream << fps;
        std::string fpsString = stream.str();

        // Append the FPS value to the window title details
        theWindowTitle = " | FPS: " + fpsString;

        // Convert the new window title to a c_str and set it
        const char* pszConstString = theWindowTitle.c_str();
        glfwSetWindowTitle(pszConstString);

		// Reset the FPS frame counter and set the initial time to be now
		FrameCount = 0;
		t0Value = glfwGetTime();
	}
	else // FPS calculation time interval hasn't elapsed yet? Simply increment the FPS frame counter
	{
		FrameCount++;
	}
}
  #2 (permalink)  
Antiguo 16/03/2013, 09:03
 
Fecha de Ingreso: agosto-2012
Mensajes: 601
Antigüedad: 11 años, 8 meses
Puntos: 83
Respuesta: Caso extraño variable Int

Igual me equivoco, pero cuando llamas al condicional 'if ((currentTime - t0Value) > theTimeInterval)' tanto si se cumple como si no se cumple se modifica FrameCount no? Si se cumple se reinicia a 0 (linea 36), y si no se cumple se incremente en 1 (linea 41). Cual es el valor mostrado antes del condicional y cual es el mostrado despues?

Saludos
vosk
  #3 (permalink)  
Antiguo 16/03/2013, 09:11
 
Fecha de Ingreso: septiembre-2012
Mensajes: 38
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Caso extraño variable Int

Gracias por la respuesta, pero al parecer ya esta solucionado. He recontruido el proyecto entero y ahora funciona correctamente.

Etiquetas: cout, extraño, valor, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:42.