Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 22-Oct-2014 17:59:09

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

crazy loop behavior...I must be doing something wrong here

I am currently experiencing a strange problem with a loop.

The code I have written does this

It takes a list of files [S r1].
It gets the file size for the file represented by each element of the list
It adds up the file sizes for all the files in the list to get a total number of bites as a float (I treat all numbers as floats because at first I was using itof and ftoi and thought that this was the cause of the problem)

while the packages are loading, the code keeps track of how much in bytes have been loaded with the packages, and how much a percentage of the total has been loaded.

For some reason, the percentage figure jumps from 35% to 222% when a package that is only 1% of the total amount of bytes is loaded.

I've tried to figure out why, but have failed?  It's a bug (probably not) or I'm doing something wrong (probably)

code to get size of all files loaded together.  everything is properly indented in bluefish, but it gets messed up when pasted into crhome or openoffice, so I made the indents more readable by hand. (they are properly nested in bluefish)

ack! what am I missing (after looking again and again)
thx for your help

//filelist is [S r1], totalfilesize is F
fun getsizeofallfilesaddedtogether (filelist, totalfilesize)=
	//get head of list
	let hd filelist -> filepath in
	let _checkpack filepath -> file in 
	(
	if filelist == nil then
	//open then brace
			(
			totalfilesize;
			)
			else
			(	
			set totalfilesize = totalfilesize +.  itof((_fileSize file));
			set filelist = tl filelist;
			getsizeofallfilesaddedtogether filelist totalfilesize;
			);
	);;

code to print out status of file loading, giving name of file, size of file, and percentage of total bytes loaded:

  
 typeof total_filesize = I;;
 typeof linecount = I;; 
 typeof bytesloadedsofar = I;;
 typeof fbytesloadedsofar = F;;
 typeof loadedfilelist = [S r1];;


fun loadOS3D (file, projname, pw, ph, fullscreen, text_control,  log_window,  environment)=
  set total_filesize = 0;
  let "tools/os3dlib/tools.pkg"::
    "tools/os3dlib/xmlparser.pkg"::
    "tools/os3dlib/keyblib.pkg"::
    "tools/os3dlib/ogrematparser.pkg"::
    "tools/os3dlib/v3dlib.pkg"::
    "tools/os3dlib/v3dlib_physics.pkg"::
    "tools/os3dlib/2dglib.pkg"::
    "tools/os3dlib/minidhdms.pkg"::
    "tools/os3dlib/mkapplet.pkg"::
    "tools/os3dlib/netcomlib.pkg"::
    "tools/os3dlib/os3dpaths.pkg"::
    "tools/os3dlib/os3dstruct.pkg"::
    "tools/os3dlib/os3dtypeconv.pkg"::
    "tools/os3dlib/os3dplugins.pkg"::
    "tools/os3dlib/os3dpluginscb.pkg"::
    "tools/os3dlib/os3dloader.pkg"::
    "tools/mediaoctopus3dplayer/os3dversion.pkg"::
    "tools/mediaoctopus3dplayer/os3dlogs.pkg"::
    "tools/mediaoctopus3dplayer/mediaoctopus3dplayer.pkg"::
      nil
  -> lfiles in
  (
  	
    		let 0 -> linecount in
    		let 0.0-> fbytesloadedsofar in
   			(
    				_SETfirstLine text_control linecount;_ADDtext text_control strcatn  (ftoa (getsizeofallfilesaddedtogether lfiles 0.0)):: " total bytes to be loaded  ":: "\n"::nil; 	
    				set linecount = linecount +1;
    				while (lfiles != nil) && (secureLoad hd lfiles) do
    				(
      				 //get file from head of list
      				 let _checkpack hd lfiles -> file in
				//get size of file at head of list        				
				let _fileSize file -> ipackage_filesize_inbytes in
        				//convert size of file to float
        				let itof ipackage_filesize_inbytes -> fpackage_filesize_inbytes in
        				//get size of all files in list added together
        				let getsizeofallfilesaddedtogether lfiles 0.0 -> float_total_bytesize in
		  		//divide bytes loaded so far by total bytes to be loaded
		  		let fbytesloadedsofar/. float_total_bytesize -> fpercentageloaded in
		  		//change fraction to percent
		  		let fpercentageloaded *. 100.0 -> fpercentageloaded in 
		  		( 
        				//add size of current package tto bytes loaded so far
	        			set fbytesloadedsofar =  fbytesloadedsofar +. fpackage_filesize_inbytes; 
				//get name of file at head of list and print it
        				getPackageNames2 (hd lfiles) text_control;
        				_SETfirstLine text_control linecount;
        				//print size of current file
        				_ADDtext text_control strcatn  (ftoa fpackage_filesize_inbytes):: " bytes loaded in current package ":: "\n"::nil;
        				_SETfirstLine text_control linecount;
        				//print bytes loaded so far
        				_ADDtext text_control strcatn  "bytes loaded so far "::(ftoa fbytesloadedsofar):: "\n"::nil;        														_SETfirstLine text_control linecount;
       				set linecount = linecount +1;
       				//print percentage loaded
       				_ADDtext text_control strcatn  (ftoa fpercentageloaded):: " % loaded now.":: "\n"::nil;
        				_SETfirstLine text_control linecount;
        				_PAINTtext text_control;
        				_PAINTwindow log_window; 
        				//for the next iteration of the while do loop, cut head off list and repeat 
        				set lfiles = tl lfiles; 
        				0;
      				);
    				if (lfiles == nil) then
   				(      
      				commandToAx "OS3DPlayerLoading" "Done.";
      				// launch Player
      				initOs3dPlayer file projname pw ph fullscreen;
      				0;
    				)	
    				else
    				(
      				f (winAX == nil) then
      				(
       				 _DLGrflmessage (_DLGMessageBox _channel nil "Error" "This version of OpenSpace3D Player is not compatible with your Scol Voy@ger version, please perform an update or ask the webmaster to uptade his projects." 0) @cbVersionError nil;
        				0;
      				)
      				else
      				(
        				commandToAx "OS3DPlayerError" "This version of OpenSpace3D Player is not compatible with your Scol Voy@ger version, please perform an update or ask the webmaster to uptade his projects.";
        				0;
      				);
      				0;
       				);
       				0;
  				);
 				0;
  	);
  0;;

Offline

#2 22-Oct-2014 18:12:07

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: crazy loop behavior...I must be doing something wrong here

and even after all that indentation cleanup, chrome manages to make things less readable ....sigh

Offline

#3 22-Oct-2014 18:35:57

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: crazy loop behavior...I must be doing something wrong here

[solved]

I was making the list of files smaller and smaller, which made the percentage get bigger and bigger. hmm time to get rid of those annoying floats and see what happens.

Last edited by hebdemnobad (22-Oct-2014 18:38:04)

Offline

#4 23-Oct-2014 15:26:52

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: crazy loop behavior...I must be doing something wrong here

final code that works...i've given up on copying and pasting indentations because every method I have tried fails...if any of you guys has a method of doing it please tell me so I can save your eyes. it would be great if the forum allowed file attachements, fwiw (just for small files such as .pkg files)

fun loadOS3D (file, projname, pw, ph, fullscreen, text_control,  log_window,  environment)=
  
  let "tools/os3dlib/tools.pkg"::
    "tools/os3dlib/xmlparser.pkg"::
    "tools/os3dlib/keyblib.pkg"::
    "tools/os3dlib/ogrematparser.pkg"::
    "tools/os3dlib/v3dlib.pkg"::
    "tools/os3dlib/v3dlib_physics.pkg"::
    "tools/os3dlib/2dglib.pkg"::
    "tools/os3dlib/minidhdms.pkg"::
    "tools/os3dlib/mkapplet.pkg"::
    "tools/os3dlib/netcomlib.pkg"::
    "tools/os3dlib/os3dpaths.pkg"::
    "tools/os3dlib/os3dstruct.pkg"::
    "tools/os3dlib/os3dtypeconv.pkg"::
    "tools/os3dlib/os3dplugins.pkg"::
    "tools/os3dlib/os3dpluginscb.pkg"::
    "tools/os3dlib/os3dloader.pkg"::
    "tools/mediaoctopus3dplayer/os3dversion.pkg"::
    "tools/mediaoctopus3dplayer/os3dlogs.pkg"::
    "tools/mediaoctopus3dplayer/mediaoctopus3dplayer.pkg"::
      nil
  -> lfiles in
  (
  	
    		let 0 -> linecount in
    		let 0-> ibytesloadedsofar in
    		//get size of all files in list added together
    		let getsizeofallfilesaddedtogether lfiles 0 -> i_total_bytesize in
   					 (
    						_SETfirstLine text_control linecount;_ADDtext text_control strcatn  (itoa (getsizeofallfilesaddedtogether lfiles 0)):: " total bytes to be loaded  ":: "\n"::nil; 	
    						set linecount = linecount +1;
    						
    						while (lfiles != nil) && (secureLoad hd lfiles) do
    								(
      								   //get file from head of list
      								   let _checkpack hd lfiles -> file in
											//get size of file at head of list        									
											let _fileSize file -> ipackage_filesize_inbytes in
        								
        									
        									let itof ibytesloadedsofar -> fbytesloadedsofar in
        									let itof i_total_bytesize -> f_total_bytesize  in
		  									//divide bytes loaded so far by total bytes to be loaded
		  									let fbytesloadedsofar/. f_total_bytesize -> fpercentageloaded in
		  									//change fraction to percent
		  									let fpercentageloaded *. 100.0 -> fpercentageloaded in
		  									let ftoi  fpercentageloaded -> ipercentageloaded in
		  									
       										( 
        
	        												//add size of current package tto bytes loaded so far
	        												set ibytesloadedsofar =  ibytesloadedsofar + ipackage_filesize_inbytes; 
															//get name of file at head of list and print it
        													getPackageNames2 (hd lfiles) text_control;
        													_SETfirstLine text_control linecount;
        													//print size of current file
        													_ADDtext text_control strcatn  (itoa ipackage_filesize_inbytes):: " bytes loaded in current package ":: "\n"::nil;
        												   _SETfirstLine text_control linecount;
        													//print bytes loaded so far
        													_ADDtext text_control strcatn  "bytes loaded so far "::(itoa ibytesloadedsofar):: "\n"::nil;        													
       												 	_SETfirstLine text_control linecount;
       												 	set linecount = linecount +1;
       												 	//print percentage loaded
       												 	_ADDtext text_control strcatn  (itoa ipercentageloaded):: " % loaded now.":: "\n"::nil;
        												 	_SETfirstLine text_control linecount;
        												 	_PAINTtext text_control;
        												 	_PAINTwindow log_window; 
        													//for the next iteration of the while do loop, cut head off list and repeat 
        													set lfiles = tl lfiles; 
        													
        													0;
      										);
    									);
							    
    							if (lfiles == nil) then
   									(      
      										
      										commandToAx "OS3DPlayerLoading" "Done.";
   											//destroy loading window
   											_DSwindow log_window;    										
												// launch Player
      										initOs3dPlayer file projname pw ph fullscreen;
      										0;
    									)	
    									else
    									(
      									if (winAX == nil) then
      										(
       										 _DLGrflmessage (_DLGMessageBox _channel nil "Error" "This version of OpenSpace3D Player is not compatible with your Scol Voy@ger version, please perform an update or ask the webmaster to uptade his projects." 0) @cbVersionError nil;
        											0;
      										)
      									else
      										(
        												commandToAx "OS3DPlayerError" "This version of OpenSpace3D Player is not compatible with your Scol Voy@ger version, please perform an update or ask the webmaster to uptade his projects.";
        												0;
      										);
      								0;
       								);
       						0;
  						);
 				0;
  	);
  0;;

Last edited by hebdemnobad (23-Oct-2014 15:28:02)

Offline

Board footer

Powered by FluxBB