• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
NiteLordz

Physics and Triggers oh my

4 posts in this topic

I have an event driven engine. Each subsystem will fire off events that other systems and objects can register for. example. scene will fire off of an "Update" event, and skinned meshes are registered to listen for those events. OnUpdate they update the animation, etc...

now my question is this. I have N amount of triggers. And i have different cinematics that play depending on which trigger is hit. What is the best way for me to "trigger" the cinema.

Thoughts are

1) user enters trigger_0, trigger_0 calls OnTouch. Inside OnTouch i cycle thru a list of all methods that have preregistered for this trigger. This is different then teh registering i currently have.

2) trigger_0 sends an event container an triggerID. All systems and objects that register for the generic triggerOnTouch event will listen. WHen they "hear" the event, they will check to see if the triggerID is the one they care about, and if so, will do the corresponding action. if not, they will just continue on thier business as normal.

option 2 seems like a bad choice, as if i have 1000 triggers, and i only care about trigger999, i will be checking against each one.

option 1 seems counter productive to me, as it almost defeats the purpose of the event drive system.

Thanks for any input
0

Share this post


Link to post
Share on other sites
You can make the data structure that holds who registered for a message be a tree: each node has a list of objects listening for that message and a hash map of children, with each level becoming more specific. For example, when someone registers with the root node, they get all messages. The root node has two children in its hash map, triggerOnTouch and buttonActivated (or whatever other messages). When an object registers with the triggerOnTouch node, it only gets all triggerOnTouch events. The triggerOnTouch node's hash map contains the nodes for a specific triggerID, so when an object registers with it, it would get only triggerOnTouch events sent by something with that specific id.

Its kind of like a BHV tree, but for messages. I've used this before and it works really well both from a usability and performance standpoint.
0

Share this post


Link to post
Share on other sites
can you give a little more detail into that explanation. i kind of follow it... but i am kinda lost at the same point. that sounds like a option 2, where the trigger would send out messages with onTouch(ID=x) to the world. but only those that care about ID=x woudl actually do anything on that event
0

Share this post


Link to post
Share on other sites
[code]

class Message
{
unsigned int messageType;
unsigned int senderID;
}
class MessageNode
{
virtual void register(MessageReceiver* receiver, Message* messageToReceive)
{
if (messageToReceive->messageType == 0)
{
registeredReceivers.push_back(receiver);
}
else
{
std::map<unsigned int*, MessageNode*>::iterator iter;
iter = childNodes.find(messageToReceive->messageType);

if(iter == childNodes.end())
{
childNodes.insert(pair<unsigned int, MessageNode*>(messageToReceive->messageType, new MessageNodeType()));
iter = childNodes.find(messageToReceive->messageType);
}

(*iter).second.register(receiver, messageToReceive);
}
}
virtual void sendMessage(Message* message)
{
for each receiver in registeredReceivers
{
receiver.sendMessage(message)
}

MessageNode* node = childNodes[message->messageType].second;

if (node != NULL)
{
(*iter).second->sendMessage(message);
}
}

std::list<MessageReceiver*> registeredReceivers;
std::map<unsigned int*, MessageNode*> childNodes;
};
class MessageNodeType : public MessageNode
{
virtual void register(MessageReceiver* receiver, Message* messageToReceive)
{
if (messageToReceive->senderID == 0)
{
registeredReceivers.push_back(receiver);
}
else
{
std::map<unsigned int*, MessageNode*>::iterator iter;
iter = childNodes.find(messageToReceive->senderID);

if(iter == childNodes.end())
{
childNodes.insert(pair<unsigned int, MessageNode*>(messageToReceive->senderID, new MessageNodeID()));
iter = childNodes.find(messageToReceive->senderID);
}

(*iter).second.register(receiver, messageToReceive);
}
}

virtual void sendMessage(Message* message)
{
for each receiver in registeredReceivers
{
receiver.sendMessage(message)
}

std::map<unsigned int*, MessageNode>::iterator iter;
iter = childNodes.find(message->senderID);

if (iter != childNodes.end())
{
(*iter).second->sendMessage(message);
}
}
}

[/code]

[b]Message:[/b]
We use a hashed string for a lot of stuff, which is basically just a fancy unsigned int. messageType would be HashString("triggerOnTouch").hash
senderID is just whatever unique id you use to identify stuff.

[b]MessageNode:[/b]
Base class for other message managing structures. Holds a map of children keyed by the type of message.
register - first, check the message type. If it is 0, the caller is registering for all messages, so add caller to the list of registered receivers. Otherwise, call register on appropriate child node, creating it if necessary.
sendMessage - send message to all objects in registeredReceivers list (objects that want all messages) and pass along to appropriate child node (the one which is in the map with a key matching messageType).

[b]MessageNodeType:[/b]
Registered receivers all want a message of a certain type.
register - same as above, except the key is senderID instead of message type
sendMessage - same as above, except the key is senderID instead of message type

[b]MessageNodeID: [/b](not shown)
Registered receivers all want a message of a certain type from a certain sender. Same as other two classes, except doesn't have children (is a leaf node)

I just threw that together, you can make it much more elegant and simple by using comparison functions and templates rather than derived classes, and of course using something other than stl [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
That also allows you to use [b]anything[/b] you write a comparison function for, you could have all messages from a certain sender (not possible above, only specific message from specific sender) or sending to all objects within x distance of location.
1

Share this post


Link to post
Share on other sites
The obvious suggestion would be to make more detailed events. So, instead of just a onTrigger event, you have onTrigger_Area1, so you only get trigger in area1 (say, some level, world, or area of a the world).

Or, make the sub event filters more efficient, so it works more like what turch suggested. Except, your second level (under the top level onTrigger) is some sub-event that filtered similarly to the root event.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0