User Tools

Site Tools


proton_entity_part2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
proton_entity_part2 [2010/10/27 14:09]
seth created
proton_entity_part2 [2010/10/27 14:54]
seth
Line 2: Line 2:
 What is the most useful component, one that we've already used several times at once on each entity in the last tutorial? What is the most useful component, one that we've already used several times at once on each entity in the last tutorial?
  
-The answer may surprise you.+The answer may surprise you... we'll use an extremely simple example to contrast the "old way" with the "new way".
  
-Traditionally in an entity system, you may have said I want to be able to fade out my entity by doing a simple **Entity::​FadeOut(int fadeTimeMS);​** Or possibly a more fancy **Entity::​FadeOut(int fadeTimeMS, int delayBeforeStartingFadeMS);​**+Traditionally in an entity system, you may have said //"Hey mom, I want to be able to fade out my entity by doing a simple **Entity::​FadeOut(int fadeTimeMS);​** Or possibly a more fancy **Entity::​FadeOut(int fadeTimeMS, int delayBeforeStartingFadeMS);​**"//
  
 And you'd need to add a timer to keep track of the fade which would manipulate the alpha component when rendering. ​ You may end up writing it more than once for different entity types. ​ You might end up with every entity in the game having this fade timer that most of them don't use. And you'd need to add a timer to keep track of the fade which would manipulate the alpha component when rendering. ​ You may end up writing it more than once for different entity types. ​ You might end up with every entity in the game having this fade timer that most of them don't use.
Line 10: Line 10:
 ====What'​s the Proton way to do it?==== ====What'​s the Proton way to do it?====
  
-You may say, "//well, that's ok, I'll write a FadeOutComponent//"​. ​ No, my good sir, that would be overkill. ​ Simply modifying values over time doesn'​t need a custom component.+You"//​I'​ll ​just write a FadeOutComponent//"​. ​ No, my good sir, that would be overkill. ​ Simply modifying values over time doesn'​t need a custom component.
  
 First, here is a brute force dumb way it could be done by overusing the message message manager: (but notice it does save us from needing to add any code inside the entity or any component classes, we want to keep them as pure as fresh snow) First, here is a brute force dumb way it could be done by overusing the message message manager: (but notice it does save us from needing to add any code inside the entity or any component classes, we want to keep them as pure as fresh snow)
Line 65: Line 65:
 </​code>​ </​code>​
  
-Yeah, it's almost so simple we don't even need the FadeOutEntity() wrapper at all.+Yeah, it's almost so simple we don't even need the **FadeOutEntity()** wrapper at all.
  
 ====Getting fancy: eInterpolateType and scheduling==== ====Getting fancy: eInterpolateType and scheduling====
Line 75: Line 75:
  
 Interpolate type is an optional setting that allows you to control how the interpolation works. ​ The enum gives you these options: Interpolate type is an optional setting that allows you to control how the interpolation works. ​ The enum gives you these options:
-<​code>​+<​code ​cpp>
 enum eInterpolateType enum eInterpolateType
 { {
Line 88: Line 88:
 </​code>​ </​code>​
 If you are an animator you'll shrug and know what most of these mean already. ​ If not, go visit [[http://​sol.gfxile.net/​interpolation/​index.html|Sol_HSA'​s excellent page about interpolation here]]. If you are an animator you'll shrug and know what most of these mean already. ​ If not, go visit [[http://​sol.gfxile.net/​interpolation/​index.html|Sol_HSA'​s excellent page about interpolation here]].
 +**
 +INTERPOLATE_SMOOTHSTEP** is the one you'll use the most, it's just so.. smooooooth.
  
-INTERPOLATE_SMOOTHSTEP is the one you'll use the most, it's just so.. smooooooth. +The last two tell the engine that the **uint32** should be treated as a color. ​ (it will break it up into four bytes and interpolate all four separately)
- +
-The last two tell the engine that the uint32 should be treated as a color. ​ (it will break it up into four bytes and interpolate all four separately)+
  
-The delayBeforeActionMS parm is self explanatory,​ it's useful to schedule things to happen in advance at specific times. ​ So you can play a sound effect, fade out, and then kill the entity step by step instead of all at once.+The **delayBeforeActionMS** parm is self explanatory,​ it's useful to schedule things to happen in advance at specific times. ​ So you can play a sound effect, fade out, and then kill the entity step by step instead of all at once.
  
-So, finally, let's take a look at the actual FadeEntity() function in EntityUtils.cpp:​+So, finally, let's take a look at the actual ​**FadeEntity()** function in **EntityUtils.cpp**:
  
 <code cpp> <code cpp>
Line 137: Line 137:
   * It allows you to specify the interpolation type   * It allows you to specify the interpolation type
   * It allows you to specify a delay before starting the fade   * It allows you to specify a delay before starting the fade
 +  * It let's you set what to fade to, up or down
  
 This is a great example of how you can use basic components to do interesting things. All of the helper functions in EntityUtils.cpp work this way. This is a great example of how you can use basic components to do interesting things. All of the helper functions in EntityUtils.cpp work this way.
  
proton_entity_part2.txt · Last modified: 2012/02/07 09:45 by aki