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

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