Component System for IVBodies #30
Replies: 2 comments 5 replies
|
This will be v0.3, since it's an overhaul of IVBody API (which is currently rather massive). Just some high level thoughts for now... IVBody used to be a free object in space. Even the Sun was supposed to get an IVOrbit, since its path is just a locally perturbed orbit around the galaxy center of gravity (exactly what IVOrbit and its subclasses are designed to handle). But we're talking about making IVBody into an abstract "entity" (more on ECS below) that could be a rocket on the ground, a rover, or a building. So orbit then becomes optional. There's are benefits and costs to doing that. The cost is that all of my game code can't just query a body for its orbit periapsis. Instead it has to check if body has an orbit, get the orbit, then query the orbit. Same goes for position, geometry, size, etc. It's a pain if you have to go through 3 steps to get anything. We should think about what minimal thing an IVBody represents, and allow at least those things to be gotten from members or API getters. Current architecture for "visuals" and HUDs is that body isn't aware of them. They need information from body. Body needs nothing from them. (Note: If you're reaching into the visual for something like geometry, that's an indication that something is missing from body.) On ECS, I'll probably use a little ECS-inspired architecture for IVOrbit specifically. It's the biggest processor load now and would be prohibitive at many 1000s or 10000s of orbiting bodies. (IVSmallBodiesGroup can handle 100000s already but that's via GPU.) In v0.2, I've already overhauled most IVOrbit API to use PackedFloat64Array as the main data type. The next step is to move all orbit data and its calculations to the "S" part of ECS (class "IVOrbitSystem" or something like that). IVOrbit keeps all of its API but becomes an interface to IVOrbitSystem. I'm not interested in wholesale ECS everywhere. But I'm happy to use a better data system where it matters for performance. (Tangential note: After change above, porting IVOrbit to C++ is the logical next step for performance. This is one reason that I'm so loath to use duck-typing in anything like "physics" code.) [Edit:] I wonder if the class should be renamed IVEntity? When doing such a large change, it's often easier to code the replacement as an entirely new class rather than editing the existing class. And "body" has an astronomical implication that we're intentionally moving away from. (The name may annoy ECS fans if we're not fully ECS, but that's not a big deal.) |
|
See IVBody_REDESIGN_v0.3.md planning doc. The link points to the working doc in my develop branch, which will change more frequently than the master branch. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Heyhey, just dropping a random thought into the discussion forum here: Maybe IVBody could profit from being split into components. I think we have talked about this somewhere already shortly, but I couldn't find it for now, so sorry if I repeat myself at some spots.
The background of the thought is that with every feature added, the IVBody class tends to get bigger and bigger, combining more and more functionality into one class. It is important that IVBody keeps that functionality, but I regularly loose overview of the class simply because of its size.
At the same time, I am starting to think about extending IVBody with ground and space asset specific functionality. But sometimes, they might even combine, having e.g. antennae to display. So instead of using inheritance, it might make sense to split IVBodies' functionalities into components, and thus cleanly separate code chunks from each other.
That way, we could split the whopping almost 2000 (!) lines of code of ivbody into, let's say, the following components:
Visualizationcomponent, which handles everything in regards to visualsHUDscomponent, which handles everything in regards to hudsselectioncomponent, which handles everything in regards to selectioncamera_navigatablecomponent, containing the necessary functions for the camera to focus this objectspheroid_bodycomponent, if the body can be modelled as a spheroid, containing relevant functions (mean radius, poles, ...)small_asset_bodycomponent, if the body is too small to be a spheroid.orbitcomponent, containing everything in regards to orbit dataThe upside of this is that it separates code that does not necessarily rely on each other (or only has a one-way relationship), but also allows to configure bodies to e.g. become unselectable or unfocusable when never adding the specific components, and adding new components only to these bodies that require it. (The idea is thus closely related to ECS btw, which is often used in games with lots of bodies)
Let me know what you think. I believe such a system would require a lot of rework within the architecture, and maybe there is a better way to handle said problems other than using components.
All reactions