Jump to content

  • Log In with Google      Sign In   
  • Create Account

fourvector

Member Since 16 May 2012
Offline Last Active Jul 13 2012 02:27 PM

Posts I've Made

In Topic: Am I over engineering? A generalized Game Action framework

12 June 2012 - 07:44 AM

Hi ApochPiQ. I've taken your very last piece of advice and decided to do away with a generalized action framework. I've realized it's more important to write a specific piece of code to handle picking things up than a framework for doing EVERYTHING. At least for now, maybe when I've written some specific pieces of code for different actions I might more easily be able to recognize a common theme among the various actions.

In Topic: Am I over engineering? A generalized Game Action framework

19 May 2012 - 09:11 AM

I'm still mulling over and playing with what you've said, ApochPiQ. I believe I understand and agree with what you've said about Data: turn CanPickUp into a piece of data instead of an interface, and you can move it around and use its functionality in a more versatile way.

I also like the idea of having Nouns as being a fundamental sort of object for storing these pieces of Data, because it closely mirrors the Entity-Component architecture.

I'm a bit confused about the distinction between a capability and a verb. It seems to me that in defining a capability, what you're really doing is implicitly defining a verb. This is how I understand what you're saying:

A capability has a perform() function, in which it does the thing which it is capable of doing, and a canPerform() function, in which it determines if it can do the thing it is capable of doing. In your example you include three capabilities:
PickUp, ContainerCapability, and ItemCapability.
In addition to their perform() and canPerform() functions, ContainerCapability and ItemCapability also have functions which are related to our understanding of how Containers and Items operate, such as Container.canFit(Item) or Item.getContainer(). I'll call functions of this type "the meat", they are what make the actual game behave in a specific fashion, as opposed to the bones, which is the scaffolding, like perform(). So capabilities hold the meat. This makes sense to me. After the meat has been defined in the capabilities, you can then construct a phrase list, with verbs being the linking up of two different capabilities. This linking defines the verb itself.

I attempted to implement this structure, but got stuck at what exactly the Container.perform() function should do. It seems as though the functionality of this function had been preempted by the PickUp.perform() function. It seems to me that Container.perform() should do what PickUp.perform() does, namely, cause an item to be contained by it. Here is where I realized that Container, in this scheme, implicitly defines a verb, namely "contain", through its perform() function. I would assume then that Item.perform() would do the exact same thing as Container.perform(), only maybe in a sort of converse way. We could really rename container and item to CanContain and CanBeContained, and the perform function on both of them does the same thing.

This implies that when we make our list of acceptable phrases, there's a natural verb that should be defined, namely contain, with the acceptable triplet being
[CanContain contain CanBeContained]

Which, when executed, does this: CanContain.perform(CanContain, CanBeContained), or CanBeContained.perform(CanContain, CanBeContained).

I suppose I'm stuck at this point. How might I define other verbs in my phrase list besides the natural verb implied by the perform() function? For instance, it makes sense that I should be able to remove an item from a container. But no combination of perform() calls from the two capabilities would implement that functionality. Do I create a CanRemove capability, with a perform() function that deals with the CanContain and CanBeContained capabilities, in a similar way to how the PickUp capability did before I subsumed it into my CanContain (Container) and CanBeContained (item) capabilities. Isn't this verging too closely on precisely what I was doing before?

I don't mean to be difficult, but I feel like I'm running around in circles in my head.


As an aside, I've been giving some thought to the kinds of functions I'd like to call on a general subject-verb-object structure. There are three groups:
Group A
boolean CanVerbNow(verb, subject, object);
boolean CanBeVerbedNow(verb, object, subject);
void do(verb, subject, object);
Group B
boolean CanVerb(verb, subject);
booean CanBeVerbed(verb,object);
Group C
set<Noun> getVerbed(verb, subject);
set<Noun> getVerbedBy(verb, object);
boolean isVerbed(verb, object);
boolean isVerbedBy(verb, subject)

Group A contains the meat, these are the functions that actually care about what the verb DOES

Group B only really care about what the verb does on a conceptual design level, but not on an actual functional programming level. They guarantee that the noun does these things, but they don't care what these things are.

Group C don't care at all what the verb does, but instead only care about semantic relationships. I've realized group C are actually questions about the topology of a directed graph, where nodes are nouns, and verbs are edges. I think it's a very interesting observation with bearing on how I should engineer my code.

A little bit of googling indicates that this problem is being though about, but maybe not much for game programming: http://en.wikipedia.org/wiki/Semantic_network

In Topic: Am I over engineering? A generalized Game Action framework

17 May 2012 - 06:48 AM

ApochPiQ,

Perhaps I am confused about what you mean by data. Data wouldn't have any functionality besides getters and setters and such. I would imagine here that the noun data would just be an enum, : {CanPickUp, CanBePickedUp, etc...}. But then in the example you've given, we have a function like subject.CanReach(object). How are these functions defined? Additionally, does every Noun need to have a CanReach(object) function, shouldn't only the ones that CanPickUp? I appreciate your help, I just feel like I must not be understanding something that you're trying to say.

In Topic: Am I over engineering? A generalized Game Action framework

17 May 2012 - 02:48 AM

ApochPiQ
I considered implementing it as data, but I wanted different CanAct and CanBeActedUpon objects to be able to modify the Action. So for instance this is PickUp:

public class PickUp implements Action{

CanPickUp subject;
CanBePickedUp object;

public PickUp(CanPickUp subject,CanBePickedUp object){
  this.object=object;
  this.subject=subject;
}

public void Act(){
  //iff the subject can pickup
  if(subject.isInReach(object) && subject.add(object)){
   //remove the object from the region
   object.removeFromWorld();
  }
}


public String getName(){
  return "Pick Up "+object.getGameObject().name;
}
}

With the CanPickUp and CanBePickedUp interfaces having the functions implied here. Now different components can implement these interfaces in different ways. For instance a land mine, when it is "removeFromWorld()" might, in addition to leaving the world, also do a test to see if it explodes, or something to that effect. In general it makes sense to me that different nouns should modify the action. With a data implementation, I'd have to construct some kind of huge case structure to account for different functionality.

6510
Is using instanceof expensive, or is it just considered bad form? To me it seems like the right thing to do. I use it frequently for my event distribution system to my components, since it seems more type safe than having some kind of string as an ID, which could be tricked, for instance, I could send a RegionChanged event, any component listening for RegionChanged events would check the type and respond in the right way.

PARTNERS