Home » Community » Forums » » Why Pluggable Factories Rock My Multiplayer World
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Why Pluggable Factories Rock My Multiplayer World
Post Reply 
Excellent use of the object factory system! I have now not only decided to use the system for network message handling but am going to use a version of the system to handle WorldToken events, and expand my TokenFactory to allow the soft architecture to add new tokens to the enviroment.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Why not use factory factories ? that would be fun.

Having one class per message type is not necessary, it's just for the pleasure of writing lots of classes, lots of code, and being proud to use abstract classes when not necessary.

 User Rating: 1015    Report this Post to a Moderator | Link

The problem is that if u never reference a static member of a class then linker simply gets rid of it so your map entry never becomes registered. I still didn't find solution to this problem.

 User Rating: 1015    Report this Post to a Moderator | Link

If the map's find fails, a NULL pointer will be returned. Dereferencing a NULL pointer does NOT cause a C++ language exception as the article indicates. It is undefined behavior and will probably do something weird (or crash) and the exception handler will not be entered. You should probably check the result of the find operation before trying to use it.

If your linker is removing static objects, it's busted.

 User Rating: 1015    Report this Post to a Moderator | Link

Let me amend that last part. If your linker is removing static objects that are not referenced, but the static objects have non-default constructors, then I think it is busted. How does the linker know that omitting the constructor calls is okay? It can't, so it should leave those objects in the build.

 User Rating: 1015    Report this Post to a Moderator | Link

I like this aritcle very much, Ive implemented it into my network engine. It was all working fine till one day it crashed suddenly when I compiled it.

Anyway the reason it crashed was that the static registry map was constructed after one of the makers, so when the maker called the base constructor to register it it caused an error as the map had not been created.

The way round this is to make the map a static ptr to a map. Then whan you declare it in the cpp file set it to 0. Then on the base constructor check if its 0 and if so allocate it. Then register your maker.

This raises the issue of deallocating the map. You can't put it in the destructor of the base object as it is a static member and you want it to deallocate when all the program ends.

The solution to this is have an unregister function which takes the id and erases the entry in the map. Then in that function also check the size of the map if its 0 then all objects have unregistered so delete the map.

Hope this helps
Iain Fraser

 User Rating: 1060   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by WizHarDx
Stuff

I love you. I love you so much.

 User Rating: 1383   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

What about open-source/cross platform software. I imagine that building on different platforms/compilers could cause different id constructor mappings depending on the order the static variables get initialized.

 User Rating: 1015    Report this Post to a Moderator | Link

Quote:
Original post by Anonymous Poster
What about open-source/cross platform software. I imagine that building on different platforms/compilers could cause different id constructor mappings depending on the order the static variables get initialized.
We encountered this problem and all the others mentioned so far (out of order construction, dynamic list creation, the linker removing unreferenced modules).
The linker part was solved by adding explicit references to the classes (dummy functions called somewhere within the program essentially). And the order of unique message IDs was handled by naming each message and sorting the list before using it.

But really.. It caused an enormous amount of problems for no real gain, an enum of all messages and a simple switch case somewhere dispatching messages to the appropriate classes would've worked just as well. Having to recompile large parts of the project whenever the list of messages changed certainly wouldn't have been a problem in our case.
Perhaps it could've savied time if the system had hundreds of messages or was to be extended by third parties.

 User Rating: 1492   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: