Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 149 150 [151] 152 153 ... 796

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

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2250 on: April 20, 2012, 05:46:57 pm »

I don't think you can overload file input... can you?
Yes you can but no, you don't need to. It's standard istream functionality, and my example should work "just like that". Well, if you define "name" and the ints first.
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))

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2251 on: April 20, 2012, 08:35:01 pm »

So, I've been working for a few days on my simple noise generator. I was trying to make it multithreaded, but then I seemingly hit a brick wall. I simply couldn't figure out why it was throwing an exception at a random point in a boost header file. I was about to get some help from you awesome people, but I didn't want to share all ~1000 lines of code, in case it turned out to be a simple oversight on my part. Turns out, it was a simple oversight. Both threads were doing things to the same boost RNG, and I forgot to change it.

So, now I have a noise generator that can generate a 4096x4096 texture in 0.7 seconds, and uses a mostly arbitrary number of threads. That's about 40 nanoseconds per pixel!  :o

I've had a goal to make an extremely fast perlin noise generator for a while now. The last time I did stuff with perlin noise, the generation of random numbers was always so slow. It was so slow it made me think that any kind of real-time procedural stuff just wasn't worth it. Now it doesn't seem like a pipedream anymore. I'm starting to really love C++.


I do have one issue, though. Currently, the RNGs are given seeds based on the current time. When two RNGs are seeded at almost the same time, they get the same seed, and the image looks funky. I know why this happens, and I know there are lots of ways around it, but I thought I would ask for the best solution for this problem.
Logged

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2252 on: April 20, 2012, 08:40:50 pm »

Start your program with n = (int)(current time).
Manually seed your RNGs with n++.
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2253 on: April 20, 2012, 10:39:42 pm »

@Virex: That Battleship link that you provided is pure unadulterated win in my book :D I will add some of the theory from that when I get into changing difficulty modes.

Just found my code files for the Battleship game... omg it's so damned messy :( I'm surprised it runs as fast as it does. I wonder if I could make it a multithreaded AI where each player has its own thread so it can "think" about what to do while the other player is making its move... and then just have a token get passed around to let the thread know it is allowed to make a move. That might speed things up even more... or it could have a horrible effect of slowing it down if it tries to put both threads onto the same core (assuming a dual core processor here)...

Well, looks like I have a lot of work to do :P Will start production of the next devcycle for this later in the week... probably this weekend if I don't have to do a lot of extra work around the house.

GalenEvil
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

armeggedonCounselor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2254 on: April 21, 2012, 12:06:11 am »

Code: [Select]
studentdata >> name >> int1>>int2>>int3>>int4;
Or something like that.
Streams ftw.

While this wouldn't work for the assignment (I have to save both names and test scores into arrays), it did spark an idea in my mind.

I tried it. It works. This problem is now halfway done. Getting the data into the arrays was the hard part. Now it's just manipulating data.

Tomorrow, I make numbers beg for mercy. MUAHAHAHAHAHAHA!

.... dun judge me I'm tired

FTR, what I did to get it to work was adding a second for loop in the input loop, then went back to using "studentData >> blah" to save the name in the first array, then in the second for loop, I took all the numbers and saved them into TestScores.

I was aware of how useful nested loops are for arrays, but I didn't stop to consider that you can actually fill more than one array at a time.

Needless to say, I felt a little dumb. Fittingly, the answer was staring me right in the face from the beginning, and I didn't see it.
« Last Edit: April 21, 2012, 12:09:51 am by armeggedonCounselor »
Logged
Quote from: Stargrasper
It's an incredibly useful technique that will crash the computer if you aren't careful with it.
That really describes any programming.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2255 on: April 21, 2012, 01:49:58 am »

Don't feel dumb, every mistake is a chance to learn. Every time I make a mistake I try to learn from it, redo it to figure out why the mistake happened, and then redo it several different ways to see what is the absolute best way to attack the problem. Then once I have that information I make a new file in notepad and file away the results :D

Sometimes not looking at your code is the best way to find the problems. I try to work out every step of my program from beginning to end with a pen and paper using pseudocode. First I do a general a->b mockup of the program's flow (a chart, if you will), and then go into each step in the chart and figure out what needs to be done there (usually ending up with another chart). With each chart comes more information, and with each bit of information comes understanding. Sure, you are going to make mistakes that later when observed make you feel stupid, but it is the journey that counts with gaining knowledge... not the destination.

I feel like a self help book, but oh well heh... I am a compulsive note-taker so it works for me to make flowcharts out of all of my programs from beginning to end with all of the general ins and outs of the program exposed on paper. Makes it easier to look at and conceptualize that way for me. Once I start diving into actual code I can usually do it pretty quickly since I have all of the steps written out, and then it is just a matter of adding a debugger to the process to figure out where things are making bottlenecks or just taking too long in general so that I can put in either duct-tape optimizations or real useful optimizations.

GalenEvil
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2256 on: April 21, 2012, 11:15:04 am »

Yay RP2pre5!
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2257 on: April 21, 2012, 12:59:56 pm »


My favorite kinds of fixes are the ones where I don't know why it wasn't working in the first place, and I don't know why it does work now.  But at least I've finally fixed some lingering bugs from my old code, and everything is chugging along nicely again.  Now to copy more old half-functioning code and get back to where I left off again.

Max White would appalled if he could see what I'm doing.  He went to all that trouble of making an example game with fancy stateswitching and input modes and stuff, and as duly impressed as I was, I went right back to bodging together my magical moving castle of beginner code.  I can't help it, I almost like this project more for how ramshackle the internals are.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2258 on: April 21, 2012, 02:50:17 pm »

I kind of think of that kind of thing myself for my own projects. I didn't go to school for programming, it's something I picked up after years of just doing it for giggles, and because I wanted to get something done. I'm not the licensed repairman; I'm the friend of a friend who comes over with a toolbox, and two rolls of duct tape. Because at the end of the day, all I want is for my code to do what I want it to do.

On a different topic: My Audio Engineering course has a class this term for Audio in Gaming. My teacher is a person who went to my school and who is now working at a video game company in a nearby city. This week was only our second class, so it's still mostly just learning terminology and breaking out the Xbox for practical demonstrations. Still, it's giving me all sorts of ideas that I sort of want to put into practice. I'm craving to make a game right now.

I'm thinking platformer.
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2259 on: April 21, 2012, 03:18:02 pm »

Max White
Speaking of which, where did he go?
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))

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2260 on: April 21, 2012, 03:37:02 pm »

On a different topic: My Audio Engineering course has a class this term for Audio in Gaming. My teacher is a person who went to my school and who is now working at a video game company in a nearby city.

Might I suggest taking this to class at some point.  If I were making a platformer, I'd be all over that.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2261 on: April 21, 2012, 10:12:05 pm »

How do you set up a version control system for a project in VC++ other than being compulsive about backing up all of the files daily or something like that? I have screwed a few things up and it took a few hours to get them back in working condition on a different project from my battleship game. A version control will be useful once I start getting more done in Battleship GUI version so that I don't accidentally completely break the project in half >.<

EDIT!!!

Hopefully someone can help me with this since my in-brain calculus has flown out the window at this point...

Description of Coding Challenge:
*  You have a base circle of radius = whatever
*  You have a threshhold that the difference in subsequent radii cannot fall under without "failing" (1)
*  All circles are concentric around a single middle point
*  All circles are essentially increasing in area by ((circle number) * base circle area) such that the area between the outer most circle and the next circle inward is the same as the base circle's area. (hope that makes sense w/o pictures)

Now for the problem I am having:
*  I can properly iterate upwards from the first circle to the last circle increasing in radius until the threshold is reached, but am unable to create an algorithm to "predict" with certainty that the last circle will be of a certain radius given a certain initial radius and threshold.

SO.... I ask you awesome coders whom have extensive calculus knowledge:
*  What is the best way to go about creating this algorithm WITHOUT it having to step through each circle individually?
*  Is this even possible?

This project is more of a thought project to see if I could remember work from my old college days but it seems to have stalled. My pen-and-paper work on it has been less than encouraging as I seem to be coming up with numbers that are either half the iterations actually necessary or many times higher than the iterations necessary.

I am not sure how to proceed since I have so far been just iterating from the beginning with:

Initial Radius = 10
Initial Area = 3.14 * 10^2 = 314
Threshold between R(n) and R(n-1) = 0.001

A(0) = Initial Area
A(1) = 2A(0)
A(2) = 3A(0)
...
A(n) = (n-1)A(0)

R(0) = Initial Area
R(1) = sqrt(2A(0) / pi)
R(2) = sqrt(3A(0) / pi)
...
R(n) = sqrt((n-1)A(0) / pi)

And the differences in Radius are calculated simply using the latest R value, let's say R(n), against the previous R value, R(n-1):

Rdiff = R(n) - R(n-1) = [sqrt((n-1)A(0)/pi)] - [sqrt((n-2)A(0)/pi)]

If Rdiff is below the threshold set then the program exits the loop and ends the run.

I guess the easiest way would be to set it up as a series of Areas against a series of Radii but I am not sure how to do that.
What I have in my head is probably wrong and I hope someone here will fill me in on what I am doing wrong with my reasoning...

I failed Calculus 2 a few times, which runs from whatever was at the end of Calculus 1 until the Taylor and Mclauren series in my school so I am really not entirely sure where I am screwing up. If I had my notes right next to me I could probably write out some really screwed up Calculus equations but, alas, I do not :(
« Last Edit: April 21, 2012, 11:18:46 pm by GalenEvil »
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2262 on: April 22, 2012, 12:03:39 am »

Well, you could always solve the equation Rdiff=Threshold (or Rdiff-Threshold=0) numerically, using some root-finding algorithm.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2263 on: April 22, 2012, 02:29:55 am »

If that works I am going to feel much more stupid than I already do... though, since a root is essentially where the equation zeroes out there wouldn't be a root where I need it to be. The limit approaches 0 but never actually makes it to 0.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2264 on: April 22, 2012, 02:58:49 am »

If that works I am going to feel much more stupid than I already do... though, since a root is essentially where the equation zeroes out there wouldn't be a root where I need it to be. The limit approaches 0 but never actually makes it to 0.
Given that I said to solve for Rdiff-Threshold=0, it would only fail to approach 0 if the difference in radii failed to go below the threshold which is clearly impossible. I did a bit more work on your problem, and you could solve 3*n^2-(9+2*T*pi/A0)*n+([T*pi/A0]^2-7)=0 for n, the positive solution of which should be the point at which the expression for Rdiff is equal to zero.
Logged
Pages: 1 ... 149 150 [151] 152 153 ... 796