Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Don't rewrite your old code

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Don't rewrite your old code
Neil Black
Member #7,867
October 2006
avatar

Why use that old cart? When you can get... the Ultra-Cart 5000! Its fast, its sleek, its wheels are always compatible with the cart and the axle*. And what's more, it requires no elephant** and is assassin resistant***. Only two hundred seventy-six EASY payments of $99.99****! Supplies are limited, buy now.

-----------------------------------------------------------------------------------

*Wheel-axle-cart compatability not guaranteed.
**Elephant may be required in polar regions.
***Assassin defenses are limited to the delux edition.
****Must be paid in cash and all the payments are required within two days of purchase.

kronoman
Member #2,911
November 2002
avatar

I have a double moral.

I like to rewrite from scratch my own code, because I do it as a hobby, and is fun, and educational, and I usually get better results.

I don't like, and I don't think that is good (usually, there are cases were is good) to rewrite business code from working systems that are used to generate revenue. In those systems, I think that the KISS approach, and the "don't fix it until it is broken" really apply.

Trezker
Member #1,739
December 2001
avatar

That's what branching is for.
When something isn't broken but you would gain a lot by impoving it, you create a branch so you can work on it until it works without messing up the trunk.

Neil Black
Member #7,867
October 2006
avatar

my old code needs rewriting. And this is only a few weeks old ;)

it works, though.

1#include <fstream>
2 
3 
4int Dialouge(int TextC = 255, int TextX = 420){
5 clear_keybuf();
6 rect(buffer, 0, 410, 640, 480, makecol(255, 255, 255));
7 rect(buffer, 1, 411, 639, 479, makecol(192, 192, 192));
8 rect(buffer, 2, 412, 638, 478, makecol(128, 128, 128));
9 rect(buffer, 3, 413, 637, 477, makecol(96, 96, 96));
10 rect(buffer, 4, 414, 636, 476, makecol(64, 64, 64));
11 rect(buffer, 5, 415, 635, 475, makecol(32, 32, 32));
12 rectfill(buffer, 6, 416, 634, 474, makecol(0, 0, 0));
13 int x = 20, y = 420;
14 for (int i = 0; i < message.size(); i++){
15 textprintf_ex(buffer, font, x, y,makecol(255,255,255),-1,"%c",message<i>);
16 x += 8; // whatever your font may be
17 if(x >= 612){
18 x = 20;
19 y += 10;
20 }
21
22 draw_sprite(screen, buffer, 0, 0);
23
24 rest(25);
25 }
26}
27 
28int main(){
29 allegro_init();
30 install_keyboard();
31 set_color_depth(16);
32 set_gfx_mode( GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
33
34 buffer = create_bitmap(640, 480);
35 Col_Map = create_bitmap(640, 480);
36 Col_Block = create_bitmap(32, 32);
37 clear_to_color(Col_Block, makecol(255, 255, 255));
38 Col_Empty = create_bitmap(32, 32);
39 clear_to_color(Col_Empty, makecol(0, 0, 0));
40
41 Warrior = load_bitmap( "Characters/Warrior.bmp", NULL);
42 Grass = load_bitmap( "Tiles/Grass.bmp", NULL);
43 Floor = load_bitmap( "Tiles/Floor.bmp", NULL);
44 Water = load_bitmap( "Tiles/Water.bmp", NULL);
45 Rock = load_bitmap( "Tiles/Rock.bmp", NULL);
46 Tree = load_bitmap( "Tiles/Tree.bmp", NULL);
47 Door = load_bitmap( "Tiles/Door.bmp", NULL);
48 Stone_Wall = load_bitmap( "Tiles/Stone Wall.bmp", NULL);
49 Stone_Wall_Top = load_bitmap( "Tiles/Stone Wall Top.bmp", NULL);
50 Stone_Wall_Turret = load_bitmap( "Tiles/Stone Wall Turret.bmp", NULL);
51 Rock_Wall = load_bitmap( "Tiles/Rock Wall.bmp", NULL);
52 Wood_Wall = load_bitmap( "Tiles/Wood Wall.bmp", NULL);
53 Wood_Roof = load_bitmap( "Tiles/Wood Roof.bmp", NULL);
54 Cabinet = load_bitmap( "Tiles/Cabinet.bmp", NULL);
55 Bed_Top = load_bitmap( "Tiles/BedTop.bmp", NULL);
56 Bed_Bottom = load_bitmap( "Tiles/BedBottom.bmp", NULL);
57
58 Game_Speed = 50;
59
60 Load_Maps();
61
62 Plr.X = 256;
63 Plr.Y = 32;
64 Plr.Cell = 11;
65 Plr.Spd = 8;
66 Plr.Facing = 1;
67 Plr.Anim_Frame = 2;
68
69 while(!key[KEY_ESC]){
70 if(key[KEY_DOWN]){
71 if(Check_Collision(1) == 1){
72 Plr.Anim_Frame++;
73 if(Plr.Anim_Frame > 3) Plr.Anim_Frame = 1;
74 Plr.Facing = 1;
75 Plr.Y += Plr.Spd;
76 }
77 }else
78 if(key[KEY_UP]){
79 if(Check_Collision(2) == 1){
80 Plr.Anim_Frame++;
81 if(Plr.Anim_Frame > 6 || Plr.Anim_Frame < 4) Plr.Anim_Frame = 4;
82 Plr.Facing = 2;
83 Plr.Y -= Plr.Spd;
84 }
85 }else
86 if(key[KEY_RIGHT]){
87 if(Check_Collision(3) == 1){
88 Plr.Anim_Frame++;
89 if(Plr.Anim_Frame > 9 || Plr.Anim_Frame < 7) Plr.Anim_Frame = 7;
90 Plr.Facing = 3;
91 Plr.X += Plr.Spd;
92 }
93 }else
94 if(key[KEY_LEFT]){
95 if(Check_Collision(4) == 1){
96 Plr.Anim_Frame++;
97 if(Plr.Anim_Frame > 12 || Plr.Anim_Frame < 10) Plr.Anim_Frame = 10;
98 Plr.Facing = 4;
99 Plr.X -= Plr.Spd;
100 }
101 }
102 if(key[KEY_PLUS_PAD] && Game_Speed > 5) Game_Speed -= 5;
103 if(key[KEY_MINUS_PAD] && Game_Speed < 295) Game_Speed += 5;
104
105 if(key[KEY_SPACE]){
106 //Text1 = "Okay, so the dialouge works.";
107 //Text2 = "I hope...";
108 //Text3 = "Maybe this will confirm that hope,";
109 //Text4 = "but if it doesn't then I'll just have to keep working.";
110 //Text5 = "Wow, The formatting on this looks like crap.";
111 message = "Possumdude0: Okay, so this should display properly on screen, although there is no word-wrap, so I'll have to do it manually";
112 Dialouge();
113 }
114
115 Cell_Events();
116 Events();
117
118 Draw_Screen();
119
120 rest(Game_Speed);
121
122 }
123}
124END_OF_MAIN()

gnolam
Member #2,030
March 2002
avatar

Quote:

     rect(buffer, 0, 410, 640, 480, makecol(255, 255, 255));
     rect(buffer, 1, 411, 639, 479, makecol(192, 192, 192));
     rect(buffer, 2, 412, 638, 478, makecol(128, 128, 128));
     rect(buffer, 3, 413, 637, 477, makecol(96, 96, 96));
     rect(buffer, 4, 414, 636, 476, makecol(64, 64, 64));
     rect(buffer, 5, 415, 635, 475, makecol(32, 32, 32));
     rectfill(buffer, 6, 416, 634, 474, makecol(0, 0, 0));

Ever heard of for loops? :P
Then there's the clear_keybuf() (In a drawing function. When you're not even using readkey().), the non-returning main, the complete lack of return value checking... Gah!

And for the love of the Antichrist, stop using rest() timing...

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Taiko Keiji
Member #8,307
February 2007
avatar

I would look into using a DATAFILE to store your images. it would make it easier to keep track of later.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

