This July 15th I'll have been doing this a year. I really hope I have something other than a better grasp of pointers to show for it!
That's cynical of me. I'm doing things now that a year ago I'd have considered to be black voodoo magic, like linking to libraries, playing sounds, downloading and compiling other people's programs, taking pictures with a webcam, and so on.
I'm 28 (oops, 29 now) and I want to be C literate by the time I'm 30. That's two (one) years to become competent at something I've been wanting to do nearly my whole life. No pressure.
Thursday, March 31, 2011
the GTK wagon
I pulled out my GTK book to see if it had any Cairo info but it really doesn't have much more than a brief 1 page mention of it.
The two chapters of that book that I got through were very enlightening, and I stopped because the rest of it seemed like just adding on specialty widgets to what I had already learned and that seemed like more gruntwork. Gruntwork isn't motivating.
Now that I have a goal I think I should get through the next chapter.
The biggest GTK mystery to me is passing data to callback functions. If I have a callback function to run whenever I press a button I have to pass the window handle, the button handle, and ONE pointer to misc data of my choosing. The general consensus is that I should be packing all of my variables into structures and then passing a pointer to the structure. This seems wrong in some way. I've spent time learning how to pass data to functions and now you're telling me that if I use GTK I have to wrap all of my variables in a structure? Maybe I'm missing something. This makes shoehorning a GTK interface into existing programs impossible because it would require an entire rewrite if your necessary functions.
Well, now that I think about it this might not be true.
Press button, THEN pack variables into structure, pass structure to callback, unpack variables and then pass to more interesting function?
-sigh-
Yea I think I need to get another chapter of this book under my belt before tackling anything else. Gotta walk before you can run, right?
The two chapters of that book that I got through were very enlightening, and I stopped because the rest of it seemed like just adding on specialty widgets to what I had already learned and that seemed like more gruntwork. Gruntwork isn't motivating.
Now that I have a goal I think I should get through the next chapter.
The biggest GTK mystery to me is passing data to callback functions. If I have a callback function to run whenever I press a button I have to pass the window handle, the button handle, and ONE pointer to misc data of my choosing. The general consensus is that I should be packing all of my variables into structures and then passing a pointer to the structure. This seems wrong in some way. I've spent time learning how to pass data to functions and now you're telling me that if I use GTK I have to wrap all of my variables in a structure? Maybe I'm missing something. This makes shoehorning a GTK interface into existing programs impossible because it would require an entire rewrite if your necessary functions.
Well, now that I think about it this might not be true.
Press button, THEN pack variables into structure, pass structure to callback, unpack variables and then pass to more interesting function?
-sigh-
Yea I think I need to get another chapter of this book under my belt before tackling anything else. Gotta walk before you can run, right?
Wednesday, March 30, 2011
Starting the Wumpus
I suppose I could make a Wumpus clone using GTK and Cairo.
Ok, project for this weekend (assuming I get to coding between my cousin's wedding and the usual weekend chores):
1) Initialize a Cairo window and put something there. A line, circle, box, anything.
2) Figure out how to load in an image and repeat that image (like tiles)
3) Create an array (2d if I'm feeling sassy) with values 0, 1, or 2 where each number means a different thing - lets say color of a box. Read the array and create a tile accordingly in the Cairo window.
4) See if I can get the dev/runtime dev stuff on OS X so I don't have to use the Ubuntu boot in VirtualBox.
Ok, project for this weekend (assuming I get to coding between my cousin's wedding and the usual weekend chores):
1) Initialize a Cairo window and put something there. A line, circle, box, anything.
2) Figure out how to load in an image and repeat that image (like tiles)
3) Create an array (2d if I'm feeling sassy) with values 0, 1, or 2 where each number means a different thing - lets say color of a box. Read the array and create a tile accordingly in the Cairo window.
4) See if I can get the dev/runtime dev stuff on OS X so I don't have to use the Ubuntu boot in VirtualBox.
Hunt the Wumpus
I don't remember the first time I was exposed to a computer. It was either when my dad brought home a 286 when I was four or five, or sometime earlier with my uncle's TI-99. If an original Atari 2600 counts then it was that. That thing is still somewhere in the attic....
The TI-99 was awe inducing. It didn't do much but boot into TI-BASIC and run programs off of cartridges. All the programs my uncle had were games. Some were in BASIC and some were on those cartridges. There was a racing game, some tanks game, Parsec, and Hunt the Wumpus.
http://www.stageselect.com/News/NewsViewer.aspx?newsid=593
Ah, the Wumpus. Bane of my existence whenever I went to my grandmother's house and was allowed to play.
I did some searching today and learned that Hunt the Wumpus started as a text based game. The version on the TI-99 had graphics. You just move from room to room trying to find clues about where the Wumpus had been while avoiding rooms that had pits or bats that would pick you up and put you in a random spot.
I'm at a crossroad right now. I've gotten as far as I really want to with my file reader program. I didn't get the experience allocating memory that I wanted, but that can wait until a rainy afternoon. It's a matter of feeling up to rewriting the program again. My latest quick and dirty project for work was a furious few hours of coding with a mixture of my own code and the work programmer's example code that ended with success and a knowledge of how to utilize libraries in the Windows SDK. I think what comes next should be a simple game, like Hunt the Wumpus. It could even be just text.
The TI-99 was awe inducing. It didn't do much but boot into TI-BASIC and run programs off of cartridges. All the programs my uncle had were games. Some were in BASIC and some were on those cartridges. There was a racing game, some tanks game, Parsec, and Hunt the Wumpus.
http://www.stageselect.com/News/NewsViewer.aspx?newsid=593
Ah, the Wumpus. Bane of my existence whenever I went to my grandmother's house and was allowed to play.
I did some searching today and learned that Hunt the Wumpus started as a text based game. The version on the TI-99 had graphics. You just move from room to room trying to find clues about where the Wumpus had been while avoiding rooms that had pits or bats that would pick you up and put you in a random spot.
I'm at a crossroad right now. I've gotten as far as I really want to with my file reader program. I didn't get the experience allocating memory that I wanted, but that can wait until a rainy afternoon. It's a matter of feeling up to rewriting the program again. My latest quick and dirty project for work was a furious few hours of coding with a mixture of my own code and the work programmer's example code that ended with success and a knowledge of how to utilize libraries in the Windows SDK. I think what comes next should be a simple game, like Hunt the Wumpus. It could even be just text.
success, sorta
The program for work functioned, but not better than the Matlab version. I'm certain that the function I used to play the sound is reloading the .wave every time. The other issue is that I'm trying to play a very short click and I had to make the .wav file at least a few hundred microseconds long for anything to come out of the speakers.
So the win here is that my new programming knowledge (specifically reading API docs better and linking to libraries) came in handy.
So the win here is that my new programming knowledge (specifically reading API docs better and linking to libraries) came in handy.
Tuesday, March 29, 2011
Sound 2
I've looked into SDL and CSound (thanks, Matt) but I think I'll just DL the Windows SDK and try to use the PlaySound() function. I need a .lib file that doesn't come with Windows.
I'm genuinely surprised that playing sound is this hard. Yes, I know it's tough to manage bit depth, voltage range, sampling rate, etc, but I'd have figured there would be "one way" to just get a sound out with minimal difficulty. Maybe Linux/OSX is simpler, but I need to stay in Windows-land for this project.
EDIT: I have had some success.
PlaySound("C:\\Program Files (x86)\\Steam\\resource\\warning.wav", NULL, SND_FILENAME);
I had to download the Windows SDK to link the file WinMM.lib (which must have the PlaySound implementation in it).
Ok, good. Now what? I have no idea if this will be fast enough to do what I need it to do. I'll have to generate a very tiny impulse - like a square wave 100 uS wide. Ok. Crap, I hate making such progress this late at night. It's past 10PM already and I'm trying to go to bed at a reasonable time so that I can get up early and go for a run. Healthy body healthy mind, right?
EDIT 2: I will write up a quick how-to on this topic. It's like three lines of code but NOBODY ON THE FREAKING INTERNET has written how to do what I just did succinctly and accurately.
I'm genuinely surprised that playing sound is this hard. Yes, I know it's tough to manage bit depth, voltage range, sampling rate, etc, but I'd have figured there would be "one way" to just get a sound out with minimal difficulty. Maybe Linux/OSX is simpler, but I need to stay in Windows-land for this project.
EDIT: I have had some success.
PlaySound("C:\\Program Files (x86)\\Steam\\resource\\warning.wav", NULL, SND_FILENAME);
I had to download the Windows SDK to link the file WinMM.lib (which must have the PlaySound implementation in it).
Ok, good. Now what? I have no idea if this will be fast enough to do what I need it to do. I'll have to generate a very tiny impulse - like a square wave 100 uS wide. Ok. Crap, I hate making such progress this late at night. It's past 10PM already and I'm trying to go to bed at a reasonable time so that I can get up early and go for a run. Healthy body healthy mind, right?
EDIT 2: I will write up a quick how-to on this topic. It's like three lines of code but NOBODY ON THE FREAKING INTERNET has written how to do what I just did succinctly and accurately.
ideas
I keep getting good ideas for video games.
These days I don't play so much. It used to be a hobby I sank serious time into - not just playing but also learning the ins and outs of. Late high school and early 2000s I learned how to make maps for several games (Quake, Half-Life) but I don't do that anymore.
I bought a bunch of games last year that I never played (damn you Christmas Steam sales) and whenever I do play I feel like I'm chasing the feeling I used to get when I was younger. I played maybe 10 hours into Mass Effect 2 over the winter but haven't played again since December (it says when I last played, conveniently).
I played Star Wars: Galaxies to chase the feeling I had with Ultima Online. I played Bad Company 2 to chase the feeling I had with Desert Combat. I played Dragon Age: Origins to chase the feeling I had with Baldur's Gate. Team Fortress 2 to chase Team Fortress.
Oblivion, Fallout 3, and Portal were fantastic. I played those to play them - not to chase anything. I stopped playing Mass Effect 2 because it turned into a grind to play through all the companion NPCs special missions. I am very much looking forward to Portal 2.
Anyways, sometimes I get ideas for games that I'd play. I hope someday I can get to a point where I can actually make them. I'll throw down an idea I had a while back.
1) I really like the idea of asynchronous gameplay. You make your move and send it off and wait for your opponent to make his in response (Scrabble, Words With Friends, checkers, chess, etc). I'd like to apply that concept to a light strategy game - or rather a "real time strategy" that's not real time.
You have five units: two offensive, two defensive, and one "boss" unit that protects the flag (or whatever). So does your opponent. The field is something like a soccer field with the flag your offensive units need to capture in the goal area (or something like that). You can only (at first) see your units. All characters are autonomous and you have to define some basic behaviors.
You set the defensive (two defense and the boss) in positions and define behaviors like patrol pathways and aggressiveness, weapons, and whatnot. Your offensive units you give general directions to go and maybe sacrifice not having weapons for speed. The offensive units are going to "home into" the flag once they get to a certain distance (if they get there, anyways).
So, you and your opponents set units up and then when both are finished (which can be at different times) the system says "ok you're both done setting up so run the simulation" and the game plays out with the offensive units on both teams running across the field to get the flag and encountering the defenses set up. Maybe both teams get the flag, maybe not. The point is you see the results and then can adjust your setup (and save/recall setups) and keep playing. The action of the play can be seen in "real time" since each player will have a view of the whole field (maybe?) when the game is ready to be played and the total time of the play would probably be 15-20 seconds (?).
It would make a good browser or mobile game.
These days I don't play so much. It used to be a hobby I sank serious time into - not just playing but also learning the ins and outs of. Late high school and early 2000s I learned how to make maps for several games (Quake, Half-Life) but I don't do that anymore.
I bought a bunch of games last year that I never played (damn you Christmas Steam sales) and whenever I do play I feel like I'm chasing the feeling I used to get when I was younger. I played maybe 10 hours into Mass Effect 2 over the winter but haven't played again since December (it says when I last played, conveniently).
I played Star Wars: Galaxies to chase the feeling I had with Ultima Online. I played Bad Company 2 to chase the feeling I had with Desert Combat. I played Dragon Age: Origins to chase the feeling I had with Baldur's Gate. Team Fortress 2 to chase Team Fortress.
Oblivion, Fallout 3, and Portal were fantastic. I played those to play them - not to chase anything. I stopped playing Mass Effect 2 because it turned into a grind to play through all the companion NPCs special missions. I am very much looking forward to Portal 2.
Anyways, sometimes I get ideas for games that I'd play. I hope someday I can get to a point where I can actually make them. I'll throw down an idea I had a while back.
1) I really like the idea of asynchronous gameplay. You make your move and send it off and wait for your opponent to make his in response (Scrabble, Words With Friends, checkers, chess, etc). I'd like to apply that concept to a light strategy game - or rather a "real time strategy" that's not real time.
You have five units: two offensive, two defensive, and one "boss" unit that protects the flag (or whatever). So does your opponent. The field is something like a soccer field with the flag your offensive units need to capture in the goal area (or something like that). You can only (at first) see your units. All characters are autonomous and you have to define some basic behaviors.
You set the defensive (two defense and the boss) in positions and define behaviors like patrol pathways and aggressiveness, weapons, and whatnot. Your offensive units you give general directions to go and maybe sacrifice not having weapons for speed. The offensive units are going to "home into" the flag once they get to a certain distance (if they get there, anyways).
So, you and your opponents set units up and then when both are finished (which can be at different times) the system says "ok you're both done setting up so run the simulation" and the game plays out with the offensive units on both teams running across the field to get the flag and encountering the defenses set up. Maybe both teams get the flag, maybe not. The point is you see the results and then can adjust your setup (and save/recall setups) and keep playing. The action of the play can be seen in "real time" since each player will have a view of the whole field (maybe?) when the game is ready to be played and the total time of the play would probably be 15-20 seconds (?).
It would make a good browser or mobile game.
Subscribe to:
Posts (Atom)