reflexion 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -195,6 +195,8 @@ ReflexViewController_get_show_fun ()
195
195
 
196
196
  ptr_for_rebind->Xot::template RefCountable<>::release();
197
197
  ptr_for_rebind = NULL;
198
+
199
+ Window_register(pwindow);
198
200
  }
199
201
  }
200
202
 
@@ -203,6 +205,8 @@ ReflexViewController_get_show_fun ()
203
205
  [self rebind];
204
206
  if (!pwindow) return;
205
207
 
208
+ Window_unregister(pwindow);
209
+
206
210
  Window_get_data(pwindow).view_controller = nil;
207
211
 
208
212
  pwindow->release();
@@ -365,13 +369,7 @@ ReflexViewController_get_show_fun ()
365
369
 
366
370
  ++update_count;
367
371
 
368
- double now = Xot::time();
369
- Reflex::UpdateEvent e(now, now - win->self->prev_time_update);
370
- win->self->prev_time_update = now;
371
-
372
- win->on_update(&e);
373
- if (!e.is_blocked())
374
- Reflex::View_update_tree(win->root(), e);
372
+ Window_call_update_event(win);
375
373
 
376
374
  if (win->self->redraw)
377
375
  {
@@ -38,10 +38,11 @@
38
38
  if (!app)
39
39
  Reflex::argument_error(__FILE__, __LINE__);
40
40
 
41
- if (app->self->delegate)
41
+ Reflex::ApplicationData& data = Reflex::Application_get_data(app);
42
+ if (data.delegate)
42
43
  Reflex::invalid_state_error(__FILE__, __LINE__);
43
44
 
44
- app->self->delegate = [self retain];
45
+ data.delegate = [self retain];
45
46
  app->retain();
46
47
 
47
48
  application = app;
@@ -51,10 +52,11 @@
51
52
  {
52
53
  if (!application) return;
53
54
 
54
- if (application->self->delegate)
55
+ Reflex::ApplicationData& data = Reflex::Application_get_data(application);
56
+ if (data.delegate)
55
57
  {
56
- [application->self->delegate release];
57
- application->self->delegate = nil;
58
+ [data.delegate release];
59
+ data.delegate = nil;
58
60
  }
59
61
 
60
62
  application->release();
@@ -4,7 +4,7 @@
4
4
  #define __REFLEX_SRC_OSX_APPLICATION_H__
5
5
 
6
6
 
7
- #include "reflex/application.h"
7
+ #include "../application.h"
8
8
 
9
9
 
10
10
  @class ReflexAppDelegate;
@@ -14,16 +14,19 @@ namespace Reflex
14
14
  {
15
15
 
16
16
 
17
- struct Application::Data
17
+ struct ApplicationData : public Application::Data
18
18
  {
19
19
 
20
20
  ReflexAppDelegate* delegate;
21
21
 
22
- String name;
22
+ ApplicationData ();
23
23
 
24
- Data ();
24
+ };// ApplicationData
25
25
 
26
- };// Application::Data
26
+
27
+ ApplicationData& Application_get_data ( Application* app);
28
+
29
+ const ApplicationData& Application_get_data (const Application* app);
27
30
 
28
31
 
29
32
  }// Reflex
@@ -12,33 +12,33 @@ namespace Reflex
12
12
  {
13
13
 
14
14
 
15
- namespace global
15
+ Application::Data*
16
+ Application_create_data ()
16
17
  {
18
+ return new ApplicationData();
19
+ }
17
20
 
18
- static Application* instance = NULL;
19
-
20
- }// global
21
+ ApplicationData&
22
+ Application_get_data (Application* app)
23
+ {
24
+ if (!app)
25
+ argument_error(__FILE__, __LINE__);
21
26
 
27
+ return (ApplicationData&) *app->self;
28
+ }
22
29
 
23
- Application*
24
- app ()
30
+ const ApplicationData&
31
+ Application_get_data (const Application* app)
25
32
  {
26
- return global::instance;
33
+ return Application_get_data(const_cast<Application*>(app));
27
34
  }
28
35
 
29
36
 
30
- Application::Application ()
37
+ ApplicationData::ApplicationData ()
38
+ : delegate(nil)
31
39
  {
32
- if (global::instance)
33
- reflex_error(__FILE__, __LINE__, "multiple application instances.");
34
-
35
- global::instance = this;
36
40
  }
37
41
 
38
- Application::~Application ()
39
- {
40
- global::instance = NULL;
41
- }
42
42
 
43
43
  static ReflexAppDelegate*
44
44
  setup_app_delegate (NSApplication* app)
@@ -75,21 +75,6 @@ namespace Reflex
75
75
  [NSApp terminate: nil];
76
76
  }
77
77
 
78
- void
79
- Application::set_name (const char* name)
80
- {
81
- if (!name)
82
- argument_error(__FILE__, __LINE__);
83
-
84
- self->name = name;
85
- }
86
-
87
- const char*
88
- Application::name () const
89
- {
90
- return self->name.c_str();
91
- }
92
-
93
78
  void
94
79
  Application::on_start (Event* e)
95
80
  {
@@ -121,17 +106,5 @@ namespace Reflex
121
106
  return true;
122
107
  }
123
108
 
124
- bool
125
- Application::operator ! () const
126
- {
127
- return !operator bool();
128
- }
129
-
130
-
131
- Application::Data::Data ()
132
- : delegate(nil)
133
- {
134
- }
135
-
136
109
 
137
110
  }// Reflex
@@ -119,6 +119,8 @@ move_to_main_screen_origin (NativeWindow* window)
119
119
 
120
120
  ptr_for_rebind->Xot::template RefCountable<>::release();
121
121
  ptr_for_rebind = NULL;
122
+
123
+ Window_register(pwindow);
122
124
  }
123
125
  }
124
126
 
@@ -127,6 +129,8 @@ move_to_main_screen_origin (NativeWindow* window)
127
129
  [self rebind];
128
130
  if (!pwindow) return;
129
131
 
132
+ Window_unregister(pwindow);
133
+
130
134
  Window_get_data(pwindow).native = nil;
131
135
 
132
136
  pwindow->release();
@@ -197,13 +201,7 @@ move_to_main_screen_origin (NativeWindow* window)
197
201
 
198
202
  ++update_count;
199
203
 
200
- double now = Xot::time();
201
- Reflex::UpdateEvent e(now, now - win->self->prev_time_update);
202
- win->self->prev_time_update = now;
203
-
204
- win->on_update(&e);
205
- if (!e.is_blocked())
206
- Reflex::View_update_tree(win->root(), e);
204
+ Window_call_update_event(win);
207
205
 
208
206
  if (win->self->redraw)
209
207
  {
data/src/view.cpp CHANGED
@@ -235,6 +235,8 @@ namespace Reflex
235
235
  }
236
236
  else
237
237
  pbody->set_transform(frame.x, frame.y, angle);
238
+
239
+ pbody->awake();
238
240
  }
239
241
 
240
242
  void update_body_states ()
@@ -2295,9 +2297,9 @@ namespace Reflex
2295
2297
  bool capture = types != CAPTURE_NONE;
2296
2298
 
2297
2299
  if (capture && !registered)
2298
- Window_register_capture(w, this, CAPTURE_ALL);
2300
+ Window_register_capture(w, this, CAPTURE_ALL_EVENTS);
2299
2301
  else if (!capture && registered)
2300
- Window_unregister_capture(w, this, CAPTURE_ALL);
2302
+ Window_unregister_capture(w, this, CAPTURE_ALL_EVENTS);
2301
2303
 
2302
2304
  CaptureEvent e(~old & types, old & ~types);
2303
2305
  on_capture(&e);
@@ -1,48 +1,41 @@
1
- #include "reflex/application.h"
1
+ #include "../application.h"
2
2
 
3
3
 
4
4
  #include <xot/windows.h>
5
5
  #include "reflex/exception.h"
6
+ #include "window.h"
6
7
 
7
8
 
8
9
  namespace Reflex
9
10
  {
10
11
 
11
12
 
12
- namespace global
13
+ Application::Data*
14
+ Application_create_data ()
13
15
  {
14
-
15
- static Application* instance = NULL;
16
-
17
- }// global
18
-
19
-
20
- Application*
21
- app ()
22
- {
23
- return global::instance;
16
+ return new Application::Data();
24
17
  }
25
18
 
26
19
 
27
- struct Application::Data
28
- {
29
-
30
- String name;
31
-
32
- };// Application::Data
33
-
34
-
35
- Application::Application ()
20
+ static double
21
+ get_time ()
36
22
  {
37
- if (global::instance)
38
- reflex_error(__FILE__, __LINE__, "multiple application instances.");
23
+ static const double FREQUENCY_INV = []() {
24
+ LARGE_INTEGER freq;
25
+ QueryPerformanceFrequency(&freq);
26
+ return 1.0 / (double) freq.QuadPart;
27
+ }();
39
28
 
40
- global::instance = this;
29
+ LARGE_INTEGER counter;
30
+ QueryPerformanceCounter(&counter);
31
+ return (double) counter.QuadPart * FREQUENCY_INV;
41
32
  }
42
33
 
43
- Application::~Application ()
34
+ static void
35
+ update_all_windows (Application* app)
44
36
  {
45
- global::instance = NULL;
37
+ for (auto it = app->window_begin(), end = app->window_end(); it != end; ++it)
38
+ Window_update(it->get());
46
39
  }
47
40
 
48
41
  void
@@ -51,13 +44,39 @@ namespace Reflex
51
44
  Event e;
52
45
  on_start(&e);
53
46
 
47
+ timeBeginPeriod(1);
48
+
49
+ double prev = get_time();
50
+
54
51
  MSG msg;
55
- while (GetMessage(&msg, NULL, 0, 0))
52
+ while (true)
56
53
  {
57
- TranslateMessage(&msg);
58
- DispatchMessage(&msg);
54
+ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
55
+ {
56
+ if (msg.message == WM_QUIT) break;
57
+ TranslateMessage(&msg);
58
+ DispatchMessage(&msg);
59
+ }
60
+ else
61
+ {
62
+ static const double INTERVAL = 1.0 / 60.0;
63
+ static const double SLEEPABLE = INTERVAL * 0.9;
64
+
65
+ double now = get_time();
66
+ double dt = now - prev;
67
+ if (dt < INTERVAL)
68
+ {
69
+ if (dt < SLEEPABLE) Sleep(1);
70
+ continue;
71
+ }
72
+
73
+ update_all_windows(this);
74
+ prev = now;
75
+ }
59
76
  }
60
77
 
78
+ timeEndPeriod(1);
79
+
61
80
  if (msg.wParam != 0)
62
81
  reflex_error(__FILE__, __LINE__, "WM_QUIT with wParam %d.", msg.wParam);
63
82
  }
@@ -68,21 +87,6 @@ namespace Reflex
68
87
  PostQuitMessage(0);
69
88
  }
70
89
 
71
- void
72
- Application::set_name (const char* name)
73
- {
74
- if (!name)
75
- argument_error(__FILE__, __LINE__);
76
-
77
- self->name = name;
78
- }
79
-
80
- const char*
81
- Application::name () const
82
- {
83
- return self->name.c_str();
84
- }
85
-
86
90
  void
87
91
  Application::on_start (Event* e)
88
92
  {
@@ -113,11 +117,5 @@ namespace Reflex
113
117
  return true;
114
118
  }
115
119
 
116
- bool
117
- Application::operator ! () const
118
- {
119
- return !operator bool();
120
- }
121
-
122
120
 
123
121
  }// Reflex
data/src/win32/window.cpp CHANGED
@@ -1,4 +1,4 @@
1
- #include "../window.h"
1
+ #include "window.h"
2
2
 
3
3
 
4
4
  #include <assert.h>
@@ -8,7 +8,6 @@
8
8
  #include <xot/windows.h>
9
9
  #include <rays/rays.h>
10
10
  #include "reflex/defs.h"
11
- #include "reflex/application.h"
12
11
  #include "reflex/exception.h"
13
12
  #include "reflex/debug.h"
14
13
  #include "../view.h"
@@ -28,8 +27,6 @@ namespace Reflex
28
27
 
29
28
  static const char* USERDATA_PROP = "Reflex:Window:HWND";
30
29
 
31
- enum {UPDATE_TIMER_ID = 99999};
32
-
33
30
 
34
31
  struct WindowData : public Window::Data
35
32
  {
@@ -152,18 +149,12 @@ namespace Reflex
152
149
  win->release();
153
150
  }
154
151
 
155
- static void
156
- update (Window* win)
152
+ void
153
+ Window_update (Window* win)
157
154
  {
158
155
  WindowData* self = get_data(win);
159
156
 
160
- double now = Xot::time();
161
- Reflex::UpdateEvent e(now, now - self->prev_time_update);
162
- self->prev_time_update = now;
163
-
164
- win->on_update(&e);
165
- if (!e.is_blocked())
166
- Reflex::View_update_tree(win->root(), e);
157
+ Window_call_update_event(win);
167
158
 
168
159
  if (self->redraw)
169
160
  {
@@ -435,13 +426,6 @@ namespace Reflex
435
426
  break;
436
427
  }
437
428
 
438
- case WM_TIMER:
439
- {
440
- if (wp == UPDATE_TIMER_ID)
441
- update(win);
442
- return 0;
443
- }
444
-
445
429
  case WM_SYSCOMMAND:
446
430
  {
447
431
  #if 0
@@ -458,8 +442,6 @@ namespace Reflex
458
442
  static LRESULT CALLBACK
459
443
  wndproc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
460
444
  {
461
- static int window_total = 0;
462
-
463
445
  Window* win = NULL;
464
446
  if (msg == WM_NCCREATE)
465
447
  {
@@ -467,7 +449,7 @@ namespace Reflex
467
449
  win = (Window*) cs->lpCreateParams;
468
450
  setup_window(win, hwnd);
469
451
 
470
- ++window_total;
452
+ Window_register(win);
471
453
  }
472
454
 
473
455
  if (!win)
@@ -477,9 +459,11 @@ namespace Reflex
477
459
 
478
460
  if (msg == WM_NCDESTROY)
479
461
  {
462
+ Window_unregister(win);
463
+
480
464
  cleanup_window(win);
481
465
 
482
- if (--window_total == 0)
466
+ if (Window_all().empty())
483
467
  Reflex::app()->quit();
484
468
  }
485
469
 
@@ -556,28 +540,6 @@ namespace Reflex
556
540
  create_window(window);
557
541
  }
558
542
 
559
- static void
560
- start_timer (HWND hwnd, UINT id, UINT interval)
561
- {
562
- if (!hwnd)
563
- argument_error(__FILE__, __LINE__);
564
-
565
- if (!SetTimer(hwnd, id, interval, NULL))
566
- system_error(__FILE__, __LINE__);
567
- }
568
-
569
- static void
570
- stop_timer (HWND hwnd, UINT id)
571
- {
572
- if (!hwnd)
573
- argument_error(__FILE__, __LINE__);
574
-
575
- if (id == 0) return;
576
-
577
- if (!KillTimer(hwnd, id))
578
- system_error(__FILE__, __LINE__);
579
- }
580
-
581
543
  void
582
544
  Window_show (Window* window)
583
545
  {
@@ -590,8 +552,6 @@ namespace Reflex
590
552
  self->hwnd, HWND_TOP, 0, 0, 0, 0,
591
553
  SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
592
554
  UpdateWindow(self->hwnd);
593
-
594
- start_timer(self->hwnd, UPDATE_TIMER_ID, 1000 / 60);
595
555
  }
596
556
 
597
557
  void
@@ -605,8 +565,6 @@ namespace Reflex
605
565
  SetWindowPos(
606
566
  self->hwnd, NULL, 0, 0, 0, 0,
607
567
  SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE);
608
-
609
- stop_timer(self->hwnd, UPDATE_TIMER_ID);
610
568
  }
611
569
 
612
570
  void
@@ -0,0 +1,20 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_SRC_WIN32_WINDOW_H__
4
+ #define __REFLEX_SRC_WIN32_WINDOW_H__
5
+
6
+
7
+ #include "../window.h"
8
+
9
+
10
+ namespace Reflex
11
+ {
12
+
13
+
14
+ void Window_update (Window* win);
15
+
16
+
17
+ }// Reflex
18
+
19
+
20
+ #endif//EOH