Results 1 to 26 of 26

Thread: REALLY fast collection - for stuff like bullets and enemies in a game! ;)

  1. #1

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457

    Lightbulb REALLY fast collection - for stuff like bullets and enemies in a game! ;)

    Hey all, I just developed a new technique that makes it so that you *NEVER* have to use loops to create and destroy objects in an array in a game (looking for an inactive object and stuff) - and as you know, these loops really slow down a game. My technique is really simple and very easy to implement. I made a small sample but the only part you really need is like 20 lines long (2 functions - CreateBullet() and DeleteBullet() ). No credits needed
    Attached Files Attached Files
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I already do my stuff in a way similar to that
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    @Jotaf98: lol...

    And soon you'll find out about objects and collections.


  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Jotaf, I read over all your stuff and it's nice, but I wouldn't market it as a new technique, like Fox has implied (if I read it right, lol).
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Junior Member
    Join Date
    Aug 2002
    Location
    Sydney
    Posts
    16
    Sorry, I can't download the code right now, so I can't actually comment on it specifically, but 2 really quick methods I have used are:

    1) Dynamic array with a bit smarter memory management. Each element has an "Exists" property and it allocates memory in large chunks so Redim calls are minimised (they are quite slow, especially when it is Redim Preserve).

    2) Dictionary object: similar to the collection object, can be used by referencing the Microsoft Scripting Runtime. Usage is almost identical to a collection with a couple of changes (you can't directly copy paste, but it is intuitive). Stores objects by a key which can be anything - numbers, strings, UDTs etc. Behind the scenes it is just a hash table (like the collection). But it is a lot quicker.
    Trying is the first step towards failure

  6. #6

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Lol of course you all do it in a similar way - I saw all your code samples just like everyone else and the only new thing about it is a small detail that makes it so you don't need to loop to look for inactive members: the stack of pointers to free slots in the array... the rest is exactly like most people do, and as to collections and objects, I made a few tests and this way it's a LOT faster

    Huh Rag it's exactly like your first technique except that you don't need to search for inactive objects...
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    How do you know its not how I do it I did it that way in my Winsock multiple downloading program.. of course it didn't need that speed, but thats how it was

    Cool code though.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Heh ok... It's just that I never saw this in any program, and it has a huge advantage for such a small amount of code, so I thought I would share it.
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    If I hadn't known about it, I would've used it after.. well, kind of.. errr... yeah..... disregard this post please
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I'm using this technique since ages.. also I made a little more complex management to delete items. Basically it just copies the last item of the array to the one that's going to be deleted, then cut the last item and change the 'pointer' to the new index. This way you don't even have to check for inactive members

  11. #11
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    well aren't you a little clever bunny, then

  12. #12
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Thats how I do it, Fox. A quick swap, decrement the size (you dont even have to resize the array, just keep values for filled and total, and only resize when you exit, or need more space), and youre done. Linked Lists are also great for object managment, but since VB isnt very good at inheritance, and doesnt support templating at all, you would have to re-implement everything for every object type that you have.

    Z.

  13. #13
    Frenzied Member yrwyddfa's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    1,253
    I would have been tempted to use GlobalAlloc to allocate memory directly rather than use a safearray . . .

  14. #14
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I didn't say any word about ReDimming ^^

  15. #15
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    I didnt mean ReDim (unless you run out of space, of course). I was simply referring to holding a size value =).

    Z.

  16. #16

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Heh I had never thought of that Fox, yes it's a great idea (I wonder how I never thought of that )

    I also keep a size value and never redim the arrays (unless I need more memory). Sometimes what I do is redim it for more 100 items or something and keep the size valuelower so I don't have to redim it a lot of times
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  17. #17
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Exactly, Jotaf =).

    Z.

  18. #18

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Heh

    Hey what do you think if we wrote an article or something on these techniques... I had to figure them out by myself... what a waste of brain power
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  19. #19
    Lively Member
    Join Date
    Jul 2002
    Posts
    118
    JOTAF

    A tutorials sounds good since I have no idea wot u guys r on about

    Dan

  20. #20
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Uh-oh, another Jotaf community project... lol
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  21. #21

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Lol com'on sas, you're talking like if I ever did something like that (or do it all the time)
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  22. #22
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You made a community project out of your particle systems thing, we all chipped in
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  23. #23
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192

    Wink

    It is now mid-November. I think I read this thread in September. I downloaded your file and read some of your comments. Didn't really click at the time but what did make sense "in the back of my mind" was pulling an element from the top. It's about 2 days now that I've had my own stack-based recycling system running. I use 2 stacks, and each has its own pointer. It is 'your original idea' that sparked my system. Thanks

  24. #24

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Heh you're welcome dafhi, I'm glad it was of some use to you

    Sas yeah you're right lol sorry I didn't reply... I haven't really coded anything for the past few weeks (months?), busy with hmm social life and stuff
    I learned some C++ though and made a few simple projects and all. Oh well. Maybe some day I'll come back. I wanted to code a game in C++ but somehow I like VB much better, the syntax and all is much more hmm "confy". Yeah, that.

    Oh Fox, there's a huge glitch in your technique, it kinda screws up the indexes I think... my way the indexes never ever change.

    Well, later I guess, I don't surf the forums anymore but you can still find me on MSN Messenger
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  25. #25
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yeah, I was just about to call you the genie (only comes when somebody calls him )

    Catch you later, I suppose!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  26. #26

    Thread Starter
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah, rub the lamp and I always show up... hmm... my e-mail is [email protected] , I'm usually online since I have a nice cable connection hehe
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width