… | |
… | |
22 | |
22 | |
23 | our $FACECACHE; |
23 | our $FACECACHE; |
24 | |
24 | |
25 | our $VERSION = '0.1'; |
25 | our $VERSION = '0.1'; |
26 | |
26 | |
|
|
27 | our %GL_EXT; |
|
|
28 | |
27 | our $CFG; |
29 | our $CFG; |
28 | our $CONN; |
30 | our $CONN; |
|
|
31 | |
|
|
32 | our $WIDTH; |
|
|
33 | our $HEIGHT; |
|
|
34 | our $FULLSCREEN; |
29 | |
35 | |
30 | our $UIFONT; |
36 | our $UIFONT; |
31 | |
37 | |
32 | our $SDL_TIMER; |
38 | our $SDL_TIMER; |
33 | our $SDL_APP; |
39 | our $SDL_APP; |
34 | our $SDL_EV = new SDL::Event; |
40 | our $SDL_EV = new SDL::Event; |
35 | our %SDL_CB; |
41 | our %SDL_CB; |
36 | |
42 | |
37 | our @GL_INIT; # hooks called on every gl init |
43 | our @GL_INIT; # hooks called on every gl init |
38 | |
44 | |
|
|
45 | our $ALT_ENTER_MESSAGE; |
|
|
46 | |
39 | sub init_screen { |
47 | sub init_screen { |
40 | $SDL_APP = new SDL::App |
48 | $SDL_APP = new SDL::App |
41 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
49 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
42 | -title => "Crossfire+ Client", |
50 | -title => "Crossfire+ Client", |
43 | -width => $CFG->{width}, |
51 | -width => $WIDTH, |
44 | -height => $CFG->{height}, |
52 | -height => $HEIGHT, |
45 | -opengl => 1, |
53 | -opengl => 1, |
46 | -red_size => 8, |
54 | -red_size => 8, |
47 | -green_size => 8, |
55 | -green_size => 8, |
48 | -blue_size => 8, |
56 | -blue_size => 8, |
49 | -double_buffer => 1, |
57 | -double_buffer => 1, |
50 | -fullscreen => $CFG->{fullscreen}, |
58 | -fullscreen => $FULLSCREEN, |
51 | -resizeable => 0; |
59 | -resizeable => 0; |
52 | |
60 | |
|
|
61 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
|
|
62 | |
|
|
63 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
|
|
64 | or warn "WARNING: non-power-of-two opengl extension required"; |
|
|
65 | |
53 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $CFG->{height} / 40 |
66 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
54 | or die "TTFOpenFont: $!"; |
67 | or die "TTFOpenFont: $!"; |
|
|
68 | |
|
|
69 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; |
|
|
70 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
|
|
71 | $ALT_ENTER_MESSAGE->activate; |
55 | |
72 | |
56 | glClearColor 0, 0, 0, 0; |
73 | glClearColor 0, 0, 0, 0; |
57 | |
74 | |
58 | glEnable GL_TEXTURE_2D; |
75 | glEnable GL_TEXTURE_2D; |
59 | glShadeModel GL_FLAT; |
76 | glShadeModel GL_FLAT; |
60 | glDisable GL_DEPTH_TEST; |
77 | glDisable GL_DEPTH_TEST; |
61 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
78 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
62 | |
79 | |
63 | glMatrixMode GL_PROJECTION; |
80 | glMatrixMode GL_PROJECTION; |
64 | glLoadIdentity; |
81 | glLoadIdentity; |
65 | glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; |
82 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
66 | |
83 | |
67 | glMatrixMode GL_MODELVIEW; |
84 | glMatrixMode GL_MODELVIEW; |
68 | |
85 | |
69 | $_->() for @GL_INIT; |
86 | $_->() for @GL_INIT; |
70 | } |
87 | } |
71 | |
88 | |
72 | my $label;#d# |
|
|
73 | |
|
|
74 | sub start_game { |
89 | sub start_game { |
75 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
90 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
76 | while ($SDL_EV->poll) { |
|
|
77 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
91 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
78 | } |
92 | while $SDL_EV->poll; |
79 | |
93 | |
80 | 1 |
94 | 1 |
81 | }; |
95 | }; |
82 | |
96 | |
|
|
97 | $WIDTH = $CFG->{width}; |
|
|
98 | $HEIGHT = $CFG->{height}; |
|
|
99 | $FULLSCREEN = 0; |
|
|
100 | |
83 | init_screen; |
101 | init_screen; |
84 | |
|
|
85 | my $v = new Crossfire::Client::Widget::Table; |
|
|
86 | $v->add (0, 0, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "T"); |
|
|
87 | $v->add (0, 1, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "TT"); |
|
|
88 | $v->add (0, 2, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "TTT"); |
|
|
89 | $v->add (1, 1, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"); |
|
|
90 | $v->size_request; |
|
|
91 | my $f = new Crossfire::Client::Widget::Frame; |
|
|
92 | $f->add ($v); |
|
|
93 | $f->activate; |
|
|
94 | |
|
|
95 | # $v->add ($label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"); |
|
|
96 | # $v->add ($label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]!!"); |
|
|
97 | # $v->activate; |
|
|
98 | # $f->add ($v);#$label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"); |
|
|
99 | # $label->activate; |
|
|
100 | |
102 | |
101 | $CONN = new conn |
103 | $CONN = new conn |
102 | host => $CFG->{host}, |
104 | host => $CFG->{host}, |
103 | port => $CFG->{port}, |
105 | port => $CFG->{port}, |
104 | user => $CFG->{user}, |
106 | user => $CFG->{user}, |
… | |
… | |
110 | |
112 | |
111 | undef $SDL_APP; |
113 | undef $SDL_APP; |
112 | SDL::Quit; |
114 | SDL::Quit; |
113 | } |
115 | } |
114 | |
116 | |
|
|
117 | |
|
|
118 | sub force_refresh { |
|
|
119 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
120 | glClear GL_COLOR_BUFFER_BIT; |
|
|
121 | |
|
|
122 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
123 | |
|
|
124 | SDL::GLSwapBuffers; |
|
|
125 | } |
|
|
126 | |
|
|
127 | my $refresh_handler; |
|
|
128 | |
115 | sub refresh { |
129 | sub refresh { |
116 | glClear GL_COLOR_BUFFER_BIT; |
130 | $refresh_handler ||= add Glib::Idle sub { |
117 | |
131 | force_refresh; |
118 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
132 | undef $refresh_handler; |
119 | |
133 | 0 |
120 | SDL::GLSwapBuffers; |
134 | }; |
121 | } |
135 | } |
122 | |
136 | |
123 | %SDL_CB = ( |
137 | %SDL_CB = ( |
124 | SDL_QUIT() => sub { |
138 | SDL_QUIT() => sub { |
125 | main_quit Gtk2; |
139 | main_quit Gtk2; |
… | |
… | |
130 | refresh; |
144 | refresh; |
131 | }, |
145 | }, |
132 | SDL_KEYDOWN() => sub { |
146 | SDL_KEYDOWN() => sub { |
133 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
147 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
134 | # alt-enter |
148 | # alt-enter |
135 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
149 | $FULLSCREEN = !$FULLSCREEN; |
136 | init_screen; |
150 | init_screen; |
137 | } else { |
151 | } else { |
138 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
152 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
139 | } |
153 | } |
140 | }, |
154 | }, |