修訂 | 38 (tree) |
---|---|
時間 | 2009-02-27 14:11:42 |
作者 | karasimiso |
#15210 KeyActionをプールする
@@ -27,27 +27,32 @@ | ||
27 | 27 | #include "KeyAction.h" |
28 | 28 | #include "KeyEntry.h" |
29 | 29 | #include "Scene/SceneMediator.h" |
30 | +#include "GC.h" | |
30 | 31 | |
31 | -KeyAction::KeyAction(ActionFO* target, ActionCommand* pressed, ActionCommand* released) | |
32 | +KeyAction* KeyAction::create(ActionFO* target, ActionCommand* pressed, ActionCommand* released) | |
32 | 33 | { |
33 | 34 | if ( released == NULL ) { |
34 | 35 | throw ("KeyAction::KeyAction(ActionFO*, ActionCommand*, ActionCommand*): NULL pointer is set.\n"); |
35 | 36 | } |
36 | - setTarget(target); | |
37 | - setCommandPressed(pressed); | |
38 | - setCommandReleased(released); | |
37 | + KeyAction* ka = GC<KeyAction>::getInstance(); | |
38 | + ka->setTarget(target); | |
39 | + ka->setCommandPressed(pressed); | |
40 | + ka->setCommandReleased(released); | |
41 | + return ka; | |
39 | 42 | } |
40 | 43 | |
41 | -KeyAction::KeyAction(ActionFO* target, KeyEntry* keyEntry) | |
44 | +KeyAction* KeyAction::create(ActionFO* target, KeyEntry* keyEntry) | |
42 | 45 | { |
43 | 46 | if ( keyEntry->commandReleased == NULL ) { |
44 | 47 | throw ("KeyAction::KeyAction(ActionFO*, KeyEntry*): NULL pointer is set.\n"); |
45 | 48 | } |
46 | - setTarget(target); | |
47 | - setCommandPressed(keyEntry->commandPressed); | |
48 | - setCommandReleased(keyEntry->commandReleased); | |
49 | - setKeyName(keyEntry->keyName); | |
50 | - setKeySym(keyEntry->keySym); | |
49 | + KeyAction* ka = GC<KeyAction>::getInstance(); | |
50 | + ka->setTarget(target); | |
51 | + ka->setCommandPressed(keyEntry->commandPressed); | |
52 | + ka->setCommandReleased(keyEntry->commandReleased); | |
53 | + ka->setKeyName(keyEntry->keyName); | |
54 | + ka->setKeySym(keyEntry->keySym); | |
55 | + return ka; | |
51 | 56 | } |
52 | 57 | |
53 | 58 | void KeyAction::setTarget(ActionFO* target) |
@@ -84,7 +89,7 @@ | ||
84 | 89 | { |
85 | 90 | commandPressed->destroy(); |
86 | 91 | commandReleased->destroy(); |
87 | - delete this; | |
92 | + GC<KeyAction>::destroy(this); | |
88 | 93 | } |
89 | 94 | |
90 | 95 | void KeyAction::destroy(SceneMediator* mediator) |
@@ -101,7 +106,7 @@ | ||
101 | 106 | |
102 | 107 | KeyAction* KeyAction::clone() |
103 | 108 | { |
104 | - KeyAction* keyAction = new KeyAction(target, commandPressed->clone(), commandReleased->clone()); | |
109 | + KeyAction* keyAction = KeyAction::create(target, commandPressed->clone(), commandReleased->clone()); | |
105 | 110 | keyAction->setKeyName(getKeyName()); |
106 | 111 | keyAction->setKeySym(getKeySym()); |
107 | 112 | return keyAction; |
@@ -280,7 +280,7 @@ | ||
280 | 280 | |
281 | 281 | void ActionFO::addKeyAction(KeyEntry* keyEntry) |
282 | 282 | { |
283 | - keyAction.push_back( new KeyAction(this, keyEntry) ); | |
283 | + keyAction.push_back( KeyAction::create(this, keyEntry) ); | |
284 | 284 | } |
285 | 285 | |
286 | 286 | void ActionFO::setDamageAmount(int amount) |
@@ -41,13 +41,13 @@ | ||
41 | 41 | ActionCommand* commandReleased; |
42 | 42 | ActionFO* target; |
43 | 43 | public: |
44 | - KeyAction(ActionFO* target, ActionCommand* pressed, ActionCommand* released); | |
45 | - KeyAction(ActionFO* target, KeyEntry* keyEntry); | |
46 | 44 | void setTarget(ActionFO* target); |
47 | 45 | void setCommandPressed(ActionCommand* command); |
48 | 46 | void setCommandReleased(ActionCommand* command); |
49 | 47 | virtual bool keyPressed(SceneMediator* mediator); |
50 | 48 | virtual bool keyReleased(SceneMediator* mediator); |
49 | + static KeyAction* create(ActionFO* target, ActionCommand* pressed, ActionCommand* released); | |
50 | + static KeyAction* create(ActionFO* target, KeyEntry* keyEntry); | |
51 | 51 | void destroy(); |
52 | 52 | void destroy(SceneMediator* mediator); |
53 | 53 | KeyAction* clone(); |
@@ -1,3 +1,9 @@ | ||
1 | +* Mon Feb 23 2009 karasimiso <karasimiso@users.sourceforge.jp> 1.1 | |
2 | +- 内部フォーマットを調整して画像描画を高速化 | |
3 | +- <発射>タグを通した循環参照によって一般保護例外が発生するバグの修正 | |
4 | +- <テキスト>タグの実装 | |
5 | +- KeyActionのオブジェクト管理をGCに任せる | |
6 | + | |
1 | 7 | * Mon Feb 2 2009 karasimiso <karasimiso@users.sourceforge.jp> 1.0.2 |
2 | 8 | - <進路維持>タグの不具合を修正 |
3 | 9 |