1 |
root |
1.1 |
#!/opt/bin/perl |
2 |
root |
1.2 |
use strict; |
3 |
|
|
|
4 |
root |
1.13 |
use Glib; |
5 |
|
|
use Gtk2 -init; |
6 |
|
|
|
7 |
|
|
use SDL; |
8 |
|
|
use SDL::App; |
9 |
|
|
use SDL::Event; |
10 |
|
|
use SDL::Surface; |
11 |
|
|
use SDL::OpenGL; |
12 |
|
|
use SDL::OpenGL::Constants; |
13 |
|
|
|
14 |
elmex |
1.11 |
use Crossfire; |
15 |
root |
1.2 |
use Crossfire::Client; |
16 |
|
|
use Crossfire::Protocol; |
17 |
|
|
|
18 |
elmex |
1.10 |
use Client::Util; |
19 |
elmex |
1.15 |
use Client::Widget; |
20 |
elmex |
1.10 |
|
21 |
root |
1.13 |
our $VERSION = '0.1'; |
22 |
root |
1.2 |
|
23 |
elmex |
1.10 |
our $CFG; |
24 |
root |
1.13 |
our $CONN; |
25 |
root |
1.2 |
|
26 |
root |
1.13 |
our $SDL_TIMER; |
27 |
|
|
our $SDL_APP; |
28 |
|
|
our $SDL_EV = new SDL::Event; |
29 |
|
|
our %SDL_CB; |
30 |
root |
1.17 |
our @GL_INIT; |
31 |
root |
1.2 |
|
32 |
root |
1.13 |
sub init_screen { |
33 |
|
|
$SDL_APP = new SDL::App |
34 |
root |
1.5 |
-flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
35 |
|
|
-title => "Crossfire+ Client", |
36 |
root |
1.13 |
-width => $CFG->{width}, |
37 |
|
|
-height => $CFG->{height}, |
38 |
root |
1.5 |
-opengl => 1, |
39 |
|
|
-red_size => 8, |
40 |
|
|
-green_size => 8, |
41 |
|
|
-blue_size => 8, |
42 |
root |
1.2 |
-double_buffer => 1, |
43 |
root |
1.13 |
-fullscreen => $CFG->{fullscreen}, |
44 |
root |
1.5 |
-resizeable => 0; |
45 |
root |
1.2 |
|
46 |
|
|
glEnable GL_TEXTURE_2D; |
47 |
root |
1.9 |
glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
48 |
root |
1.2 |
glShadeModel GL_FLAT; |
49 |
|
|
glDisable GL_DEPTH_TEST; |
50 |
root |
1.9 |
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
51 |
root |
1.8 |
glEnable GL_BLEND; |
52 |
root |
1.2 |
|
53 |
root |
1.9 |
glMatrixMode GL_PROJECTION; |
54 |
root |
1.4 |
glLoadIdentity; |
55 |
root |
1.13 |
glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -1 , 1; |
56 |
root |
1.4 |
|
57 |
root |
1.17 |
$_->() for @GL_INIT; |
58 |
root |
1.2 |
} |
59 |
|
|
|
60 |
root |
1.13 |
sub start_game { |
61 |
|
|
$SDL_TIMER = add Glib::Timeout 1000/20, sub { |
62 |
|
|
while ($SDL_EV->poll) { |
63 |
|
|
($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
1 |
67 |
|
|
}; |
68 |
|
|
|
69 |
|
|
init_screen; |
70 |
|
|
|
71 |
|
|
$CONN = new conn |
72 |
|
|
host => $CFG->{host}, |
73 |
|
|
port => $CFG->{port}; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
sub stop_game { |
77 |
|
|
remove Glib::Source $SDL_TIMER; |
78 |
|
|
|
79 |
|
|
undef $SDL_APP; |
80 |
|
|
SDL::Quit; |
81 |
|
|
} |
82 |
|
|
|
83 |
root |
1.2 |
sub refresh { |
84 |
root |
1.8 |
glClearColor 0, 0, 0, 0; |
85 |
root |
1.5 |
glClear GL_COLOR_BUFFER_BIT; |
86 |
root |
1.2 |
|
87 |
elmex |
1.16 |
for (values %Client::Widget::ACTIVE_WIDGETS) { |
88 |
|
|
$_->draw |
89 |
root |
1.2 |
} |
90 |
root |
1.1 |
|
91 |
root |
1.2 |
SDL::GLSwapBuffers; |
92 |
root |
1.1 |
} |
93 |
|
|
|
94 |
root |
1.13 |
%SDL_CB = ( |
95 |
|
|
SDL_QUIT() => sub { |
96 |
|
|
warn "sdl quit\n";#d# |
97 |
|
|
exit; |
98 |
|
|
}, |
99 |
|
|
SDL_VIDEORESIZE() => sub { |
100 |
|
|
}, |
101 |
|
|
SDL_VIDEOEXPOSE() => sub { |
102 |
|
|
refresh; |
103 |
|
|
}, |
104 |
|
|
SDL_KEYDOWN() => sub { |
105 |
elmex |
1.16 |
Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
106 |
root |
1.13 |
}, |
107 |
|
|
SDL_KEYUP() => sub { |
108 |
elmex |
1.16 |
Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
109 |
root |
1.13 |
}, |
110 |
|
|
SDL_MOUSEMOTION() => sub { |
111 |
|
|
warn "sdl motion\n";#d# |
112 |
|
|
}, |
113 |
|
|
SDL_MOUSEBUTTONDOWN() => sub { |
114 |
elmex |
1.16 |
Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
115 |
root |
1.13 |
}, |
116 |
|
|
SDL_MOUSEBUTTONUP() => sub { |
117 |
elmex |
1.16 |
Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
118 |
root |
1.13 |
}, |
119 |
|
|
SDL_ACTIVEEVENT() => sub { |
120 |
|
|
warn "active\n";#d# |
121 |
|
|
}, |
122 |
|
|
); |
123 |
root |
1.1 |
|
124 |
root |
1.2 |
@conn::ISA = Crossfire::Protocol::; |
125 |
root |
1.1 |
|
126 |
root |
1.2 |
sub conn::map_update { |
127 |
root |
1.1 |
my ($self, $dirty) = @_; |
128 |
|
|
|
129 |
root |
1.2 |
refresh; |
130 |
root |
1.1 |
} |
131 |
|
|
|
132 |
root |
1.2 |
sub conn::map_scroll { |
133 |
root |
1.1 |
my ($self, $dx, $dy) = @_; |
134 |
|
|
|
135 |
root |
1.2 |
refresh; |
136 |
root |
1.1 |
} |
137 |
|
|
|
138 |
root |
1.2 |
sub conn::map_clear { |
139 |
root |
1.1 |
my ($self) = @_; |
140 |
|
|
|
141 |
root |
1.2 |
refresh; |
142 |
root |
1.1 |
} |
143 |
|
|
|
144 |
root |
1.2 |
sub conn::face_update { |
145 |
root |
1.1 |
my ($self, $num, $face) = @_; |
146 |
|
|
|
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
############################################################################# |
150 |
|
|
|
151 |
elmex |
1.16 |
my $mapwidget = Client::MapWidget->new; |
152 |
|
|
|
153 |
|
|
$mapwidget->activate; |
154 |
|
|
$mapwidget->focus_in; |
155 |
|
|
|
156 |
elmex |
1.11 |
Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc"; |
157 |
elmex |
1.10 |
|
158 |
root |
1.13 |
$CFG ||= { |
159 |
|
|
width => 640, |
160 |
|
|
height => 480, |
161 |
|
|
fullscreen => 0, |
162 |
|
|
host => "crossfire.schmorp.de", |
163 |
|
|
port => 13327, |
164 |
|
|
}; |
165 |
elmex |
1.12 |
|
166 |
elmex |
1.14 |
Client::Util::run_config_dialog |
167 |
elmex |
1.16 |
login => sub { start_game }, |
168 |
|
|
logout => sub { stop_game }; |
169 |
root |
1.1 |
|
170 |
root |
1.13 |
main Gtk2; |