gzdoom-last-svn/src/gl/gl_missinglines.cpp
Christoph Oelckers cac80858f4 Update to ZDoom r1146 (warning: massive changes ahead!)
- Removed DECORATE's ParseClass because it was only used to add data to fully
  internal actor classes which no longer exist.
- Changed the state structure so that the Tics value doesn't need to be hacked
  into misc1 with SF_BIGTIC anymore. 
- Changed sprite processing so that sprite names are converted to indices 
  during parsing so that an additional postprocessing step is no longer needed.
- Fixed: Sprite names in DECORATE were case sensitive.
- Exported AActor's defaults to DECORATE and removed all code for the 
  internal property parser which is no longer needed.
- Converted the Heresiarch to DECORATE.
- Added an Active and Inactive state for monsters.
- Made the speed a parameter to A_RaiseMobj and A_SinkMobj and deleted
  GetRaiseSpeed and GetSinkSpeed.
- Added some remaining DECORATE conversions for Hexen by Karate Chris.
- Changed Windows to use the performance counter instead of rdtsc.
- Changed Linux to use clock_gettime for profiling instead of rdtsc. This
  avoids potential erroneous results on multicore and variable speed
  processors.
- Converted the last of Hexen's inventory items to DECORATE so that I could
  export AInventory.
- Removed AT_GAME_SET because it's no longer used anywhere.
- Converted the last remaining global classes to DECORATE.
- Fixed: Inventory.PickupFlash requires an class name as parameter not an
  integer. Some Hexen definitions got it wrong.
- Converted Hexen's Pig to DECORATE.
- Replaced the ActorInfo definitions of all internal inventory classes with 
  DECORATE definitions.
- Added option to specify a powerup's duration in second by using a negative
  number.
- Added Gez's Freedoom detection patch.
- SBARINFO update:
  * Added: The ability to have drawkeybar auto detect spacing.
  * Added: Offset parameter to drawkeybar to allow two key bars with
    different keys.
  * Added: Multi-row/column keybar parameters.  Spacing can also be auto.
    These  defualt to left to right/top to bottom but can be switched.
  * Added: Drawshadow flag to drawnumber.  This will draw a solid color and
    translucent number under the normal number.
  * Added: hexenarmor to drawimage.  This takes a parameter for a hexen
    armor type and will fade the image like the hexen status bar.
  * Added: centerbottom offset to draw(switchable)image.
  * Added: translucent flag to drawinventorybar.
  * Fixed: Accidentally removed flag from DrawTexture that allowed negative
    coordinates to work with fullscreenoffsets.  Hopefully this is the last
    major bug in the fullscreenoffsets system.
- Ported vlinetallasm4 to AMD64 assembly. Even with the increased number of
  registers AMD64 provides, this routine still needs to be written as self-
  modifying code for maximum performance. The additional registers do allow
  for further optimization over the x86 version by allowing all four pixels
  to be in flight at the same time. The end result is that AMD64 ASM is about
  2.18 times faster than AMD64 C and about 1.06 times faster than x86 ASM.
  (For further comparison, AMD64 C and x86 C are practically the same for
  this function.) Should I port any more assembly to AMD64, mvlineasm4 is the
  most likely candidate, but it's not used enough at this point to bother.
  Also, this may or may not work with Linux at the moment, since it doesn't
  have the eh_handler metadata. Win64 is easier, since I just need to
  structure the function prologue and epilogue properly and use some
  assembler directives/macros to automatically generate the metadata. And
  that brings up another point: You need YASM to assemble the AMD64 code,
  because NASM doesn't support the Win64 metadata directives.
- Replaced the ActorInfo definitions of several internal classes with DECORATE definitions
- Converted teleport fog and destinations to DECORATE.
- AActor::PreExplode is gone now that the last item that was using it has been converted.
- Converted the Sigil and the remaining things in a_strifeitems.cpp to DECORATE.
- Exported Point pushers, CustomSprite and AmbientSound to DECORATE.
- Changed increased lightning damage for Centaurs into a damage factor.
- Changed PoisonCloud and Lightning special treatment in P_DamageMobj to use damage
  types instead to keep dependencies on specific actor types out of the main engine code.
- Added Korax DECORATE conversion by Gez and a few others by Karate Chris.
- Removed FourthWeaponClass and based Hexen's fourth weapons on the generic weapon
  pieces.
- Added DECORATE conversions for Hexen's Fighter weapons by Karate Chris.
- Added aWeaponGiver class to generalize the standing AssaultGun.
- converted a_Strifeweapons.cpp to DECORATE, except for the Sigil.
- Added an SSE version of DoBlending. This is strictly C intrinsics.
  VC++ still throws around unneccessary register moves. GCC seems to be
  pretty close to optimal, requiring only about 2 cycles/color. They're
  both faster than my hand-written MMX routine, so I don't need to feel
  bad about not hand-optimizing this for x64 builds.
- Removed an extra instruction from DoBlending_MMX, transposed two
  instructions, and unrolled it once, shaving off about 80 cycles from the
  time required to blend 256 palette entries. Why? Because I tried writing
  a C version of the routine using compiler intrinsics and was appalled by
  all the extra movq's VC++ added to the code. GCC was better, but still
  generated extra instructions. I only wanted a C version because I can't
  use inline assembly with VC++'s x64 compiler, and x64 assembly is a bit
  of a pain. (It's a pain because Linux and Windows have different calling
  conventions, and you need to maintain extra metadata for functions.) So,
  the assembly version stays and the C version stays out.
- Converted the rest of a_strifestuff.cpp to DECORATE.
- Fixed: AStalker::CheckMeleeRange did not perform all checks of AActor::CheckMeleeRange.
  I replaced this virtual override with a new flag MF5_NOVERTICALMELEERANGE so that
  this feature can also be used by other actors.
- Converted Strife's Stalker to DECORATE.
- Converted ArtiTeleport to DECORATE.
- Removed the NoBlockingSet method from AActor because everything using it has been
  converted to DECORATE using DropItem instead.
- Changed: Macil doesn't need the StrifeHumanoid's special death states so he might
  as well inherit directly from AActor.
- Converted Strife's Coin, Oracle, Macil and StrifeHumanoid to DECORATE. Also moved
  the burning hand states to StrifePlayer where they really belong.
- Added Gez's dropammofactor submission with some necessary changes. Also merged
  redundant ammo multiplication code from P_DropItem and ADehackedPickup::TryPickup.
- Restricted native action function definitions to zdoom.pk3.
- Fixed. The Firedemon was missing a game filter.
- Added: disablegrin, disableouch, disablepain, and disablerampage flags to
  drawmugshot.
- Fixed: LowerHealthCap did not work properly.
- Fixed: Various bugs I noticed in the fullscreenoffsets code.
- Removed all the pixel doubling r_detail modes, since the one platform they
  were intended to assist (486) actually sees very little benefit from them.
- Rewrote CheckMMX in C and renamed it to CheckCPU.
- Fixed: CPUID function 0x80000005 is specified to return detailed L1 cache
  only for AMD processors, so we must not use it on other architectures, or
  we end up overwriting the L1 cache line size with 0 or some other number
  we don't actually understand.
- The x87 precision control is now explicitly set for double precision, since
  GCC defaults to extended precision instead, unlike Visual C++.
- Converted Strife's Programmer, Loremaster and Thingstoblowup to DECORATE.
- Fixed: Attacking a merchant in Strife didn't alert the enemies.
- Removed AT_GAME_SET(PowerInvulnerable) due to the problems it caused. The two
  occurences in the code that depended on it were changed accordingly.
  Invulnerability colormaps are now being set by the items exclusively.
- Changed many checks for the friendly Minotaur to a new flag MF5_SUMMONEDMONSTER
  so that it can hopefully be generalized to be usable elsewhere later.
- Added Gez's submission for converting the Minotaur to DECORATE.
- Fixed a few minor DECORATE bugs.
- Changed coordinate storage for EntityBoss so that it works properly even
  when the pod is not used to spawn it.
- Converted Strife's Spectres and Entity to DECORATE.
- Added: fullscreenoffsets flag for status bars.  This changes the coordinate
  system to be relative to the top left corner of the screen.  This is useful
  for full screen status bars.
- Changed: drawinventorybar will use the width of artibox or invcurs (strife)
  to determine the spacing.  Let me know if this breaks any released mods.
- Fixed: If a status bar height of 0 was specified in SBarInfo the wrong bar
  would be shown.
- Fixed: If a static inventory bar was used the user still had to press invuse
  in order to get rid of the "overlay".