Neil Black
Member #7,867
October 2006
avatar

I told you it needs re-writing.;D

Johan Halmén
Member #1,550
September 2001

At the present I'm very attempted to rewrite one application. It has a rather large allegro dialog struct and the indices are somehow wrong. Months ago I added something to the dialog and never got it ready. Now I need to make it ready and I have a hard time debugging it. It compiles and runs, but doesn't do the thing it should. And it is because indices are wrong. It's all about image manipulation and I have these radio buttons for whether creating a new file or overwriting the old. And some buttons for jpg quality. So when I wan't to make resized copies of all images in a folder, it overwrites all images with b/w, unresized, really screwed up versions of the images.

The main problem is only in my coding style. I haven't figured out how to write maintainable code what comes to allegro dialogs. It would be nice to have a way of using macros or something for the indices, so if you add one item in the middle of the dialog struct, you wouldn't have to change the indices all over the code. I bet masking or any other gui lib handles this better.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Bruce Perry
Member #270
April 2000

That code does not need rewriting!! :o

I read it quickly and understood it pretty easily. I don't know what all the functions you haven't included do, but there's nothing in there that looks particularly bad. Fixing the location of the clear_keybuf call is a question of moving the line from one place to another. The 'rest' timing thing is a bit harder to fix, but only because Allegro has such a horrible timing API (it doesn't even have a 'get current time' function) - and it's still only a question of writing more code, not throwing the old code away. (The problem is that the code running in between calls to 'rest' also takes time, thereby slowing the game down on slower computers, since gnolam didn't have the manners to tell you.) You could change it to use datafiles, but you don't have to; I don't see how it makes it easier, it just keeps everything nicely in one file and allows you to compress it. And there is no need to write that series of rects as a loop; the existing code is short and it's clear, and if you use a loop, you'll have to generate the series of colour values somehow - perhaps using an array. It'll also be slower. There's just no point.

