Code refactoring thread

Report bugs you found in any Vavoom version

Code refactoring thread

Postby Crimson Wizard » 02 Mar 2011 22:02

Sometimes there are pieces of code that are not principally buggy but rather unoptimized or excessive. I wonder if it could be a good idea to have a thread for such cases.

As a start, here's a code from Actor.Special final void A_KlaxonBlare():

Self exp
Last edited by Crimson Wizard on 03 Mar 2011 11:01, edited 1 time in total.
Crimson Wizard
 
Posts: 881
Joined: 09 Nov 2005 14:21
Location: St. Petersburg, Russia

Re: Code optimization thread

Postby Crimson Wizard » 02 Mar 2011 22:24

actors/strife/strifestuff.txt

Code: Select all
actor KneelingGyu 204

Spelling error in "guy".
Crimson Wizard
 
Posts: 881
Joined: 09 Nov 2005 14:21
Location: St. Petersburg, Russia

Re: Code optimization thread

Postby b0rsuk » 03 Mar 2011 06:09

It's called "refactoring", right ? When you talk about optimization, the first thing that comes to my mind is execution speed.

Am I to report typos in comments as well ? "Delfection angle" and so forth ?

There's a lot of repetition i
User avatar
b0rsuk
 
Posts: 189
Joined: 10 May 2010 15:55

Re: Code refactoring thread

Postby Crimson Wizard » 03 Mar 2011 06:24

If you want to post something, consider yourself :) (I wouldn't report lengthy functions though, unless same code is used more than once).
BTW, I also noticed that sam
Crimson Wizard
 
Posts: 881
Joined: 09 Nov 2005 14:21
Location: St. Petersburg, Russia

Re: Code optimization thread

Postby b0rsuk » 03 Mar 2011 08:07

When functions or methods are very long, it's harder to understand them. Take a look at HitMobj and HitLine in EntityEx.Physics.vc . I've found several bugs in the two methods already, and there are more coming ! A good rule of thumb is to avoid functions
User avatar
b0rsuk
 
Posts: 189
Joined: 10 May 2010 15:55

Re: Code optimization thread

Postby Crimson Wizard » 03 Mar 2011 08:39

b0rsuk wrote:When functions or methods are very long, it's harder to understand them.

I am not going to report that because that's too obvious. Simply that. I just wanted to pay attention to less noticable things.
Crimson Wizard
 
Posts: 881
Joined: 09 Nov 2005 14:21
Location: St. Petersburg, Russia

Re: Code optimization thread

Postby b0rsuk » 03 Mar 2011 10:49

Code: Select all
    if (Special1 == 3)
 57         {
 58             damage <<= 1;
 59             power = 6.0;
 60             PuffType = HammerPuff;
 61         }


This is "third punch" of Hexen warrior (Spiked Gaunt
User avatar
b0rsuk
 
Posts: 189
Joined: 10 May 2010 15:55

Re: Code optimization thread

Postby Crimson Wizard » 03 Mar 2011 11:01

LOL that's not the kind of "mistakes" I was going to post in this thread. :?
but, oh well....
Crimson Wizard
 
Posts: 881
Joined: 09 Nov 2005 14:21
Location: St. Petersburg, Russia

Re: Code optimization thread

Postby BondEar » 04 Mar 2011 07:58

b0rsuk wrote:I know bit shifting is faster than multiplication by 2, but performance gain here is marginal ! It has its place in the renderer, the engine etc. But this code is being run only once per 3 punches of the player, and it h
BondEar
 
Posts: 28
Joined: 04 Mar 2011 07:26

Re: Code refactoring thread

Postby Firebrand » 04 Mar 2011 16:23

I also think that these type of problems reported here won't help much in terms of performance.

Also, that class typo can't be changed without affecting ZDoom's compatibility, unfortunately, that's how the class is named in ZDoom, if we change it, that c
User avatar
Firebrand
 
Posts: 1000
Joined: 11 Feb 2004 08:12
Location: Mexico

Re: Code refactoring thread

Postby b0rsuk » 04 Mar 2011 17:51

Firebrand wrote:I also think that these type of problems reported here won't help much in terms of performance.

Also, that class typo can't be changed without affecting ZDoom's compatibility, unfortunately, that's how the class is n
User avatar
b0rsuk
 
Posts: 189
Joined: 10 May 2010 15:55

Re: Code optimization thread

Postby Janis Legzdinsh » 07 Mar 2011 20:25

BondEar wrote:It would be interesting to know whether that was in the original Hexen source.

Yes it was
User avatar
Janis Legzdinsh
Site Admin
 
Posts: 1952
Joined: 13 Jan 2002 08:30
Location: Limassol, Cyprus

Re: Code refactoring thread

Postby Firebrand » 12 Mar 2011 00:52

The one reported by Crimson Wizard is fixed.
User avatar
Firebrand
 
Posts: 1000
Joined: 11 Feb 2004 08:12
Location: Mexico

Re: Code refactoring thread

Postby b0rsuk » 12 Mar 2011 06:01

I have one undeniable ugly bit, and one questionable one.

1. (questionable)

in linespec/EntityEx.Morphvc, method Morph checks for bIsPlayer and calls either MorphMonster or MorphPlayer.

Then in MorphMonster, there's another bIsPlayer check - but it wil
User avatar
b0rsuk
 
Posts: 189
Joined: 10 May 2010 15:55

Re: Code refactoring thread

Postby b0rsuk » 14 Mar 2011 13:18

I've found a really strange thing while debugging my special effects. In progs/linespec/EntityEx.Physics.vc, method HitFloorType:

[code]
1288 // Small splash for small masses
1289 if (Mass < 10.0 || bSmallSplash)
1290 smal
User avatar
b0rsuk
 
Posts: 189
Joined: 10 May 2010 15:55

Next

Return to Bug reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron