Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 560 561 [562] 563 564 ... 796

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

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8415 on: November 13, 2015, 05:15:52 pm »

Rounding is fun.
Code: (Python) [Select]
>>> 0.1 + 0.1 + 0.1
0.30000000000000004
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8416 on: November 13, 2015, 05:31:34 pm »

If you can avoid using floats, do. You can store it as an int and just divide it by 100 before displaying it if you don't need precision beyond that. (e.g. storing money as cents instead of dollars)
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.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8417 on: November 13, 2015, 05:50:44 pm »

Rounding is fun.
Code: (Python) [Select]
>>> 0.1 + 0.1 + 0.1
0.30000000000000004

0.30000000000000004.com

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8418 on: November 16, 2015, 01:42:46 pm »

In c++, doubles are usually a better idea than floats anyway if you absolutely need decimal representation. Your first impulse is probably to avoid them because of their high memory usage compared to floats, but unless you're allocating a billion of them it really doesn't matter.

Of course, I've been using SFML as a graphical back-end lately, and it uses floats for EVERYTHING. Consistency is often more important than using the most "correct" method, especially when you're gluing a bunch of external code libraries together.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8419 on: November 16, 2015, 03:10:29 pm »

If I'm not mistaken, some modern architectures even perform math with doubles faster than floats anyway.  I guess they're optimized to expect people to use them since memory is so cheap as to make floats largely irrelevant.

Now, this is an entirely different story with some specialized hardware, like GPUs.  I think they've actually managed to unify performance between floats and doubles now, but for a very long time it used to be the case that floats were vastly faster than doubles because of the way the hardware math was implemented.
Logged
Through pain, I find wisdom.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8420 on: November 16, 2015, 05:55:19 pm »

Looking through old projects (or in this case, old parts of a current project) is always interesting.
Code: [Select]
rgb[c] = abs (int (math.sin (math.sqrt((x - somemodx * consolew) ** 2 + (y - somemody * consoleh) ** 2) / somecirc - someiter / somerate) * 200))
I think this does something with circles? Coloured circles?
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8421 on: November 16, 2015, 06:07:13 pm »

Aieeeeeee menusplosion.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8422 on: November 16, 2015, 06:20:17 pm »

Looking through old projects (or in this case, old parts of a current project) is always interesting.
Code: [Select]
rgb[c] = abs (int (math.sin (math.sqrt((x - somemodx * consolew) ** 2 + (y - somemody * consoleh) ** 2) / somecirc - someiter / somerate) * 200))
I think this does something with circles? Coloured circles?

We can break that down a bit. math.sqrt((x - somemodx * consolew) ** 2 + (y - somemody * consoleh) ** 2) is a distance function, so it's the distance from a circle center

I'm going to assume that someiter actually iterates. What that implies is that there are colour bands radiating out from the center of a circle, and it's animated. i.e. it's got colour-cycling like a plasma. the rgb array would be an array of all the possible colours, so you can customize the animation colours by changing that table.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8423 on: November 16, 2015, 06:21:29 pm »

Oh! That's what that is. I'm impressed that I actually managed to do that.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8424 on: November 16, 2015, 06:24:06 pm »

Since you're doing that per-pixel you should really pull some of the maths etc outside of the loop. It would be a lot faster and neater.

e.g. "(y - somemody * consoleh) ** 2" will be the same for every y-line, so you can calculate this only once in the outer loop, then use the result. Same with things like the division, it can go outside both the x and y loops.

Also, rather than the abs function you can just add 1 to sine value (to get it to 0...2 range), then scale it after that.

« Last Edit: November 16, 2015, 06:27:14 pm by Reelya »
Logged

Uristides

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8425 on: November 18, 2015, 06:56:18 pm »

So, has anyone here ever dealt with SWIG and Python and managed to successfully interface C++ STL vectors(or even C arrays) with NumPy arrays? Everything I found around stack exchange and the likes I find too abstract and have no idea how to implement(I just started learning how C/C++ interfaces with Python work last month), and the few implementations I found I haven't got to work, probably because they are from 2008 and it seems NumPy's C/C++ API changed drastically at least once since then.

I may be open to other options besides SWIG too, as long as they play nice with C++11 features. I know there's Cython, and some people really think it's great and more "pythonic" than SWIG, and seems to handle both STL vectors and numpy ok(not sure if fastly or seamlessly though), but right now just the thought of polluting my Python code with static typing garbage puts me off completely.
« Last Edit: November 18, 2015, 07:01:06 pm by Uristides »
Logged

Mesa

  • Bay Watcher
  • Call me River.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8426 on: November 19, 2015, 03:45:28 pm »

Some context:
One of my IT classes revolves around JavaScript (with some AJAX and/or jQuery later on, I think) and our teacher gave us two choices for how to do our first exam.
Either everyone makes their own JS project in a week or we do a more standard test solely in class.
We went with the first option.

And me being the gamer I am went a bit further ahead and decided to make a game. Pretty ambitious, but it's not meant to be hyper-complex or have GOTY-level art/design.

I'm using the Phaser framework.
So far it's going pretty okay and I've been following their "First Game" tutorial rather closely but I've ran into an issue with the collision checking - it just doesn't work (and by proxy neither does jumping).
I have it exactly like the tutorial said, I even checked the API docs for the collision function, but it just doesn't work.

If anyone here happens to know Phaser better than me, I've uploaded the game to my GitHub (after a LOT of trial-and-error with Git...don't look at the commit history, that one's ugly).

There might be some other issues like the fact there's only one stage and no score or anything but those are secondary to fixing this collision problem that is probably stupidly easy and I'm just a big ol' dumbo.
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8427 on: November 19, 2015, 04:07:46 pm »

Learning git is annoying but once you understand it you can look down on the filthy scrubs using svn it's pretty nice, really.
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.

Mesa

  • Bay Watcher
  • Call me River.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8428 on: November 19, 2015, 05:03:28 pm »

Okay, I fixed that problem now. Turns out it's the usual JavaScript "too few semicolons, maybe too many vars" problem. Go me.
Now to fix some other things and wrap this up.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8429 on: November 19, 2015, 11:48:32 pm »

lol, just put a damn semi-colon at the end of each line to save yourself a whole layer of bullshit later on. That Javascript "too few semi-colons" problem is self-inflicted and actually makes you worse at doing proper c-style languages that Javascript is based on. In other words, for the few c-style languages where semi-colons are optional, just put them in anyway. It's one less thing you have to give a fuck about then.
« Last Edit: November 19, 2015, 11:53:23 pm by Reelya »
Logged
Pages: 1 ... 560 561 [562] 563 564 ... 796