2023-02-19 22:08:25 +08:00
|
|
|
|
"""
|
2020-11-28 15:17:44 +08:00
|
|
|
|
writen by shenjackyuanjie
|
2023-01-02 19:46:25 +08:00
|
|
|
|
email: 3695888@qq.com
|
2021-02-16 11:35:10 +08:00
|
|
|
|
"""
|
2021-05-24 22:28:42 +08:00
|
|
|
|
import os
|
|
|
|
|
import sys
|
2022-06-18 17:53:35 +08:00
|
|
|
|
import time
|
2021-11-06 19:07:32 +08:00
|
|
|
|
import cProfile
|
2021-08-13 12:25:29 +08:00
|
|
|
|
import traceback
|
2023-05-02 15:31:28 +08:00
|
|
|
|
import threading
|
2021-05-24 22:28:42 +08:00
|
|
|
|
|
2023-04-23 00:15:36 +08:00
|
|
|
|
from io import StringIO
|
|
|
|
|
|
2021-11-04 23:32:05 +08:00
|
|
|
|
# TODO 默认位置配置文件
|
|
|
|
|
# TODO 可自定义工作路径
|
2021-05-24 22:28:42 +08:00
|
|
|
|
|
2021-08-24 22:31:52 +08:00
|
|
|
|
hi = """Difficult Rocket is writen by shenjackyuanjie
|
2023-01-02 19:46:25 +08:00
|
|
|
|
email: 3695888@qq.com or shyj3695888@163.com
|
2021-08-24 22:31:52 +08:00
|
|
|
|
QQ: 3695888"""
|
2021-09-27 23:22:07 +08:00
|
|
|
|
|
2021-10-01 23:12:01 +08:00
|
|
|
|
error_format = {
|
|
|
|
|
'TestError': '游戏正在调试中,某处引发了一个 TestError,不是bug造成的原因',
|
|
|
|
|
'AssertionError': '游戏的某处检查未通过,情报告issue',
|
|
|
|
|
'error.unknown': '游戏报错了,现在输出报错信息,请报告issue',
|
|
|
|
|
'error.happen': '游戏出现了一个报错!正在处理'
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 13:16:35 +08:00
|
|
|
|
|
2023-02-26 08:46:04 +08:00
|
|
|
|
def print_path() -> None:
|
2021-10-01 23:12:01 +08:00
|
|
|
|
print(f'{__file__=}')
|
2023-02-26 08:46:04 +08:00
|
|
|
|
print(f'{sys.path=}')
|
2021-10-01 23:12:01 +08:00
|
|
|
|
print(f'{sys.path[0]=}')
|
|
|
|
|
print(f'{sys.argv[0]=}')
|
2023-04-08 02:14:06 +08:00
|
|
|
|
print(f'{os.curdir=}')
|
2021-10-01 23:12:01 +08:00
|
|
|
|
print(f'{os.getcwd()=}')
|
2023-04-08 02:14:06 +08:00
|
|
|
|
print(f'{os.path.abspath(os.curdir)=}')
|
2021-10-01 23:12:01 +08:00
|
|
|
|
print(f'{os.path.abspath(__file__)=}')
|
|
|
|
|
print(f'{os.path.realpath(__file__)=}')
|
2021-11-06 19:07:32 +08:00
|
|
|
|
print(f'{os.path.split(os.path.split(os.path.realpath(__file__))[0])=}')
|
2021-09-23 06:34:23 +08:00
|
|
|
|
# 输出一遍大部分文件位置相关信息 以后可能会加到logs里
|
2023-02-26 08:46:04 +08:00
|
|
|
|
|
|
|
|
|
|
2023-05-02 15:31:28 +08:00
|
|
|
|
def main() -> int:
|
2023-02-26 08:46:04 +08:00
|
|
|
|
print(hi) # hi!
|
|
|
|
|
start_time_ns = time.time_ns()
|
|
|
|
|
start_time_perf_ns = time.perf_counter_ns()
|
|
|
|
|
print_path()
|
2021-09-27 23:22:07 +08:00
|
|
|
|
file_path = os.path.split(os.path.realpath(__file__))[0]
|
2022-07-04 10:36:19 +08:00
|
|
|
|
os.chdir(file_path) # 将运行路径切换到文件位置 防止bug
|
|
|
|
|
sys.path.append(f'{file_path}/Difficult_Rocket') # 添加local path
|
|
|
|
|
sys.path.append(f'{file_path}/libs') # 添加 libs path
|
2021-09-16 19:18:06 +08:00
|
|
|
|
|
2022-06-29 13:45:25 +08:00
|
|
|
|
from Difficult_Rocket.exception import TestError
|
2023-02-25 09:18:41 +08:00
|
|
|
|
from Difficult_Rocket import crash
|
2023-06-16 23:36:24 +08:00
|
|
|
|
from Difficult_Rocket import DR_status
|
2021-08-13 12:25:29 +08:00
|
|
|
|
try:
|
2023-01-25 20:13:36 +08:00
|
|
|
|
from libs import pyglet # 导入pyglet
|
2022-08-12 21:07:36 +08:00
|
|
|
|
pyglet.resource.path = ['/textures/']
|
|
|
|
|
pyglet.resource.reindex()
|
2022-04-08 23:07:41 +08:00
|
|
|
|
|
2023-06-17 00:47:00 +08:00
|
|
|
|
from Difficult_Rocket import main
|
|
|
|
|
from Difficult_Rocket.runtime import DR_runtime
|
2022-08-12 21:07:36 +08:00
|
|
|
|
DR_runtime.start_time_ns = start_time_ns
|
2022-03-22 23:20:07 +08:00
|
|
|
|
|
2022-07-04 10:36:19 +08:00
|
|
|
|
game = main.Game() # 实例化一个游戏
|
2022-08-12 21:07:36 +08:00
|
|
|
|
print(time.perf_counter_ns() - start_time_perf_ns, (time.perf_counter_ns() - start_time_perf_ns) / (10 ** 9), 'start') # 输出一下启动用时
|
2022-06-18 17:53:35 +08:00
|
|
|
|
|
2022-07-04 10:36:19 +08:00
|
|
|
|
cprofile = False # 是否使用cprofile
|
2021-11-06 19:07:32 +08:00
|
|
|
|
if cprofile:
|
2022-07-04 10:36:19 +08:00
|
|
|
|
cProfile.run('game.start()', sort='calls') # 使用 cprofile 启动
|
2021-11-06 19:07:32 +08:00
|
|
|
|
else:
|
2022-07-04 10:36:19 +08:00
|
|
|
|
game.start() # 直接启动
|
2023-06-16 23:36:24 +08:00
|
|
|
|
if DR_status.crash_report_test:
|
2022-07-04 10:36:19 +08:00
|
|
|
|
raise TestError('debugging') # debug 嘛,试试crash
|
|
|
|
|
except Exception as exp: # 出毛病了
|
2023-05-02 15:31:28 +08:00
|
|
|
|
# 解析错误信息
|
|
|
|
|
print(error_format['error.happen'])
|
2021-08-13 12:25:29 +08:00
|
|
|
|
error = traceback.format_exc()
|
2021-10-28 06:43:35 +08:00
|
|
|
|
name = type(exp).__name__
|
|
|
|
|
if name in error_format:
|
2021-10-01 23:12:01 +08:00
|
|
|
|
print(error_format[name])
|
|
|
|
|
else:
|
|
|
|
|
print(error_format['error.unknown'])
|
2021-08-13 12:25:29 +08:00
|
|
|
|
print(error)
|
2023-05-02 15:31:28 +08:00
|
|
|
|
# 输出 crash 信息
|
2021-09-16 19:18:06 +08:00
|
|
|
|
crash.create_crash_report(error)
|
2023-04-23 00:15:36 +08:00
|
|
|
|
cache_steam = StringIO()
|
|
|
|
|
crash.write_info_to_cache(cache_steam)
|
|
|
|
|
text = cache_steam.getvalue()
|
|
|
|
|
print(text)
|
2021-09-05 00:50:05 +08:00
|
|
|
|
else:
|
2021-09-08 23:38:34 +08:00
|
|
|
|
crash.record_thread = False
|
|
|
|
|
print(crash.all_thread)
|
2021-09-22 06:21:48 +08:00
|
|
|
|
print(crash.all_process)
|
2023-05-02 15:31:28 +08:00
|
|
|
|
# join all thread
|
|
|
|
|
for thread in threading.enumerate():
|
|
|
|
|
print(thread)
|
|
|
|
|
if thread.name == 'MainThread' or thread == threading.main_thread() or thread == threading.current_thread():
|
|
|
|
|
continue
|
|
|
|
|
if thread.daemon:
|
|
|
|
|
continue
|
|
|
|
|
thread.join()
|
|
|
|
|
# stop pyglet
|
|
|
|
|
import pyglet
|
|
|
|
|
pyglet.app.exit()
|
2023-05-02 12:38:48 +08:00
|
|
|
|
print("Difficult_Rocket 已关闭")
|
2023-05-02 15:31:28 +08:00
|
|
|
|
return 0
|
2023-02-06 13:16:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-05-02 15:31:28 +08:00
|
|
|
|
sys.exit(main())
|