Note that there are some explanatory texts on larger screens.

plurals
  1. POSharing data between graphics and physics engine in the game?
    primarykey
    data
    text
    <p>I'm writing the game engine that consists of few modules. Two of them are the <strong>graphics engine</strong> and the <strong>physics engine</strong>.</p> <p><strong>I wonder if it's a good solution to share data between them?</strong></p> <p>Two ways (sharing or not) looks like that:</p> <h2>Without sharing data</h2> <pre><code>GraphicsModel{ //some common for graphics and physics data like position //some only graphic data //like textures and detailed model's verticles that physics doesn't need }; PhysicsModel{ //some common for graphics and physics data like position //some only physics data //usually my physics data contains A LOT more informations than graphics data } engine3D-&gt;createModel3D(...); physicsEngine-&gt;createModel3D(...); //connect graphics and physics data //e.g. update graphics model's position when physics model's position will change </code></pre> <p>I see two main problems:</p> <ol> <li>A lot of redundant data (like two positions for both physics and graphics data) </li> <li>Problem with updating data (I have to manually update graphics data when physics data changes)</li> </ol> <h2>With sharing data</h2> <pre><code>Model{ //some common for graphics and physics data like position }; GraphicModel : public Model{ //some only graphics data //like textures and detailed model's verticles that physics doesn't need }; PhysicsModel : public Model{ //some only physics data //usually my physics data contains A LOT more informations than graphics data } model = engine3D-&gt;createModel3D(...); physicsEngine-&gt;assignModel3D(&amp;model); //will cast to //PhysicsModel for it's purposes?? //when physics changes anything (like position) in model //(which it treats like PhysicsModel), the position for graphics data //will change as well (because it's the same model) </code></pre> <p>Problems here:</p> <ol> <li>physicsEngine cannot create new objects, just "assign" existing ones from engine3D (somehow it looks more anti-independent for me)</li> <li>Casting data in assignModel3D function</li> <li>physicsEngine and graphicsEngine must be careful - they cannot delete data when they don't need them (because second one may need it). But it's rare situation. Moreover, they can just delete the pointer, not the object. Or we can assume that graphicsEngine will delete objects, physicsEngine just pointers to them.</li> </ol> <p><strong>Which way is better?</strong></p> <p>Which will produce more problems in the future?</p> <p>I like the second solution more, but I wonder why most graphics and physics engines prefer the first one (maybe because they normally make only graphics or only physics engine and somebody else connect them in the game?).</p> <p><strong>Have they any more hidden pros &amp; contras?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload