Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 229 230 [231] 232 233 ... 796

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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3450 on: November 11, 2012, 08:33:03 pm »

The most complicated way of getting random numbers yet, did render me some cool element and mineral names:
Code: [Select]
int NMaterialManager::getRandomInt(const int& seed, const int& max){
  boost::mt19937 gener(seed);  // Mersenne twister
  boost::uniform_smallint<> normal(0,max-1); // uniform distribution optimised for small integer ranges
  boost::variate_generator<boost::mt19937&,boost::uniform_smallint<> > rng(gener, normal); // Variatic generator combining the two
  return rng(); // Finally, a number.
}

Spoiler (click to show/hide)

Damn. Imagine trying to cram all of that into one line.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3451 on: November 12, 2012, 03:45:25 am »

Damn. Imagine trying to cram all of that into one line.
Assuming that was sarcasm:
:P No premature optimisation! Writing that into one line would just mean re-writing it again when I make them resettable members instead of re-allocating it for every call. I'm just getting into boost and learning what's in there. It's a lot...
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 #3452 on: November 12, 2012, 03:59:27 am »

Deciding on a point between memory and performance is hard. Dx Right now, I'm dumping efficient memory usage, in having every variable stored instead of being looked up. I don't know if it's a good idea, but I'm really feeling that trade-off. Ten megabytes of ram!
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

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3453 on: November 12, 2012, 04:34:21 am »

What are you trying to do, Skyrunner? It might be that flyweight pattern helps you out here, I don't know, depends on the problem.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3454 on: November 12, 2012, 04:48:18 am »

Oh, hmm. I could see how I could make that work, if each variable is replaced with a pointer to a data structure that has the actual information. It would reduce memory usage by a lot.

I feel too lazy to do that... maybe after I make a working demo. xD
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

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3455 on: November 12, 2012, 04:51:30 am »

I feel too lazy to do that
The second most common cause of people not using OOP when it will help them. The first most is not knowing what to do.  :P

I'll just sit in my corner, rambling about patterns...

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3456 on: November 12, 2012, 05:03:46 am »

...But I am using OOP. The flyswatter pattern is just a pattern, not OOP embodied. xD

Besides, I'm prioritizing! Ten megabytes on a four gigabyte computer won't matter right now! xD
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

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3457 on: November 12, 2012, 05:07:25 am »

Grr... Kids these days! *Grumble* give you information expert! * Mumble mumble* so much force you will feel it through your facade!!!!

 :P

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3458 on: November 12, 2012, 05:47:51 am »

Extremely. It's difficult even getting through the opening menu, and the game is entirely unplayable.

The fact that the opening MENU almost locks up is a preeeetty good sign there's something wonky going on in your code.
That's extremely weird. On my laptop, it uses only a tiny fraction of CPU/GPU time/memory, yet it still runs at 60 FPS without any problems, even when I scale the game speed to 100 ticks/frame (instead of the 1 tick/frame that I uploaded the game with). I have loader classes that make sure that no external file is loaded twice. Yet you still experience lag? I'll try changing the rendering approach, let's see if that works.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3459 on: November 12, 2012, 05:50:52 am »

Extremely. It's difficult even getting through the opening menu, and the game is entirely unplayable.

The fact that the opening MENU almost locks up is a preeeetty good sign there's something wonky going on in your code.
That's extremely weird. On my laptop, it uses only a tiny fraction of CPU/GPU time/memory, yet it still runs at 60 FPS without any problems, even when I scale the game speed to 100 ticks/frame (instead of the 1 tick/frame that I uploaded the game with). I have loader classes that make sure that no external file is loaded twice. Yet you still experience lag? I'll try changing the rendering approach, let's see if that works.

Is this a 3D app? Perhaps with shaders?
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3460 on: November 12, 2012, 05:55:29 am »

I don't suppose you are running any weird dev version of Java that might still be prone to these sort of problems, Glyph?
It seems strange that my laptop can handle something that a real computer can't, so it seems very unlikely to be eating resources.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3461 on: November 12, 2012, 06:08:34 am »

Is this a 3D app? Perhaps with shaders?
It does use OpenGL polygons instead of blitting, but no shaders.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3462 on: November 12, 2012, 06:29:32 am »

The most complicated way of getting random numbers yet, did render me some cool element and mineral names:
Code: [Select]
int NMaterialManager::getRandomInt(const int& seed, const int& max){
  boost::mt19937 gener(seed);  // Mersenne twister
  boost::uniform_smallint<> normal(0,max-1); // uniform distribution optimised for small integer ranges
  boost::variate_generator<boost::mt19937&,boost::uniform_smallint<> > rng(gener, normal); // Variatic generator combining the two
  return rng(); // Finally, a number.
}

You're reseeding the generator every time it is called. Both pointless and possibly expensive with Mersenne's  twister, just a heads up :-)
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3463 on: November 12, 2012, 07:36:22 am »

You're reseeding the generator every time it is called. Both pointless and possibly expensive with Mersenne's  twister, just a heads up :-)
No and yes. I know it's expensive, but not pointless: I need to have the same results every seed (pseudorng), and I vary the seed myself. I know the Mersenne isn't a really good choice for this, if you know a better one (cheaper to re-seed), I'd like to know :)

So, in my simulation, I have a seed number, that renders a Material Name, which is then re-converted into a number, which is then used to seed the properties of that material. So every time and everywhere you encounter a material called "hyperpharmatite", it will have the exact same properties.
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))

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3464 on: November 12, 2012, 07:39:23 am »

I like what Siquo is doing.
It isn't a random number generator, it is a hard to predict sequence generator.  ;)
Pages: 1 ... 229 230 [231] 232 233 ... 796