private static KeyframeRope InitKeyframeRope(KeyframeRope ent, ValveBsp.Entities.Entity value, MapParams mapParams) { var min = (SourceUtils.Vector3)value["origin"]; var max = min; ent.NextKey = value["NextKey"]; if (!string.IsNullOrEmpty(ent.NextKey)) { var next = mapParams.Bsp.Entities.FirstOrDefault(x => ent.NextKey.Equals(x["targetname"])); if (next != null) { var nextOrigin = (SourceUtils.Vector3)next["origin"]; min = SourceUtils.Vector3.Min(min, nextOrigin); max = SourceUtils.Vector3.Max(max, nextOrigin); } } var clusters = GetIntersectingClusters(mapParams.Tree, min, max); if (InitPvsEntity(ent, value, clusters) == null) { return(null); } ent.Width = value["Width"]; ent.TextureScale = value["TextureScale"]; ent.SubDivisions = value["Subdiv"]; ent.Slack = value["Slack"]; ent.RopeMaterial = MaterialDictionary.GetResourceIndex(mapParams.Bsp, value["RopeMaterial"]); ent.MoveSpeed = value["MoveSpeed"]; return(ent); }
private static BrushEntity InitBrushEntity(BrushEntity ent, ValveBsp.Entities.Entity value, MapParams mapParams) { if (value.TargetName != null && mapParams.AreaPortalNames.Contains(value.TargetName)) { return(null); } var modelName = ent is Worldspawn ? "*0" : value["model"]; if (modelName == null) { return(null); } var modelIndex = int.Parse(modelName.Substring(1)); var model = mapParams.Bsp.Models[modelIndex]; var min = model.Min + value.Origin; var max = model.Max + value.Origin; var clusters = modelIndex == 0 ? null : GetIntersectingClusters(mapParams.Tree, min, max); if (InitPvsEntity(ent, value, clusters) == null) { return(null); } ent.Model = modelIndex; return(ent); }
private Entity InitEntity(ValveBsp.Entities.Entity value, MapParams mapParams) { var classname = (string)value["classname"]; EntityCtor ctor; if (_sEntityCtors.TryGetValue(classname, out ctor)) { return(ctor == null ? null : ctor(value, mapParams)); } MethodInfo matchingMethod = null; foreach (var method in typeof(IndexController).GetMethods(BindingFlags.Static | BindingFlags.NonPublic)) { var attrib = method.GetCustomAttribute <ClassnameAttribute>(); if (attrib == null) { continue; } if (attrib.Default && matchingMethod == null || attrib.Names.Contains(classname)) { matchingMethod = method; if (!attrib.Default) { break; } } } if (matchingMethod == null) { _sEntityCtors.Add(classname, null); return(null); } var parameters = matchingMethod.GetParameters(); var entType = parameters[0].ParameterType; var hasParams = parameters.Length == 3; var valueParam = Expression.Parameter(typeof(ValveBsp.Entities.Entity), "value"); var mapParamsParam = Expression.Parameter(typeof(MapParams), "mapParams"); var ctorCall = Expression.New(entType.GetConstructor(Type.EmptyTypes)); var methodCall = hasParams ? Expression.Call(matchingMethod, ctorCall, valueParam, mapParamsParam) : Expression.Call(matchingMethod, ctorCall, valueParam); var deleg = Expression.Lambda <EntityCtor>(methodCall, valueParam, mapParamsParam).Compile(); _sEntityCtors.Add(classname, deleg); return(deleg(value, mapParams)); }
private static MoveRope InitMoveRope(MoveRope ent, ValveBsp.Entities.Entity value, MapParams mapParams) { if (InitKeyframeRope(ent, value, mapParams) == null) { return(null); } ent.PositionInterpolator = value["PositionInterpolator"]; return(ent); }
private static SkyCamera InitSkyCamera(SkyCamera ent, ValveBsp.Entities.Entity value) { if (InitEnvFogController(ent, value) == null) { return(null); } ent.Scale = value["scale"]; return(ent); }
private static Worldspawn InitWorldspawn(Worldspawn ent, ValveBsp.Entities.Entity value, MapParams mapParams) { if (InitBrushEntity(ent, value, mapParams) == null) { return(null); } ent.SkyMaterial = Material.CreateSkyMaterial(mapParams.Bsp, value["skyname"]); return(ent); }
private static PvsEntity InitPvsEntity(PvsEntity ent, ValveBsp.Entities.Entity value, IEnumerable <int> clusters) { if (InitEntity(ent, value) == null) { return(null); } ent.Clusters = clusters; return(ent); }
private static EnvFogController InitEnvFogController(EnvFogController ent, ValveBsp.Entities.Entity value) { if (InitEntity(ent, value) == null) { return(null); } ent.FogEnabled = value["fogenable"]; ent.FogStart = value["fogstart"]; ent.FogEnd = value["fogend"]; ent.FogMaxDensity = value["fogmaxdensity"]; ent.FarZ = value["farz"]; ent.FogColor = new MaterialColor(value["fogcolor"]); return(ent); }
private static LightEnvironment InitLightEnvironment(LightEnvironment ent, ValveBsp.Entities.Entity value) { if (InitEntity(ent, value) == null) { return(null); } ent.Brightness = value["_light"]; ent.BrightnessHdr = value["_lightHDR"]; ent.BrightnessScaleHdr = value["_lightscaleHDR"]; ent.Ambient = value["_ambient"]; ent.AmbientHdr = value["_ambientHDR"]; ent.AmbientScaleHdr = value["_AmbientScaleHDR"]; ent.Pitch = value["pitch"]; return(ent); }
private static Entity InitEntity(Entity ent, ValveBsp.Entities.Entity value) { if (value["rendermode"] == 10) { return(null); } ent.ClassName = value["classname"]; if ((string)value["origin"] != null) { ent.Origin = (SourceUtils.Vector3)value["origin"]; } if ((string)value["angles"] != null) { ent.Angles = (SourceUtils.Vector3)value["angles"]; } if ((string)value["targetname"] != null) { ent.TargetName = value["targetname"]; } return(ent); }