-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path3dfsb.c
2500 lines (2229 loc) · 77.5 KB
/
3dfsb.c
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
/***************************************************************************
3dfsb.c - 3D filesystem browser
-------------------
begin : Fri Feb 23 2001
copyleft : (C) 2014 - 2015 by Tom Van Braeckel as 3dfsb
copyright : (C) 2001 - 2007 by Leander Seige as tdfsb
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/***************************************************************************
Everything here is released under the GPL and maintained by Tom Van Braeckel.
Help is welcome. I would like to invite everyone to make improvements so
if you have bugreports, additional code, bugfixes, comments, suggestions,
questions, testing reports, quality measures or something similar, do get in touch!
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <ctype.h>
#include <math.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <GL/glut.h>
#include <SDL.h>
#include <SDL_image.h>
#include <GL/gl.h>
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
#include <GL/glx.h>
#include "SDL/SDL_syswm.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
#include <gst/gst.h>
#pragma GCC diagnostic pop
#include <magic.h>
#include <regex.h>
// For saving pixbuf's to a file for debugging
/*
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
#include <gtk/gtk.h>
#pragma GCC diagnostic pop
*/
// Icons
#include "images/icon_pdf.xpm"
// Own headers
#include "3dfsb.h"
#include "input.h"
#include "str_replace.h"
#include "tools.h"
#include "media.h"
#include "config.h"
#ifndef _GLUfuncptr
#define _GLUfuncptr void*
#endif
const SDL_VideoInfo *info = NULL;
GLUquadricObj *aua1, *aua2;
//unsigned long int www, hhh, p2w, p2h, cglmode;
long int c1, cc, cc1;
static GLuint TDFSB_DisplayLists = 0;
static GLuint TDFSB_CylinderList = 0;
static GLuint TDFSB_AudioList = 0;
static GLuint TDFSB_HelpList = 0;
static GLuint TDFSB_SolidList = 0;
static GLuint TDFSB_BlendList = 0;
unsigned long int total_objects_in_grid;
unsigned int total_objects_in_grid_ratio;
GLdouble mx, my, mz, r, u, v;
struct tree_entry *root, *FMptr;
char *FCptr;
char fullpath[4096], yabuf[4096];
char *alert_kc = "MALFORMED KEYBOARD MAP";
char *alert_kc2 = "USING DEFAULTS";
unsigned char ch;
GLuint TDFSB_TEX_NUM;
GLuint *TDFSB_TEX_NAMES;
char *help_copy;
int cnt;
GLdouble prevlen;
#define NUMBER_OF_EXTENSIONS 3
char *xsuff[NUMBER_OF_EXTENSIONS];
unsigned int tsuff[NUMBER_OF_EXTENSIONS];
char *nsuff[NUMBER_OF_FILETYPES];
GLfloat fh, fh2, mono;
struct timeval ltime, ttime, rtime, wtime;
long sec;
GLdouble TDFSB_NORTH_X = 0, TDFSB_NORTH_Z = 0;
GLfloat TDFSB_MAXX, TDFSB_MAXZ;
GLfloat TDFSB_MINX, TDFSB_MINZ;
GLfloat TDFSB_STEPX, TDFSB_STEPZ;
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_red[] = { 1.0, 0.0, 0.0, 0.5 };
GLfloat mat_ambient_grn[] = { 0.0, 1.0, 0.0, 0.5 };
GLfloat mat_ambient_yel[] = { 1.0, 1.0, 0.0, 0.5 };
GLfloat mat_ambient_gry[] = { 1.0, 1.0, 1.0, 0.25 };
GLfloat mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat mat_diffuse_red[] = { 1.0, 0.0, 0.0, 0.5 };
GLfloat mat_diffuse_grn[] = { 0.0, 1.0, 0.0, 0.5 };
GLfloat mat_diffuse_yel[] = { 1.0, 1.0, 0.0, 0.5 };
GLfloat mat_diffuse_gry[] = { 1.0, 1.0, 1.0, 0.25 };
GLfloat mat_specular[] = { 0.9, 0.9, 0.9, 1.0 };
GLfloat mat_specular_red[] = { 1.0, 0.0, 0.0, 0.5 };
GLfloat mat_specular_grn[] = { 0.0, 1.0, 0.0, 0.5 };
GLfloat mat_specular_yel[] = { 1.0, 1.0, 0.0, 0.5 };
GLfloat mat_specular_gry[] = { 1.0, 1.0, 1.0, 0.25 };
GLfloat mat_emission[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_emission_red[] = { 0.4, 0.2, 0.2, 0.5 };
GLfloat mat_emission_grn[] = { 0.2, 0.4, 0.2, 0.5 };
GLfloat mat_emission_yel[] = { 0.4, 0.4, 0.2, 0.5 };
GLfloat mat_emission_gry[] = { 0.3, 0.3, 0.3, 0.25 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 1.0, 2.0, 1.0, 0.0 };
DIR *mydir, *tempdir;
struct dirent *myent;
static GLfloat spin = 0.0;
static GLfloat verTex2[] = {
0.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0, 1.0,
0.0, 0.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0,
1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 0.0, 0.0, 1.0, 1.0, -1.0, 1.0,
0.0, 1.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0,
0.0, 0.0, 0.0, 0.0, -1.0, -1.0, 1.0, -1.0,
1.0, 0.0, 0.0, 0.0, -1.0, 1.0, 1.0, -1.0,
1.0, 1.0, 0.0, 0.0, -1.0, 1.0, -1.0, -1.0,
0.99, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, /* please mail me if you know why 1.0 doesn't work here but 0.99 */
0.99, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, -1.0,
0.99, 0.99, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0,
0.99, 0.99, 1.0, 0.0, 0.0, 1.0, -1.0, 1.0,
0.0, 1.0, -1.0, 0.0, 0.0, -1.0, -1.0, -1.0,
0.0, 1.0, -1.0, 0.0, 0.0, -1.0, -1.0, 1.0,
0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 1.0, 1.0,
0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 1.0, -1.0,
1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, -1.0,
1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 1.0, 1.0,
0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 1.0, -1.0
};
/* Texture Normals Vertex */
// Used both for the on-screen display and for the console help text
#define STATIC_HELP_TEXT \
"3D File System Browser\n" \
"----------------------\n" \
"Esc quit F1/F2 speed +/-\n" \
"Mouse move look F3/F4 rot +/-\n" \
"UP forward F5/F6 ball detail\n" \
"DOWN backward F7/F8 max fps +/-\n" \
"L/R arrow strafe F9 change tool\n" \
"PgUp/Down or MMB+Mouse move up/downward\n" \
"HOME start pos END ground zero\n" \
"CTRL approach F12 send input\n" \
"SHIFT+TAB start x-terminal-emulator\n" \
"Left Mouse/ENTER apply tool on object\n\n" \
static void display(void);
static void standstillDisplay(void);
int keyboard(unsigned char key);
int keyboardup(unsigned char key);
//int keyfinder(unsigned char key);
//int keyupfinder(unsigned char key);
int speckey(int key);
int specupkey(int key);
// Mimetype database handle
magic_t magic;
// Asynchronous texture loading
pthread_t async_load_textures_thread_id = (pthread_t) NULL;
GAsyncQueue *loaded_textures_queue = NULL;
void ende(int code)
{
struct tree_entry *help;
// Stop the texture rendering thread *before* the GStreamer cleanups because the texture rendering thread *uses* the GStreamer data
if (async_load_textures_thread_id) {
pthread_cancel(async_load_textures_thread_id);
async_load_textures_thread_id = (pthread_t) NULL;
}
cleanup_media_player();
gst_deinit();
magic_close(magic); // Mimetype database
glDeleteTextures(TDFSB_TEX_NUM, TDFSB_TEX_NAMES);
if (TDFSB_TEX_NAMES != NULL)
free(TDFSB_TEX_NAMES);
if (total_objects_in_grid != 0) {
help = root;
while (help) {
//printf("Freeing %s\n", help->name);
FMptr = help;
FCptr = help->name;
free(FCptr);
if (help->openwith != NULL)
free(help->openwith);
if (help->textfilecontents != NULL) {
FCptr = (char *)help->textfilecontents;
free(FCptr);
}
// Free up any texturesurface's that are set
if (help->texturesurface != NULL) {
SDL_FreeSurface(help->texturesurface);
help->texturesurface = NULL;
}
if (help->linkpath != NULL) {
FCptr = help->linkpath;
free(FCptr);
}
help = help->next;
free(FMptr);
}
root = NULL;
total_objects_in_grid = 0;
}
free(help_str); // This can only be free'd in the end, because we need it every time the user asks for help
SDL_Quit();
exit(code);
}
static char *uppercase(char *str)
{
char *newstr, *p;
p = newstr = strdup(str);
while (*p) {
*p = (char)toupper(*p);
p++;
}
return newstr;
}
tree_entry *calculate_scale(tree_entry * object)
{
if (object->originalwidth < object->originalheight) {
object->scalex = object->scalez = ((GLfloat) log(((double)object->originalwidth / 128) + 1)) + 1;
object->scaley = (object->originalheight * (object->scalex)) / object->originalwidth;
} else {
object->scaley = ((GLfloat) log(((double)object->originalheight / 128) + 1)) + 1;
object->scalex = object->scalez = (object->originalwidth * (object->scaley)) / object->originalheight;
}
object->posy = object->scaley - 1; // vertical position of the object
object->scalez = 0.5; // make the objects flatscreens because I don't like the big square blocks :-)
return object;
}
static int get_file_type(char *filename, const char *mimetype)
{
unsigned int temptype = 0; // temptype needs to be 0 to check if we found a match later on!
unsigned int extensionnr;
//printf("Got mimetype: %s for file %s\n", mimetype, filename);
if (!strncmp(mimetype, MIME_TEXT, 5)) {
temptype = TEXTFILE;
} else if (!strncmp(mimetype, MIME_IMAGE, 6)) {
temptype = IMAGEFILE;
} else if (!strncmp(mimetype, MIME_VIDEO, 6)) {
temptype = VIDEOFILE;
} else if (!strncmp(mimetype, MIME_AUDIO, 6)) {
temptype = AUDIOFILE;
} else if (!strncmp(mimetype, MIME_PDF, 15)) {
temptype = PDFFILE;
} else {
// Some files are not identified by magic_file(), so we fallback to extension-based identification here
for (extensionnr = 0; extensionnr < NUMBER_OF_EXTENSIONS; extensionnr++) {
char *xsuff_upper = uppercase(xsuff[extensionnr]);
char *ext_upper = uppercase(&(filename[strlen(filename) - strlen(xsuff[extensionnr])]));
if (!strncmp(xsuff_upper, ext_upper, strlen(xsuff[extensionnr]))) {
temptype = tsuff[extensionnr];
break;
}
}
// As a last resort, we consider it an unknown file
if (!temptype)
temptype = UNKNOWNFILE;
}
return temptype;
}
// This new thread loads the textures
static void *async_load_textures(void *arg)
{
UNUSED(arg);
// For each object, load its texture and (if possible) set the dimensions...
struct tree_entry *object;
for (object = root; object; object = object->next) {
// For regular files or device files (because the others don't have textures (yet),
// but I think these can be either symlinks or real files because of the way this "mode" property is devised...
if ((((object->mode) & 0x1F) != 0) && ((object->mode) & 0x1F) != 2 && (object->regtype != PROCESS))
continue;
char async_fullpath[4096] = { 0 }; // allocate on the stack for automatic free'ing
strcpy(async_fullpath, TDFSB_CURRENTPATH);
if (strlen(async_fullpath) > 1)
strcat(async_fullpath, "/");
strcat(async_fullpath, object->name);
printf("Loading texture of %s\n", async_fullpath);
if (object->regtype == TEXTFILE) {
FILE *fileptr = fopen(async_fullpath, "r");
if (!fileptr) {
printf("TEXT FAILED: %s\n", async_fullpath);
} else {
object->textfilecontents = (unsigned char *)malloc(1000 * sizeof(unsigned char));
fread(object->textfilecontents, sizeof(char), 1000, fileptr);
fclose(fileptr);
}
} else if (object->regtype == IMAGEFILE || object->regtype == VIDEOFILE || object->regtype == VIDEOSOURCEFILE || object->regtype == PROCESS) {
texture_description *result = get_image_from_file(async_fullpath, object->regtype, TDFSB_MAX_TEX_SIZE);
if (result) {
object->originalwidth = result->originalwidth;
object->originalheight = result->originalheight;
object->textureformat = result->textureformat;
object->texturesurface = result->texturesurface;
}
} else if (object->regtype == PDFFILE) {
// Show the PDF logo
// This is also possible:
// object->texturesurface = get_image_from_file("images/icon_pdf.png", IMAGEFILE);
SDL_Surface *loader = IMG_ReadXPMFromArray(icon_pdf);
SDL_PixelFormat RGBAFormat;
RGBAFormat.palette = 0;
RGBAFormat.colorkey = 0;
RGBAFormat.alpha = 0;
RGBAFormat.BitsPerPixel = 32;
RGBAFormat.BytesPerPixel = 4;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
RGBAFormat.Rmask = 0xFF000000;
RGBAFormat.Rshift = 0;
RGBAFormat.Rloss = 0;
RGBAFormat.Gmask = 0x00FF0000;
RGBAFormat.Gshift = 8;
RGBAFormat.Gloss = 0;
RGBAFormat.Bmask = 0x0000FF00;
RGBAFormat.Bshift = 16;
RGBAFormat.Bloss = 0;
RGBAFormat.Amask = 0x000000FF;
RGBAFormat.Ashift = 24;
RGBAFormat.Aloss = 0;
#else
RGBAFormat.Rmask = 0x000000FF;
RGBAFormat.Rshift = 24;
RGBAFormat.Rloss = 0;
RGBAFormat.Gmask = 0x0000FF00;
RGBAFormat.Gshift = 16;
RGBAFormat.Gloss = 0;
RGBAFormat.Bmask = 0x00FF0000;
RGBAFormat.Bshift = 8;
RGBAFormat.Bloss = 0;
RGBAFormat.Amask = 0xFF000000;
RGBAFormat.Ashift = 0;
RGBAFormat.Aloss = 0;
#endif
object->texturesurface = SDL_ConvertSurface(loader, &RGBAFormat, SDL_SWSURFACE);
object->textureformat = GL_RGBA;
object->originalwidth = 512;
object->originalheight = 512;
}
if (object->texturesurface) {
object->texturewidth = object->texturesurface->w;
object->textureheight = object->texturesurface->h;
printf("Original dimensions: %dx%d %s TEXTURE: %dx%d\n", object->originalwidth, object->originalheight, async_fullpath, object->texturewidth, object->textureheight);
object = calculate_scale(object);
// Add to queue to redraw/retexture this object in the rendering thread
g_async_queue_push(loaded_textures_queue, object);
}
} // end of directory entry iterator
printf("Finished loading all textures, texture loading thread exiting...\n");
return NULL;
}
/*
* Redraw the (fairly static) list of solid shapes in the world,
* which should only be updated when first entering a directory
* or when a new texture is loaded, which means the texture size comes known,
* and the the size of (one of) the blocks must be updated.
* About ~300 lines of code
*/
static void tdb_gen_list(void)
{
int mat_state;
struct tree_entry *help;
mat_state = 0;
glNewList(TDFSB_SolidList, GL_COMPILE);
for (help = root; help; help = help->next) {
//printf("Adding file %s with mode %x and regtype %x\n", help->name, help->mode, help->regtype);
if (help->tombstone)
continue; // Skip files that are tombstoned
glPushMatrix();
mx = help->posx;
mz = help->posz;
my = help->posy;
if ((((help->mode) & 0x1F) == 1 || ((help->mode) & 0x1F) == 11) && help->regtype != PROCESS) { // Directory
glTranslatef(mx, my, mz);
if ((help->mode) & 0x20)
glutSolidSphere(0.5, TDFSB_BALL_DETAIL, TDFSB_BALL_DETAIL);
else
glutSolidSphere(1, TDFSB_BALL_DETAIL, TDFSB_BALL_DETAIL);
} else if ((((help->mode) & 0x1F) == 0 || ((help->mode) & 0x1F) == 10) || ((((help->mode) & 0x1F) == 2) && (help->regtype == VIDEOSOURCEFILE)) || (help->regtype == PROCESS) || (help == TDFSB_MEDIA_FILE)) { // Regular file, except VIDEOSOURCEFILE's, which are character devices
if ((((help->regtype == IMAGEFILE) || (help->regtype == PDFFILE) || (help->regtype == VIDEOFILE) || (help->regtype == VIDEOSOURCEFILE)) && (((help->mode) & 0x1F) == 0 || ((help->mode) & 0x1F) == 2)) || (help->regtype == PROCESS) || (help == TDFSB_MEDIA_FILE)) {
if ((help->mode) & 0x20) {
glTranslatef(mx, 0, mz);
if (help->scalex > help->scaley) {
if (help->scalex > help->scalez)
glScalef(0.5, 0.5 * (help->scaley) / (help->scalex), 0.5 * (help->scalez) / (help->scalex)); /* x am groessten */
else
glScalef(0.5 * (help->scalex) / (help->scalez), 0.5 * (help->scaley) / (help->scalez), 0.5); /* z am groessten */
} else if (help->scaley > help->scalez)
glScalef(0.5 * (help->scalex) / (help->scaley), 0.5, 0.5 * (help->scalez) / (help->scaley)); /* y am groessten */
else
glScalef(0.5 * (help->scalex) / (help->scalez), 0.5 * (help->scaley) / (help->scalez), 0.5); /* z am groessten */
} else {
glTranslatef(mx, my, mz);
glScalef(help->scalex, help->scaley, help->scalez);
}
// Link the texture to the cube
//printf("Linking texture with id %d to cube for object with name %s\n", help->textureid, help->name);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, help->textureid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
// Draw the cube
if (TDFSB_ICUBE)
cc1 = 20;
else
cc1 = 4;
glBegin(GL_QUADS);
for (cc = 0; cc < cc1; cc++) {
glNormal3f(verTex2[cc * 8 + 2], verTex2[cc * 8 + 3], verTex2[cc * 8 + 4]);
glTexCoord2f(verTex2[cc * 8 + 0], verTex2[cc * 8 + 1]);
glVertex3f(verTex2[cc * 8 + 5], verTex2[cc * 8 + 6], verTex2[cc * 8 + 7]);
}
glEnd();
glDisable(GL_TEXTURE_2D);
} else if (help->regtype == UNKNOWNFILE) {
if ((help->mode) & 0x20) {
glTranslatef(mx, 0, mz);
if (help->scalex > help->scaley) {
if (help->scalex > help->scalez)
glScalef(0.5, 0.5 * (help->scaley) / (help->scalex), 0.5 * (help->scalez) / (help->scalex)); /* x am groessten */
else
glScalef(0.5 * (help->scalex) / (help->scalez), 0.5 * (help->scaley) / (help->scalez), 0.5); /* z am groessten */
} else if (help->scaley > help->scalez)
glScalef(0.5 * (help->scalex) / (help->scaley), 0.5, 0.5 * (help->scalez) / (help->scaley)); /* y am groessten */
else
glScalef(0.5 * (help->scalex) / (help->scalez), 0.5 * (help->scaley) / (help->scalez), 0.5); /* z am groessten */
} else {
glTranslatef(mx, my, mz);
glScalef(help->scalex, help->scaley, help->scalez);
}
glutSolidCube(2);
}
} else {
if ((help->mode) != 0x25) {
glTranslatef(mx, my, mz);
if (((help->mode) & 0x20))
glScalef(0.5, 0.5, 0.5);
glutSolidOctahedron();
}
}
glPopMatrix();
}
/* drawing the ground grid */
glPushMatrix();
glDisable(GL_LIGHTING);
glColor4f(TDFSB_GG_R, TDFSB_GG_G, TDFSB_GG_B, 1.0);
unsigned int gridnr;
for (gridnr = 0; gridnr <= 20; gridnr++) {
glBegin(GL_LINES);
glVertex3f(TDFSB_MINX + TDFSB_STEPX * gridnr, -1, TDFSB_MINZ);
glVertex3f(TDFSB_MINX + TDFSB_STEPX * gridnr, -1, TDFSB_MAXZ);
glVertex3f(TDFSB_MINX, -1, TDFSB_MINZ + TDFSB_STEPZ * gridnr);
glVertex3f(TDFSB_MAXX, -1, TDFSB_MINZ + TDFSB_STEPZ * gridnr);
glEnd();
}
glEnable(GL_LIGHTING);
glPopMatrix();
glEndList();
glNewList(TDFSB_BlendList, GL_COMPILE);
glEnable(GL_LIGHTING);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Draw text files
mat_state = 0;
for (help = root; help; help = help->next) {
if (help->tombstone)
continue; // Skip files that are tombstoned
mx = help->posx;
mz = help->posz;
my = help->posy;
if (((help->regtype == TEXTFILE) && ((help->mode) & 0x1F) == 0) && (help != TDFSB_MEDIA_FILE)) {
if (!mat_state) {
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_yel);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_yel);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_yel);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission_yel);
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse_yel);
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient_yel);
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular_yel);
glMaterialfv(GL_BACK, GL_EMISSION, mat_emission_yel);
mat_state = 1;
}
glPushMatrix();
if (((help->mode) & 0x20)) {
glTranslatef(mx, 0, mz);
glScalef(0.25, 0.55, 0.25);
glRotatef(90, 1, 0, 0);
} else {
glTranslatef(mx, 3.5, mz);
glScalef(help->scalex, 4.5, help->scalez);
glRotatef(90, 1, 0, 0);
}
glCallList(TDFSB_CylinderList);
glPopMatrix();
}
}
// Draw audio files
mat_state = 0;
for (help = root; help; help = help->next) {
if (help->tombstone)
continue; // Skip files that are tombstoned
mx = help->posx;
mz = help->posz;
my = help->posy;
if ((((help->regtype) == AUDIOFILE) && ((help->mode) & 0x1F) == 0)) {
if (!mat_state) {
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_grn);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_grn);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_grn);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission_grn);
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse_grn);
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient_grn);
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular_grn);
glMaterialfv(GL_BACK, GL_EMISSION, mat_emission_grn);
mat_state = 2;
}
glPushMatrix();
if (((help->mode) & 0x20)) {
glTranslatef(mx, 0, mz);
glScalef(0.5, 0.5, 0.5);
glRotatef(90, 1, 0, 0);
} else {
glTranslatef(mx, my, mz);
glScalef(help->scalex, help->scaley, help->scalez);
glRotatef(90, 1, 0, 0);
}
glCallList(TDFSB_AudioList);
glPopMatrix();
}
}
// Draw symlinks?
mat_state = 0;
for (help = root; help; help = help->next) {
if (help->tombstone)
continue; // Skip files that are tombstoned
mx = help->posx;
mz = help->posz;
my = help->posy;
if (((help->mode) & 0x1F) >= 10) { // Symlink check?
if (!mat_state) {
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_red);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_red);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_red);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission_red);
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse_red);
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient_red);
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular_red);
glMaterialfv(GL_BACK, GL_EMISSION, mat_emission_red);
mat_state = 3;
}
glPushMatrix();
if (((help->mode) & 0x20)) {
glTranslatef(help->posx, 0.2, help->posz);
glScalef(1.2, 1.2, 1.2);
} else {
glTranslatef(help->posx, help->posy + .25, help->posz);
glScalef((help->scalex) + .25, (help->scaley) + .25, (help->scalez) + .25);
}
glutSolidCube(2);
glPopMatrix();
}
}
// Draw symlinks?
mat_state = 0;
for (help = root; help; help = help->next) {
if (help->tombstone)
continue; // Skip files that are tombstoned
mx = help->posx;
mz = help->posz;
my = help->posy;
if (((help->mode) & 0x20)) { // Symlink check?
if (!mat_state) {
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse_gry);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_gry);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_gry);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission_gry);
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse_gry);
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient_gry);
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular_gry);
glMaterialfv(GL_BACK, GL_EMISSION, mat_emission_gry);
mat_state = 4;
}
glPushMatrix();
glTranslatef(mx, 0, mz);
if ((help->mode) == 0x25)
glutSolidSphere(0.5, TDFSB_BALL_DETAIL, TDFSB_BALL_DETAIL);
glutSolidSphere(1, TDFSB_BALL_DETAIL, TDFSB_BALL_DETAIL);
glPopMatrix();
}
}
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_BACK, GL_EMISSION, mat_emission);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glEndList();
}
static void set_filetypes(void)
{
// These filetypes are known to be mis- or non-identified by libmagic, so we fallback to extensions for those.
// We intentionally don't list all possible options here, because we want to have an idea of which fail to identify, and why.
xsuff[0] = ".mp3"; // Some .mp3's are misidentified, they seem to be part of a stream and are missing headers...
tsuff[0] = AUDIOFILE;
xsuff[1] = ".txt"; // Some .txt's are identified as "application/data"
tsuff[1] = TEXTFILE;
xsuff[2] = ".mp4"; // I had an .mp4 file that was actually detected as an "ISO Media" file...
tsuff[2] = VIDEOFILE;
nsuff[DIRECTORY] = "DIRECTORY";
nsuff[IMAGEFILE] = "PICTURE";
nsuff[TEXTFILE] = "TEXT";
nsuff[PDFFILE] = "PDF";
nsuff[ZIPFILE] = "ZIPFILE";
nsuff[VIDEOFILE] = "VIDEO";
nsuff[AUDIOFILE] = "AUDIO-MP3";
nsuff[VIDEOSOURCEFILE] = "VIDEOSOURCE";
nsuff[UNKNOWNFILE] = "UNKNOWN";
nsuff[PROCESS] = "PROCESS";
}
static void setup_help(void)
{
help_str = (char *)malloc(1024 * sizeof(char));
help_copy = (char *)malloc(1024 * sizeof(char));
char *tmpstr = (char *)malloc(64 * sizeof(char));
if (!help_copy || !tmpstr) {
printf("Malloc Failure setup_help \n");
exit(1);
}
strcpy(help_str, STATIC_HELP_TEXT);
sprintf(tmpstr, "\"%c\" filenames \"%c\" ground cross\n", TDFSB_KC_NAME, TDFSB_KC_GCR);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" crosshair \"%c\" display\n", TDFSB_KC_CRH, TDFSB_KC_DISP);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" dot files \"%c\" print FPS\n", TDFSB_KC_DOT, TDFSB_KC_FPS);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" rel./get mouse \"%c\" fullscreen\n", TDFSB_KC_RELEASE_MOUSE, TDFSB_KC_FS);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" reload dir \"%c\" image bricks\n", TDFSB_KC_RL, TDFSB_KC_IMBR);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" cd.. \"%c\" alphasort\n", TDFSB_KC_CDU, TDFSB_KC_SORT);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" shading \"%c\" flying\n", TDFSB_KC_SHD, TDFSB_KC_FLY);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" jump home \"%c\" classic nav\n", TDFSB_KC_HOME, TDFSB_KC_CLASS);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" save config \"%c\" fps throttle\n", TDFSB_KC_SAVE, TDFSB_KC_FTH);
strcat(help_str, tmpstr);
sprintf(tmpstr, " \"%c|%c|%c|%c\" Up|Down|Left|Right\n", TDFSB_KC_UP, TDFSB_KC_DOWN, TDFSB_KC_LEFT, TDFSB_KC_RIGHT);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c|%c\" Forward|Backward\n\n", TDFSB_KC_FORWARD, TDFSB_KC_BACKWARD);
strcat(help_str, tmpstr);
sprintf(tmpstr, "\"%c\" print GL info \"%c\" show/hide help\n", TDFSB_KC_INFO, TDFSB_KC_HELP);
strcat(help_str, tmpstr);
free(tmpstr);
}
void viewm(void)
{
if ((centY = (asin(-tposy)) * (((double)SWY) / PI)) > SWY / 2)
centY = SWY / 2;
else if (centY < (-SWY / 2))
centY = -SWY / 2;
if (tposz > 0)
centX = (GLdouble) acos(tposx / ((GLdouble) cos((((double)centY) / (double)((double)SWY / PI))))) * (GLdouble) ((GLdouble) SWX / mousesense / PI);
else
centX = -(GLdouble) acos(tposx / ((GLdouble) cos((((double)centY) / (double)((double)SWY / PI))))) * (GLdouble) ((GLdouble) SWX / mousesense / PI);
}
void check_standstill(void)
{
if (!(forwardkeybuf + backwardkeybuf + leftkeybuf + rightkeybuf + upkeybuf + downkeybuf))
TDFSB_FUNC_IDLE = standstillDisplay;
}
void stop_move(void)
{
forwardkeybuf = backwardkeybuf = leftkeybuf = rightkeybuf = upkeybuf = downkeybuf = 0;
}
Uint32 fps_timer(void)
{
sprintf(fpsbuf, "FPS: %d", (int)((1000 * TDFSB_FPS_DISP) / TDFSB_FPS_DT));
TDFSB_FPS_DISP = 0;
return (TDFSB_FPS_DT);
}
static void init(void)
{
unsigned int charpos;
TDFSB_DisplayLists = glGenLists(3);
TDFSB_CylinderList = TDFSB_DisplayLists + 0;
TDFSB_HelpList = TDFSB_DisplayLists + 1;
TDFSB_AudioList = TDFSB_DisplayLists + 2;
TDFSB_SolidList = glGenLists(1);
TDFSB_BlendList = glGenLists(1);
/* building audio object */
aua2 = gluNewQuadric();
gluQuadricDrawStyle(aua2, GLU_FILL);
gluQuadricNormals(aua2, GLU_SMOOTH);
glNewList(TDFSB_AudioList, GL_COMPILE);
glTranslatef(0.0, 0.0, 0.0);
glRotatef(90, 1.0, 0.0, 0.0);
gluCylinder(aua2, 0.2, 1.0, 0.5, 16, 1);
glRotatef(180, 0.0, 1.0, 0.0);
gluCylinder(aua2, 0.2, 1.0, 0.5, 16, 1);
glEndList();
gluDeleteQuadric(aua2);
/* building Textfilecylinder */
aua1 = gluNewQuadric();
gluQuadricDrawStyle(aua1, GLU_FILL);
gluQuadricNormals(aua1, GLU_SMOOTH);
glNewList(TDFSB_CylinderList, GL_COMPILE);
glTranslatef(0.0, 0.0, -1.0);
gluCylinder(aua1, 0.6, 0.6, 2.0, 16, 1);
glTranslatef(0.0, 0.0, 2.0);
gluDisk(aua1, 0.0, 0.6, 16, 1);
glTranslatef(0.0, 0.0, -2.0);
gluDisk(aua1, 0.0, 0.6, 16, 1);
glEndList();
gluDeleteQuadric(aua1);
glNewList(TDFSB_HelpList, GL_COMPILE);
prevlen = 0;
cnt = 0;
strcpy(help_copy, help_str);
char *tmpstr = strtok(help_copy, "\n");
while (tmpstr != NULL) {
cnt++;
glTranslatef(-prevlen, -14 / 0.09, 0);
unsigned int tmpstr_len = (int)strlen(tmpstr);
for (charpos = 0; charpos < tmpstr_len; charpos++) {
glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, tmpstr[charpos]);
}
prevlen = tmpstr_len * 104.76;
tmpstr = strtok(NULL, "\n");
}
free(help_copy); // help_copy is only used to create the TDFSB_HelpList
glEndList();
SDL_WarpMouse(SWX / 2, SWY / 2);
vposy = 0;
lastposx = lastposz = vposx = vposz = -10;
smooy = tposy = 0;
smoox = tposx = SQF;
smooz = tposz = SQF;
smoou = 0;
uposy = 0;
viewm();
TDFSB_TEX_NUM = 0;
TDFSB_TEX_NAMES = NULL;
glClearColor(TDFSB_BG_R, TDFSB_BG_G, TDFSB_BG_B, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_BACK, GL_SHININESS, mat_shininess);
glMaterialfv(GL_BACK, GL_EMISSION, mat_emission);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
mono = glutStrokeWidth(GLUT_STROKE_MONO_ROMAN, 'W');
}
void reshape(int w, int h)
{
centY = ((((GLdouble) h) * centY) / ((GLdouble) SWY));
centX = ((((GLdouble) w) * centX) / ((GLdouble) SWX));
SWX = w;
SWY = h;
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
}
static void insert(char *value, const char *mimetype, char *openwith, char *linkpath, unsigned int mode, off_t size, unsigned int type, unsigned int texturewidth, unsigned int textureheight, unsigned int textureformat, unsigned int textureid, GLfloat posx, GLfloat posy, GLfloat posz, GLfloat scalex, GLfloat scaley, GLfloat scalez)
{
char *temp;
struct tree_entry *help;
char *mimetypetemp;
temp = (char *)malloc(strlen(value) + 1);
if (temp == NULL) {
printf("low mem while inserting object!\n");
ende(1);
}
strcpy(temp, value);
// Copy the mimetype in
mimetypetemp = (char *)malloc(strlen(mimetype) + 1);
if (mimetypetemp == NULL) {
printf("low mem while inserting object!\n");
ende(1);
}
strcpy(mimetypetemp, mimetype);
if (root == NULL) {
root = (struct tree_entry *)malloc(sizeof(struct tree_entry));
if (root == NULL) {
printf("low mem while inserting object!\n");
ende(1);
}
root->name = temp;
root->mimetype = mimetypetemp;
root->openwith = openwith;
root->namelen = strlen(temp);
root->linkpath = linkpath;
root->mode = mode;
root->regtype = type;
root->texturewidth = texturewidth;
root->textureheight = textureheight;
root->textureformat = textureformat;
root->textureid = textureid;
root->tombstone = 0;
root->posx = posx;
root->posy = posy;
root->posz = posz;
root->scalex = scalex;
root->scaley = scaley;
root->scalez = scalez;
root->textfilecontents = NULL;
root->texturesurface = NULL; // this gets filled in later
root->size = size;
root->next = NULL;
} else {
help = root;
while (help->next)
help = help->next;
help->next = (struct tree_entry *)malloc(sizeof(struct tree_entry));
if ((help->next) == NULL) {
printf("low mem while inserting object!\n");
ende(1);
}
(help->next)->name = temp;
(help->next)->mimetype = mimetypetemp;
(help->next)->openwith = openwith;
(help->next)->namelen = strlen(temp);
(help->next)->linkpath = linkpath;
(help->next)->mode = mode;
(help->next)->regtype = type;
(help->next)->texturewidth = texturewidth;
(help->next)->textureheight = textureheight;
(help->next)->textureformat = textureformat;
(help->next)->textureid = textureid;
(help->next)->tombstone = 0;
(help->next)->posx = posx;
(help->next)->posy = posy;
(help->next)->posz = posz;
(help->next)->scalex = scalex;
(help->next)->scaley = scaley;
(help->next)->scalez = scalez;
(help->next)->textfilecontents = NULL;
(help->next)->texturesurface = NULL;
(help->next)->size = size;
(help->next)->next = NULL;
}
}
/*
* Directory handling code, about ~450 lines of code
*/
static char **leoscan(char *ls_path)
{