float CLogicEntity::getRadius() { switch (getType()) { case LE_DYNAMIC: return 10; case LE_STATIC: { if (staticEntity->type == ET_MAPMODEL) { vec bbcenter, bbradius; model *m = theModel; if (m) { LogicEntityPtr ptr = LogicSystem::getLogicEntity(getUniqueId()); assert(ptr.get()); m->collisionbox(0, bbcenter, bbradius, ptr.get()); rotatebb(bbcenter, bbradius, int(staticEntity->attr1)); bbcenter.add(staticEntity->o); return bbradius.x + bbradius.y; } else { Logging::log(Logging::WARNING, "Invalid mapmodel model, cannot find radius\r\n"); return 8; } } else return 8; } }; assert(0 && "getting the radius of a NONE or non-Sauer LogicEntity!"); return -1; }
bool getentboundingbox(extentity &e, ivec &o, ivec &r) { switch(e.type) { case ET_EMPTY: return false; case ET_MAPMODEL: { LogicEntityPtr entity = LogicSystem::getLogicEntity(e); // INTENSITY model *m = entity.get() ? entity->getModel() : NULL; // INTENSITY if(m) { vec center, radius; m->boundbox(0, center, radius, entity.get()); // INTENSITY: entity rotatebb(center, radius, e.attr1); o = e.o; o.add(center); r = radius; r.add(1); o.sub(r); r.mul(2); break; } } // invisible mapmodels use entselradius default: o = e.o; o.sub(GETIV(entselradius)); r.x = r.y = r.z = GETIV(entselradius)*2; break; } return true; }
vec CLogicEntity::getOrigin() { switch (getType()) { case LE_DYNAMIC: return dynamicEntity->o; case LE_STATIC: { if (staticEntity->type == ET_MAPMODEL) { vec bbcenter, bbradius; model *m = theModel; if (m) { LogicEntityPtr ptr = LogicSystem::getLogicEntity(getUniqueId()); assert(ptr.get()); m->collisionbox(0, bbcenter, bbradius, ptr.get()); rotatebb(bbcenter, bbradius, int(staticEntity->attr1)); bbcenter.add(staticEntity->o); return bbcenter; } else { Logging::log(Logging::WARNING, "Invalid mapmodel model\r\n"); return staticEntity->o; } } else return staticEntity->o; } }; assert(0 && "getting the origin of a NONE or non-Sauer LogicEntity!"); return vec(0,0,0); }
LogicEntityPtr V8Engine::getCLogicEntity(Handle<Object> scriptingEntity) { //// static Benchmarker benchmarker; //// benchmarker.start(); LogicEntityPtr ret; // for (int i = 0; i < 10; i++) // For speed testing/profiling - simple way to see how much effect this has, by worsening it { // We do this in a slow but sure manner: read the uniqueId from JS, // and look up the entity using that. In the future, speed this up // using private data or some other method int uniqueId = scriptingEntity->Get(String::New("uniqueId"))->IntegerValue(); ret = LogicSystem::getLogicEntity(uniqueId); Logging::log(Logging::INFO, "V8 getting the CLE for UID %d\r\n", uniqueId); //// benchmarker.stop(); //// SystemManager::showBenchmark(" ---V8lookup---", benchmarker); if (!ret.get()) { Logging::log(Logging::ERROR, "Cannot find CLE for entity %d\r\n", uniqueId); printV8Value(scriptingEntity, true); } } return ret; }
void CharacterRendering::render(fpsent* entity) { Logging::log(Logging::INFO, "CharacterRendering::rendering %d\r\n", LogicSystem::getUniqueId(entity)); INDENT_LOG(Logging::INFO); if (!ClientSystem::loggedIn) // If not logged in remotely, do not render, because entities lack all the fields like model_name // in the future, perhaps add these, if we want local rendering { Logging::log(Logging::INFO, "Not logged in remotely, so not rendering\r\n"); return; } LogicEntityPtr logicEntity = LogicSystem::getLogicEntity(entity->uniqueId); if ( !logicEntity.get() ) { Logging::log(Logging::INFO, "fpsent exists, but no logic entity yet for it, so not rendering\r\n"); return; } lua::engine.getref(logicEntity.get()->luaRef); if (!lua::engine.t_get<bool>("initialized")) { Logging::log(Logging::INFO, "Not initialized, so not rendering\r\n"); return; } lua::engine.pop(1); // Render client using model name, attachments, and animation information Logging::log(Logging::INFO, "Rendering %d, with o=(%f,%f,%f)\r\n", logicEntity.get()->getUniqueId(), logicEntity.get()->getOrigin().x, logicEntity.get()->getOrigin().y, logicEntity.get()->getOrigin().z); model* theModel = logicEntity.get()->getModel(); if (theModel) { renderclient(entity, theModel->name(), logicEntity, logicEntity.get()->attachments[0].name ? logicEntity.get()->attachments : NULL, 0, logicEntity.get()->getAnimation(), 300, // Delay TODO: Figure out what this is entity->lastaction, entity->lastpain); } else { Logging::log(Logging::INFO, "No model, so no render.\r\n"); } // INTENSITY: Class above head in edit mode if (editmode) particle_textcopy(entity->abovehead(), logicEntity.get()->getClass().c_str(), 16, 1); Logging::log(Logging::INFO, "CharacterRendering::render complete.\r\n"); }
void LogicSystem::unregisterLogicEntity(LogicEntityPtr entity) { assert(0); // Deprecated XXX Logging::log(Logging::DEBUG, "UNregisterLogicEntity: %d\r\n", entity.get()->getUniqueId()); int uniqueId = entity.get()->getUniqueId(); logicEntities.erase(uniqueId); // TODO: Cleanup // if (newEntity.get()->scriptEntity) { // delete newEntity.get()->scriptEntity; // } }
void luaFocusOnEntity(int uniqueId) { // Orient towards TODO: Move to WorldSystem or such LogicEntityPtr entity = LogicSystem::getLogicEntity(uniqueId); if (entity.get()) { vec pos(entity.get()->getOrigin()); pos.sub(player->o); vectoyawpitch(pos, player->yaw, player->pitch); // Target and Show details window TargetingControl::targetLogicEntity = entity; showEditEntityGUI(); } else { IntensityCEGUI::showMessage("Manage Entities", "That entity no longer exists", false); // luaPopulateEntityList(...) TODO } }
LogicEntityPtr TraceMonkeyEngine::getCLogicEntity(JSObject* scriptingEntity) { // We do this in a slow but sure manner: read the uniqueId from JS, // and look up the entity using that. In the future, speed this up // using private data or some other method jsval temp; bool success = JS_GetProperty(context, scriptingEntity, "uniqueId", &temp); assert(success); assert(JSVAL_IS_INT(temp)); int uniqueId = JSVAL_TO_INT(temp); LogicEntityPtr ret = LogicSystem::getLogicEntity(uniqueId); Logging::log(Logging::DEBUG, "TraceMonkey getting the CLE for UID %d\r\n", uniqueId); assert(ret.get()); return ret; }
void LogicSystem::registerLogicEntity(LogicEntityPtr newEntity) { Logging::log(Logging::DEBUG, "C registerLogicEntity: %d\r\n", newEntity.get()->getUniqueId()); INDENT_LOG(Logging::DEBUG); int uniqueId = newEntity.get()->getUniqueId(); assert(logicEntities.find(uniqueId) == logicEntities.end()); logicEntities.insert( LogicEntityMap::value_type( uniqueId, newEntity ) ); newEntity.get()->scriptEntity = ScriptEngineManager::getGlobal()->call("getEntity", uniqueId); assert(newEntity.get()->scriptEntity.get()); // Cannot be NULL assert( ! ( newEntity.get()->scriptEntity->compare(ScriptEngineManager::getNull()) ) ); // Cannot be NULL newEntity.get()->scriptEntity->debugPrint(); Logging::log(Logging::DEBUG, "C registerLogicEntity completes\r\n"); }