types ???
Blitz3D Forums/Blitz3D Programming/types ???
| ||
Hi again... Im making a dynamic system, 3D project. where i need to use a lot of vectors and boids. i made my program run quite nice and even made a little screensaver out of,,,, my first app… I’ll post it later on in this thread… My problems is to understand types… I thought I figured them out but now when printing variables to the screen I see that my temp type is way bigger and for each iteration it magically grow. ?????.. I found something quite disturbing with this little example I made… Type m Field x#, y#, z# End Type For i = 1 To 100 v.m = New m Next ma.m = New m Temp = 0 temp2 = 0 Repeat temp = 0 temp2 = 0 For v.m = Each m temp = temp + 1 Next For v.m = Each m ;Delete v Next For ma.m = Each m temp2 = temp2 + 1 Next Text 10, 10, "1: " + temp Text 10,20, "2: " + temp2 Until KeyHit(1) End 1. look at the two different variables temp and temp2, they are both 101 in my case, where temp2 should ONLY be 1 since my MA.vector only consist of one type..? it seem like when you create a new instance of the vector you don’t create a totally new one 2. when I delete all in my V.type holder I delete them all, included the one from MA.m this is rather irritating problem since im not only deleting my temp vectors that I need to calculate on but also all the vectors that I need inside other types for positing my entity’s…. HELP.. how do I create a new copy of my vector type (here it is M).. and how do I make sure it a totally independent copy. So something like this will work properly…? Type vector Field x# Field y# Field z# End Type Type objData Field obj Field SpaceObj Field id Field velocity.vector ; = New vector Field pos.vector ; = New vector Field oldpos.vector ; = New Vector Field seekVar# Field fleeVar# Field speed# Field max_speed# Field min_speed# Field personalSpace# End Type |
| ||
"The For .. Each loop allows you to walk through each object in the Type collection. This is perfect for updating a large group of objects (such as a group of alien invaders). Do look over the Type command. " --- from the help file ---- Just came up with another question... do the above mean that everytime i create a new vector or copy of a type (as i thought i was). then im just adding that to the "list" of vector types and not like in my code before (the last snippet). a vector type WITHIN and holded by my objData..... ? Field velocity.vector ; = New vector Field pos.vector ; = New vector Field oldpos.vector ; = New Vector do i really have to create a vector type for each copy/instance.. like type vector_pos type vector_temp type vector_velocity type vector_oldPos to be sure i can delete some without deleting eks. my temp vectors...... ????... this is very strange for my... |
| ||
If you write "v.m=New m", or just "New m" does not make a difference, v.m is just a handle keeper, and when you next time use "v.m=New m" the old handle will be lost, all m types are just m types, when you loop trough the types with "For v.m = Each m" v.m will in turn hold all of the m type handles, so there is nothing funny about your code. I don't think you need multiple vector types, just make shure that you keep track of the handles. Finally I will tell you that you could also use arrays for this job, they are easier to understand, and are multiple times faster to use. The only drawback is that you will need to set a roof on how many objects you can have. If you stick to types then you could have a variable in each vector type telling if it's a temp vector or whatever it might be. |
| ||
aha...... yes i figured that all types i make of the M type will be in the same "file chunk" list thingie.. so if my handler is called peter, john or whetever and i have more, all the data will still be locatet one place and in a row from when it was born..... right.... therefor for each will delete everything.... BUT... Aren't there a way only to loop throug all the v or MA or A or B ..... types. so when i loop them through my temp variable will only count to the amount of the V.m types and not the MA.types........... it would make life so much easier than having an ID number for each type...... like Temp vectors have an ID of 0 or something. and then run ALL M types through and delete ID=0's..... 2 questions... running ALL types instances through (like 1500) ain't that a cpu time comsumer? Are there anyway to make dynamic array's... any..... asm code snippet or something :).... and last thing, the only way to see how many instances/copies there are of one type class, is that by running them all through?????... no m.count code function.. ???? (could set ANOTHER variable hehe) THanks.. |
| ||
Sorry no dynamic arrays, but you can make something almost as good if you should run into trouble. An array can be redimmed, but you will lose everything stored in it, you can start out by passing every value from your array to a midway array, then redim your array, and pass the variables back.array1size=99999 dim array1(array1size) ;the expansion part dim midway(array1size) for a=0 to array1size midway(a)=array1(a) next dim array1(array1size+100000) for a=0 to array1size array1(a)=midway(a) next array1size=array1size+100000 About counting types, just keep track of the number in a variable if you need so. Looping trough 1500 types is probably not going to take more than a millisecond. |
| ||
Thanks.. again. but i think Array trix is complex and clumsy to use.. :).. I sad to say that im really disappointed with blitz way of handeling array's and types.. It should be so that when i wrote A.vector = new vector Then time i added a new A.vector it would be placed into the A file chunk (or where it keep the data).. so in this way we could dynamic run a for-each on A and get one end value than if we runned on any other instance of .vector (ect.. B.vector) but now.. every vector that have ever been created are storage in .Vector..... and i hate it :).... because a function like this.. Function Vec_ADD2Types.vector(source1.vector, source1.vector) --- something End Function will result in a newly created vector in out type and therefor... and when we run our little program for some time we will end up with 10000's of instance of types in .vector sad...... mr. blitz please make some dynamic array's or better Object stuff... the program is so fine, but then this... well we all learn :)))) |
| ||
Oh, come off it, you just need to make your arrays big enought from the start. I'm not shure that I perfectly understand your problem, what is it that you are making? I'm pretty shure that I can help you with the exact problem, you just need to get into the way programming works. |
| ||
yep that's why i ended with "we all learn".... im used to OOP. so there for, having a hard time getting the concept of those types in detail, overall types are quite nice... but just the fact that you can't say.... vector.type(3) or something like that do not make any sense..... anyway.. tanks for the help and brainstorm on types :).. |
| ||
hey ebussiness, you can define a type that closely resembles a dynamic array. You just have to write the code for them. starting with something like... Type dynamic_array field x,next_element.dynamic_array End Type |
| ||
odd, doesn't seen to be any dynamic array library in the archives. Someone should upload one. |
| ||
odd, doesn't seen to be any dynamic array library in the archives. Someone should upload one. Thats probably due to the fact most folks use banks instead. |
| ||
an amd athlon ~1.5 ghz can count from 1 to 1billion within a second so 1500 types is nothing. it all depends on what your program is doing when its looping through types like printing values or whatever. |
| ||
here. http://mtwirefree.net/kbilling/DynamicDataStructures.zip there's your dynamic array. now to use types with it, there's an extra step. to put a type into the array, you use Handle(): v.m=New m ArraySetValue a,0,Handle(v) then, to convert from a handle back to a type pointer, you use Object.<type>(): ma.m=Object.m(ArrayGetValue(a,0)) there you go. be sure to read the docs with it as well. |
| ||
Check these pages at BlitzCoder: http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=mutteringgoblin09232002232208.html http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=gamekrylar10192000.html They give a complete explanation to what types actually ARE and how to use them. |