ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.18
Committed: Fri Apr 7 18:49:53 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.17: +10 -2 lines
Log Message:
*** empty log message ***

File Contents

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