Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 312 313 [314] 315 316 ... 796

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

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4695 on: July 19, 2013, 11:04:25 pm »

Best not to compare C# to C/C++.  It turns out that it's the Microsoft equivalent of Java and should probably be treated as such.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4696 on: July 19, 2013, 11:23:51 pm »

So, I'm hitting a wall here, and I have no clue why:

Code: [Select]
void a(const char* s) { // do something; }
void a(string s) { a(s.c_str()); } // error


The error is an ambiguous call, listing a(const char*) and a(string) as candidates. However, a(s.c_str()) exactly matches a(const char*), so it should unambiguously resolve to the first overload.

Dafuq is going on?

EDIT: Changed the description because I misread the error message, but still the same problem.

EDIT2: Disregard, it was an issue with namespaces, and the fact that I forgot to wrap the definitions of the functions in the same namespace where their prototypes resided.
« Last Edit: July 19, 2013, 11:28:28 pm by Mego »
Logged

Skyrunner

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

This code seems to show no errors. That's with -Wall and 'treat warnings as errors' on. Maybe it's a compiler-specific error?

Code: [Select]
#include <string>
#include <iostream>

using namespace std;

void a(const char* s) { cout << "boop! " << s; }
void a(string s) { a(s.c_str()); }

int main()
{
a(string("hello world"));
}
output is boop! hello world as expected.
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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4698 on: July 19, 2013, 11:31:42 pm »

See above, I forgot the namespace wrapper :P

Angle

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

I'm using XML for the raws for my game, and I'm trying to figure out which particular bit of tech to use. All my program does with the xml is load it, copy down data, and then close it. I'm currently writing in java, and using the DOM, which works, but some of it is a little overly complicated - I have to load everything as a string and then interpret it, despite using a schema to declare some things as other data types. Any advice on which XML tech I should use?
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

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4700 on: July 20, 2013, 03:31:00 pm »

I stick with simple XML structures, and then I just use an XML stream parser stepping through each token. Specifically Qt QXMLStreamReader and Writer. There seems to be something equivalent for Java called StAX.

edit: Or perhaps more specifically the javax.xml.stream package.
« Last Edit: July 20, 2013, 03:45:51 pm by olemars »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4701 on: July 20, 2013, 09:57:22 pm »

Wouldn't a map/dictionary-based storage format like YAML or JSON (which I use) be easier to use, and more intuitive than XML? o_O
In fact, it's really easy to make a file that outputs json using Perl, because it has minimal tags.
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 #4702 on: July 20, 2013, 10:25:47 pm »

Perhaps. I've already learned xml, though, and it seems pretty decent. Just out of curiosity, how would I present

Spoiler (click to show/hide)

in JSON?
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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4703 on: July 20, 2013, 10:32:43 pm »

Code: [Select]
{
"materials" :
[
{
"name" : "steel",
"symbol" : "I",
"color" : "GRAY",
"density" : 5
},
{
"name" : "iron",
"symbol" : "B",
"color" : "LIGHT_GRAY",
"density" : 5
}
],

"items" :
[
{
"singular" : "Sword",
"plural" : "Swords",
"adjective" : "Sword",
"show name" : "true",
"symbol" : "\",
"volume" : 5.0,
"mass" : [ "volume", "density", "*" ]
}
]
}

Should work.
I'm not sure about the items: [] part, because I usually put material defs and item defs in different json files. o.O

Reading the file is pretty simple using jsoncpp or picojson. It works just like C++'s std::map, but layered.
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 #4704 on: July 20, 2013, 10:36:49 pm »

Hmm. Well, I'll look into it- I'm using java though, so I'll need to find different libraries.
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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4705 on: July 20, 2013, 11:11:03 pm »

Hmm. Well, I'll look into it- I'm using java though, so I'll need to find different libraries.

Or a different language

* Mego snickers

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4706 on: July 21, 2013, 02:26:09 am »

After learning about and using JSON I fell in love with it and use it in place of XML everywhere I can.  I'd intended to use it as the configuration format for the game I'm working on now actually.

Admittedly I feel a bit silly for thinking that V8 would make loading and using such files easier.  I'd intended to use V8 as a scripting system for map triggers and possibly AI, but it would have been a nice side feature.

After getting V8 to work I now realize I'd be much better off just using a JSON parsing library and leave V8 to the scripting stuff.  Getting the config values out of it would be pretty annoying after V8 was done with it.  :)

Edit: Actually, I take that back.  Maybe it wouldn't be so bad.  You could just have it compile a script that wrapped the JSON in a JSON.parse call and returned the object.  Then the C++ function that called the config loader would just store a persistent handle to the returned object somewhere that you'd query the values out of.
« Last Edit: July 21, 2013, 02:28:47 am by Telgin »
Logged
Through pain, I find wisdom.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4707 on: July 21, 2013, 03:59:26 pm »

There's nothing wrong with using xml; especially if you already know it.  Plus the Java API supports it without external libraries.  Offhand, I'm not familiar with any json libraries for Java, but they're out there.  You could also devise your own format and write a parser for it.  Not actually all that hard.  I'm not familiar with your game, but why you want to externalize this data?  You could save yourself about a thousand times worth of work by hard coding that data.  Not saying you should do that, but make sure you have a good reason for doing whatever you choose to do.
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #4708 on: July 21, 2013, 04:54:21 pm »

To make it more easily mod-able. I found a library, json.simple, and am switching to it right 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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4709 on: July 21, 2013, 05:37:11 pm »

I Feel Smart!

I've been dealing with Java for far too long. I was attempting to store raw types of a templated class in a container, not thinking about how raw types don't exist in C++, because templates are not generics. So I was staring at my code for a while, trying to figure out how to store objects of any instantiation of a templated class in the container. And then it hit me.

My class:

Code: [Select]
template<class T>
class MyClass {
public:
    typedef T value_type;
protected:
    value_type data;
    // other class guts
public:
    MyClass() = delete; // get that shit out of here
    MyClass(MyClass&) = delete; // also get that shit out of here
    MyClass(value_type val): data(val) { // do some smart-looking stuff here }
    virtual ~MyClass() { // undo above smart-looking stuff }
    value_type getdata() { return this->data; }
};

The solution? Derive the templated class from an abstract base class!

Code: [Select]
class MyBase {
public:
    typedef void* value_type; // needed something here, so why not voidberg?
    MyBase() = delete; // gtfo
    MyBase(MyBase&) = delete; // also gtfo
    virtual ~MyBase() {}
    virtual value_type getdata() = 0; // yay pure virtual functions
};

template<class T>
class MyClass: public MyBase {
    // as above
};

Now it works flawlessly! Remember kids, polymorphism is your friend!
Pages: 1 ... 312 313 [314] 315 316 ... 796