--- Log opened Wed Dec 24 00:00:26 2008 |
00:04 | <@McMartin> | Oh, hey, AnnoDomini is logged in again. |
00:05 | <@AnnoDomini> | Hm? |
00:05 | <@McMartin> | I had a bunch of comments on your snake game. |
00:05 | <@McMartin> | http://www.stanford.edu/~mcmartin/misc/snake-comments.txt |
00:06 | <@Consul> | Seriously, he scrolled up three or four pages in my IRC client talking about it. :-P |
00:06 | <@AnnoDomini> | Whoah. |
00:06 | <@Consul> | Probably a better education than you'll ever get in a comp-sci class. :-) |
00:08 | <@AnnoDomini> | :) |
00:11 | <@AnnoDomini> | McMartin: It's for practice purposes. I actually doubt the world is ready for another snake clone. ;) |
00:13 | <@Consul> | Maybe if it were first-person? :-P |
00:13 | <@AnnoDomini> | I think I saw a FP snake on a cellphone once. :P |
00:20 | <@Consul> | And to think I thought I was making a joke. |
00:21 | <@Consul> | You know what I never see? Second-person games. |
00:21 | <@Consul> | Where your POV sits in the head of one character, but you actually control a different one. |
00:22 | <@Consul> | You could do a whole second-person deathmatch game, where everyone is controlling a character from the POV of a different character. |
00:22 | <@AnnoDomini> | There's an RPG like that. |
00:22 | <@Consul> | Or maybe not. |
00:22 | <@AnnoDomini> | It's called "W?adcy Losu" and is a really obscure Polish PnP RPG. |
00:23 | <@Consul> | Interesting... |
00:24 | <@AnnoDomini> | The players are kinda sorta 'conscience ghost thingies' that interact with the world through eldritch powers, but are bound to a specific individual. Can't directly control the individual, unless you use a power to do so, and you really can't see anywhere too far away from him. |
00:24 | <@Consul> | Oh, that actually sounds interesting. |
00:26 | <@AnnoDomini> | The players are divided into order and chaos camps, who have divergent objectives, but must work together in many situations, because some things are only possible if several talents the specific player characters may have are brought into play at once. |
00:40 | <@AnnoDomini> | I need to start going to sleep sooner. |
00:40 | | AnnoDomini [~farkoff@Nightstar-29222.neoplus.adsl.tpnet.pl] has quit [Quit: The body is alive, but the eyes are dead.] |
01:10 | | Reiver [~reaverta@Admin.Nightstar.Net] has quit [Quit: And off I go for holidays. Merry Christmas, all!] |
01:28 | <@Vornicus> | I really should use simpler methods for some of these things. |
01:29 | | You're now known as TheWatcher[T-2] |
01:34 | | You're now known as TheWatcher[zZzZ] |
01:39 | <@Vornicus> | Or, rather, more general methods |
01:46 | | crem [~moo@Nightstar-28703.adsl.mgts.by] has quit [Ping Timeout] |
01:46 | | crem [~moo@Nightstar-28703.adsl.mgts.by] has joined #code |
03:29 | <@McMartin> | Hooray for airport wireless |
03:29 | <@Vornicus> | where are you headed? |
03:30 | <@Vornicus> | er. wait. home. christmas. duh. |
03:31 | <@McMartin> | So yeah. San Diego. |
03:32 | <@McMartin> | Also, people raiding in WoW over the airport wireless by the security checkpoing. |
03:32 | <@McMartin> | point. |
03:32 | <@Vornicus> | I prefer checkpoing. |
03:32 | | * Vornicus tries to figure out how to submit a bug report for Inform. |
03:33 | <@McMartin> | There's a form on the downloads page; one moment while I find it. |
03:34 | <@McMartin> | http://www.inform-fiction.org/I7Downloads/Documents/BugReport.txt |
03:34 | <@Vornicus> | Thank you. |
03:34 | <@McMartin> | Fill it out, mail it to Graham or David as appropriate. |
03:35 | | * Vornicus mails it to Andrew instead. |
03:35 | <@McMartin> | Er, right. Got the maintainers backwards. |
03:36 | <@Vornicus> | ...this is not a very helpful form if your problem is a display issue in the gui. |
03:37 | <@McMartin> | ... yeah, you may be better off mailing Andrew directly. |
03:37 | <@McMartin> | My last bug report involved an incorrect deduction by the type system that longcat was short. |
03:40 | <@Vornicus> | While you're here, could you try reproducing? Grab a source file that's longer than the source pane can handle, remove any trailing newlines, scroll all the way to the bottom, and see if you can see the descenders. |
03:40 | <@Vornicus> | on the bottom line. |
03:41 | <@Vornicus> | (bug reproduces if you don't see the descenders) |
03:41 | <@McMartin> | Confirmed, and it's more than just the descenders; c doesn't have a descender but it's still visibly cut off. |
03:41 | <@Vornicus> | Okay, thank you. |
03:42 | <@McMartin> | (I did this by shrinking the window) |
08:22 | | Vornicus is now known as Vornicus-Latens |
08:35 | | McMartin is now known as McM[SanDiego] |
09:16 | | You're now known as TheWatcher |
10:55 | | AnnoDomini [~farkoff@Nightstar-29359.neoplus.adsl.tpnet.pl] has joined #Code |
10:55 | | mode/#code [+o AnnoDomini] by ChanServ |
11:07 | <@AnnoDomini> | So, how does one split a program into functions? Are there some guidelines for it? |
11:47 | <@Serah> | Anything that does something you could logically repeat is a function? |
15:53 | | * Consul gets to figure out how to install Adobe AIR on Linux. Yay. |
15:54 | <@ToxicFrog> | AnnoDomini: I assume you're asking about the design/philosophy part of it, not the syntax. |
15:55 | <@ToxicFrog> | It's...hard to articulate. Serah has a good start: repetitious parts should be split into functions that are called from multiple places, rather than copy-pasted. |
15:56 | <@ToxicFrog> | And stuff that's a single logical step should be a function, but I have no hard rules for this.... |
15:57 | <@ToxicFrog> | Generally the way I do it is by writing top down; eg, main() might be something like: init(); startgame(); rungame(); cleanup(); return 0; initially, and those functions will be fleshed out (and main itself improved to accomodate stuff like actual return values) as the program ripens. |
15:58 | <@ToxicFrog> | Consul: well, how is it distributed? |
15:59 | <@Consul> | As a bin file, which is run. It was not difficult. |
15:59 | <@Consul> | It's a standard installer, actually. I hadn't seen one of those since Windows. |
15:59 | <@Consul> | Presumably it dropped the package somewhere then updated some environment vars. |
16:01 | <@ToxicFrog> | Well, it probably did the same thing a standard package file does |
16:01 | <@ToxicFrog> | Ie: dropped a bunch of files in /usr (and possibly /etc and /var and whatnot), edited some stuff in /etc if necessary, added some menu entries... |
16:01 | <@Consul> | I can't seem to install an AIR application, though. Keeps throwing error 5100, which seems undocumented. |
16:01 | <@ToxicFrog> | Except it did it by hand rather than using the system package manager. |
16:02 | <@Consul> | Yup, f*&^ing undocumented error code. |
16:02 | <@Consul> | I'm assuming I needed to install AIR as root. |
16:03 | <@Consul> | I probably have to install all AIR apps as root as well. I'll try that. |
16:03 | <@Consul> | Even though I told it to install it to my home directory. |
16:04 | <@ToxicFrog> | Depends on what it is/does. |
16:05 | <@Consul> | It also wants to install to /opt by default, which seems odd to me. |
16:09 | <@Consul> | Yeah, I keep getting an undocumented error code. |
16:09 | <@Consul> | The AIR installer is supposed to be able to ask for elevated privs if it needs them. |
16:09 | <@Consul> | But that seems to not be happening. |
16:15 | <@Consul> | I emailed the Tweetdeck dev, maybe he'll have an idea. I told him no hurry, though, being Christmas Eve and all. |
16:36 | <@Consul> | But this Adobe AIR thing does fascinate me. It'll be interesting to explore it. |
16:50 | <@AnnoDomini> | What does it change if one compiles with gcc --std=c99 rather than with g++? |
17:06 | | * AnnoDomini tries to make a function that will shut down everything. Wonders if it's wise to call it AManIsCoughingInBrazil(). ;) |
17:11 | | You're now known as TheWatcher[afk] |
17:47 | <@ToxicFrog> | AnnoDomini: g++ defaults to compiling C++. |
17:47 | <@ToxicFrog> | gcc defaults to ANSI C89. |
17:47 | <@ToxicFrog> | --std=c99 changes that to C99, which is typically what you want. |
17:51 | <@AnnoDomini> | But what's the point? |
17:56 | <@ToxicFrog> | ...C++ and C are different languages? |
17:57 | <@AnnoDomini> | Yes, I know that, but what would it change if I compiled the same code (assuming it was compatible with both) with one or the other? |
17:57 | <+Pink> | hey, I have a question |
17:58 | <@ToxicFrog> | Pink: don't ask to ask. Just ask. |
17:58 | <+Pink> | If I have a folder filled with files, is there a way to automatically give them numbered filenames by date? |
17:58 | <+Pink> | I was typing it out |
17:58 | | Pink is now known as ASCII |
17:59 | <@ToxicFrog> | AnnoDomini: oh. The semantics of some C constructs change slightly, and the ABI is completely different between them |
17:59 | <@ToxicFrog> | And C++ code needs extra decorations to link with C ibraries |
17:59 | <+ASCII> | I really don't want to manually number 2500 files |
17:59 | <@ToxicFrog> | (extern "C" {}) |
17:59 | <@ToxicFrog> | ASCII: in *nix, yes, easily. |
17:59 | <@ToxicFrog> | In windows, yes, but you'll need extra tools. |
18:00 | <+ASCII> | in windows at the moment. |
18:00 | <@AnnoDomini> | http://www.google.com/search?q=mass+file+renaming&sourceid=opera&num=0&ie=utf-8& oe=utf-8 |
18:01 | <@ToxicFrog> | Ok. Do you have a bash shell handy? |
18:01 | <@AnnoDomini> | I recall a buddy of mine wrote a program to rename pictures to be the dates they were taken on. |
18:02 | <+ASCII> | fresh windows install |
18:02 | <@AnnoDomini> | ToxicFrog: Hmm. Is there a way to pass around an entire table to and from a function? |
18:03 | <@AnnoDomini> | s/table/array |
18:04 | <@ToxicFrog> | AnnoDomini: yes, but it's done differently depending on the behaviour you want |
18:05 | <@ToxicFrog> | The typical approach is to pass the pointer, in which case the callee and caller both refer to the same array, and modifications by one are reflected by the other |
18:05 | <@ToxicFrog> | Declare the function as taking a type[] or type* (remember, arrays are pointers in C) and just pass it in. |
18:06 | <@AnnoDomini> | (Are they pointers in C++?) |
18:06 | <@ToxicFrog> | ASCII: ok. There's a bunch of pre-existing file rename tools for windows - Anno's given you a search key to start with - which may do what you want. I don't know any of these, but someone else in here might. |
18:06 | <@ToxicFrog> | I do know how to do it with bash and basic *nix tools, which are available for windows in a few ways (MSYS, Cygwin, unxutils) |
18:07 | <@ToxicFrog> | AnnoDomini: yes. |
18:07 | <@ToxicFrog> | So you might have, say, void printints(int * list, size_t size) { for (size_t i = 0; i < size; ++i) printf("%d ", list[i]); return; } |
18:08 | <@AnnoDomini> | http://www.123renamer.com/Mass-File-Renamer-Review.htm <- This seems what you want, ASCII. |
18:08 | <@AnnoDomini> | Seems easy enough. |
18:08 | <@ToxicFrog> | And then call it as, say: int ints[4] = { 1, 2, 4, 8 }; printints(ints); |
18:09 | <@ToxicFrog> | If you want to pass in a copy, things get slightly more complicated, as you need to allocate a new array and copy the data into it. |
18:09 | <@AnnoDomini> | Ah. |
18:09 | <@ToxicFrog> | But this is rarely necessary. |
18:09 | <@AnnoDomini> | Mhm. |
18:10 | <@ToxicFrog> | Also, remember that C has no array bounds checking and no array length knowledge. |
18:10 | <@ToxicFrog> | Any function that takes an array needs to have some way of telling where the end is. |
18:10 | <@AnnoDomini> | Yes, yes, I remember that. |
18:11 | <@AnnoDomini> | My first bug in this code was overwriting elements from 0 to 639 when the array was 0 to 63. >_< |
18:12 | <@ToxicFrog> | Heh |
18:37 | | You're now known as TheWatcher |
19:25 | <@AnnoDomini> | ToxicFrog: How do you do passing around multidimensional arrays? |
19:27 | <@GeekSoldier> | You'd have to pass by reference. |
19:27 | <@AnnoDomini> | Que? |
19:27 | <@ToxicFrog> | The same way. |
19:27 | <@ToxicFrog> | int ** foo or int[][] foo. |
19:28 | <@GeekSoldier> | TF's a lot quicker than I! |
19:32 | <@AnnoDomini> | http://pastie.org/346390 <- What does this mean? |
19:36 | <@GeekSoldier> | what does the offending line of code look like? |
19:36 | <@AnnoDomini> | Drawing(screen, state, MAXXD10, MAXYD10); |
19:36 | <@GeekSoldier> | is state the 2d array? |
19:36 | <@AnnoDomini> | Yep. |
19:39 | | Vornicus-Latens is now known as Vornicus |
19:42 | <@ToxicFrog> | AnnoDomini: type mismatch. You're passing it an int * [48], but the function declared takes an int **. |
19:42 | <@ToxicFrog> | This implies that I'm actually wrong about passing 2d arrays. |
19:42 | <@ToxicFrog> | It has been years since I needed to do so. |
19:43 | | * ToxicFrog does some experimentaiton |
19:44 | <@ToxicFrog> | Interesting. g++ has more informative type mismatch errors than gcc. |
19:49 | <@ToxicFrog> | Aha |
19:49 | <@ToxicFrog> | Yeah, I was wrong |
19:49 | <@ToxicFrog> | It needs to know the array width |
19:49 | <@ToxicFrog> | So: int ** foo //illegal |
19:49 | <@ToxicFrog> | int foo[][] //illegal |
19:49 | <@ToxicFrog> | int foo[][WIDTH] // legal |
19:50 | <@ToxicFrog> | int * foo[WIDTH] // illegal |
19:51 | <@ToxicFrog> | int (* foo)[WIDTH] // legal |
19:53 | <@GeekSoldier> | wow, I can't even write a competent piece of C anymore; I've been spoilt on Python for too long. |
19:53 | <@AnnoDomini> | This is problematic, since the array's dimensions are defined by a pair of const ints. |
19:54 | <@GeekSoldier> | pass the consts, like TF did. |
19:54 | <@GeekSoldier> | oh, a pair... |
19:54 | <@AnnoDomini> | Not #defined constants, actual const int thingies. |
19:55 | <@ToxicFrog> | #define or enumerize them, then |
19:56 | <@ToxicFrog> | ...although |
19:56 | <@ToxicFrog> | In my tests, const int works |
19:56 | <@ToxicFrog> | So you shouldn't need to change that at all |
19:56 | <@AnnoDomini> | I'm lost. |
19:56 | <@ToxicFrog> | const int ARRAYWIDTH = 16; |
19:57 | <@ToxicFrog> | void foo(int (*array)[ARRAYWIDTH]) { ... } |
19:57 | <@ToxicFrog> | The above is legal. |
19:57 | <@AnnoDomini> | That's a global const int? |
19:57 | <@ToxicFrog> | You can replace the first line with [[ #define ARRAYWIDTH 16 ]] or with [[ enum { ARRAYWIDTH=16 }; ]], but it's not necessary. |
19:57 | <@ToxicFrog> | Yes. |
19:57 | <@AnnoDomini> | Okay. I can work with global constants. |
19:57 | <@ToxicFrog> | Holy shit, how did I not know about alloca() before? |
19:58 | <@ToxicFrog> | But, yeah, you'll note that I haven't done anything in C that isn't completely trivial in ages. |
19:58 | <@ToxicFrog> | These days I have HLLs for that stuff. |
19:59 | <@ToxicFrog> | ...aah. I didn't know about it because it's hilariously unsafe. |
20:01 | <@ToxicFrog> | Also, as a gcc specific extension, you can write something like: |
20:01 | <@ToxicFrog> | int foo(size_t width, size_t height, int array[width][height]) |
20:05 | <@AnnoDomini> | Cool. |
20:05 | <@GeekSoldier> | This reminds me that I really should be working on getting my game working. |
20:23 | <@AnnoDomini> | POINTERS! |
20:23 | <@AnnoDomini> | NEED MORE POINTERS. :E |
20:29 | <@Vornicus> | you must construct additional pointers? |
20:29 | | * AnnoDomini laughs. |
20:30 | <@AnnoDomini> | What's the correct way of incrementing the value under a pointer? *ptr++ doesn't seem to work. |
20:31 | <@ToxicFrog> | It should. |
20:33 | <@AnnoDomini> | "*amountOfApples = *amountOfApples + 1;" works but "*amountOfApples++;" doesn't. |
20:33 | <@AnnoDomini> | I remember something about incrementation firstly returning the old value before incrementing, if done this way. |
20:37 | <@ToxicFrog> | Oh right, you need to () it |
20:37 | <@ToxicFrog> | [ben@ancilla tmp]$ cat | gcc -xc - && ./a.out |
20:38 | <@ToxicFrog> | #include <stdio.h> |
20:38 | <@ToxicFrog> | int main() { int i = 0; int * pi = &i; printf("%d ", *pi); (*pi)++; printf("%d ", *pi); return 0; } |
20:38 | <@ToxicFrog> | ^D |
20:38 | <@ToxicFrog> | 0 1 |
20:40 | <@ToxicFrog> | And yes. "Returning" isn't quite the right term, though. |
20:40 | <@ToxicFrog> | int i = 0; |
20:41 | <@ToxicFrog> | print(i++); // prints "0", i is 1 afterwards |
20:41 | <@ToxicFrog> | If instead we do print(++i), it prints "1" and i is 1 afterwards. |
20:41 | <@AnnoDomini> | Uhuh. |
20:42 | <@ToxicFrog> | Postincrement/decrement evaluates to the value before mutation; preincrement/decrement, the value afterwards. |
20:42 | <@AnnoDomini> | Man, I've decreased the size of main() by over a half by now. |
20:42 | <@ToxicFrog> | In the case of *pi++ versus (*pi)++, the former is *(pi++) - that is to say, increment the pointer, then follow it. |
21:16 | | You're now known as TheWatcher[afk] |
21:37 | <@AnnoDomini> | Man. 50 lines in main() now, from 250 earlier. |
22:28 | | You're now known as TheWatcher |
22:43 | | Vornicus is now known as Vornicus-Latens |
22:44 | <@AnnoDomini> | o_O |
22:44 | <@AnnoDomini> | Filesize is down by a factor of 4. |
23:00 | <@AnnoDomini> | http://pastie.org/346470 <- Source. http://www.sendspace.pl/file/2vnGZAgE/ <- Source, executable, bitmaps, libraries. Arrow keys steer, ENTER resets, ESCAPE quits, SPACEBAR accelerates until another key is pressed. |
23:00 | <@AnnoDomini> | SO MANY POINTERS. 400 POINTERS! |
23:00 | | * AnnoDomini wanders off for ablutions. |
23:17 | <@AnnoDomini> | I'm pretty certain I'm doing something very wrong there. |
23:39 | <@ToxicFrog> | It may be time to introduce structs~ |
23:39 | <@ToxicFrog> | Generally, when you are passing around lots and lots of state variables like that (or pointers to state variables), this is a sign that they should all be packed into one easy to carry struct. |
23:40 | <@AnnoDomini> | I see. |
23:41 | <@AnnoDomini> | Nonetheless, I feel greatly empowered to sucessfully use pointers for practical purposes for the first time in my life. :D |
23:42 | <@ToxicFrog> | Like, say, typedef struct SnakeState { int score; int size; int nrof_apples; int max_apples; int grid[MAXXD10][MAXYD10]; int snake[SNAKE_MAXBLOCKS][2]; } SnakeState; |
23:43 | <@ToxicFrog> | And the rather than passing them all around individually you just pass a SnakeState * gamestate |
23:43 | <@ToxicFrog> | And access, say, gamestate->score as needed. |
23:43 | <@AnnoDomini> | Uhuh. |
23:43 | <@ToxicFrog> | Structured data: it's not just for breakfast anymore. |
23:43 | <@ToxicFrog> | (have you done structs in C - or classes in C++ - at all?) |
23:43 | <@AnnoDomini> | This would be more efficient thas passing the actual struct, yes, since we're passing just the pointer, not the entire chunk of data? |
23:43 | <@ToxicFrog> | Yes. |
23:44 | <@ToxicFrog> | Passing in the entire struct creates a copy of it on the stack. |
23:44 | <@ToxicFrog> | This is less efficient and, furthermore, any changes made to the copy are not reflected in the original. |
23:44 | <@ToxicFrog> | In this case, you probably want the functions to be able to update the actual game state rather than just a throwaway copy of it. |
23:44 | <@AnnoDomini> | (I am familiar with the concept of a struct, I think they were introduced on a lecture that I slept through. They were never necessary to pass the exercises.) |
23:50 | <@AnnoDomini> | Structs were also in every C/C++ book I've ever read, but were never used in a fashion that suggested they were necessary or the best solution to the problem. |
--- Log closed Thu Dec 25 00:00:38 2008 |