diff --git a/Difficult_Rocket.py b/Difficult_Rocket.py index af6c8fa..11b38e3 100644 --- a/Difficult_Rocket.py +++ b/Difficult_Rocket.py @@ -19,15 +19,16 @@ if __name__ == '__main__': print("__file__ = ", __file__) print("os.path.abspath(__file__) = ", os.path.abspath(__file__)) print("os.path.realpath(__file__) = ", os.path.realpath(__file__)) - print("os.path.dirname(os.path.realpath(__file__)) = ", - os.path.dirname(os.path.realpath(__file__))) - print("os.path.split(os.path.realpath(__file__)) = ", - os.path.split(os.path.realpath(__file__))) - print("os.path.split(os.path.realpath(__file__))[0] = ", - os.path.split(os.path.realpath(__file__))[0]) + print("os.path.dirname(os.path.realpath(__file__)) = ", + os.path.dirname(os.path.realpath(__file__))) + print("os.path.split(os.path.realpath(__file__)) = ", + os.path.split(os.path.realpath(__file__))) + print("os.path.split(os.path.realpath(__file__))[0] = ", + os.path.split(os.path.realpath(__file__))[0]) print("os.getcwd() = ", os.getcwd()) from bin import main - os.chdir(sys.path[0]) # TODO 没做完.ing + + os.chdir(sys.path[0]) # TODO 没做完.ing print(hi) game = main.Game() - game.start() \ No newline at end of file + game.start() diff --git a/README.md b/README.md index add2ca2..3542d18 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Version -0.4.2 (developing DEMO) +0.4.3 (developing DEMO) [Update logs](https://github.com/shenjackyuanjie/Difficult-Rocket/blob/main/docs/update_logs.md) diff --git a/bin/client.py b/bin/client.py index 69b8f53..92845e9 100644 --- a/bin/client.py +++ b/bin/client.py @@ -39,7 +39,7 @@ class client(mp.Process): self.net_mode = net_mode self.window_config = tools.config('configs/sys_value/window.json5') self.caption = self.window_config['caption'] - self.caption = configs.name_handler(self.caption, {'version': self.window_config['caption_option']['version']}) + self.caption = tools.name_handler(self.caption, {'version': self.window_config['caption_option']['version']}) self.window = window(logger=logger, dev_dic=dev_dic, dev_list=dev_list, diff --git a/bin/configs.py b/bin/configs.py index d51f142..559b63f 100644 --- a/bin/configs.py +++ b/bin/configs.py @@ -3,12 +3,12 @@ writen by shenjackyuanjie mail: 3695888@qq.com """ -import decimal -import logging # import re import os import sys import time +import decimal +import logging sys.path.append('./bin/libs/') sys.path.append('./') @@ -127,18 +127,6 @@ def basic_force() -> list: return BasicNumber(unit1='N', num=2) -def configs(name, option=None) -> dict: - with open(name, 'r') as file: - data = json5.load(file) - if option: - try: - data = data[option] - except IndexError as exp: - log = 'can\'t find stack named %s in file %s' % (option, name) - configs_logger.exception(log) - raise IndexError(log) - return data - """ name_handlers = {'time.time': str(time.time()), 'dir': str(os.getcwd()), @@ -159,31 +147,3 @@ def name_handler(name: str, configs=dict) -> str: handler_name = name.format(**names) return handler_name """ - -names = {'{time.time}': str(time.time()), - '{dir}': str(os.getcwd()), - '{py_v}': str(sys.version.split(' ')[0])} - - -def default_name_handler(name: str) -> str: - """ - won't change the string - just return one - """ - name = name - name = name.replace('{time.time}', str(time.time())) - name = name.replace('{dir}', str(os.getcwd())) - name = name.replace('{py_v}', str(sys.version.split(' ')[0])) - return name - - -def name_handler(name: str, formats=None) -> str: - if formats is None: - return default_name_handler(name) - name = default_name_handler(name) - for need_replace in formats: - replace = formats[need_replace] - if need_replace == '{date}': - replace = time.strftime(formats['{date}'], time.gmtime(time.time())) - name = name.replace(need_replace, replace) - return name diff --git a/bin/main.py b/bin/main.py index c6a1579..3b6ac97 100644 --- a/bin/main.py +++ b/bin/main.py @@ -41,7 +41,7 @@ class Game: self.lang = tools.config('configs/sys_value/lang/%s.json5' % self.language, 'main') # logger self.log_config = tools.config('configs/logging.json5', 'file') - self.log_filename = configs.name_handler(self.log_config['filename']['main'], + self.log_filename = tools.name_handler(self.log_config['filename']['main'], {'date': self.log_config['date_fmt']}) self.root_logger_fmt = logging.Formatter(self.log_config['fmt'], self.log_config['date_fmt']) self.root_logger_stream_handler = logging.StreamHandler() @@ -88,7 +88,7 @@ class Game: self.main_logger.critical('%s' % self.lang['version.need3+']) raise SystemError('%s' % self.lang['version.need3+']) elif self.on_python_v_info[1] < 9: - warning = configs.name_handler(self.lang['version.best3.8+']) + warning = tools.name_handler(self.lang['version.best3.8+']) self.main_logger.warning(warning) def start(self): diff --git a/bin/tools.py b/bin/tools.py index 21f08fe..4b722e5 100644 --- a/bin/tools.py +++ b/bin/tools.py @@ -3,16 +3,18 @@ writen by shenjackyuanjie mail: 3695888@qq.com """ -import configparser -import decimal -import logging -import math import sys -from xml.dom.minidom import parse sys.path.append('./bin/libs/') sys.path.append('./') import json5 +import configparser +import decimal +import logging +import math +import time +import os +from xml.dom.minidom import parse try: import configs @@ -253,7 +255,6 @@ def config(file_name, stack=None): # // TODO 加上.config的读取+解析 cp.read(file_name) # config parser -> reader - def get_At(name, in_xml, need_type=str): """ get Attribute from a XML tree @@ -278,3 +279,32 @@ def get_At(name, in_xml, need_type=str): else: raise TypeError('only str and list type is ok but you give me a' + name_type + 'type') return need_type(At) + + +names = {'{time.time}': str(time.time()), + '{dir}': str(os.getcwd()), + '{py_v}': str(sys.version.split(' ')[0])} + + +def default_name_handler(name: str) -> str: + """ + won't change the string + just return one + """ + name = name + name = name.replace('{time.time}', str(time.time())) + name = name.replace('{dir}', str(os.getcwd())) + name = name.replace('{py_v}', str(sys.version.split(' ')[0])) + return name + + +def name_handler(name: str, formats=None) -> str: + if formats is None: + return default_name_handler(name) + name = default_name_handler(name) + for need_replace in formats: + replace = formats[need_replace] + if need_replace == '{date}': + replace = time.strftime(formats['{date}'], time.gmtime(time.time())) + name = name.replace(need_replace, replace) + return name diff --git a/configs/sys_value/window.json5 b/configs/sys_value/window.json5 index 58da0a6..fc7dd32 100644 --- a/configs/sys_value/window.json5 +++ b/configs/sys_value/window.json5 @@ -6,14 +6,14 @@ 'caption': 'Simple Rocket {version}', // {version} -> version of SR 'caption_option': { - 'version': '0.4.1' + 'version': '0.4.3' }, 'resizable': 'true', // bool 'visible': 'true', // bool 'style': 'None', - 'fps': 120, + 'fps': 60, 'views': [ 'space', 'map', diff --git a/docs/README-cn.md b/docs/README-cn.md index d0ea9e3..563b316 100644 --- a/docs/README-cn.md +++ b/docs/README-cn.md @@ -2,7 +2,7 @@ ## 版本 -0.4.2 (开发DEMO.ing) +0.4.3 (开发DEMO.ing) [更新日志](https://github.com/shenjackyuanjie/Difficult-Rocket/blob/main/docs/update_logs.md) diff --git a/docs/update_logs.md b/docs/update_logs.md index 8fe6d07..98c25b0 100644 --- a/docs/update_logs.md +++ b/docs/update_logs.md @@ -5,6 +5,21 @@ - [README](https://github.com/shenjackyuanjie/Difficult-Rocket) - [中文README](https://github.com/shenjackyuanjie/Difficult-Rocket/blob/main/docs/README-cn.md) +## 2021/06/26 V 0.4.3 + +### DEBUG + +- some name_format bug + +### Change + +- doing: change render pip line ('m really doing) +- default FPS from 120 -> 60 + +### Add + +- add performance_test folder +- add some performances test ## 2021/05/24 V 0.4.2 diff --git a/performance_test/test_for_speed.py b/performance_test/test_for_speed.py new file mode 100644 index 0000000..fd8edd7 --- /dev/null +++ b/performance_test/test_for_speed.py @@ -0,0 +1,33 @@ +# test of "for" speed +# R5 5600X 16*2GB DDR4 3200 +import random +import time +from pprint import pprint +TPS = 60 +SPT = 1 / TPS + +list_num = 100 +test_list = {} +for x in range(list_num): + test_list[x] = [random.random()] +time_list = {} + +times = 100 +t = 0 +start_t = time.time() +while t < times: + s_t = time.time() + t += 1 + for x in test_list: + if test_list[x][0] > 0.5: + print('y', end=' ') + else: + print('n', end=' ') + pass + print(t, end='\n') + e_t = time.time() + time_list[t] = [s_t, e_t, e_t-s_t] +end_time = time.time() +pprint(time_list) +pprint(test_list) +print(start_t, end_time, end_time-start_t) diff --git a/performance_test/test_speed_of_sprite.py b/performance_test/test_speed_of_sprite.py new file mode 100644 index 0000000..6bd44ca --- /dev/null +++ b/performance_test/test_speed_of_sprite.py @@ -0,0 +1,31 @@ +import time + +import pyglet + +window = pyglet.window.Window(resizable=True) + +ball_image = pyglet.image.load('/DR/textures/Atmospheres.png') # 可自定义材质 +batch = pyglet.graphics.Batch() + +ball_sprites = [] +start_t = time.time() +for i in range(1500): # 可自定义数量 + x, y = i * 10, 50 + ball_sprites.append(pyglet.sprite.Sprite(ball_image, x, y, batch=batch)) +end_t = time.time() +print(start_t, end_t, end_t-start_t) + +a = 0 +@window.event +def on_draw(): + start_t = time.time() + if a: + for x in ball_sprites: + x.draw() + else: + batch.draw() + end_t = time.time() + print(start_t, end_t-start_t) + print(end_t, pyglet.clock.get_fps(), 'fps') + +pyglet.app.run()