Entity Attributes

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

no worries. I sincerely appreciate the conversation. Everyone has a different methodology, and chatting like this helps us both. I was able to rebuild my property manager system slightly based on our talk here. I still am not sure that I like the lack of strong type checking though.... anyhow, back to the grindstone for me. I will see you next time.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

well i kinda liked ur idea about the set/get thing. so i decided to add this feature. Btw my system has and had strong type checking. Its done internaly with the typeid().name() function. that way i made sure that both classes are of the same type. anyway my new system supports the following and is really awesome.

Code: Select all

class Test : public AppFrame::SAttributeContainer
{
public:
    Test(void)
    {
        Health = 100;
        Power = 100.f;
        Bind("Health", &Test::setHealth, &Test::getHealth, &Test::setHealthStr, &Test::getHealthStr);
        Bind("Power", &Power);
    }

protected:
    int Health;
    float Power;
    AppFrame::string getHealthStr(void)
    {
        char buffer[128];
        sprintf(buffer, "%i", Health);
        return buffer;
    }
    bool setHealthStr(const AppFrame::string& health)
    {
        sscanf(health.c_str(), "%i", &Health);
        return true;
    }

    bool getHealth(int& health)
    {
        health = Health;
        return true;
    }
    bool setHealth(const int& health)
    {
        Health = health;
        return true;
    }
};

int main()
{
    int value = 0;
    float value1 = 0.f;
    Test t;

    t.getValue("Health", value);
    printf("Health: %i\n", value);

    t.setValue("Health", "35");
    t.getValue("Health", value);
    printf("Health: %i\n", value);

    t.setValue("Health", 1);
    t.getValue("Health", value);
    printf("Health: %i\n", value);

    t.setValue("Health", "2");
    printf("HealthString: %s\n", t.getValue("Health").c_str());

    printf("--------------------------------------------------------------\n");

    t.getValue("Power", value1);
    printf("Power: %f\n", value1);

    t.setValue("Power", "54.02");
    t.getValue("Power", value1);
    printf("Power: %f\n", value1);

    t.setValue("Power", 87.010f);
    t.getValue("Power", value1);
    printf("Power: %f\n", value1);

    t.setValue("Power", "11.50");
    printf("PowerString: %s\n", t.getValue("Power").c_str());
}
The user has the choice to either set his own Set/Get methods or to use the premade ones.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

it looks very good. Ours are very similar , the only difference being that I need some specialized ability due to the way that the editor will use the data. very nice though, lots of folks should be interested in what you have done. i look forward to seeing where all you head with it.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Awesome i just replaced my old Attribute system with the one i just showed.
Just had to make some name changes and it works so perfect. Its double the speed of the old system. (well microseconds...) not really noticeable 8)
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply