Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the bug with entity culling code #67

Merged
merged 2 commits into from
Jun 5, 2023
Merged
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
12 changes: 6 additions & 6 deletions nmmo/entity/entity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, realm):
self.config = realm.config

self.entities: Dict[int, Entity] = {}
self.dead: Dict[int, Entity] = {}
self.dead_this_tick: Dict[int, Entity] = {}

def __len__(self):
return len(self.entities)
Expand All @@ -37,7 +37,7 @@ def items(self):

@property
def corporeal(self):
return {**self.entities, **self.dead}
return {**self.entities, **self.dead_this_tick}

@property
def packet(self):
Expand All @@ -52,21 +52,21 @@ def reset(self):
ent.datastore_record.delete()

self.entities = {}
self.dead = {}
self.dead_this_tick = {}

def spawn(self, entity):
pos, ent_id = entity.pos, entity.id.val
self.realm.map.tiles[pos].add_entity(entity)
self.entities[ent_id] = entity

def cull(self):
self.dead = {}
self.dead_this_tick = {}
for ent_id in list(self.entities):
player = self.entities[ent_id]
if not player.alive:
r, c = player.pos
ent_id = player.ent_id
self.dead[ent_id] = player
self.dead_this_tick[ent_id] = player

self.realm.map.tiles[r, c].remove_entity(ent_id)

Expand All @@ -79,7 +79,7 @@ def cull(self):
self.entities[ent_id].datastore_record.delete()
del self.entities[ent_id]

return self.dead
return self.dead_this_tick

def update(self, actions):
for entity in self.entities.values():
Expand Down
11 changes: 9 additions & 2 deletions utils/pre-git-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ echo "Checking pylint, xcxc, pytest without touching git"
echo

# Check the number of physical cores only
cores=$(lscpu -b -p=Core,Socket | grep -v '^#' | sort -u | wc -l)
if command -v lscpu &> /dev/null
then
# lscpu is available
cores=$(lscpu -b -p=Core,Socket | grep -v '^#' | sort -u | wc -l)
else
# lscpu is not available, use sysctl instead
cores=$(sysctl -n hw.physicalcpu)
fi

# Run linter
echo "--------------------------------------------------------------------"
Expand Down Expand Up @@ -51,4 +58,4 @@ fi

echo
echo "Pre-git checks look good!"
echo
echo