Skip to content

Commit

Permalink
Better type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Apr 1, 2024
1 parent 8e4b1ca commit bae8bf3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rlviser-py"
version = "0.6.4"
version = "0.6.5"
edition = "2021"
description = "Python implementation that manages a UDP connection to RLViser"
license = "MIT"
Expand Down
14 changes: 13 additions & 1 deletion rlviser_py.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
from typing import Sequence, Optional, Tuple

from RocketSim import BallState, CarConfig, CarState, GameMode, Team
from RocketSim import BallState, CarState, GameMode

type TVec3 = Tuple[float, float, float]
"""
The items are (X, Y, Z) respectively
"""
type TRotmat = Tuple[TVec3, TVec3, TVec3]
"""
The items are (forward, right, up) respectively
"""
type TBall = Tuple[TVec3, TRotmat, TVec3, TVec3]
"""
The items are (location, rotation, velocity, angular velocity) respectively
"""
type TCar = Tuple[int, TVec3, TRotmat, TVec3, TVec3, float, bool, bool, bool, float]
"""
The items are (car_id, location, rotation, velocity, angular velocity, boost, has jumped, has double jumped, has flipped, demo respawn timer) respectively
"""

def set_boost_pad_locations(locations: Sequence[TVec3]) -> ...:
pass
Expand Down
4 changes: 2 additions & 2 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Default for BallState {

impl BallState {
#[inline]
pub fn to_array(self) -> TBall {
pub const fn to_array(self) -> TBall {
(
self.pos.to_array(),
self.rot_mat.to_array(),
Expand Down Expand Up @@ -232,7 +232,7 @@ pub type TCar = (u32, TVec3, TRotMat, TVec3, TVec3, f32, bool, bool, bool, f32);

impl CarInfo {
#[inline]
pub fn to_array(self) -> TCar {
pub const fn to_array(self) -> TCar {
(
self.id,
self.state.pos.to_array(),
Expand Down
4 changes: 3 additions & 1 deletion src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{
sync::OnceLock,
};

const ROCKETSIM_PORT: u16 = 34254;

#[repr(u8)]
enum UdpPacketTypes {
Quit,
Expand All @@ -23,7 +25,7 @@ pub fn init() -> io::Result<(UdpSocket, SocketAddr)> {
}

// Connect to RLViser
let socket = UdpSocket::bind("0.0.0.0:34254")?;
let socket = UdpSocket::bind(("0.0.0.0", ROCKETSIM_PORT))?;

println!("Waiting for connection to socket...");
let mut buf = [0; 1];
Expand Down

0 comments on commit bae8bf3

Please sign in to comment.