Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 496 497 [498] 499 500 ... 796

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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7455 on: May 26, 2015, 09:51:21 am »

Ohh, right, quad/octrees work for n-body simulations because those only need "good enough" approximations...
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

monkey

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7456 on: May 26, 2015, 11:57:10 am »

What would be the best method for finding which point from an array is the closest to a chosen point in an N dimension space (where N is a large number), if there are a lot of points and I can't afford to simply loop through all of them?

If you need to find several points using with the same array, it might be worth it to build a tree (quadtree / octree or kd-tree)
It might be cheaper to just check all of them, easy to parallelize or even send it to a gpu ?
Logged

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7457 on: May 26, 2015, 01:05:52 pm »

What would be the best method for finding which point from an array is the closest to a chosen point in an N dimension space (where N is a large number), if there are a lot of points and I can't afford to simply loop through all of them?

Never forget that you don't need the actual distance, only the closest point(you can do the actual distance later if you need it), so there is no need for square roots or its ilk.
Logged

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7458 on: May 26, 2015, 01:15:18 pm »

no need for square roots per point at all. you just do distance^2 which is faster. then a single square root for the final chosen point.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7459 on: May 26, 2015, 02:20:04 pm »

Anyone know how to print non char or string variables onto a screen in curses? I'm using pdcurses in c++. Seems like all the print commands for curses only take strings/characters, so if I wanted to print, say, the value of an int onto the curses window, the print commands won't take the variable itself.

So I guess I'd need a way for the program to take the int variable, make a char variable of the number, and use that variable. Like, if int X is 3, the program takes X and makes a char variable that is '3' for printing.

I'm stumped.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7460 on: May 26, 2015, 02:27:41 pm »

In C++11, std::tostring(num) is apparently a thing.

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7461 on: May 26, 2015, 03:28:13 pm »

Spoiler: errorlog (click to show/hide)

googling "c++ tostring" brings up "to_string". Neither works.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7462 on: May 26, 2015, 03:31:17 pm »

std::to_string(whatever)

Should be included with just strings in general coming from any random included thing, but you can try adding #include <string> if it doesn't work.
« Last Edit: May 26, 2015, 03:35:30 pm by cerapa »
Logged

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

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7463 on: May 26, 2015, 03:41:12 pm »

Tried that too. Still doesn't work. "not declared in this scope".

Spoiler: code so far (click to show/hide)
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7464 on: May 26, 2015, 03:45:52 pm »

Are you sure you have C++11 enabled? What IDE and compiler are you using?
Logged

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

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7465 on: May 26, 2015, 03:54:45 pm »

Are you sure you have C++11 enabled? What IDE and compiler are you using?
IDE==Code::Blocks and compiler==GNU GCC compiler. I set it to use c++11 after someone mentioned it during an earlier question I had. I checked earlier, the option is still checked.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7466 on: May 26, 2015, 04:03:43 pm »

Strange. I have the same IDE and compiler.

Can you use other c++11 features? Like...range based loops for example?

Code: [Select]
int my_array[5] = {1, 2, 3, 4, 5};

for (int &x : my_array) {
    x += 1;
}
Logged

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

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7467 on: May 26, 2015, 04:33:35 pm »

Strange. I have the same IDE and compiler.

Can you use other c++11 features? Like...range based loops for example?
Spoiler (click to show/hide)
Yeah, that compiled ok.
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7468 on: May 26, 2015, 04:44:21 pm »

I distinctly remember having a similar issue with to_string at some point, but that might have just been because I didn't have c++11 turned on.

Meanwhile you can convert numbers to string through a stream. Less convenient than to_string, but you gotta do what you gotta do.

Code: [Select]
#include <sstream>

stringstream streamofstrings;
streamofstrings << yourint;
resultingstring = streamofstrings.str();

String doesn't look like a word anymore.
Logged

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

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7469 on: May 26, 2015, 05:58:27 pm »

@spehss

Simple solution! Make a function that feeds a string, character-by-character into the curses print function.

It's not pretty, it's not optimized, but it'll damn well work.
« Last Edit: May 26, 2015, 06:06:27 pm by Pufferfish »
Logged
Pages: 1 ... 496 497 [498] 499 500 ... 796