public SkyBox(SourceMap map, string texturename, Entity light_environment) { Init(texturename); Color4 skyColor = new Color4(2f, 255f, 255f, 255f); if (light_environment != null) { // This makes the skybox blend in better with the rest of the world string lightval = light_environment.Values["_light"]; string[] vals = lightval.Split(' '); if (vals.Length == 4) { // Try to get sun light color float r, g, b; r = int.Parse(vals[0]); g = int.Parse(vals[1]); b = int.Parse(vals[2]); float brightness = int.Parse(vals[3]); skyColor = new Color4(brightness, r, g, b); } } // Create a tiny lightmap, and take white+ maxExponent from the map as a color // Grab brightness of environment light and convert to exponent offset tex2 = TextureManager.CreateTexture(1,1,Format.A16B16G16R16F, skyColor); SharedTexture2 = true; }
public SkyBox3D(SourceMap map, Entity sky_camera) { this.sky_camera = sky_camera; this.map = map; // Get origin of 3d skybox string origin = sky_camera.Values["origin"]; origin = origin.Replace('.', ','); // Needed for proper C# float parsing string[] origin_values = origin.Split(' ', '\t'); if (origin_values.Length == 3) { Vector3 position = Vector3.Zero; position.X = float.Parse(origin_values[0], System.Globalization.CultureInfo.InvariantCulture); position.Y = float.Parse(origin_values[1], System.Globalization.CultureInfo.InvariantCulture); position.Z = float.Parse(origin_values[2], System.Globalization.CultureInfo.InvariantCulture); startPosition = SourceParser.SwapZY(position); } // Get scale of 3d skybox if (sky_camera.Values.ContainsKey("scale")) { float result; if (float.TryParse(sky_camera.Values["scale"], out result)) { Scale = result; } } }
public static void LoadWorldMap(string filename) { FileStream stream; // Check filecache if (FileCache.Instance.Contains(filename)) { stream = File.OpenRead(FileCache.Instance.GetFile(filename).FullName); } // Check absolute path else if (File.Exists(filename)) { stream = File.OpenRead(filename); } else { Common.Instance.Error(string.Format("LoadWorldMap: {0} not found", filename)); return; } world = new World(); BinaryReader br = new BinaryReader(stream, Encoding.UTF8); // Read header.. int magic = (('P' << 24) + ('S' << 16) + ('B' << 8) + 'V'); int id = br.ReadInt32(); if (id != magic) { Common.Instance.Error(string.Format("LoadWorldMap:{0}: Wrong magic number", filename)); return; } Header sHeader = new Header(); sHeader.ident = id; sHeader.version = br.ReadInt32(); // GoldSrc map if (sHeader.version == 30) { GoldSrcParser.LoadWorldMap(sHeader, br); return; } sHeader.lumps = new Lump_t[Header.HEADER_LUMPS]; for (int i = 0; i < Header.HEADER_LUMPS; i++) { Lump_t lump; lump.fileofs = br.ReadInt32(); lump.filelen = br.ReadInt32(); lump.version = br.ReadInt32(); lump.fourCC = br.ReadChars(4); sHeader.lumps[i] = lump; } sHeader.mapRevision = br.ReadInt32(); LoadWorldLights(br, sHeader); LoadLightGrids(br, sHeader); LoadLightmaps(br, sHeader); LoadPak(br, sHeader); LoadTextures(br, sHeader); LoadPlanes(br, sHeader); LoadDisplacement(br, sHeader); LoadFaces(br, sHeader); // Req: planes & texinfos & light & displacemtn LoadLeafBrushes(br, sHeader); LoadBrushes(br, sHeader); LoadLeafFaces(br, sHeader); LoadNodesAndLeafs(br, sHeader); // Req: planes LoadGameAndProps(br, sHeader); // Req: leafs LoadModels(br, sHeader); LoadEntities(br, sHeader); LoadVisibility(br, sHeader); DispTreeLeafnum(world); SourceMap map = new SourceMap(world); map.Init(); Renderer.Instance.SourceMap = map; long now = HighResolutionTimer.Ticks; for (int i = 0; i < world.sourceProps.Count; i++) { world.sourceProps[i].UpdateMesh(); } float propLightingTime = (float)(HighResolutionTimer.Ticks - now) / HighResolutionTimer.Frequency; Common.Instance.WriteLine("Finished prop lighting: {0:0.000}s", propLightingTime); }