本文整理汇总了C++中SDL_GetTicks函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetTicks函数的具体用法?C++ SDL_GetTicks怎么用?C++ SDL_GetTicks使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_GetTicks函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
}
}
bool sleeping = false;
unsigned int timeSinceLastEvent = 0;
int lastTime = 0;
while(running)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_JOYAXISMOTION:
if(window.getInputManager()->parseEvent(event))
{
sleeping = false;
timeSinceLastEvent = 0;
}
break;
case InputManager::SDL_USEREVENT_POLLDEVICES:
//try to poll input devices, but do not necessarily wake up...
window.getInputManager()->parseEvent(event);
break;
case SDL_QUIT:
running = false;
break;
}
}
if(sleeping)
{
lastTime = SDL_GetTicks();
sleep(1); //this doesn't need to accurate
continue;
}
int curTime = SDL_GetTicks();
int deltaTime = curTime - lastTime;
lastTime = curTime;
window.update(deltaTime);
Renderer::swapBuffers(); //swap here so we can read the last screen state during updates (see ImageComponent::copyScreen())
window.render();
if(Settings::getInstance()->getBool("DRAWFRAMERATE"))
{
static int timeElapsed = 0;
static int nrOfFrames = 0;
static std::string fpsString;
nrOfFrames++;
timeElapsed += deltaTime;
//wait until half a second has passed to recalculate fps
if (timeElapsed >= 500) {
std::stringstream ss;
ss << std::fixed << std::setprecision(1) << (1000.0f * (float)nrOfFrames / (float)timeElapsed) << "fps, ";
ss << std::fixed << std::setprecision(2) << ((float)timeElapsed / (float)nrOfFrames) << "ms";
fpsString = ss.str();
nrOfFrames = 0;
timeElapsed = 0;
}
Renderer::drawText(fpsString, 50, 50, 0x00FF00FF, Renderer::getDefaultFont(Renderer::MEDIUM));
}
//sleep if we're past our threshold
//sleeping entails setting a flag to start skipping frames
//and initially drawing a black semi-transparent rect to dim the screen
timeSinceLastEvent += deltaTime;
if(timeSinceLastEvent >= (unsigned int)Settings::getInstance()->getInt("DIMTIME") && Settings::getInstance()->getInt("DIMTIME") != 0)
{
sleeping = true;
timeSinceLastEvent = 0;
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000A0);
Renderer::swapBuffers();
}
Log::flush();
}
Renderer::deinit();
SystemData::deleteSystems();
std::cout << "EmulationStation cleanly shutting down...\n";
Log::close();
#ifdef _RPI_
bcm_host_deinit();
#endif
return 0;
}
示例2: place_sides_in_preferred_locations
void play_controller::init(CVideo& video){
util::scoped_resource<loadscreen::global_loadscreen_manager*, util::delete_item> scoped_loadscreen_manager;
loadscreen::global_loadscreen_manager* loadscreen_manager = loadscreen::global_loadscreen_manager::get();
if (!loadscreen_manager)
{
scoped_loadscreen_manager.assign(new loadscreen::global_loadscreen_manager(video));
loadscreen_manager = scoped_loadscreen_manager.get();
}
loadscreen::start_stage("load level");
// If the recorder has no event, adds an "game start" event
// to the recorder, whose only goal is to initialize the RNG
if(recorder.empty()) {
recorder.add_start();
} else {
recorder.pre_replay();
}
recorder.set_skip(false);
bool snapshot = level_["snapshot"].to_bool();
if (level_["modify_placing"].to_bool()) {
LOG_NG << "modifying placing...\n";
place_sides_in_preferred_locations();
}
BOOST_FOREACH(const config &t, level_.child_range("time_area")) {
tod_manager_.add_time_area(t);
}
LOG_NG << "initialized teams... " << (SDL_GetTicks() - ticks_) << "\n";
loadscreen::start_stage("init teams");
resources::teams->resize(level_.child_count("side"));
// This *needs* to be created before the show_intro and show_map_scene
// as that functions use the manager state_of_game
// Has to be done before registering any events!
events_manager_.reset(new game_events::manager(level_));
std::set<std::string> seen_save_ids;
std::vector<team_builder_ptr> team_builders;
int team_num = 0;
BOOST_FOREACH(const config &side, level_.child_range("side"))
{
std::string save_id = get_unique_saveid(side, seen_save_ids);
seen_save_ids.insert(save_id);
if (first_human_team_ == -1) {
const std::string &controller = side["controller"];
if (controller == "human" &&
side["id"] == preferences::login()) {
first_human_team_ = team_num;
} else if (controller == "human") {
first_human_team_ = team_num;
}
}
team_builder_ptr tb_ptr = gamedata_.create_team_builder(side,
save_id, teams_, level_, map_, units_, snapshot, gamestate_.replay_start());
++team_num;
gamedata_.build_team_stage_one(tb_ptr);
team_builders.push_back(tb_ptr);
}
BOOST_FOREACH(team_builder_ptr tb_ptr, team_builders)
{
gamedata_.build_team_stage_two(tb_ptr);
}
示例3: reguleFPS
void reguleFPS(Timer *timer)
{
timer->ellapsedTime = SDL_GetTicks() - timer->lastTime;
if (timer->ellapsedTime < FPS)
SDL_Delay(FPS-timer->ellapsedTime);
}
示例4: PPGetTickCount
// This needs to be visible from outside
pp_uint32 PPGetTickCount()
{
return SDL_GetTicks();
}
示例5: SDL_GetTicks
void RenderBackend::startFrame() {
if (m_isframelimit) {
m_frame_start = SDL_GetTicks();
}
}
示例6: SDL_GetTicks
unsigned int Engine::TimeSDL2Adapter::GetTime() {
return SDL_GetTicks();
}
示例7: while
void GLWindow::MainLoop()
{
bool loop = true;
while (loop)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
for (Helpers::EventHandling::BaseEventHanler *handler : this->eventHandlers)
{
handler->HandleEvent(event);
}
if (event.type == SDL_QUIT)
{
loop = false;
}
if (event.type == SDL_KEYDOWN)
{
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
loop = false;
break;
default:
break;
}
}
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
unsigned long timeSpan = SDL_GetTicks();
for (BaseRenderHandler *handler : this->renderHandlers)
{
handler->BeforeFrameRender(timeSpan - this->prevFrameStartedTime, timeSpan - this->prevFrameFinishedTime);
}
for (RenderObjectShaderProgram *prog : this->programs)
{
prog->RenderObjects(timeSpan);
}
for (BaseRenderHandler *handler : this->renderHandlers)
{
handler->OnFrameRendering();
}
fpsTimer += timeSpan - this->prevFrameStartedTime;
++fpcChechCount;
if (fpsTimer > FPS_RENEW_CYCLE)
{
this->fps = (float)fpcChechCount / ((float)fpsTimer / FPS_RENEW_CYCLE);
fpsTimer = 0;
fpcChechCount = 0;
}
this->RenderText(5, 5, "FPS: " + std::to_string(fps));
this->prevFrameStartedTime = timeSpan;
unsigned long prevFinishTmp = this->prevFrameFinishedTime;
this->prevFrameFinishedTime = SDL_GetTicks();
for (BaseRenderHandler *handler : this->renderHandlers)
{
handler->AfterFrameRender(this->prevFrameFinishedTime - timeSpan, this->prevFrameFinishedTime - prevFinishTmp);
}
SDL_GL_SwapWindow(this->mainWindow);
}
}
示例8: NameEntry
/* Get pl_name from user; other strings are text displayed by dialog: */
void NameEntry(char* pl_name, const char* s1, const char* s2, const char* s3)
{
char UTF8_buf[HIGH_SCORE_NAME_LENGTH * 3] = {'\0'};
SDL_Rect loc;
SDL_Rect redraw_rect;
int redraw = 0;
int first_draw = 1;
int finished = 0;
Uint32 frame = 0;
Uint32 start = 0;
wchar_t wchar_buf[HIGH_SCORE_NAME_LENGTH + 1] = {'\0'};
const int NAME_FONT_SIZE = 32;
const int BG_Y = 100;
const int BG_WIDTH = 400;
const int BG_HEIGHT = 200;
if (!pl_name)
return;
/* We need to get Unicode vals from SDL keysyms */
SDL_EnableUNICODE(SDL_ENABLE);
DEBUGMSG(debug_highscore, "Enter NameEntry()\n" );
DrawTitleScreen();
/* Red "Stop" circle in upper right corner to go back to main menu: */
if (stop_button)
{
SDL_BlitSurface(stop_button, NULL, screen, &stop_rect);
}
/* Draw translucent background for text: */
{
SDL_Rect bg_rect;
bg_rect.x = (screen->w)/2 - BG_WIDTH/2;
bg_rect.y = BG_Y;
bg_rect.w = BG_WIDTH;
bg_rect.h = BG_HEIGHT;
T4K_DrawButton(&bg_rect, 15, REG_RGBA);
bg_rect.x += 10;
bg_rect.y += 10;
bg_rect.w -= 20;
bg_rect.h = 60;
T4K_DrawButton(&bg_rect, 10, SEL_RGBA);
}
/* Draw headings: */
{
SDL_Surface* surf = T4K_BlackOutline(_(s1),
DEFAULT_MENU_FONT_SIZE, &white);
if (surf)
{
loc.x = (screen->w/2) - (surf->w/2);
loc.y = 110;
SDL_BlitSurface(surf, NULL, screen, &loc);
SDL_FreeSurface(surf);
}
surf = T4K_BlackOutline(_(s2),
DEFAULT_MENU_FONT_SIZE, &white);
if (surf)
{
loc.x = (screen->w/2) - (surf->w/2);
loc.y = 140;
SDL_BlitSurface(surf, NULL, screen, &loc);
SDL_FreeSurface(surf);
}
surf = T4K_BlackOutline(_(s3),
DEFAULT_MENU_FONT_SIZE, &white);
if (surf)
{
loc.x = (screen->w/2) - (surf->w/2);
loc.y = 170;
SDL_BlitSurface(surf, NULL, screen, &loc);
SDL_FreeSurface(surf);
}
}
if (_(s3) != NULL)
T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s %s",_(s1),_(s2),_(s3));
else if(_(s2) != NULL)
T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s %s",_(s1),_(s2));
else
T4K_Tts_say(DEFAULT_VALUE,DEFAULT_VALUE,APPEND,"%s",_(s1));
/* and update: */
SDL_UpdateRect(screen, 0, 0, 0, 0);
while (!finished)
{
start = SDL_GetTicks();
while (SDL_PollEvent(&event))
//.........这里部分代码省略.........
示例9: int
void Enemy::update()
{
m_position.setX(m_position.getX() + 1);
m_position.setY(m_position.getY() + 1);
m_currentFrame = int((SDL_GetTicks() / 100) % 6);
}
示例10: SDL_CreateWindow
void App::run()
{
is_running = true;
//inicjalizacja SDL i utworzenie okan
if(SDL_Init(SDL_INIT_VIDEO) == 0)
{
m_window = SDL_CreateWindow("TANKS", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
AppConfig::windows_rect.w, AppConfig::windows_rect.h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if(m_window == nullptr) return;
if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) return;
if(TTF_Init() == -1) return;
srand(time(NULL)); //inicjowanie generatora pseudolosowego
Engine& engine = Engine::getEngine();
engine.initModules();
engine.getRenderer()->loadTexture(m_window);
engine.getRenderer()->loadFont();
m_app_state = new Menu;
double FPS;
Uint32 time1, time2, dt, fps_time = 0, fps_count = 0, delay = 15;
time1 = SDL_GetTicks();
while(is_running)
{
time2 = SDL_GetTicks();
dt = time2 - time1;
time1 = time2;
if(m_app_state->finished())
{
AppState* new_state = m_app_state->nextState();
delete m_app_state;
m_app_state = new_state;
}
if(m_app_state == nullptr) break;
eventProces();
m_app_state->update(dt);
m_app_state->draw();
SDL_Delay(delay);
//FPS
fps_time += dt; fps_count++;
if(fps_time > 200)
{
FPS = (double)fps_count / fps_time * 1000;
if(FPS > 60) delay++;
else if(delay > 0) delay--;
fps_time = 0; fps_count = 0;
}
}
engine.destroyModules();
}
SDL_DestroyWindow(m_window);
m_window = nullptr;
TTF_Quit();
IMG_Quit();
SDL_Quit();
}
示例11: init_text
void init_text(int splash)
{
char fname[256];
SDL_Surface *tmp;
if (!text_screen)
{
text_screen=SDL_CreateRGBSurface(prSDLScreen->flags,prSDLScreen->w,prSDLScreen->h,prSDLScreen->format->BitsPerPixel,prSDLScreen->format->Rmask,prSDLScreen->format->Gmask,prSDLScreen->format->Bmask,prSDLScreen->format->Amask);
window_screen=SDL_CreateRGBSurface(prSDLScreen->flags,prSDLScreen->w,prSDLScreen->h,prSDLScreen->format->BitsPerPixel,prSDLScreen->format->Rmask,prSDLScreen->format->Gmask,prSDLScreen->format->Bmask,prSDLScreen->format->Amask);
tmp=SDL_LoadBMP(MENU_FILE_TEXT);
if (text_screen==NULL || tmp==NULL)
exit(-1);
text_image=SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
if (text_image==NULL)
exit(-2);
SDL_SetColorKey(text_image,(SDL_SRCCOLORKEY | SDL_RLEACCEL),SDL_MapRGB(text_image -> format, 0, 0, 0));
tmp=SDL_LoadBMP(MENU_FILE_BACKGROUND);
if (tmp==NULL)
exit(-3);
text_background=SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
if (text_background==NULL)
exit(-3);
tmp=SDL_LoadBMP(MENU_FILE_WINDOW);
if (tmp==NULL)
exit(-4);
SDL_Rect dest;
dest.w=32;
dest.h=24;
for (int y=0;y<10;y++)
{
//text_window_background
dest.y=24*y;
for(int x=0;x<10;x++)
{
dest.x=32*x;
SDL_BlitSurface(tmp,NULL,window_screen,&dest);
}
}
SDL_FreeSurface(tmp);
}
if (splash)
{
SDL_Surface *sur;
SDL_Rect r;
int i,j;
obten_colores();
if (skipintro)
goto skipintro;
tmp=SDL_LoadBMP(MENU_FILE_SPLASH);
if (tmp==NULL)
exit(-6);
sur = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
r.x=(text_screen->w - sur->w)/2;
r.y=(text_screen->h - sur->h)/2;
r.h=sur->w;
r.w=sur->h;
SDL_FillRect(text_screen,NULL,0xFFFFFFFF);
for (i=128;i>-8;i-=8)
{
SDL_Delay(50);
SDL_FillRect(text_screen,NULL,0xFFFFFFFF);
SDL_BlitSurface(sur,NULL,text_screen,&r);
fade16(text_screen,i);
text_flip();
}
SDL_Delay(3000);
for(i=0;i<128;i+=16)
{
SDL_Delay(50);
SDL_FillRect(text_screen,NULL,0xFFFFFFFF);
SDL_BlitSurface(sur,NULL,text_screen,&r);
fade16(text_screen,i);
text_flip();
}
for(i=128;i>-8;i-=8)
{
SDL_Delay(50);
text_draw_background();
fade16(text_screen,i);
text_flip();
}
SDL_FreeSurface(sur);
}
else
{
SDL_FillRect(text_screen,NULL,0xFFFFFFFF);
text_flip();
uae4all_resume_music();
}
skipintro:
menu_msg_time=SDL_GetTicks();
}
示例12: vec2f
void Gource::interactUsers() {
// update quad tree
Bounds2D quadtreebounds = user_bounds;
quadtreebounds.min -= vec2f(1.0f, 1.0f);
quadtreebounds.max += vec2f(1.0f, 1.0f);
update_user_tree_time = SDL_GetTicks();
if(userTree != 0) delete userTree;
int max_depth = 1;
//dont use deep quad tree initially when all the nodes are in one place
if(dir_bounds.area() > 10000.0) {
max_depth = gGourceMaxQuadTreeDepth;
}
userTree = new QuadTree(quadtreebounds, max_depth, 1);
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
RUser* user = it->second;
user->updateQuadItemBounds();
userTree->addItem(user);
}
//move users - interact with other users and files
for(std::map<std::string,RUser*>::iterator ait = users.begin(); ait!=users.end(); ait++) {
RUser* a = ait->second;
std::set<int> seen;
std::set<int>::iterator seentest;
std::vector<QuadItem*> inbounds;
int found = userTree->getItemsInBounds(inbounds, a->quadItemBounds);
for(std::vector<QuadItem*>::iterator it = inbounds.begin(); it != inbounds.end(); it++) {
RUser* b = (RUser*) (*it);
if(b==a) continue;
if((seentest = seen.find(b->getTagID())) != seen.end()) {
continue;
}
seen.insert(b->getTagID());
a->applyForceUser(b);
gGourceUserInnerLoops++;
}
a->applyForceToActions();
}
update_user_tree_time = SDL_GetTicks() - update_user_tree_time;
}
示例13: drawBackground
void Gource::draw(float t, float dt) {
display.mode2D();
drawBackground(dt);
if(draw_loading) {
loadingScreen();
draw_loading = false;
return;
}
Frustum frustum(camera);
trace_time = SDL_GetTicks();
mousetrace(frustum,dt);
trace_time = SDL_GetTicks() - trace_time;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
camera.focus();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//draw tree
drawTree(frustum, dt);
glColor4f(1.0, 1.0, 0.0, 1.0);
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
trace_debug ? it->second->drawSimple(dt) : it->second->draw(dt);
}
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
//draw bloom
drawBloom(frustum, dt);
root->drawNames(font,frustum);
if(!(gGourceSettings.hide_usernames || gGourceSettings.hide_users)) {
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
it->second->drawName();
}
}
//draw selected item names again so they are over the top
if(selectedUser !=0) selectedUser->drawName();
if(selectedFile !=0) {
vec2f dirpos = selectedFile->getDir()->getPos();
glPushMatrix();
glTranslatef(dirpos.x, dirpos.y, 0.0);
selectedFile->drawName();
glPopMatrix();
}
if(debug) {
glDisable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
track_users ? user_bounds.draw() : dir_bounds.draw();
}
if(gGourceQuadTreeDebug) {
glDisable(GL_TEXTURE_2D);
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glLineWidth(1.0);
dirNodeTree->outline();
glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
userTree->outline();
}
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
display.mode2D();
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
vec3f campos = camera.getPos();
if(logotex!=0) {
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0, 1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, logotex->textureid);
//.........这里部分代码省略.........
示例14: SDL_GetTicks
void Gource::drawTree(Frustum& frustum, float dt) {
draw_tree_time = SDL_GetTicks();
root->calcEdges();
//switch to 2d
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, display.width, display.height, 0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if(!gGourceSettings.hide_tree) {
glBindTexture(GL_TEXTURE_2D, beamtex->textureid);
root->drawEdgeShadows(dt);
root->drawEdges(dt);
}
//switch back
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//draw shadows
if(!gGourceSettings.hide_users) {
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
it->second->drawShadow(dt);
}
}
if(!gGourceSettings.hide_files) {
root->drawShadows(frustum, dt);
}
drawActions(dt);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if(!trace_debug) {
if(!gGourceSettings.hide_files) {
root->drawFiles(frustum,dt);
}
} else {
root->drawSimple(frustum,dt);
}
draw_tree_time = SDL_GetTicks() - draw_tree_time;
}
示例15: SDL_GetTicks
void Watch::reset()
{
elapsed = lastUpdate = 0;
lastRun = SDL_GetTicks();
}