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

View File

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