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

How to successfully precache files


Post New Thread Reply   
 
Thread Tools Display Modes
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-06-2010 , 09:56   Re: How to successfully precache files
Reply With Quote #31

Looking at the engine dll, the array size for the sounds are not 255. There are 3 arrays.

- PF_precache_sound_I -> 512
- PF_precache_model_I -> 1024 but the check is set to 512 (Something which could be changed)
- PF_precache_generic_I -> 527
__________________
Arkshine is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 09-06-2010 , 10:12   Re: How to successfully precache files
Reply With Quote #32

Quote:
Originally Posted by Arkshine View Post
Looking at the engine dll, the array size for the sounds are not 255. There are 3 arrays.

- PF_precache_sound_I -> 512
- PF_precache_model_I -> 1024 but the check is set to 512 (Something which could be changed)
- PF_precache_generic_I -> 527
You forgot that the sound index that can be transmitted via SVC_SOUND does not go further than 255. That is one problem.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-06-2010 , 12:12   Re: How to successfully precache files
Reply With Quote #33

I can't agree with you. :p

To find where SVC_SOUND is used : PF_sound_I -> SV_StartSound -> SV_BuildSoundMsg

Based on Quak1SDK, SV_BuildSoundMsg() looks like :

PHP Code:
int SV_BuildSoundMsg (edict_t *entityint channelchar *sampleint volumefloat attenuationint flagsint pitchorigin?, datagram? )
{       
    
int sound_num;
    
int field_mask;
    
int ent;
    
    if ( 
volume || volume 255 )
        
Sys_Error"SV_StartSound: volume = %i"volume );

    if ( 
attenuation || attenuation )
        
Sys_Error"SV_StartSound: attenuation = %f"attenuation);

    if ( 
channel || channel )
        
Sys_Error"SV_StartSound: channel = %i"channel );

    if ( 
pitch || pitch 255 )
        
Sys_Error"SV_StartSound: pitch = %i"pitch );
       
    if ( 
sample )
    {
        if ( 
sample[0] == '!' || sample[0] == '#' )
        {
            
field_mask flags SND_SENTENCE(?); // 1 << 4
            
            
if ( Q_atoisample ) > 1536 )
            {
                
Con_Printf"invalid sentence number: %s"sample );
                return 
0;
            }
        }   
    }

    
sound_num SV_LookupSoundIndexsample )
    
    if ( !
sound_num || !sv.sound_precache[sound_num] )
    {
        
Con_Printf"SV_StartSound: %s not precacheed\n"sample );
        return 
0;
    }

    
ent NUM_FOR_EDICTentity );

    if ( 
volume != 255 )
        
field_mask |= SND_VOLUME// 1 << 0
        
    
if ( attenuation != 1.0 )
        
field_mask |= SND_ATTENUATION// 1 << 1
        
    
if ( pitch != 100 )
        
field_mask |= SND_PITCH// 1 << 3
        
    
if ( sound_num 255 )
        
field_mask |= SND_?; // 1 << 2

    
MSG_WriteBytedatagramSVC_SOUND );
    
MSG_StartBitWritingdatagram );
    
MSG_WriteBitsfield_mask);
    if ( 
field_mask SND_VOLUME )
        
MSG_WriteBitsvolume );
    if ( 
field_mask SND_ATTENUATION )
        
MSG_WriteBitsattenuation 64);
    
MSG_WriteBitschannel);
    
MSG_WriteBitsent11 );
    
MSG_WriteBitssound_numsound_num <= 255 16 );
    
MSG_WriteBitVec3Coordorigin );
    if ( 
field_mask SND_PITCH )
        
MSG_WriteBitspitch);
    
MSG_EndBitWriting( &sv.datagram );
    
    
reutrn 1;

And looking at SV_LookupSoundIndex(), basically check the "sample" in the array and returns its index if found.

So, there is not a problem like you say, there is probably some bits manipulation like you can see in the code. If I have well understood. :p
__________________

Last edited by Arkshine; 09-06-2010 at 12:26.
Arkshine is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 09-06-2010 , 17:22   Re: How to successfully precache files
Reply With Quote #34

Oh, I thought it was the same as quake.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-06-2010 , 17:28   Re: How to successfully precache files
Reply With Quote #35

Just based on it with a lot of changes. But It can help to understand some things.
__________________
Arkshine is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 09-09-2010 , 20:12   Re: How to successfully precache files
Reply With Quote #36

What I was refering to, is what "ot_207" said. But, not just the precache list/limit/whatever. Like Arkshine was talking about, open the quake source, and look through "zone.c" it's all the memory allocating stuff. This file, is exactly the same ( or super close - as a decompiled showed) to the HL engine.

When you use precache_sound/model() - it add's to all kinds of internal limits (that have been discussed millions of times). But behind all the HL related stuff, memory wise it loads it into. When you use precache_generic() it loads into a "dynamic" hunk. This data will be whiped/re-loaded upon, a map change. When it's anything else, it permanently keeps that data (just the string to the file name) within the engine. Now, this data does get re-loaded, but it doesn't get "pushed" around. You can set model onto and ent, display it in-game, etc. When it's precached. This also can cause problems. (Cache_TryAlloc() and Hunk_Alloc() errors)

OVERALL. DON'T PRECACHE MODEL/SOUNDS - IF YOU JUST WANT A PLAYER TO DOWNLOAD THEM.
__________________
Oh yeah

Last edited by Drak; 09-09-2010 at 20:22.
Drak is offline
Send a message via MSN to Drak
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-11-2010 , 07:11   Re: How to successfully precache files
Reply With Quote #37

I was thinking that this tut would be more about a snippet like this :

- Make sure the file exists before trying to precache it (prevent servers crashes).
- Ability to format the file path.

PHP Code:
PrecacheFile(fmt[], any:...)
{
    new 
szFile[256], n
    n 
vformat(szFilecharsmax(szFile), fmt2)

    if( 
)
    {
        if( 
equali(szFile[n-4], ".mdl") || equali(szFile[n-4], ".spr") )
        {
            if( !
file_exists(szFile) )
            {
                new 
szError[512]
                
formatex(szErrorcharsmax(szError), "File %s doesn't exists"szFile)
                
set_fail_state(szError)
                return 
0
            
}
            return 
precache_model(szFile)
        }
        else if( 
equali(szFile[n-4], ".wav") )
        {
            new 
szFullPathFile[262] = "sound/"
            
add(szFullPathFilecharsmax(szFullPathFile), szFile)
            if( !
file_exists(szFullPathFile) )
            {
                new 
szError[512]
                
formatex(szErrorcharsmax(szError), "File %s doesn't exists"szFullPathFile)
                
set_fail_state(szError)
                return 
0
            
}
            return 
precache_sound(szFile)
        }
        else 
// .mp3 .tga
        
{
            if( !
file_exists(szFile) )
            {
                new 
szError[512]
                
formatex(szErrorcharsmax(szError), "File %s doesn't exists"szFile)
                
set_fail_state(szError)
                return 
0
            
}
            return 
precache_generic(szFile)
        }
    }
    return 
0

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Lawer
Senior Member
Join Date: Jul 2010
Location: C:\WINDOWS\MyHouse
Old 09-11-2010 , 09:44   Re: How to successfully precache files
Reply With Quote #38

PHP Code:
client_cmdid"spk subfolder/sound.wav" 
You can use EmitSound or no?
__________________
Lawer is offline
Send a message via Skype™ to Lawer
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 09-11-2010 , 12:18   Re: How to successfully precache files
Reply With Quote #39

Quote:
Originally Posted by Lawer View Post
PHP Code:
client_cmdid"spk subfolder/sound.wav" 
You can use EmitSound or no?
Yes
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX 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 09:08.


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