Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 338 339 [340] 341 342 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 902782 times)

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5085 on: October 03, 2013, 02:58:19 pm »

Why would you want to split it into two loops though?
It's multithreaded. It was quite consistently crashing before I pulled the drawing of a surface and creation of a texture out of the secondary thread and into the main one. Seems quite a bit more stable right now. Most likely the conversion to texture was crashing it*, but the drawing of the surface is so lightweight that you really only notice it when the created thing is fuckhuge, so it's not really worth it to juggle things around more.

*putpixel() doesn't affect the inner workings of SDL at all actually, but whatever
« Last Edit: October 03, 2013, 03:06:09 pm by cerapa »
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5086 on: October 03, 2013, 04:12:43 pm »

You might want to check the documentation for whatever you're using to draw stuff. Graphics libraries generally don't like it when you're sending requests from multiple threads.
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5087 on: October 03, 2013, 04:58:39 pm »

Is the problem here that tokens is never reset in the loop, so that tokens[3] means the same thing no matter how many times the loop is run? If so, how do I reset the value of a vector? Should I be using some other aggregate data type besides a vector for this?
« Last Edit: October 03, 2013, 05:10:15 pm by MrWillsauce »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5088 on: October 03, 2013, 05:14:59 pm »

Code: [Select]
                vector<string> tokens;
                for(int iii = 0; iii < (sizeof tokens); ++iii)
                {
                        string strCommand;
                        getline(inf, strCommand);
                        if (strCommand == strEndRead) break;
                        istringstream iss(strCommand);
                        copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
                        if (nTemporaryPopulation < 1) break;
                        int y = strToInt(tokens[1]);
                        nTemporaryPopulation = nTemporaryPopulation - y;
                        CommandController::runCommand(tokens, data, y, strStartRead);
                }
                inf.close();
                return 0;
Okay, this is an absolute mess. First off, what the hell is the for loop for? Next, "sizeof tokens" doesn't even remotely mean what you think it means, you should never ever use it unless you're writing advanced memory optimization code.
Lemme just clean this up for you:

Code: [Select]
vector<string> tokens;
string strCommand;
getline(inf, strCommand);
if (strCommand == strEndRead) break;
istringstream iss(strCommand);
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
nTemporaryPopulation -= y;
if (nTemporaryPopulation < 0) break;
if (tokens.size() < 2) break;
int y = strToInt(tokens[1]);
CommandController::runCommand(tokens, data, y, strStartRead);
inf.close();
return 0;
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5089 on: October 03, 2013, 06:03:57 pm »

Right. I think I originally made the for loop conditions while not entirely coherent after I tried to make the condition tokens.size and that didn't work (or something). I don't really have an excuse for that manifestation of my idiocy, but I do know what the sizeof operator does. I actually changed it to a while(inf) loop since my last paste, but I figured it wouldn't have worked either way.


Code: [Select]
while(inf)
{
string strCommand;
getline(inf, strCommand);
if (strCommand == strEndRead) break;
istringstream iss(strCommand);
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
if (tokens.size() < 2) break;
int y = strToInt(tokens[1]);
nTemporaryPopulation -= y;
if (nTemporaryPopulation < 0)
{break;
cout << "error";}
CommandController::runCommand(tokens, data, y, strStartRead);
}

Seems to work perfectly, I just need to tidy up the function that prints everything.
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5090 on: October 04, 2013, 07:23:36 am »

Code: [Select]
{break;
cout << "error";}

Unreachable code?

Also, those curly braces.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5091 on: October 04, 2013, 07:35:25 am »

Code: [Select]
{break;
cout << "error";}

Unreachable code?

Also, those curly braces.
It's a totally new style.

I dig it.

I'm going to spend the afternoon re-styling all my code like that.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5092 on: October 04, 2013, 07:59:35 am »

I just realized that Visual Studio 2010 doesn't support the for (x : y) syntax, which is why it instead has for each (x in y)....
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5093 on: October 04, 2013, 04:26:49 pm »

My program suddenly stopped working, seemingly without cause.

1>------ Build started: Project: MrWillsauce2.0, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1168: cannot open C:\Microsoft Visual Studio 10.0\Projects\MrWillsauce2.0\Debug\MrWillsauce2.0.exe for writing
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any idea why this file would disappear or how I can fix this or what?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5094 on: October 04, 2013, 04:50:11 pm »

If there is such a file, you need to delete it. If it is currently used by another process, your program is probably still running and you need to quit it.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5095 on: October 05, 2013, 04:27:18 am »

Googling for help abot a stack overflow problem has becoming a lot harder in recent years.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5096 on: October 05, 2013, 04:44:57 am »

Googling for help abot a stack overflow problem has becoming a lot harder in recent years.
What changed?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Draxis

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5097 on: October 05, 2013, 06:41:08 am »

Now all you will find is the site Stack Overflow.
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5098 on: October 05, 2013, 12:05:27 pm »

I'm having difficulties with my program.

When the EmpireHoldings.dat file has these contents
Spoiler (click to show/hide)

and HFC Input.dat has these
Spoiler (click to show/hide)

the holdings of the empire aren't changed at all. Also, in the loop that reads the inputs, trying to stream the strings being read from the input file into the console doesn't work.
Code: [Select]
while(inf)
{
string strCommand;
getline(inf, strCommand);
cout << strCommand; //does not show up on console
if (strCommand == strEndRead) break;
istringstream iss(strCommand);
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
if (tokens.size() < 2) break;
int y = strToInt(tokens[1]);
nTemporaryPopulation -= y;
if (nTemporaryPopulation < 0)
{cout << "error";
break;}
CommandController::runCommand(tokens, data, y, strStartRead);
}
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5099 on: October 05, 2013, 01:28:07 pm »

There's a problem with this line:

Code: [Select]
if (tokens.size() < 2) break;

This will abort the entire input reading process if any line has less than 2 tokens.
Try this instead:

Code: [Select]
while(inf) {
string strCommand;
getline(inf, strCommand);
cout << "Parsing command: " << strCommand << endl;
if (strCommand == strEndRead) break;
istringstream iss(strCommand);
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
if (tokens.size() >= 2) {
int y = strToInt(tokens[1]);
nTemporaryPopulation -= y;
if (nTemporaryPopulation < 0) {
cout << "error";
break;
}
CommandController::runCommand(tokens, data, y, strStartRead);
}
}
Logged
Pages: 1 ... 338 339 [340] 341 342 ... 796