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