• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=Niteshifter;27337110]Nothing happened. I did a test and it seems as if it wants to do one or the other, but not both. If I set seekg to 0 before the first while, it will do the first while and if I set it to -1, it will do the second while, but if I set it to 0 before the first while then reset it to -1 before the second while, it only does the first one.[/QUOTE] What? You should replace where you had fp.clear() with what I put. So it would be: [cpp] void Parser::advance() { /* We go through two iterations: 1. Search for l commands and pass them to the symbol table 2. Search for a and c commands and pass them to the translator */ ifstream fp(file.c_str(), ios::in); lines=0; //records the lines (used for location of syntax errors) if(fp.is_open()) { while(fp.good()) { lines++; getline(fp, cmd); if(commandType() == L_COMMAND) symbol(); } fp.seekg(0, ios::beg); // reset the get pointer to the beginning of the file fp.clear(); //clear the state flag to reset lines=0; while(fp.good()) { lines++; getline(fp, cmd); switch(commandType()) { case A_COMMAND: cout<<lines<<": A_COMMAND"<<endl; symbol(); break; case C_COMMAND: cout<<lines<<": C_COMMAND"<<endl; dest(); comp(); jump(); break; case L_COMMAND: cout<<lines<<": L_COMMAND"<<endl; break; } } fp.close(); } else {std::cout<<"Error: Unable to open file"<<std::endl; exit(2);} }[/cpp] I'm not sure whether clear and seekg have to be done in a particular order, so if one doesn't work, try the other.
That's what I did. I also switched the order of clear and seekg and still got the same thing.
I don't know what could be wrong, but here's some code I wrote that does work, maybe you can see what you're doing wrong from it: [cpp] fstream infile(fname.c_str()); // if the file failed to open, stop if (!infile) return NULL; string line; infile >> line; int numlines = 0; do numrows++; while (infile >> line); infile.clear(); infile.seekg(0, ios::beg); for (int i = 0; i < numrows; i++) { infile >> line; cout << line; } infile.close();[/cpp]
Tried switching the clear and seekg again and it worked. I probably left something before the first while which messed it up previously.
[QUOTE=neos300;27335817]So I've got a class, which is just a wrapper class for values, and I'm trying to std::sort through a vector of pointers of them. Here is my code: [code] bool Sorter(Car* a, Car* B) { return a->fitness() > b->fitness(); } vector<Car*> sortCars(vector<Car*> vec) { vector<Car*> newvec = vec; sort(newvec.begin(), newvec.end(), Sorter); return newvec; } [/code] (Yes, I'm doing genetic algorthims) And I get this error (one of the ones were you have no idea what it says) error: no matching function for call to 'sort(__gnu_cxx::__normal_iterator<Car**, std::vector<Car*, std::allocator<Car*> > >, __gnu_cxx::__normal_iterator<Car**, std::vector<Car*, std::allocator<Car*> > >, <unresolved overloaded function type>)' I've got no idea how to fix this.[/QUOTE] Why are you copying the vector inside the body, when you pass by value? It already gets copied there. Did you include the algorithm-header?
[img]http://i.imgur.com/02y0l.png[/img] How do I fix this weird lighting I get in XNA? I just exported a cube from Blender (I know nothing about Blender) with a red texture and no material. The thing is that it looks right when I use a sample spaceship model from MSDN. The drawing code is straight from a tutorial [cpp] Matrix[] transforms = new Matrix[ obj.Model.Bones.Count ]; obj.Model.CopyAbsoluteBoneTransformsTo( transforms ); foreach ( ModelMesh mesh in obj.Model.Meshes ) { foreach ( BasicEffect effect in mesh.Effects ) { effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; effect.World = transforms[ mesh.ParentBone.Index ] * Matrix.CreateRotationY( obj.Yaw ) * Matrix.CreateTranslation( obj.Position ); effect.View = gameCamera.ViewMatrix; effect.Projection = gameCamera.ProjectionMatrix; } mesh.Draw(); } [/cpp]
I'm trying to get a array of structs set up within a class, however I can only determine it's size inside a function, so I must create it inside that function. Is there a way to make it be used outside it's scope?
If I understand your problem, the simplest way is just to use a pointer to it.
[QUOTE=shill le 2nd;27361808]If I understand your problem, the simplest way is just to use a pointer to it.[/QUOTE] Already tried and, as expected, I got characters flooding the screen when trying to print the contents by iterating through the array after the function finished.
Would you mind sharing some of the related code?
[cpp] class Parser { struct commandList //struct { string command1; string command2; }; commandList* cmds; //struct pointer }; void Parser::advance() { /* We go through two iterations: 1. Search for l commands and pass them to the symbol table 2. Search for a and c commands and pass them to the translator */ ifstream fp(file.c_str(), ios::in); lines=0; //records the lines (used for location of syntax errors) aclines=0; //records the number of a and c command lines if(fp.is_open()) { while(fp.good()) { lines++; getline(fp, cmd); if(commandType() == L_COMMAND) symbol(); else aclines++; } commandList commands[aclines]; //struct array that's within the function cmds = commands; //make the pointer point to the struct array //The rest just reiterates through the file again and places the parsed substrings into the struct array via the pointer. else {std::cout<<"Error: Unable to open file"<<std::endl; exit(2);} } void Parser::printParseList() { //iterates through the parsed list via the pointer //as expected, will fail while not called during the main parsing function for(int i=0;i<=aclines;i++) { cout<<i<<": "<<cmds[i].command1<<", "<<cmds[i].command2<<endl; } } int main(int argc, char *argv[]) { Parser parse(argv[1]); parse.advance(); parse.printParseList(); return 0; } [/cpp]
You need to allocate on the heap (look up the operators new[] and delete[]).
Could anyone please link some pages on making light which will be obstructed by objects? Preferably in C# (XNA), but if it has some solid math I could probably translate it across. I've been searching but all I can find with google (and my limited games programming vocabulary) is sprite blend addition methods where each "light" is pre-defined. Thanks in advance for anyone who looks.
So I was wondering what's the easiest way to cause a BSOD in assembly. I'd really appreciate if anyone could tell me.
[QUOTE=TerabyteS;27367102]So I was wondering what's the easiest way to cause a BSOD in assembly. I'd really appreciate if anyone could tell me.[/QUOTE] :cop: Anyway, in standard C, how do I convert an integer between 0-9 to a single char?
I'm in the process of creating a load bar which shows which models have been loaded into memory. I have most of it coded but I don't know how to check which models have been loaded, i have a loaded boolean which is turned true once the load method has finished but doing a if statement but each object in my game will be terrible. I was considering creating an array and adding in all objects in the scene and then doing a for look to loop through and check which ones have been loaded but this only works if all my models are based off the object class. Some of my classes are subclasses of the object class because they needed extra functionality.
[QUOTE=ProWaffle;27367263]:cop: Anyway, in standard C, how do I convert an integer between 0-9 to a single char?[/QUOTE] Do you mean convert an int to it's char representation, so that 65 = 'A', 66 = 'B', etc? If so, just cast the int to a char. If you mean, to convert an int to a letter representing that int, such that 1 = '1', 2 = '2', etc. then there are many ways of doing it, but two of the main ones are here: [cpp] // with this way if the number is higher than 9 you will get undefined behaviour, possibly a seg fault char[] numbers = "0123456789"; int num = 5; // random number char c = numbers[num]; [/cpp] And c will contain the letter value. Here is another way: [cpp] // with this method, if the number is higher than 9 it will simply turn into a letter int num = 5; char c = (char)(num + 48); // 48 because the ascii value of '0' is 48 [/cpp]
Or char c = num + '0'; Not sure if it needs to be cast explicitly.
[QUOTE=Jimmylaw;27367526]I'm in the process of creating a load bar which shows which models have been loaded into memory. I have most of it coded but I don't know how to check which models have been loaded, i have a loaded boolean which is turned true once the load method has finished but doing a if statement but each object in my game will be terrible. I was considering creating an array and adding in all objects in the scene and then doing a for look to loop through and check which ones have been loaded but this only works if all my models are based off the object class. Some of my classes are subclasses of the object class because they needed extra functionality.[/QUOTE] Deploy a callback to which the progressbar can be subscribed.
Is anyone else having trouble with SFML2 render windows? I keep getting undefined reference errors
[QUOTE=Richy19;27370351]Is anyone else having trouble with SFML2 render windows? I keep getting undefined reference errors[/QUOTE] Happened to me a lot when I was messing with static classes (Was trying to have a static Content class, didn't ended well.)
[QUOTE=PiXeN;27370398]Happened to me a lot when I was messing with static classes (Was trying to have a static Content class, didn't ended well.)[/QUOTE] Now that you mention it, i just tried dynamic linking and it works fine, so there must be some problem with static linking
[QUOTE=TerabyteS;27367102]So I was wondering what's the easiest way to cause a BSOD in assembly. I'd really appreciate if anyone could tell me.[/QUOTE] Start writing to random addresses? It's hard [i]not[/i] to cause a BSOD in assembly.
The real question is why you'd WANT to cause a BSoD intentionally
I have a couple of .png files in a directory. How would a regexp that only searches for .png files but avoids those starting with "refl_" look like?
[QUOTE=neos300;27335817]So I've got a class, which is just a wrapper class for values, and I'm trying to std::sort through a vector of pointers of them. Here is my code: [code] bool Sorter(Car* a, Car* B) { return a->fitness() > b->fitness(); } vector<Car*> sortCars(vector<Car*> vec) { vector<Car*> newvec = vec; sort(newvec.begin(), newvec.end(), Sorter); return newvec; } [/code] (Yes, I'm doing genetic algorthims) And I get this error (one of the ones were you have no idea what it says) error: no matching function for call to 'sort(__gnu_cxx::__normal_iterator<Car**, std::vector<Car*, std::allocator<Car*> > >, __gnu_cxx::__normal_iterator<Car**, std::vector<Car*, std::allocator<Car*> > >, <unresolved overloaded function type>)' I've got no idea how to fix this.[/QUOTE] I didn't see anyone respond to this, so here's my take - it looks like you have multiple functions called "Sorter". [editline]12th January 2011[/editline] [QUOTE=Armandur;27371567]I have a couple of .png files in a directory. How would a regexp that only searches for .png files but avoids those starting with "refl_" look like?[/QUOTE] [b]Edit:[/b] [code]^(?!refl_).*\.png$[/code]
[QUOTE=Metroid48;27371609] [b]Edit:[/b] [code]^(?!refl_).*\.png$[/code][/QUOTE] Thanks, I really appreciate it!
Is there any way to stop VAX from putting spaces between the parentheses and the function arguments?
[QUOTE=ZeekyHBomb;27365520]You need to allocate on the heap (look up the operators new[] and delete[]).[/QUOTE] I remembered about those right after I shut the computer off and thought "Wow, I'm an idiot...".
If you haven't said that to yourself at least five times, you're not a real programmer :v: (Stack allocation in the middle of a block can do some really weird things with memory, since it's kind of a kludge. I've had so many bugs involving that kind of allocation, where printing some debug information would actually change the behaviour of the bug since it changed the alignment of the memory.) EDIT: Oh, you weren't just allocating stack memory in the middle of a block, you were also allocating an array with a runtime size. That's double the kludge. The compiled assembly code for that makes me cringe.
Sorry, you need to Log In to post a reply to this thread.