Ohhh I see now. The containers do their own thing with the IDs, but the IDs match up to the ID returned from your monster container?
What I thought was going on was you had an Object Container and were using that to get your object instances based on ID and then worked with those (originally I assumed a map). So what do you do if you want to add extra functionality to a Monster? For instance FireBall(), when not all Monsters should have that method? Just add every method to Monster? Or add some scripting/retrieve from file system that CornedBee was talking about and Diablo?
That makes a lot more sense now at least. I was trying to get some psuedo c++ code (obviously bubbeudo), but I found if I was retrieving Object's from an ObjectSystem then there would be no use for a functor (because I could just call it from the object), therefor a map (in MessageSystem) either, so that didn't match up with what you were saying.
Would inheriting from MessageSystem solve the problem to have them use the default handler unless defined? might be kind of illogical though.
This is some of the bubbeudo I got from your posts, without all the bells and whistles, in order to try and grasp the message system (I think I failed):
Code:
#include <iostream>
#include <vector>
#include "windows.h"
struct ObjectInfo;
class Object;
class ObjectContainer;
class Message;
class MessageSystem;
class Message
{
public:
std::vector<DWORD> ObjectIDs;
std::vector<DWORD> CommandIDs;
};
struct ObjectInfo
{
DWORD dwStartIndex;
DWORD dwEndIndex;
DWORD dwID;
DWORD *dwTextureIDs;
};
class Object
{
private:
ObjectInfo ObjectData;
public:
//queue and such here
void RecieveMessage(Message* p_Message)
{
HandleMessage(p_Message);
}
//enum commands { FIRE, ICE, LIGHTNING }
void HandleMessage(Message* p_Message)
{
//handle all commands in the message
for(int i = 0; i < p_Message->CommandIDs.size(); ++i) {
switch(p_Message->CommandIDs[i]) {
case 1: Fire(p_Message->ObjectIDs[i]);
break;
case 2: Ice(p_Message->ObjectIDs[i]);
break;
case 3: Lightning(p_Message->ObjectIDs[i]);
break;
}
}
}
void Fire(DWORD dwID) { std::cout << "Fire! on " << dwID << std::endl; }
void Ice(DWORD dwID) { std::cout << "Ice! on " << dwID << std::endl; }
void Lightning(DWORD dwID) { std::cout << "Lightning! on " << dwID << std::endl; }
DWORD GetID(void) { return ObjectData.dwID; }
void SetID(DWORD dwID) { ObjectData.dwID = dwID; }
};
class ObjectContainer
{
std::vector<Object*> m_Objects;
static ObjectContainer* m_Instance;
public:
Object* GetObject(DWORD dwID)
{
return m_Objects[dwID];
}
DWORD Add(void)
{
Object* Obj = new Object();
Obj->SetID(m_Objects.size()-1);
m_Objects.push_back(Obj);
return m_Objects.size()-1;
}
bool Remove(DWORD dwID)
{
delete m_Objects[dwID];
}
static ObjectContainer* Instance(void)
{
if(!m_Instance) {
m_Instance = new ObjectContainer;
}
return m_Instance;
}
};
ObjectContainer* ObjectContainer::m_Instance = 0;
class MessageSystem
{
private:
//std::vector<DWORD> m_Registered;
static MessageSystem* m_Instance;
public:
void RegisterObject(DWORD dwID)
{
//
}
void SendMessageToObject(Message* p_Message, DWORD dwID)
{
ObjectContainer::Instance()->GetObject(dwID)->RecieveMessage(p_Message);
}
//enum commands { DIE, STUFF }
void HandleMessage(Message* p_Message)
{
for(int i = 0; i < p_Message->CommandIDs.size(); ++i) {
switch(p_Message->CommandIDs[i]) {
case 1: //Defualt1();
break;
case 2: //Defualt2();
break;
}
}
}
static MessageSystem* Instance()
{
if(!m_Instance) {
m_Instance = new MessageSystem;
}
return m_Instance;
}
};
MessageSystem* MessageSystem::m_Instance = 0;
int main()
{
ObjectContainer* ObjCon = ObjectContainer::Instance();
MessageSystem* MsgSys = MessageSystem::Instance();
DWORD Obj = ObjCon->Add();
//MsdSys->RegisterObject(Obj);
Message* Msg = new Message;
Msg->CommandIDs.push_back(3); //Lightning Command 3
Msg->ObjectIDs.push_back(2); //Use Command on Object 2
Msg->CommandIDs.push_back(1); //Fire Command 1
Msg->ObjectIDs.push_back(4); //Use Command on Object 4
MsgSys->SendMessageToObject(Msg, Obj);
std::cin.get();
}
As you can see, HandleMessage() has a switch, and thats the only way I could visualize it. Maybe its the handler that I'm ultimately unclear on. Like if you're recieving messages that use command IDs like FIRE_BALL, then wouldn't you HAVE to use a switch to resolve the function. And if you did derive from Object in my example, then you would have to make it virtual and overwrite it in the derived so it could call its new methods. See why I'm so confused? lol.
Anyway, feel free to give up on me whenever - I won't mind. I'm having a hard time understanding because my experience with game programming is: few days; my experience in c++ is: 6 months (include vacation/school/learning flash/java).
EDIT: Updated the bubbeudo a bit based on your last posts before I go out.
EDIT: I'll reread all your posts and see if I can impliment some stuff and hopefully understand whats going on.