#21 Members - Reputation: 103
Posted 14 April 2012 - 07:49 AM
#22 Members - Reputation: 252
Posted 14 April 2012 - 08:07 AM
Then surely having a state class with event/update/render functions (which mine have always had) wouldn't be needed.
Yes and no. Yes, because the game objects are renderered and updated by thyself. However, you should need to update your logic somewhere. One possibility is to associate scripts components to game objects. The scripts have custom update functions (the only component with an update method that is called by the script manager) and know the entity (the entity could be an empty entity with just the script). Another alternative is to manage the logic partial or totally in a higher level.
It’s up to you. But yes, the components are managed only by their manager, you only modified their data.
Project page: < XNA FINAL Engine >
#23 Members - Reputation: 178
Posted 17 April 2012 - 11:18 AM
Usually, I'll have something like: title_state, menu, level1, level2, pause_menu, for example. But if each component is updating every loop (via the component managers) then surely having a state class with event/update/render functions (which mine have always had) wouldn't be needed since the component managers are being called every loop independently? The only role I can see for my game states now is just to load/remove any game entities relevant for that state. I guess it'll just take a bit of tweaking.
Your game states should also respond to the event system as well.
For example, you may want your Level state to shift to the Game Menu state after the player hits the ESCAPE button. Depending on the current state (avatar has a target or has no target) would drive whether you progress to the new state or not but the Level State would need to subscribe to the E_STATE_CHANGE event that gets triggered if a state change was needed.
Steps:
1. Keyboard Component receives ESC
2. Keyboard Component checks if entity has Target
3. If Target, dispatch E_TARGET_BLUR event to deselect target then end.
4. If No Target, dispatch E_STATE_CHANGE event with state id "GameMenu" then end.
#24 Members - Reputation: 252
Posted 17 April 2012 - 12:49 PM
Events are double edged weapons, an event call could generate garbage (it can be avoided of course), events are slower than states, you could forget to eliminate a reference with disposing the listener and more important, the code execution order could be lost. But it’s true that they are very useful in several scenarios; I use them like a message system in my engine.
EDIT: I forget that I am in a C++ thread. Some disadvantages are more for C# than C++.
Project page: < XNA FINAL Engine >
#25 Members - Reputation: 178
Posted 17 April 2012 - 01:55 PM
#26 Members - Reputation: 252
Posted 17 April 2012 - 02:17 PM
So in your design you'd have the Level State receive the ESCAPE keyboard input
For me the level state has to ask to the input manager what is the keyboard state.
query the target system using the current player as a parameter to determine if that entity had a target
If it is not a game object or component (states are not one of them) then it is managed/updated in your game logic update time using the technique you want. For the contrary, if it is a component or game object then the corresponded manager will update it in a very specific time and place (data oriented design).
Does that sound appropriate?
Project page: < XNA FINAL Engine >
#27 Members - Reputation: 1612
Posted 17 April 2012 - 06:12 PM
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
#28 Members - Reputation: 103
Posted 18 April 2012 - 10:05 AM
int Arc::run()
{
while(m_stateID != STATE_EXIT)
{
changeState();
sf::Event event;
while(m_window.pollEvent(event))
{
if(event.type == sf::Event::Closed || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
setNextState(STATE_EXIT);
m_pState->VEvents(&event);
}
m_pState->VLogic();
m_window.clear();
m_pState->VRender(&m_window);
m_window.display();
}
shutdown();
return m_exitStatus;
}As of yet I don't really have a 'input manager', more so I'm simply passing the 'sf::event' (that SFML2 provides) to each component that needs it. On a side note, SFML 2.0 RC just came out and I highly recommend it for 2D game development, if anyone is interested.






