Results 1 to 11 of 11

Thread: [VB6] - i nee some code advices

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    [VB6] - i nee some code advices

    how many more controls i put in my game, more slow will be
    the problem is my control code
    what i need is sugestions for don't use so many processing power.
    (here a text file for show something that i belive is slowing the pc)
    and anotherthing i have 1 timer(with 1 ms) for catch the key down event(for avoid the delay).
    the text file is for show you how i do the colision test. some of i need update(for avoid the Extender object).
    can anyone advice me?
    thanks
    Last edited by joaquim; Mar 17th, 2010 at 04:23 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [VB6] - i nee some code advices

    It might be the low Interval value of the Timer, causing the overhead to the CPU....!

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - i nee some code advices

    Quote Originally Posted by akhileshbc View Post
    It might be the low Interval value of the Timer, causing the overhead to the CPU....!
    in these event what is the minium that you advice me?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - i nee some code advices

    A couple of ideas to speed things up.

    1. Unless you need to test collisions with multiple controls, Exit the loop after you find a collision and raise the event.

    2. You have the following code deep in your IF statements. Suggest moving it closer to the top so you are not wasting time calculating position for a control you won't be testing
    Code:
    If IsControlArray(ctlTemp) = True And IndexControlArray(ctlTemp) = -1 Then
           'do nothing
    3. Your CollisionPrecise function may be able to be optimized too?

    If you are calling this every 1 ms, it may be overkill. You should cache and check whatever values/variables you are using to determine when a collision should be checked. Only do the collision test when those variables change values.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - i nee some code advices

    1. Unless you need to test collisions with multiple controls, Exit the loop after you find a collision and raise the event.
    - i try before, but don't give me the right control. the control can stay in a picturebox, but stills in form too. that's why i give up from exit loop

    2. You have the following code deep in your IF statements. Suggest moving it closer to the top so you are not wasting time calculating position for a control you won't be testing
    Code:
    If IsControlArray(ctlTemp) = True And IndexControlArray(ctlTemp) = -1 Then
           'do nothing
    i don't thot in that way, but thanks

    3. Your CollisionPrecise function may be able to be optimized too?
    -honestly i don't know, but i will see it

    If you are calling this every 1 ms, it may be overkill. You should cache and check whatever values/variables you are using to determine when a collision should be checked. Only do the collision test when those variables change values.
    - the colision test is only call, if the move event is activated(or when i change the control size, when i show a new image).

    LaVolte, what can you tell me about variable types?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - i nee some code advices

    Quote Originally Posted by joaquim View Post
    1. Unless you need to test collisions with multiple controls, Exit the loop after you find a collision and raise the event.
    - i try before, but don't give me the right control. the control can stay in a picturebox, but stills in form too. that's why i give up from exit loop
    I don't understand, if you know you have a collision, why not exit the loop since you know what control you collided with?
    Quote Originally Posted by joaquim View Post
    LaVolte, what can you tell me about variable types?
    What do you mean exactly?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - i nee some code advices

    I don't understand, if you know you have a collision, why not exit the loop since you know what control you collided with?
    i understand what you mean, but think in these way:
    your control is in a picturebox, but colides with other control. in these case your control colides with 2 controls. and if i put the exit loop i recive only 1 of them(but i don't need the picturebox).
    that's why i can change my control colision list

    What do you mean exactly?
    -what can you tell me about variable types?
    i know that variables types use memory. what i need is use less possivel memory.
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] - i nee some code advices

    Ok, looking at your code a bit more closely and assuming you cannot exit the loop sooner (which is what you want to do if you can figure it out), there may be some other optimizations you can make.

    What is lngOldPosX & lngOldPosY?
    Are you moving your control during the CollisionPrecise function?
    The reason I ask is that you calculate L1 & T1 before your loop starts and are recalculating them in your loops. If your control is not moving during the ColisionTest function, you should not have to recalcuate the position/dimensions.

    Are you sure this is the function that is taking so much time? How many controls are you collision testing against? Unless you are collision testing against 100s of controls I would not think your function is the slow-down.

    Regarding variable types. Bytes=1 byte, Integer/Boolean=2, Single/Long=4, Date/Currency=8, Variant=16, Strings=6+2*Len(String). Arrays use 16 + 8 bytes (per dimension) more bytes for each variable type. But unless you are creating 1000s of variables, I doubt these are the problem -- images & windowed controls will use more memory.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - i nee some code advices

    What is lngOldPosX & lngOldPosY?
    these variables is for change.

    Are you moving your control during the CollisionPrecise function?
    The reason I ask is that you calculate L1 & T1 before your loop starts and are recalculating them in your loops. If your control is not moving during the ColisionTest function, you should not have to recalcuate the position/dimensions.

    i must calculate, because, by tests, can give me round resolts. but with new changes i will see it

    Are you sure this is the function that is taking so much time? How many controls are you collision testing against? Unless you are collision testing against 100s of controls I would not think your function is the slow-down.
    honestly i simply don't know
    but how many controls i put in game more slow can be

    Regarding variable types. Bytes=1 byte, Integer/Boolean=2, Single/Long=4, Date/Currency=8, Variant=16, Strings=6+2*Len(String). Arrays use 16 + 8 bytes (per dimension) more bytes for each variable type. But unless you are creating 1000s of variables, I doubt these are the problem -- images & windowed controls will use more memory.
    in stoped controls(controls that don't move), these variables aren't created.

    i will do the changes and test it. thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - i nee some code advices

    in my control i'm using vb6 timers. these timers can block or slow very the cpu?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - i nee some code advices

    finally i resolve the problem
    LaVolpe let me ask you 1 thing: very api timers(2, in these case) working in same time, interval diferent, they can "crash"(give problems)?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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