FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
minetest/src/game.cpp at master · basicinside/minetest · GitHub
basicinside
/
minetest
Public
forked from
kahrl/minetest
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
minetest
/
src
/
game.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
2490 lines (2170 loc) · 59.1 KB
Breadcrumbs
minetest
/
src
/
game.cpp
Copy path
File metadata and controls
2490 lines (2170 loc) · 59.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Minetest-c55
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#
include
"
game.h
"
#
include
"
common_irrlicht.h
"
#
include
<
IGUICheckBox.h
>
#
include
<
IGUIEditBox.h
>
#
include
<
IGUIButton.h
>
#
include
<
IGUIStaticText.h
>
#
include
<
IGUIFont.h
>
#
include
"
client.h
"
#
include
"
server.h
"
#
include
"
guiPauseMenu.h
"
#
include
"
guiPasswordChange.h
"
#
include
"
guiInventoryMenu.h
"
#
include
"
guiTextInputMenu.h
"
#
include
"
guiDeathScreen.h
"
#
include
"
materials.h
"
#
include
"
config.h
"
#
include
"
clouds.h
"
#
include
"
camera.h
"
#
include
"
farmesh.h
"
#
include
"
mapblock.h
"
#
include
"
settings.h
"
#
include
"
profiler.h
"
#
include
"
mainmenumanager.h
"
#
include
"
craftitemdef.h
"
#
include
"
gettext.h
"
#
include
"
log.h
"
#
include
"
filesys.h
"
//
Needed for determining pointing to nodes
#
include
"
nodedef.h
"
#
include
"
nodemetadata.h
"
#
include
"
main.h
"
//
For g_settings
#
include
"
tooldef.h
"
#
include
"
tile.h
"
//
For TextureSource
#
include
"
logoutputbuffer.h
"
/*
Setting this to 1 enables a special camera mode that forces
the renderers to think that the camera statically points from
the starting place to a static direction.
This allows one to move around with the player and see what
is actually drawn behind solid things and behind the player.
*/
#
define
FIELD_OF_VIEW_TEST
0
//
Chat data
struct
ChatLine
{
ChatLine
():
age
(
0.0
)
{
}
ChatLine
(
const
std::wstring &a_text):
age
(
0.0
),
text
(a_text)
{
}
float
age;
std::wstring text;
};
/*
Inventory stuff
*/
//
Inventory actions from the menu are buffered here before sending
Queue<InventoryAction*> inventory_action_queue;
//
This is a copy of the inventory that the client's environment has
Inventory local_inventory;
/*
Text input system
*/
struct
TextDestChat
:
public
TextDest
{
TextDestChat
(Client *client)
{
m_client = client;
}
void
gotText
(std::wstring text)
{
//
Discard empty line
if
(text ==
L"
"
)
return
;
//
Send to others
m_client->
sendChatMessage
(text);
//
Show locally
m_client->
addChatMessage
(text);
}
Client *m_client;
};
struct
TextDestNodeMetadata
:
public
TextDest
{
TextDestNodeMetadata
(v3s16 p, Client *client)
{
m_p = p;
m_client = client;
}
void
gotText
(std::wstring text)
{
std::string ntext =
wide_to_narrow
(text);
infostream<<
"
Changing text of a sign node:
"
<<ntext<<std::endl;
m_client->
sendSignNodeText
(m_p, ntext);
}
v3s16 m_p;
Client *m_client;
};
/*
Respawn menu callback
*/
class
MainRespawnInitiator
:
public
IRespawnInitiator
{
public:
MainRespawnInitiator
(
bool
*active, Client *client):
m_active
(active), m_client(client)
{
*m_active =
true
;
}
void
respawn
()
{
*m_active =
false
;
m_client->
sendRespawn
();
}
private:
bool
*m_active;
Client *m_client;
};
/*
Hotbar draw routine
*/
void
draw_hotbar
(video::IVideoDriver *driver, gui::IGUIFont *font,
ITextureSource *tsrc,
v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
Inventory *inventory, s32 halfheartcount,
u16
playeritem)
{
InventoryList *mainlist = inventory->
getList
(
"
main
"
);
if
(mainlist ==
NULL
)
{
errorstream<<
"
draw_hotbar(): mainlist == NULL
"
<<std::endl;
return
;
}
s32 padding = imgsize/
12
;
//
s32 height = imgsize + padding*2;
s32 width = itemcount*(imgsize+padding*
2
);
//
Position of upper left corner of bar
v2s32 pos = centerlowerpos -
v2s32
(width/
2
, imgsize+padding*
2
);
//
Draw background color
/*
core::rect<s32> barrect(0,0,width,height);
barrect += pos;
video::SColor bgcolor(255,128,128,128);
driver->draw2DRectangle(bgcolor, barrect, NULL);
*/
core::rect<s32>
imgrect
(
0
,
0
,imgsize,imgsize);
for
(s32 i=
0
; i<itemcount; i++)
{
InventoryItem *item = mainlist->
getItem
(i);
core::rect<s32> rect = imgrect + pos
+
v2s32
(padding+i*(imgsize+padding*
2
), padding);
if
(playeritem == i)
{
video::SColor
c_outside
(
255
,
255
,
0
,
0
);
//
video::SColor c_outside(255,0,0,0);
//
video::SColor c_inside(255,192,192,192);
s32 x1 = rect.
UpperLeftCorner
.
X
;
s32 y1 = rect.
UpperLeftCorner
.
Y
;
s32 x2 = rect.
LowerRightCorner
.
X
;
s32 y2 = rect.
LowerRightCorner
.
Y
;
//
Black base borders
driver->
draw2DRectangle
(c_outside,
core::rect<s32>(
v2s32
(x1 - padding, y1 - padding),
v2s32
(x2 + padding, y1)
),
NULL
);
driver->
draw2DRectangle
(c_outside,
core::rect<s32>(
v2s32
(x1 - padding, y2),
v2s32
(x2 + padding, y2 + padding)
),
NULL
);
driver->
draw2DRectangle
(c_outside,
core::rect<s32>(
v2s32
(x1 - padding, y1),
v2s32
(x1, y2)
),
NULL
);
driver->
draw2DRectangle
(c_outside,
core::rect<s32>(
v2s32
(x2, y1),
v2s32
(x2 + padding, y2)
),
NULL
);
/*
// Light inside borders
driver->draw2DRectangle(c_inside,
core::rect<s32>(
v2s32(x1 - padding/2, y1 - padding/2),
v2s32(x2 + padding/2, y1)
), NULL);
driver->draw2DRectangle(c_inside,
core::rect<s32>(
v2s32(x1 - padding/2, y2),
v2s32(x2 + padding/2, y2 + padding/2)
), NULL);
driver->draw2DRectangle(c_inside,
core::rect<s32>(
v2s32(x1 - padding/2, y1),
v2s32(x1, y2)
), NULL);
driver->draw2DRectangle(c_inside,
core::rect<s32>(
v2s32(x2, y1),
v2s32(x2 + padding/2, y2)
), NULL);
*/
}
video::SColor
bgcolor2
(
128
,
0
,
0
,
0
);
driver->
draw2DRectangle
(bgcolor2, rect,
NULL
);
if
(item !=
NULL
)
{
drawInventoryItem
(driver, font, item, rect,
NULL
, tsrc);
}
}
/*
Draw hearts
*/
video::ITexture *heart_texture = tsrc->
getTextureRaw
(
"
heart.png
"
);
if
(heart_texture)
{
v2s32 p = pos +
v2s32
(
0
, -
20
);
for
(s32 i=
0
; i<halfheartcount/
2
; i++)
{
const
video::SColor
color
(
255
,
255
,
255
,
255
);
const
video::SColor colors[] = {color,color,color,color};
core::rect<s32>
rect
(
0
,
0
,
16
,
16
);
rect += p;
driver->
draw2DImage
(heart_texture, rect,
core::rect<s32>(core::position2d<s32>(
0
,
0
),
core::dimension2di
(heart_texture->
getOriginalSize
())),
NULL
, colors,
true
);
p +=
v2s32
(
16
,
0
);
}
if
(halfheartcount %
2
==
1
)
{
const
video::SColor
color
(
255
,
255
,
255
,
255
);
const
video::SColor colors[] = {color,color,color,color};
core::rect<s32>
rect
(
0
,
0
,
16
/
2
,
16
);
rect += p;
core::dimension2di
srcd
(heart_texture->
getOriginalSize
());
srcd.
Width
/=
2
;
driver->
draw2DImage
(heart_texture, rect,
core::rect<s32>(core::position2d<s32>(
0
,
0
), srcd),
NULL
, colors,
true
);
p +=
v2s32
(
16
,
0
);
}
}
}
/*
Check if a node is pointable
*/
inline
bool
isPointableNode
(
const
MapNode& n,
Client *client,
bool
liquids_pointable)
{
const
ContentFeatures &features = client->
getNodeDefManager
()->
get
(n);
return
features.
pointable
||
(liquids_pointable && features.
isLiquid
());
}
/*
Find what the player is pointing at
*/
PointedThing
getPointedThing
(Client *client, v3f player_position,
v3f camera_direction, v3f camera_position,
core::line3d<
f32
> shootline,
f32
d,
bool
liquids_pointable,
bool
look_for_object,
core::aabbox3d<
f32
> &hilightbox,
bool
&should_show_hilightbox,
ClientActiveObject *&selected_object)
{
PointedThing result;
hilightbox = core::aabbox3d<
f32
>(
0
,
0
,
0
,
0
,
0
,
0
);
should_show_hilightbox =
false
;
selected_object =
NULL
;
//
First try to find a pointed at active object
if
(look_for_object)
{
selected_object = client->
getSelectedActiveObject
(d*
BS
,
camera_position, shootline);
}
if
(selected_object !=
NULL
)
{
core::aabbox3d<
f32
> *selection_box
= selected_object->
getSelectionBox
();
//
Box should exist because object was returned in the
//
first place
assert
(selection_box);
v3f pos = selected_object->
getPosition
();
hilightbox = core::aabbox3d<
f32
>(
selection_box->
MinEdge
+ pos,
selection_box->
MaxEdge
+ pos
);
should_show_hilightbox = selected_object->
doShowSelectionBox
();
result.
type
=
POINTEDTHING_OBJECT
;
result.
object_id
= selected_object->
getId
();
return
result;
}
//
That didn't work, try to find a pointed at node
f32
mindistance =
BS
*
1001
;
v3s16 pos_i =
floatToInt
(player_position,
BS
);
/*
infostream<<"pos_i=("<<pos_i.X<<","<<pos_i.Y<<","<<pos_i.Z<<")"
<<std::endl;
*/
s16 a = d;
s16 ystart = pos_i.
Y
+
0
- (camera_direction.
Y
<
0
? a :
1
);
s16 zstart = pos_i.
Z
- (camera_direction.
Z
<
0
? a :
1
);
s16 xstart = pos_i.
X
- (camera_direction.
X
<
0
? a :
1
);
s16 yend = pos_i.
Y
+
1
+ (camera_direction.
Y
>
0
? a :
1
);
s16 zend = pos_i.
Z
+ (camera_direction.
Z
>
0
? a :
1
);
s16 xend = pos_i.
X
+ (camera_direction.
X
>
0
? a :
1
);
for
(s16 y = ystart; y <= yend; y++)
for
(s16 z = zstart; z <= zend; z++)
for
(s16 x = xstart; x <= xend; x++)
{
MapNode n;
try
{
n = client->
getNode
(
v3s16
(x,y,z));
}
catch
(InvalidPositionException &e)
{
continue
;
}
if
(!
isPointableNode
(n, client, liquids_pointable))
continue
;
v3s16
np
(x,y,z);
v3f npf =
intToFloat
(np,
BS
);
f32
d =
0.01
;
v3s16 dirs[
6
] = {
v3s16
(
0
,
0
,
1
),
//
back
v3s16
(
0
,
1
,
0
),
//
top
v3s16
(
1
,
0
,
0
),
//
right
v3s16
(
0
,
0
,-
1
),
//
front
v3s16
(
0
,-
1
,
0
),
//
bottom
v3s16
(-
1
,
0
,
0
),
//
left
};
const
ContentFeatures &f = client->
getNodeDefManager
()->
get
(n);
if
(f.
selection_box
.
type
==
NODEBOX_FIXED
)
{
core::aabbox3d<
f32
> box = f.
selection_box
.
fixed
;
box.
MinEdge
+= npf;
box.
MaxEdge
+= npf;
v3s16 facedirs[
6
] = {
v3s16
(-
1
,
0
,
0
),
v3s16
(
1
,
0
,
0
),
v3s16
(
0
,-
1
,
0
),
v3s16
(
0
,
1
,
0
),
v3s16
(
0
,
0
,-
1
),
v3s16
(
0
,
0
,
1
),
};
core::aabbox3d<
f32
> faceboxes[
6
] = {
//
X-
core::aabbox3d<
f32
>(
box.
MinEdge
.
X
, box.
MinEdge
.
Y
, box.
MinEdge
.
Z
,
box.
MinEdge
.
X
+d, box.
MaxEdge
.
Y
, box.
MaxEdge
.
Z
),
//
X+
core::aabbox3d<
f32
>(
box.
MaxEdge
.
X
-d, box.
MinEdge
.
Y
, box.
MinEdge
.
Z
,
box.
MaxEdge
.
X
, box.
MaxEdge
.
Y
, box.
MaxEdge
.
Z
),
//
Y-
core::aabbox3d<
f32
>(
box.
MinEdge
.
X
, box.
MinEdge
.
Y
, box.
MinEdge
.
Z
,
box.
MaxEdge
.
X
, box.
MinEdge
.
Y
+d, box.
MaxEdge
.
Z
),
//
Y+
core::aabbox3d<
f32
>(
box.
MinEdge
.
X
, box.
MaxEdge
.
Y
-d, box.
MinEdge
.
Z
,
box.
MaxEdge
.
X
, box.
MaxEdge
.
Y
, box.
MaxEdge
.
Z
),
//
Z-
core::aabbox3d<
f32
>(
box.
MinEdge
.
X
, box.
MinEdge
.
Y
, box.
MinEdge
.
Z
,
box.
MaxEdge
.
X
, box.
MaxEdge
.
Y
, box.
MinEdge
.
Z
+d
),
//
Z+
core::aabbox3d<
f32
>(
box.
MinEdge
.
X
, box.
MinEdge
.
Y
, box.
MaxEdge
.
Z
-d,
box.
MaxEdge
.
X
, box.
MaxEdge
.
Y
, box.
MaxEdge
.
Z
),
};
for
(
u16
i=
0
; i<
6
; i++)
{
v3f
facedir_f
(facedirs[i].
X
, facedirs[i].
Y
, facedirs[i].
Z
);
v3f centerpoint = npf + facedir_f *
BS
/
2
;
f32
distance = (centerpoint - camera_position).
getLength
();
if
(distance >= mindistance)
continue
;
if
(!faceboxes[i].
intersectsWithLine
(shootline))
continue
;
result.
type
=
POINTEDTHING_NODE
;
result.
node_undersurface
= np;
result.
node_abovesurface
= np+facedirs[i];
mindistance = distance;
hilightbox = box;
should_show_hilightbox =
true
;
}
}
else
if
(f.
selection_box
.
type
==
NODEBOX_WALLMOUNTED
)
{
v3s16 dir =
unpackDir
(n.
param2
);
v3f dir_f =
v3f
(dir.
X
, dir.
Y
, dir.
Z
);
dir_f *=
BS
/
2
-
BS
/
6
-
BS
/
20
;
v3f cpf = npf + dir_f;
f32
distance = (cpf - camera_position).
getLength
();
core::aabbox3d<
f32
> box;
//
top
if
(dir ==
v3s16
(
0
,
1
,
0
)){
box = f.
selection_box
.
wall_top
;
}
//
bottom
else
if
(dir ==
v3s16
(
0
,-
1
,
0
)){
box = f.
selection_box
.
wall_bottom
;
}
//
side
else
{
v3f vertices[
2
] =
{
f.
selection_box
.
wall_side
.
MinEdge
,
f.
selection_box
.
wall_side
.
MaxEdge
};
for
(s32 i=
0
; i<
2
; i++)
{
if
(dir ==
v3s16
(-
1
,
0
,
0
))
vertices[i].
rotateXZBy
(
0
);
if
(dir ==
v3s16
(
1
,
0
,
0
))
vertices[i].
rotateXZBy
(
180
);
if
(dir ==
v3s16
(
0
,
0
,-
1
))
vertices[i].
rotateXZBy
(
90
);
if
(dir ==
v3s16
(
0
,
0
,
1
))
vertices[i].
rotateXZBy
(-
90
);
}
box = core::aabbox3d<
f32
>(vertices[
0
]);
box.
addInternalPoint
(vertices[
1
]);
}
box.
MinEdge
+= npf;
box.
MaxEdge
+= npf;
if
(distance < mindistance)
{
if
(box.
intersectsWithLine
(shootline))
{
result.
type
=
POINTEDTHING_NODE
;
result.
node_undersurface
= np;
result.
node_abovesurface
= np;
mindistance = distance;
hilightbox = box;
should_show_hilightbox =
true
;
}
}
}
else
//
NODEBOX_REGULAR
{
for
(
u16
i=
0
; i<
6
; i++)
{
v3f dir_f =
v3f
(dirs[i].
X
,
dirs[i].
Y
, dirs[i].
Z
);
v3f centerpoint = npf + dir_f *
BS
/
2
;
f32
distance =
(centerpoint - camera_position).
getLength
();
if
(distance < mindistance)
{
core::CMatrix4<
f32
> m;
m.
buildRotateFromTo
(
v3f
(
0
,
0
,
1
), dir_f);
//
This is the back face
v3f corners[
2
] = {
v3f
(
BS
/
2
,
BS
/
2
,
BS
/
2
),
v3f
(-
BS
/
2
, -
BS
/
2
,
BS
/
2
+d)
};
for
(
u16
j=
0
; j<
2
; j++)
{
m.
rotateVect
(corners[j]);
corners[j] += npf;
}
core::aabbox3d<
f32
>
facebox
(corners[
0
]);
facebox.
addInternalPoint
(corners[
1
]);
if
(facebox.
intersectsWithLine
(shootline))
{
result.
type
=
POINTEDTHING_NODE
;
result.
node_undersurface
= np;
result.
node_abovesurface
= np + dirs[i];
mindistance = distance;
//
hilightbox = facebox;
const
float
d =
0.502
;
core::aabbox3d<
f32
> nodebox
(-
BS
*d, -
BS
*d, -
BS
*d,
BS
*d,
BS
*d,
BS
*d);
v3f nodepos_f =
intToFloat
(np,
BS
);
nodebox.
MinEdge
+= nodepos_f;
nodebox.
MaxEdge
+= nodepos_f;
hilightbox = nodebox;
should_show_hilightbox =
true
;
}
}
//
if distance < mindistance
}
//
for dirs
}
//
regular block
}
//
for coords
return
result;
}
void
update_skybox
(video::IVideoDriver* driver, ITextureSource *tsrc,
scene::ISceneManager* smgr, scene::ISceneNode* &skybox,
float
brightness)
{
if
(skybox)
{
skybox->
remove
();
}
/*
// Disable skybox if FarMesh is enabled
if(g_settings->getBool("enable_farmesh"))
return;
*/
if
(brightness >=
0.5
)
{
skybox = smgr->
addSkyBoxSceneNode
(
tsrc->
getTextureRaw
(
"
skybox2.png
"
),
tsrc->
getTextureRaw
(
"
skybox3.png
"
),
tsrc->
getTextureRaw
(
"
skybox1.png
"
),
tsrc->
getTextureRaw
(
"
skybox1.png
"
),
tsrc->
getTextureRaw
(
"
skybox1.png
"
),
tsrc->
getTextureRaw
(
"
skybox1.png
"
));
}
else
if
(brightness >=
0.2
)
{
skybox = smgr->
addSkyBoxSceneNode
(
tsrc->
getTextureRaw
(
"
skybox2_dawn.png
"
),
tsrc->
getTextureRaw
(
"
skybox3_dawn.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_dawn.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_dawn.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_dawn.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_dawn.png
"
));
}
else
{
skybox = smgr->
addSkyBoxSceneNode
(
tsrc->
getTextureRaw
(
"
skybox2_night.png
"
),
tsrc->
getTextureRaw
(
"
skybox3_night.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_night.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_night.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_night.png
"
),
tsrc->
getTextureRaw
(
"
skybox1_night.png
"
));
}
}
/*
Draws a screen with a single text on it.
Text will be removed when the screen is drawn the next time.
*/
/*
gui::IGUIStaticText *
*/
void
draw_load_screen
(
const
std::wstring &text,
video::IVideoDriver* driver, gui::IGUIFont* font)
{
v2u32 screensize = driver->
getScreenSize
();
const
wchar_t
*loadingtext = text.
c_str
();
core::vector2d<
u32
> textsize_u = font->
getDimension
(loadingtext);
core::vector2d<s32>
textsize
(textsize_u.
X
,textsize_u.
Y
);
core::vector2d<s32>
center
(screensize.
X
/
2
, screensize.
Y
/
2
);
core::rect<s32>
textrect
(center - textsize/
2
, center + textsize/
2
);
gui::IGUIStaticText *guitext = guienv->
addStaticText
(
loadingtext, textrect,
false
,
false
);
guitext->
setTextAlignment
(gui::
EGUIA_CENTER
, gui::
EGUIA_UPPERLEFT
);
driver->
beginScene
(
true
,
true
,
video::SColor
(
255
,
0
,
0
,
0
));
guienv->
drawAll
();
driver->
endScene
();
guitext->
remove
();
//
return guitext;
}
void
the_game
(
bool
&kill,
bool
random_input,
InputHandler *input,
IrrlichtDevice *device,
gui::IGUIFont* font,
std::string map_dir,
std::string playername,
std::string password,
std::string address,
u16
port,
std::wstring &error_message,
std::string configpath
)
{
video::IVideoDriver* driver = device->
getVideoDriver
();
scene::ISceneManager* smgr = device->
getSceneManager
();
//
Calculate text height using the font
u32
text_height = font->
getDimension
(
L"
Random test string
"
).
Height
;
v2u32
screensize
(
0
,
0
);
v2u32
last_screensize
(
0
,
0
);
screensize = driver->
getScreenSize
();
const
s32 hotbar_itemcount =
8
;
//
const s32 hotbar_imagesize = 36;
//
const s32 hotbar_imagesize = 64;
s32 hotbar_imagesize =
48
;
//
The color of the sky
//
video::SColor skycolor = video::SColor(255,140,186,250);
video::SColor bgcolor_bright =
video::SColor
(
255
,
170
,
200
,
230
);
/*
Draw "Loading" screen
*/
draw_load_screen
(
L"
Loading...
"
, driver, font);
//
Create texture source
IWritableTextureSource *tsrc =
createTextureSource
(device);
//
These will be filled by data received from the server
//
Create tool definition manager
IWritableToolDefManager *tooldef =
createToolDefManager
();
//
Create node definition manager
IWritableNodeDefManager *nodedef =
createNodeDefManager
();
//
Create CraftItem definition manager
IWritableCraftItemDefManager *craftitemdef =
createCraftItemDefManager
();
//
Add chat log output for errors to be shown in chat
LogOutputBuffer
chat_log_error_buf
(
LMT_ERROR
);
/*
Create server.
SharedPtr will delete it when it goes out of scope.
*/
SharedPtr<Server> server;
if
(address ==
"
"
){
draw_load_screen
(
L"
Creating server...
"
, driver, font);
infostream<<
"
Creating server
"
<<std::endl;
server =
new
Server
(map_dir, configpath);
server->
start
(port);
}
{
//
Client scope
/*
Create client
*/
draw_load_screen
(
L"
Creating client...
"
, driver, font);
infostream<<
"
Creating client
"
<<std::endl;
MapDrawControl draw_control;
Client
client
(device, playername.
c_str
(), password, draw_control,
tsrc, tooldef, nodedef, craftitemdef);
//
Client acts as our GameDef
IGameDef *gamedef = &client;
draw_load_screen
(
L"
Resolving address...
"
, driver, font);
Address
connect_address
(
0
,
0
,
0
,
0
, port);
try
{
if
(address ==
"
"
)
//
connect_address.Resolve("localhost");
connect_address.
setAddress
(
127
,
0
,
0
,
1
);
else
connect_address.
Resolve
(address.
c_str
());
}
catch
(ResolveError &e)
{
errorstream<<
"
Couldn't resolve address
"
<<std::endl;
//
return 0;
error_message =
L"
Couldn't resolve address
"
;
//
gui_loadingtext->remove();
return
;
}
/*
Attempt to connect to the server
*/
infostream<<
"
Connecting to server at
"
;
connect_address.
print
(&infostream);
infostream<<std::endl;
client.
connect
(connect_address);
/*
Wait for server to accept connection
*/
bool
could_connect =
false
;
try
{
float
frametime =
0.033
;
const
float
timeout =
10.0
;
float
time_counter =
0.0
;
for
(;;)
{
//
Update client and server
client.
step
(frametime);
if
(server !=
NULL
)
server->
step
(frametime);
//
End condition
if
(client.
connectedAndInitialized
()){
could_connect =
true
;
break
;
}
//
Break conditions
if
(client.
accessDenied
())
break
;
if
(time_counter >= timeout)
break
;
//
Display status
std::wostringstream ss;
ss<<
L"
Connecting to server... (timeout in
"
;
ss<<(
int
)(timeout - time_counter +
1.0
);
ss<<
L"
seconds)
"
;
draw_load_screen
(ss.
str
(), driver, font);
//
Delay a bit
sleep_ms
(
1000
*frametime);
time_counter += frametime;
}
}
catch
(con::PeerNotFoundException &e)
{}
/*
Handle failure to connect
*/
if
(could_connect ==
false
)
{
if
(client.
accessDenied
())
{
error_message =
L"
Access denied. Reason:
"
+client.
accessDeniedReason
();
errorstream<<
wide_to_narrow
(error_message)<<std::endl;
}
else
{
error_message =
L"
Connection timed out.
"
;
errorstream<<
"
Timed out.
"
<<std::endl;
}
//
gui_loadingtext->remove();
return
;
}
/*
Wait until content has been received
*/
bool
got_content =
false
;
{
float
frametime =
0.033
;
const
float
timeout =
30.0
;
float
time_counter =
0.0
;
for
(;;)
{
//
Update client and server
client.
step
(frametime);
if
(server !=
NULL
)
server->
step
(frametime);
//
End condition
if
(client.
texturesReceived
() &&
client.
tooldefReceived
() &&
client.
nodedefReceived
() &&
client.
craftitemdefReceived
()){
got_content =
true
;
break
;
}
//
Break conditions
if
(!client.
connectedAndInitialized
())
break
;
if
(time_counter >= timeout)
break
;
//
Display status
std::wostringstream ss;
ss<<
L"
Waiting content... (continuing anyway in
"
;
ss<<(
int
)(timeout - time_counter +
1.0
);
ss<<
L"
seconds)
\n
"
;
ss<<(client.
tooldefReceived
()?
L"
[X]
"
:
L"
[ ]
"
);
ss<<
L"
Tool definitions
\n
"
;
ss<<(client.
nodedefReceived
()?
L"
[X]
"
:
L"
[ ]
"
);
ss<<
L"
Node definitions
\n
"
;
ss<<(client.
craftitemdefReceived
()?
L"
[X]
"
:
L"
[ ]
"
);
ss<<
L"
Item definitions
\n
"
;
//
ss<<(client.texturesReceived()?L"[X]":L"[ ]");
ss<<
L"
[
"
<<(
int
)(client.
textureReceiveProgress
()*
100
+
0.5
)<<
L"
%]
"
;
ss<<
L"
Textures
\n
"
;
draw_load_screen
(ss.
str
(), driver, font);
//
Delay a bit
sleep_ms
(
1000
*frametime);
time_counter += frametime;
}
}
/*
Create skybox
*/
float
old_brightness =
1.0
;
scene::ISceneNode* skybox =
NULL
;
update_skybox
(driver, tsrc, smgr, skybox,
1.0
);
/*
Create the camera node
*/
Camera
camera
(smgr, draw_control);
if
(!camera.
successfullyCreated
(error_message))
return
;
f32
camera_yaw =
0
;
//
"right/left"
f32
camera_pitch =
0
;
//
"up/down"
/*
Clouds
*/
float
cloud_height =
BS
*
100
;
Clouds *clouds =
NULL
;
if
(g_settings->
getBool
(
"
enable_clouds
"
))
{
clouds =
new
Clouds
(smgr->
getRootSceneNode
(), smgr, -
1
,
cloud_height,
time
(
0
));
}
/*
FarMesh
*/
FarMesh *farmesh =
NULL
;
if
(g_settings->
getBool
(
"
enable_farmesh
"
))
{
farmesh =
new
FarMesh
(smgr->
getRootSceneNode
(), smgr, -
1
, client.
getMapSeed
(), &client);
}
/*
Move into game
*/
//
gui_loadingtext->remove();
/*
Add some gui stuff
*/
//
First line of debug text
gui::IGUIStaticText *guitext = guienv->
addStaticText
(
L"
Minetest-c55
"
,
core::rect<s32>(
5
,
5
,
795
,
5
+text_height),
false
,
false
);
//
Second line of debug text
gui::IGUIStaticText *guitext2 = guienv->
addStaticText
(
L"
"
,
core::rect<s32>(
5
,
5
+(text_height+
5
)*
1
,
795
, (
5
+text_height)*
2
),
false
,
false
);
//
At the middle of the screen
//
Object infos are shown in this
gui::IGUIStaticText *guitext_info = guienv->
addStaticText
(
L"
"
,
core::rect<s32>(
0
,
0
,
400
,text_height+
5
) +
v2s32
(
100
,
200
),
false
,
false
);
//
Chat text
gui::IGUIStaticText *guitext_chat = guienv->
addStaticText
(
L"
"
,
core::rect<s32>(
0
,
0
,
0
,
0
),
//
false, false); // Disable word wrap as of now
false
,
true
);
//
guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
core::list<ChatLine> chat_lines;
//
Profiler text (size is updated when text is updated)
gui::IGUIStaticText *guitext_profiler = guienv->
addStaticText
(
L"
<Profiler>
"
,
core::rect<s32>(
6
,
4
+(text_height+
5
)*
2
,
400
,
(text_height+
5
)*
2
+ text_height*
35
),
false
,
false
);
guitext_profiler->
setBackgroundColor
(
video::SColor
(
80
,
0
,
0
,
0
));
guitext_profiler->
setVisible
(
false
);
/*
GUIQuickInventory *quick_inventory = new GUIQuickInventory
(guienv, NULL, v2s32(10, 70), 5, &local_inventory);
*/
/*
GUIQuickInventory *quick_inventory = new GUIQuickInventory
(guienv, NULL, v2s32(0, 0), quickinv_itemcount, &local_inventory);
*/
//
Test the text input system
/*
(new GUITextInputMenu(guienv, guiroot, -1, &g_menumgr,
NULL))->drop();
*/
/*
GUIMessageMenu *menu =
new GUIMessageMenu(guienv, guiroot, -1,
&g_menumgr,
L"Asd");
menu->drop();
*/
//
Launch pause menu
(
new
GUIPauseMenu
(guienv, guiroot, -
1
, g_gamecallback,
&g_menumgr))->
drop
();
//
Enable texts
/*
guitext2->setVisible(true);
guitext_info->setVisible(true);
guitext_chat->setVisible(true);
*/
//
s32 guitext_chat_pad_bottom = 70;
/*
Some statistics are collected in these
*/
u32
drawtime =
0
;
u32
beginscenetime =
0
;
u32
scenetime =
0
;
u32
endscenetime =
0
;
//
A test
//
throw con::PeerNotFoundException("lol");
float
brightness =
1.0
;
core::list<
float
> frametime_log;
float
nodig_delay_timer =
0.0
;
float
dig_time =
0.0
;
u16
dig_index =
0
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL