private idUserInterface AddRenderGui(string name, idDict args) { idUserInterface gui = idR.UIManager.FindInterface(name, true, args.ContainsKey("gui_parm")); UpdateGuiParams(gui, args); return(gui); }
private idUserInterface AddRenderGui(string name, idDict args) { idUserInterface gui = idR.UIManager.FindInterface(name, true, args.ContainsKey("gui_parm")); UpdateGuiParams(gui, args); return gui; }
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; }
public override bool Parse(string text) { if (this.Disposed == true) { throw new ObjectDisposedException(this.GetType().Name); } idLexer lexer = new idLexer(idDeclFile.LexerOptions); lexer.LoadMemory(text, this.FileName, this.LineNumber); lexer.SkipUntilString("{"); idToken token; idToken token2; string value; while (true) { if ((token = lexer.ReadToken()) == null) { break; } value = token.ToString(); if (value == "}") { break; } if (token.Type != TokenType.String) { lexer.Warning("Expected quoted string, but found '{0}'", value); MakeDefault(); return(false); } if ((token2 = lexer.ReadToken()) == null) { lexer.Warning("Unexpected end of file"); MakeDefault(); return(false); } if (_dict.ContainsKey(value) == true) { lexer.Warning("'{0}' already defined", value); } _dict.Set(value, token2.ToString()); } // we always automatically set a "classname" key to our name _dict.Set("classname", this.Name); // "inherit" keys will cause all values from another entityDef to be copied into this one // if they don't conflict. We can't have circular recursions, because each entityDef will // never be parsed more than once // find all of the dicts first, because copying inherited values will modify the dict List <idDeclEntity> defList = new List <idDeclEntity>(); List <string> keysToRemove = new List <string>(); foreach (KeyValuePair <string, string> kvp in _dict.MatchPrefix("inherit")) { idDeclEntity copy = idE.DeclManager.FindType <idDeclEntity>(DeclType.EntityDef, kvp.Value, false); if (copy == null) { lexer.Warning("Unknown entityDef '{0}' inherited by '{1}'", kvp.Value, this.Name); } else { defList.Add(copy); } // delete this key/value pair keysToRemove.Add(kvp.Key); } _dict.Remove(keysToRemove.ToArray()); // now copy over the inherited key / value pairs foreach (idDeclEntity def in defList) { _dict.SetDefaults(def._dict); } // precache all referenced media // do this as long as we arent in modview idE.Game.CacheDictionaryMedia(_dict); return(true); }
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; }