Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Silas Reinagel
    @SilasReinagel
    For simple games, you can use any paradigm you wish. I think for serious game, the Entity-Component-System pattern is probably one of the most important patterns.
    ECS Systems completely separate the data from the functionality. They are oriented towards the Functional Programming paradigm.
    Joshua Light
    @JoshuaLight

    Hi!

    You can have objects render themselves to the SpritesBatch or render themselves into the world. That's easy

    Can you explain, how? I really see this only as a beautiful idea, but unimplementable in practice.

    VytasGit
    @VytasGit
    @JoshuaLight Do you need any domain info (damage, weight, etc.) for rendering? If not, it seems to me domain Weapon and presentation RenderableItem could be totally different objects. Weapon could encapsulate/hide its damage and have only methods like hit(something), and RenderableItem could have textures, etc. (and maybe just the ID of Weapon so it knows which item it represents), and have a method render(canvas).
    Joshua Light
    @JoshuaLight

    @VytasGit

    Well, this is actually really depends on... But, in my example domain, I need at least one getter with resulting enum ItemType, so that I know, whether this is Weapon or Armor. Then I need to check it's durability to know, should I use broken texture or just simple. Also, it's very common that Item has rarity, so that I can render blue frame or green or orange etc.

    So there will be always GETTERS:

    • getItemType().
    • getDurability().
    • getRareness().

    And, as you can see, they depend on representation, not vice versa. I don't know a proper way to do correct encapsulation and OO for such things. Yegor offen says "The whole design is wrong", but it's not even design, it's just simple case. By the way, games development domain is far more richer, than any other, because sometimes to implement some features you must be really close to real world.

    What I think is may be a good compromise is when Item itself declares another interface like ItemDocument or ItemCanvas, that interface must generalize rendering for Item as much as possible. Then I can implement that interface in game client library and use it for a proper rendering.

    As renderer I still depend on some DATA, but this data (behaviour) is concentrated in some specific API, which is not mixed with actual Item interface. Maybe this is a good compromise, I don't know...

    Laurent V.
    @monsieurluge
    Yep, the whole design is wrong. The Item doesn't care about its rarity, type and durability. It's ok when you are not designing your objects using the "tell don't ask" principle but in a proper OO way it's not as good as it sounds.
    What is the purpose of an Item ? What an Item do ?
    Do the rarity change the Item's behaviour ? I don't think so.
    Joshua Light
    @JoshuaLight

    Well, it's a key entity in games. It can be stored in inventory, it can be equiped in hand (only weapon, actually), it generalize other items: weapons (can hit, can broke), armor (can defend) and etc. There is a lot of behaviour, on which items can influence. You can drink a potion and restore health.

    For example, you have bag — technically the list of Item — and you need to render it on the screen. Also, there can be tooltip, which shows all information of item: damage, critical chance, dodge chance, etc.

    Laurent V.
    @monsieurluge
    So, in the bag you don't have the Item but an ItemDescription, which is a simple ValueObject.
    Joshua Light
    @JoshuaLight
    Even if I separate inventory representation of item and it's key object like Weapon, there is still some DATA (like damage), which influence both sides: rendering and behaviour.
    Laurent V.
    @monsieurluge
    And what about using decorators ? For example new DamagedWeapon(new Weapon(...), amount), or something like that
    The behaviour is still the same, but the decorator changes the behaviour according to the amount
    (we really need to join the Slack board ^^)
    Joshua Light
    @JoshuaLight

    This is ok. But what about rendering? How ItemDescription will know, whether it's weapon or not, what it's durability, critical chance and etc.? Do Item create ItemDescription or ItemDescription is created from Item? This dependency flow, actually, can be or from one side to other or vice versa.

    The main problem in first direction is GETTERS.
    In second — generalization (I cannot abstract rendering and representation, only with some hacks and simplifications).

    Laurent V.
    @monsieurluge
    From the game engine point of view, i know, the getters are mandatory
    Laurent V.
    @monsieurluge
    What about a PrintableItemwhich can respond to the print(to) message ?
    The PrintableItem sends only raw informations to the output (maybe through the with(name, data) message), and these informations may be critical chances or anything else. The Item does not need to know what kind of object will receive these informations
    These informations does not have behaviour attached to them. They are pure raw informations.
    Joshua Light
    @JoshuaLight

    Well, this can be good for generic engines like serialization: serializer doesn't care about anything and can work with property-value pairs. But more specific engines cannot.

    So the problem with with( name, data ) is that as RENDERER how do I know, which kinds of names are available and which one is related to durability, damage and etc.? Even if I know, how can I be sure that contract is not changed? Oh, I mentioned word contract because, as you can see, this will be just another way to implement... getters!

    It seems like the whole problem to render an item leads us to some kind of getters in one way or another.

    VytasGit
    @VytasGit

    @JoshuaLight You don't need ItemType. Just have interfaces such as Weapon, Armour, Bag, etc. If you need properties like "durability" for rendering, ask yourself - why? If it's to determine whether it's broken or not, just give it a method isBroken(). So your Renderable could encapsulate (not decorate) Item it's supposed to render and just ask it item.isBroken() ?.

    Rareness may be more tricky. Perhaps your game World should have the responsibility of tracking which items are rare and which aren't?

    And to display its stats in inventory, how about a printer? Item could have a method display(InventorySpecs), where InventorySpecs could have methods such as withWeight(int), withDamage(int), etc.
    Joshua Light
    @JoshuaLight

    Just have interfaces such as Weapon, Armour, Bag, etc.

    So you think I should use type-casting? Because only with type-casting I can check whether Item is weapon or not. Also, there are a lot of weapons here: swords, axes, maces etc. How can I determine which texture to use to render specified Weapon? With IsAxe()? This approach conceptually is almost like getters, no encapsulation at all.

    I think rareness was a bad example, because this is really a property of item, which is needed only to show player that his weapon differs from others on a quality level.

    @VytasGit

    This printers idea with InventorySpecs is a good one. As I said earlier, it looks like this is a acceptable compromise, if InventorySpecs is driven by domain model, but related only for InventoryRepresentation. Then I can create ConsoleInventorySpecs, Direct3DInventorySpecs and so on. We conceptually separated rendering from behaviour. This is still looks isomorphic to getters, but in more elegant and objective way, as for me. Will try it soon on my game, where I test such things.

    Thanks a lot for discussion and help, guys!
    VytasGit
    @VytasGit
    Why do you need to know if it's a weapon? To equip it? How about Character interface with a method equip(Weapon)?
    Laurent V.
    @monsieurluge
    Avoid type casting. Think "interface".
    Yep, the InventorySpecs is a good solution.
    Silas Reinagel
    @SilasReinagel
    @JoshuaLight There are some other flaws with this code, but here is an example: https://github.com/EnigmaDragons/MegaBuy/blob/master/MegaBuy/Pads/Pad.cs
    We composed our object graph, beginning with a parent graph who is a Scene, and then the Scene might encapsulate other Objects, each of whom is told to render themselves Draw based on a Parent Position. The calls propagate downwards until every object in the graph (each encapsulated in a specific group or container) has been told to draw himself.
    One the the flaws is that we used a Static Class that we called to do our rendered, rather than passing the SpritesBatch like we did in later projects.
    In the example code, we have a simulated Tablet Computer in the game who can switch between various In-Game Apps. Each App would do composed of it's own encapsulated objects (buttons, images, icons, text, characters... and so forth)
    Joshua Light
    @JoshuaLight

    @SilasReinagel

    I like such approach and seen it in many places, actually. But, as for me, it can be used only for UI things in UI domain. Yes, we can abstract rendering for visual things, as it has done in, for example, Avalonia UI, where guys just created something like SpriteBatch that is used in many OS and contexts.

    But when we're talking about separation of domain model from UI (I think this is obvious, why we're doing that), then all become more complicated. I think this is just theoretically impossible without getters.

    Joshua Light
    @JoshuaLight
    But what I think is that such "getters" are not even getters, because they're queries. Getters are all about direct field encapsulation.
    Silas Reinagel
    @SilasReinagel
    I also agree
    Naked data manipulation is dangerous
    But there is nothing wrong with being able to ask an object for a piece of information and receive back a message with that information
    It has to do more with the general design of the Object, and not whether it uses "getter" syntax or not.
    Joshua Light
    @JoshuaLight

    @SilasReinagel
    Agreed!

    Can you give me a link to OOP slack channel? I mailed goqp, but he is silent. ))

    Victor Noël
    @victornoel
    @JoshuaLight @goqp didn't seem to want to make it public, but anyway you need an invite to get on it, so you will have to wait for @goqp (as I am ^^).
    Joshua Light
    @JoshuaLight
    Let's wait together! ))
    Zsolt Sandor
    @sz332
    guys, give me some email address, and I try to send an invitation.
    @JoshuaLight @victornoel give me your email address and i will try to send you an invitation.
    Victor Noël
    @victornoel
    thx
    JP
    @nqafield
    @/all Do you think there's any chance of convincing Yegor to abandon Telegram and move to something that doesn't (entirely unnecessarily) require your phone number...?
    Luca Guadagnini
    @tryIO
    I don't think so :smile: but I agree there's no sense to give our phone numbers just for chatting, I suppose Slack would be another valid and better solution (as much as Discord in my opinion)
    Zsolt Sandor
    @sz332
    @tryIO a couple of us moves already to slack, ask @goqp for access
    JP
    @nqafield
    Thanks. I'll give Slack a go I think.
    Zsolt Sandor
    @sz332
    welcome. Just write me a private message with your email address, and i will try to send you an invitation.
    @nqafield ^^^^
    JP
    @nqafield
    Thanks @sz332!