Raised This Month: $51 Target: $400
 12% 

inaccurate float ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 06-10-2015 , 11:54   inaccurate float ?
Reply With Quote #1

I make this code:
PHP Code:
    #define DEBUG_DRAW_NONE    0
    #define DEBUG_DRAW_CONSOLE 1
    #define DEBUG_DRAW_LOG       2


    #define _DEBUG_BUFF    512
    #define _DEBUG_CALLS    25
    #define _DEBUG_MAXLINES    300

    
new _debug_buff[_DEBUG_CALLS][_DEBUG_BUFF], Float:_debug_time[_DEBUG_CALLS]
    new 
_debug_start_debug_sizeFloat:_gametime
    
    
new const debug_file[] = "debug.log"

    
stock _debug(draw, const func[], any:...)
    {
        new 
slot
        
if(_debug_size == _DEBUG_CALLS)
        {
            
slot _debug_start++
            
_debug_start _debug_start%_DEBUG_CALLS
        
}
        else    
slot _debug_size++
    
        
vformat(_debug_buff[slot], _DEBUG_BUFF-1func3)
        
_debug_time[slot] = _gametime get_gametime()
        
        if(
draw == DEBUG_DRAW_NONE)
            return

        if(
draw == DEBUG_DRAW_CONSOLE)
            
server_print("*DEBUG: -gametime: (%.3f)  |  -info[%s]"_gametime_debug_buff[slot])
        else 
/*if(draw == DEBUG_DRAW_LOG) */
        
{
            static 
lines
            
if(++lines _DEBUG_MAXLINES)
            {
                
lines 0
                delete_file
(debug_file)
                
log_to_file(debug_file"==== Empty debug file =============")
            }
                
            
log_to_file(debug_file"*DEBUG: -gametime: (%.3f)  |  -info[%s]"_gametime_debug_buff[slot])
        }
    }

    
stock _debug_draw(max_calls=_DEBUG_CALLSsame_frames=true)
    {
        
_gametime get_gametime()
        
        new 
map[32], amxx_file[32]
        
get_mapname(map31)
        
get_plugin(-1amxx_file31)
        
log_to_file(debug_file"# DEBUG END: plugin: [%s]  -  gametime: (%.3f)  -  map: [%s] ---"amxx_file_gametimemap)
        
        if(
_debug_size == 0)
        {
            
log_to_file(debug_file"No call log")
            
log_to_file(debug_file"----------------------------------------------------------------------^n")
            return
        }
        
        new 
_maxFloat:_lastcall_timeslot
        _max 
clamp(max_calls1_debug_size)
        
        
slot _debug_start 1
        
if(slot 0slot += _debug_size
        _lastcall_time 
_debug_time[slot]
        
        if(
same_frames)
            
log_to_file(debug_file"# Time Difference: (%dms)"floatround((_gametime _lastcall_time) * 1000.0))
        
        for(new 
count=1count <= _maxcount++)
        {
            
slot _debug_start count
            
if(slot 0slot += _debug_size
            
            
if(same_frames)
            {
                if(
_lastcall_time != _debug_time[slot])
                    break

                
log_to_file(debug_file"#%2d:  -info:[%s]"count_debug_buff[slot])
            }
            else {
                
log_to_file(debug_file"#%2d:  -difference: (%dms)   |   -info: [%s]"countfloatround((_gametime _debug_time[slot]) * 1000.0), _debug_buff[slot])
            }
        }
    
        
log_to_file(debug_file"----------------------------------------------------------------------^n")
    } 
Use:
PHP Code:
public fw_PlayerPreThink(id)
{
    
_debug(DEBUG_DRAW_NONE"fw_PlayerPreThink Pre")

    
// code...

    
_debug(DEBUG_DRAW_NONE"fw_PlayerPreThink Post")
}

public 
plugin_end()
{
    
_debug_draw()

Usually, the output is something like this:
Code:
L 06/10/2015 - 11:49:46: # DEBUG END: plugin: [file.amxx]  -  gametime: (784.340)  -  map: [de_dust2] ---
L 06/10/2015 - 11:49:46: # Time Difference: (10ms)  // Positive number
L 06/10/2015 - 11:49:46: # 1:  -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 2:  -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: # 3:  -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 4:  -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: ----------------------------------------------------------------------
Rare times i get this:
Code:
L 06/10/2015 - 11:49:46: # DEBUG END: plugin: [file.amxx]  -  gametime: (983.158)  -  map: [de_dust2] ---
L 06/10/2015 - 11:49:46: # Time Difference: (-10ms)  // negative number
L 06/10/2015 - 11:49:46: # 1:  -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 2:  -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: # 3:  -info:[fw_PlayerPreThink Post2]
L 06/10/2015 - 11:49:46: # 4:  -info:[fw_PlayerPreThink Pre]
L 06/10/2015 - 11:49:46: ----------------------------------------------------------------------
What is the cause of a negative value?
__________________

Last edited by Destro-; 06-10-2015 at 18:49.
Destro- 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 05:08.


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