src: transform all old writable in annotations
[nit.git] / lib / mnit / mnit_null.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Dummy mnit platform for headless executions
16 #
17 # Extends `mnit_injected_input` so that the whole application is simulated.
18 # This permits more debugging and benchmarking, even without screen (thinks
19 # regression tests).
20 #
21 # Assets loading and display operations are executed with an empty body,
22 # Except on frames that have some injected input events, in theses the
23 # description of all blit operations are printed to screen.
24 module mnit_null
25
26 import mnit_app
27 intrude import mnit_injected_input
28 import mnit_fps
29 import assets
30
31 # Dummy display that just display nothing
32 class NullDisplay
33 super Display
34 redef var width = 640
35 redef var height = 480
36 redef fun begin do end
37 redef fun finish do end
38 redef fun clear(r,g,b)
39 do
40 if not app.verbose then return
41 print "CLEAR rgb({r};{g};{b})"
42 end
43 redef fun blit(image, x, y)
44 do
45 if not app.verbose then return
46 print "BLIT {image} ({x},{y})"
47 end
48 redef fun blit_centered(image, x, y)
49 do
50 if not app.verbose then return
51 print "BLIT {image} CENTERED ({x},{y})"
52 end
53 redef fun blit_rotated(image, x, y, a)
54 do
55 if not app.verbose then return
56 print "BLIT {image} CENTERED ({x},{y}) ROTATED {a}"
57 end
58 redef fun blit_rotated_scaled(image, x, y, a, s)
59 do
60 if not app.verbose then return
61 print "BLIT {image} CENTERED ({x},{y}) ROTATED {a} SCALED {s}"
62 end
63 redef fun blit_scaled(image, x, y, w, h)
64 do
65 if not app.verbose then return
66 print "BLIT {image} ({x},{y}) -- ({x+w},{y+h})"
67 end
68 redef fun blit_stretched(image, ax, ay, bx, by, cx, cy, dx, dy)
69 do
70 if not app.verbose then return
71 print "BLIT {image} ({ax},{ay}) -- ({bx},{by}) -- ({cx},{cy}) -- ({dx},{dy})"
72 end
73 end
74
75 # Dummy image for a NullDisplay
76 class NullImage
77 super Image
78 var path: String
79 redef fun to_s do return path
80 redef var scale = 1.0 is redef writable
81 redef var width = 32
82 redef var height = 32
83 end
84
85 redef class App
86 redef fun setup
87 do
88 super
89 display = new NullDisplay
90 window_created
91 end
92
93 # Force the printing of blit operations
94 # So traces of execution can be generated
95 # Managed by `generate_injected_input`
96 private var verbose = false
97
98 redef fun limit_fps do return
99
100 redef fun generate_injected_input
101 do
102 var res = super
103 verbose = res
104 return res
105 end
106 redef fun generate_input
107 do
108 # An implementation is required but to avoid infinite loops
109 # we just `quit` when the stream is closed.
110 if injected_input_stream == null then
111 print "END OF INPUT"
112 quit = true
113 end
114 end
115
116 redef fun try_loading_asset(path)
117 do
118 print "LOAD {path}"
119 return new NullImage(path)
120 end
121 end