Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 73 74 [75] 76 77 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100485 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1110 on: June 30, 2013, 05:07:11 pm »

Why would autos increase complexity? S: They're a nod to scripting language's implicit types and also make life a lot easier. You don't need to type out std::map<int,int>::iterator or std::vector<int>::const_reverse_iterator :D

Also, I think templates are one of the big things that complicate C++. Even though honestly you don't use them much :P
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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: Programming Help Thread (For Dummies)
« Reply #1111 on: June 30, 2013, 05:08:04 pm »

I find templates very useful at the lower level toolset level, I use them indirectly a lot via the standard container classes, and explicitally at several points. I figured out how to do some pretty neat things with them for my unit testing library whilst keeping it largely out sight of the public interface.

For example, deducing whether or not a type can be streamed to a string at runtime. If it can, I can print out the value in an error message, if not I can print out the name of the class.

It can even deduce if a type is iterable or not, and do different comparisons. Like comparing each member in order for iterables, and just the objects themselves for non-iterables. I even considered checking for the == operator, and doing a byte-for-byte comparison if that's missing. May still do that eventually.

Admittedly that's no different to the reflection voodoo of languages like C#, but that it's done at the compile time is pretty cool to me xD

Between multiple inheritance, templates, operator overloading, and C++11/14 lambdas and autos and whatnot, the least of C++'s worries is from backwards C compatibility.

You do realise all of those but multiple inheritance and templates are in the majority of languages, right? :) Admittedly operator overloading is often not included (Java!!! *shakes fist*) despite being useful...but still, even lambdas are coming to Java 8 (admittedly I think they're doing it in a way that completely misses the f-ing point...so in a very Java way, I guess). And even generics are in C# and Java for a reason.
« Last Edit: June 30, 2013, 05:34:27 pm by MorleyDev »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1112 on: July 01, 2013, 03:10:00 am »

You do realise all of those but multiple inheritance and templates are in the majority of languages, right?
Java does not have multiple inheritance, neither does C#, Php or Ruby. C++, lisp, python and perl do. So with that list of "common languages", that is a very small majority ;)
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))

Killjoy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1113 on: July 01, 2013, 10:13:21 am »

Admittedly operator overloading is often not included (Java!!! *shakes fist*) despite being useful..
True, it is very sad. It is probably my most missed feature of the language.

And even generics are in C# and Java for a reason.
Templates are much more complex than generics are, and open up for some very interesting features. But if you don't know how they work you risk the compiler producing a ton of redundant code making your binaries take forever to load.
Logged
Merchants Quest me programming a trading game with roguelike elements.

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1114 on: July 01, 2013, 09:28:14 pm »

@skyrunner:
autos decrease the amount of code that needs to be written at the cost of increasing the complexity of the compilation process. In practice autos will definitely make your life easier in the vast majority of cases, but be sure not to confuse a lightweight syntax with a lightweight language!

@MorleyDev:
I wasn't saying any of the features I mentioned were not in other languages or bad in any way, simply that they added to the weight of C++ more than C backwards compatibility does (which does bring up a curious point: C++ is actually not entirely backwards compatible with C. How much of C++'s features are then C++'s own language idioms, and how many are actually C backwards compatibility?). This is speaking relative to something like scheme or javascript, both of which are much more lightweight languages. And many would argue that C is a much more lightweight language than C++ anyways.

Also a note on templates (along the vein of killjoy):
- Templates are very powerful and allow for some pretty nifty things (just take a look at boost), but templates are subtler and more complex than generics are. The underlying instructions for a generic does not change from one type to another (hence why they work only with reference types or PODs in languages that have generics). On the other hand, templates actually compile into different instructions for each type that you use. So templates are quite different from reflection+generics, since reflection happens at runtime while templates are created during compile-time and do not change their behavior during runtime.
« Last Edit: July 01, 2013, 09:31:08 pm by Normandy »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: Programming Help Thread (For Dummies)
« Reply #1115 on: July 02, 2013, 01:05:42 pm »

True they aren't the same, but the basic reasoning behind them was. Templates just grew because people figured out all this clever stuff they could do which led to more clever stuff that led to constexpr being introduced to simplify that.

I was thinking more of complexity for the programmer using C++ than complexity for the programmer of C++. I have very little capacity to care for a languages implementation difficulty, that's an implementation detail I may find technically interesting but is greatly dwarfed for me by any problems in the usage difficulty. C and it's way of doing things are what influenced a lot of C++'s design decisions. And that C-weight adds more to C++'s usage difficulty than anything else in the language.

It's C++11 may be more complex feature-wise but for the programmer it's much simpler. And quite frankly, the end user shouldn't need to care about the pains the programmer went through. They do occasionally, but they shouldn't have to. A programmer is just the end-user of both the ones who created the compiler and the language :)
« Last Edit: July 02, 2013, 01:08:01 pm by MorleyDev »
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #1116 on: July 19, 2013, 12:05:55 am »

I'm programming in java, and I have a single string that I want to get a float out of. I'm currently creating a new scanner, and using that, but it seems really inefficient. Is there a better way? Alternatively, is there a way to store that float in an xml document as something other than a string? I'm using org.w3c.dom for my xml managing.
« Last Edit: July 19, 2013, 12:11:56 am by Angle »
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

JanusTwoface

  • Bay Watcher
  • murbleblarg
    • View Profile
    • jverkamp.com
Re: Programming Help Thread (For Dummies)
« Reply #1117 on: July 19, 2013, 12:12:39 am »

If the string only has the number (you can pull it out with a regular expression or substring) then this will do what you want:

Code: [Select]
float Float.parseFloat(String s)
Here's the documentation: parseFloat
Logged
You may think I'm crazy / And I think you may be right
But life is ever so much more fun / If you are the crazy one

My blog: Photography, Programming, Writing
Novels: A Sea of Stars, Confession

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #1118 on: July 19, 2013, 12:21:46 am »

Aha! Thank you.
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

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1119 on: July 31, 2013, 01:26:08 pm »

How would you suggest I handle pathfinding?  In particular, the code is Python and simple pathfinding is good enough.  Ideally I'd like something similar to DF, with priorities of 'don't pass through here if you can avoid it' and whatnot.

In a bit more specifics, the idea is to have, more or less, 'DF on a spaceship' and deal with issues like spacing and whatnot, so ideally it'd run a test 'pathfind to this location safely' and then 'pathfind here and use a space suit'.

EDIT:
http://www.policyalmanac.org/games/aStarTutorial.htm
This is the best thing.
« Last Edit: July 31, 2013, 02:46:05 pm by Girlinhat »
Logged

JanusTwoface

  • Bay Watcher
  • murbleblarg
    • View Profile
    • jverkamp.com
Re: Programming Help Thread (For Dummies)
« Reply #1120 on: July 31, 2013, 03:05:01 pm »

Another option (depending on how far along you are) would be to use libtcod. That will primarily give you a Roguelike rendering system--even if you plan on something more eventually, it's a good start so far as getting things working quickly--but they also have pathfinding algorithms built in.
Logged
You may think I'm crazy / And I think you may be right
But life is ever so much more fun / If you are the crazy one

My blog: Photography, Programming, Writing
Novels: A Sea of Stars, Confession

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1121 on: July 31, 2013, 03:27:35 pm »

I'm using libtcod, but the A* pathfinding included is a little... simple?  From what I could tell, it only registers a few simple variables.  Instead I want to deal with a lot of potential options, which is going to make pathfinding into a very large function.

For instance, it could determine the fastest route from the bridge to the engine rather easily.
Finding the route for a scientist to get from the living quarters to the science bay could be a problem if the most direct route is through the engine room - somewhere they really want to avoid because of the high levels of radiation, so it gets flagged "very expensive to move through".
Although if that particular crewman was some sort of rock-man, he might be resistant to radiation, so passing through the engine room would be flagged 'only a little expensive to move through'.

I'd need something customized enough to handle many variables from many unit types through many terrain types, so doing something custom would be ideal.

monkey

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1122 on: July 31, 2013, 04:14:21 pm »

You can do that with libtcod using callbacks instead of a tcodmap.

http://doryen.eptalys.net/data/libtcod/doc/1.5.2/html2/path_init.html, ie:
I dont use python but something like:
Code: [Select]
def path_func(xFrom,yFrom,xTo,yTo,userData) :
    return 1.0*radiation_level[xTo][yTo]

path_new_using_function(width, height, path_func, user_data=0, diagonalCost=1.41)
« Last Edit: July 31, 2013, 04:48:46 pm by monkey »
Logged

dennislp3

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1123 on: August 01, 2013, 01:30:46 am »

Pardon my potential ignorance...but would it not be an easier solution to have weighted terrain be a separate painted or set variable assigned to certain terrains that the path finding then calculates when being asked to potentially move through that room...it sounds like your trying to make path finding and weighted terrain the same thing/system. I would imagine adding a path cost (defaulting to say 1 per tile) function to the path finding would be easier than a system which ties to dynamically assign a weight as it calculates the path
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1124 on: August 01, 2013, 08:09:30 am »

Each tile will be given a list of dangers, like vacuum, hazardous atmosphere, radiation, etc.  This will by listed on the tile's info.  When pathfinding begins, each danger is assigned a modifier, based on what unit is starting the pathfinding.  So calling the function will look like path(start, end, vacuum_weight, radiation_weight).  A regular human might get path([1,1], [10,10], 1, 1) - they takes 100% damage from vacuum and radiation.  A 'rockman' on the other hand, man not need to breathe and may suffer lesser damage from radiation, so if a rockman was going somewhere it'd be path([1,1], [10,10], 0, .5).

When calculating pathing cost, it has 3 factors to sum up.  Regular pathfinding is F = G + H which is Total = Movement_Cost + Estimated_Distance.  This helps going straight for the target instead of checking all sorts of path options.  For mine, it'll be F = G + H + D.  Total = Movement_Cost + Estimated_Distance + Danger.  The "Danger" is factored against the unit's resistances, so it'd be vacuum_danger * vacuum_resistance - humans trying to path through a radiation saturated zone would get something like +1,000 to the cost to move through that tile, while a rockman would only get a +500 cost to move.

Eventually this would also be weighted against that particular unit's personality types - a "reckless" human might get a 20% cost reduction to all danger, so they'd be more likely to run through brief bouts of radiation to get somewhere more quickly and take radiation sickness, while an "unrepentant coward" might get a 1000x multiplier on danger weight, and simply refuse to pass through any dangerous terrain.
Pages: 1 ... 73 74 [75] 76 77 ... 91