void framerate::renderFPS() { //Renders the FPS
				al_draw_filled_rectangle(0,0,32,16,al_map_rgba_f(0,0,0,0.5));
				al_draw_rectangle(1,1,31,15,al_map_rgba_f(1,1,1,0.7),1);
				al_draw_ustr(FPSRenderFont,al_map_rgb(255,255,255),6,2,0,FPSText);
				ALLEGRO_USTR* nS = al_ustr_newf("%i",networking::gameServer::getLatency());
				al_draw_ustr(FPSRenderFont,al_map_rgb(255,255,255),6,16,0,nS);
				al_ustr_free(nS);
			}
			void framerate::calculateFramerate() { //Calculate the framerate. This should be called every step of the game loop
				FPS = 1/((al_get_time()-lastFrameTime)); //Calculate the FPS
				if (al_get_time()-lastSlowFPSUpdate>1)
				{
					slowFPS = FPS;
					al_ustr_free(FPSText);
					FPSText = al_ustr_newf("%i",slowFPS);
					lastSlowFPSUpdate = al_get_time();
				}
			
				deltaTime = ((double)(targetFramerate/FPS));

				lastFrameTime = al_get_time();

			}
Exemple #3
0
/** adds or sets a font of a skin.
    The font must be placed manually in the skin's folder.
    The font is not saved in 
    @param skin skin to set the bitmap of.
    @param wgt widget name (UTF-8 string).
    @param res resource name (UTF-8 string).
    @param filename the filename of the font (UTF-8 string).
    @param size the size of the font.
    @param flags font flags, as in al_load_font.
    @return non-zero on success, zero on failure.
 */
int algui_set_skin_font(ALGUI_SKIN *skin, const char *wgt, const char *res, const char *filename, unsigned int size, unsigned int flags) {
    ALLEGRO_USTR *temp;
    int result;
    
    //convert the font to a string
    temp = al_ustr_newf("%s, %ui, %ui", filename, size, flags);

    //set the string    
    result = algui_set_skin_str(skin, wgt, res, al_cstr(temp));
    
    //free the temp string
    al_ustr_free(temp);
    
    return result;
}
Exemple #4
0
/** adds or sets a double value of a skin.
    @param skin skin to set the value of.
    @param wgt widget name (UTF-8 string).
    @param res resource name (UTF-8 string).
    @param val resource value.
    @return non-zero on success, zero on failure.
 */
int algui_set_skin_double(ALGUI_SKIN *skin, const char *wgt, const char *res, double val) {
    ALLEGRO_USTR *temp;
    int result;
    
    //use printf style to add the value
    temp = al_ustr_newf("%g", val);
    
    //set the string
    result = algui_set_skin_str(skin, wgt, res, al_cstr(temp));
    
    //free the temp string
    al_ustr_free(temp);
    
    return result;
}  
Exemple #5
0
/** adds or sets a color of a skin.
    @param skin skin to set the color of.
    @param wgt widget name (UTF-8 string).
    @param res resource name (UTF-8 string).
    @param val resource value.
    @return non-zero on success, zero on failure.
 */
int algui_set_skin_color(ALGUI_SKIN *skin, const char *wgt, const char *res, ALLEGRO_COLOR color) {
    ALLEGRO_USTR *temp;
    unsigned char red, green, blue, alpha;
    int result;
    
    //convert the color to a string
    al_unmap_rgba(color, &red, &green, &blue, &alpha);
    temp = al_ustr_newf("%ui, %ui, %ui, %ui", (unsigned int)red, (unsigned int)green, (unsigned int)blue, (unsigned int)alpha);
    
    //set the skin
    result = algui_set_skin_str(skin, wgt, res, al_cstr(temp));
    
    //free the temp string
    al_ustr_free(temp);
    
    return result;
}
Exemple #6
0
/* Test al_ustr_newf, al_ustr_appendf, al_ustr_vappendf. */
static void t46(void)
{
   ALLEGRO_USTR *us;

   us = al_ustr_newf("%s %c %.2f %.02d", "hõljuk", 'c', ALLEGRO_PI, 42);
   CHECK(0 == strcmp(al_cstr(us), "hõljuk c 3.14 42"));

   CHECK(al_ustr_appendf(us, " %s", "Luftchüssiboot"));
   CHECK(0 == strcmp(al_cstr(us), "hõljuk c 3.14 42 Luftchüssiboot"));

   CHECK(call_vappendf(us, " %s", "χόβερκράφτ"));
   CHECK(0 == strcmp(al_cstr(us), "hõljuk c 3.14 42 Luftchüssiboot χόβερκράφτ"));

   al_ustr_free(us);

   us = al_ustr_new("");
   call_vappendf(us, "%s", "test");
   CHECK(0 == strcmp(al_cstr(us), "test"));
   al_ustr_free(us);
}
			void framerate::initializeFPSRenderer() { //Initializes the font renderer
				FPSRenderFont = gameEngine::resources::fonts.loadFont(":debug:arial.ttf",-10,ALLEGRO_TTF_MONOCHROME);
				FPSText = al_ustr_newf("%i",slowFPS);
			}