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