Raised This Month: $ Target: $400
 0% 

Trace a line until hitting a solid, efficient method


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 06-09-2013 , 13:45   Trace a line until hitting a solid, efficient method
Reply With Quote #1

I think that I've searched many times and i haven't found it yet. So that's why I created my own way to execute a traceline with multiple hits until it hits a solid/wall.

Sometimes the process it just gets freezed, and I had to restart the process. While trying to check the code that caused this, I've suddenly saw that it was this.

My current code:

PHP Code:
#define SetBitsum(%1,%2)             %1 |= (1<<(%2 & 31))
#define IsBitsumSet(%1,%2)             (%1 & (1<<(%2 & 31)))

static Float:vecStart[3], Float:vecEnd[3]
// vecStart = eye position or entity center origin
// vecEnd = angle direction scaled to 9999

static iPlayers[32], iCountiStartEntiTraceHitbitsPlayerMask
arrayset
(iPlayers032)
iCount 0
iStartEnt 
iId // me, or any other entity
bitsPlayerMask 0

while(engfunc(EngFunc_TraceLinevecStartvecEndDONT_IGNORE_MONSTERSiStartEnt0) > 0// will always return 1, see engfunc.cpp
{
    
get_global_vector(GL_trace_endposvecStart)
    
    if(
get_global_float(GL_trace_fraction) == 1.0)
        break;
        
    
iTraceHit get_global_edict(GL_trace_ent)
    
    if(!
is_user_alive(iTraceHit)) // it supposes to stop here...
        
break;
        
    
iStartEnt iTraceHit

    
if(/* custom conditions, like checking team, is admin, etc etc etc */)
    {
        if(
IsBitsumSet(bitsPlayerMaskiTraceHit))
        {
            
log_to_file("tracebug.log""bitsPlayerMask contains repeated player (HIT ID: %d - ENT ID: %d)"iTraceHitiEnt)
        }
        else
        {
            
iPlayers[iCount++] = iTraceHit
            SetBitsum
(bitsPlayerMaskiTraceHit)
        }
    }

One day a 1gb size file was created on the logs folder called tracebug.log, it had the same phrase repeated million of times, an user get stucked on the trace line execution, and I don't know why that happened.

Before calling IsBitsumSet to check if there're repeated players on the array, the iStartEnt var is set to iTraceHit value, and IT SUPPOSES to ignore that entity on the traceline execution.

I'm just defeated, wanted to ask if there's an efficient method to get multiple hits with a traceline, like how CS does with a bullet but until it hits a solid.

Thanks in advance
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-09-2013 , 14:58   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #2

If you see it freezes, it means you got an infinite loop for some reason.

You should add a more concrete check, like after x count, it stops.

If you want to see what CS does, check FireBullets3() in combat.cpp ( from here )
__________________
Arkshine is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 06-09-2013 , 16:06   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #3

Quote:
Originally Posted by Arkshine View Post
If you see it freezes, it means you got an infinite loop for some reason.
I know that i've got an infinite loop, and that is what I was asking for, don't know why it continues looping

Quote:
Originally Posted by Arkshine View Post
You should add a more concrete check, like after x count, it stops.
I thought on that before, but beside that, I wanted to know why it fails

Quote:
Originally Posted by Arkshine View Post
If you want to see what CS does, check FireBullets3() in combat.cpp ( from here )
FireBullets3 does certain checks with distance, penetration power and range modifyiers, well, the unique condition that I applyed to this was to hit a wall. Don't know if anyone haves a code, or knows to fix it
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-09-2013 , 16:29   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #4

The point is your conditions don't follow, it could happen since you got a freeze but I don't see the need to waste your time to to try to figure out the very specific situation ; just add an "obvious" check for safety, like allowing only x tracelines.
If you want still to understand the issue, just debug your code...
__________________

Last edited by Arkshine; 06-09-2013 at 16:30.
Arkshine is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 06-09-2013 , 16:45   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #5

Quote:
Originally Posted by Arkshine View Post
If you want still to understand the issue, just debug your code...
That's another problem, I don't know how to reproduce it haha it's something very specific, and it always happens when i'm not viewing it
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 06-09-2013 , 18:58   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #6

If the map is not surrounded by walls you may hit the bug. Well is not a bug, your way to do that is buggy.

Try to add another check with PointContents to exit (SKY).
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 06-09-2013 , 21:01   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #7

Quote:
Originally Posted by joropito View Post
If the map is not surrounded by walls you may hit the bug. Well is not a bug, your way to do that is buggy.

Try to add another check with PointContents to exit (SKY).
Will add a > 32 trace execution check, and the endposition pointcontent check that you said, hope that work anyway.

PD: I'm still having the doubt of why it hits the entity that i'm actually passing in the ignoreEnt param.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
a7811311622
Member
Join Date: Apr 2010
Old 06-10-2013 , 00:19   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #8

Sorry for my bad English...

You mean that you want to trace a line, if TR_pHit > 0, get it and penetrate it until hitting a wall?
__________________
a7811311622 is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 06-10-2013 , 19:04   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #9

Quote:
Originally Posted by joropito View Post
Try to add another check with PointContents to exit (SKY).
Oh, also, i've noticed:

PHP Code:
    if(!is_user_alive(iTraceHit)) // it supposes to stop here... 
        
break; 
So...?

Quote:
Originally Posted by a7811311622 View Post
Sorry for my bad English...

You mean that you want to trace a line, if TR_pHit > 0, get it and penetrate it until hitting a wall?
Not really pHit > 0, any solid entity, func_breakable entities are solid too.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
a7811311622
Member
Join Date: Apr 2010
Old 06-11-2013 , 00:21   Re: Trace a line until hitting a solid, efficient method
Reply With Quote #10

Quote:
Originally Posted by meTaLiCroSS View Post
Oh, also, i've noticed:

PHP Code:
    if(!is_user_alive(iTraceHit)) // it supposes to stop here... 
        
break; 
So...?



Not really pHit > 0, any solid entity, func_breakable entities are solid too.
Another way to say it that trace a line if TR_pHit is the player, get it and penetrate it until hitting a solid entity which isn't the player?
__________________

Last edited by a7811311622; 06-11-2013 at 00:58.
a7811311622 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:47.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode