ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.21
Committed: Fri Apr 7 20:08:57 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.20: +0 -1 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 for (values %Client::Widget::ACTIVE_WIDGETS) {
94 $_->draw
95 }
96
97 SDL::GLSwapBuffers;
98 }
99
100 %SDL_CB = (
101 SDL_QUIT() => sub {
102 main_quit Gtk2;
103 },
104 SDL_VIDEORESIZE() => sub {
105 },
106 SDL_VIDEOEXPOSE() => sub {
107 refresh;
108 },
109 SDL_KEYDOWN() => sub {
110 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
111 # alt-enter
112 $CFG->{fullscreen} = !$CFG->{fullscreen};
113 init_screen;
114 } else {
115 Client::Widget::feed_sdl_key_down_event ($SDL_EV);
116 }
117 },
118 SDL_KEYUP() => sub {
119 Client::Widget::feed_sdl_key_up_event ($SDL_EV);
120 },
121 SDL_MOUSEMOTION() => sub {
122 warn "sdl motion\n";#d#
123 },
124 SDL_MOUSEBUTTONDOWN() => sub {
125 Client::Widget::feed_sdl_button_down_event ($SDL_EV);
126 },
127 SDL_MOUSEBUTTONUP() => sub {
128 Client::Widget::feed_sdl_button_up_event ($SDL_EV);
129 },
130 SDL_ACTIVEEVENT() => sub {
131 warn "active\n";#d#
132 },
133 );
134
135 @conn::ISA = Crossfire::Protocol::;
136
137 sub conn::map_update {
138 my ($self, $dirty) = @_;
139
140 refresh;
141 }
142
143 sub conn::map_scroll {
144 my ($self, $dx, $dy) = @_;
145
146 refresh;
147 }
148
149 sub conn::map_clear {
150 my ($self) = @_;
151
152 refresh;
153 }
154
155 sub conn::face_find {
156 my ($self, $face) = @_;
157
158 $FACECACHE->{"$face->{chksum},$face->{name}"}
159 }
160
161 sub conn::face_update {
162 my ($self, $face) = @_;
163
164 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
165
166 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
167 }
168
169 #############################################################################
170
171 SDL::Init(SDL_INIT_EVERYTHING());
172
173 my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
174
175 #find_rcfile "uifont.ttf";
176
177 $mapwidget->activate;
178 $mapwidget->focus_in;
179
180 read_cfg "$Crossfire::VARDIR/pclientrc";
181
182 $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
183
184 $CFG ||= {
185 width => 640,
186 height => 480,
187 fullscreen => 0,
188 host => "crossfire.schmorp.de",
189 port => 13327,
190 };
191
192 Crossfire::Client::Util::run_config_dialog
193 login => sub { start_game },
194 logout => sub { stop_game };
195
196 main Gtk2;
197
198 Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";