//================================================================== // // P_SpawnLightFlash // // After the map has been loaded, scan each sector for specials that spawn thinkers // //================================================================== public static void P_SpawnStrobeFlash(r_local.sector_t sector, int fastOrSlow, int inSync) { p_spec.strobe_t flash; flash = new p_spec.strobe_t(); p_tick.P_AddThinker(flash.thinker); flash.sector = sector; flash.darktime = fastOrSlow; flash.brighttime = p_spec.STROBEBRIGHT; flash.thinker.function = new T_StrobeFlash(flash); flash.maxlight = sector.lightlevel; flash.minlight = p_spec.P_FindMinSurroundingLight(sector, sector.lightlevel); if (flash.minlight == flash.maxlight) { flash.minlight = 0; } sector.special = 0; // nothing special about it during gameplay if (inSync == 0) { flash.count = (m_misc.P_Random() & 7) + 1; } else { flash.count = 1; } }
public static void GatherSectorsInRadius(Vector2 pos, r_local.sector_t sector, float radius, ref List <r_local.sector_t> out_sectors) { ++checkId; sector.checkId = checkId; out_sectors.Add(sector); GatherSectorsInRadiusIter(pos, sector, radius, ref out_sectors); }
public static void GatherSectorsInRadiusIter(Vector2 pos, r_local.sector_t sector, float radius, ref List <r_local.sector_t> out_sectors) { for (int i = 0; i < sector.linecount; ++i) { r_local.line_t li = p_setup.linebuffer[sector.linesi + i]; GatherSectorsInRadiusIterThroughLine(pos, sector, li, radius, ref out_sectors); } }
public static void XNARenderFlatToAmbientMap(r_local.sector_t sector) { if (sector.triangleList == null) { return; } if (sector.triangleList.Count == 0) { return; } GraphicsDevice device = Game1.instance.GraphicsDevice; if (verts.Count() < sector.triangleList.Count()) { verts = new VertexPositionColorTexture[sector.triangleList.Count]; } float floorH = sector.floorheight >> DoomDef.FRACBITS; float ceilH = sector.ceilingheight >> DoomDef.FRACBITS; for (int i = 0; i < sector.triangleList.Count; i += 3) { r_data.Vector2AndTags p1 = sector.triangleList[i + 0]; r_data.Vector2AndTags p2 = sector.triangleList[i + 1]; r_data.Vector2AndTags p3 = sector.triangleList[i + 2]; Vector3 v1 = new Vector3(p1.p, floorH); Vector3 v2 = new Vector3(p2.p, floorH); Vector3 v3 = new Vector3(p3.p, floorH); Vector2 floorCeil; floorCeil.X = ((sector.floorheight >> DoomDef.FRACBITS) + 1024.0f) / 2048.0f; floorCeil.Y = ((sector.ceilingheight >> DoomDef.FRACBITS) + 1024.0f) / 2048.0f; verts[i + 0] = new VertexPositionColorTexture( v1, new Color( 1.0f, 1, 1, 1), floorCeil); verts[i + 1] = new VertexPositionColorTexture( v2, new Color( 1.0f, 1, 1, 1), floorCeil); verts[i + 2] = new VertexPositionColorTexture( v3, new Color( 1.0f, 1, 1, 1), floorCeil); } device.DrawUserPrimitives <VertexPositionColorTexture>( PrimitiveType.TriangleList, verts, 0, sector.triangleList.Count / 3); }
public static void P_SpawnGlowingLight(r_local.sector_t sector) { p_spec.glow_t g; g = new p_spec.glow_t(); p_tick.P_AddThinker(g.thinker); g.sector = sector; g.minlight = p_spec.P_FindMinSurroundingLight(sector, sector.lightlevel); g.maxlight = sector.lightlevel; g.thinker.function = new T_Glow(g); g.direction = -1; sector.special = 0; }
internal void fillUIWithSector(r_local.sector_t selectedSector) { if (selectedSector == null) { return; } if (Game1.instance.flatSelfIllumById.ContainsKey(selectedSector.floorpic)) { sldSelfIllumination.Value = (int)(Game1.instance.flatSelfIllumById[selectedSector.floorpic] * 100.0f); } else { sldSelfIllumination.Value = 0; } if (useFloor) { if (Game1.instance.flatLightInfoById.ContainsKey(Game1.instance.selectedSector.floorpic)) { btnAddLight.Text = "Remove Light"; Game1.Floorlightinfo lightInfo = Game1.instance.flatLightInfoById[Game1.instance.selectedSector.floorpic]; sldDistance.Value = (int)lightInfo.distance; sldHue.Value = lightInfo.hue; sldSaturation.Value = lightInfo.saturation; sldBrightness.Value = (int)(lightInfo.brightness * 100.0f); sldSpread.Value = (int)(lightInfo.spread * 10.0f); } else { btnAddLight.Text = "Add Light"; } } else { if (Game1.instance.flatCLightInfoById.ContainsKey(Game1.instance.selectedSector.ceilingpic)) { btnAddLight.Text = "Remove Light"; Game1.Floorlightinfo lightInfo = Game1.instance.flatCLightInfoById[Game1.instance.selectedSector.ceilingpic]; sldDistance.Value = (int)lightInfo.distance; sldHue.Value = lightInfo.hue; sldSaturation.Value = lightInfo.saturation; sldBrightness.Value = (int)(lightInfo.brightness * 100.0f); sldSpread.Value = (int)(lightInfo.spread * 10.0f); } else { btnAddLight.Text = "Add Light"; } } }
private static void checkLines(r_local.sector_t sector, ref Vector4 in_prevScreenBB) { foreach (r_local.seg_t seg in sector.segs) { if (seg.culling_checkId == checkId) { continue; } if (seg.culling_alreadyFullyIncluded == checkId) { continue; } testLine(sector, seg, ref in_prevScreenBB); } }
//================================================================== // // P_SpawnLightFlash // // After the map has been loaded, scan each sector for specials that spawn thinkers // //================================================================== public static void P_SpawnLightFlash(r_local.sector_t sector) { p_spec.lightflash_t flash; sector.special = 0; // nothing special about it during gameplay flash = new p_spec.lightflash_t(); p_tick.P_AddThinker(flash.thinker); flash.thinker.function = new T_LightFlash(flash); flash.sector = sector; flash.maxlight = sector.lightlevel; flash.minlight = p_spec.P_FindMinSurroundingLight(sector, sector.lightlevel); flash.maxtime = 64; flash.mintime = 7; flash.count = (m_misc.P_Random() & flash.maxtime) + 1; }
private static void addSector(r_local.sector_t sector, ref Vector4 in_prevScreenBB) { if (sector.checkId == checkId) { return; } if (sector.addedId != checkId) { sectors[sectorCount++] = sector; } #if DEBUG ++sectorChecked; #endif sector.addedId = checkId; sector.checkId = checkId; checkLines(sector, ref in_prevScreenBB); sector.checkId = 0; }
private static void findVisibleSectors() { sectorCount = 0; // Find starting sector, the one we stand in r_local.sector_t startSector = r_main.R_PointInSubsector( (int)Game1.instance.camPos.X << DoomDef.FRACBITS, (int)Game1.instance.camPos.Y << DoomDef.FRACBITS).sector; /* r_local.sector_t startSector = r_main.R_PointInSubsector( * g_game.players[g_game.consoleplayer].mo.x, * g_game.players[g_game.consoleplayer].mo.y).sector;*/ projectMat = Game1.instance.view * Game1.instance.proj; ++checkId; #if DEBUG sectorChecked = 0; portalChecked = 0; portalTraversed = 0; DateTime t = DateTime.Now; #endif screenSize = new Vector2((float)Game1.instance.GraphicsDevice.Viewport.Width, (float)Game1.instance.GraphicsDevice.Viewport.Height); depth = new Vector3( Game1.instance.GraphicsDevice.Viewport.MinDepth, Game1.instance.GraphicsDevice.Viewport.MaxDepth, Game1.instance.GraphicsDevice.Viewport.MaxDepth - Game1.instance.GraphicsDevice.Viewport.MinDepth); Vector4 screenBB = new Vector4(0, 0, screenSize.X, screenSize.Y); debugRects.Clear(); #if CULLING_ENABLED addSector(startSector, ref screenBB); #else foreach (r_local.sector_t sector in p_setup.sectors) { sectors[sectorCount++] = sector; } #endif #if DEBUG cullingTime = (DateTime.Now - t).TotalMilliseconds; #endif }
/* * ================ * = * = R_Subsector * = * = Draw one or more segments * ================ */ public static void R_Subsector(int num) { int count; int line; r_local.subsector_t sub; r_main.sscount++; sub = p_setup.subsectors[num]; frontsector = sub.sector; count = sub.numlines; line = sub.firstline; if (frontsector.floorheight < r_main.viewz) { r_plane.floorplane = r_plane.R_FindPlane(frontsector.floorheight, frontsector.floorpic, frontsector.lightlevel, frontsector.special); } else { r_plane.floorplane = null; } if (frontsector.ceilingheight > r_main.viewz || frontsector.ceilingpic == r_plane.skyflatnum) { r_plane.ceilingplane = r_plane.R_FindPlane(frontsector.ceilingheight, frontsector.ceilingpic, frontsector.lightlevel, 0); } else { r_plane.ceilingplane = null; } r_thing.R_AddSprites(frontsector); while ((count--) != 0) { r_bsp.R_AddLine(p_setup.segs[line]); line++; } }
public static void GatherSectorsInRadiusIterThroughLine( Vector2 pos, r_local.sector_t sector, r_local.line_t li, float radius, ref List <r_local.sector_t> out_sectors) { r_local.sector_t newSector = null; Vector2 liNormal = Vector2.Zero; Vector2 v = new Vector2( li.v1.x >> DoomDef.FRACBITS, li.v1.y >> DoomDef.FRACBITS); Vector2 w = new Vector2( li.v2.x >> DoomDef.FRACBITS, li.v2.y >> DoomDef.FRACBITS); if (li.frontsector == sector) { if (li.backsector != null) { newSector = li.backsector; Vector2 dir = w - v; dir.Normalize(); liNormal.X = dir.Y; liNormal.Y = -dir.X; } } else if (li.backsector == sector) { newSector = li.frontsector; Vector2 dir = v - w; dir.Normalize(); liNormal.X = dir.Y; liNormal.Y = -dir.X; } if (newSector == null) { return; } if (newSector.checkId == checkId) { return; // Already checked } float dotWithNormal = Vector2.Dot( liNormal, v - pos); if (dotWithNormal > 0) { return; } // Is out line in the radius? float dis = minimum_distance(v, w, pos); if (dis > radius) { return; } newSector.checkId = checkId; out_sectors.Add(newSector); GatherSectorsInRadiusIter(pos, newSector, radius, ref out_sectors); }
public static void XNARenderFloorToBatch(r_local.sector_t sector, r_local.SectorBatch batch) { if (sector.triangleList == null) { return; } if (sector.triangleList.Count == 0) { return; } float floorH = sector.floorheight >> DoomDef.FRACBITS; { batch.textureId = sector.floorpic; int prevSource = r_data.flattranslationPrev[sector.floorpic]; int tempSource = r_data.flattranslation[sector.floorpic]; float uOffset = 0; float vOffset = 0; int textureId = 0; // tempSource; batch.isUVAnimated = false; switch (sector.special) { case 25: case 26: case 27: case 28: case 29: // Scroll_North textureId = tempSource; break; case 20: case 21: case 22: case 23: case 24: // Scroll_East uOffset = (float)((63 - ((p_tick.leveltime >> 1) & 63)) << (sector.special - 20) & 63) / 64.0f; textureId = tempSource; batch.isUVAnimated = true; break; case 30: case 31: case 32: case 33: case 34: // Scroll_South textureId = tempSource; break; case 35: case 36: case 37: case 38: case 39: // Scroll_West textureId = tempSource; break; case 4: // Scroll_EastLavaDamage uOffset = (float)(((63 - ((p_tick.leveltime >> 1) & 63)) << 3) & 63) / 64.0f; textureId = tempSource; batch.isUVAnimated = true; break; default: textureId = tempSource; break; } Texture2D texture = Game1.instance.floorTexturesById[textureId]; batch.texture = texture; for (int i = 0; i < sector.triangleList.Count; i += 3) { r_data.Vector2AndTags p1 = sector.triangleList[i + 0]; r_data.Vector2AndTags p2 = sector.triangleList[i + 1]; r_data.Vector2AndTags p3 = sector.triangleList[i + 2]; Vector3 v1 = new Vector3(p1.p, floorH); Vector3 v2 = new Vector3(p2.p, floorH); Vector3 v3 = new Vector3(p3.p, floorH); if (Settings.Default.use_deferred) { batch.vertsPNT.Add(new VertexPositionNormalTexture( v1, Vector3.UnitZ, new Vector2(v1.X / 64.0f + uOffset, -v1.Y / 64.0f + vOffset))); batch.vertsPNT.Add(new VertexPositionNormalTexture( v2, Vector3.UnitZ, new Vector2(v2.X / 64.0f + uOffset, -v2.Y / 64.0f + vOffset))); batch.vertsPNT.Add(new VertexPositionNormalTexture( v3, Vector3.UnitZ, new Vector2(v3.X / 64.0f + uOffset, -v3.Y / 64.0f + vOffset))); } else { batch.vertsPT.Add(new VertexPositionTexture( v1, new Vector2(v1.X / 64.0f + uOffset, -v1.Y / 64.0f + vOffset))); batch.vertsPT.Add(new VertexPositionTexture( v2, new Vector2(v2.X / 64.0f + uOffset, -v2.Y / 64.0f + vOffset))); batch.vertsPT.Add(new VertexPositionTexture( v3, new Vector2(v3.X / 64.0f + uOffset, -v3.Y / 64.0f + vOffset))); } } } }
public static void XNARenderFlat(r_local.sector_t sector) { /* if (sector.triangleList == null) return; * if (sector.triangleList.Count == 0) return; * GraphicsDevice device = Game1.instance.GraphicsDevice; * if (verts.Count() < sector.triangleList.Count()) * { * verts = new VertexPositionColorTexture[sector.triangleList.Count]; * } * float floorH = sector.floorheight >> DoomDef.FRACBITS; * float ceilH = sector.ceilingheight >> DoomDef.FRACBITS; * int light = (sector.lightlevel >> r_local.LIGHTSEGSHIFT) + r_main.extralight; * if (light >= r_local.LIGHTLEVELS) * light = r_local.LIGHTLEVELS - 1; * if (light < 0) * light = 0; * * // planezlight = r_main.zlight[light]; * float lightLevel = (float)(sector.lightlevel + r_main.extralight) / 255.0f; * Game1.instance.fxPlane.Parameters["lightLevel"].SetValue(lightLevel); * Vector2 floorCeil; * floorCeil.X = ((sector.floorheight >> DoomDef.FRACBITS) + 1024.0f) / 2048.0f; * floorCeil.Y = ((sector.ceilingheight >> DoomDef.FRACBITS) + 1024.0f) / 2048.0f; * Game1.instance.fxPlane.Parameters["floorCeil"].SetValue(floorCeil); * { * int prevSource = r_data.flattranslationPrev[sector.floorpic]; * int tempSource = r_data.flattranslation[sector.floorpic]; * float uOffset = 0; * float vOffset = 0; * int textureId = 0;// tempSource; * switch (sector.special) * { * case 25: * case 26: * case 27: * case 28: * case 29: // Scroll_North * textureId = tempSource; * break; * case 20: * case 21: * case 22: * case 23: * case 24: // Scroll_East * uOffset = (float)((63 - ((p_tick.leveltime >> 1) & 63)) << (sector.special - 20) & 63) / 64.0f; * textureId = tempSource; * break; * case 30: * case 31: * case 32: * case 33: * case 34: // Scroll_South * textureId = tempSource; * break; * case 35: * case 36: * case 37: * case 38: * case 39: // Scroll_West * textureId = tempSource; * break; * case 4: // Scroll_EastLavaDamage * uOffset = (float)(((63 - ((p_tick.leveltime >> 1) & 63)) << 3) & 63) / 64.0f; * textureId = tempSource; * break; * default: * textureId = tempSource; * break; * } * * Texture2D texture = Game1.instance.floorTexturesById[textureId]; * * if (prevSource != tempSource) * { * Texture2D prevTexture = Game1.instance.floorTexturesById[prevSource]; * EffectTechnique prevTechnique = Game1.instance.fxPlane.CurrentTechnique; * Game1.instance.fxPlane.CurrentTechnique = Game1.instance.fxPlane.Techniques[Game1.instance.techniqueName("TechniqueAnimatedFloor")]; * Game1.instance.fxPlane.Parameters["AnimatedTexture1"].SetValue(texture); * Game1.instance.fxPlane.Parameters["AnimatedTexture2"].SetValue(prevTexture); * float delta = r_data.flattranslationDeltas[sector.floorpic]; * Game1.instance.fxPlane.Parameters["AnimT"].SetValue(delta); * Game1.instance.fxPlane.CurrentTechnique.Passes[0].Apply(); * Game1.instance.fxPlane.CurrentTechnique = prevTechnique; * } * else * { * Game1.instance.fxPlane.Parameters["DiffuseTexture"].SetValue(texture); * Game1.instance.fxPlane.CurrentTechnique.Passes[0].Apply(); * } * for (int i = 0; i < sector.triangleList.Count; i += 3) * { * r_data.Vector2AndTags p1 = sector.triangleList[i + 0]; * r_data.Vector2AndTags p2 = sector.triangleList[i + 1]; * r_data.Vector2AndTags p3 = sector.triangleList[i + 2]; * Vector3 v1 = new Vector3(p1.p, floorH); * Vector3 v2 = new Vector3(p2.p, floorH); * Vector3 v3 = new Vector3(p3.p, floorH); * verts[i + 0] = new VertexPositionColorTexture( * v1, * new Color( * 0.0f, * 1, * 1, 1), * new Vector2(v1.X / 64.0f + uOffset, -v1.Y / 64.0f + vOffset)); * verts[i + 1] = new VertexPositionColorTexture( * v2, * new Color( * 0.0f, * 1, * 1, 1), * new Vector2(v2.X / 64.0f + uOffset, -v2.Y / 64.0f + vOffset)); * verts[i + 2] = new VertexPositionColorTexture( * v3, * new Color( * 0.0f, * 1, * 1, 1), * new Vector2(v3.X / 64.0f + uOffset, -v3.Y / 64.0f + vOffset)); * } * device.DrawUserPrimitives<VertexPositionColorTexture>( * PrimitiveType.TriangleList, verts, 0, sector.triangleList.Count / 3); * } * { * Texture2D texture = null; * if (skyflatnum == sector.ceilingpic) * { * //texture = Game1.instance.wallTextures[r_plane.skytexture]; * texture = Game1.instance.wallTexturesById[r_plane.skytexture]; * Game1.instance.fxSky.Parameters["DiffuseTexture"].SetValue(texture); * Game1.instance.fxSky.CurrentTechnique.Passes[0].Apply(); * } * else * { * texture = Game1.instance.floorTexturesById[sector.ceilingpic]; * Game1.instance.fxPlane.Parameters["DiffuseTexture"].SetValue(texture); * Game1.instance.fxPlane.CurrentTechnique.Passes[0].Apply(); * } * for (int i = 0; i < sector.triangleList.Count; i += 3) * { * r_data.Vector2AndTags p1 = sector.triangleList[i + 0]; * r_data.Vector2AndTags p2 = sector.triangleList[i + 1]; * r_data.Vector2AndTags p3 = sector.triangleList[i + 2]; * int t1 = p1.groupTag; * int t2 = p2.groupTag; * int t3 = p3.groupTag; * Vector3 v1 = new Vector3( * p1.p.X, * p1.p.Y, * ceilH); * Vector3 v2 = new Vector3( * p2.p.X, * p2.p.Y, * ceilH); * Vector3 v3 = new Vector3( * p3.p.X, * p3.p.Y, * ceilH); * verts[i + 0] = new VertexPositionColorTexture( * v1, * new Color(1.0f, 1, 1, 1), * new Vector2(v1.X / (float)texture.Width, -v1.Y / (float)texture.Height)); * verts[i + 2] = new VertexPositionColorTexture( * v2, * new Color(1.0f, 1, 1, 1), * new Vector2(v2.X / (float)texture.Width, -v2.Y / (float)texture.Height)); * verts[i + 1] = new VertexPositionColorTexture( * v3, * new Color(1.0f, 1, 1, 1), * new Vector2(v3.X / (float)texture.Width, -v3.Y / (float)texture.Height)); * } * device.DrawUserPrimitives<VertexPositionColorTexture>( * PrimitiveType.TriangleList, verts, 0, sector.triangleList.Count / 3); * }*/ }
//================================================================== //================================================================== // // FLOORS // //================================================================== //================================================================== //================================================================== // // Move a plane (floor or ceiling) and check for crushing // //================================================================== public static p_spec.result_e T_MovePlane(r_local.sector_t sector, int speed, int dest, bool crush, int floorOrCeiling, int direction) { bool flag; int lastpos; switch (floorOrCeiling) { case 0: // FLOOR switch (direction) { case -1: // DOWN if (sector.floorheight - speed < dest) { lastpos = sector.floorheight; sector.floorheight = dest; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { sector.floorheight = lastpos; p_map.P_ChangeSector(sector, crush); //return crushed; } return(p_spec.result_e.pastdest); } else { lastpos = sector.floorheight; sector.floorheight -= speed; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { sector.floorheight = lastpos; p_map.P_ChangeSector(sector, crush); return(p_spec.result_e.crushed); } } break; case 1: // UP if (sector.floorheight + speed > dest) { lastpos = sector.floorheight; sector.floorheight = dest; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { sector.floorheight = lastpos; p_map.P_ChangeSector(sector, crush); //return crushed; } return(p_spec.result_e.pastdest); } else // COULD GET CRUSHED { lastpos = sector.floorheight; sector.floorheight += speed; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { if (crush == true) { return(p_spec.result_e.crushed); } sector.floorheight = lastpos; p_map.P_ChangeSector(sector, crush); return(p_spec.result_e.crushed); } } break; } break; case 1: // CEILING switch (direction) { case -1: // DOWN if (sector.ceilingheight - speed < dest) { lastpos = sector.ceilingheight; sector.ceilingheight = dest; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { sector.ceilingheight = lastpos; p_map.P_ChangeSector(sector, crush); //return crushed; } return(p_spec.result_e.pastdest); } else // COULD GET CRUSHED { lastpos = sector.ceilingheight; sector.ceilingheight -= speed; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { if (crush == true) { return(p_spec.result_e.crushed); } sector.ceilingheight = lastpos; p_map.P_ChangeSector(sector, crush); return(p_spec.result_e.crushed); } } break; case 1: // UP if (sector.ceilingheight + speed > dest) { lastpos = sector.ceilingheight; sector.ceilingheight = dest; flag = p_map.P_ChangeSector(sector, crush); if (flag == true) { sector.ceilingheight = lastpos; p_map.P_ChangeSector(sector, crush); //return crushed; } return(p_spec.result_e.pastdest); } else { lastpos = sector.ceilingheight; sector.ceilingheight += speed; flag = p_map.P_ChangeSector(sector, crush); } break; } break; } return(p_spec.result_e.ok); }
internal void fillUIWithSector(r_local.sector_t sector) { m_sector = sector; { Microsoft.Xna.Framework.Graphics.Texture2D texture = Game1.instance.floorTexturesById[r_data.texturetranslation[sector.floorpic]]; byte[] pixels = new byte[texture.Width * texture.Height * 4]; texture.GetData <byte>(pixels); for (int i = 0; i < texture.Width * texture.Height; ++i) { byte tmp = pixels[i * 4 + 0]; pixels[i * 4 + 0] = pixels[i * 4 + 2]; pixels[i * 4 + 2] = tmp; } Bitmap bmp = new Bitmap(texture.Width, texture.Height, texture.Width * 4, PixelFormat.Format32bppArgb, GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject()); picFloor.Image = bmp; } { Microsoft.Xna.Framework.Graphics.Texture2D texture = sector.ceilingBatch.texture; byte[] pixels = new byte[texture.Width * texture.Height * 4]; texture.GetData <byte>(pixels); for (int i = 0; i < texture.Width * texture.Height; ++i) { byte tmp = pixels[i * 4 + 0]; pixels[i * 4 + 0] = pixels[i * 4 + 2]; pixels[i * 4 + 2] = tmp; } Bitmap bmp = new Bitmap(texture.Width, texture.Height, texture.Width * 4, PixelFormat.Format32bppArgb, GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject()); picCeil.Image = bmp; } { Bitmap bmp = new Bitmap(picSector.Width, picSector.Height, PixelFormat.Format24bppRgb); Pen yellowPen = new Pen(Color.Yellow, 2); float bbminX = 100000; float bbminY = 100000; float bbmaxX = -100000; float bbmaxY = -100000; sector.floorBatch.boundingBox(ref bbminX, ref bbminY, ref bbmaxX, ref bbmaxY); float biggest = Math.Max(bbmaxX - bbminX, bbmaxY - bbminY); int padding = 4; float scale = (float)(picSector.Width - padding * 2) / biggest; bbminX -= (biggest - (bbmaxX - bbminX)) * .5f; bbminY -= (biggest - (bbmaxY - bbminY)) * .5f; // Draw lines to screen Graphics graphics = Graphics.FromImage(bmp); foreach (r_local.seg_t seg in p_setup.segs) { if (seg.frontsector == sector) { Microsoft.Xna.Framework.Vector2 vp1 = new Microsoft.Xna.Framework.Vector2( seg.v1.x >> DoomDef.FRACBITS, -seg.v1.y >> DoomDef.FRACBITS); Microsoft.Xna.Framework.Vector2 vp2 = new Microsoft.Xna.Framework.Vector2( seg.v2.x >> DoomDef.FRACBITS, -seg.v2.y >> DoomDef.FRACBITS); vp1.X -= bbminX; vp2.X -= bbminX; vp1.Y -= bbminY; vp2.Y -= bbminY; vp1 *= scale; vp2 *= scale; graphics.DrawLine(yellowPen, (int)vp1.X + padding, (int)vp1.Y + padding, (int)vp2.X + padding, (int)vp2.Y + padding); } } picSector.Image = bmp; } }
/* * ================= * = * = P_LoadSectors * = * ================= */ public static void P_LoadSectors(int lump) { w_wad.CacheInfo data; int i; DoomData.mapsector_t ms; r_local.sector_t ss; numsectors = w_wad.W_LumpLength(lump) / 26; if (sectors != null) { foreach (r_local.sector_t sector in sectors) { sector.Dispose(); } } sectors = new r_local.sector_t[numsectors]; data = w_wad.W_CacheLumpNum(lump, DoomDef.PU_STATIC); byte[] bytes; BinaryReader br = new BinaryReader(new MemoryStream(data.data)); for (i = 0; i < numsectors; i++) { ms = new DoomData.mapsector_t(); ms.floorheight = br.ReadInt16(); ms.ceilingheight = br.ReadInt16(); bytes = br.ReadBytes(8); foreach (byte b in bytes) { char c = (char)b; if (c == '\0') { continue; } ms.floorpic += c; } bytes = br.ReadBytes(8); foreach (byte b in bytes) { char c = (char)b; if (c == '\0') { continue; } ms.ceilingpic += c; } ms.lightlevel = br.ReadInt16(); ms.special = br.ReadInt16(); ms.tag = br.ReadInt16(); ss = new r_local.sector_t(); ss.floorheight = ms.floorheight << DoomDef.FRACBITS; ss.ceilingheight = ms.ceilingheight << DoomDef.FRACBITS; ss.floorpic = (short)r_data.R_FlatNumForName(ms.floorpic); ss.ceilingpic = (short)r_data.R_FlatNumForName(ms.ceilingpic); ss.lightlevel = ms.lightlevel; ss.special = ms.special; ss.tag = ms.tag; ss.thinglist = null; sectors[i] = ss; } }
private static void testLine(r_local.sector_t sector, r_local.seg_t li, ref Vector4 in_prevScreenBB) { #if DEBUG ++portalChecked; #endif r_local.sector_t nextSector; if (li.frontsector == sector) { if (li.backsector == null) { return; } nextSector = li.backsector; } else { return; } Vector3 v1, v2, screenSpace; v1.X = li.v1.x >> DoomDef.FRACBITS; v1.Y = li.v1.y >> DoomDef.FRACBITS; v2.X = li.v2.x >> DoomDef.FRACBITS; v2.Y = li.v2.y >> DoomDef.FRACBITS; v1.Z = Math.Max(li.frontsector.floorheight >> DoomDef.FRACBITS, li.backsector.floorheight >> DoomDef.FRACBITS); v2.Z = Math.Min(li.frontsector.ceilingheight >> DoomDef.FRACBITS, li.backsector.ceilingheight >> DoomDef.FRACBITS); if (v1.Z >= v2.Z) { return; } // if (frustum.Contains(liBB) == ContainmentType.Disjoint) return; Vector4 screenBB; Vector2 originalBB; screenBB.X = screenSize.X + 10000; screenBB.Y = screenSize.Y + 10000; screenBB.Z = -10000; screenBB.W = -10000; bool allBehind = true; screenSpace = v1; Project(ref screenSpace); screenBB.X = screenSpace.X < screenBB.X ? screenSpace.X : screenBB.X; screenBB.W = screenSpace.Y > screenBB.W ? screenSpace.Y : screenBB.W; if (screenSpace.Z < camLimit) { allBehind = false; } screenSpace = v1; screenSpace.Z = v2.Z; Project(ref screenSpace); screenBB.X = screenSpace.X < screenBB.X ? screenSpace.X : screenBB.X; screenBB.Y = screenSpace.Y < screenBB.Y ? screenSpace.Y : screenBB.Y; if (screenSpace.Z < camLimit) { allBehind = false; } screenSpace = v2; screenSpace.Z = v1.Z; Project(ref screenSpace); screenBB.Z = screenSpace.X > screenBB.Z ? screenSpace.X : screenBB.Z; screenBB.W = screenSpace.Y > screenBB.W ? screenSpace.Y : screenBB.W; if (screenSpace.Z < camLimit) { allBehind = false; } screenSpace = v2; screenSpace.Z = v2.Z; Project(ref screenSpace); screenBB.Y = screenSpace.Y < screenBB.Y ? screenSpace.Y : screenBB.Y; screenBB.Z = screenSpace.X > screenBB.Z ? screenSpace.X : screenBB.Z; if (screenBB.X >= screenBB.Z) { return; } if (screenBB.Y >= screenBB.W) { return; } if (screenSpace.Z < camLimit) { allBehind = false; } if (allBehind) { return; } if (screenBB.X < 0) { screenBB.X = 0; } if (screenBB.Y < 0) { screenBB.Y = 0; } if (screenBB.Z > screenSize.X) { screenBB.Z = screenSize.X; } if (screenBB.W > screenSize.Y) { screenBB.W = screenSize.Y; } originalBB.X = screenBB.X; originalBB.Y = screenBB.Z; // Merge with previous bounding screenBB.X = screenBB.X > in_prevScreenBB.X ? screenBB.X : in_prevScreenBB.X; screenBB.Y = screenBB.Y > in_prevScreenBB.Y ? screenBB.Y : in_prevScreenBB.Y; screenBB.Z = screenBB.Z < in_prevScreenBB.Z ? screenBB.Z : in_prevScreenBB.Z; screenBB.W = screenBB.W < in_prevScreenBB.W ? screenBB.W : in_prevScreenBB.W; if (screenBB.X >= screenBB.Z) { return; } if (screenBB.Y >= screenBB.W) { return; } if (screenBB.Z < 0 || screenBB.X > screenSize.X) { return; } if (screenBB.W < 0 || screenBB.Y > screenSize.Y) { return; } if (originalBB.X == screenBB.X && originalBB.Y == screenBB.Z) { li.culling_alreadyFullyIncluded = checkId; } debugRects.Add(screenBB); #if DEBUG ++portalTraversed; #endif li.culling_checkId = checkId; addSector(nextSector, ref screenBB); li.culling_checkId = 0; }
public static void XNARenderCeilToBatch(r_local.sector_t sector, r_local.SectorBatch batch) { if (sector.triangleList == null) { return; } if (sector.triangleList.Count == 0) { return; } float ceilH = sector.ceilingheight >> DoomDef.FRACBITS; { if (skyflatnum == sector.ceilingpic) { batch.isSky = true; //batch.texture = Game1.instance.wallTextures[r_plane.skytexture]; batch.texture = Game1.instance.wallTexturesById[r_plane.skytexture]; } else { batch.isSky = false; batch.texture = Game1.instance.floorTexturesById[sector.ceilingpic]; } batch.textureId = sector.ceilingpic; for (int i = 0; i < sector.triangleList.Count; i += 3) { r_data.Vector2AndTags p1 = sector.triangleList[i + 0]; r_data.Vector2AndTags p2 = sector.triangleList[i + 1]; r_data.Vector2AndTags p3 = sector.triangleList[i + 2]; int t1 = p1.groupTag; int t2 = p2.groupTag; int t3 = p3.groupTag; Vector3 v1 = new Vector3( p1.p.X, p1.p.Y, ceilH); Vector3 v2 = new Vector3( p2.p.X, p2.p.Y, ceilH); Vector3 v3 = new Vector3( p3.p.X, p3.p.Y, ceilH); if (Settings.Default.use_deferred) { batch.vertsPNT.Add(new VertexPositionNormalTexture( v2, -Vector3.UnitZ, new Vector2(v2.X / (float)batch.texture.Width, -v2.Y / (float)batch.texture.Height))); batch.vertsPNT.Add(new VertexPositionNormalTexture( v1, -Vector3.UnitZ, new Vector2(v1.X / (float)batch.texture.Width, -v1.Y / (float)batch.texture.Height))); batch.vertsPNT.Add(new VertexPositionNormalTexture( v3, -Vector3.UnitZ, new Vector2(v3.X / (float)batch.texture.Width, -v3.Y / (float)batch.texture.Height))); } else { batch.vertsPT.Add(new VertexPositionTexture( v2, new Vector2(v2.X / (float)batch.texture.Width, -v2.Y / (float)batch.texture.Height))); batch.vertsPT.Add(new VertexPositionTexture( v1, new Vector2(v1.X / (float)batch.texture.Width, -v1.Y / (float)batch.texture.Height))); batch.vertsPT.Add(new VertexPositionTexture( v3, new Vector2(v3.X / (float)batch.texture.Width, -v3.Y / (float)batch.texture.Height))); } } } }