Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 682 683 [684] 685 686 ... 796

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

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10245 on: December 04, 2016, 03:20:14 am »

In c++, is there a good way to be able to use curly brace-enclosed lists for object initialization? The idea is that instead of creating an array and then copying the values from the array into a matrix class, I can just initialize the matrix class with the list of values.
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10246 on: December 04, 2016, 03:59:58 am »

Since C++11 it's supported initialization lists, so you can probably just declare the array inline with {} then feed it straight in, which should invoke the innate copy constructor (order the data inside the class how you want it fed in to simplify how this would work). Or you write a copy constructor in the class which takes the raw data and copies it in, if it doesn't recognize what to do with the data by itself.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10247 on: December 04, 2016, 08:52:00 am »

bump / double post, because I solve the problem TheDarkstar proposed. You can do it but you need to pull in an STL library that does it for you:

Code: [Select]
#include <initializer_list>

class Matrix4x4
{
public:
float data[16];

Matrix4x4(std::initializer_list<float> l)
{
             // create your matrix from the initializers here
};
};

int main()
{
Matrix4x4 m = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,0.0f, 0.0f, 0.0f, 0.0f,0.0f, 0.0f, 0.0f, 0.0f,0.0f, 0.0f, 0.0f };

return 0;
}

Obviously there are many ways to get the data into the matrix that don't require the use of a library, but that's the cleanest way to get the initializer list behavior working properly in your client code.
« Last Edit: December 04, 2016, 09:00:05 am by Reelya »
Logged

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10248 on: December 04, 2016, 07:17:34 pm »

bump / double post, because I solve the problem TheDarkstar proposed. You can do it but you need to pull in an STL library that does it for you:

Code: [Select]
#include <initializer_list>

class Matrix4x4
{
public:
float data[16];

Matrix4x4(std::initializer_list<float> l)
{
             // create your matrix from the initializers here
};
};

int main()
{
Matrix4x4 m = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,0.0f, 0.0f, 0.0f, 0.0f,0.0f, 0.0f, 0.0f, 0.0f,0.0f, 0.0f, 0.0f };

return 0;
}

Obviously there are many ways to get the data into the matrix that don't require the use of a library, but that's the cleanest way to get the initializer list behavior working properly in your client code.

Thanks! Until now my solution was to initialize a matrix and then use an overloading assignment operator, but this code is cleaner and easier to use.
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10249 on: December 04, 2016, 09:23:26 pm »

What's a good human-readable, non-verbose format for storing data? In my game, I'm defining the information about game entities in JSON like this:

Spoiler (click to show/hide)

Less verbose than XML, but I think I can do better. Ideally, my dream format would look like this:

Spoiler (click to show/hide)

Like python, everything would be whitespace dependent with very little punctuation. Does anything like this exist or would I need to come up with my own format? I really need to know before I move forward with my game because I'm going to be using the same format for *everything* including file locations, user data, save files, settings, etc.
« Last Edit: December 04, 2016, 09:27:20 pm by DragonDePlatino »
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10250 on: December 04, 2016, 09:35:05 pm »

Like python, everything would be whitespace dependent with very little punctuation. Does anything like this exist or would I need to come up with my own format? I really need to know before I move forward with my game because I'm going to be using the same format for *everything* including file locations, user data, save files, settings, etc.

The example provided is almost but not quite YAML. It's still got some punctuation but not as much as JSON. For some reason I don't really see it in use much. The only thing in recent memory I've seen is in Rails confs.

Check out this sample.
Logged

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10251 on: December 04, 2016, 09:59:26 pm »

Wow, YAML looks pretty great!

Spoiler (click to show/hide)

I can live with the colons and the lack of quotation marks is a plus. Unfortunately, it's far more complex than my needs so all of the existing libraries require a lot installation and boilerplate code. At this point I'm considering just rolling my own format. There are JSON parsers out there done in 200 LOC so how hard could it be?

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #10252 on: December 05, 2016, 03:40:21 am »

According to the internet, YAML is better suited for config files and JSON is better as a serializable data format and API communication format -- probably because you can tell when you're missing a part of a file with JSON and you can't do that with YAML.
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

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10253 on: December 05, 2016, 03:58:05 am »

It's pretty easy to roll your own config file reader. I made one for ini-style files a few years ago, since I didn't want to edit xml files or w/e.
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10254 on: December 05, 2016, 12:22:33 pm »

What's a good human-readable, non-verbose format for storing data?
TOML is nice, as something of a cross between YAML and .ini config file format.  Granted, for this particular example, it's not quite as pretty as YAML:
Spoiler (click to show/hide)
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

tonnot98

  • Bay Watcher
  • Damp stone located.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10255 on: December 05, 2016, 12:24:18 pm »

I programmed a swastika with a turtle in class today.

It was actually a valid answer for the online lesson.
Logged
Not sure if dying of old age is an honor or a shame for weaponmasters. On the one hand, it means they never got the opportunity to die in glorious battle. On the other hand, it means nothing could beat them in glorious battle.
Meow.

McTraveller

  • Bay Watcher
  • This text isn't very personal.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10256 on: December 05, 2016, 12:43:54 pm »

I programmed a swastika with a turtle in class today.

It was actually a valid answer for the online lesson.
This makes me imagine tonnot98 sitting at a desk with a turtle in the chair next to him. They have some programmable swastika, and are working on it together like pair-programming heroes.
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10257 on: December 05, 2016, 01:11:00 pm »

I thought of a swastika with a hand on each end, and each hand is holding some comically unrelated item, one of which is a turtle.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

tonnot98

  • Bay Watcher
  • Damp stone located.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10258 on: December 05, 2016, 01:50:28 pm »

Since I feel that I must elaborate, I drew a swastika using the turtle graphics program.
Logged
Not sure if dying of old age is an honor or a shame for weaponmasters. On the one hand, it means they never got the opportunity to die in glorious battle. On the other hand, it means nothing could beat them in glorious battle.
Meow.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10259 on: December 05, 2016, 07:35:58 pm »

Since I feel that I must elaborate, I drew a swastika using the turtle graphics program.
I thought of a swastika with a hand on each end, and each hand is holding some comically unrelated item, one of which is a turtle, which is drawing a swastika with a hand on each end, and each hand is holding ...
FTFY
Pages: 1 ... 682 683 [684] 685 686 ... 796