DEMO making

This commit is contained in:
沈瑗杰 2021-02-21 11:58:47 +08:00
parent 46f3550365
commit 5113a801c1
5 changed files with 27 additions and 13 deletions

View File

@ -4,7 +4,9 @@ mail: 3695888@qq.com
"""
import os
import time
import pyglet
import random
from pyglet import image
import multiprocessing as mp
@ -19,7 +21,7 @@ except (ModuleNotFoundError, ImportError, ImportWarning):
class client(mp.Process):
def __init__(self, logger, dev_dic=None, dev_list=None, net_mode='local'):
def __init__(self, logger, dev_dic=None, dev_list=None, language='zh-cn', net_mode='local'):
mp.Process.__init__(self)
# logging
self.logger = logger
@ -36,6 +38,7 @@ class client(mp.Process):
self.window = window(logger=logger,
dev_dic=dev_dic,
dev_list=dev_list,
language=language,
net_mode=net_mode,
width=int(self.window_config['width']),
height=int(self.window_config['height']),
@ -53,7 +56,7 @@ class client(mp.Process):
class window(pyglet.window.Window):
def __init__(self, logger, dev_dic=None, dev_list=None, net_mode='local', *args, **kwargs):
def __init__(self, logger, dev_dic=None, dev_list=None, language='zh-cn', net_mode='local', *args, **kwargs):
super(window, self).__init__(*args, **kwargs)
"""
:param dev_list: 共享内存
@ -67,11 +70,12 @@ class window(pyglet.window.Window):
self.dev_list = dev_list
self.dev_dic = dev_dic
# value
self.process_id = 'Client'
self.process_name = 'Client process'
self.FPS = 60
self.SPF = 1.0 / self.FPS
self.view = 'space'
self.net_mode = net_mode
# configs
self.lang = tools.config('sys_value/lang/%s.json5' % language)
self.view = tools.config('configs/view.json5')
self.map_view = [configs.basic_poi(poi_type='chunk')]
self.part_list = tools.config('sys_value/parts.json5')
@ -88,6 +92,7 @@ class window(pyglet.window.Window):
self.textures = {}
# setup
self.setup()
pyglet.clock.schedule_interval(self.update(), self.SPF)
def setup(self):
# net_mode
@ -102,16 +107,23 @@ class window(pyglet.window.Window):
self.textures['part'][part] = part_image
# tests
self.info_label = pyglet.text.Label(text='test',
x=150, y=100,
self.info_label = pyglet.text.Label(text='test %s' % pyglet.clock.get_fps(),
x=10, y=self.height - 10,
anchor_x='left', anchor_y='top',
batch=self.label_batch)
# draws
def update(self):
self.info_label.x = random.randint(100, 500)
self.info_label.y = random.randint(100, 500)
def on_draw(self):
self.draw_batch()
print(time.time())
def draw_batch(self):
self.clear()
self.part_batch.draw()
self.runtime_batch.draw()
self.label_batch.draw()

View File

@ -67,18 +67,18 @@ class Game:
# version check
self.python_version_check()
# client and server
self.client = client.client(self.client_logger, self.dicts, self.lists, net_mode='local')
self.client = client.client(self.client_logger, self.dicts, self.lists, self.language, net_mode='local')
self.server = server.server(self.lists, self.dicts, self.server_logger, net_mode='local')
def log_configs(self):
self.main_logger.info('%s %s' % (self.lang['lang.language'], self.language))
self.main_logger.info('%s %s' % (self.lang['logger.language'], self.lang['lang.language']))
self.main_logger.info('%s %s' % (self.lang['game_start.at'], self.start_time))
self.main_logger.debug('%s %s' % (self.lang['logger.logfile_name'], self.log_filename))
self.main_logger.debug('%s %s' % (self.lang['logger.logfile_level'], self.log_config['level']))
self.main_logger.debug('%s %s' % (self.lang['logger.logfile_fmt'], self.log_config['fmt']))
self.main_logger.debug('log file date format: %s' % (self.log_config['date_fmt']))
self.main_logger.debug('%s %s' % (self.lang['logger.logfile_datefmt'], self.log_config['date_fmt']))
def python_version_check(self) -> None:
def python_version_check(self):
self.main_logger.info('Difficult Rocket is running on Python Vision %s' % self.on_python_v)
if self.on_python_v_info[0] == 2:
self.main_logger.critical('Difficult Rocket need Python vision 3+ but not %s ' % self.on_python_v)

View File

@ -7,7 +7,7 @@ import multiprocessing as mp
class server(mp.Process):
def __init__(self, dev_list, dev_dic, logger, net_mode='local'):
def __init__(self, dev_list, dev_dic, logger, language='zh-cn', net_mode='local'):
# father class __init__()
mp.Process.__init__(self)
# logging

View File

@ -1,5 +1,5 @@
{
'language': 'zh_cn',
'language': 'zh-cn',
'textures': {
'back_ground_space': 'back_ground_space.png',
'planet': {

View File

@ -1,11 +1,13 @@
{
'main': {
'lang.language': '日志记录语言为:',
'lang.language': '简 体 中 文 zh-cn',
'logger.language': '日志记录语言为:',
'logger.created': '日志处理器创建完成',
'logger.main_done': '主日志处理器创建完成',
'logger.logfile_name': '日志文件文件名::',
'logger.logfile_level': '日志文件记录级别:',
'logger.logfile_fmt': '日志文件记录格式:',
'logger.logfile_datefmt': '日志文件日期格式:',
'game_start.at': '游戏主线程开始于:'
}
}