def create_entity(group=None, etype='', force_id=None): global NEXT_ENTITY_ID if force_id: _entity_id = force_id if force_id in ENTITIES: logging.error('`force_id` overwriting existing ID') if int(force_id) >= NEXT_ENTITY_ID: NEXT_ENTITY_ID = int(force_id) + 1 else: if REVOKED_ENTITY_IDS: _entity_id = REVOKED_ENTITY_IDS.pop() else: _entity_id = str(NEXT_ENTITY_ID) NEXT_ENTITY_ID += 1 #NOTE: If this happens, you're doing something you shouldn't. #if _entity_id in ENTITIES: # logging.fatal('New entity overwriting existing. Dumping to disk...') # crash_dump(ENTITIES[_entity_id], ['_id', '_groups', '_etype']) _entity = { '_id': _entity_id, '_events': {}, '_groups': [], '_etype': etype } ENTITIES[_entity['_id']] = _entity create_event(_entity, 'save') create_event(_entity, 'load') create_event(_entity, 'delete') create_event(_entity, 'logic') create_event(_entity, 'tick') create_event(_entity, 'post_tick') if group: add_entity_to_group(_entity, group) worlds.register_entity(_entity) return _entity
def create_entity(group=None, etype="", force_id=None): global NEXT_ENTITY_ID if force_id: _entity_id = force_id if force_id in ENTITIES: logging.error("`force_id` overwriting existing ID") if int(force_id) >= NEXT_ENTITY_ID: NEXT_ENTITY_ID = int(force_id) + 1 else: if REVOKED_ENTITY_IDS: _entity_id = REVOKED_ENTITY_IDS.pop() else: _entity_id = str(NEXT_ENTITY_ID) NEXT_ENTITY_ID += 1 # NOTE: If this happens, you're doing something you shouldn't. # if _entity_id in ENTITIES: # logging.fatal('New entity overwriting existing. Dumping to disk...') # crash_dump(ENTITIES[_entity_id], ['_id', '_groups', '_etype']) _entity = {"_id": _entity_id, "_events": {}, "_groups": [], "_etype": etype} ENTITIES[_entity["_id"]] = _entity create_event(_entity, "save") create_event(_entity, "load") create_event(_entity, "delete") create_event(_entity, "logic") create_event(_entity, "tick") create_event(_entity, "post_tick") if group: add_entity_to_group(_entity, group) worlds.register_entity(_entity) return _entity
def create_entity(group=None): global NEXT_ENTITY_ID if REVOKED_ENTITY_IDS: _entity_id = REVOKED_ENTITY_IDS.pop() else: _entity_id = str(NEXT_ENTITY_ID) NEXT_ENTITY_ID += 1 _entity = {"_id": _entity_id, "_events": {}, "_groups": [], "_groups_orig": []} ENTITIES[_entity["_id"]] = _entity worlds.register_entity(_entity) create_event(_entity, "delete") create_event(_entity, "create") create_event(_entity, "loop") create_event(_entity, "tick") if group: add_entity_to_group(group, _entity) return _entity