Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 317 318 [319] 320 321 ... 796

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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #4770 on: July 27, 2013, 07:45:34 pm »

« Last Edit: July 27, 2013, 07:48:13 pm by MorleyDev »
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4771 on: July 27, 2013, 08:04:46 pm »

I've been reading some stuff recently, and to draw the two current topics together (undefined behavior in C++ and A* union solutions), I don't think using unions like that is technically legal C++.

http://stackoverflow.com/questions/15952204/using-char-array-inside-union
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4772 on: July 27, 2013, 08:19:41 pm »

The standard also provides a few nice guaranteed size and guaranteed minimum size typedefs.

And those should be used in all cases where the programmer wants to rely on the type having a certain number of bits.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4773 on: July 27, 2013, 08:38:53 pm »

Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4774 on: July 27, 2013, 09:26:02 pm »

Making similar coordinate values have similar hashes slows things down? :(
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

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4775 on: July 27, 2013, 09:56:04 pm »

Making similar coordinate values have similar hashes slows things down? :(
If the hash value isn't scrambled again internally by the unordered_map when it gets used to index a bucket, then yes.
Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #4776 on: July 28, 2013, 11:19:01 pm »

It really depends on the implementation/algorithm of the hash map. Some implementations are actually worse with random keys than sequential ones.

Eeeh... the bitshifting is only guaranteed to work if both of the int32s are actually uint32s.

seriously, use the union, it's safer.

Left bit-shifts work the same for signed and unsigned types.
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #4777 on: July 30, 2013, 10:13:11 pm »

I'm writing some code where conditions can be described in my JSON Raws, and I'm stuck cause I can't decide which method to use.

Method one works by writing up a small interface, "Condition". Condition would be extended into a few actual classes, which hold the information about a condition, and a method to check if it's been met. For example, there might be a simple StatCondition, which remembers a stat and the numbers it has to be above or below, and there might be a CompositeCondition, which has a couple other conditions that it requires one or both of to be met, etc. When reading the Raws, the program builds a hierarchy of these as described.

Method two works by not parsing the relevant JSON object until it actually needs to check if the conditions are met or not. It'll have to parse it each time it checks, but it involves less programming on my part, and probably less memory usage too.

Or maybe there's another way I haven't thought of, that'll work better? Advise me, internets!
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4778 on: July 30, 2013, 10:35:20 pm »

It would be better if you could hold off on parsing the JSON object until you need it, but hold onto the relevant data after you've parsed the object. Unless there is something I'm missing which prevents you from doing the second part, but I can't really see it.
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #4779 on: July 30, 2013, 10:43:02 pm »

That would be more complicated, but I could do it. The main downside is that It might need to parse a bunch of stuff at once, and might lag a little. If it does that in the beginning while loading, then it's not a big deal, but I'd rather avoid it happening in game.
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4780 on: July 30, 2013, 10:55:32 pm »

I'd recommend parsing the conditions into condition objects immediately and not holding on to any JSON after you finish loading a raw file. It's much easier to write and it's tons faster too.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4781 on: July 30, 2013, 11:44:26 pm »

Parsing is extremely fast. Faster than you'd think, even, assuming the entire JSON is slurped into memory. Because JSON files are larger than the parsed data with no exception, and since loading files is slower than accessing RAM memory, I suggest parsing the data then releasing the JSON at program startup.

I'd recommend parsing the conditions into condition objects immediately and not holding on to any JSON after you finish loading a raw file. It's much easier to write and it's tons faster too.
This is actually my entire post, I noticed.

Unless your JSON file is a couple gigabytes there's no reason not to slurp it c:
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

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #4782 on: July 31, 2013, 12:14:07 am »

I meant parsing the text into JSONObjects, and holding onto those, not parsing the text on the spot, but yes, I'm going ahead and writing the classes now.
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4783 on: July 31, 2013, 01:36:07 pm »

Hey. I've sketched out a program in C++ to build a Markov chain of words and likeliest followups from a text (basic prediction stuff). It compiles fine, but it crashes on startup with an error message stating "deque iterator not dereferencable".

Of the classes below, it doesn't seem to rely on the Tokeniser function but something in the MarkovBuilder or the node class. I can't puzzle it out, though; not only do I have very limited experience with iterators (the code for the FindLikeliest function was mostly copy-pasted from the reference for begin() ) but try as I might, I don't have enough expertise to find the error.

Anyone else see it?

Logged

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #4784 on: July 31, 2013, 04:28:22 pm »

Use the debugger and find out where it crashed. MSVC has a fairly good one. It sounds like you might be dereferencing an "end" iterator or an iterator inside an empty container.

On other notes, that code hurts my eyes :P

You should really be using range-for loops.
MarkovNode constructor is unnecessary and inefficient, you should just use default initialization (totalLinksCount = 0;).
This is incredibly overcomplicated. Just have each node store its own string and a std::list of its children.
Logged
Pages: 1 ... 317 318 [319] 320 321 ... 796