Seriously, don't rewrite that code. There's nothing fundamentally wrong with it. There may be tweaks you can make, or you may have to rethink parts of it as you add to the project (but only if they don't work or start getting messy), but that's it.

Quote:

I haven't figured out how to write maintainable code what comes to allegro dialogs.

Sounds to me as if that's your only reason not to like the project. I also remember having a bit of trouble with that myself. I think I built the array up at run time, using a macro that fills all the fields in and then increments a counter - and then, when I needed to know an index, I just added a line that copied the value of the counter variable. That would be a bit of a 'rewrite', but you could still use a fair amount of creative copying, pasting, searching and replacing to get it done.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Johan Halmén
Member #1,550
September 2001

I use Julien Cugniere's dlg editor, which is actually very good. As good as the whole damn allegro gui system deserves. Worth its price, like Gimp. The editor does some nice things, it aligns all dialog entries nicely, you can muve each entry up or down in the struct (changing draw order), it draws even rects for custom procs. But when changing the order, you have to figure out the new indices and change your code manually. And that's the pain.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Neil Black
Member #7,867
October 2006
avatar

Did I mention that I have clear_keybuf() in almost every function? For some reason I couldn't get the dialouge to work any other way (the game would immediately read a second keypress and close the dialouge before the player could read it.)

Bruce Perry
Member #270
April 2000

Are you using key[] to check for your keys? All you're doing there is reading from an array, without changing its contents. The key[] array is the status of each key: whether it's held or not.

If you are using Allegro's GUI, then that uses readkey() to detect its key-presses. You should consider whether readkey() is better for your purpose too. You can use readkey() to get a key from the buffer - and have it removed from the buffer so nothing else can read it again - and if you don't want the function to block, you can call keypressed() first to check whether there is a key in there. See the docs for more information.

If you indeed find that key[] is more appropriate, then why don't you call clear_keybuf() in just the right place, just before you show the dialogue?

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

GullRaDriel
Member #3,861
September 2003
avatar

Possumdude0: It is because your code is a mess. ;D

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Bruce Perry
Member #270
April 2000

Ta gueule.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Kitty Cat
Member #2,815
October 2002
avatar

clear_keybuf doesn't touch the key array. It just clears the keypressed/readkey queue. The only (valid) way to modify the key array is to press or release a key on your keyboard.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

Ta gueule.

Tu peux la fermer? :-X

Don't re-write old code. Write it correctly in the first place. If it turns out not to be flexible or adaptable enough then you'll have to redesign it from scratch.

edit: damn my post button skills are too fast!
I forgot to add that if you have crappy code, or you try to extend it too many times you could end up with vista! :o

-------------
Bah weep granah weep nini bong!

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

If it turns out not to be flexible or adaptable enough then you'll have to redesign it from scratch.

That is what is implied by "rewriting old code". You would NEVER rewrite an app the same way twice. Unless it was a perfectly coded piece of ART that you somehow lost the source to.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matt Smith
Member #783
November 2000

Quote:

It has a rather large allegro dialog struct and the indices are somehow wrong. Months ago I added something to the dialog and never got it ready. Now I need to make it ready and I have a hard time debugging it. It compiles and runs, but doesn't do the thing it should. And it is because indices are wrong.

I use defines for this, although enums would be better (I have been doing this since before I knew C thoroughly) This list of defines (or enum) needs to kept manually in sync with changes to the dialog, but it saves shlepping through the rest of the code. Hopefully, the dialog editor in DevAlleg will automatically maintain this list by associating the 'ID' with the relevant index. This has stalled because I want to parse the entire file for everything, because dlg's way of doing it does not preserve comments etc., and does not have automatic run-time initialisation code refactoring.

1 
2DIALOG prjopts_dialog[] =
3{
4 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5 { d_shadow_box_proc, 0, 0, 600, 400, 255, 0, 0, 0, 0, 0, NULL },
6 { d_ctext_proc, 300, 4, 200, 16, 255, 1, 0, 0, 0, 0, "Project Options" },
7 
8 { d_text_proc, 20, 17, 130, 10, 255,1, 0, 0, 0, 0, "Project " },
9 { d_list_proc, 84, 14, 200, 16, 255,0, 0, D_EXIT, 0, 0, &project_name_getter},
10 
11 
12 { mage_tabbar_proc, 10, 30, 580, 350, 12, 66, 0, 0, 0, 0, &dev1_prjopts_tabbar}, /* 1 */
13 
14 { mage_button_proc, 400, 384, _WB, _HB, 255, 12, 'c', D_EXIT, 0, 0, "&Cancel" },
15 { mage_button_proc, 500, 384, _WB, _HB, 255, 12, 'o', D_EXIT, 0, 0, "OK" },
16 
17/* General Tab */
18 
19 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
20 
21 
22/* Directories Tab */
23 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
24 
25 { d_text_proc, 30, 50, 130, 16, 255,1, 0, 0, 0, 0, "Project name" },
26 { d_edit_proc, 30, 50, 400, 16, 255,0, 0, 0, sizeof(prjo_name),0,prjo_name},
27 { d_button_proc, 440, 60, 80, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
28 
29 { d_text_proc, 30, 80, 130, 16, 255,1, 0, 0, 0, 0, "File" },
30 { d_edit_proc, 30, 90, 400, 16, 255,0, 0, 0, sizeof(prjo_fname),0,prjo_fname},
31 { d_button_proc, 440, 90, 80, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
32 
33 { d_text_proc, 30, 110, 130, 16, 255,1, 0, 0, 0, 0, "Working Directory" },
34 { d_edit_proc, 30, 120, 400, 16, 255,0, 0, 0, sizeof(prjo_workingdir),0,prjo_workingdir},
35 { d_button_proc, 440, 120, 80, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
36 
37 { d_text_proc, 30, 140, 130, 16, 255,1, 0, 0, 0, 0, "Local Root" },
38 { d_edit_proc, 30, 150, 400, 16, 255,0, 0, 0, sizeof(prjo_localroot),0,prjo_localroot},
39 { d_button_proc, 440, 150, 80, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
40 
41 { d_textbox_proc, 80, 180, 200, 120, 12, 66, 0, 0, 0, 0, dev1prjo_target_text},
42 
43 
44/* Compilers Tab */
45 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
46 
47 { d_list_proc, 80, 50, 200, 16, 12, 66, 0, 0, 0, 0, &edit_filetype_getter},
48 { d_list_proc, 80, 70, 200, 16, 255,0, 0, D_EXIT, 0, 0, &mage_fontname_getter},
49 
50 
51 { mage_check_proc, 40,160,120,10, 255,0, 'r',D_EXIT, 1, 0 , "show &ruler"},
52 { mage_check_proc, 40,170,120,10, 255,0, 't',D_EXIT, 1, 0 , "show &tabs"},
53 { mage_check_proc, 40,180,120,10, 255,0, 's',D_EXIT, 1, 0 , "tabs to spaces"},
54 { mage_check_proc, 40,190,120,10, 255,0, 'l',D_EXIT, 1, 0 , "show &linefeed"},
55 { mage_check_proc, 40,200,120,10, 255,0, 'e',D_EXIT, 1, 0 , "show lin&ewrap"},
56 { mage_check_proc, 40,210,120,10, 255,0, 'w',D_EXIT, 1, 0 , "show &wordwrap"},
57 { mage_check_proc, 40,220,120,10, 255,0, 'n',D_EXIT, 1, 0 , "show line &numbers"},
58 
59/* Data Tab */
60 
61 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
62 
63 { d_text_proc, 30, 50, 140, 16, 255,1, 0, 0, 0, 0, "Data Plugins" },
64 { mage_check_proc, 40,60,120,10, 255,0, 'd',D_EXIT, 1, 0 , "&dialog editor"},
65 { mage_check_proc, 40,70,120,10, 255,0, 'm',D_EXIT, 1, 0 , "&menu editor"},
66 { mage_check_proc, 40,80,120,10, 255,0, 'b',D_EXIT, 1, 0 , "&bitmap editor"},
67 { mage_check_proc, 40,90,120,10, 255,0, 't',D_EXIT, 1, 0 , "&toolbar editor"},
68 { mage_check_proc, 40,100,120,10, 255,0, 'w',D_EXIT, 1, 0 , "dra&wing editor"},
69 { mage_check_proc, 40,110,120,10, 255,0, 'h',D_EXIT, 1, 0 , "&html editor"},
70 { mage_check_proc, 40,120,120,10, 255,0, 'a',D_EXIT, 1, 0 , "&audio editor"},
71 { mage_check_proc, 40,130,120,10, 255,0, 'u',D_EXIT, 1, 0 , "d&uh editor"},
72 
73 
74/* Libraries Tab */
75 
76 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
77 
78 { d_text_proc, 30, 50, 130, 16, 255,1, 0, 0, 0, 0, "Libraries" },
79 { d_edit_proc, 30, 60, 200, 16, 255,0, 0, 0, sizeof(target_pathname),0, target_pathname},
80 { d_button_proc, 440, 60, 80, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
81 
82 { d_text_proc, 30, 80, 130, 16, 255,1, 0, 0, 0, 0, "Linker Options" },
83 { d_edit_proc, 30, 90, 200, 16, 255,0, 0, 0, sizeof(target_pathname),0, target_pathname},
84 { d_button_proc, 440, 90, 80, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
85 
86 
87/* Libraries Tab */
88 
89 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
90 
91 { d_text_proc, 30, 50, 130, 16, 255,1, 0, 0, 0, 0, "Libraries" },
92 { d_edit_proc, 30, 60, 400, 16, 255,0, 0, 0, sizeof(prjo_libs),0, prjo_libs},
93 { mage_button_proc, 440, 60, 48, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
94 
95 { d_text_proc, 30, 80, 130, 16, 255,1, 0, 0, 0, 0, "Linker Options" },
96 { d_edit_proc, 30, 90, 200, 16, 255,0, 0, 0, sizeof(prjo_linkopts),0, prjo_linkopts},
97 { mage_button_proc, 440, 90, 48, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
98 
99 { mage_check_proc, 40,110,120,10, 255,0, 's',D_EXIT, 1, 0 , "Link with Standard Libs"},
100 { mage_check_proc, 40,120,120,10, 255,0, 'a',D_EXIT, 1, 0 , "Link with Allegro 4"},
101 { mage_check_proc, 40,130,120,10, 255,0, 'g',D_EXIT, 1, 0 , "Link with AllegroGL"},
102 { mage_check_proc, 40,140,120,10, 255,0, 'm',D_EXIT, 1, 0 , "Link with Mage"},
103 
104 
105/* Target Tab */
106 
107 { d_shadow_box_proc, 20, 44, 560, 330, 255, 0, 0, 0, 0, 0, NULL },
108 
109 { d_textbox_proc, 80, 120, 200, 120, 12, 66, 0, 0, 0, 0, dev1prjo_target_text},
110 { d_text_proc, 30, 50, 140, 16, 255,1, 0, 0, 0, 0, "Target Type" },
111 { d_list_proc, 160, 50, 200, 16, 255,0, 0, D_EXIT, 0, 0, &target_filetype_getter},
112 
113 { d_text_proc, 30, 70, 140, 16, 255,1, 0, 0, 0, 0, "Filename" },
114 { d_edit_proc, 160, 70, 200, 16, 255,0, 0, 0, sizeof(prjo_target_fname),0, prjo_target_fname},
115 { mage_button_proc, 440, 70, 48, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
116 
117 { d_text_proc, 30, 90, 140, 16, 255,1, 0, 0, 0, 0, "Icon" },
118 { d_edit_proc, 160, 90, 200, 16, 255,0, 0, 0, sizeof(prjo_icon_fname),0, prjo_icon_fname},
119 { mage_button_proc, 440, 90, 48, 16, 255,12,'o',D_EXIT, 0, 0, "browse" },
120 
121 
122 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL }
123};
124 
125 
126 
127#define PRJOPTS_CANCEL_BUTTON 3
128 
129#define PRJO_GEN_PANE 7
130#define PRJO_DIR_PANE 8
131#define PRJO_BROWSE_FILENAME 14
132#define PRJO_BROWSE_WORKINGDIR 17
133#define PRJO_BROWSE_LOCALROOT 20
134 
135#define PRJO_CMP_PANE 22
136#define PRJO_LINK_PANE 32
137#define PRJO_GFX_PANE 42
138#define PRJO_SOUND_PANE 49
139 
140#define PRJO_TARGET_PANE 60
141#define PRJO_BROWSE_TARGET 66
142#define PRJO_BROWSE_ICON 69
143 
144#define PRJO_E_PANE 70

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

I use defines for this, although enums would be better (I have been doing this since before I knew C thoroughly) This list of defines (or enum) needs to kept manually in sync with changes to the dialog, but it saves shlepping through the rest of the code.

This is what I do in my ogg_encoder tool for apeg (which relies quite a bit on object "positions").

1static DIALOG main_dialog[] =
2{
3 { .proc=d_agup_clear_proc, .w=SW, .h=SH },
4 { .proc=d_agup_menu_proc, .x=-1, .y=-1, .dp=main_menu },
5#define ENCODE_BTN 2
6 { .proc=d_agup_button_proc, .x=SW/4-32, .y=448, .w=64, .h=16, .flags=D_EXIT, .dp="Encode" },
7#define TEST_BTN (ENCODE_BTN+1)
8 { .proc=d_agup_push_proc, .x=SW*2/4-32, .y=448, .w=64, .h=16, .dp="Test", .dp3=simple_player
9 },
10#define CANCEL_BTN (TEST_BTN+1)
11 { .proc=d_agup_push_proc, .x=SW*3/4-32, .y=448, .w=64, .h=16, .dp="Quit", .dp3=quit },
12#define MAIN_AREA_END (CANCEL_BTN)
13 
14#define VIDEO_AREA_START (MAIN_AREA_END+1)
15 { .proc=d_agup_window_proc, .x=6, .y=16, .w=628, .h=164, .dp="Video Options" },
16#define VIDEO_RADIO_BTN(x) (VIDEO_AREA_START+1+(x))
17 { .proc=d_agup_radio_proc, .x=14, .y=40, .w=96, .h=10, .d1=1, .flags=D_EXIT,
18 .dp="Video file" },
19 { .proc=d_agup_radio_proc, .x=120, .y=40, .w=96, .h=10, .d1=1,
20 .flags=D_EXIT, .dp="Video pipe" },
21 { .proc=d_agup_radio_proc, .x=224, .y=40, .w=120, .h=10, .d1=1,
22 .flags=D_SELECTED|D_EXIT, .dp="Disable Video" },
23#define VIDEO_BROWSE_BTN (VIDEO_RADIO_BTN(0)+3)
24 { .proc=d_agup_push_proc, .x=28+522, .y=53, .w=64, .h=16,
25 .flags=D_DISABLED, .dp="Browse", .dp3=file_browser },
26 { .proc=d_agup_edit_proc, .x=32, .y=54, .w=522-8, .h=14, .flags=D_DISABLED,
27 .d1=sizeof(video_fname)-1, .dp=video_fname },
28...

That way if I add or remove a widget, I just need to modify the one macro below it, and all the macros in the dialog remain in sync.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

GullRaDriel
Member #3,861
September 2003
avatar

Bruce Perry said:

Ta gueule.

Hey Bruce, do you have a problem ? Even if is your French is good, it is not good enough to crush me at French bashing, baby :P .

Now, for your French practicing, a little bit of informations:
Reste cool, je n'ai agressé personne. Quand bien même PossumDude0 se sentirais blessé, se serait à lui de le montrer, et non à toi. "Ta Gueule" est une expression qui est loin d'être poli. A la limite tu aurais posté un "Ta Gull" et cela aurait pu passer pour une taquinerie. Pour ta culture personnelle, la définition suivante convient parfaitement au mot poli: Dont le comportement, les manières, le langage sont conformes aux règles de la bienséance, au respect des convenances. Ce qui est loin d'être le cas de ta remarque.

Goalie Ca said:

Tu peux la fermer? :-X

That is the difference between the French and Canadian speak ;-) You Canadian are more courteous than us the French ;-) ( and even more courteous than people learning French. )

Mark Oates: sorry. I did not want to derail the thread.

PossumDude0: Were you really shocked ? If so I tell you now there was no reason as it was joking. If not, heh, have a nice day.

Now, back on the thread rail:
As Johan, I am also using dlg from Julien Cugnieres, it fits my needs perfectly.
You should really give it a try.

EDIT:
A simple copy-paste in a file with Matt dialog give me this:
{"name":"591667","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/b\/2bc4bad99c0f4f66dfa4785659d86082.jpg","w":646,"h":505,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/b\/2bc4bad99c0f4f66dfa4785659d86082"}591667
_

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Bruce Perry
Member #270
April 2000

Whoa. All that reply to a post with two words in it! :o

Your post just didn't seem funny. It seemed little more than an insult. If I can take it wrongly, then a lot of people could. It was worth my posting that, because now it's painfully clear you meant it as a joke :)

(I wondered if you were going to flaunt your native French at me :P)

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Goalie Ca
Member #2,579
July 2002
avatar

In canada we have a saying for "english people" who just don't get it...

Quote:

Tête-Carré

-------------
Bah weep granah weep nini bong!

GullRaDriel
Member #3,861
September 2003
avatar

My my my, Bruce. We misunderstood each other ! :'(

Lets say it is OK now :P

While I wrote my answer I was remembering the long talk we had on irc some times ago, and your post made me a little bit angry ( as I was really joking PossumDude0 this time ).

Bwahbwahbwahbwah, everything is under control now :-)

:D

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Neil Black
Member #7,867
October 2006
avatar

I just noticed something in my code. It looks like KEY_PLUS_PAD will decrease the speed, and KEY_MINUS_PAD will increase it!?

HoHo
Member #4,534
April 2004
avatar

It is quite logical in my oppinion, you are changing friction. When you lessen the friction your whatever_it_is will move faster.

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

 1   2   3 


Go to: