[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
Re: [VB6] - i nee some code advices
It might be the low Interval value of the Timer, causing the overhead to the CPU....!
Re: [VB6] - i nee some code advices
Quote:
Originally Posted by
akhileshbc
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?
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.
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?
Re: [VB6] - i nee some code advices
Quote:
Originally Posted by
joaquim
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
LaVolte, what can you tell me about variable types?
What do you mean exactly?
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
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.
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
Re: [VB6] - i nee some code advices
in my control i'm using vb6 timers. these timers can block or slow very the cpu?
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