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

# 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.20 use Crossfire::Client::Util;
19     use Crossfire::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 root 1.19 main_quit Gtk2;
103 root 1.13 },
104     SDL_VIDEORESIZE() => sub {
105     },
106     SDL_VIDEOEXPOSE() => sub {
107     refresh;
108     },
109     SDL_KEYDOWN() => sub {
110 root 1.18 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 root 1.13 },
118     SDL_KEYUP() => sub {
119 elmex 1.16 Client::Widget::feed_sdl_key_up_event ($SDL_EV);
120 root 1.13 },
121     SDL_MOUSEMOTION() => sub {
122     warn "sdl motion\n";#d#
123     },
124     SDL_MOUSEBUTTONDOWN() => sub {
125 elmex 1.16 Client::Widget::feed_sdl_button_down_event ($SDL_EV);
126 root 1.13 },
127     SDL_MOUSEBUTTONUP() => sub {
128 elmex 1.16 Client::Widget::feed_sdl_button_up_event ($SDL_EV);
129 root 1.13 },
130     SDL_ACTIVEEVENT() => sub {
131     warn "active\n";#d#
132     },
133     );
134 root 1.1
135 root 1.2 @conn::ISA = Crossfire::Protocol::;
136 root 1.1
137 root 1.2 sub conn::map_update {
138 root 1.1 my ($self, $dirty) = @_;
139    
140 root 1.2 refresh;
141 root 1.1 }
142    
143 root 1.2 sub conn::map_scroll {
144 root 1.1 my ($self, $dx, $dy) = @_;
145    
146 root 1.2 refresh;
147 root 1.1 }
148    
149 root 1.2 sub conn::map_clear {
150 root 1.1 my ($self) = @_;
151    
152 root 1.2 refresh;
153 root 1.1 }
154    
155 root 1.19 sub conn::face_find {
156     my ($self, $face) = @_;
157    
158     $FACECACHE->{"$face->{chksum},$face->{name}"}
159     }
160    
161 root 1.2 sub conn::face_update {
162 root 1.19 my ($self, $face) = @_;
163    
164     $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
165 root 1.1
166 root 1.18 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
167 root 1.1 }
168    
169     #############################################################################
170    
171 elmex 1.20 SDL::Init(SDL_INIT_EVERYTHING());
172    
173     my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
174    
175     #find_rcfile "uifont.ttf";
176 elmex 1.16
177     $mapwidget->activate;
178     $mapwidget->focus_in;
179    
180 elmex 1.20 read_cfg "$Crossfire::VARDIR/pclientrc";
181 elmex 1.10
182 root 1.19 $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
183    
184 root 1.13 $CFG ||= {
185     width => 640,
186     height => 480,
187     fullscreen => 0,
188     host => "crossfire.schmorp.de",
189     port => 13327,
190     };
191 elmex 1.12
192 elmex 1.20 Crossfire::Client::Util::run_config_dialog
193 elmex 1.16 login => sub { start_game },
194     logout => sub { stop_game };
195 root 1.1
196 root 1.13 main Gtk2;
197 root 1.19
198     Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";