bool MapfileLoadAction::shouldAbandon(float secondsElapsed) { Logging::log(Logging::DEBUG, "Waiting for mapfile... %.1f seconds\r\n", secondsElapsed); INDENT_LOG(Logging::DEBUG); if (!acted) { // Queue SubfileActions for both subfiles AssetId subId; subId = MapfileManager::getSubfileName(assetId + ".cfg"); AssetManager::getManagerByType(AssetManager::RAWFILE)->actOnAsset( subId, AssetActionPtr( new SubfileAction(subId, this) ) ); subId = MapfileManager::getSubfileName(assetId + ".ogz"); AssetManager::getManagerByType(AssetManager::RAWFILE)->actOnAsset( subId, AssetActionPtr( new SubfileAction(subId, this) ) ); acted = true; // Do not act twice! } return false; // Never give up }
void LogicSystem::setupNonSauer(int uid) { logger::log(logger::DEBUG, "setupNonSauer: %d\r\n", uid); INDENT_LOG(logger::DEBUG); LogicSystem::registerLogicEntityNonSauer(uid); }
void LogicSystem::manageActions(long millis) { logger::log(logger::INFO, "manageActions: %d", millis); INDENT_LOG(logger::INFO); if (lua::L) lua::call_external("frame_handle", "ii", millis, lastmillis); logger::log(logger::INFO, "manageActions complete"); }
void TraceMonkeyEngine::init() { Logging::log(Logging::DEBUG, "TraceMonkeyEngine::init\r\n"); INDENT_LOG(Logging::DEBUG); assert(runtime == NULL); runtime = JS_NewRuntime(8L * 1024L * 1024L); // Force GC after X MB. if (runtime == NULL) { Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n"); assert(0); } /* Create a context. */ context = JS_NewContext(runtime, 8192); if (context == NULL) { Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n"); assert(0); } JS_SetOptions(context, JSOPTION_VAROBJFIX); JS_SetVersion(context, JSVERSION_ECMA_3); JS_SetErrorReporter(context, reportError); // Create the global object. Store it locally for a while until it is usable by others JSObject* _global = JS_NewObject(context, &global_class, NULL, NULL); if (_global == NULL) { Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n"); assert(0); } /* Populate the global object with the standard globals, like Object and Array. */ if (!JS_InitStandardClasses(context, _global)) { Logging::log(Logging::ERROR, "Cannot create TraceMonkey runtime\r\n"); assert(0); } // Create our internal wrappers globalValue = ScriptValuePtr(new TraceMonkeyValue( this, true, OBJECT_TO_JSVAL(_global) )); global = _global; // Now that globalValue is set, it is usable by others, so reveal it // JITting // JS_ToggleOptions(context, JSOPTION_JIT); // Might be buggy, wait for 1.8 to release // JS_MaybeGC - call during idle time in the main loop? Or other method? // Use JS_SetContextPrivate and JS_GetContextPrivate to associate application-specific data with a context. // - Useful for security checks, once we have a context for the system and sandboxed contexts // for user scripts // Debugging features JS_SetGCZeal(context, 2); // XXX This is 'extremely high' - make a parameter, see MDC docs }
bool MapfileManager::checkLocalAssetPresence(const AssetId& id, bool takeAction) { Logging::log(Logging::DEBUG, "MapfileManager::checkLocalAssetPresence : %s (action: %d)\r\n", id.c_str(), takeAction); INDENT_LOG(Logging::DEBUG); return AssetManager::getManagerByType(AssetManager::RAWFILE)->checkLocalAssetPresence(getSubfileName(id + ".cfg")) && AssetManager::getManagerByType(AssetManager::RAWFILE)->checkLocalAssetPresence(getSubfileName(id + ".ogz")); }
void V8Engine::init() { Logging::log(Logging::DEBUG, "V8Engine::init:\r\n"); INDENT_LOG(Logging::DEBUG); HandleScope handleScope; // Create a template for the global object. Logging::log(Logging::DEBUG, "Creating global\r\n"); // _global = ObjectTemplate::New(); Logging::log(Logging::DEBUG, "Creating context\r\n"); context = Context::New(); //NULL, _global); context->Enter(); // Create our internal wrappers Logging::log(Logging::DEBUG, "Creating wrapper for global\r\n"); globalValue = ScriptValuePtr(new V8Value(this, context->Global())); #if 0 // Setup debugger, if required - XXX Doesn't work // Debug::SetDebugEventListener(debuggerListener); // runFile("src/thirdparty/v8/src/debug-delay.js"); // FIXME: remove hardcoded src/.. runFile("src/javascript/intensity/V8Debugger.js"); // FIXME: remove hardcoded src/javascript v8::Handle<v8::Value> result = ((V8Value*)(getGlobal()->getProperty("__debuggerListener").get()))->value; assert(result->IsObject()); Local<Object> debuggerListener = result->ToObject(); assert(debuggerListener->IsFunction()); Debug::SetDebugEventListener(debuggerListener); runScript("Debug.setBrzzzzzzzzzeakOnException()"); Local<String> source = String::New( "temp = function () { Debug.setBreakOnException(); return 5098; } " ); Local<Script> code = Script::Compile(source); Local<Value> result2 = code->Run(); printV8Value(result2, true); assert(result2->IsObject()); Local<Object> obj = result2->ToObject(); assert(obj->IsFunction()); Local<Function> func = Function::Cast(*obj); Handle<Value> output = Debug::Call(func); printV8Value(output, true); assert(0); #endif Logging::log(Logging::DEBUG, "V8Engine::init complete.\r\n"); }
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::registerLogicEntity(CLogicEntity *newEntity) { logger::log(logger::DEBUG, "C registerLogicEntity: %d", newEntity->getUniqueId()); INDENT_LOG(logger::DEBUG); int uniqueId = newEntity->getUniqueId(); assert(!logicEntities.access(uniqueId)); logicEntities.access(uniqueId, newEntity); logger::log(logger::DEBUG, "C registerLogicEntity completes"); }
void LogicSystem::clear(bool restart_lua) { logger::log(logger::DEBUG, "clear()ing LogicSystem"); INDENT_LOG(logger::DEBUG); if (lua::L) { lua::call_external("entities_remove_all", ""); enumerate(logicEntities, CLogicEntity*, ent, assert(!ent)); if (restart_lua) lua::reset(); } LogicSystem::initialized = false; }
V8Value::V8Value(ScriptEngine* _engine, double _value) : ScriptValue(_engine) { debugName = "double value no. " + Utility::toString(__nameCounter); Logging::log(Logging::INFO, "Going to create a V8 value of: %s\r\n", debugName.c_str()); INDENT_LOG(Logging::INFO); value = Persistent<Value>::New(Number::New(_value)); printV8Value(value); Logging::log(Logging::INFO, "Created a V8 value of: %s\r\n", debugName.c_str()); __nameCounter += 1; }
V8Value::V8Value(ScriptEngine* _engine, Handle<Value> _value) : ScriptValue(_engine) { debugName = "Handle<Value> value no. " + Utility::toString(__nameCounter); Logging::log(Logging::INFO, "Going to create a V8 reference: %s\r\n", debugName.c_str()); INDENT_LOG(Logging::INFO); value = Persistent<Value>::New(_value); printV8Value(value); Logging::log(Logging::INFO, "Created a V8 reference: %s\r\n", debugName.c_str()); __nameCounter += 1; }
bool MessageManager::receive(int type, int receiver, int sender, ucharbuf &p) { if (messageTypes.access(type) == NULL) { logger::log(logger::DEBUG, "MessageSystem: Receiving a message of type %d from %d: Type not found in our extensions to Sauer", type, sender); return false; // This isn't one of our messages, hopefully it's a sauer one } MessageType *message_type = messageTypes[type]; logger::log(logger::DEBUG, "MessageSystem: Receiving a message of type %d from %d: %s", type, sender, message_type->type_name); INDENT_LOG(logger::DEBUG); message_type->receive(receiver, sender, p); logger::log(logger::DEBUG, "MessageSystem: message successfully handled"); return true; }
bool MessageManager::receive(int type, int receiver, int sender, ucharbuf &p) { Logging::log(Logging::DEBUG, "MessageSystem: Trying to handle a message, type/sender:: %d/%d\r\n", type, sender); INDENT_LOG(Logging::DEBUG); MessageMap::iterator messageType = messageTypes.find(type); if (messageType == messageTypes.end()) { Logging::log(Logging::DEBUG, "Message type not found in our extensions to Sauer: %d\r\n", type); return false; // This isn't one of our messages, hopefully it's a sauer one } messageType->second->receive(receiver, sender, p); Logging::log(Logging::DEBUG, "MessageSystem: message successfully handled\r\n"); return true; }
void LogicSystem::setupCharacter(int uid, int cn) { logger::log(logger::DEBUG, "setupCharacter: %d, %d", uid, cn); INDENT_LOG(logger::DEBUG); gameent* gameEntity; #ifndef SERVER logger::log(logger::DEBUG, "client numbers: %d, %d", ClientSystem::playerNumber, cn); if (uid == ClientSystem::uniqueId) lua::call_external("entity_set_cn", "ii", uid, (cn = ClientSystem::playerNumber)); #endif assert(cn >= 0); #ifndef SERVER // If this is the player. There should already have been created an gameent for this client, // which we can fetch with the valid client # logger::log(logger::DEBUG, "UIDS: in ClientSystem %d, and given to us%d", ClientSystem::uniqueId, uid); if (uid == ClientSystem::uniqueId) { logger::log(logger::DEBUG, "This is the player, use existing clientnumber for gameent (should use player1?)"); gameEntity = game::getclient(cn); // Wipe clean the uid set for the gameent, so we can re-use it. gameEntity->uid = -77; } else #endif { logger::log(logger::DEBUG, "This is a remote client or NPC, do a newClient for the gameent"); // This is another client, perhaps NPC. Connect this new client using newClient gameEntity = game::newclient(cn); } // Register with the C++ system. LogicSystem::setUniqueId(gameEntity, uid); LogicSystem::registerLogicEntity(gameEntity); }
TraceMonkeyValue::TraceMonkeyValue(ScriptEngine* _engine, double _value) : ScriptValue(_engine) { debugName = "double value no. " + Utility::toString(__nameCounter); Logging::log(Logging::INFO, "Going to create a TM value of: %s\r\n", debugName.c_str()); INDENT_LOG(Logging::INFO); value = DOUBLE_TO_JSVAL(_value); bool ret = JS_AddNamedRoot(TraceMonkeyEngine::context, &(this->value), debugName.c_str()); // Ensure our value won't be GCed assert(ret); printJSVAL(value); Logging::log(Logging::INFO, "Created a TM value of: %s\r\n", debugName.c_str()); __nameCounter += 1; JS_GC(TraceMonkeyEngine::context); // XXX For debugging purposes Logging::log(Logging::INFO, "post-creation GC ok.\r\n"); }
void LogicSystem::setupExtent(int uid, int type) { logger::log(logger::DEBUG, "setupExtent: %d, %d", uid, type); INDENT_LOG(logger::DEBUG); extentity *e = new extentity; entities::getents().add(e); e->type = type; e->o = vec(0, 0, 0); int numattrs = getattrnum(type); for (int i = 0; i < numattrs; ++i) e->attr.add(0); extern void addentity(extentity* entity); addentity(e); attachentity(*e); LogicSystem::setUniqueId(e, uid); LogicSystem::registerLogicEntity(e); }
void ClientSystem::gotoLoginScreen() { assert(0); #if 0 Logging::log(Logging::DEBUG, "Going to login screen\r\n"); INDENT_LOG(Logging::DEBUG); LogicSystem::init(); // This is also done later, but as the mainloop assumes there is always a ScriptEngine, we do it here as well ClientSystem::onDisconnect(); // disconnect has several meanings... localconnect(); game::gameconnect(false); // FPSServerInterface::vote("login", 0); game::changemap("login"); Logging::log(Logging::DEBUG, "Going to login screen complete\r\n"); #endif }
void CameraControl::positionCamera(physent* camera1) { Logging::log(Logging::INFO, "CameraControl::positionCamera\r\n"); INDENT_LOG(Logging::INFO); if (useForcedCamera || useForcedPosition || useForcedYaw || useForcedPitch || useForcedRoll) { if (useForcedPosition) { camera1->o = forcedCamera.o; useForcedPosition = false; }; if (useForcedYaw) { camera1->yaw = forcedCamera.yaw; useForcedYaw = false; }; if (useForcedPitch) { camera1->pitch = forcedCamera.pitch; useForcedPitch = false; }; if (useForcedRoll) { camera1->roll = forcedCamera.roll; useForcedRoll = false; }; if (useForcedCamera) { useForcedCamera = false; // Prepare for next frame return; } } // Sync camera height to scripts, if necessary static float lastCameraHeight = -1; if (ScriptEngineManager::hasEngine() && lastCameraHeight != cameraheight) { lastCameraHeight = cameraheight; ScriptEngineManager::getGlobal()->getProperty("Global")->setProperty("cameraHeight", cameraheight); } // If we just left forced camera mode, restore thirdperson state if (savedThirdperson != -1) { thirdperson = savedThirdperson; savedThirdperson = -1; } float saved_camera_speed = camera1->maxspeed; // Kripken: need to save this, because camera1 =?= player1 camera1->maxspeed = 50; // This speed determines the distance of the camera, so the Sauer way of tying it to the // player's speed is not completely general vec dir; vecfromyawpitch(camera1->yaw, camera1->pitch, -1, 0, dir); if (GuiControl::isCharacterViewing()) camera1->o = player->o; // Start from player if(game::collidecamera()) { vec cameraOrigin = camera1->o; if (thirdperson) { vec up(0, 0, 1); movecamera(camera1, up, cameraheight, 1); movecamera(camera1, up, clamp(cameraheight- camera1->o.dist(cameraOrigin), 0.0f, 1.0f), 0.1f); // Find distance to obstacle } vec cameraOrigin2 = camera1->o; movecamera(camera1, dir, cam_dist, 1); movecamera(camera1, dir, clamp(cam_dist - camera1->o.dist(cameraOrigin2), 0.0f, 1.0f), 0.1f); // Find distance to obstacle if (smoothcamera) { float intendedDist = camera1->o.dist(cameraOrigin2)*(1.0f-cameraavoid); static float lastDist = 5; float ACTUAL_DISTANCE_FACTOR = clamp(1.0f - (curtime/1000.0f)/smoothcamera, 0.0f, 1.0f); float actualDist = ACTUAL_DISTANCE_FACTOR*lastDist + (1-ACTUAL_DISTANCE_FACTOR)*intendedDist; // Start again, move to current distance camera1->o = cameraOrigin2; movecamera(camera1, dir, actualDist, 1); movecamera(camera1, dir, clamp(actualDist - camera1->o.dist(cameraOrigin2), 0.0f, 1.0f), 0.1f); lastDist = actualDist; } } else { camera1->o.z += cameraheight; camera1->o.add(vec(dir).mul(cam_dist)); } camera1->maxspeed = saved_camera_speed; // Kripken: Smooth camera movement: We interpolate our the new calculated position with the old one, smoothly static fpsent actualCamera; // Need fpsent for new normalization functions static vec lastPlayerPosition; vec temp(actualCamera.o); temp.sub(camera1->o); actualCamera.normalize_yaw(camera1->yaw); actualCamera.normalize_pitch(camera1->pitch); float yawDelta = camera1->yaw - actualCamera.yaw; float pitchDelta = camera1->pitch - actualCamera.pitch; // Only interpolate if we are fairly close, otherwise this might be a new map, or we teleported, etc. if (smoothcamera && !GuiControl::isMouselooking() && temp.magnitude() < 50*player->radius && fabs(yawDelta) < 30.0f && fabs(pitchDelta) < 30.0f) { float ACTUAL_CAMERA_FACTOR = clamp(1.0f - (curtime/1000.0f)/smoothcamera, 0.0f, 1.0f); vec temp = player->o; temp.sub(lastPlayerPosition); actualCamera.o.add(temp); // Prevent camera stutter actualCamera.o.mul(ACTUAL_CAMERA_FACTOR); temp = camera1->o; temp.mul(1-ACTUAL_CAMERA_FACTOR); actualCamera.o.add(temp); actualCamera.yaw = ACTUAL_CAMERA_FACTOR*actualCamera.yaw + (1-ACTUAL_CAMERA_FACTOR)*camera1->yaw; actualCamera.pitch = ACTUAL_CAMERA_FACTOR*actualCamera.pitch + (1-ACTUAL_CAMERA_FACTOR)*camera1->pitch; camera1->o = actualCamera.o; camera1->yaw = actualCamera.yaw; camera1->pitch = actualCamera.pitch; // camera1->o.z += player->aboveeye + player->eyeheight; } else { actualCamera.o = camera1->o; actualCamera.yaw = camera1->yaw; actualCamera.pitch = camera1->pitch; } lastPlayerPosition = player->o; }