• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=esalaka;38105042]I think the point was he wants to recognise certain frequencies, which would be done via Fourier transforms But I never could figure out how the hell those work[/QUOTE] It's basically a vector in the complex number plane. You rotate it with the target frequency and set the length to the current amplitude. (The e^-i*something part describes the rotation.) Then you add these vectors for each sample. If the frequencies match, the long vectors point in the same direction and the length of the sum is large. If there's a mismatch the summands cancel each other out and the result is closer to 0. The direction of the result vector is the phase shift of the signal compared to the starting point of the algorithm. This could really use one of these informative GIFs. [editline]edit[/editline] It's also possible to rotate the result vector with each step. The transform is constant in that case, so it's possible to do a matrix transform instead of calculating the sin and cos each time for the current angle.
Understanding the theory doesn't mean I can do it and that's the issue exactly :v: I guess I should try some transforms by hand to figure out how it works and then try implementing some FFT, maybe.
-snip-
Wanting to make some sort of 2D tile system, similar to terraria (Don't worry, I'm not making a survival game or a mining game). I am not sure how to store the tiles though if that makes any sense. I was going to make a 2D array of Tile objects ( x and y ), but I am not sure if there is a better way to do something like this.
A 2D Array is fine.
[QUOTE=Staneh;38107472]A 2D Array is fine.[/QUOTE] Alright. My next and last question is how I should draw this... Just loop through the array and increase the draw position by one tile every time?
[QUOTE=Duskling;38107506]Alright. My next and last question is how I should draw this... Just loop through the array and increase the draw position by one tile every time?[/QUOTE] [CPP] struct Tile { ... }; void drawTile(long x, long y, Tile tile); //The implementation is up to you struct Map { Tile** tiles; long xdim; long ydim; }; void drawMap(Map* map) { for(unsigned long i = 0; i < map->xdim; i++) { for(unsigned long j = 0; j < map->ydim; j++) { drawTile(i,j,map->tiles[i][j]); } } } [/CPP]
[QUOTE=Eudoxia;38107546][CPP] struct Tile { ... }; void drawTile(long x, long y, Tile tile); struct Map { Tile** tiles; long xdim; long ydim; }; void drawMap(Map* map) { for(unsigned long i = 0; i < map->xdim; i++) { for(unsigned long j = 0; j < map->ydim; j++) { drawTile(i,j,map->tiles[i][j]); } } } [/CPP][/QUOTE] I'm actually using Java, as I should have said. Thanks for this though, I can translate it over rather easily.
[QUOTE=Duskling;38107420]Wanting to make some sort of 2D tile system, similar to terraria (Don't worry, I'm not making a survival game or a mining game). I am not sure how to store the tiles though if that makes any sense. I was going to make a 2D array of Tile objects ( x and y ), but I am not sure if there is a better way to do something like this.[/QUOTE] A 2d array of tile objects is the most common way of doing it and is the simplest. Implement it that way now, and if in the future you find it too limiting (for something like this I doubt you'd ever need to complicate it, but hey, you never know) you can change the system to accommodate your new needs. For game programming, you should use this philosophy for pretty much everything. Users don't mind waiting a few seconds at loading screens, and you've got a whole 16ms per frame (assuming you want a constant 60fps) for everything. It might not be the best code, but it gets the job done. When the game slows down, profile the code and see what's the slowest part. Trust me, you might think that you know exactly what's slowing the game down, but it's almost always something else. Use a profiler. And as a general habit, think less about the "best way" to do something and more about the quickest way to get it done, so that you can get a working prototype out quicker and spend your time working on the game itself and not the technology behind it. [editline]19th October 2012[/editline] tl;dr game programming is unlike most programming - quick and dirty is fine because it means you can get to the core of the game programming a lot quicker.
My C sense is telling me to suggest making an 1D array[x*y] because it's much less complicated but C# other modern languages wrap that sort of stuff nicely, don't they
[QUOTE=esalaka;38107636]My C sense is telling me to suggest making an 1D array[x*y] because it's much less complicated but C# other modern languages wrap that sort of stuff nicely, don't they[/QUOTE] I think that would make resizing the map pretty hard. An array of arrays/pointer to pointer can be resized along the x dimension by reallocating/resizing every array in the array, and in the y dimension by reallocating the reallocating/resizing array.
Thanks for the help guys :)
[QUOTE=robmaister12;38107581]A 2d array of tile objects is the most common way of doing it and is the simplest. Implement it that way now, and if in the future you find it too limiting (for something like this I doubt you'd ever need to complicate it, but hey, you never know) you can change the system to accommodate your new needs. For game programming, you should use this philosophy for pretty much everything. Users don't mind waiting a few seconds at loading screens, and you've got a whole 16ms per frame (assuming you want a constant 60fps) for everything. It might not be the best code, but it gets the job done. When the game slows down, profile the code and see what's the slowest part. Trust me, you might think that you know exactly what's slowing the game down, but it's almost always something else. Use a profiler. And as a general habit, think less about the "best way" to do something and more about the quickest way to get it done, so that you can get a working prototype out quicker and spend your time working on the game itself and not the technology behind it. [editline]19th October 2012[/editline] tl;dr game programming is unlike most programming - quick and dirty is fine because it means you can get to the core of the game programming a lot quicker.[/QUOTE] All programming is like that. I spend way too much time thinking about the best data structure for something and then I never get anything done.
I saw a great presentation mirrored on a website somewhere. He was talking about how programmers think about optimizing calculations and space, but not about optimizing the time they waste analyzing, programming, debugging. I'll see if I can find it.
[QUOTE=DoctorSalt;38108643]I saw a great presentation mirrored on a website somewhere. He was talking about how programmers think about optimizing calculations and space, but not about optimizing the time they waste analyzing, programming, debugging. I'll see if I can find it.[/QUOTE] Would you happen to be thinking about this one by Jon Blow? [url]http://the-witness.net/news/2011/06/how-to-program-independent-games/[/url]
Why yes, it is, thanks
I heard that in XNA, doing KeyboardState.GetPressedKeys() is not recommended since it allocates memory each time and i plan on doing it all the time. Is this true?
Can anyone with C experience give me a hand? I need to read a line of text from a file, handed to the program as: prog < text.txt So reading from stdio. I have the following: [cpp] char line[ARRAYSIZE]; gets (line); while(line != EOF) { //Prototype for ProcessLine is: void ProcessLine(char *line); ProcessLine(&line[0]); totalLines++; gets (line); } [/cpp] which gives me this warning: [QUOTE]./Assignment1.c:20:13: warning: comparison between pointer and integer [enabled by default][/QUOTE]
What does it mean when function parameters are just int(or other variable type): [CODE]void foo(int)[/CODE] What does that exactly mean. How do I access the parameters value ? All my function have names for variables [CODE]void foo(int x)[/CODE] This is C++
The function's parameter is just an integer regardless. It's left unnamed in the prototype because it doesn't matter. The actual function definition names the parameter.
[QUOTE=Richy19;38113895]Can anyone with C experience give me a hand? I need to read a line of text from a file, handed to the program as: prog < text.txt So reading from stdio. I have the following: [cpp] char line[ARRAYSIZE]; gets (line); while(line != EOF) { //Prototype for ProcessLine is: void ProcessLine(char *line); ProcessLine(&line[0]); totalLines++; gets (line); } [/cpp] which gives me this warning:[/QUOTE] Cause line is a pointer to your string, and EOF is an integer. To check for end of File do something like: [cpp] while (!feof(stdin)) { } [/cpp]
[QUOTE=Electroholic;38119826]Cause line is a pointer to your string, and EOF is an integer. To check for end of File do something like: [cpp] while (!feof(stdin)) { } [/cpp][/QUOTE] Following this and what I was suggested in WAYWO I now have this main: [cpp] int main() { char line[ARRAYSIZE]; do { if(!feof(stdin)) break; //Prototype for ProcessLine is: void ProcessLine(const char line[]); //But doesnt do anything yet ProcessLine(line); totalLines++; fgets(line, ARRAYSIZE, stdin); }while (!feof(stdin)); //Print stuff return 0; } [/cpp] And totalLines pronts out 0 yet if I remove the if statement inside the do while loop the program just keeps on running
[QUOTE=Richy19;38119915]Following this and what I was suggested in WAYWO I now have this main: int main(){ char line[ARRAYSIZE]; do { if(!feof(stdin)) break; //Prototype for ProcessLine is: void ProcessLine(const char line[]); //But doesnt do anything yet ProcessLine(line); totalLines++; fgets(line, ARRAYSIZE, stdin); }while (!feof(stdin)); //Print stuff return 0;} And totalLines pronts out 0 yet if I remove the if statement inside the do while loop the program just keeps on running[/QUOTE] I would use something like this [cpp] int main() { char line[ARRAYSIZE]; while (!feof(stdin)); { fgets(line, ARRAYSIZE, stdin); //Prototype for ProcessLine is: void ProcessLine(const char line[]); //But doesnt do anything yet ProcessLine(line); totalLines++; } //Print stuff return 0; } [/cpp]
[QUOTE=Electroholic;38119945]I would use something like this [cpp] int main() { char line[ARRAYSIZE]; while (!feof(stdin)); { fgets(line, ARRAYSIZE, stdin); //Prototype for ProcessLine is: void ProcessLine(const char line[]); //But doesnt do anything yet ProcessLine(line); totalLines++; } //Print stuff return 0; } [/cpp][/QUOTE] I tried that out as well but no changes, put in some debug info: [cpp] int main() { char line[ARRAYSIZE]; int i = 0; while (!feof(stdin)); { i++; printf("%d", i); fgets(line, ARRAYSIZE, stdin); ProcessLine(line); totalLines++; } } [/cpp] And nothing gets printed out [editline]21st October 2012[/editline] Ok changd it to: [cpp] char line[ARRAYSIZE]; int i = 0; while (fgets(line,ARRAYSIZE,stdin) != NULL); { i++; printf("%d", i); ProcessLine(line); totalLines++; } [/cpp] and 1 gets printed out as the amount of lines, yet the sample file im piping in has 34...
[QUOTE=Richy19;38120089]I tried that out as well but no changes, put in some debug info: [cpp] int main() { char line[ARRAYSIZE]; int i = 0; while (!feof(stdin)); { i++; printf("%d", i); fgets(line, ARRAYSIZE, stdin); ProcessLine(line); totalLines++; } } [/cpp] And nothing gets printed out [editline]21st October 2012[/editline] Ok changd it to: [cpp] char line[ARRAYSIZE]; int i = 0; while (fgets(line,ARRAYSIZE,stdin) != NULL); { i++; printf("%d", i); ProcessLine(line); totalLines++; } [/cpp] and 1 gets printed out as the amount of lines, yet the sample file im piping in has 34...[/QUOTE] You might have to call fgets before feof for it to clear the flag. Try this [cpp] int main() { char line[ARRAYSIZE]; int i = 0; fgets(line, ARRAYSIZE, stdin); while (!feof(stdin)); { i++; printf("%d", i); fgets(line, ARRAYSIZE, stdin); ProcessLine(line); totalLines++; } } [/cpp]
[QUOTE=Electroholic;38120225]You might have to call fgets before feof for it to clear the flag. Try this [cpp] int main() { char line[ARRAYSIZE]; int i = 0; fgets(line, ARRAYSIZE, stdin); while (!feof(stdin)); { i++; printf("%d", i); fgets(line, ARRAYSIZE, stdin); ProcessLine(line); totalLines++; } } [/cpp][/QUOTE] It doesnt print anything. I have Put all the code into a pastebin including the code for the sample file at the bottom, maybe its my pc or something, or maybe you can see the problem easier [url]http://pastebin.com/KWwDujhP[/url]
[QUOTE=demoTron;38116556]What does it mean when function parameters are just int(or other variable type): [CODE]void foo(int)[/CODE] What does that exactly mean. How do I access the parameters value ? All my function have names for variables [CODE]void foo(int x)[/CODE] This is C++[/QUOTE] You can also ignore paramters (without triggering warnings in strict mode) like that, which is only remotely useful when you're conforming to an interface with optional arguments. For instance: [cpp]typedef std::function<void(int,int,int,int)> callback_t; void mycback(int x, int y, int, int) { // I only care about x and y }[/cpp]
I need help getting started with Ruby. I don't have a clue on how to install it and make it run. (I'm not a total newbie I just am really confused.) Also some tutorials on getting started would be nice!
[QUOTE=itsthejayden;38123907]I need help getting started with Ruby. I don't have a clue on how to install it and make it run. (I'm not a total newbie I just am really confused.) Also some tutorials on getting started would be nice![/QUOTE] Have a search for "I love Ruby 2012" and read it. It'll help you out with some of the more common items in Ruby.
[QUOTE=T3hGamerDK;38124039]Have a search for "I love Ruby 2012" and read it. It'll help you out with some of the more common items in Ruby.[/QUOTE] Not to be rude but that looks like it was written by telemarketers. any thing else?
Sorry, you need to Log In to post a reply to this thread.