- Fixed: forcescaled would not work if the height of the bar was 0.
- Added: keyslot to drawswitchableimage.
- Fixed: The transition effects for the log and keys popups were switched.
- Converted Strife's Crusader, Inquisitor and spectral missiles to
  DECORATE.
- Converted Strife's Acolytes, Rebels, Sentinel, Reaver and Templar to
  DECORATE.
- Added DECORATE conversions for Hexen's Cleric weapons by Karate Chris.
- Added a check to Zipdir that excludes files with a .orig extension. These
  can be left behind by patch.exe and create problems.
- fixed: Unmorphing from chicken caused a crash when reading non-existent
  meta-data strings.
- Converted the ScriptedMarines to DECORATE.
- Fixed: DLightTransfer and DWallLightTransfer were declared as actors.
- Converted the PhoenixRod and associated classes to DECORATE to make
  the Heretic conversion complete.
- Converted the Minotaur's projectiles to DECORATE so that I can get
  rid of the AT_SPEED_SET code.
- Converted Heretic's Blaster and SkullRod to DECORATE.
- Converted the mace and all related actors to DECORATE and generalized
  the spawn function that only spawns one mace per level.
- Moved Mace respawning code into AInventory so that it works properly
  for replacement actors.
- Added more DECORATE conversions by Karate Chris.
- Cleaned up the new bridge code and exported all related actors to
  DECORATE so that the exported code pointers can be used.
- Separated Heretic's and Hexen's invulnerability items for stability 
  reasons.
- Fixed spurious warnings on 32-bit VC++ debug builds.
- Made the subsong (order) number a proper parameter to MusInfo::Play()
  instead of requiring a separate SetPosition() call to do it.
- Added Gez's submission for custom bridge things.
- Fixed: ASpecialSpot must check the array's size before dividing by it.


git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@151 b0f79afe-0144-0410-b225-9a4edf0717df
2008-08-10 15:12:58 +00:00

239 lines
7.7 KiB
C++

/*
** gl_missinglines.cpp
** This mess is only needed because ZDBSP likes to throw out lines
** out of the BSP if they overlap
**
**---------------------------------------------------------------------------
** Copyright 2005 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
** 4. When not used as part of GZDoom or a GZDoom derivative, this code will be
** covered by the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation; either version 2.1 of the License, or (at
** your option) any later version.
** 5. Full disclosure of the entire project's source code, except for third
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#include "gl/gl_include.h"
#include "p_local.h"
#include "gl/gl_struct.h"
#include "gl/gl_renderstruct.h"
#include "gl/gl_glow.h"
#include "gl/gl_data.h"
#include "gl/gl_basic.h"
#include "gl/gl_functions.h"
#include "gl/gl_geometric.h"
static seg_t * compareseg;
int firstmissingseg;
static int STACK_ARGS segcmp(const void * a, const void * b)
{
seg_t * seg1 = *((seg_t**)a);
seg_t * seg2 = *((seg_t**)b);
return
P_AproxDistance(seg2->v1->x - compareseg->v1->x, seg2->v1->y - compareseg->v1->y) -
P_AproxDistance(seg1->v1->x - compareseg->v1->x, seg1->v1->y - compareseg->v1->y);
//return (seg2->v1 - compareseg->v1).LengthSquared() - (seg1->v1 - compareseg->v1).LengthSquared();
}
//==========================================================================
//
// Collect all sidedefs which are not entirely covered by segs
//
// (Sigh! Why do I have to compensate for ZDBSP's shortcomings...)
//
//==========================================================================
void gl_CollectMissingLines()
{
firstmissingseg=numsegs;
TArray<seg_t> MissingSides;
TArray<seg_t*> * linesegs = new TArray<seg_t*>[numsides];
float * added_seglen = new float[numsides];
memset(added_seglen, 0, sizeof(float)*numsides);
for(int i=0;i<numsegs;i++)
{
seg_t * seg = &segs[i];
if (seg->sidedef!=NULL)
{
// collect all the segs and calculate the length they occupy on their sidedef
//added_seglen[seg->linedef-lines + side]+= (*seg->v2 - *seg->v1).Length();
#ifdef _MSC_VER
added_seglen[seg->sidedef - sides]+= (Vector(seg->v2)-Vector(seg->v1)).Length();
#else
Vector vec1(Vector(seg->v1));
Vector vec2(Vector(seg->v2));
Vector tmpVec = vec2-vec1;
added_seglen[seg->sidedef - sides]+= tmpVec.Length();
#endif
linesegs[seg->sidedef - sides].Push(seg);
}
}
MissingSides.Clear();
for(int i=0;i<numsides;i++)
{
side_t * side =&sides[i];
line_t * line = &lines[side->linenum];
//float linelen = (*line->v2 - *line->v1).Length();
#ifdef _MSC_VER
float linelen = (Vector(line->v2)-Vector(line->v1)).Length();
#else
Vector vec1(Vector(line->v1));
Vector vec2(Vector(line->v2));
Vector tmpVec = (vec2-vec1);
float linelen = tmpVec.Length();
#endif
if (added_seglen[i] < linelen -1)
{
Printf("Sidedef %d (linedef %d) incomplete (Length = %f of %f)\n",
i,side->linenum, added_seglen[i], linelen);
// create a seg for the sidedef
seg_t seg;
seg.sidedef = side;
seg.linedef = line;
if (side == &sides[line->sidenum[0]])
{
seg.v1 = line->v1;
seg.v2 = line->v2;
seg.frontsector = line->frontsector;
seg.backsector = line->backsector;
}
else
{
seg.v2 = line->v1;
seg.v1 = line->v2;
seg.backsector = line->frontsector;
seg.frontsector = line->backsector;
}
seg.Subsector = NULL;
seg.PartnerSeg=NULL;
seg.bPolySeg=false;
if (linesegs[i].Size()!=0)
{
// There are already segs for this line so
// we have to fill in the gaps. To make polyobject
// spawning possible the sidedef has do be properly
// split into segs that span its entire length
compareseg = &seg;
// Sort the segs so inserting new ones becomes easier
qsort(&linesegs[i][0], linesegs[i].Size(), sizeof(seg_t*), segcmp);
for(unsigned int j=0;j<linesegs[i].Size();j++)
{
if (linesegs[i][j]->v1 != seg.v1)
{
seg_t newseg = seg;
newseg.v2 = linesegs[i][j]->v1;
MissingSides.Push(newseg);
}
seg.v1 = linesegs[i][j]->v2;
}
}
if (seg.v1!=seg.v2)
{
MissingSides.Push(seg);
}
}
}
if (MissingSides.Size())
{
// Now we have to add the newly created segs to the segs array so
// that the polyobject spawn code has access to them.
seg_t * newsegs = new seg_t[numsegs + MissingSides.Size()];
memcpy(newsegs, segs, sizeof(seg_t) * numsegs);
memcpy(newsegs+numsegs, &MissingSides[0], sizeof(seg_t)*MissingSides.Size());
for(int i = 0; i < numsegs; i++)
{
if (newsegs[i].PartnerSeg && newsegs[i].PartnerSeg>=segs && newsegs[i].PartnerSeg<segs+numsegs)
newsegs[i].PartnerSeg = newsegs + (newsegs[i].PartnerSeg - segs);
else newsegs[i].PartnerSeg=NULL;
}
numsegs += MissingSides.Size();
delete [] segs;
segs=newsegs;
Printf("%d missing segs counted\n", MissingSides.Size());
}
delete [] linesegs;
delete [] added_seglen;
}
//==========================================================================
//
// Render those lines
//
//==========================================================================
void gl_RenderMissingLines()
{
for(int i=firstmissingseg;i<numsegs;i++)
{
seg_t * seg = &segs[i];
// This line has already been processed
if (seg->linedef->validcount==validcount) continue;
// Don't draw lines facing away from the viewer
divline_t dl = { seg->v1->x, seg->v1->y, seg->v2->x-seg->v1->x, seg->v2->y-seg->v1->y };
if (P_PointOnDivlineSide(viewx, viewy, &dl)) continue;
// Unfortunately there is no simple means to exclude lines here so we have
// to draw them all.
sector_t ffakesec, bfakesec;
sector_t * sector = gl_FakeFlat(seg->frontsector, &ffakesec, false);
sector_t * backsector;
if (seg->frontsector == seg->backsector) backsector=sector;
else if (!seg->backsector) backsector=NULL;
else backsector = gl_FakeFlat(seg->backsector, &bfakesec, true);
GLWall wall;
SetupWall.Clock();
wall.Process(seg, sector, backsector, NULL);
rendered_lines++;
SetupWall.Unclock();
}
}