/// <summary> /// This is called after parsing an EntityDef and for each entity spawnArgs before /// merging the entitydef. It could be done post-merge, but that would /// avoid the fast pre-cache check associated with each entityDef. /// </summary> /// <param name="dict"></param> public override void CacheDictionaryMedia(idDict dict) { #region Model foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix("model")) { // precache model/animations if((kvp.Value != string.Empty) && (idR.DeclManager.FindType<idDecl>(DeclType.ModelDef, kvp.Value, false) == null)) { // precache the render model idR.RenderModelManager.FindModel(kvp.Value); // precache .cm files only idR.CollisionModelManager.LoadModel(kvp.Value, true); } } #endregion #region Gui foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix("gui")) { string keyLower = kvp.Key.ToLower(); if((keyLower == "gui_noninteractive") || (keyLower.StartsWith("gui_parm") == true) || (keyLower == "gui_inventory")) { // unfortunate flag names, they aren't actually a gui } else { idR.DeclManager.MediaPrint(string.Format("Precaching gui {0}", kvp.Value)); idUserInterface gui = new idUserInterface(); if(gui != null) { gui.InitFromFile(kvp.Value); idE.UIManager.Remove(gui); } } } #endregion #region Fx foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix("fx")) { idR.DeclManager.MediaPrint(string.Format("Precaching fx {0}", kvp.Value)); idR.DeclManager.FindType<idDecl>(DeclType.Fx, kvp.Value); } #endregion #region Smoke foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix("smoke")) { string prtName = kvp.Value; int dash = prtName.IndexOf('-'); if(dash > 0) { prtName = prtName.Substring(0, dash); } idR.DeclManager.FindType(DeclType.Particle, prtName); } #endregion #region Skin foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix("skin")) { idR.DeclManager.MediaPrint(string.Format("Precaching skin {0}", kvp.Value)); idR.DeclManager.FindType(DeclType.Skin, kvp.Value); } #endregion #region Def foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix("def")) { FindEntityDef(kvp.Value, false); } #endregion #region Misc string value = dict.GetString("s_shader"); if(value != string.Empty) { idR.DeclManager.FindType<idDecl>(DeclType.Sound, value); } value = dict.GetString("texture"); if(value != string.Empty) { idR.DeclManager.FindType<idDecl>(DeclType.Material, value); } Dictionary<string, DeclType> cacheElements = new Dictionary<string, DeclType>() { { "snd", DeclType.Sound }, { "mtr", DeclType.Material }, { "inv_icon", DeclType.Material }, { "pda_name", DeclType.Pda }, { "video", DeclType.Video }, { "audio", DeclType.Audio } }; foreach(KeyValuePair<string, DeclType> element in cacheElements) { foreach(KeyValuePair<string, string> kvp in dict.MatchPrefix(element.Key)) { idR.DeclManager.FindType<idDecl>(element.Value, kvp.Value); } } #endregion }
public override void SpawnPlayer(int clientIndex) { idConsole.WriteLine("SpawnPlayer: {0}", clientIndex); idDict args = new idDict(); args.Set("spawn_entnum", clientIndex); args.Set("name", string.Format("player{0}", clientIndex + 1)); // TODO: refactor in to idGameRules args.Set("classname", (this.IsMultiplayer == true) ? "player_doommarine_mp" : "player_doommarine"); idEntity ent = SpawnEntityDef(args); if((ent == null) || (_entities[clientIndex] == null)) { idConsole.Error("Failed to spawn player as {0}", args.GetString("classname")); } // make sure it's a compatible class if((ent is idPlayer) == false) { idConsole.Error("'{0}' spawn the player as a '{1}'. Player spawnclass must be a subclass of Player.", args.GetString("classname"), ent.ClassName); } if(clientIndex >= _clientCount) { _clientCount++; } this.Rules.SpawnPlayer(clientIndex); }
public idEntity SpawnEntityDef(idDict args, bool setDefaults = true) { _spawnArgs = args; string error = string.Empty; string name = string.Empty; string className = string.Empty; if(_spawnArgs.ContainsKey("name") == false) { error = string.Format(" on '{0}'", name); } name = _spawnArgs.GetString("name", ""); className = _spawnArgs.GetString("classname"); idDeclEntity def = FindEntityDef(className, false); if(def == null) { idConsole.Warning("Unknown classname '{0}'{1}.", className, error); return null; } _spawnArgs.SetDefaults(def.Dict); // check if we should spawn a class object string spawn = _spawnArgs.GetString("spawnclass", null); if(spawn != null) { // need to check all loaded assemblies to find the type we're looking for. Type type = null; foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { // all entity types must be in the idTech4.Game.Entities namespace. string typeName = string.Format("idTech4.Game.Entities.{0}", spawn); type = asm.GetType(typeName, false, true); if(type != null) { break; } } if(type == null) { idConsole.Warning("Could not spawn '{0}'. Class '{1}' not found{2}.", className, spawn, error); return null; } object obj = type.Assembly.CreateInstance(type.FullName); if(obj == null) { idConsole.Warning("Could not spawn '{0}'. Instance could not be created{1}.", className, error); return null; } idEntity ent = (idEntity) obj; ent.Spawn(); idConsole.DeveloperWriteLine("Spawned {0} ({1})", ent.ClassName, ent.GetType().FullName); return ent; } idConsole.Warning("TODO: Spawnfunc"); // check if we should call a script function to spawn /*spawnArgs.GetString( "spawnfunc", NULL, &spawn ); if ( spawn ) { const function_t *func = program.FindFunction( spawn ); if ( !func ) { Warning( "Could not spawn '%s'. Script function '%s' not found%s.", classname, spawn, error.c_str() ); return false; } idThread *thread = new idThread( func ); thread->DelayedStart( 0 ); return true; } Warning( "%s doesn't include a spawnfunc or spawnclass%s.", classname, error.c_str() ); return false;*/ return null; }
private bool InhibitEntitySpawn(idDict args) { bool result = false; if(this.IsMultiplayer == true) { result = args.GetBool("not_multiplayer", false); } else if(idR.CvarSystem.GetInteger("g_skill") == 0) { result = args.GetBool("not_easy", false); } else if(idR.CvarSystem.GetInteger("g_skill") == 1) { result = args.GetBool("not_medium", false); } else { result = args.GetBool("not_hard", false); } string name; if(idR.CvarSystem.GetInteger("g_skill") == 3) { name = args.GetString("classname").ToLower(); if((name == "item_medkit") || (name == "item_medkit_small")) { result = true; } } if(this.IsMultiplayer == true) { name = args.GetString("classname").ToLower(); if((name == "weapon_bfg") || (name == "weapon_soulcube")) { result = true; } } return result; }
private void InitDefaultPhysics(Vector3 origin, Matrix axis) { string temp = _spawnArgs.GetString("clipmodel", ""); idClipModel clipModel = null; // check if a clipmodel key/value pair is set if (temp != string.Empty) { if (idClipModel.CheckModel(temp) != null) { clipModel = new idClipModel(temp); } } if (_spawnArgs.GetBool("noclipmodel", false) == false) { // check if mins/maxs or size key/value pairs are set if (clipModel == null) { idBounds bounds = idBounds.Zero; bool setClipModel = false; if ((_spawnArgs.ContainsKey("mins") == true) && (_spawnArgs.ContainsKey("maxs") == true)) { bounds = new idBounds(_spawnArgs.GetVector3("mins"), _spawnArgs.GetVector3("maxs")); setClipModel = true; if ((bounds.Min.X > bounds.Max.X) || (bounds.Min.Y > bounds.Max.Y) || (bounds.Min.Z > bounds.Max.Z)) { idConsole.Error("Invalid bounds '{0}'-'{1}' on entity '{2}'", bounds.Min, bounds.Max, this.Name); } } else if (_spawnArgs.ContainsKey("size") == true) { Vector3 size = _spawnArgs.GetVector3("size"); if ((size.X < 0.0f) || (size.Y < 0.0f) || (size.Z < 0.0f)) { idConsole.Error("Invalid size '{0}' on entity '{1}'", size, this.Name); } setClipModel = true; bounds = new idBounds( new Vector3(size.X * -0.5f, size.Y * -0.5f, 0.0f), new Vector3(size.X * 0.5f, size.Y * 0.5f, size.Z) ); } if (setClipModel == true) { int sideCount = _spawnArgs.GetInteger("cyclinder", 0); idTraceModel traceModel = new idTraceModel(); if (sideCount > 0) { idConsole.Warning("TODO: traceModel.SetupCyclinder(bounds, (sideCount < 3) ? 3 : sideCount);"); } else if ((sideCount = _spawnArgs.GetInteger("cone", 0)) > 0) { idConsole.Warning("TODO: traceModel.SetupCone(bounds, (sideCount < 3) ? 3 : sideCount);"); } else { traceModel.SetupBox(bounds); } clipModel = new idClipModel(traceModel); } } // check if the visual model can be used as collision model if (clipModel == null) { temp = _spawnArgs.GetString("model"); if (temp != string.Empty) { if (idClipModel.CheckModel(temp) != null) { clipModel = new idClipModel(temp); } } } } _defaultPhysicsObject.Self = this; _defaultPhysicsObject.SetClipModel(clipModel, 1.0f); _defaultPhysicsObject.SetOrigin(origin); _defaultPhysicsObject.SetAxis(axis); _physics = _defaultPhysicsObject; }
public override RenderEntityComponent ParseSpawnArgsToRenderEntity(idDict args) { RenderEntityComponent renderEntity = new RenderEntityComponent(); idDeclModel modelDef = null; string temp = args.GetString("model"); if (temp != string.Empty) { modelDef = idE.DeclManager.FindType <idDeclModel>(DeclType.ModelDef, temp, false); if (modelDef != null) { renderEntity.Model = modelDef.Model; } if (renderEntity.Model == null) { renderEntity.Model = idE.RenderModelManager.FindModel(temp); } } if (renderEntity.Model != null) { renderEntity.Bounds = renderEntity.Model.GetBounds(renderEntity); } else { renderEntity.Bounds = new idBounds(); } temp = args.GetString("skin"); if (temp != string.Empty) { renderEntity.CustomSkin = idR.DeclManager.FindSkin(temp); } else if (modelDef != null) { renderEntity.CustomSkin = modelDef.DefaultSkin; } temp = args.GetString("shader"); if (temp != null) { renderEntity.CustomMaterial = idR.DeclManager.FindMaterial(temp); } renderEntity.Origin = args.GetVector3("origin", Vector3.Zero); // get the rotation matrix in either full form, or single angle form renderEntity.Axis = args.GetMatrix("rotation", "1 0 0 0 1 0 0 0 1"); if (renderEntity.Axis == Matrix.Identity) { float angle = args.GetFloat("angle"); if (angle != 0.0f) { renderEntity.Axis = new idAngles(0.0f, angle, 0.0f).ToMatrix(); } else { renderEntity.Axis = Matrix.Identity; } } // TODO: //renderEntity.ReferencedSound = null; // get shader parms Vector3 color = args.GetVector3("_color", new Vector3(1, 1, 1)); float[] materialParms = renderEntity.MaterialParameters; materialParms[(int)MaterialParameter.Red] = color.X; materialParms[(int)MaterialParameter.Green] = color.Y; materialParms[(int)MaterialParameter.Blue] = color.Z; materialParms[3] = args.GetFloat("shaderParm3", 1); materialParms[4] = args.GetFloat("shaderParm4", 0); materialParms[5] = args.GetFloat("shaderParm5", 0); materialParms[6] = args.GetFloat("shaderParm6", 0); materialParms[7] = args.GetFloat("shaderParm7", 0); materialParms[8] = args.GetFloat("shaderParm8", 0); materialParms[9] = args.GetFloat("shaderParm9", 0); materialParms[10] = args.GetFloat("shaderParm10", 0); materialParms[11] = args.GetFloat("shaderParm11", 0); renderEntity.MaterialParameters = materialParms; // check noDynamicInteractions flag renderEntity.NoDynamicInteractions = args.GetBool("noDynamicInteractions"); // check noshadows flag renderEntity.NoShadow = args.GetBool("noshadows"); // check noselfshadows flag renderEntity.NoSelfShadow = args.GetBool("noselfshadows"); // init any guis, including entity-specific states int count = renderEntity.Gui.Length; for (int i = 0; i < count; i++) { temp = args.GetString(i == 0 ? "gui" : string.Format("gui{0}", i + 1)); if (temp != null) { renderEntity.Gui[i] = AddRenderGui(temp, args); } } return(renderEntity); }
public override RenderEntityComponent ParseSpawnArgsToRenderEntity(idDict args) { RenderEntityComponent renderEntity = new RenderEntityComponent(); idDeclModel modelDef = null; string temp = args.GetString("model"); if(temp != string.Empty) { modelDef = idE.DeclManager.FindType<idDeclModel>(DeclType.ModelDef, temp, false); if(modelDef != null) { renderEntity.Model = modelDef.Model; } if(renderEntity.Model == null) { renderEntity.Model = idE.RenderModelManager.FindModel(temp); } } if(renderEntity.Model != null) { renderEntity.Bounds = renderEntity.Model.GetBounds(renderEntity); } else { renderEntity.Bounds = new idBounds(); } temp = args.GetString("skin"); if(temp != string.Empty) { renderEntity.CustomSkin = idR.DeclManager.FindSkin(temp); } else if(modelDef != null) { renderEntity.CustomSkin = modelDef.DefaultSkin; } temp = args.GetString("shader"); if(temp != null) { renderEntity.CustomMaterial = idR.DeclManager.FindMaterial(temp); } renderEntity.Origin = args.GetVector3("origin", Vector3.Zero); // get the rotation matrix in either full form, or single angle form renderEntity.Axis = args.GetMatrix("rotation", "1 0 0 0 1 0 0 0 1"); if(renderEntity.Axis == Matrix.Identity) { float angle = args.GetFloat("angle"); if(angle != 0.0f) { renderEntity.Axis = new idAngles(0.0f, angle, 0.0f).ToMatrix(); } else { renderEntity.Axis = Matrix.Identity; } } // TODO: //renderEntity.ReferencedSound = null; // get shader parms Vector3 color = args.GetVector3("_color", new Vector3(1, 1, 1)); float[] materialParms = renderEntity.MaterialParameters; materialParms[(int) MaterialParameter.Red] = color.X; materialParms[(int) MaterialParameter.Green] = color.Y; materialParms[(int) MaterialParameter.Blue] = color.Z; materialParms[3] = args.GetFloat("shaderParm3", 1); materialParms[4] = args.GetFloat("shaderParm4", 0); materialParms[5] = args.GetFloat("shaderParm5", 0); materialParms[6] = args.GetFloat("shaderParm6", 0); materialParms[7] = args.GetFloat("shaderParm7", 0); materialParms[8] = args.GetFloat("shaderParm8", 0); materialParms[9] = args.GetFloat("shaderParm9", 0); materialParms[10] = args.GetFloat("shaderParm10", 0); materialParms[11] = args.GetFloat("shaderParm11", 0); renderEntity.MaterialParameters = materialParms; // check noDynamicInteractions flag renderEntity.NoDynamicInteractions = args.GetBool("noDynamicInteractions"); // check noshadows flag renderEntity.NoShadow = args.GetBool("noshadows"); // check noselfshadows flag renderEntity.NoSelfShadow = args.GetBool("noselfshadows"); // init any guis, including entity-specific states int count = renderEntity.Gui.Length; for(int i = 0; i < count; i++) { temp = args.GetString(i == 0 ? "gui" : string.Format("gui{0}", i + 1)); if(temp != null) { renderEntity.Gui[i] = AddRenderGui(temp, args); } } return renderEntity; }