|
This thread is locked; no one can reply to it. |
1
2
|
How would you do it? |
Albin Engström
Member #8,110
December 2006
|
I've written many different types of builds for my games, i would like you to describe how you would have done it, as i have no name for the subject i will describe my "builds", and you will probably realize what im talking about: 1. To put everything in main... no functions at all and drawing directly to the screen. I've done a lot more but the difference between them and these are so small so i didn't post them. ALL of these was failures, at first i thought number 7 was a little good and it ran so well, but the frames lagged more the more the cpu was used, and it did not look good at all when using draw_trans_sprite for fading(the cpu went 100%). also, i realized that if the cpu could not execute a logic loop in less than a millisecond on normal speed the program would screw up. Before i struggle with the next one i'd like to listen some advices, because i really need some as you might have realized, the reason i like to have a logic rate of a 1000 is because it's convenient, the collision detection gets much better looking and i don't have to waste as much time as i would have with a logic rate synced with the frame rat. if you have any smart ideas and tricks on how to make an efficient yet good build, please tell me. |
Onewing
Member #6,152
August 2005
|
Quote: How would you do it? With classes and style. ------------ |
Kikaru
Member #7,616
August 2006
|
I don't get what you want to attempt. Here is what I do, though most people don't like it. I put a mix of things in main. Mostly, if it seems too long, or is redundant, or needs arguments, or needs a return value, then it goes in a global function. I always use double buffering, and put all drawing in main. I use timed game loops, with the help of an interrupt handler from Allegro. |
Onewing
Member #6,152
August 2005
|
Quote: Oh, the part most people don't like is that I use all global variables. Using global variables is not a sin, but using all global variables could be a questionable religion in itself. ------------ |
Arthur Kalliokoski
Second in Command
February 2005
|
If a given module (such as main) grows beyond a screenful or two, it's easy to get confused. The little example programs in allegro/examples are pushing it, but they're "self contained" as examples. If your program gets really big, main() should be more like a table of contents, letting you see the big picture, and you'd look at the individual modules for more detail. Same with globals, since every module can see them, it gets harder to think of unique names for them all in a big program, also they can slow down a program if the access patterns are always causing cache misses. Having static variables in your modules can do the same, but you eliminate the first problem. Locals in functions are on the stack, which is accessed pretty often (especially since a called function pushed the return value) but if you need to access some variable in several modules or they're huge arrays or something then that's out too. They all watch too much MSNBC... they get ideas. |
Trezker
Member #1,739
December 2001
|
I'm very much satisfied with 100 logic updates per second. If collisions require more then I'll improve the handling in those situations but I wont do more frequent handling. I rather not put anything in main except call the run function of the game. I also don't want to go into more of my programming style. There's way too much of it. |
ReyBrujo
Moderator
January 2001
|
Classes, inheritance and interfaces. Every class is small, doing very little things. I use composite to create bigger classes with smaller ones. And things like that -- |
Audric
Member #907
January 2001
|
If you have performance problems, compile your game with profiling options, and analyze what takes time. Doing more than 100 updates per second is probably wasteful, but there's probably something else as well. |
Evert
Member #794
November 2000
|
Lots of functions with as few global variables as possible (I still have a few more than I should though). I do use a fair number of static variables in each source file, which is probably ok given that each of these source files are fairly specialised to a specific task. Quote: it did not look good at all when using draw_trans_sprite for fading(the cpu went 100%). Make sure you don't use draw_trans_sprite() with video bitmaps, since reading from video bitmaps is slow. Quote: also, i realized that if the cpu could not execute a logic loop in less than a millisecond on normal speed the program would screw up. Limit the number of frames that may be skipped. Quote: the reason i like to have a logic rate of a 1000 is because it's convenient, Do not run your logic at 1000Hz; Allegro's timers can't run at that frequency reliably. Stick to 100Hz if you need an easy number. Quote: the collision detection gets much better looking Collision detection should not depend on your logic rate (I see how it could, but it shouldn't). Quote: and i don't have to waste as much time as i would have with a logic rate synced with the frame rat. What do you mean here? |
Albin Engström
Member #8,110
December 2006
|
"Audric: Doing more than 100 updates per second is probably wasteful / Evert: Stick to 100Hz if you need an easy number." got it, but would you say no to multiply it with 10 and use it with a logic loop? . "Evert: The game loop rests when no graphics need to be updated and the next logic cycle hasn't started yet (reducing CPU usage to a few percent)." Great tip!! gave me a lot of good ideas . "Evert: Make sure you don't use draw_trans_sprite() with video bitmaps, since reading from video bitmaps is slow." drawing a video bitmap or to a video bitmap? i'm (was) drawing to a videobitmap. "Evert: Collision detection should not depend on your logic rate (I see how it could, but it shouldn't)." what should it depend on? i can't see any easy solutions that would satisfy me . "Evert: What do you mean here?" I meant that i don't have to waste as much time on figuring out how to convert everything from 1000ll to 100ll with the same effect. |
gnolam
Member #2,030
March 2002
|
Gah. Use [quotes} like normal people. Quote: got it, but would you say no to multiply it with 10 and use it with a logic loop? I would. You don't need a 1000 Hz update frequency. Quote: drawing a video bitmap or to a video bitmap? i'm (was) drawing to a videobitmap. Think about it: to simulate transparency, you take the pixels from both the bitmap you're drawing from and the one you're drawing to and blend them together. So if reading from video bitmaps is slow, that means..? -- |
Evert
Member #794
November 2000
|
Quote: drawing a video bitmap or to a video bitmap? Check the manual on vram->vram blits; you should only do it if what you're trying tio do can be accelerated in hardware (Allegro's translucent blits can not be). Quote: what should it depend on? Old and new positions of the colliders, maybe the two or three previous positions as well if you need estimates for the velocity and the acceleration. |
Albin Engström
Member #8,110
December 2006
|
don't know how to use quotes ^^, looked in the help file, but i don't want to test it on a "serious" conversation. "gnolam: Think about it: to simulate transparency, you take the pixels from both the bitmap you're drawing from and the one you're drawing to and blend them together. So if reading from video bitmaps is slow, that means..?" haha, i guess the answer was that simple, but i'd have to ask, you never know what may happen in this strange world of allegro and c++ if you don't know the truth.. "Old and new positions of the colliders, maybe the two or three previous positions as well if you need estimates for the velocity and the acceleration." sounds good, but i can't help to think that it would be much harder to inplent. my other questions still remains to answer... and "I would. You don't need a 1000 Hz update frequency." doesn't qualify as an answer thanks! |
Evert
Member #794
November 2000
|
Quote: looked in the help file, but i don't want to test it on a "serious" conversation. You can edit your posts, you know? Quote: i can't help to think that it would be much harder to inplent. Depends on your implementation, I suppose. Without seeing an implmentation I can't comment on that (you don't have to post code; I don't have time to look at it in detail anyway). |
LennyLen
Member #5,313
December 2004
|
Quote: You can edit your posts, you know? Or use the preview feature.
|
Albin Engström
Member #8,110
December 2006
|
"You can edit your posts, you know?" "you don't have to post code" |
gnolam
Member #2,030
March 2002
|
And so you choose not to better yourself because..? -- |
Michael Jensen
Member #2,870
October 2002
|
|
Albin Engström
Member #8,110
December 2006
|
"gnolam: And so you choose not to better yourself because..?" "Michael Jensen: Have you been programming on paper again? [thedailywtf.com]" |
LennyLen
Member #5,313
December 2004
|
Quote: Gah. Use [quotes} like normal people. Just a reminder.
|
BAF
Member #2,981
December 2002
|
Use quotes FFS! |
Albin Engström
Member #8,110
December 2006
|
BAF said: Use quotes FFS! HA! in your face.. |
ImLeftFooted
Member #3,935
October 2003
|
Go to the mockup page and read the section entitled 'Quotes'. Very nice feature . edit: Wow that is the definition of beaten |
Goalie Ca
Member #2,579
July 2002
|
If a tree falls down an no one is around does it make a sound? In other news does foot->kick(ass) or does ass->getKicked(foot)? I haven't quite figured that one out. ------------- |
Richard Phipps
Member #1,632
November 2001
|
Everyone has a different opinion on the correct way to program, and the style you should use. While some methods are going to be better than other, I think personally the most important thing is finishing a project rather than how it is written. |
|
1
2
|