Use system clock instead of used CPU time. Fixes key repeat and some
other stuff. close #206
This commit is contained in:
parent
d38b7b9b11
commit
a105ed9df8
15
src/Misc.cpp
15
src/Misc.cpp
@ -663,11 +663,22 @@ void millisleep(long int t)
|
||||
Sleep(t);
|
||||
#else
|
||||
struct timespec s;
|
||||
s.tv_sec = t/1000;
|
||||
s.tv_nsec = (t%1000)*10000000;
|
||||
s.tv_sec = t / 1000;
|
||||
s.tv_nsec = (t % 1000) * 10000000;
|
||||
nanosleep(&s, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
long unsigned int gettime()
|
||||
{
|
||||
#ifdef WIN
|
||||
return GetTickCount();
|
||||
#else
|
||||
struct timespec s;
|
||||
clock_gettime(CLOCK_MONOTONIC, &s);
|
||||
return s.tv_sec * 1000 + s.tv_nsec / 1000000;
|
||||
#endif
|
||||
}
|
||||
|
||||
vector2d v2d_zero = {0,0};
|
||||
matrix2d m2d_identity = {1,0,0,1};
|
||||
|
@ -90,6 +90,8 @@ int splitsign(const char* str, char * type = NULL);
|
||||
|
||||
void millisleep(long int t);
|
||||
|
||||
long unsigned int gettime();
|
||||
|
||||
// a b
|
||||
// c d
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <cstdio>
|
||||
#include <time.h>
|
||||
|
||||
#include "Config.h"
|
||||
#include "Misc.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include "gui/interface/Platform.h"
|
||||
#include "gui/interface/Engine.h"
|
||||
@ -181,7 +181,7 @@ void Engine::Tick()
|
||||
state_->DoTick(dt);
|
||||
|
||||
|
||||
lastTick = clock();
|
||||
lastTick = gettime();
|
||||
if(windowOpenState<1.0f)
|
||||
{
|
||||
if(lastBuffer)
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
#include "Config.h"
|
||||
#include "Misc.h"
|
||||
#include "gui/interface/Point.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
#include "gui/interface/Keys.h"
|
||||
@ -299,10 +299,10 @@ void Textbox::Tick(float dt)
|
||||
keyDown = 0;
|
||||
characterDown = 0;
|
||||
}
|
||||
if((keyDown || characterDown) && repeatTime <= clock())
|
||||
if((keyDown || characterDown) && repeatTime <= gettime())
|
||||
{
|
||||
OnVKeyPress(keyDown, characterDown, false, false, false);
|
||||
repeatTime = clock()+(0.03 * CLOCKS_PER_SEC);
|
||||
repeatTime = gettime()+30;
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
{
|
||||
characterDown = character;
|
||||
keyDown = key;
|
||||
repeatTime = clock()+(0.3 * CLOCKS_PER_SEC);
|
||||
repeatTime = gettime()+300;
|
||||
OnVKeyPress(key, character, shift, ctrl, alt);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include "SearchController.h"
|
||||
#include "SearchModel.h"
|
||||
#include "SearchView.h"
|
||||
@ -9,6 +8,7 @@
|
||||
#include "gui/dialogues/ErrorMessage.h"
|
||||
#include "gui/preview/PreviewController.h"
|
||||
#include "client/Client.h"
|
||||
#include "Misc.h"
|
||||
#include "tasks/Task.h"
|
||||
#include "tasks/TaskWindow.h"
|
||||
|
||||
@ -61,7 +61,7 @@ void SearchController::ReleaseLoadedSave()
|
||||
|
||||
void SearchController::Update()
|
||||
{
|
||||
if(!nextQueryDone && nextQueryTime < clock())
|
||||
if(!nextQueryDone && nextQueryTime < gettime())
|
||||
{
|
||||
nextQueryDone = true;
|
||||
searchModel->UpdateSaveList(1, nextQuery);
|
||||
@ -107,7 +107,7 @@ void SearchController::DoSearch(std::string query, bool now)
|
||||
nextQuery = query;
|
||||
if(!now)
|
||||
{
|
||||
nextQueryTime = clock()+(0.6 * CLOCKS_PER_SEC);
|
||||
nextQueryTime = gettime()+600;
|
||||
nextQueryDone = false;
|
||||
}
|
||||
else
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Format.h"
|
||||
#include "LuaScriptInterface.h"
|
||||
#include "LuaScriptHelper.h"
|
||||
#include "Misc.h"
|
||||
#include "PowderToy.h"
|
||||
|
||||
#include "gui/dialogues/ErrorMessage.h"
|
||||
@ -18,7 +19,6 @@
|
||||
#include "gui/game/GameModel.h"
|
||||
#include "simulation/Simulation.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifndef FFI
|
||||
int luacon_partread(lua_State* l){
|
||||
@ -512,7 +512,7 @@ int luacon_keyevent(int key, int modifier, int event)
|
||||
{
|
||||
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
||||
{
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
for(j=i;j<=c-1;j++)
|
||||
{
|
||||
lua_rawgeti(l, -2, j+1);
|
||||
@ -564,7 +564,7 @@ int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel)
|
||||
{
|
||||
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
||||
{
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
for(j=i;j<=c-1;j++)
|
||||
{
|
||||
lua_rawgeti(l, -2, j+1);
|
||||
@ -625,7 +625,7 @@ int luacon_step(int mx, int my, std::string selectl, std::string selectr, std::s
|
||||
{
|
||||
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
||||
{
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
for(j=i;j<=c-1;j++)
|
||||
{
|
||||
lua_rawgeti(l, -2, j+1);
|
||||
@ -646,17 +646,17 @@ int luacon_step(int mx, int my, std::string selectl, std::string selectr, std::s
|
||||
|
||||
|
||||
int luacon_eval(const char *command){
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
return luaL_dostring (luacon_ci->l, command);
|
||||
}
|
||||
|
||||
void luacon_hook(lua_State * l, lua_Debug * ar)
|
||||
{
|
||||
if(ar->event == LUA_HOOKCOUNT && clock()-ui::Engine::Ref().LastTick() > CLOCKS_PER_SEC*3)
|
||||
if(ar->event == LUA_HOOKCOUNT && gettime()-ui::Engine::Ref().LastTick() > 3000)
|
||||
{
|
||||
if(ConfirmPrompt::Blocking("Script not responding", "The Lua script may have stopped responding. There might be an infinite loop. Press \"Stop\" to stop it", "Stop"))
|
||||
luaL_error(l, "Error: Script not responding");
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "gui/game/Tool.h"
|
||||
#include "LuaScriptHelper.h"
|
||||
#include "client/HTTP.h"
|
||||
#include "Misc.h"
|
||||
#include "PowderToy.h"
|
||||
|
||||
#include "LuaBit.h"
|
||||
@ -44,7 +45,6 @@ extern "C"
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <time.h>
|
||||
#include "socket/luasocket.h"
|
||||
}
|
||||
#include "socket/socket.lua.h"
|
||||
@ -2804,7 +2804,7 @@ void LuaScriptInterface::OnTick()
|
||||
lua_getglobal(l, "simulation");
|
||||
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, -2, "NUM_PARTS");
|
||||
lua_pop(l, 1);
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
if(luacon_mousedown)
|
||||
luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
|
||||
luacon_step(luacon_mousex, luacon_mousey, luacon_selectedl, luacon_selectedr, luacon_selectedalt, luacon_brushx, luacon_brushy);
|
||||
@ -2829,7 +2829,7 @@ int LuaScriptInterface::Command(std::string command)
|
||||
lastCode += "\n";
|
||||
lastCode += command;
|
||||
std::string tmp = "return " + lastCode;
|
||||
ui::Engine::Ref().LastTick(clock());
|
||||
ui::Engine::Ref().LastTick(gettime());
|
||||
luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console");
|
||||
if(lua_type(l, -1) != LUA_TFUNCTION)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user