ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.19
Committed: Fri Apr 7 19:33:42 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.18: +21 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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.19 our $FACECACHE;
22    
23 root 1.13 our $VERSION = '0.1';
24 root 1.2
25 elmex 1.10 our $CFG;
26 root 1.13 our $CONN;
27 root 1.2
28 root 1.13 our $SDL_TIMER;
29     our $SDL_APP;
30     our $SDL_EV = new SDL::Event;
31     our %SDL_CB;
32 root 1.18
33     our @GL_INIT; # hooks called on every gl init
34 root 1.2
35 root 1.13 sub init_screen {
36     $SDL_APP = new SDL::App
37 root 1.5 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
38     -title => "Crossfire+ Client",
39 root 1.13 -width => $CFG->{width},
40     -height => $CFG->{height},
41 root 1.5 -opengl => 1,
42     -red_size => 8,
43     -green_size => 8,
44     -blue_size => 8,
45 root 1.2 -double_buffer => 1,
46 root 1.13 -fullscreen => $CFG->{fullscreen},
47 root 1.5 -resizeable => 0;
48 root 1.2
49 root 1.19 glClearColor 0, 0, 0, 0;
50    
51 root 1.2 glEnable GL_TEXTURE_2D;
52 root 1.9 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
53 root 1.2 glShadeModel GL_FLAT;
54     glDisable GL_DEPTH_TEST;
55 root 1.9 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
56 root 1.8 glEnable GL_BLEND;
57 root 1.2
58 root 1.9 glMatrixMode GL_PROJECTION;
59 root 1.4 glLoadIdentity;
60 root 1.19 glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -100 , 100;
61    
62     glMatrixMode GL_MODELVIEW;
63 root 1.4
64 root 1.17 $_->() for @GL_INIT;
65 root 1.2 }
66    
67 root 1.13 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 root 1.2 sub refresh {
91 root 1.5 glClear GL_COLOR_BUFFER_BIT;
92 root 1.2
93 elmex 1.16 for (values %Client::Widget::ACTIVE_WIDGETS) {
94     $_->draw
95 root 1.2 }
96 root 1.1
97 root 1.2 SDL::GLSwapBuffers;
98 root 1.1 }
99    
100 root 1.13 %SDL_CB = (
101     SDL_QUIT() => sub {
102     warn "sdl quit\n";#d#
103 root 1.19 main_quit Gtk2;
104 root 1.13 },
105     SDL_VIDEORESIZE() => sub {
106     },
107     SDL_VIDEOEXPOSE() => sub {
108     refresh;
109     },
110     SDL_KEYDOWN() => sub {
111 root 1.18 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
112     # alt-enter
113     $CFG->{fullscreen} = !$CFG->{fullscreen};
114     init_screen;
115     } else {
116     Client::Widget::feed_sdl_key_down_event ($SDL_EV);
117     }
118 root 1.13 },
119     SDL_KEYUP() => sub {
120 elmex 1.16 Client::Widget::feed_sdl_key_up_event ($SDL_EV);
121 root 1.13 },
122     SDL_MOUSEMOTION() => sub {
123     warn "sdl motion\n";#d#
124     },
125     SDL_MOUSEBUTTONDOWN() => sub {
126 elmex 1.16 Client::Widget::feed_sdl_button_down_event ($SDL_EV);
127 root 1.13 },
128     SDL_MOUSEBUTTONUP() => sub {
129 elmex 1.16 Client::Widget::feed_sdl_button_up_event ($SDL_EV);
130 root 1.13 },
131     SDL_ACTIVEEVENT() => sub {
132     warn "active\n";#d#
133     },
134     );
135 root 1.1
136 root 1.2 @conn::ISA = Crossfire::Protocol::;
137 root 1.1
138 root 1.2 sub conn::map_update {
139 root 1.1 my ($self, $dirty) = @_;
140    
141 root 1.2 refresh;
142 root 1.1 }
143    
144 root 1.2 sub conn::map_scroll {
145 root 1.1 my ($self, $dx, $dy) = @_;
146    
147 root 1.2 refresh;
148 root 1.1 }
149    
150 root 1.2 sub conn::map_clear {
151 root 1.1 my ($self) = @_;
152    
153 root 1.2 refresh;
154 root 1.1 }
155    
156 root 1.19 sub conn::face_find {
157     my ($self, $face) = @_;
158    
159     $FACECACHE->{"$face->{chksum},$face->{name}"}
160     }
161    
162 root 1.2 sub conn::face_update {
163 root 1.19 my ($self, $face) = @_;
164    
165     $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
166 root 1.1
167 root 1.18 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
168 root 1.1 }
169    
170     #############################################################################
171    
172 elmex 1.16 my $mapwidget = Client::MapWidget->new;
173    
174     $mapwidget->activate;
175     $mapwidget->focus_in;
176    
177 elmex 1.11 Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc";
178 elmex 1.10
179 root 1.19 $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
180    
181 root 1.13 $CFG ||= {
182     width => 640,
183     height => 480,
184     fullscreen => 0,
185     host => "crossfire.schmorp.de",
186     port => 13327,
187     };
188 elmex 1.12
189 elmex 1.14 Client::Util::run_config_dialog
190 elmex 1.16 login => sub { start_game },
191     logout => sub { stop_game };
192 root 1.1
193 root 1.13 main Gtk2;
194 root 1.19
195     Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";