Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion controller_process.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from games import game, joust_non_stop, werewolf, zombie, commander, tournament, speed_bomb, fight_club
import common, piparty
import logging
import setproctitle

logger = logging.getLogger(__name__)

Expand All @@ -10,6 +11,9 @@ def main_track_move(menu, restart, move_serial, move_num, menu_opts, game_opts,
team, team_color_enum, sensitivity, dead_move, invincible_move, music_speed, show_team_colors, red_on_kill,\
revive, kill_proc):

# Set the process title
setproctitle.setproctitle(f"JoustMania-main_track_move({move_serial})")

move = common.get_move(move_serial, move_num)

while not kill_proc.value:
Expand Down Expand Up @@ -69,4 +73,4 @@ def main_track_move(menu, restart, move_serial, move_num, menu_opts, game_opts,
move=move, team=team, team_color_enum=team_color_enum, dead_move=dead_move, invincible_move=invincible_move, \
force_color=force_color, music_speed=music_speed, show_team_colors=show_team_colors, red_on_kill=red_on_kill, \
restart=restart, menu=menu, sensitivity=sensitivity, revive=revive, opts=game_opts
)
)
7 changes: 6 additions & 1 deletion games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,13 @@ def game_loop(self):

self.handle_status()
self.check_end_game()


if self.game_end:
self.end_game()

#Give up 10ms to prevent CPU thrashing
time.sleep(0.01)

self.stop_tracking_moves()

def switch_teams(self, serial, team):
Expand Down Expand Up @@ -587,3 +589,6 @@ def track_move(cls, move, team, team_color_enum, dead_move, invincible_move, for
move.set_leds(*Colors.Black.value)
move.update_leds()
move.set_rumble(0)

#Give up 10ms to prevent CPU thrashing
time.sleep(0.01)
2 changes: 1 addition & 1 deletion kill_processes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#this is for development purposes only, to stop the automattically
#running piparty scripts
sudo supervisorctl stop joustmania
sudo kill -9 $(ps aux | grep '[p]iparty' | awk '{print $2}')
sudo kill -9 $(ps aux | grep 'JoustMania-' | awk '{print $2}')
2 changes: 2 additions & 0 deletions pacemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def choose_new_pace_(self, old_pace) -> typing.Tuple[object, float]:

@common.async_print_exceptions
async def run_(self):
import setproctitle
setproctitle.setproctitle(f"JoustMania-PaceManager")
await asyncio.sleep(self.initial_pace_time_)

pace = self.initial_pace_
Expand Down
7 changes: 7 additions & 0 deletions piaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import pygame
import random
import glob
import setproctitle

from sys import platform
if platform == "linux" or platform == "linux2":
import alsaaudio
Expand Down Expand Up @@ -189,10 +191,13 @@ def Resample(samples):
wf.close()
device.close()
song_loaded = False
#Give up 500ms to prevent CPU thrashing
time.sleep(0.5)

@functools.lru_cache(maxsize=128)
class Audio:
def __init__(self, fname):
setproctitle.setproctitle(f"JoustMania-Audio({fname})")
#these are probably not necessary
#segment = AudioSegment.from_file(fname)
#buf = io.BytesIO()
Expand Down Expand Up @@ -224,6 +229,8 @@ def start_effect_and_wait(self):
@functools.lru_cache(maxsize=16)
class Music:
def __init__(self, name):
setproctitle.setproctitle(f"JoustMania-Music({name})")

self.name = name
self.transition_future_ = asyncio.Future()

Expand Down
16 changes: 13 additions & 3 deletions piparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sys import platform
from dotenv import find_dotenv, load_dotenv
import logging.config
import setproctitle

if platform == "linux" or platform == "linux2":
import jm_dbus
Expand Down Expand Up @@ -86,7 +87,7 @@ def track_move(serial, move_num, move, menu_opts, force_color, battery, dead_cou
while True:
if(restart.value == 1 or menu.value == 0 or kill_proc.value):
return # Stop tracking move if restarting, exiting menu, or kill_procedures
time.sleep(0.01)

# If there is a new event from the move
if move.poll():

Expand Down Expand Up @@ -297,10 +298,14 @@ def track_move(serial, move_num, move, menu_opts, force_color, battery, dead_cou
move.set_leds(*move_color)
#Update colors
move.update_leds()


#Give up 30ms to prevent CPU thrashing
time.sleep(0.03)

class Menu():
def __init__(self):

setproctitle.setproctitle(f"JoustMania-Menu()")

# Set up shared namespace between webserver and joustmania
self.command_queue = Queue()
self.joust_manager = Manager()
Expand Down Expand Up @@ -654,6 +659,8 @@ def check_charging_controller(self):
move_opt[Opts.STATUS.value] = Status.ALIVE.value #If move is not charging, set it to alive

def game_loop(self):
import setproctitle
setproctitle.setproctitle(f"JoustMania-game_loop()")
self.play_menu_music = True
while True:
# Only start the music the first loop
Expand Down Expand Up @@ -704,6 +711,9 @@ def game_loop(self):
self.check_command_queue()
self.update_status('menu')

#Give up 30ms to prevent CPU thrashing
time.sleep(0.03)


def check_admin_controls(self):
show_bat = False
Expand Down
5 changes: 3 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ setup() {
libudev-dev swig libbluetooth-dev \
alsa-utils alsa-tools libasound2-dev libsdl2-mixer-2.0-0 \
python-dbus-dev python3-dbus libdbus-glib-1-dev usbutils libatlas-base-dev \
python3-pyaudio python3-psutil || exit -1
python3-pyaudio python3-psutil python3-setproctitle || exit -1

echo "Installing PS move A.P.I. software updates"
#install components for psmoveapi
Expand All @@ -55,7 +55,8 @@ setup() {
PYTHON=$VENV/bin/python3

echo "installing virtual environment dependencies"
$PYTHON -m pip install --ignore-installed flask Flask-WTF pyalsaaudio pydub pyyaml dbus-python python-dotenv || exit -1

$PYTHON -m pip install --ignore-installed flask Flask-WTF pyalsaaudio pydub pyyaml dbus-python python-dotenv

#Sometimes pygame tries to install without a whl, and fails (like 2.4.0) this
#checks that only correct versions will install
Expand Down
2 changes: 2 additions & 0 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def randomize_teams(self,num_teams):
return str(team_colors).replace("'",'"')#JSON is dumb and demands double quotes

def start_web(command_queue, ns):
import setproctitle
setproctitle.setproctitle(f"JoustMania-WebUI")
webui = WebUI(command_queue,ns)
webui.web_loop()

Expand Down