Page 2 of 2
Re: Wrapping My Head Around a Component-Based Architecture
Posted: Tue Jul 19, 2011 1:16 am
by EddieRingle
XianForce wrote:EddieRingle wrote:In my system, there would never be a "collision response" component. Whatever behavior is checking for collisions (if I have the behaviors doing that all, that might even be handled elsewhere), should fix the entity's position (if the entity collided with a solid object), and execute the appropriate lua function (if it exists).
The fact that you said it would "execute the appropriate lua function", shows that it IS a behavior, by the way you've defined your system...? (I was using component/behavior interchangeably)
However you want to look at it, that's how I intend on doing things at the moment (extending through Lua).
Re: Wrapping My Head Around a Component-Based Architecture
Posted: Wed Jul 20, 2011 3:43 am
by EccentricDuck
EddieRingle wrote:XianForce wrote:EddieRingle wrote:In my system, there would never be a "collision response" component. Whatever behavior is checking for collisions (if I have the behaviors doing that all, that might even be handled elsewhere), should fix the entity's position (if the entity collided with a solid object), and execute the appropriate lua function (if it exists).
The fact that you said it would "execute the appropriate lua function", shows that it IS a behavior, by the way you've defined your system...? (I was using component/behavior interchangeably)
However you want to look at it, that's how I intend on doing things at the moment (extending through Lua).
Wait, I'm confused. I thought you were going to implement your behaviors via function pointers now - hence a behavior is simply defining an entity as having access to some function that will "do stuff". What you're telling me is that the behavior will instead be implemented inside the Lua script rather than in the engine, so I'm not sure where a function pointer would fit in with that.
Re: Wrapping My Head Around a Component-Based Architecture
Posted: Wed Jul 20, 2011 11:47 am
by XianForce
EccentricDuck wrote:EddieRingle wrote:XianForce wrote:EddieRingle wrote:In my system, there would never be a "collision response" component. Whatever behavior is checking for collisions (if I have the behaviors doing that all, that might even be handled elsewhere), should fix the entity's position (if the entity collided with a solid object), and execute the appropriate lua function (if it exists).
The fact that you said it would "execute the appropriate lua function", shows that it IS a behavior, by the way you've defined your system...? (I was using component/behavior interchangeably)
However you want to look at it, that's how I intend on doing things at the moment (extending through Lua).
Wait, I'm confused. I thought you were going to implement your behaviors via function pointers now - hence a behavior is simply defining an entity as having access to some function that will "do stuff". What you're telling me is that the behavior will instead be implemented inside the Lua script rather than in the engine, so I'm not sure where a function pointer would fit in with that.
Which was kind of what I was getting at
Re: Wrapping My Head Around a Component-Based Architecture
Posted: Wed Jul 20, 2011 1:30 pm
by EddieRingle
EccentricDuck wrote:EddieRingle wrote:However you want to look at it, that's how I intend on doing things at the moment (extending through Lua).
Wait, I'm confused. I thought you were going to implement your behaviors via function pointers now - hence a behavior is simply defining an entity as having access to some function that will "do stuff". What you're telling me is that the behavior will instead be implemented inside the Lua script rather than in the engine, so I'm not sure where a function pointer would fit in with that.
No no. The behaviors are implemented via function pointers and do their job in C/C++. Lua comes into play when I want to execute logic specific to that entity (e.g., what it does when it's used).
Example:
behaviors.cpp
Code: Select all
void behavior_usable(Entity *_entity, float _delta) {
// ... Check requirements for use ...
if ( /* can be used */ ) {
g_scripting->ExecuteHook(_entity, "onUse");
}
// ... Remove object from the scene/inventory/whatever, since it's been used ...
}
potion.lua
Code: Select all
...
behaviors = {
...,
"usable"
}
function onUse()
health = entity:GetProperty("health")
if health ~= nil then
health = health + 100
entity:SetProperty("health", health)
end
end
Re: Wrapping My Head Around a Component-Based Architecture
Posted: Sat Jul 30, 2011 7:15 pm
by EccentricDuck
Got it - you call the lua script (if there's one available), then let the engine do its thing, both inside the scope of the function you have the pointer to.