Loading Files from a string by OSX Using Happy Dude30th Aug 2003 5:03
|
---|
Summary Allows loading of X, 3DS, DBO and various other files in one go. Description This routine allows you to load X, 3DS, DBO, WAV, MP3, MID, DLL, BMP, JPG and PNG files from a string, and all in one go. A progress bar is displayed whilst everything is loaded. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Rem Project: LoadDLL Rem Created: 04/11/2002 20:29:04 Rem ***** Main Source File ***** REM <file,numile,num> REM Version 1.0 #constant ERROR_FILEMISSING -1 #constant ERROR_NUMMISSING -2 #constant UNLOAD_FILE 0 #constant LOAD_FILE 1 #constant PROCESS_DLL 1 #constant PROCESS_IMAGE 2 #constant PROCESS_XFILE 3 #constant PROCESS_MP3 4 #constant SEPERATOR "-" #constant SECTIONSEP "," #constant FILEEXT "." function processMusicFile(fileName as string,musicNum as DWORD,load as DWORD) select load case LOAD_FILE : Rem Load if music exist (musicNum)=0 and file exist(fileName) load music fileName,musicNum endif endcase case default : Rem Unload if music exist (musicNum)<>0 stop music musicNum delete music musicNum endif endcase endselect endfunction function processDLLFile(fileName as string,dllNum as DWORD,load as DWORD) select load case LOAD_FILE : Rem Load if dll exist (dllNum)=0 and file exist(fileName) load dll fileName,dllNum endif endcase case default : Rem Unload if dll exist (dllNum)<>0 delete dll dllNum endif endcase endselect endfunction function processImageFile(fileName as string,imgNum as DWORD,load as DWORD) select load case LOAD_FILE : if image exist (imgNum)=0 and file exist(fileName) load image fileName,imgNum,1 endif endcase case default : if image exist (imgNum)<>0 delete image imgNum endif endcase endselect endfunction function process3DFile(fileName as string,xnum as DWORD,load as DWORD) select load case LOAD_FILE : if object exist(xnum)=0 and file exist(fileName) load object fileName,xnum endif endcase case default : if object exist(xnum)<>0 delete object xnum endif endcase endselect endfunction function processSoundFile(fileName as string,soundNum as DWORD,load as DWORD) select load case LOAD_FILE : Rem Load if sound exist (soundNum)=0 and file exist(fileName) load sound fileName,soundNum endif endcase case default : Rem Unload if sound exist (soundNum)<>0 stop sound soundNum delete sound soundNum endif endcase endselect endfunction function loadData(str as string,load as DWORD) local pos as DWORD local cpos as DWORD local full$ as string local filename$ as string local objnum as DWORD local done as DWORD local extPos as DWORD local extension$ as string local temp as DWORD local tl as DWORD local sH as DWORD local sW as DWORD local st# as float local cl as DWORD tl=0 sH=screen height() sW=screen width() st#=0.25 done=0 while str<>"" pos=strpos$(str,SEPERATOR) if pos=0 pos=len(str)+1 endif full$=left$(str,pos-1) cpos=strpos$(full$,SECTIONSEP) if cpos<>0 filename$=left$(full$,cpos-1) objnum=val(right$(full$,len(full$)-cpos)) REM Look for the extension on the filename extPos=strpos$(filename$,FILEEXT) if extPos<>0 extension$=mid$(filename$,extPos+1,len(filename$)-extPos) REM We now have the extension, so we decide what it is select extension$ case "X" : process3DFile(filename$,objnum,load) endcase case "3DS": process3DFile(filename$,objnum,load) endcase case "DBO": process3DFile(filename$,objnum,load) endcase case "WAV": processSoundFile(filename$,objnum,load) endcase case "MP3": processMusicFile(filename$,objnum,load) endcase case "MID": processMusicFile(filename$,objnum,load) endcase case "DLL": processDLLFile(filename$,objnum,load) endcase case "BMP": processImageFile(filename$,objnum,load) endcase case "JPG": processImageFile(filename$,objnum,load) endcase case "PNG": processImageFile(filename$,objnum,load) endcase endselect endif str=right$(str,(len(str)-pos)) inc done if tl<sW box sW-1-tl,sH-8,_ sW-1,sH-1,_ rgb(255,0,0),rgb(255,0,0),rgb(0,255,0),rgb(0,255,0) inc tl else if tl=sW cl=255 inc tl else box 0,sH-7,sW,sH,rgb(cl,0,0),rgb(cl,0,0),rgb(0,(cl-16) && 255,0),rgb(0,(cl-16) && 255,0) inc cl,0.025 if tl>255 then tl=0 endif endif sync else exitfunction ERROR_NUMMISSING endif endwhile endfunction done |