inprove performance

This commit is contained in:
chrys 2016-09-25 22:14:35 +02:00
parent c3e67168a2
commit b5dc878d37
2 changed files with 12 additions and 7 deletions

View File

@ -40,6 +40,8 @@ class inputManager():
if mEvent['EventName'] in self.env['input']['currInput']:
self.env['input']['currInput'].remove(mEvent['EventName'])
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
if len(self.env['input']['prevDeepestInput']) < len(self.env['input']['currInput']):
self.env['input']['prevDeepestInput'] = self.env['input']['currInput'].copy()
elif mEvent['EventState'] == 1:
if not mEvent['EventName'] in self.env['input']['currInput']:
self.env['input']['currInput'].append(mEvent['EventName'])
@ -102,7 +104,7 @@ class inputManager():
def writeEventBuffer(self):
try:
self.env['runtime']['inputDriver'].writeEventBuffer()
time.sleep(0.005)
time.sleep(0.0005)
self.clearEventBuffer()
except Exception as e:
print(e)

View File

@ -36,7 +36,6 @@ class fenrir():
def handleProcess(self):
eventReceived = self.environment['runtime']['inputManager'].getInputEvent()
startTime = time.time()
if eventReceived:
self.prepareCommand()
if not (self.wasCommand or self.environment['runtime']['inputManager'].isFenrirKeyPressed() or self.environment['generalInformation']['tutorialMode']):
@ -50,9 +49,11 @@ class fenrir():
if self.environment['input']['keyForeward'] > 0:
self.environment['input']['keyForeward'] -=1
self.environment['input']['prevDeepestInput'] = []
else:
startTime = time.time()
self.environment['runtime']['screenManager'].update()
self.environment['runtime']['commandManager'].executeDefaultTrigger('onInput')
print(time.time()-startTime)
else:
self.environment['runtime']['screenManager'].update()
@ -65,12 +66,15 @@ class fenrir():
if self.environment['runtime']['screenManager'].isScreenChange():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenChanged')
else:
if self.environment['runtime']['inputManager'].noKeyPressed():
self.environment['runtime']['commandManager'].executeDefaultTrigger('onScreenUpdate')
self.handleCommands()
#print(time.time()-startTime)
def prepareCommand(self):
if self.environment['runtime']['inputManager'].noKeyPressed():
return
if self.environment['input']['keyForeward'] > 0:
return
shortcut = self.environment['runtime']['inputManager'].getCurrShortcut()
@ -79,7 +83,6 @@ class fenrir():
self.environment['runtime']['commandManager'].queueCommand(command)
if len(self.environment['input']['prevDeepestInput']) < len(self.environment['input']['currInput']):
self.wasCommand = command != ''
self.environment['input']['prevDeepestInput'] = self.environment['input']['currInput'].copy()
def handleCommands(self):
if time.time() - self.environment['commandInfo']['lastCommandExecutionTime'] < 0.2: