Browse Source

gittertest

Johannes Kimmel 9 years ago
parent
commit
81268686f7
9 changed files with 1521 additions and 0 deletions
  1. 4
    0
      gitter/.gitignore
  2. 835
    0
      gitter/.vim_session
  3. 18
    0
      gitter/Makefile
  4. 24
    0
      gitter/globals.h
  5. 13
    0
      gitter/main.c
  6. 349
    0
      gitter/route.c
  7. 17
    0
      gitter/route.h
  8. 244
    0
      gitter/screen.c
  9. 17
    0
      gitter/screen.h

+ 4
- 0
gitter/.gitignore View File

@@ -0,0 +1,4 @@
1
+*.o
2
+.*.sw*
3
+main
4
+gmon.out

+ 835
- 0
gitter/.vim_session View File

@@ -0,0 +1,835 @@
1
+let SessionLoad = 1
2
+if &cp | set nocp | endif
3
+let s:cpo_save=&cpo
4
+set cpo&vim
5
+imap <F12> :tabnext
6
+imap <F11> :tabprevious
7
+imap <F10> :wall
:make
:!./main
8
+imap <F9> :wall
:make
9
+imap <F8> :mksession! .vim_session
10
+map ;a :e # 
11
+map Q gq
12
+map \rwp <Plug>RestoreWinPosn
13
+map \swp <Plug>SaveWinPosn
14
+map \tt <Plug>AM_tt
15
+map \tsq <Plug>AM_tsq
16
+map \tsp <Plug>AM_tsp
17
+map \tml <Plug>AM_tml
18
+map \tab <Plug>AM_tab
19
+map \m= <Plug>AM_m=
20
+map \t@ <Plug>AM_t@
21
+map \t~ <Plug>AM_t~
22
+map \t? <Plug>AM_t?
23
+map \w= <Plug>AM_w=
24
+map \ts= <Plug>AM_ts=
25
+map \ts< <Plug>AM_ts<
26
+map \ts; <Plug>AM_ts;
27
+map \ts: <Plug>AM_ts:
28
+map \ts, <Plug>AM_ts,
29
+map \t= <Plug>AM_t=
30
+map \t< <Plug>AM_t<
31
+map \t; <Plug>AM_t;
32
+map \t: <Plug>AM_t:
33
+map \t, <Plug>AM_t,
34
+map \t# <Plug>AM_t#
35
+map \t| <Plug>AM_t|
36
+map \T~ <Plug>AM_T~
37
+map \Tsp <Plug>AM_Tsp
38
+map \Tab <Plug>AM_Tab
39
+map \T@ <Plug>AM_T@
40
+map \T? <Plug>AM_T?
41
+map \T= <Plug>AM_T=
42
+map \T< <Plug>AM_T<
43
+map \T; <Plug>AM_T;
44
+map \T: <Plug>AM_T:
45
+map \Ts, <Plug>AM_Ts,
46
+map \T, <Plug>AM_T,o
47
+map \T# <Plug>AM_T#
48
+map \T| <Plug>AM_T|
49
+map \Htd <Plug>AM_Htd
50
+map \anum <Plug>AM_aunum
51
+map \aunum <Plug>AM_aenum
52
+map \afnc <Plug>AM_afnc
53
+map \adef <Plug>AM_adef
54
+map \adec <Plug>AM_adec
55
+map \ascom <Plug>AM_ascom
56
+map \aocom <Plug>AM_aocom
57
+map \adcom <Plug>AM_adcom
58
+map \acom <Plug>AM_acom
59
+map \abox <Plug>AM_abox
60
+map \a( <Plug>AM_a(
61
+map \a= <Plug>AM_a=
62
+map \a< <Plug>AM_a<
63
+map \a, <Plug>AM_a,
64
+map \a? <Plug>AM_a?
65
+nmap gx <Plug>NetrwBrowseX
66
+nnoremap <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cWORD>"),0)
67
+nmap <silent> <Plug>RestoreWinPosn :call RestoreWinPosn()
68
+nmap <silent> <Plug>SaveWinPosn :call SaveWinPosn()
69
+nmap <SNR>12_WE <Plug>AlignMapsWrapperEnd
70
+map <SNR>12_WS <Plug>AlignMapsWrapperStart
71
+map <F12> :tabnext
72
+map <F11> :tabprevious
73
+map <F10> :wall
:make
:!./main
74
+map <F9> :wall
:make
75
+map <F8> :mksession! .vim_session
76
+let &cpo=s:cpo_save
77
+unlet s:cpo_save
78
+set autoindent
79
+set background=dark
80
+set backspace=2
81
+set fileencodings=ucs-bom,utf-8,default,latin1
82
+set helplang=en
83
+set history=50
84
+set hlsearch
85
+set ignorecase
86
+set laststatus=2
87
+set nomodeline
88
+set path=.,/usr/include,,,/usr/lib/gcc/x86_64-pc-linux-gnu/*/include
89
+set ruler
90
+set shiftwidth=4
91
+set smartcase
92
+set splitright
93
+set statusline=%<%F%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
94
+set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.info,.aux,.log,.dvi,.bbl,.out,.o,.lo
95
+set switchbuf=usetab
96
+set tabstop=4
97
+set viminfo='20,\"500
98
+let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
99
+let v:this_session=expand("<sfile>:p")
100
+silent only
101
+cd /tmp/gitter
102
+if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
103
+  let s:wipebuf = bufnr('%')
104
+endif
105
+set shortmess=aoO
106
+badd +1 main.c
107
+badd +0 route.c
108
+badd +0 screen.c
109
+badd +0 route.h
110
+badd +0 screen.h
111
+badd +0 globals.h
112
+args main.c route.c screen.c
113
+edit main.c
114
+set splitbelow splitright
115
+wincmd _ | wincmd |
116
+vsplit
117
+1wincmd h
118
+wincmd w
119
+set nosplitbelow
120
+wincmd t
121
+set winheight=1 winwidth=1
122
+exe 'vert 1resize ' . ((&columns * 158 + 158) / 317)
123
+exe 'vert 2resize ' . ((&columns * 158 + 158) / 317)
124
+argglobal
125
+inoremap <buffer> 	 =CodeComplete()
=SwitchRegion()
126
+setlocal keymap=
127
+setlocal noarabic
128
+setlocal autoindent
129
+setlocal nobinary
130
+setlocal bufhidden=
131
+setlocal buflisted
132
+setlocal buftype=
133
+setlocal cindent
134
+setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
135
+setlocal cinoptions=
136
+setlocal cinwords=if,else,while,do,for,switch
137
+setlocal colorcolumn=
138
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
139
+setlocal commentstring=/*%s*/
140
+setlocal complete=.,w,b,u,t,i
141
+setlocal concealcursor=
142
+setlocal conceallevel=0
143
+setlocal completefunc=
144
+setlocal nocopyindent
145
+setlocal cryptmethod=
146
+setlocal nocursorbind
147
+setlocal nocursorcolumn
148
+setlocal nocursorline
149
+setlocal define=
150
+setlocal dictionary=
151
+setlocal nodiff
152
+setlocal equalprg=
153
+setlocal errorformat=
154
+setlocal noexpandtab
155
+if &filetype != 'c'
156
+setlocal filetype=c
157
+endif
158
+setlocal foldcolumn=0
159
+setlocal foldenable
160
+setlocal foldexpr=0
161
+setlocal foldignore=#
162
+setlocal foldlevel=0
163
+setlocal foldmarker={{{,}}}
164
+setlocal foldmethod=manual
165
+setlocal foldminlines=1
166
+setlocal foldnestmax=20
167
+setlocal foldtext=foldtext()
168
+setlocal formatexpr=
169
+setlocal formatoptions=croql
170
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
171
+setlocal grepprg=
172
+setlocal iminsert=0
173
+setlocal imsearch=0
174
+setlocal include=
175
+setlocal includeexpr=
176
+setlocal indentexpr=
177
+setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
178
+setlocal noinfercase
179
+setlocal iskeyword=@,48-57,_,192-255
180
+setlocal keywordprg=
181
+setlocal nolinebreak
182
+setlocal nolisp
183
+setlocal nolist
184
+setlocal makeprg=
185
+setlocal matchpairs=(:),{:},[:]
186
+setlocal nomodeline
187
+setlocal modifiable
188
+setlocal nrformats=octal,hex
189
+setlocal nonumber
190
+set numberwidth=3
191
+setlocal numberwidth=3
192
+setlocal omnifunc=ccomplete#Complete
193
+setlocal path=
194
+setlocal nopreserveindent
195
+setlocal nopreviewwindow
196
+setlocal quoteescape=\\
197
+setlocal noreadonly
198
+setlocal norelativenumber
199
+setlocal norightleft
200
+setlocal rightleftcmd=search
201
+setlocal noscrollbind
202
+setlocal shiftwidth=4
203
+setlocal noshortname
204
+setlocal nosmartindent
205
+setlocal softtabstop=0
206
+setlocal nospell
207
+setlocal spellcapcheck=[.?!]\\_[\\])'\"\	\ ]\\+
208
+setlocal spellfile=
209
+setlocal spelllang=en
210
+setlocal statusline=
211
+setlocal suffixesadd=
212
+setlocal swapfile
213
+setlocal synmaxcol=3000
214
+if &syntax != 'c'
215
+setlocal syntax=c
216
+endif
217
+setlocal tabstop=4
218
+setlocal tags=
219
+setlocal textwidth=0
220
+setlocal thesaurus=
221
+setlocal noundofile
222
+setlocal nowinfixheight
223
+setlocal nowinfixwidth
224
+setlocal wrap
225
+setlocal wrapmargin=0
226
+silent! normal! zE
227
+let s:l = 1 - ((0 * winheight(0) + 43) / 87)
228
+if s:l < 1 | let s:l = 1 | endif
229
+exe s:l
230
+normal! zt
231
+1
232
+normal! 0
233
+wincmd w
234
+argglobal
235
+edit globals.h
236
+inoremap <buffer> 	 =CodeComplete()
=SwitchRegion()
237
+setlocal keymap=
238
+setlocal noarabic
239
+setlocal autoindent
240
+setlocal nobinary
241
+setlocal bufhidden=
242
+setlocal buflisted
243
+setlocal buftype=
244
+setlocal cindent
245
+setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
246
+setlocal cinoptions=
247
+setlocal cinwords=if,else,while,do,for,switch
248
+setlocal colorcolumn=
249
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
250
+setlocal commentstring=/*%s*/
251
+setlocal complete=.,w,b,u,t,i
252
+setlocal concealcursor=
253
+setlocal conceallevel=0
254
+setlocal completefunc=
255
+setlocal nocopyindent
256
+setlocal cryptmethod=
257
+setlocal nocursorbind
258
+setlocal nocursorcolumn
259
+setlocal nocursorline
260
+setlocal define=
261
+setlocal dictionary=
262
+setlocal nodiff
263
+setlocal equalprg=
264
+setlocal errorformat=
265
+setlocal noexpandtab
266
+if &filetype != 'cpp'
267
+setlocal filetype=cpp
268
+endif
269
+setlocal foldcolumn=0
270
+setlocal foldenable
271
+setlocal foldexpr=0
272
+setlocal foldignore=#
273
+setlocal foldlevel=0
274
+setlocal foldmarker={{{,}}}
275
+setlocal foldmethod=manual
276
+setlocal foldminlines=1
277
+setlocal foldnestmax=20
278
+setlocal foldtext=foldtext()
279
+setlocal formatexpr=
280
+setlocal formatoptions=croql
281
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
282
+setlocal grepprg=
283
+setlocal iminsert=0
284
+setlocal imsearch=0
285
+setlocal include=
286
+setlocal includeexpr=
287
+setlocal indentexpr=
288
+setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
289
+setlocal noinfercase
290
+setlocal iskeyword=@,48-57,_,192-255
291
+setlocal keywordprg=
292
+setlocal nolinebreak
293
+setlocal nolisp
294
+setlocal nolist
295
+setlocal makeprg=
296
+setlocal matchpairs=(:),{:},[:]
297
+setlocal nomodeline
298
+setlocal modifiable
299
+setlocal nrformats=octal,hex
300
+setlocal nonumber
301
+set numberwidth=3
302
+setlocal numberwidth=3
303
+setlocal omnifunc=ccomplete#Complete
304
+setlocal path=
305
+setlocal nopreserveindent
306
+setlocal nopreviewwindow
307
+setlocal quoteescape=\\
308
+setlocal noreadonly
309
+setlocal norelativenumber
310
+setlocal norightleft
311
+setlocal rightleftcmd=search
312
+setlocal noscrollbind
313
+setlocal shiftwidth=4
314
+setlocal noshortname
315
+setlocal nosmartindent
316
+setlocal softtabstop=0
317
+setlocal nospell
318
+setlocal spellcapcheck=[.?!]\\_[\\])'\"\	\ ]\\+
319
+setlocal spellfile=
320
+setlocal spelllang=en
321
+setlocal statusline=
322
+setlocal suffixesadd=
323
+setlocal swapfile
324
+setlocal synmaxcol=3000
325
+if &syntax != 'cpp'
326
+setlocal syntax=cpp
327
+endif
328
+setlocal tabstop=4
329
+setlocal tags=
330
+setlocal textwidth=0
331
+setlocal thesaurus=
332
+setlocal noundofile
333
+setlocal nowinfixheight
334
+setlocal nowinfixwidth
335
+setlocal wrap
336
+setlocal wrapmargin=0
337
+silent! normal! zE
338
+let s:l = 1 - ((0 * winheight(0) + 43) / 87)
339
+if s:l < 1 | let s:l = 1 | endif
340
+exe s:l
341
+normal! zt
342
+1
343
+normal! 0
344
+wincmd w
345
+2wincmd w
346
+exe 'vert 1resize ' . ((&columns * 158 + 158) / 317)
347
+exe 'vert 2resize ' . ((&columns * 158 + 158) / 317)
348
+tabedit screen.c
349
+set splitbelow splitright
350
+wincmd _ | wincmd |
351
+vsplit
352
+1wincmd h
353
+wincmd w
354
+set nosplitbelow
355
+wincmd t
356
+set winheight=1 winwidth=1
357
+exe 'vert 1resize ' . ((&columns * 158 + 158) / 317)
358
+exe 'vert 2resize ' . ((&columns * 158 + 158) / 317)
359
+argglobal
360
+3argu
361
+inoremap <buffer> 	 =CodeComplete()
=SwitchRegion()
362
+setlocal keymap=
363
+setlocal noarabic
364
+setlocal autoindent
365
+setlocal nobinary
366
+setlocal bufhidden=
367
+setlocal buflisted
368
+setlocal buftype=
369
+setlocal cindent
370
+setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
371
+setlocal cinoptions=
372
+setlocal cinwords=if,else,while,do,for,switch
373
+setlocal colorcolumn=
374
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
375
+setlocal commentstring=/*%s*/
376
+setlocal complete=.,w,b,u,t,i
377
+setlocal concealcursor=
378
+setlocal conceallevel=0
379
+setlocal completefunc=
380
+setlocal nocopyindent
381
+setlocal cryptmethod=
382
+setlocal nocursorbind
383
+setlocal nocursorcolumn
384
+setlocal nocursorline
385
+setlocal define=
386
+setlocal dictionary=
387
+setlocal nodiff
388
+setlocal equalprg=
389
+setlocal errorformat=
390
+setlocal noexpandtab
391
+if &filetype != 'c'
392
+setlocal filetype=c
393
+endif
394
+setlocal foldcolumn=0
395
+setlocal foldenable
396
+setlocal foldexpr=0
397
+setlocal foldignore=#
398
+setlocal foldlevel=0
399
+setlocal foldmarker={{{,}}}
400
+setlocal foldmethod=manual
401
+setlocal foldminlines=1
402
+setlocal foldnestmax=20
403
+setlocal foldtext=foldtext()
404
+setlocal formatexpr=
405
+setlocal formatoptions=croql
406
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
407
+setlocal grepprg=
408
+setlocal iminsert=0
409
+setlocal imsearch=0
410
+setlocal include=
411
+setlocal includeexpr=
412
+setlocal indentexpr=
413
+setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
414
+setlocal noinfercase
415
+setlocal iskeyword=@,48-57,_,192-255
416
+setlocal keywordprg=
417
+setlocal nolinebreak
418
+setlocal nolisp
419
+setlocal nolist
420
+setlocal makeprg=
421
+setlocal matchpairs=(:),{:},[:]
422
+setlocal nomodeline
423
+setlocal modifiable
424
+setlocal nrformats=octal,hex
425
+setlocal nonumber
426
+set numberwidth=3
427
+setlocal numberwidth=3
428
+setlocal omnifunc=ccomplete#Complete
429
+setlocal path=
430
+setlocal nopreserveindent
431
+setlocal nopreviewwindow
432
+setlocal quoteescape=\\
433
+setlocal noreadonly
434
+setlocal norelativenumber
435
+setlocal norightleft
436
+setlocal rightleftcmd=search
437
+setlocal noscrollbind
438
+setlocal shiftwidth=4
439
+setlocal noshortname
440
+setlocal nosmartindent
441
+setlocal softtabstop=0
442
+setlocal nospell
443
+setlocal spellcapcheck=[.?!]\\_[\\])'\"\	\ ]\\+
444
+setlocal spellfile=
445
+setlocal spelllang=en
446
+setlocal statusline=
447
+setlocal suffixesadd=
448
+setlocal swapfile
449
+setlocal synmaxcol=3000
450
+if &syntax != 'c'
451
+setlocal syntax=c
452
+endif
453
+setlocal tabstop=4
454
+setlocal tags=
455
+setlocal textwidth=0
456
+setlocal thesaurus=
457
+setlocal noundofile
458
+setlocal nowinfixheight
459
+setlocal nowinfixwidth
460
+setlocal wrap
461
+setlocal wrapmargin=0
462
+silent! normal! zE
463
+let s:l = 171 - ((43 * winheight(0) + 43) / 87)
464
+if s:l < 1 | let s:l = 1 | endif
465
+exe s:l
466
+normal! zt
467
+171
468
+normal! 06l
469
+wincmd w
470
+argglobal
471
+3argu
472
+edit screen.h
473
+inoremap <buffer> 	 =CodeComplete()
=SwitchRegion()
474
+setlocal keymap=
475
+setlocal noarabic
476
+setlocal autoindent
477
+setlocal nobinary
478
+setlocal bufhidden=
479
+setlocal buflisted
480
+setlocal buftype=
481
+setlocal cindent
482
+setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
483
+setlocal cinoptions=
484
+setlocal cinwords=if,else,while,do,for,switch
485
+setlocal colorcolumn=
486
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
487
+setlocal commentstring=/*%s*/
488
+setlocal complete=.,w,b,u,t,i
489
+setlocal concealcursor=
490
+setlocal conceallevel=0
491
+setlocal completefunc=
492
+setlocal nocopyindent
493
+setlocal cryptmethod=
494
+setlocal nocursorbind
495
+setlocal nocursorcolumn
496
+setlocal nocursorline
497
+setlocal define=
498
+setlocal dictionary=
499
+setlocal nodiff
500
+setlocal equalprg=
501
+setlocal errorformat=
502
+setlocal noexpandtab
503
+if &filetype != 'cpp'
504
+setlocal filetype=cpp
505
+endif
506
+setlocal foldcolumn=0
507
+setlocal foldenable
508
+setlocal foldexpr=0
509
+setlocal foldignore=#
510
+setlocal foldlevel=0
511
+setlocal foldmarker={{{,}}}
512
+setlocal foldmethod=manual
513
+setlocal foldminlines=1
514
+setlocal foldnestmax=20
515
+setlocal foldtext=foldtext()
516
+setlocal formatexpr=
517
+setlocal formatoptions=croql
518
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
519
+setlocal grepprg=
520
+setlocal iminsert=0
521
+setlocal imsearch=0
522
+setlocal include=
523
+setlocal includeexpr=
524
+setlocal indentexpr=
525
+setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
526
+setlocal noinfercase
527
+setlocal iskeyword=@,48-57,_,192-255
528
+setlocal keywordprg=
529
+setlocal nolinebreak
530
+setlocal nolisp
531
+setlocal nolist
532
+setlocal makeprg=
533
+setlocal matchpairs=(:),{:},[:]
534
+setlocal nomodeline
535
+setlocal modifiable
536
+setlocal nrformats=octal,hex
537
+setlocal nonumber
538
+set numberwidth=3
539
+setlocal numberwidth=3
540
+setlocal omnifunc=ccomplete#Complete
541
+setlocal path=
542
+setlocal nopreserveindent
543
+setlocal nopreviewwindow
544
+setlocal quoteescape=\\
545
+setlocal noreadonly
546
+setlocal norelativenumber
547
+setlocal norightleft
548
+setlocal rightleftcmd=search
549
+setlocal noscrollbind
550
+setlocal shiftwidth=4
551
+setlocal noshortname
552
+setlocal nosmartindent
553
+setlocal softtabstop=0
554
+setlocal nospell
555
+setlocal spellcapcheck=[.?!]\\_[\\])'\"\	\ ]\\+
556
+setlocal spellfile=
557
+setlocal spelllang=en
558
+setlocal statusline=
559
+setlocal suffixesadd=
560
+setlocal swapfile
561
+setlocal synmaxcol=3000
562
+if &syntax != 'cpp'
563
+setlocal syntax=cpp
564
+endif
565
+setlocal tabstop=4
566
+setlocal tags=
567
+setlocal textwidth=0
568
+setlocal thesaurus=
569
+setlocal noundofile
570
+setlocal nowinfixheight
571
+setlocal nowinfixwidth
572
+setlocal wrap
573
+setlocal wrapmargin=0
574
+silent! normal! zE
575
+let s:l = 17 - ((16 * winheight(0) + 43) / 87)
576
+if s:l < 1 | let s:l = 1 | endif
577
+exe s:l
578
+normal! zt
579
+17
580
+normal! 0
581
+wincmd w
582
+2wincmd w
583
+exe 'vert 1resize ' . ((&columns * 158 + 158) / 317)
584
+exe 'vert 2resize ' . ((&columns * 158 + 158) / 317)
585
+tabedit route.c
586
+set splitbelow splitright
587
+wincmd _ | wincmd |
588
+vsplit
589
+1wincmd h
590
+wincmd w
591
+set nosplitbelow
592
+wincmd t
593
+set winheight=1 winwidth=1
594
+exe 'vert 1resize ' . ((&columns * 158 + 158) / 317)
595
+exe 'vert 2resize ' . ((&columns * 158 + 158) / 317)
596
+argglobal
597
+2argu
598
+inoremap <buffer> 	 =CodeComplete()
=SwitchRegion()
599
+setlocal keymap=
600
+setlocal noarabic
601
+setlocal autoindent
602
+setlocal nobinary
603
+setlocal bufhidden=
604
+setlocal buflisted
605
+setlocal buftype=
606
+setlocal cindent
607
+setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
608
+setlocal cinoptions=
609
+setlocal cinwords=if,else,while,do,for,switch
610
+setlocal colorcolumn=
611
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
612
+setlocal commentstring=/*%s*/
613
+setlocal complete=.,w,b,u,t,i
614
+setlocal concealcursor=
615
+setlocal conceallevel=0
616
+setlocal completefunc=
617
+setlocal nocopyindent
618
+setlocal cryptmethod=
619
+setlocal nocursorbind
620
+setlocal nocursorcolumn
621
+setlocal nocursorline
622
+setlocal define=
623
+setlocal dictionary=
624
+setlocal nodiff
625
+setlocal equalprg=
626
+setlocal errorformat=
627
+setlocal noexpandtab
628
+if &filetype != 'c'
629
+setlocal filetype=c
630
+endif
631
+setlocal foldcolumn=0
632
+setlocal foldenable
633
+setlocal foldexpr=0
634
+setlocal foldignore=#
635
+setlocal foldlevel=0
636
+setlocal foldmarker={{{,}}}
637
+setlocal foldmethod=manual
638
+setlocal foldminlines=1
639
+setlocal foldnestmax=20
640
+setlocal foldtext=foldtext()
641
+setlocal formatexpr=
642
+setlocal formatoptions=croql
643
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
644
+setlocal grepprg=
645
+setlocal iminsert=0
646
+setlocal imsearch=0
647
+setlocal include=
648
+setlocal includeexpr=
649
+setlocal indentexpr=
650
+setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
651
+setlocal noinfercase
652
+setlocal iskeyword=@,48-57,_,192-255
653
+setlocal keywordprg=
654
+setlocal nolinebreak
655
+setlocal nolisp
656
+setlocal nolist
657
+setlocal makeprg=
658
+setlocal matchpairs=(:),{:},[:]
659
+setlocal nomodeline
660
+setlocal modifiable
661
+setlocal nrformats=octal,hex
662
+setlocal nonumber
663
+set numberwidth=3
664
+setlocal numberwidth=3
665
+setlocal omnifunc=ccomplete#Complete
666
+setlocal path=
667
+setlocal nopreserveindent
668
+setlocal nopreviewwindow
669
+setlocal quoteescape=\\
670
+setlocal noreadonly
671
+setlocal norelativenumber
672
+setlocal norightleft
673
+setlocal rightleftcmd=search
674
+setlocal noscrollbind
675
+setlocal shiftwidth=4
676
+setlocal noshortname
677
+setlocal nosmartindent
678
+setlocal softtabstop=0
679
+setlocal nospell
680
+setlocal spellcapcheck=[.?!]\\_[\\])'\"\	\ ]\\+
681
+setlocal spellfile=
682
+setlocal spelllang=en
683
+setlocal statusline=
684
+setlocal suffixesadd=
685
+setlocal swapfile
686
+setlocal synmaxcol=3000
687
+if &syntax != 'c'
688
+setlocal syntax=c
689
+endif
690
+setlocal tabstop=4
691
+setlocal tags=
692
+setlocal textwidth=0
693
+setlocal thesaurus=
694
+setlocal noundofile
695
+setlocal nowinfixheight
696
+setlocal nowinfixwidth
697
+setlocal wrap
698
+setlocal wrapmargin=0
699
+silent! normal! zE
700
+let s:l = 160 - ((68 * winheight(0) + 43) / 87)
701
+if s:l < 1 | let s:l = 1 | endif
702
+exe s:l
703
+normal! zt
704
+160
705
+normal! 0
706
+wincmd w
707
+argglobal
708
+2argu
709
+edit route.h
710
+inoremap <buffer> 	 =CodeComplete()
=SwitchRegion()
711
+setlocal keymap=
712
+setlocal noarabic
713
+setlocal autoindent
714
+setlocal nobinary
715
+setlocal bufhidden=
716
+setlocal buflisted
717
+setlocal buftype=
718
+setlocal cindent
719
+setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
720
+setlocal cinoptions=
721
+setlocal cinwords=if,else,while,do,for,switch
722
+setlocal colorcolumn=
723
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
724
+setlocal commentstring=/*%s*/
725
+setlocal complete=.,w,b,u,t,i
726
+setlocal concealcursor=
727
+setlocal conceallevel=0
728
+setlocal completefunc=
729
+setlocal nocopyindent
730
+setlocal cryptmethod=
731
+setlocal nocursorbind
732
+setlocal nocursorcolumn
733
+setlocal nocursorline
734
+setlocal define=
735
+setlocal dictionary=
736
+setlocal nodiff
737
+setlocal equalprg=
738
+setlocal errorformat=
739
+setlocal noexpandtab
740
+if &filetype != 'cpp'
741
+setlocal filetype=cpp
742
+endif
743
+setlocal foldcolumn=0
744
+setlocal foldenable
745
+setlocal foldexpr=0
746
+setlocal foldignore=#
747
+setlocal foldlevel=0
748
+setlocal foldmarker={{{,}}}
749
+setlocal foldmethod=manual
750
+setlocal foldminlines=1
751
+setlocal foldnestmax=20
752
+setlocal foldtext=foldtext()
753
+setlocal formatexpr=
754
+setlocal formatoptions=croql
755
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
756
+setlocal grepprg=
757
+setlocal iminsert=0
758
+setlocal imsearch=0
759
+setlocal include=
760
+setlocal includeexpr=
761
+setlocal indentexpr=
762
+setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
763
+setlocal noinfercase
764
+setlocal iskeyword=@,48-57,_,192-255
765
+setlocal keywordprg=
766
+setlocal nolinebreak
767
+setlocal nolisp
768
+setlocal nolist
769
+setlocal makeprg=
770
+setlocal matchpairs=(:),{:},[:]
771
+setlocal nomodeline
772
+setlocal modifiable
773
+setlocal nrformats=octal,hex
774
+setlocal nonumber
775
+set numberwidth=3
776
+setlocal numberwidth=3
777
+setlocal omnifunc=ccomplete#Complete
778
+setlocal path=
779
+setlocal nopreserveindent
780
+setlocal nopreviewwindow
781
+setlocal quoteescape=\\
782
+setlocal noreadonly
783
+setlocal norelativenumber
784
+setlocal norightleft
785
+setlocal rightleftcmd=search
786
+setlocal noscrollbind
787
+setlocal shiftwidth=4
788
+setlocal noshortname
789
+setlocal nosmartindent
790
+setlocal softtabstop=0
791
+setlocal nospell
792
+setlocal spellcapcheck=[.?!]\\_[\\])'\"\	\ ]\\+
793
+setlocal spellfile=
794
+setlocal spelllang=en
795
+setlocal statusline=
796
+setlocal suffixesadd=
797
+setlocal swapfile
798
+setlocal synmaxcol=3000
799
+if &syntax != 'cpp'
800
+setlocal syntax=cpp
801
+endif
802
+setlocal tabstop=4
803
+setlocal tags=
804
+setlocal textwidth=0
805
+setlocal thesaurus=
806
+setlocal noundofile
807
+setlocal nowinfixheight
808
+setlocal nowinfixwidth
809
+setlocal wrap
810
+setlocal wrapmargin=0
811
+silent! normal! zE
812
+let s:l = 14 - ((13 * winheight(0) + 43) / 87)
813
+if s:l < 1 | let s:l = 1 | endif
814
+exe s:l
815
+normal! zt
816
+14
817
+normal! 0
818
+wincmd w
819
+2wincmd w
820
+exe 'vert 1resize ' . ((&columns * 158 + 158) / 317)
821
+exe 'vert 2resize ' . ((&columns * 158 + 158) / 317)
822
+tabnext 1
823
+if exists('s:wipebuf')
824
+  silent exe 'bwipe ' . s:wipebuf
825
+endif
826
+unlet! s:wipebuf
827
+set winheight=1 winwidth=20 shortmess=filnxtToO
828
+let s:sx = expand("<sfile>:p:r")."x.vim"
829
+if file_readable(s:sx)
830
+  exe "source " . fnameescape(s:sx)
831
+endif
832
+let &so = s:so_save | let &siso = s:siso_save
833
+doautoall SessionLoadPost
834
+unlet SessionLoad
835
+" vim: set ft=vim :

+ 18
- 0
gitter/Makefile View File

@@ -0,0 +1,18 @@
1
+CXX = gcc
2
+FLAGS = -Wall -g3 -O2 -march=native -mtune=native
3
+CLIBS = `sdl-config --cflags`
4
+LDFLAGS = `sdl-config --libs` -lSDL_gfx  -lm -lpthread
5
+OBJ = main.o screen.o route.o
6
+
7
+main: $(OBJ)
8
+	$(CXX) $(FLAGS) $(LDFLAGS) -o $@ $(OBJ) 
9
+
10
+%.o: %.c %.h
11
+	$(CXX) $(FLAGS) $(CLIBS) -c $< 
12
+
13
+%.o: %.c 
14
+	$(CXX) $(FLAGS) $(CLIBS) -c $< 
15
+
16
+.PHONY : clean
17
+clean:
18
+	rm -f *.o main

+ 24
- 0
gitter/globals.h View File

@@ -0,0 +1,24 @@
1
+#ifndef GLOBALS_H
2
+#define GLOBALS_H
3
+
4
+typedef struct {
5
+	int WIDTH;
6
+	int HEIGHT;
7
+	int DISPLAY_WIDTH;
8
+	int DISPLAY_HEIGHT;
9
+	int FULLSCREEN_WIDTH;
10
+	int FULLSCREEN_HEIGHT;
11
+	int DELTA;
12
+	int FULLSCREEN;
13
+	int VERBOSE;
14
+} options_t;
15
+
16
+options_t GLOBALS;
17
+
18
+#define VERBOSE(...) \
19
+	if (GLOBALS.VERBOSE) {\
20
+		printf(__VA_ARGS__);\
21
+	}
22
+
23
+#define ERROR(...) fprintf(stderr, __VA_ARGS__);
24
+#endif  /*GLOBALS_H*/

+ 13
- 0
gitter/main.c View File

@@ -0,0 +1,13 @@
1
+#include <stdio.h>
2
+#include "screen.h"
3
+#include "route.h"
4
+
5
+int main(int argc, char *argv[]) {
6
+	GLOBALS.WIDTH  = 1024;
7
+	GLOBALS.HEIGHT = 1024;
8
+
9
+	sdl_init();
10
+	main_loop();
11
+
12
+	return 0;
13
+}

+ 349
- 0
gitter/route.c View File

@@ -0,0 +1,349 @@
1
+#include <math.h>
2
+#include <stdio.h>
3
+#include <stdlib.h>
4
+#include "route.h"
5
+#include "globals.h"
6
+
7
+// Abstand zwischen zwei Punkten
8
+double dist(pixel_t* A, pixel_t* B) {
9
+	return hypotf(B->x - A->x, B->y - A->y);
10
+}
11
+
12
+// Wo auf der Linie zwischen A und B sitzt der Fußpunkt des Lots von C auf AB?
13
+// Werte kleiner Null bedeuten vor A entlang AB
14
+// Werte zwischen 0 und 1 geben an nach welchem Bruchteil von AB der Fußpunkt kommt
15
+// Werte größer 1 bedeuten daß der Fußpunkt auf der Verlängerung von AB hinter B liegt
16
+// Wert den Code mit A=B aufruf ist doof und verdient daß alles platzt
17
+double dividing_ratio(pixel_t* A, pixel_t* B, pixel_t* C) {
18
+	return ((C->x - A->x)*(B->x - A->x) + (C->y - A->y)*(B->y - A->y))/pow(dist(A, B),2);
19
+}
20
+
21
+// Was ist der Minimal-Abstand von C zum Linien AB?
22
+// Achtung dies liefert den vorzeichenbehafteten Abstand
23
+// Werte kleiner Null bedeuten das C "links" der Verbindungslinie liegt wenn man von A Richtung B schaut
24
+// Werte größer Null dementsprechend recht, exakt null auf der Verbindungslinie
25
+double dist_to_line(pixel_t* A, pixel_t* B, pixel_t* C) {
26
+	//return ((A->y - B->y)*C->x + (A->x - B->x)*C->y + (A->x * B->y - A->y * B->x))/dist(A,B);
27
+	//return ((B->y - A->y)*C->x + (A->x - B->x)* C->y - ((B->y - A->y)* A->x + (A->x - B->x)* A->y))/dist(A,B);
28
+	return ((A->y - B->y)*C->x - (A->x - B->x)* C->y + ((B->y - A->y)* A->x + (A->x - B->x)* A->y))/dist(A,B);
29
+}
30
+
31
+// Was ist der Minimal-Abstand von C zum Liniensegment AB?
32
+// Die ist der Abstand zwischen C und dem Fußpunkt des Lots auf AB fall dieser zwischen A und B fällt
33
+// Ansonsten der Abstand zu A btw B
34
+double dist_to_seg(pixel_t* A, pixel_t* B, pixel_t* C) {
35
+	double r = dividing_ratio(A, B, C);
36
+	if(r <= 0) {
37
+		return dist(A, C);
38
+	} else if (r >= 1) {
39
+		return dist(B, C);
40
+	} else {
41
+		return fabs(dist_to_line(A, B, C));
42
+	}
43
+}
44
+
45
+waypoint_t* go_around(pixel_t* A, pixel_t* B, pixel_t* C) {
46
+	double r = dividing_ratio(A, B, C);
47
+	pixel_t X = { A->x + r*(B->x - A->x), A->y + r*(B->y - A->y) };
48
+	double d = dist(&X, C);
49
+	pixel_t W = {C->x + 15*sqrt(2)*(X.x - C->x) / d, C->y + 15*sqrt(2)*(X.y - C->y) / d};
50
+	waypoint_t* wp = malloc(sizeof(waypoint_t));
51
+	wp->next = NULL;
52
+	wp->point.x = W.x;
53
+	wp->point.y = W.y;
54
+	printf("Suggest you go via (%f,%f) to avoid (%f,%f)\n", W.x, W.y, C->x, C->y);
55
+	return wp;
56
+}
57
+
58
+waypoint_t* route(pixel_t* start, pixel_t* stop, pixel_t* points, int n_points) {
59
+	printf("Running route\n");
60
+
61
+	/*
62
+	pixel_t A = {0, 0};
63
+	pixel_t B = {1000, 0};
64
+	pixel_t C1 = {500, 200};
65
+	printf("A = (0,0), B=(1000,0), C1=(500,200)\n");
66
+	printf("dist(A,B) = %f\n", dist(&A, &B));
67
+	printf("r(AB, C1) = %f\n", dividing_ratio(&A, &B, &C1));
68
+	printf("dist_to_seg(A, B, C1) = %f\n", dist_to_seg(&A, &B, &C1));
69
+	pixel_t C2 = {-100, 200};
70
+	printf("C2 = (-100,200)\n");
71
+	printf("r(AB, C2) = %f\n", dividing_ratio(&A, &B, &C2));
72
+	printf("dist_to_seg(A, B, C2) = %f\n", dist_to_seg(&A, &B, &C2));
73
+	pixel_t C3 = {200, -400};
74
+	printf("C3 = (200,-400)\n");
75
+	printf("r(AB, C3) = %f\n", dividing_ratio(&A, &B, &C2));
76
+	printf("dist_to_seg(A, B, C3) = %f\n", dist_to_seg(&A, &B, &C3));
77
+	*/
78
+
79
+	int i;
80
+
81
+	int i_min = -1;
82
+	double r_min = 1;
83
+
84
+	for(i = 0; i < n_points; i++) {
85
+		double r = dividing_ratio(start, stop, &(points[i]));
86
+		if (r > 0 && r < 1) {
87
+			double d = dist_to_line(start, stop, &(points[i]));
88
+			if (fabs(d) < 15) {
89
+				//printf("Point #%d at (%f,%f) is an obstacle %f pixel away from the course\n", i, points[i].x, points[i].y, d);
90
+				if(r < r_min) {
91
+					i_min = i;
92
+					r_min = r;
93
+				}
94
+			}
95
+		}
96
+	}
97
+
98
+	if(i_min >= 0) {
99
+		printf("Point #%d at (%f,%f) is the first obstacle %f pixel down the course\n", i_min, points[i_min].x, points[i_min].y, r_min * dist(start, stop));
100
+		waypoint_t* wp = go_around(start, stop, &(points[i_min]));
101
+
102
+		waypoint_t* part1 = route(start, &(wp->point), points, n_points);
103
+		if(part1 == NULL) {
104
+			part1 = wp;
105
+		} else {
106
+			waypoint_t* t = part1;
107
+			while(t->next != NULL) {
108
+				t = t->next;
109
+			}
110
+			t->next = wp;
111
+		}
112
+		waypoint_t* part2 = route(&(wp->point), stop, points, n_points);
113
+		if(part2 != 0) {
114
+			waypoint_t* t = part1;
115
+			while(t->next != NULL) {
116
+				t = t->next;
117
+			}
118
+			t->next = part2;
119
+		}
120
+		return part1;
121
+	} else {
122
+		return NULL;
123
+	}
124
+}
125
+
126
+waypoint_t* plotCourse(pixel_t* start, pixel_t* stop, pixel_t* points, int n) {
127
+	int n_points = n*n;
128
+	waypoint_t* wp_start = malloc(sizeof(waypoint_t));
129
+	waypoint_t* wp_stop = malloc(sizeof(waypoint_t));
130
+	wp_start->point.x = start->x;
131
+	wp_start->point.y = start->y;
132
+	wp_stop->point.x = stop->x;
133
+	wp_stop->point.y = stop->y;
134
+	wp_start->next = route(start, stop, points, n_points);
135
+	waypoint_t* t = wp_start;
136
+
137
+	while (t->next != NULL) {
138
+		t = t->next;
139
+	}
140
+
141
+	t->next = wp_stop;
142
+	return wp_start;
143
+}
144
+
145
+void get_surrounding_points(pixel_t *surrounding_points, pixel_t *points, int n, int face_x, int face_y) {
146
+	surrounding_points[0] = points[(face_y - 1) * n + (face_x - 1)];
147
+	surrounding_points[1] = points[(face_y) * n + (face_x - 1)];
148
+	surrounding_points[2] = points[(face_y) * n + (face_x)];
149
+	surrounding_points[3] = points[(face_y - 1) * n + (face_x)];
150
+}
151
+
152
+int get_line_intersection(pixel_t *P0, pixel_t *P1, pixel_t *P2, pixel_t *P3, pixel_t *result)
153
+{
154
+	float s1_x, s1_y, s2_x, s2_y;
155
+	s1_x = P1->x - P0->x;
156
+	s1_y = P1->y - P0->y;
157
+	s2_x = P3->x - P2->x;
158
+	s2_y = P3->y - P2->y;
159
+
160
+	float s, t;
161
+	s = (-s1_y * (P0->x - P2->x) + s1_x * (P0->y - P2->y)) / (-s2_x * s1_y + s1_x * s2_y);
162
+	t = ( s2_x * (P0->y - P2->y) - s2_y * (P0->x - P2->x)) / (-s2_x * s1_y + s1_x * s2_y);
163
+
164
+	if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
165
+	{
166
+		if (result) {
167
+			result->x = P0->x + (t * s1_x);
168
+			result->y = P0->y + (t * s1_y);
169
+		}
170
+		return 1;
171
+	}
172
+
173
+	return 0;
174
+}
175
+
176
+void find_face(pixel_t *p, pixel_t *points, int n, int *x, int *y) {
177
+	int face_x = p->x / (GLOBALS.WIDTH / (n + 1));
178
+	int face_y = p->y / (GLOBALS.HEIGHT / (n + 1));
179
+	int edge;
180
+	int retry = 1;
181
+	int count = 0;
182
+
183
+	pixel_t surrounding[4];
184
+
185
+	while (retry && count < 4) {
186
+		retry = 0;
187
+		get_surrounding_points(surrounding, points, n, face_x, face_y);
188
+
189
+		for (edge = 0; edge < 4; edge++) {
190
+			double r = dist_to_line(surrounding + edge, surrounding + (edge + 1) % 4, p);
191
+			if (r > 0) {
192
+
193
+				printf("edge: %d, r %f, x %d, y %d\n", edge, r, face_x, face_y);
194
+				retry = 1;
195
+
196
+				switch (edge) {
197
+					case 0 :
198
+						face_x--;
199
+						break;
200
+					case 1 :
201
+						face_y++;
202
+						break;
203
+					case 2 :
204
+						face_x++;
205
+						break;
206
+					case 3 :
207
+						face_y--;
208
+						break;
209
+				}
210
+
211
+				break;
212
+			}
213
+		}
214
+	}
215
+
216
+	*x = face_x;
217
+	*y = face_y;
218
+
219
+}
220
+
221
+waypoint_t *smooth(waypoint_t *way, int res) {
222
+	waypoint_t *end = way;
223
+	waypoint_t *working_start;
224
+	waypoint_t *working;
225
+
226
+	pixel_t startp;
227
+	pixel_t midp;
228
+	pixel_t endp;
229
+	pixel_t t1, t2;
230
+	pixel_t v1, v2;
231
+	pixel_t s;
232
+
233
+	int i;
234
+
235
+	working_start = malloc(sizeof(waypoint_t));
236
+	*working_start = *way;
237
+	working_start->next = NULL;
238
+	working = working_start;
239
+
240
+	if (end) {
241
+		midp = end->point;
242
+		end  = end->next;
243
+	} else return NULL;
244
+
245
+	if (end) {
246
+		endp = end->point;
247
+		end  = end->next;
248
+	} else return NULL;
249
+
250
+
251
+	while (end != NULL) {
252
+		startp = midp;
253
+		midp   = endp;
254
+		endp   = end->point;
255
+
256
+		t1.x = (startp.x + midp.x) / 2.;
257
+		t1.y = (startp.y + midp.y) / 2.;
258
+
259
+		t2 = midp;
260
+
261
+		v1.x = (midp.x - startp.x) / 2. / res;
262
+		v1.y = (midp.y - startp.y) / 2. / res;
263
+
264
+		v2.x = (endp.x - midp.x) / 2. / res;
265
+		v2.y = (endp.y - midp.y) / 2. / res;
266
+
267
+		for (i = 0; i < res; i++) {
268
+			s.x = t1.x + ((t2.x - t1.x) * i) / res;
269
+			s.y = t1.y + ((t2.y - t1.y) * i) / res;
270
+
271
+			t1.x += v1.x;
272
+			t1.y += v1.y;
273
+
274
+			t2.x += v2.x;
275
+			t2.y += v2.y;
276
+
277
+			working->next = malloc (sizeof(waypoint_t));
278
+			working = working->next;
279
+			working->point = s;
280
+		}
281
+		
282
+		working->next = end;
283
+		end = end->next;
284
+	}
285
+
286
+	return working_start;
287
+}
288
+
289
+waypoint_t* plotCourse_gridbased(pixel_t *start, pixel_t *stop, pixel_t *points, int n) {
290
+	int face_x, face_y, face_s_x, face_s_y;
291
+	int edge;
292
+	int last_edge = -1;
293
+
294
+	find_face(start, points, n, &face_x, &face_y);
295
+	find_face(stop, points, n, &face_s_x, &face_s_y);
296
+	pixel_t surrounding[4];
297
+	waypoint_t *wp_start = malloc (sizeof(waypoint_t));
298
+	wp_start->point = *start;
299
+	wp_start->next  = NULL;
300
+
301
+	waypoint_t *working = wp_start;
302
+
303
+	while (face_x != face_s_x || face_y != face_s_y) {
304
+		pixel_t c;
305
+		get_surrounding_points(surrounding, points, n, face_x, face_y);
306
+
307
+		for (edge = 0; edge < 4; edge++) {
308
+			if (edge == last_edge) continue;
309
+			c = working->point;
310
+
311
+			if (get_line_intersection(surrounding + edge, surrounding + (edge + 1)%4, &c, stop, NULL)) {
312
+				c.x = (surrounding[edge].x + surrounding[(edge + 1) % 4].x) / 2;
313
+				c.y = (surrounding[edge].y + surrounding[(edge + 1) % 4].y) / 2;
314
+				break;
315
+			}
316
+		}
317
+
318
+		working->next = malloc(sizeof(waypoint_t));
319
+		working = working->next;
320
+		working->point = c;
321
+		working->next = NULL;
322
+
323
+		switch (edge) {
324
+			case 0 :
325
+				face_x--;
326
+				break;
327
+			case 1 :
328
+				face_y++;
329
+				break;
330
+			case 2 :
331
+				face_x++;
332
+				break;
333
+			case 3 :
334
+				face_y--;
335
+				break;
336
+			default:
337
+				return wp_start;
338
+		}
339
+
340
+		last_edge = (edge + 2) % 4;
341
+	}
342
+
343
+	working->next = malloc(sizeof(waypoint_t));
344
+	working = working->next;
345
+	working->point = *stop;
346
+	working->next = NULL;
347
+
348
+	return wp_start;
349
+}

+ 17
- 0
gitter/route.h View File

@@ -0,0 +1,17 @@
1
+#ifndef ROUTE_H
2
+#define ROUTE_H
3
+
4
+#include "screen.h"
5
+
6
+typedef struct wp_t waypoint_t;
7
+
8
+struct wp_t {
9
+        pixel_t point;
10
+        waypoint_t* next;
11
+};
12
+
13
+waypoint_t *smooth(waypoint_t *way, int res);
14
+waypoint_t* plotCourse(pixel_t* start, pixel_t* stop, pixel_t* points, int n);
15
+waypoint_t* plotCourse_gridbased(pixel_t* start, pixel_t* stop, pixel_t* points, int n);
16
+
17
+#endif  /*ROUTE_H*/

+ 244
- 0
gitter/screen.c View File

@@ -0,0 +1,244 @@
1
+#include <stdio.h>
2
+#include <SDL/SDL.h>
3
+#include <SDL/SDL_gfxPrimitives.h>
4
+#include <errno.h>
5
+
6
+#include "globals.h"
7
+#include "screen.h"
8
+#include "route.h"
9
+
10
+/* TODO:
11
+ *
12
+ * a global scene for easy rerender
13
+ * fast image switch
14
+ */
15
+
16
+SDL_Surface *screen;
17
+
18
+void sdl_setup() {
19
+	const SDL_VideoInfo *info;
20
+	if (SDL_Init(SDL_INIT_VIDEO) == -1) {
21
+		ERROR("SDL_Init() failed: %s\n", SDL_GetError());
22
+		exit(1);
23
+	}
24
+
25
+	info = SDL_GetVideoInfo();
26
+	GLOBALS.DISPLAY_WIDTH  = info->current_w;
27
+	GLOBALS.DISPLAY_HEIGHT = info->current_h;
28
+
29
+	atexit(SDL_Quit);
30
+}
31
+
32
+void sdl_screen_init() {
33
+	if (GLOBALS.FULLSCREEN) {
34
+		screen = SDL_SetVideoMode(GLOBALS.DISPLAY_WIDTH, GLOBALS.DISPLAY_HEIGHT, 0, SDL_FULLSCREEN);
35
+	} else {
36
+		screen = SDL_SetVideoMode(GLOBALS.WIDTH, GLOBALS.HEIGHT, 0, 0);
37
+	}
38
+}
39
+
40
+void sdl_init() {
41
+	sdl_setup();
42
+	sdl_screen_init();
43
+
44
+	if (screen == NULL) {
45
+		ERROR("SDL_SetVideoMode() failed: %s\n", SDL_GetError());
46
+		exit(1);
47
+	}
48
+}
49
+
50
+void draw_line(pixel_t *p1, pixel_t *p2) {
51
+	aalineRGBA(screen, p1->x, p1->y, p2->x, p2->y, 255, 255, 255, 255);
52
+}
53
+
54
+void draw_blob(pixel_t *p1) {
55
+	aacircleRGBA(screen, p1->x, p1->y, 2, 255, 255, 255, 255);
56
+	//aacircleRGBA(screen, p1->x, p1->y, 10, 64, 64, 64, 255);
57
+}
58
+
59
+void draw_points(pixel_t *points, int n) {
60
+	int x, y;
61
+
62
+	for (y = 0; y < n; y++) {
63
+		for (x = 0; x < n; x++) {
64
+			draw_blob(&points[y*n + x]);
65
+		}
66
+	}
67
+}
68
+
69
+void draw_grid(pixel_t *points, int n) {
70
+	int x, y;
71
+
72
+	for (y = 0; y < n - 1; y++) {
73
+		for (x = 0; x < n - 1; x++) {
74
+			draw_line(&points[y*n + x], &points[y*n + x + 1]);
75
+			draw_line(&points[y*n + x], &points[(y + 1)*n + x]);
76
+		}
77
+		draw_line(&points[y*n + x], &points[(y + 1)*n + x]);
78
+	}
79
+	for (x = 0; x < n - 1; x++) {
80
+		draw_line(&points[y*n + x], &points[y*n + x + 1]);
81
+	}
82
+}
83
+
84
+void randomize(pixel_t *points, int n, float fac) {
85
+	int i;
86
+
87
+	for (i = 0; i < n * n; i++) {
88
+		points[i].x += (((float) rand() / RAND_MAX) - 0.5) * 2 * fac;
89
+		points[i].y += (((float) rand() / RAND_MAX) - 0.5) * 2 * fac;
90
+	}
91
+	
92
+}
93
+
94
+void set(pixel_t *points, int n) {
95
+	int x, y;
96
+
97
+	for (y = 0; y < n; y++) {
98
+		for (x = 0; x < n; x++) {
99
+			points[y*n + x].x = GLOBALS.WIDTH  * (x + 1) / (n + 1);
100
+			points[y*n + x].y = GLOBALS.HEIGHT * (y + 1) / (n + 1);
101
+		}
102
+	}
103
+}
104
+
105
+int main_loop() {
106
+	int quit = 0;
107
+	int n = 5;
108
+	int view_grid = 0;
109
+	int view_points  = 1;
110
+	float fac = GLOBALS.WIDTH / (n + 1) * 0.3;
111
+	SDL_Event e;
112
+	pixel_t *points;
113
+	pixel_t start = {0, 0};
114
+	pixel_t stop = {0, 0};
115
+	waypoint_t* route = NULL;
116
+
117
+	points = (pixel_t *) malloc (sizeof(pixel_t) * n * n);
118
+
119
+	set(points, n);
120
+
121
+	while (!quit) {
122
+		SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
123
+		if (view_grid) {
124
+			draw_grid(points, n);
125
+		}
126
+
127
+		if (view_points) {
128
+			draw_points(points, n);
129
+		}
130
+
131
+		if (route != NULL) {
132
+			waypoint_t* r = route;
133
+			while (r->next != NULL) {
134
+				aacircleRGBA(screen, r->point.x, r->point.y, 2, 0, 0, 255, 255);
135
+				aalineRGBA(screen, r->point.x, r->point.y, r->next->point.x, r->next->point.y, 0, 0, 255, 64);
136
+				r = r->next;
137
+			}
138
+			aacircleRGBA(screen, r->point.x, r->point.y, 2, 0, 0, 255, 255);
139
+			r = smooth(route, 5);
140
+			while (r->next != NULL) {
141
+				aacircleRGBA(screen, r->point.x, r->point.y, 2, 0, 255, 255, 255);
142
+				aalineRGBA(screen, r->point.x, r->point.y, r->next->point.x, r->next->point.y, 0, 255, 255, 64);
143
+				r = r->next;
144
+			}
145
+			aacircleRGBA(screen, r->point.x, r->point.y, 2, 0, 0, 255, 255);
146
+		}
147
+
148
+		if (start.x != 0 && start.y != 0) {
149
+			aacircleRGBA(screen, start.x, start.y, 2, 0, 255, 0, 255);
150
+		}
151
+
152
+		if (stop.x != 0 && stop.y != 0) {
153
+			aacircleRGBA(screen, stop.x, stop.y, 2, 255, 0, 0, 255);
154
+		}
155
+
156
+		SDL_Flip(screen);
157
+		SDL_WaitEvent(&e);
158
+		switch (e.type) {
159
+			case SDL_QUIT :
160
+				quit = 1;
161
+				break;
162
+			case SDL_MOUSEBUTTONDOWN :
163
+				switch (e.button.button) {
164
+					case SDL_BUTTON_LEFT:
165
+						start.x = e.button.x;
166
+						start.y = e.button.y;
167
+						break;
168
+					case SDL_BUTTON_RIGHT:
169
+						stop.x = e.button.x;
170
+						stop.y = e.button.y;
171
+						break;
172
+				}
173
+				if (start.x != 0 && start.y != 0 && stop.x != 0 && stop.y != 0) {
174
+					printf("Route from (%f,%f) to (%f,%f)\n", start.x, start.y, stop.x, stop.y);
175
+					route = plotCourse_gridbased(&start, &stop, points, n);
176
+					waypoint_t* r = route;
177
+					while (r != NULL) {
178
+						printf("Waypoint (%f,%f)\n", r->point.x, r->point.y);
179
+						r = r->next;
180
+					}
181
+				}
182
+				break;
183
+			case SDL_KEYDOWN :
184
+				switch (e.key.keysym.sym) {
185
+					case SDLK_p:
186
+						view_points = !view_points;
187
+						break;
188
+					case SDLK_g:
189
+					case SDLK_l:
190
+						view_grid = !view_grid;
191
+						break;
192
+					case SDLK_r:
193
+						randomize(points, n, fac);
194
+						break;
195
+					case SDLK_s:
196
+						set(points, n);
197
+						break;
198
+					case SDLK_q:
199
+						quit = 1;
200
+						break;
201
+					case SDLK_UP:
202
+						n++;
203
+						points = (pixel_t *) realloc (points, sizeof(pixel_t) * n * n);
204
+						fac = GLOBALS.WIDTH / (n + 1) * 0.3;
205
+						set(points, n);
206
+						break;
207
+					case SDLK_DOWN:
208
+						n--;
209
+						points = (pixel_t *) realloc (points, sizeof(pixel_t) * n * n);
210
+						fac = GLOBALS.WIDTH / (n + 1) * 0.3;
211
+						set(points, n);
212
+						break;
213
+					case SDLK_PLUS:
214
+					case SDLK_KP_PLUS:
215
+						fac *= 1.1;
216
+						printf("fac: %f\n", fac);
217
+						set(points, n);
218
+						randomize(points, n, fac);
219
+						break;
220
+					case SDLK_MINUS:
221
+					case SDLK_KP_MINUS:
222
+						fac /= 1.1;
223
+						printf("fac: %f\n", fac);
224
+						set(points, n);
225
+						randomize(points, n, fac);
226
+						break;
227
+					default:
228
+						break;
229
+				}
230
+				break;
231
+			case SDL_VIDEORESIZE:
232
+				GLOBALS.WIDTH  = e.resize.w;
233
+				GLOBALS.HEIGHT = e.resize.h;
234
+				sdl_screen_init();
235
+				break;
236
+			default :
237
+				break;
238
+		}
239
+	}
240
+
241
+	free(points);
242
+
243
+	return 0;
244
+}

+ 17
- 0
gitter/screen.h View File

@@ -0,0 +1,17 @@
1
+#ifndef SCREEN_H
2
+#define SCREEN_H
3
+
4
+#include "globals.h"
5
+
6
+typedef struct {
7
+	float x;
8
+	float y;
9
+} pixel_t;
10
+
11
+void sdl_init();
12
+int main_loop();
13
+
14
+void draw_line(pixel_t *p1, pixel_t *p2);
15
+void draw_blob(pixel_t *p1);
16
+
17
+#endif  /*SCREEN_H*/