Entities¶
Manages packet entity lifecycle (create/update/delete) and typed access to live networked field state.
See also: The Entity System, Entity State
gem.entities.EntityOp
¶
Bases: IntFlag
Bitmask indicating what happened to an entity in a packet.
Source code in src/gem/entities.py
gem.entities.Entity
¶
A live game entity with decoded field state.
The entity state is stored in _state (a FieldState tree for decoded
replay fields) and optionally in a plain dict overlay for direct key-value
access. The get() method queries the flat _state dict first (which
tests may set directly), then falls back to FieldState path resolution.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
Entity slot index. |
|
serial |
Serial number for handle validation. |
|
cls |
Class metadata (has .name, .class_id, .serializer). |
|
active |
False while the entity is in the leave state. |
Source code in src/gem/entities.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get(name: str) -> Any
¶
Return the current value of name, or None if absent.
Checks the flat _state dict first, then resolves through the
FieldState tree using the serializer's field schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Dotted field name, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The decoded value, or None. |
Source code in src/gem/entities.py
exists(name: str) -> bool
¶
Return True if name has a value in the entity state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name to check. |
required |
get_int32(name: str) -> int | None
¶
Return the value as int32, or None if absent/wrong type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Integer value, or None if the field is absent or not an int. |
Source code in src/gem/entities.py
get_uint32(name: str) -> int | None
¶
Return the value as uint32 (low 32 bits), or None if absent.
Accepts both int and uint64 values (truncating to 32 bits if needed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Integer value masked to 32 bits, or None if absent. |
Source code in src/gem/entities.py
get_uint64(name: str) -> int | None
¶
Return the value as uint64, or None if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Integer value, or None if absent. |
Source code in src/gem/entities.py
get_float32(name: str) -> float | None
¶
Return the value as float32, or None if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name. |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
Float value, or None if absent or not numeric. |
Source code in src/gem/entities.py
get_string(name: str) -> str | None
¶
Return the value as str, or None if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
String value, or None if absent or not a string. |
Source code in src/gem/entities.py
get_bool(name: str) -> bool | None
¶
Return the value as bool, or None if absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Field name. |
required |
Returns:
| Type | Description |
|---|---|
bool | None
|
Boolean value, or None if absent or not a bool/int. |
Source code in src/gem/entities.py
to_map() -> dict[str, Any]
¶
Return a snapshot of the flat _state dict.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of field name → value. |
get_class_name() -> str
¶
get_class_id() -> int
¶
get_index() -> int
¶
gem.entities.EntityManager
¶
Manages entity lifecycle across a replay stream.
Processes CSVCMsg_ServerInfo, CDemoClassInfo,
CSVCMsg_CreateStringTable / CSVCMsg_UpdateStringTable side effects,
and CSVCMsg_PacketEntities.
Attributes:
| Name | Type | Description |
|---|---|---|
entities |
list[Entity | None]
|
Sparse list indexed by entity slot (None = empty slot). |
classes_by_id |
dict[int, ClassInfo]
|
class_id → ClassInfo. |
classes_by_name |
dict[str, ClassInfo]
|
class_name → ClassInfo. |
class_baselines |
dict[int, bytes]
|
class_id → baseline bytes. |
serializers |
Output of |
|
string_tables |
StringTables container (shared with caller). |
|
game_build |
int
|
Server build number extracted from ServerInfo. |
class_id_size |
int
|
Number of bits used to encode class IDs. |
Source code in src/gem/entities.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
on_entity(handler: EntityHandler) -> None
¶
Register an entity event handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
EntityHandler
|
Callable |
required |
on_server_info(msg: object) -> None
¶
Extract classIdSize and game build from CSVCMsg_ServerInfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
object
|
A |
required |
Source code in src/gem/entities.py
on_class_info(msg: object) -> None
¶
Build class maps from CDemoClassInfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
object
|
A |
required |
Source code in src/gem/entities.py
on_baseline_updated() -> None
¶
on_packet_entities(msg: object) -> list[tuple[Entity, EntityOp]]
¶
Decode a CSVCMsg_PacketEntities message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
object
|
A |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[Entity, EntityOp]]
|
List of (Entity, EntityOp) tuples in the order they were processed. |
Source code in src/gem/entities.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
find(index: int) -> Entity | None
¶
Return the entity at the given slot index, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Entity slot index. |
required |
find_by_handle(handle: int) -> Entity | None
¶
Return the entity for a Source 2 entity handle, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
int
|
32-bit entity handle (index in low 14 bits, serial in high bits). |
required |
Source code in src/gem/entities.py
filter(predicate: Any) -> list[Entity]
¶
Return all entities matching a predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicate
|
Any
|
Callable |
required |
Returns:
| Type | Description |
|---|---|
list[Entity]
|
List of matching Entity objects. |
Source code in src/gem/entities.py
find_by_class_name(class_name: str) -> Entity | None
¶
Return the first active entity whose class name matches, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
Entity class name, e.g. |
required |