Bay 12 Games Forum

Please login or register.

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

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

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5115 on: October 07, 2013, 02:25:39 am »

For a logarithmic spiral, just keep the angle of the bearing to the spiral's center constant. For an Archimedean spiral, set the bearing to be at right angles to the center, then turn the ship by cot-1(c * the distance to the center).
« Last Edit: October 07, 2013, 02:28:22 am by MagmaMcFry »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5116 on: October 07, 2013, 09:51:30 pm »

But a ship can't magically change its position. It has variables of bearing, acceleration, and speed which it can change to a degree.

Vectors and calculus. Assuming constant acceleration, it all boils down to a few equations:

r(t) = r0 + v0*t + 1/2*a*t2
(r is the position vector, r0 is the initial position vector, v0 is the initial velocity vector, and a is the acceleration vector)

x(t) = ||r(t)||*cos(A)
y(t) = ||r(t)||*sin(A)
(||r(t)|| is the magnitude of the position at time t, A is the angle made with the positive x axis (east), otherwise known as bearing)

For varied acceleration, it's probably easier in this case to treat acceleration like a piecewise function and reevaluate the formula at small time intervals with the acceleration and velocity for that time.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5117 on: October 07, 2013, 11:40:35 pm »

I really hate working with Fortran.  I was handed a 10,000 line Fortran program and tasked with doing some painful things with it.  I only have a pretty basic understanding of Fortran, and am currently very stumped on why the program is crashing when reading from an input file.

The input file looks like this:

Code: [Select]
       3
       6       26        8
       6       26        8
       4       26        8
 0.00000000000e+00  1.01010096073e+00  2.02020192146e+00  3.03030300140e+00
 4.04040384293e+00  5.05050516129e+00  0.00000000000e+00  1.01010096073e+00
 2.02020192146e+00  3.03030300140e+00  4.04040384293e+00  5.05050516129e+00
...etc...

The code that opens and begins reading it looks like this:

Code: [Select]
      open (2,file=gridFileName, iostat=openStatus)
      if (openStatus>0) stop "**Open input file failed**"
 
      read (2,*) BloNo
      print *, 'Block No.: ',BloNo
      iTotal(1)=0

It opens the file successfully.  It also reports that the file's size is correct if I use INQUIRE on it.  Using Intel's compiler works.  If I use PGI's compiler, which I must, then it crashes at the read line claiming that it's reading past the end of the line.

I have no clue why this is happening.  By everything I'm reading it should be perfectly fine to do this, and it works using ifort.  It should read the 3 into BloNo as per list-directed input.   Why does pgfortran produce a binary that crashes here!?
Logged
Through pain, I find wisdom.

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5118 on: October 08, 2013, 03:40:34 am »

Try status='OLD' in the open statement, just to make sure it's not creating a blank file somewhere randomly. As a general precaution I'd also recommend action='READ' if the file is precious to you somehow. The latter might actually imply status=old, I'm a bit rusty after a few years of little exposure to scientific code. The terror of FORMAT statements linger though (though apart from IO, I actually like fortran).

edit: somehow failed to read the very clear sentence where you point out you get the right file size. Then I don't know.
« Last Edit: October 08, 2013, 03:44:51 am by olemars »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5119 on: October 08, 2013, 07:26:27 am »

Yeah, I tried the status=old thing too thinking the same thing about it creating a file and that didn't help.  I haven't tried adding action='read', which can't hurt anything at least.  I did try converting the code to formatted input instead to see if that helped, and it didn't.  I think I might have gotten the format specification wrong though.

Thanks anyway.  I foresee a few more painful hours in my near future...
Logged
Through pain, I find wisdom.

MrWillsauce

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

[C++]
Would it be possible for me to make my program generate maps with the name of the thing they contain based on strings in a .dat file? For instance, if there are a set of values that I would categorize as "structures" I would like to have the text file set up like this:

Spoiler (click to show/hide)

and then have a program that reads through that file, making new maps for the categories, then adding keys and values to those maps based on the things under them, and then stop reading for that category when it hits whitespace. So should I make a map <string, data> or something to accomplish that?
« Last Edit: October 08, 2013, 04:40:07 pm by MrWillsauce »
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5121 on: October 08, 2013, 05:08:50 pm »

There are dozens of ways to achieve that. You just need to pick one that fits what you intend to do with the categories. What you want them to be, if there is a fixed set you have in mind or it's meant to be a more generic concept, etc.

Also, whitespace can be a tricky thing to use as a delimiter.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5122 on: October 08, 2013, 06:55:22 pm »

[C++]
Would it be possible for me to make my program generate maps with the name of the thing they contain based on strings in a .dat file? For instance, if there are a set of values that I would categorize as "structures" I would like to have the text file set up like this:

Spoiler (click to show/hide)

and then have a program that reads through that file, making new maps for the categories, then adding keys and values to those maps based on the things under them, and then stop reading for that category when it hits whitespace. So should I make a map <string, data> or something to accomplish that?

What you want is a map<string, map<string, int> >. Yes, that is possible. I assume you are doing this so you can print the data in order, right? Well, that's kinda not the best way to do that. Here's an alternative way to do this: Just make a format file that specifies the order of all the data values:

Code: [Select]
STRUCTURES
Towns: $towns
Farms: $farms

POPULATION
Population: $pop

(and so on)
Read this file into memory at the start of your program and save it as a vector<vector<string> >, saving each line as a vector<string> of words. When you want to print your data, you just do this:

Code: [Select]
// format is the vector<vector<string> >.
for (vector<string>& formatLine : format) {
  for (string word : formatLine) {
    // If a format word begins with a $, replace it by the data value of that name (minus the $ of course).
    if (word.front() == '$') word = data[word.substr(1)];
    // os is your output stream.
    os << word << " ";
  }
  os << endl;
}

This also means that you don't need to save the description of the variable in the name of the variable, so you can write data["pop"] instead of data["Population:"].
« Last Edit: October 08, 2013, 06:58:34 pm by MagmaMcFry »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5123 on: October 09, 2013, 09:15:02 am »

Figured out my Fortran problem, and I don't know if I should blame it or Linux.  There was a second empty file with the same name in the directory, except its file name apparently ended in an unprintable character (ls listed it as 3dminput.grd?).  I deleted that file and reran the program twice and it started working.  No idea why it took two runs... or where the file came from.

Normally I'd just cast the blame on whoever created that file, but I still want to know why Fortran was happy to tell me the correct file size and tell me that it had opened the file, when apparently it opened that other empty one.

Again, not sure if this is a quirk of Linux's file I/O system or PGI's Fortran implementation... considering that Intel's compiler produced a working binary it's probably the implementation's fault somehow.  I've noticed other interesting differences between the two compilers, such as Intel's compiler allowing you to initialize unallocated arrays, where PGI's crashes (sensibly in my opinion).  Not sure who's to blame there either.  Maybe the Fortran spec allows that.
Logged
Through pain, I find wisdom.

moghopper

  • Bay Watcher
  • The not quite as great as Toady or Three toe
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5124 on: October 09, 2013, 10:19:51 am »

I was going to start my own thread, but this seems like a better place to post.

I'm starting an indie gaming company, and I'm currently looking for a coder to help with the development of 2D games.

The ideal candidate will be proficient in:

C++
SDL


Any kind of sound/music experience is also welcome.

If you are interested, Pm me
« Last Edit: October 09, 2013, 10:25:42 am by moghopper »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5125 on: October 09, 2013, 10:42:37 am »

This isn't an advertising thread, so not quite the right place.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

moghopper

  • Bay Watcher
  • The not quite as great as Toady or Three toe
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5126 on: October 09, 2013, 10:54:35 am »

This isn't an advertising thread, so not quite the right place.

I just figured it would be the best place to find interested and dedicated individuals.
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5127 on: October 09, 2013, 11:15:15 am »

This isn't an advertising thread, so not quite the right place.

I just figured it would be the best place to find interested and dedicated individuals.
Make a thread in creative projects.

Possibly with a better outline than "2D game". Something to make people want to work with and for you.
Logged

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

moghopper

  • Bay Watcher
  • The not quite as great as Toady or Three toe
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5128 on: October 09, 2013, 11:18:44 am »

This isn't an advertising thread, so not quite the right place.

I just figured it would be the best place to find interested and dedicated individuals.
Make a thread in creative projects.

Possibly with a better outline than "2D game". Something to make people want to work with and for you.

Fair enough. I'll do that then.
Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5129 on: October 09, 2013, 05:07:50 pm »

Figured out my Fortran problem, and I don't know if I should blame it or Linux.  There was a second empty file with the same name in the directory, except its file name apparently ended in an unprintable character (ls listed it as 3dminput.grd?).  I deleted that file and reran the program twice and it started working.  No idea why it took two runs... or where the file came from.

Normally I'd just cast the blame on whoever created that file, but I still want to know why Fortran was happy to tell me the correct file size and tell me that it had opened the file, when apparently it opened that other empty one.

Again, not sure if this is a quirk of Linux's file I/O system or PGI's Fortran implementation... considering that Intel's compiler produced a working binary it's probably the implementation's fault somehow.  I've noticed other interesting differences between the two compilers, such as Intel's compiler allowing you to initialize unallocated arrays, where PGI's crashes (sensibly in my opinion).  Not sure who's to blame there either.  Maybe the Fortran spec allows that.
Files in Linux consist of a series of bytes, usually assumed to be UTF-8. A few searches tell me that Fortran does not null-terminate strings, so my (completely in the dark) guess is that something somehow overran the string for some bizarre reason.
Logged
Pages: 1 ... 340 341 [342] 343 344 ... 796