int update_client_contpre1(void) { int quitflag = 0; // redraw scene if necessary if(force_redraw || fabsf(tcam.mpx-ompx) > 0.001f || fabsf(tcam.mpy-ompy) > 0.01f || fabsf(tcam.mpz-ompz) > 0.001f) { #ifdef RENDER_FACE_COUNT render_face_remain = 6; #else render_vxl_redraw(&tcam, clmap); #endif ompx = tcam.mpx; ompy = tcam.mpy; ompz = tcam.mpz; force_redraw = 0; } #ifdef RENDER_FACE_COUNT if(render_face_remain > 0) render_vxl_redraw(&tcam, clmap); #endif // update FPS counter frame_now = SDL_GetTicks(); fps++; if(frame_now - frame_prev > 1000) { char buf[64]; // topo how the hell did this not crash at 16 --GM sprintf(buf, "iceball | FPS: %d", fps); SDL_WM_SetCaption(buf, NULL); fps = 0; frame_prev = SDL_GetTicks(); } //printf("%.2f",); // draw scene to cubemap SDL_LockSurface(screen); //memset(screen->pixels, 0x51, screen->h*screen->pitch); render_cubemap(screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, clmap); SDL_UnlockSurface(screen); return quitflag; }
int update_client_cont1(void) { int quitflag = 0; // skip while still loading if(mod_basedir == NULL || (boot_mode & 8)) return 0; #ifdef USE_OPENGL if (render_map_visible_chunks_count_dirty(clmap) > 0) force_redraw = 1; #endif // redraw scene if necessary if(force_redraw || fabsf(tcam.mpx-ompx) > 0.001f || fabsf(tcam.mpy-ompy) > 0.01f || fabsf(tcam.mpz-ompz) > 0.001f) { #ifdef RENDER_FACE_COUNT render_face_remain = 6; #else render_vxl_redraw(&tcam, clmap); #endif ompx = tcam.mpx; ompy = tcam.mpy; ompz = tcam.mpz; force_redraw = 0; } #ifdef RENDER_FACE_COUNT if(render_face_remain > 0) render_vxl_redraw(&tcam, clmap); #endif //printf("%.2f",); // draw scene to cubemap SDL_LockSurface(screen); //memset(screen->pixels, 0x51, screen->h*screen->pitch); render_cubemap((uint32_t*)screen->pixels, screen->w, screen->h, screen->pitch/4, &tcam, clmap); // apply Lua HUD / model stuff lua_getglobal(lstate_client, "client"); lua_getfield(lstate_client, -1, "hook_render"); lua_remove(lstate_client, -2); if(!lua_isnil(lstate_client, -1)) { if(lua_pcall(lstate_client, 0, 0, 0) != 0) { printf("Lua Client Error (render): %s\n", lua_tostring(lstate_client, -1)); lua_pop(lstate_client, 1); return 1; } } SDL_UnlockSurface(screen); #ifdef USE_OPENGL SDL_GL_SwapBuffers(); #else SDL_Flip(screen); #endif int msec_wait = 10*(int)(sec_wait*100.0f+0.5f); if(msec_wait > 0) { sec_wait -= msec_wait; SDL_Delay(msec_wait); } SDL_Event ev; while(SDL_PollEvent(&ev)) switch(ev.type) { case SDL_KEYUP: case SDL_KEYDOWN: // inform Lua client lua_getglobal(lstate_client, "client"); lua_getfield(lstate_client, -1, "hook_key"); lua_remove(lstate_client, -2); if(lua_isnil(lstate_client, -1)) { // not hooked? ignore! lua_pop(lstate_client, 1); break; } { char ch = ev.key.keysym.sym; if ((ev.key.keysym.unicode & 0xFF80) == 0) ch = ev.key.keysym.unicode & 0x1FF; lua_pushinteger(lstate_client, ev.key.keysym.sym); lua_pushboolean(lstate_client, (ev.type == SDL_KEYDOWN)); lua_pushinteger(lstate_client, (int)(ev.key.keysym.mod)); lua_pushinteger(lstate_client, ch); if(lua_pcall(lstate_client, 4, 0, 0) != 0) { printf("Lua Client Error (key): %s\n", lua_tostring(lstate_client, -1)); lua_pop(lstate_client, 1); quitflag = 1; break; } } break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: // inform Lua client lua_getglobal(lstate_client, "client"); lua_getfield(lstate_client, -1, "hook_mouse_button"); lua_remove(lstate_client, -2); if(lua_isnil(lstate_client, -1)) { // not hooked? ignore! lua_pop(lstate_client, 1); break; } lua_pushinteger(lstate_client, ev.button.button); lua_pushboolean(lstate_client, (ev.type == SDL_MOUSEBUTTONDOWN)); if(lua_pcall(lstate_client, 2, 0, 0) != 0) { printf("Lua Client Error (mouse_button): %s\n", lua_tostring(lstate_client, -1)); lua_pop(lstate_client, 1); quitflag = 1; break; } break; case SDL_MOUSEMOTION: // inform Lua client lua_getglobal(lstate_client, "client"); lua_getfield(lstate_client, -1, "hook_mouse_motion"); lua_remove(lstate_client, -2); if(lua_isnil(lstate_client, -1)) { // not hooked? ignore! lua_pop(lstate_client, 1); break; } lua_pushinteger(lstate_client, ev.motion.x); lua_pushinteger(lstate_client, ev.motion.y); lua_pushinteger(lstate_client, ev.motion.xrel); lua_pushinteger(lstate_client, ev.motion.yrel); if(lua_pcall(lstate_client, 4, 0, 0) != 0) { printf("Lua Client Error (mouse_motion): %s\n", lua_tostring(lstate_client, -1)); lua_pop(lstate_client, 1); quitflag = 1; break; } break; case SDL_ACTIVEEVENT: if( ev.active.state & SDL_APPACTIVE || ev.active.state & SDL_APPINPUTFOCUS ) { lua_getglobal(lstate_client, "client"); lua_getfield(lstate_client, -1, "hook_window_activate"); lua_remove(lstate_client, -2); if(lua_isnil(lstate_client, -1)) { // not hooked? ignore! lua_pop(lstate_client, 1); break; } lua_pushboolean(lstate_client, ev.active.gain == 1); if(lua_pcall(lstate_client, 1, 0, 0) != 0) { printf("Lua Client Error (window_activate): %s\n", lua_tostring(lstate_client, -1)); lua_pop(lstate_client, 1); quitflag = 1; break; } } break; case SDL_QUIT: quitflag = 1; break; default: break; } return quitflag; }