Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
fret logic
Mar 8, 2005
roffle

HB posted:

Manipulating a character display the way NetHack does isn't really the same as "lines or pixels".

Yeah I know that much, I just haven't found the basic idea behind the graphics in that game, graphics that for some odd reason I really enjoy.[/QUOTE]

HB posted:

The best way to quickly make something appear on the screen is probably OpenGL with GLUT. A program that opens a window and draws some simple shapes can come in under 30 lines. Once you're comfortable with that, you can leave GLUT behind to do your own context setup, and you're off and running.

Oh I never realized I'd have to use something like OpenGL. Haha I thought it'd be like QBASIC and have a command or two for drawing to the screen, I'm retarded. Thanks though, I'll look that up!

edit: I checked out some of the sample source code, thanks again this is exactly what I was looking for :)

fret logic fucked around with this message at 01:52 on Apr 1, 2008

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

fret logic posted:

Yeah I know that much, I just haven't found the basic idea behind the graphics in that game, graphics that for some odd reason I really enjoy.
Nethack uses CURSES for terminal text graphics, in this case, probably ncurses. (named for the difficulty of writing such a library).

If you want to examine a simpler game using ncurses, read the source code for bombardier.

If you want something shinier, SDL is probably a better choice than GLUT.

ColdPie
Jun 9, 2006

Scaevolus posted:

If you want something shinier, SDL is probably a better choice than GLUT.

I was also going to suggest SDL. It handles everything you need for media applications in a cross-platform manner. It has methods for handling input, audio, video, and even networking. All of its facilities are very low-level, but there are libraries that abstract it up further, as well as the ability to just use OpenGL. I personally use SDL with OpenGL for video and SDL_mixer for audio and handle input on my own. My games compile in any of the three major operating systems with no modifications and only one #if, so that's awful nice.

TurtleBoy
Nov 7, 2002
I am looking into programming a game and I had a question which google is proving useless to answer, possibly because I am asking it the wrong questions.

The art assets for this project I want to store in such a way that only the program can retrieve them(the artists are VERY protective of their work). By this I mean how most games you play don't have big folders of jpgs for everything, they have some sort of data file that is read when loading a level.

What is the best way to implement this?

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

TurtleBoy posted:

I am looking into programming a game and I had a question which google is proving useless to answer, possibly because I am asking it the wrong questions.

The art assets for this project I want to store in such a way that only the program can retrieve them(the artists are VERY protective of their work). By this I mean how most games you play don't have big folders of jpgs for everything, they have some sort of data file that is read when loading a level.

What is the best way to implement this?

Point out to the artists that no matter how much work you spend hiding the art, people will still be able to take screenshots of it.

haveblue
Aug 15, 2005



Toilet Rascal

TurtleBoy posted:

I am looking into programming a game and I had a question which google is proving useless to answer, possibly because I am asking it the wrong questions.

The art assets for this project I want to store in such a way that only the program can retrieve them(the artists are VERY protective of their work). By this I mean how most games you play don't have big folders of jpgs for everything, they have some sort of data file that is read when loading a level.

What is the best way to implement this?

The best way to implement it is zlib; the data files are just compressed directory trees.

You won't be able to stop people from taking the art if they really want it, so you may as well save yourself some work.

tef
May 30, 2004

-> some l-system crap ->

TurtleBoy posted:

What is the best way to implement this?

Do not distribute your game.

tyrelhill
Jul 30, 2006

tef posted:

Do not distribute your game.

Haha, pretty much. If someone wants the assets in your game, they're going to get it.

TurtleBoy
Nov 7, 2002

HB posted:

The best way to implement it is zlib; the data files are just compressed directory trees.

You won't be able to stop people from taking the art if they really want it, so you may as well save yourself some work.

this sounds like what I am looking for.

We only really want to keep idiots at bay. Of course anyone can screenshot it but we just want the source files somewhat hidden from...
"Hur! look at all jpegs thats just what I needed to make my own game! I can't wait to tighten up those graphics on level 3!"

Scaevolus
Apr 16, 2007

TurtleBoy posted:

