Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 706 707 [708] 709 710 ... 795

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10605 on: June 25, 2017, 04:03:01 am »

It's more portable because it will work in all languages, many compatible languages do not support multiple inheritance.

It's more flexible because you get to determine what components go into which "type" at runtime, and you can mix and match components rather than needing to explicitly define every type in code.

Also, you don't need to virtualize your vector that's holding the gui_elements, which means you can have references / concrete types instead of needing pointers everywhere in your client code.

If you think it's more complex then you should actually write out the code that you would need in the multiple inheritance / polymorphics type case. It's a lot, lot, lot more complex.

e.g. say your base type is gui_element, then you inherit from three different interfaces to get the virtuals:
Code: [Select]
class gui_draw
{
    virtual void draw() {};
}

class gui_update
{
    virtual void update() {};
}

class gui_input
{
    virtual void input() {};
}

Now, you also have a "gui_element" base class:

class gui_element
{
}

and your concrete element inherits from all of those:

class gui_button: public gui_element, public gui_draw, public gui_update, public gui_input
{
    // override each of the virtual functions here
    void draw() { // my draw };
    void update() { // my update };
    void logic() { // my logic };
}

then, since you want to store different types of gui_element inside a data structure you need to define a vector of gui_element pointers:

vector<gui_element*> elements;

now, since they're [i]pointers[/i] you have to use new and delete whenever you add a new element:

gui_element *g = new gui_button;
elements.push_back(g);

Compare that to doing the same thing with components:

Code: [Select]
gui_element is the cocrete class of all ui elements:

class gui_element
{
    gui_component *m_draw;
    gui_component *m_input;
    gui_component *m_update;

    void draw()
    {
        if(m_draw) m_draw->process(this);
    }
    void update()
    {
        if(m_update) m_update->process(this);
    }
    void logic()
    {
        if(m_logic) m_logic->process(this);
    }
    // etc
}

vector<gui_elements> elements;

elements.push_back(gui_element(/*params*/)); // notice we didn't need a pointer here

class  gui_component // only one base class needed for components
{
    virtual void process(gui_element *parent) = 0;
}

class gui_draw_button : public gui_component // wrapper for "draw button" functionality
{
    void process(gui_element *parent) { /* do the drawing */ };
} draw_button;
// etc

Now you can make gui_elements by making a constructor which takes three components:

gui_element:: gui_element(gui_component *a, gui_component *b, gui_component *c)
{
    m_draw = a;
    m_input = b;
    m_logic = c;
}

Which allows you to basically concoct variant types much faster than needing to make them all explicitly inherited types from a base class.

Plus, you don't need to refer to [b]all[/b] gui_elements by pointers now and can use references.
« Last Edit: June 25, 2017, 04:29:10 am by Reelya »
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10606 on: June 25, 2017, 04:26:26 am »

Multiple inheritance is one of those things that sounds like a good idea, but turns into a real pain when you try to use it in a real project.

Personally in this situation I would use Go interfaces, but that is rather language specific. For other languages composition would result in practically the same thing.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Mesa

  • Bay Watcher
  • Call me River.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10607 on: June 25, 2017, 06:34:06 am »

I wonder, do we have a B12 programming-focused chat on $some_service (Discord, IRC, Matrix, Gitter, whatever-the-fuck-is-hip-these-days.io...)?

And if not, would there be any sort of interest in actually doing that? (I'd certainly like to do that because apparently I feel a weird sort of anxiety trying to ask programming questions and whatnot on the forums. No clue why exactly.)

I'm willing to set it up, though I'm not the most familiar with the workings of IRC so that one might be less than preferable, but I can set something up on Discord in no time flat.
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10608 on: June 25, 2017, 06:56:36 am »

There is a bay12 Discord, but it doesn't have a programming channel.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10609 on: June 25, 2017, 02:42:56 pm »

#bay12lb irc has programmers; not a programming focused chat, but it's quiet enough to get responses to questions or interesting discussions.
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10611 on: June 25, 2017, 06:21:32 pm »

And such a nice server it is too, now it just needs more people...
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #10612 on: June 25, 2017, 08:05:32 pm »

#bay12lb irc has programmers; not a programming focused chat, but it's quiet enough to get responses to questions or interesting discussions.

server is darkmyst

it's a very quiet channel tho
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

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10613 on: August 03, 2017, 04:14:25 pm »

Unity is Y-up.  Blender is Z-up.

Y would you do Zis?
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #10614 on: August 03, 2017, 04:28:54 pm »

Unity is Y-up.  Blender is Z-up.

Y would you do Zis?
I zee what you did there.

Yeah the coordinates in Unity are a little confusing.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10615 on: August 03, 2017, 04:29:42 pm »

Just be glad you're not using Blender and Unreal Engine 4.  Because then you get to ask what setting you messed up that made your model 100x too big or small.  Or causes it to explode violently when ragdolling.  Or causes some animations to go nuts.
Logged
Through pain, I find wisdom.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10616 on: August 13, 2017, 05:14:54 pm »

EDIT

NEVER PAY ATTENTION TO ME
« Last Edit: August 13, 2017, 05:28:54 pm by 3man75 »
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10617 on: September 06, 2017, 08:05:04 am »

Just be glad you're not using Blender and Unreal Engine 4.  Because then you get to ask what setting you messed up that made your model 100x too big or small.  Or causes it to explode violently when ragdolling.  Or causes some animations to go nuts.

UE4 is also another Y-up engine. It's a PITA, honestly.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #10618 on: September 06, 2017, 10:35:50 am »

EDIT

NEVER PAY ATTENTION TO ME
Got it.
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10619 on: September 07, 2017, 12:05:00 am »

The "player" part of my music player and library app is almost done, I just need to hack around a few small issues and I can start using it.

The UI on the other hand is a kinda-sorta working train wreck of javascript and HTML. Anyone who thinks JavaScript and HTML are the future of UI design is an idiot. I want QT or some other "real" UI library with a visual designer and decent layout tools. Oh well, HTML will be OK for the prototype.

The DB server on the other hand is in pretty good shape, I just need to finish the iTunes importer (I don't use iTunes, but WinAmp can export iTunes DBs) and I can move away from the testing DB to the one I actually use. In the process I need to rewrite some aspects of the DB, in particular how albums and artists are stored. Instead of giving them their own records in the DB, I will regenerate that info from the track records and store it in memory. This will make certain things much nicer, and make it much simpler to keep the DB "clean". The nice thing is that this is all internal, the player and UI could care less, so long as the API stays unchanged (which it will).

In other words, I m nearing the point where I can start "eating my own dog food" so to speak. I expect progress to speed up greatly once there is a strong incentive to fix bugs :P
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS
Pages: 1 ... 706 707 [708] 709 710 ... 795