static PyObject *entity_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *documentURI = Py_None; static char *kwlist[] = { "documentURI", NULL }; EntityObject *self; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:entity", kwlist, &documentURI)) { return NULL; } documentURI = XmlString_ConvertArgument(documentURI, "documentURI", 1); if (documentURI == NULL) { return NULL; } if (type != &DomletteEntity_Type) { self = Entity(type->tp_alloc(type, 0)); if (self != NULL) { self = entity_init(self, documentURI); } } else { self = Entity_New(documentURI); } Py_DECREF(documentURI); return (PyObject *) self; }
/* ======================================================================================================================= Map_New ======================================================================================================================= */ void Map_New(void) { common->Printf("Map_New\n"); Map_Free(); Patch_Cleanup(); g_Inspectors->entityDlg.SetEditEntity ( NULL ); world_entity = Entity_New(); world_entity->brushes.onext = world_entity->brushes.oprev = &world_entity->brushes; SetKeyValue(world_entity, "classname", "worldspawn"); world_entity->eclass = Eclass_ForName("worldspawn", true); g_pParentWnd->GetCamera()->Camera().angles[YAW] = 0; g_pParentWnd->GetCamera()->Camera().angles[PITCH] = 0; VectorCopy(vec3_origin, g_pParentWnd->GetCamera()->Camera().origin); g_pParentWnd->GetCamera()->Camera().origin[2] = 48; VectorCopy(vec3_origin, g_pParentWnd->GetXYWnd()->GetOrigin()); Map_RestoreBetween(); Sys_UpdateWindows(W_ALL); mapModified = 0; g_qeglobals.mapVersion = MAP_VERSION; }
entity_t *EntityFromMapEntity(idMapEntity *mapent, CWaitDlg *dlg) { entity_t *ent = NULL; if (mapent) { ent = Entity_New(); ent->brushes.onext = ent->brushes.oprev = &ent->brushes; ent->origin.Zero(); ent->epairs = mapent->epairs; GetVectorForKey(ent, "origin", ent->origin); int count = mapent->GetNumPrimitives(); long lastUpdate = 0; idStr status; for (int i = 0; i < count; i++) { idMapPrimitive *prim = mapent->GetPrimitive(i); if (prim) { // update 20 times a second if ((GetTickCount() - lastUpdate) > 50) { lastUpdate = GetTickCount(); if (prim->GetType() == idMapPrimitive::TYPE_BRUSH) { sprintf(status, "Reading primitive %i (brush)", i); } else if (prim->GetType() == idMapPrimitive::TYPE_PATCH) { sprintf(status, "Reading primitive %i (patch)", i); } dlg->SetText(status, true); } if (dlg->CancelPressed()) { return ent; } brush_t *b = NULL; if (prim->GetType() == idMapPrimitive::TYPE_BRUSH) { idMapBrush *mapbrush = reinterpret_cast<idMapBrush *>(prim); b = BrushFromMapBrush(mapbrush, ent->origin); } else if (prim->GetType() == idMapPrimitive::TYPE_PATCH) { idMapPatch *mappatch = reinterpret_cast<idMapPatch *>(prim); b = BrushFromMapPatch(mappatch, ent->origin); } if (b) { b->owner = ent; // add to the end of the entity chain b->onext = &ent->brushes; b->oprev = ent->brushes.oprev; ent->brushes.oprev->onext = b; ent->brushes.oprev = b; } } } } return ent; }
/* ======================================================================================================================= Entity_Parse If onlypairs is set, the classname info will not be looked up, and the entity will not be added to the global list. Used for parsing the project. ======================================================================================================================= */ entity_t *Entity_Parse(bool onlypairs, brush_t *pList) { entity_t *ent; if (!GetToken(true)) { return NULL; } if (strcmp(token, "{")) { Error("ParseEntity: { not found"); } ent = Entity_New(); ent->brushes.onext = ent->brushes.oprev = &ent->brushes; ent->origin.Zero(); int n = 0; do { if (!GetToken(true)) { Warning("ParseEntity: EOF without closing brace"); return NULL; } if (!strcmp(token, "}")) { break; } if (!strcmp(token, "{")) { GetVectorForKey(ent, "origin", ent->origin); brush_t *b = Brush_Parse(ent->origin); if (b != NULL) { b->owner = ent; // add to the end of the entity chain b->onext = &ent->brushes; b->oprev = ent->brushes.oprev; ent->brushes.oprev->onext = b; ent->brushes.oprev = b; } else { break; } } else { ParseEpair(&ent->epairs); } } while (1); if (onlypairs) { return ent; } return Entity_PostParse(ent, pList); }
/* ======================================================================================================================= Entity_Clone ======================================================================================================================= */ entity_t *Entity_Clone(entity_t *e) { entity_t *n; n = Entity_New(); n->brushes.onext = n->brushes.oprev = &n->brushes; n->eclass = e->eclass; n->rotation = e->rotation; n->origin = e->origin; // add the entity to the entity list Entity_AddToList(n, &entities); n->epairs = e->epairs; return n; }
static ExpatStatus builder_StartDocument(void *userState) { ParserState *state = (ParserState *)userState; PyObject *uri; EntityObject *document; #ifdef DEBUG_PARSER fprintf(stderr, "--- builder_StartDocument(%p)\n", state); #endif uri = ExpatReader_GetBase(state->reader); if (state->entity_factory) { PyObject *obj = PyObject_CallFunction(state->entity_factory, "N", uri); if (obj) { if (Entity_Check(obj)) { /* populate the remaining factory callables */ if (!load_factory(obj, "xml_element_factory", &DomletteElement_Type, &state->element_factory)) goto factory_error; if (!load_factory(obj, "xml_text_factory", &DomletteText_Type, &state->text_factory)) goto factory_error; if (!load_factory(obj, "xml_processing_instruction_factory", &DomletteProcessingInstruction_Type, &state->processing_instruction_factory)) goto factory_error; if (!load_factory(obj, "xml_comment_factory", &DomletteComment_Type, &state->comment_factory)) goto factory_error; } else { PyErr_Format(PyExc_TypeError, "entity_factory should return entity, not %s", obj->ob_type->tp_name); factory_error: Py_DECREF(obj); return EXPAT_STATUS_ERROR; } } document = Entity(obj); } else { document = Entity_New(uri); Py_DECREF(uri); } if (document == NULL) return EXPAT_STATUS_ERROR; /* Callout to matcher */ if (state->rule_matcher) { if (RuleMatch_StartDocument(state->rule_matcher, (PyObject *) document) < 0) { Py_DECREF(document); return EXPAT_STATUS_ERROR; } } if (ParserState_AddContext(state, (NodeObject *)document) == NULL) { Py_DECREF(document); return EXPAT_STATUS_ERROR; } Py_INCREF(document); state->owner_document = document; return EXPAT_STATUS_OK; }
/* ======================================================================================================================= Entity_Create Creates a new entity out of the selected_brushes list. If the entity class is fixed size, the brushes are only used to find a midpoint. Otherwise, the brushes have their ownership transfered to the new entity. ======================================================================================================================= */ entity_t *Entity_Create(eclass_t *c, bool forceFixed) { entity_t *e; brush_t *b; idVec3 mins, maxs, origin; char text[32]; texdef_t td; brushprimit_texdef_t bp; // check to make sure the brushes are ok for (b = selected_brushes.next; b != &selected_brushes; b = b->next) { if (b->owner != world_entity) { Sys_Status("Entity NOT created, brushes not all from world\n"); Sys_Beep(); return NULL; } } idStr str; if (c->defArgs.GetString("model", "", str) && c->entityModel == NULL) { c->entityModel = gameEdit->ANIM_GetModelFromEntityDef( &c->defArgs ); } // create it e = Entity_New(); e->brushes.onext = e->brushes.oprev = &e->brushes; e->eclass = c; e->epairs.Copy(c->args); SetKeyValue(e, "classname", c->name); Entity_Name(e, false); // add the entity to the entity list Entity_AddToList(e, &entities); if (c->fixedsize) { // // just use the selection for positioning b = selected_brushes.next; for (i=0 ; // i<3 ; i++) { e->origin[i] = b->mins[i] - c->mins[i]; } // Select_GetMid(e->origin); VectorCopy(e->origin, origin); // create a custom brush VectorAdd(c->mins, e->origin, mins); VectorAdd(c->maxs, e->origin, maxs); b = Brush_Create(mins, maxs, &c->texdef); Entity_LinkBrush(e, b); if (c->defMaterial.Length()) { td.SetName(c->defMaterial); Brush_SetTexture(b, &td, &bp, false); } // delete the current selection Select_Delete(); // select the new brush b->next = b->prev = &selected_brushes; selected_brushes.next = selected_brushes.prev = b; Brush_Build(b); } else { Select_GetMid(origin); // change the selected brushes over to the new entity for (b = selected_brushes.next; b != &selected_brushes; b = b->next) { Entity_UnlinkBrush(b); Entity_LinkBrush(e, b); Brush_Build(b); // so the key brush gets a name if (c->defMaterial.Length()) { td.SetName(c->defMaterial); Brush_SetTexture(b, &td, &bp, false); } } //for (int i = 0; i < 3; i++) { // origin[i] = vMin[i] + vMax[i] * 0.5; //} if (!forceFixed) { SetKeyValue(e, "model", ValueForKey(e, "name")); } } sprintf(text, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]); SetKeyValue(e, "origin", text); VectorCopy(origin, e->origin); Sys_UpdateWindows(W_ALL); return e; }