Results 1 to 30 of 30

Thread: Classes and Speed....

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    22

    Classes and Speed....

    Ok, I am writing a DX7 game and am suffering of low frame rates....

    I pull about 30 fps on average, which isn't alot considering I can pull more in Quake 3. (yeah its like comparing apples with oranges, but it has to be done )

    Now the first time I started this I wrote it with pretty much no structure, all the code in the form, all variables global and in the module. But I was gettig good fps, no stutters.
    After a couple of weeks of this, I re-wrote the game using OOP and structuring everything nicely, but now I am getting some major stutters!

    Now I have cut down on alot of the code, using loops instead of writing everything out, barking up things into sub-routines that can be re-used ect, but that can't be causing the fps loss...can it?

    So I figured it must be the classes.

    Right now I only have 15 objects, player objects and one graphics object. Surey this is not enough to bring down the fps so much?

    Now the question is: Should I remove some of the code from the Classes and place them in modules? should I move ALLof it? If just some, which peices? graphics?

    Thanks for your help
    Two Wrongs May Not Make A Right, But Three Rights Make A Left....

  2. #2
    Zaei
    Guest
    1) Quake 3 was written in C++, by extremely experienced programmers, who know how to optimize code.

    2) Quake 3 gets a big bonus by using the top notch video cards for rendering.

    3) VB classes are slower then snails (ok, not that slow, but thats where your hit is occuring).

    You should use Types, with functions that act on those types. Then just hold all of your objects in an array, or collection. It wont be much of a change:
    Code:
    from
    object.method
    to
    method(object)
    Z.

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    4) You might not want to hear this (or then again you could be very happy!) but you should probably use DirectGraphics for 2D. Using pretransformed and prelit vertices with no Z value you can have 2D surfaces that don't get changed in any way. Expanding on this, you can also use Alpha Blending and any features on the card easily, so you get performance increases.

    If you don't want to make this jump, just get rid of your classes.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    VB, 12 classes, DirectX 7 (DirectDraw), Pentium 133 Mhz with Voodoo 3 video card, Win2K, 70 FPS... now explain that if classes are slow


    Another of my programs:

    VB, 3 classes -> 1000 instances, DirectX 7 (DDraw), same computer, 60 FPS...



    I think there's something else wrong in your code, you can't blame those 40 FPS on the classes if I can get it this fast on a slow computer like mine



    Oh, just for the record:

    VB, no classes, DirectX 7 (Direct3D, faking 2D), one image, 50 FPS... any one said Direct3D is faster?

    Yes, it is easy to use effects like alpha blending and rotation, I agree, that's why I posted 3 samples to PSC a while back, but DirectDraw is pretty fast too, if you don't need the effects it saves you a lot of calculation which is needed to display 3D, even if it looks like 2D
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  5. #5
    Zaei
    Guest
    Your Voodoo 3 would be accelerating the drawing. I have an overclocked P3, ~500mHz, with one of the worst cards in existance (ATI Rage Pro), and cant do anything near those rates, VB or no.

    Z.

  6. #6
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Originally posted by Zaei
    VB or no.

    Thus the classes won't matter either
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  7. #7
    Zaei
    Guest
    You know what I mean =).

    Z.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    22
    I don't know if I should be happy that all that time I spent putting code into classes wasn't wasted.....or be annoyed that there is something wrong with my code

    Either way, thanks guys.
    Two Wrongs May Not Make A Right, But Three Rights Make A Left....

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    VB wasn't made for programming games

    The OOP in vb is pretty much useless, if you want to get the full advantage of OOP then you should learn C++. The vb classes are COM objects that has loads of overheads you'd never want around in a time critical game loop. VB does no optimations whatsoever, all integrated objects and functions comes with loads of bulky error handling and overheads that slows down anything you do. Reason why you even get a readable framecount is since most of the time critical algoritms are inside the api's that are compiled in C++
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I agree VB has it's limitations, that's why I stepped away from it, but that doesn't mean you can't get the most out of it...

    If classes are such a speed difference to you, just use the types as Zaei suggested and put the code in different modules instead of classes...


    If you want real OO (and better speeds), move to Pascal (or C++, although it's more difficult to learn if you're a VBer.... and no Zaei, Pascal isn't for weirdos, it's for people who want a clean (fast, even faster than C++ in some cases) language with a compiler that does the job within seconds and produces error messages which are relevant to the actual error )
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Pascal is definitely for Weirdos. I don't know how anybody could stand that syntax. How on earth can you say that Pascal is faster when it doesn't support inlining? C++ supports generic programming which is an advantage over all other languages in terms of design and runtime issues.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    "I don't know how anybody could stand that syntax."


    I don't know how anybody could stand working with pointers when absolutely not needed. The only reason why people still think C++ is better is because it has a reputation.

    Pascal is far more of a typed language than C++, that's why it compiles as fast as it does, that's why errors are easily spotted, that's why the compiler can optimize it so it produces code just as fast. C++ ends up in machine language, so does Pascal, so there's absolutely no reason why C++ would be faster...


    It should be pointed out that Delphi produces highly optimized machine code that is usually not noticeably different from VC++ code in speed of execution. What is amazing is that Delphi creates this code in a fraction of the time it takes VC++ to produce the equivalent.
    If you are like most Visual C++ programmers you would say that code created with Visual C++ will most likely be faster because "everyone knows that Visual C++ is what you use when you need speed". You would be wrong to make such a blanket assumption about Delphi's ability to produce optimal code. See Jake's Code Efficiency Challenge for real world examples of attempts at optimal code in both languages.
    http://home.xnet.com/~johnjac/Delphi...Visual%20C.htm


    If you can honestly say that either of the two languages is better, you don't know what you are talking about. They may both have their advantages and disadvantages, but you can do anything with either of them and the outputted code runs just as fast...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    C++ ends up in machine language, so does Pascal, so there's absolutely no reason why C++ would be faster...
    If you are like most Visual C++ programmers you would say that code created with Visual C++ will most likely be faster because "everyone knows that Visual C++ is what you use when you need speed". You would be wrong to make such a blanket assumption about Delphi's ability to produce optimal code
    No that's not what i'm talking about. Certain things to do about Object orientation, polymorphism for instance, callbacks, object expressions(okay i Pascal you might have nested function calls) can never be optimized at compiletime in Pascal, because they leave unnessesary room for dynamical typing/call issues at runtime. In C++ you can use templates to overcome each one of these at compiletime. How long it takes to compile is another issue, I can agree on that Pascal has some advantages, It's cleaner OOP language indeed (except there is no const protection and references(is there?)), but certain lowlevel tools like pointer aritmetics, bitwise logic, shifting, casting loopholes, C style strings have their place, you don't need to use them but you can use them to achieve more optimized code. A regular programmer's code would achieve the same with Pascal but the programmer that has some lowlevel sense can achieve better in C++.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Originally posted by kedaman
    A regular programmer's code would achieve the same with Pascal but the programmer that has some lowlevel sense can achieve better in C++.

    It's not the language who controls the programmer, it's the programmer who controls the language

    (well, except in the case of VB, but we're not talking about that right now )


    It all depends on how much you are willing to try to optimize your code. I can write C++ code which is slow too, no problem. Like I said before, some people make extremely slow VB programs, but I don't know if you've ever played 'Flux', it's pretty fast, so it all depends on which method you are using to accomplish your goals




    So far for my wise words, now let's quit this discussing and get back on topic, because this discussion will ultimately end in a yes-no fight over which language is better while the arguments are mostly opinions
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by PsychoMark
    So far for my wise words, now let's quit this discussing and get back on topic, because this discussion will ultimately end in a yes-no fight over which language is better while the arguments are mostly opinions [/B]
    Bonkers :P It's always a pleasure to compare languages even if it's not how it's suppose to be, you choose language per purpose

    Now what were we discussing before this?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Uhm....... don't know, did anyone say Bacardi?


    (btw, JSG, if you look up a couple of posts you'll find your answers )
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    22
    I think the problems is in my graphics class.

    If I bump down the resolution to 600x480, I go up to the 35-40 fps. Like wise if I bump up the resolution to 1024x768, I go way down to 20-25.

    Which is kind of disapointing, since I was really proud of my graphics class.
    Two Wrongs May Not Make A Right, But Three Rights Make A Left....

  18. #18
    Zaei
    Guest
    Originally posted by PsychoMark .... and no Zaei, Pascal isn't for weirdos, it's for people who want a clean (fast, even faster than C++ in some cases) language with a compiler that does the job within seconds and produces error messages which are relevant to the actual error ) [/B]
    Uhh... where did this come from? =).

    I personally cant stand pascal syntax. I dont know anything about the OOP in delphi, because have never used it, but from what I see, I dont like pascal at all. MSVC does the job in seconds too, you know, as well as giving you readable errors, and, in most cases, more then one error at a time (still speaking from knowledge, the pascal version i have used stop at the first error encountered). The case sensitivity in C++ is also good, dont know about delphi.

    I wont dispute the runtime speed difference, as I know that they are very similar.

    Z.

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    MSVC does the job in seconds too, you know, as well as giving you readable errors, and, in most cases, more then one error at a time
    MSVC6 sucks at the error handling, especially around those non-compliance issues all hell can break loose. I wonder if i should switch over to Borland's
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  20. #20
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Originally posted by Zaei
    MSVC does the job in seconds too, you know

    Sure, but not on a p133 . Delphi: 2 seconds. C++: 30 seconds.
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  21. #21
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by PsychoMark



    Sure, but not on a p133 . Delphi: 2 seconds. C++: 30 seconds.
    Buy a new one
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  22. #22
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I should have had one by now, if that **** school didn't claim I am missing a few points, which is going to cost me about $1000 (oh well, I've got a job as Delphi programmer now anyways )


    Besides that, it sure proves that the Pascal compiler is a lot more efficient, no matter how fast your computer is
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  23. #23
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Going to buy a 1.8 Ghz or something like that, will be fast enough I guess

    I'm keeping the P133 though, the problem with fast computers is that you won't notice it if a function is relatively slow, but if it runs on a p133, it runs on all computers nowadays
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  24. #24
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by PsychoMark
    Going to buy a 1.8 Ghz or something like that, will be fast enough I guess

    I'm keeping the P133 though, the problem with fast computers is that you won't notice it if a function is relatively slow, but if it runs on a p133, it runs on all computers nowadays
    Bah! A real prorgrammer doesn't "notice" if a function is slow or fast, he goes and check the asm listings, always!
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  25. #25
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Originally posted by kedaman
    Bah! A real prorgrammer doesn't "notice" if a function is slow or fast, he goes and check the asm listings, always!

    *ignores*
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  26. #26
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Bah to you too!

    If he wants to program straight VB he will!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  27. #27

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    22
    ...and this has to do with Classes and speed, how?
    Two Wrongs May Not Make A Right, But Three Rights Make A Left....

  28. #28
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    well, we're posting useless posts at an amazing speed, and I'm not in class at the moment


    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  29. #29
    Zaei
    Guest
    kedaman has discovered the disassembler... be afraid =).

    A real programmer doesnt bother with the assembly listings, and goes straight for the profiler. Of course, this wouldnt help, unless the programmer knows how to write functions, which the real programmer would =).

    Z.

  30. #30
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by Zaei
    kedaman has discovered the disassembler... be afraid =).
    Z.
    No i'm not going to hurt you It's just that MSVC will if you don't check out what it's doing
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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