Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:05:52+00:00 2026-06-06T18:05:52+00:00

I’m considering porting the java library Artemis . An entity system framework. I havn’t

  • 0

I’m considering porting the java library Artemis. An entity system framework. I havn’t started yet. Instead I have been analyzing the internal works of how the java code is put together. I know there is half worked up CPP port.

I’ve looked at both codes and noticed that the java code puts certain things more elegantly.
And mainly the following:

package com.artemis;

import java.util.HashMap;

public class ComponentTypeManager {
    private static HashMap<Class<? extends Component>, ComponentType> componentTypes = new HashMap<Class<? extends Component>, ComponentType>();

    public static final ComponentType getTypeFor(Class<? extends Component> c){
        ComponentType type = componentTypes.get(c);

        if(type == null){
            type = new ComponentType();
            componentTypes.put(c, type);
        }

        return type;
    }

    public static long getBit(Class<? extends Component> c){
        return getTypeFor(c).getBit();
    }

    public static int getId(Class<? extends Component> c){
        return getTypeFor(c).getId();
    }
}

And the componentType “object”

package com.artemis;

public class ComponentType {
    private static long nextBit = 1;
    private static int nextId = 0;

    private long bit;
    private int id;

    public ComponentType() {
        init();
    }

    private void init() {
        bit = nextBit;
        nextBit = nextBit << 1;
        id = nextId++;
    }

    public long getBit() {
        return bit;
    }

    public int getId() {
        return id;
    }
}

Basically what the componentTypeManager does is map a componentType to a class type.
Which makes it dynamic when adding new components.

The C++ port solution is as follows:

#ifndef __COMPONENT_TYPE_H__
#define __COMPONENT_TYPE_H__

namespace SGF
{
    enum ComponentType 
    {
        CT_TRANSFORM = 0,
        CT_HEALTH,
        CT_RENDERABLE,
        CT_RIGID_BODY,
        CT_JOINT,

        CT_LAST
    };

    // Component type bits. Used by the entity systems to determine if an entity is compatible.
    const unsigned int CT_TRANSFORM_BIT  = 1 << CT_TRANSFORM;
    const unsigned int CT_HEALTH_BIT     = 1 << CT_HEALTH;
    const unsigned int CT_RENDERABLE_BIT = 1 << CT_RENDERABLE;
    const unsigned int CT_RIGID_BODY_BIT = 1 << CT_RIGID_BODY;
    const unsigned int CT_JOINT_BIT      = 1 << CT_JOINT;
};

#endif

Here the ComponentManager is completely left out. Instead an enum is used.
My problem with this is the fact you have to add new component types to the enumerator and the constants as “type” identifiers. The java framework allows you to pass a component class type to identify it’s id.

My question is, how would I go about to get a similar effect of passing a type to map it’s id like the Java code without hard coding enumerator types for every new component?
I know C++ doesn’t support class types as arguments. So this is rather mind boggling to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:05:55+00:00Added an answer on June 6, 2026 at 6:05 pm

    As long as you are not planning to instantiate components given their component type, and assuming that Component has one or more virtual function, using RTTI should be sufficient for your purposes. You can use unordered_map in place of HashMap, and replace the Class<C> with type_info.

    One thing I’m not certain about is how ComponentType would know what exact bits to return: the code instantiates ComponentType with no parameters when one is not found in the map, yet it’s assumed that different instances would return different patterns of set and unset bits. I assume this is because your hash map is pre-populated for known component types, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.