Adam's Lair Forum

game development and casual madness
It is currently 2018/12/18, 16:10

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: 2018/08/21, 09:11 
Novice Member
Novice Member

Joined: 2018/06/17, 19:09
Posts: 11
Role: Hobbyist
SirePi wrote:
There is not a right or wrong way to do it, as with many other things, it pretty much depends on your own preference.
Personally, if it's an object that provides engine-related behavior (i.e. implements any of the ICmpInterfaces), then it's a Component; if it's something that multiple objects or entities reference, and does not require ICmpInterfaces, then probably it's modeled as a static object, or at the very least accessed through a game-wide singleton. In all other cases it's a simple object.

That's pretty much how I was thinking it. It feels pretty straight forward that when ICmpUpdatable is needed, it's a component. But when ICmpInitializable could be used, often it feels easier to just make it so that some active component calls the methods of that said class, instead of using the ICmpInitializable. Maybe a good way to learn this would be that first I make extensive use of Components ( make pretty much everything a component) and start dropping the components if it seems it won't make sense for the said class to be a component?

SirePi wrote:
why not use an enum? the small size of an int (or even just a byte, really) with the full expressiveness of a string

I must look into that, I guess that's the best solution. But generally, how important it is to make the objects as small as possible? Let's say the map size is between 100x100 and 1000x1000 and basically all of those tiles would contain X amount of characters ( some of which are very simple, like the bear example and some more complex)


Top
 Profile  
 
PostPosted: 2018/08/21, 18:35 
Site Admin
Site Admin
User avatar

Joined: 2013/05/11, 22:30
Posts: 2063
Location: Germany
Role: Professional
StrigoiTyrannus wrote:
But generally, how important it is to make the objects as small as possible? Let's say the map size is between 100x100 and 1000x1000 and basically all of those tiles would contain X amount of characters ( some of which are very simple, like the bear example and some more complex)


Smaller is always better, but usually you don't need to worry about that at all. If you want to get an idea of how much memory you need, just sum up the field sizes of your data to get a rough estimate. Let's say you express a single cell as follows:

Code:
public struct CellInfo
{
    public float SomeValue;
    public int SomethingElse;
    public Vector3 SomeVector;
    public bool SomeFlag;
    public Foo SomeReference;
}


A float is 4 bytes, an int is 4 bytes. A Vector3 consists of three floats, so it's 12 bytes. A bool is just one byte, but let's assume it's 4 for padding reasons. Foo is a class, and references are 4 or 8 bytes depending on architecture, but let's go with 8. The entire struct is now 4 + 4 + 12 + 4 + 8 = 32 bytes. Now let's say you put it in a Grid<CellInfo> that's 1000x1000, so you'll get 1000 * 1000 * 32 bytes of data, which is about 30 MB. Still pretty okay, considering 1000x1000 is a really huge map.

Another thing to consider: If you say a tile contains characters, that doesn't mean you have to model your tiles in a way that they actually have a list of charactes in them - lists can get costly when you have 1000x1000 of them, and most of them will probably be empty almost all the time. Just put your characters or groups somewhere else, and let each of them point to the cell they're in right now with a Point2 or similar. Same effect, much more efficient!

_________________
Blog | GitHub | Twitter (@Adams_Lair)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group