Mercurial > otakunoraifu
comparison window/system.cc @ 52:15a18fbe6f21
* Known bugs added to the README
* Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author | thib |
---|---|
date | Sat, 18 Apr 2009 18:35:39 +0000 |
parents | 223b71206888 |
children | d7cde171a1de |
comparison
equal
deleted
inserted
replaced
51:cbb301016a4e | 52:15a18fbe6f21 |
---|---|
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include<SDL.h> | 28 #include <SDL.h> |
29 #include"system.h" | 29 #include "system.h" |
30 #include<iostream> | 30 #include <iostream> |
31 #include<stdio.h> | 31 #include <stdio.h> |
32 | 32 |
33 using namespace std; | 33 using namespace std; |
34 | 34 |
35 // void SDL_SetEventFilter(SDL_EventFilter filter); | 35 // void SDL_SetEventFilter(SDL_EventFilter filter); |
36 // typedef int (*SDL_EventFilter)(const SDL_Event *event); | 36 // typedef int (*SDL_EventFilter)(const SDL_Event *event); |
37 namespace System { | 37 namespace System { |
38 Main* Main::instance = NULL; | |
38 | 39 |
39 Main* Main::instance = 0; | 40 int Main::event_filter(const SDL_Event* event) { |
41 return 1; /* throw all event */ | |
42 } | |
40 | 43 |
41 int Main::event_filter(const SDL_Event* event) { | 44 Main::Main(void) { |
42 return 1; /* throw all event */ | 45 instance = this; |
43 } | 46 framerate = 20; |
47 cursor = NULL; | |
48 } | |
44 | 49 |
45 Main::Main(void) { | 50 Main::~Main() { |
46 instance = this; | 51 if (cursor) delete cursor; |
47 framerate = 20; | 52 } |
48 cursor = 0; | |
49 } | |
50 Main::~Main() { | |
51 if (cursor) delete cursor; | |
52 } | |
53 void Main::Quit(void) { | |
54 is_exit = true; | |
55 } | |
56 void Main::EnableVideo(void) { | |
57 is_video_update = true; | |
58 } | |
59 void Main::DisableVideo(void) { | |
60 is_video_update = false; | |
61 } | |
62 bool Main::is_exit = false; | |
63 bool Main::is_video_update = true; | |
64 | 53 |
65 void Main::Mainloop(void) { | 54 void Main::Quit(void) { |
66 SDL_SetEventFilter(&event_filter); | 55 is_exit = true; |
67 Uint32 old_time = 0; | 56 } |
68 while(!is_exit) { | 57 |
69 Uint32 start_time = SDL_GetTicks(); | 58 void Main::EnableVideo(void) { |
70 if (! event.Exec(start_time)) break; | 59 is_video_update = true; |
71 if (start_time - old_time > 1000/framerate) { | 60 } |
72 if (is_video_update) root.ExecUpdate(); | 61 |
73 event.Exec(Event::Time::FRAME_UPDATE); | 62 void Main::DisableVideo(void) { |
74 cout.flush(); | 63 is_video_update = false; |
75 old_time = start_time; | 64 } |
65 | |
66 bool Main::is_exit = false; | |
67 bool Main::is_video_update = true; | |
68 | |
69 void Main::Mainloop(void) { | |
70 SDL_SetEventFilter(&event_filter); | |
71 Uint32 old_time = 0; | |
72 while(!is_exit) { | |
73 Uint32 start_time = SDL_GetTicks(); | |
74 if (! event.Exec(start_time)) break; | |
75 if (start_time - old_time > 1000/framerate) { | |
76 if (is_video_update) root.ExecUpdate(); | |
77 event.Exec(Event::Time::FRAME_UPDATE); | |
78 cout.flush(); | |
79 old_time = start_time; | |
80 } | |
81 | |
82 // 問題: | |
83 // z 軸と xy 軸の相互干渉;高速化 | |
84 // 移動するウィジット描画の高速化 | |
85 // キャッシュ | |
86 // 文字列の一部のみ更新の高速化 | |
87 // 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose | |
88 /* | |
89 Uint32 end_time = SDL_GetTicks(); | |
90 Uint32 delay = (end_time-start_time); | |
91 if(delay < 1000/framerate) SDL_Delay(1000/framerate - delay); | |
92 else SDL_Delay(0); | |
93 */ | |
94 SDL_Delay(0); | |
76 } | 95 } |
96 } | |
77 | 97 |
78 // 問題: | 98 void Main::SetCursor(Surface* s, const Rect& r) { |
79 // z 軸と xy 軸の相互干渉;高速化 | 99 if (instance == 0) return; |
80 // 移動するウィジット描画の高速化 | 100 if (instance->cursor) delete instance->cursor; |
81 // キャッシュ | 101 if (s == 0) { // カーソル消去 |
82 // 文字列の一部のみ更新の高速化 | 102 instance->cursor = 0; |
83 // 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose | 103 } else if (s == DEFAULT_MOUSECURSOR) { |
84 /* | 104 instance->cursor = 0; |
85 Uint32 end_time = SDL_GetTicks(); | 105 SDL_ShowCursor(SDL_ENABLE); |
86 Uint32 delay = (end_time-start_time); | 106 } else { |
87 if(delay < 1000/framerate) SDL_Delay(1000/framerate - delay); | 107 instance->cursor = new WidMouseCursor(instance->event, instance->root.root, s, r.lx, r.ty, r.width(), r.height()); |
88 else SDL_Delay(0); | 108 instance->cursor->show(); |
89 */ | 109 SDL_ShowCursor(SDL_DISABLE); |
90 SDL_Delay(0); | 110 } |
91 }; | |
92 } | |
93 | |
94 void Main::SetCursor(Surface* s, const Rect& r) { | |
95 if (instance == 0) return; | |
96 if (instance->cursor) delete instance->cursor; | |
97 if (s == 0) { // カーソル消去 | |
98 instance->cursor = 0; | |
99 } else if (s == DEFAULT_MOUSECURSOR) { | |
100 instance->cursor = 0; | |
101 SDL_ShowCursor(SDL_ENABLE); | |
102 } else { | |
103 instance->cursor = new WidMouseCursor(instance->event, instance->root.root, s, r.lx, r.ty, r.width(), r.height()); | |
104 instance->cursor->show(); | |
105 SDL_ShowCursor(SDL_DISABLE); | |
106 } | 111 } |
107 } | 112 } |
108 } |