this sounds like what I am looking for.
Zlib is what Quake 3 does, "assets0.pk3" is just a zip file containing a bunch of data. If they don't think that's enough, try just having the archives password-protected with the password hardcoded in the source code (not effective at all, but the artists don't need to know that).

Scaevolus fucked around with this message at 05:07 on Apr 2, 2008

Soldat
Jan 22, 2008
my name is soldat and I get respect, your cash and your jewelery is what I expect
In c++, is there anyone to code this:

Switch statement.. {
.
.
.

}
if (default case in above switch statement was reached)

return false;

?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Is there something wrong with doing this?
code:
switch(foo)
{
case 1:
    // blah
    break;
default:
    return false;
}

casey
Dec 12, 2002

Soldat posted:

In c++, is there anyone to code this:

Switch statement.. {
.
.
.

}
if (default case in above switch statement was reached)

return false;

?

code:
switch (int)
{
   case 0: do something; break;
   .
   .
   .
   default: return 0;
}
googling "switch c++" comes with numerous resources.

Soldat
Jan 22, 2008
my name is soldat and I get respect, your cash and your jewelery is what I expect
Thank you for the quick response, it's what I needed, although I feel sort of stupid for not thinking of it...must be stressed.

Thanks again

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Is there a way to truncate a stream at a certain offset? That is, suppose I have a file open and want to delete a line of text and shorten a file by so many bytes. I can shift the subsequent lines of text with no problem, but there'll be extra space at the end, which kind of defeats the purpose in this case.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Avenging Dentist posted:

Is there a way to truncate a stream at a certain offset? That is, suppose I have a file open and want to delete a line of text and shorten a file by so many bytes. I can shift the subsequent lines of text with no problem, but there'll be extra space at the end, which kind of defeats the purpose in this case.

The ftruncate(2) system call is probably what you want.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
It's pretty much essential that this work with stream objects, since the only guarantee I have is that the stream is open for writing, and supports random access. Nine times out of ten, it'll be a file, but it's entirely possible that the file will be run through a Boost.Iostreams filter like gzip.

xgalaxy
Jan 27, 2004
i write code
Can anyone recommend any good books on compiler / interpreter / language theory, lex and yacc, etc?

Thanks.

haveblue
Aug 15, 2005



Toilet Rascal

xgalaxy posted:

Can anyone recommend any good books on compiler / interpreter / language theory, lex and yacc, etc?

Thanks.

Compilers: Principles, Techniques, and Tools, aka the Dragon Book, is the gold standard.

csammis
Aug 26, 2003

Mental Institution
Aside from the Dragon book, I would also recommend Modern Compiler Implementation in Java by Appel (or ML or whatever the other one is)

Morgen
Dec 1, 2007
Neuroscientician
I am trying to write a program in C that will read a text file as input and store the numbers in several arrays. I have code that will read the first line in the file and store it into the array 'L', but I can't find anything about reading in more than one line. I want to use fscanf instead of get so I don't have to go through the hassle of conversions, since I already know what the format of the file will be, and I'm using spaces and newlines as delimiters. Does anyone know how to read separate lines into different arrays using fscanf?

code:
int main()
{
	FILE *fp;
	int n;
	char c;
	float *Lp, L[4], R[5];
        int N[4], Nm;
	int i;

	Lp = L;


	fp = fopen("attributes.txt", "r");


	for (i=0; i< 4; i++)
	{
		fscanf(fp, "%f", Lp++);
	}
	fclose(fp);
	for(i=0; i<4; i++)
        {
               printf("%f ", L[i]);
        }
}
attributes.txt
code:
0.40   0.20   0.30   0.60 
0.00030000   0.00020000   0.00010000   0.00010000   0.00006366 
40 20 30 60 
10 

Morgen fucked around with this message at 16:44 on Apr 6, 2008

Scaevolus
Apr 16, 2007

Morgen posted:

attributes.txt
code:
0.40   0.20   0.30   0.60 
0.00030000   0.00020000   0.00010000   0.00010000   0.00006366 
40 20 30 60 
10 
If that's all your attributes.txt is, then try:
code:
int main()
{
	FILE *fp;
	int n;
	char c;
	float L[4], R[5];
        int N[4], Nm;
	int i;

	fp = fopen("attributes.txt", "r");

	fscanf(fp, "%f %f %f %f %f %f %f %f %f %d %d %d %d %d", 
		&L[0], &L[1], &L[2], &L[3],
		&R[0], &R[1], &R[2], &R[3], &R[4],
		&N[0], &N[1], &N[2], &N[3],
		&Nm);

	fclose(fp);

        printf("%.2f %.2f %.2f %.2f\n%.8f %.8f %.8f %.8f %.8f\n%d %d %d %d\n%d\n", 
		L[0], L[1], L[2], L[3],
		R[0], R[1], R[2], R[3], R[4],
		N[0], N[1], N[2], N[3],
		Nm);

        return 0;
}
You can split those fscanf and printf calls into multiple parts, but I think this is clear enough.

&L[2] is the same thing as L+2, but I think the first is clearer.

Scaevolus fucked around with this message at 19:23 on Apr 6, 2008

Morgen
Dec 1, 2007
Neuroscientician

Scaevolus posted:

If that's all your attributes.txt is, then try...

You can split those fscanf and printf calls into multiple parts, but I think this is clear enough.

&L[2] is the same thing as L+2, but I think the first is clearer.

I can't seem to make it work, it gives me a runtime error. Am I missing something important?

I didn't realize that fscanf would treat spaces and newlines the same and continue putting things into the array until it reached the end of the file until I saw your code though. Thank you! As a (hopefully) temporary solution, I've just saved all of the numbers into a temp array, and then copied the relevant parts to the right arrays from it. It still seems rather inelegant though, and I wish I could make your solution work.

Scaevolus
Apr 16, 2007

Morgen posted:

I can't seem to make it work, it gives me a runtime error. Am I missing something important?

Well, I did omit "#include <stdio.h>" from the first line.

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it
Can anyone see anything wrong with these function declarations? I keep getting "previous declaration of 'readFlights' was here" and "previous declaration of 'print_flight' was here" when I try and compile it.

code:
void readAirports(FILE *, airport airports[100]);
void readRoutes(FILE *, route routes[500]);
void readFlights(FILE *, flight flights[3000], int count[3000]);
void print_flight(flight flights[3000], int count[3000], route routes[500], airport airports[100]);
void printairport(route routes[500], airport airports[100]);
What do those errors even mean?

haveblue
Aug 15, 2005



Toilet Rascal
Is your header protected by #ifdefs? That error means that the compiler passed over the same declarations twice.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Captain Frigate posted:

Can anyone see anything wrong with these function declarations? I keep getting "previous declaration of 'readFlights' was here" and "previous declaration of 'print_flight' was here" when I try and compile it.

code:
void readAirports(FILE *, airport airports[100]);
void readRoutes(FILE *, route routes[500]);
void readFlights(FILE *, flight flights[3000], int count[3000]);
void print_flight(flight flights[3000], int count[3000], route routes[500], airport airports[100]);
void printairport(route routes[500], airport airports[100]);
What do those errors even mean?

It means you're including declarations of those functions more than once, and the different declarations don't match. The most obvious way is if you accidentally have an older version in a different header file or something. I see you use a lot of custom types (airport, route, etc.) so, assuming that's in a header file, it could be you're including the header file twice and redefining one of those types in between.

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it
well, that wasn't the whole thing. The whole one is:
code:
typedef struct airport_
{
  char code[3];
  char location[40];
}airport;

typedef struct route__
{
  int routeID;
  char origin[3];
  char dest[3];
}route;

typedef struct flight_
{
  int flightnumber;
  int routeID;
  int departhr;
  int departmin;
  char departap;
  int arrhr;
  int arrmin;
  char arrap;
  char freq[8];
}flight;

void readAirports(FILE *, airport airports[100]);
void readRoutes(FILE *, route routes[500]);
void readFlights(FILE *, flight flights[3000], int count[3000]);
void print_flight(flight flights[3000], int count[3000], route routes[500], airport airports[100]);
void printairport(route routes[500], airport airports[100]);
And that's the only header file that I'm including in everything. I am writing the main function and the other functions in two separate modules and #including this in both of them. Do I not need it for the function module?

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Does your header include #ifndef guards?

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

JoeNotCharles posted:

Does your header include #ifndef guards?

No. Could that be what is causing the problem?

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Captain Frigate posted:

No. Could that be what is causing the problem?

No, I was just wondering. :rolleyes:

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

JoeNotCharles posted:

No, I was just wondering. :rolleyes:

I had no idea what that was before you brought it up and I searched for it. Some people don't already know a language back and forth.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.

Captain Frigate posted:

I had no idea what that was before you brought it up and I searched for it. Some people don't already know a language back and forth.

The point is, why would I have asked (not to mention I'm the second person to bring it up) if it wouldn't be causing the problem?

Captain Frigate
Apr 30, 2007

you cant have it, you dont have nuff teef to chew it

JoeNotCharles posted:

The point is, why would I have asked (not to mention I'm the second person to bring it up) if it wouldn't be causing the problem?

I have no idea. As far as I know, you might have assumed that they were in there and that the problem was that they were interacting with something else in a strange way.

haveblue
Aug 15, 2005



Toilet Rascal
...this is the thread for answering programming questions. Is that process really so complicated?

Yes, it's almost certainly the lack of that that is causing the problem. There's a point in your code where airport.h can be reached through two different include statements (one to airport.h itself, one to another file that also includes airport.h), so the compiler thinks it's been defined twice.

haveblue fucked around with this message at 05:19 on Apr 7, 2008

Llama Patrol
Mar 11, 2007

JoeNotCharles posted:

The point is, why would I have asked (not to mention I'm the second person to bring it up) if it wouldn't be causing the problem?

It would only cause a problem if there is another header file, which he's already said there is not. Unless he's doing something weird like including C files.

6174
Dec 4, 2004

Llama Patrol posted:

It would only cause a problem if there is another header file, which he's already said there is not. Unless he's doing something weird like including C files.

No, only one header file is needed for the problem JoeNotCharles is diagnosing. If the file Captain Frigate mentioned is called header.h and is included by both file1.cpp and file2.cpp, it is enough to cause a problem. This problem is fixed exactly as JoeNotCharles said, with ifndef guards.

Llama Patrol
Mar 11, 2007

6174 posted:

No, only one header file is needed for the problem JoeNotCharles is diagnosing. If the file Captain Frigate mentioned is called header.h and is included by both file1.cpp and file2.cpp, it is enough to cause a problem. This problem is fixed exactly as JoeNotCharles said, with ifndef guards.

You're definitely wrong in C. I'm a C programmer primarily and don't do much in C++, but I'm pretty certain it's the same. Two files, file1.c and file2.c, can include the same header file without a problem, because both C files get compiled independently of each other. They have no idea about each other at compile time, so there's no conflict.

When it's time to link, again there's no problem, because the contents of the header file are "hidden" in file1.o and file2.o.

6174
Dec 4, 2004

Llama Patrol posted:

You're definitely wrong in C. I'm a C programmer primarily and don't do much in C++, but I'm pretty certain it's the same. Two files, file1.c and file2.c, can include the same header file without a problem, because both C files get compiled independently of each other. They have no idea about each other at compile time, so there's no conflict.

When it's time to link, again there's no problem, because the contents of the header file are "hidden" in file1.o and file2.o.

I just checked it and you're right, you need two headers and one header to include the other header. I know this kind of poo poo happens in Fortran as that is what I spent several hours last week fixing exactly this problem, I must have gotten confused.

Adbot
ADBOT LOVES YOU

McGravin
Aug 25, 2004

Tantum via caeli per ferro incendioque est.
I would like some help figuring out how to use ncurses or something similar under Visual C++. I am a bit new to both C++ and MSVC++, but I would like to do some text-based GUIs. With some google searching, I have at least figured out that people have been able to use pdcurses in VC++, but I haven't found any clear how-to.

Can someone give me a link to a how-to for installing ncurses or pdcurses for use in VC++ 2005 EE, or else give me a clear step-by-step?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply