~ubuntu-branches/debian/wheezy/gource/wheezy

« back to all changes in this revision

Viewing changes to src/gource.cpp

  • Committer: Package Import Robot
  • Author(s): Andrew Caudwell
  • Date: 2012-04-24 11:25:45 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20120424112545-18fbnycu9xrsl4s5
Tags: 0.38-1
* New upstream release (closes: #667189)
* New build dependencies on libglm-dev and libboost-filesystem-dev. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    if(!GLEW_VERSION_2_0) gGourceSettings.ffp = true;
33
33
 
34
34
    if(!gGourceSettings.file_graphic) {
35
 
        gGourceSettings.file_graphic = texturemanager.grab("file.png");
 
35
        gGourceSettings.file_graphic = texturemanager.grab("file.png", true, GL_CLAMP_TO_EDGE);
36
36
    }
37
37
 
38
38
    fontlarge = fontmanager.grab("FreeSans.ttf", 42);
52
52
 
53
53
    bloomtex = texturemanager.grab(bloom_tga);
54
54
    beamtex  = texturemanager.grab("beam.png");
55
 
    usertex  = texturemanager.grab("no_photo.png");
 
55
    usertex  = texturemanager.grab("user.png", true, GL_CLAMP_TO_EDGE);
56
56
 
57
57
    shadow_shader = text_shader = bloom_shader = 0;
58
58
 
84
84
 
85
85
    paused       = false;
86
86
    first_read   = true;
87
 
    draw_loading = true;
88
87
 
89
88
    grab_mouse   = false;
90
89
    mousemoved   = false;
91
90
    mousedragged = false;
92
91
    mouseclicked = false;
93
92
 
94
 
    cursor.setCursorTexture(texturemanager.grab("cursor.png"));
95
 
    cursor.useSystemCursor(false);
96
 
 
97
93
    if(gGourceSettings.hide_mouse) {
98
94
        cursor.showCursor(false);
99
95
    }
121
117
 
122
118
    file_key = FileKey(1.0f);
123
119
 
124
 
    camera = ZoomCamera(vec3f(0,0, -300), vec3f(0.0, 0.0, 0.0), 250.0, 5000.0);
 
120
    camera = ZoomCamera(vec3(0,0, -300), vec3(0.0, 0.0, 0.0), gGourceSettings.camera_zoom_default, gGourceSettings.camera_zoom_max);
125
121
    camera.setPadding(gGourceSettings.padding);
126
122
 
127
123
    setCameraMode(gGourceSettings.camera_mode);
136
132
 
137
133
    reset();
138
134
 
 
135
    logmill = new RLogMill(logfile);
 
136
 
 
137
    shutdown = false;
 
138
    
139
139
    if(exporter!=0) setFrameExporter(exporter, gGourceSettings.output_framerate);
140
140
 
141
141
    //if recording a video or in demo mode, or multiple repos, the slider is initially hidden
143
143
}
144
144
 
145
145
void Gource::writeCustomLog(const std::string& logfile, const std::string& output_file) {
146
 
    RCommitLog* commitlog = determineFormat(logfile);
147
 
 
148
 
    if(!commitlog) return;
 
146
 
 
147
    RLogMill logmill(logfile);
 
148
    RCommitLog* commitlog = logmill.getLog();
 
149
 
 
150
    // TODO: exception handling
 
151
 
 
152
    if(!commitlog) {
 
153
        std::string error = logmill.getError();
 
154
        if(!error.empty()) SDLAppQuit(error);
 
155
        return;
 
156
    }
149
157
 
150
158
    RCommit commit;
151
159
 
179
187
    if(output_file != "-") fclose(fh);
180
188
}
181
189
 
182
 
RCommitLog* Gource::determineFormat(const std::string& logfile) {
183
 
    debugLog("determineFormat(%s)\n", logfile.c_str());
184
 
 
185
 
    RCommitLog* clog = 0;
186
 
 
187
 
    //we've been told what format to use
188
 
    if(gGourceSettings.log_format.size() > 0) {
189
 
        debugLog("--log-format = %s\n", gGourceSettings.log_format.c_str());
190
 
 
191
 
        if(gGourceSettings.log_format == "git") {
192
 
            clog = new GitCommitLog(logfile);
193
 
            if(clog->checkFormat()) return clog;
194
 
            delete clog;
195
 
 
196
 
            clog = new GitRawCommitLog(logfile);
197
 
            if(clog->checkFormat()) return clog;
198
 
            delete clog;
199
 
        }
200
 
 
201
 
        if(gGourceSettings.log_format == "hg") {
202
 
            clog = new MercurialLog(logfile);
203
 
            if(clog->checkFormat()) return clog;
204
 
            delete clog;
205
 
        }
206
 
        if(gGourceSettings.log_format == "bzr") {
207
 
            clog = new BazaarLog(logfile);
208
 
            if(clog->checkFormat()) return clog;
209
 
            delete clog;
210
 
        }
211
 
 
212
 
        if(gGourceSettings.log_format == "cvs") {
213
 
            clog = new CVSEXPCommitLog(logfile);
214
 
            if(clog->checkFormat()) return clog;
215
 
            delete clog;
216
 
        }
217
 
 
218
 
        if(gGourceSettings.log_format == "custom") {
219
 
            clog = new CustomLog(logfile);
220
 
            if(clog->checkFormat()) return clog;
221
 
            delete clog;
222
 
        }
223
 
 
224
 
        if(gGourceSettings.log_format == "apache") {
225
 
            clog = new ApacheCombinedLog(logfile);
226
 
            if(clog->checkFormat()) return clog;
227
 
            delete clog;
228
 
        }
229
 
 
230
 
        if(gGourceSettings.log_format == "svn") {
231
 
            clog = new SVNCommitLog(logfile);
232
 
            if(clog->checkFormat()) return clog;
233
 
            delete clog;
234
 
        }
235
 
 
236
 
        if(gGourceSettings.log_format == "cvs2cl") {
237
 
            clog = new CVS2CLCommitLog(logfile);
238
 
            if(clog->checkFormat()) return clog;
239
 
            delete clog;
240
 
        }
241
 
 
242
 
        return 0;
243
 
    }
244
 
 
245
 
    //git
246
 
    debugLog("trying git...\n");
247
 
    clog = new GitCommitLog(logfile);
248
 
    if(clog->checkFormat()) return clog;
249
 
 
250
 
    delete clog;
251
 
 
252
 
    //mercurial
253
 
    debugLog("trying mercurial...\n");
254
 
    clog = new MercurialLog(logfile);
255
 
    if(clog->checkFormat()) return clog;
256
 
 
257
 
    delete clog;
258
 
 
259
 
    //bzr
260
 
    debugLog("trying bzr...\n");
261
 
    clog = new BazaarLog(logfile);
262
 
    if(clog->checkFormat()) return clog;
263
 
 
264
 
    delete clog;
265
 
 
266
 
    //git raw
267
 
    debugLog("trying git raw...\n");
268
 
    clog = new GitRawCommitLog(logfile);
269
 
    if(clog->checkFormat()) return clog;
270
 
 
271
 
    delete clog;
272
 
 
273
 
    //cvs exp
274
 
    debugLog("trying cvs-exp...\n");
275
 
    clog = new CVSEXPCommitLog(logfile);
276
 
    if(clog->checkFormat()) return clog;
277
 
 
278
 
    delete clog;
279
 
 
280
 
    //svn
281
 
    debugLog("trying svn...\n");
282
 
    clog = new SVNCommitLog(logfile);
283
 
    if(clog->checkFormat()) return clog;
284
 
 
285
 
    delete clog;
286
 
 
287
 
    //cvs2cl
288
 
    debugLog("trying cvs2cl...\n");
289
 
    clog = new CVS2CLCommitLog(logfile);
290
 
    if(clog->checkFormat()) return clog;
291
 
 
292
 
    delete clog;
293
 
 
294
 
    //custom
295
 
    debugLog("trying custom...\n");
296
 
    clog = new CustomLog(logfile);
297
 
    if(clog->checkFormat()) return clog;
298
 
 
299
 
    delete clog;
300
 
 
301
 
    //apache
302
 
    debugLog("trying apache combined...\n");
303
 
    clog = new ApacheCombinedLog(logfile);
304
 
    if(clog->checkFormat()) return clog;
305
 
 
306
 
    delete clog;
307
 
 
308
 
    return 0;
309
 
}
310
 
 
311
190
Gource::~Gource() {
312
191
    reset();
313
192
 
314
 
    if(commitlog!=0) delete commitlog;
315
 
    if(root!=0) delete root;
 
193
    if(logmill!=0)   delete logmill;
 
194
    if(root!=0)      delete root;
316
195
 
317
196
    //reset settings
318
197
    gGourceSettings.setGourceDefaults();
321
200
void Gource::init() {
322
201
}
323
202
 
 
203
void Gource::unload() {
 
204
 
 
205
    file_vbo.unload();
 
206
    user_vbo.unload();
 
207
    edge_vbo.unload();
 
208
    action_vbo.unload();
 
209
    bloom_vbo.unload();
 
210
 
 
211
}
 
212
 
 
213
void Gource::reload() {
 
214
 
 
215
    slider.resize();
 
216
}
 
217
 
 
218
void Gource::quit() {
 
219
    shutdown = true;    
 
220
}
 
221
 
324
222
void Gource::update(float t, float dt) {
325
223
 
326
224
    float scaled_dt = std::min(dt, max_tick_rate);
347
245
    draw(runtime, scaled_dt);
348
246
 
349
247
    //extract frames based on frameskip setting if frameExporter defined
350
 
    if(frameExporter != 0) {
 
248
    if(frameExporter != 0 && commitlog && !shutdown) {
351
249
        if(framecount % (frameskip+1) == 0) {
352
250
            frameExporter->dump();
353
251
        }
388
286
 
389
287
    bool rightmouse = cursor.rightButtonPressed();
390
288
 
 
289
#if not SDL_VERSION_ATLEAST(1,3,0)
391
290
    if(grab_mouse) {
392
291
         int warp_x = display.width/2;
393
292
         int warp_y = display.height/2;
397
296
 
398
297
         SDL_WarpMouse(warp_x, warp_y);
399
298
    }
 
299
#endif
400
300
 
401
301
    //move camera in direction the user dragged the mouse
402
302
    if(mousedragged || rightmouse) {
403
 
        vec2f mag( e->xrel, e->yrel );
 
303
        vec2 mag( e->xrel, e->yrel );
404
304
 
405
305
        //if right mouse button is held while dragging, rotate tree instead of
406
306
        //moving camera
425
325
 
426
326
    if(grab_mouse) return;
427
327
 
428
 
    mousepos = vec2f(e->x, e->y);
 
328
    mousepos = vec2(e->x, e->y);
429
329
    mousemoved=true;
430
330
 
431
331
    cursor.updatePos(mousepos);
450
350
    if(zoomin) {
451
351
        distance /= zoom_multi;
452
352
 
453
 
        if(distance < 100.0f) distance = 100.0f;
 
353
        if(distance < gGourceSettings.camera_zoom_min) distance = gGourceSettings.camera_zoom_min;
454
354
    } else {
455
355
        distance *= zoom_multi;
456
356
 
457
 
        if(distance > 4999.0f) distance = 4999.0f;
 
357
        if(distance > gGourceSettings.camera_zoom_max) distance = gGourceSettings.camera_zoom_max;
458
358
    }
459
359
 
460
360
    camera.setDistance(distance);
461
361
}
462
362
 
 
363
#if SDL_VERSION_ATLEAST(1,3,0)
 
364
void Gource::mouseWheel(SDL_MouseWheelEvent *e) {
 
365
 
 
366
   int mouse_x, mouse_y;
 
367
    SDL_GetMouseState(&mouse_x, &mouse_y);
 
368
 
 
369
    vec2 mousepos(mouse_x, mouse_y);
 
370
 
 
371
    if(e->y > 0) {
 
372
        zoom(true);
 
373
    }
 
374
 
 
375
    if(e->y < 0) {
 
376
        zoom(false);
 
377
    }
 
378
}
 
379
 
 
380
#endif
 
381
 
463
382
void Gource::mouseClick(SDL_MouseButtonEvent *e) {
464
383
    if(commitlog==0) return;
465
384
    if(gGourceSettings.hide_mouse) return;
477
396
 
478
397
        if(e->button == SDL_BUTTON_LEFT || e->button == SDL_BUTTON_RIGHT) {
479
398
            if(!cursor.buttonPressed()) {
 
399
                grab_mouse=false;
 
400
#if SDL_VERSION_ATLEAST(1,3,0)
 
401
                SDL_SetRelativeMouseMode(SDL_FALSE);
 
402
                SDL_WarpMouseInWindow(display.sdl_window, mousepos.x, mousepos.y);
 
403
#else
 
404
                SDL_WarpMouse(mousepos.x, mousepos.y);
 
405
#endif
480
406
                cursor.showCursor(true);
481
 
                grab_mouse=false;
482
 
                SDL_WarpMouse(mousepos.x, mousepos.y);
483
407
            }
484
408
        }
485
409
    }
507
431
    if(e->button == SDL_BUTTON_RIGHT) {
508
432
        cursor.showCursor(false);
509
433
        grab_mouse=true;
 
434
#if SDL_VERSION_ATLEAST(1,3,0)
 
435
        SDL_SetRelativeMouseMode(SDL_TRUE);
 
436
#endif
510
437
        return;
511
438
    }
512
439
 
513
440
    if(e->button == SDL_BUTTON_LEFT) {
514
441
 
515
 
        //mousepos = vec2f(e->x, e->y);
 
442
        //mousepos = vec2(e->x, e->y);
516
443
        mouseclicked=true;
517
444
 
518
445
        if(canSeek()) {
682
609
    if (e->type == SDL_KEYUP) return;
683
610
 
684
611
    if (e->type == SDL_KEYDOWN) {
685
 
        if (e->keysym.unicode == SDLK_ESCAPE) {
686
 
            appFinished=true;
 
612
 
 
613
#if SDL_VERSION_ATLEAST(1,3,0)
 
614
        bool key_escape       = e->keysym.scancode == SDL_SCANCODE_ESCAPE;
 
615
        bool key_tab          = e->keysym.scancode == SDL_SCANCODE_TAB;
 
616
        bool key_space        = e->keysym.scancode == SDL_SCANCODE_SPACE;
 
617
        bool key_plus         = e->keysym.scancode == SDL_SCANCODE_EQUALS;
 
618
        bool key_equals       = e->keysym.scancode == SDL_SCANCODE_EQUALS;
 
619
        bool key_minus        = e->keysym.scancode == SDL_SCANCODE_MINUS;
 
620
        bool key_leftbracket  = e->keysym.scancode == SDL_SCANCODE_LEFTBRACKET;
 
621
        bool key_rightbracket = e->keysym.scancode == SDL_SCANCODE_RIGHTBRACKET;
 
622
        bool key_comma        = e->keysym.scancode == SDL_SCANCODE_COMMA;
 
623
        bool key_period       = e->keysym.scancode == SDL_SCANCODE_PERIOD;
 
624
        bool key_slash        = e->keysym.scancode == SDL_SCANCODE_SLASH;
 
625
#else
 
626
        bool key_escape       = e->keysym.unicode == SDLK_ESCAPE;
 
627
        bool key_tab          = e->keysym.unicode == SDLK_TAB;
 
628
        bool key_space        = e->keysym.unicode == SDLK_SPACE;
 
629
        bool key_plus         = e->keysym.unicode == SDLK_PLUS;
 
630
        bool key_equals       = e->keysym.unicode == SDLK_EQUALS;
 
631
        bool key_minus        = e->keysym.unicode == SDLK_MINUS;
 
632
        bool key_leftbracket  = e->keysym.unicode == SDLK_LEFTBRACKET;
 
633
        bool key_rightbracket = e->keysym.unicode == SDLK_RIGHTBRACKET;
 
634
        bool key_comma        = e->keysym.unicode == SDLK_COMMA;
 
635
        bool key_period       = e->keysym.unicode == SDLK_PERIOD;
 
636
        bool key_slash        = e->keysym.unicode == SDLK_SLASH;
 
637
#endif
 
638
 
 
639
        if (key_escape) {
 
640
            quit();
687
641
        }
688
642
 
689
643
        if(commitlog==0) return;
809
763
            recolour=true;
810
764
        }
811
765
 
812
 
        if(e->keysym.unicode == SDLK_TAB) {
 
766
        if(key_tab) {
813
767
            selectNextUser();
814
768
        }
815
769
 
816
 
        if (e->keysym.unicode == SDLK_SPACE) {
 
770
        if (key_space) {
817
771
            paused = !paused;
818
772
        }
819
773
 
820
 
        if (e->keysym.unicode == SDLK_EQUALS || e->keysym.unicode == SDLK_PLUS) {
 
774
        if (key_equals || key_plus) {
821
775
            if(gGourceSettings.days_per_second>=1.0) {
822
776
                gGourceSettings.days_per_second = std::min(30.0f, floorf(gGourceSettings.days_per_second) + 1.0f);
823
777
            } else {
825
779
            }
826
780
        }
827
781
 
828
 
        if (e->keysym.unicode == SDLK_MINUS) {
 
782
        if (key_minus) {
829
783
            if(gGourceSettings.days_per_second>1.0) {
830
784
                gGourceSettings.days_per_second = std::max(0.0f, floorf(gGourceSettings.days_per_second) - 1.0f);
831
785
            } else {
841
795
            zoom(false);
842
796
        }
843
797
 
844
 
        if(e->keysym.unicode == SDLK_LEFTBRACKET) {
 
798
        if(key_leftbracket) {
845
799
            gGourceForceGravity /= 1.1;
846
800
        }
847
801
 
848
 
        if(e->keysym.unicode == SDLK_RIGHTBRACKET) {
 
802
        if(key_rightbracket) {
849
803
            gGourceForceGravity *= 1.1;
850
804
        }
851
805
 
852
 
        if(e->keysym.unicode == SDLK_PERIOD) {
 
806
        if(key_period) {
853
807
 
854
808
            if(gGourceSettings.time_scale>=1.0) {
855
809
                gGourceSettings.time_scale = std::min(4.0f, floorf(gGourceSettings.time_scale) + 1.0f);
858
812
            }
859
813
        }
860
814
 
861
 
        if(e->keysym.unicode == SDLK_COMMA) {
 
815
        if(key_comma) {
862
816
 
863
817
            if(gGourceSettings.time_scale>1.0) {
864
818
                gGourceSettings.time_scale = std::max(0.0f, floorf(gGourceSettings.time_scale) - 1.0f);
867
821
            }
868
822
        }
869
823
 
870
 
        if(e->keysym.unicode == SDLK_SLASH) {
 
824
        if(key_slash) {
871
825
            gGourceSettings.time_scale = 1.0f;
872
826
        }
873
827
    }
904
858
 
905
859
    message_timer = 0.0f;
906
860
 
907
 
    cursor_move = vec2f(0.0f, 0.0f);
 
861
    cursor_move = vec2(0.0f, 0.0f);
908
862
 
909
863
    selectedUser = 0;
910
864
    hoverUser = 0;
917
871
    mousemoved=false;
918
872
    mousedragged = false;
919
873
 
 
874
    commitqueue_max_size = 100;
 
875
 
920
876
    rotate_angle = 0.0f;
921
877
 
922
878
    if(root!=0) delete root;
980
936
 
981
937
RFile* Gource::addFile(const RCommitFile& cf) {
982
938
 
 
939
    //if we already have max files in circulation
 
940
    //we cant add any more
 
941
    if(gGourceSettings.max_files > 0 && files.size() >= gGourceSettings.max_files) return 0;
 
942
 
 
943
    //see if this is a directory
 
944
    std::string file_as_dir = cf.filename;
 
945
    if(file_as_dir[file_as_dir.size()-1] != '/') file_as_dir.append("/");
 
946
 
 
947
    if(root->isDir(file_as_dir)) return 0;
 
948
 
983
949
    int tagid = tag_seq++;
984
950
 
985
 
    RFile* file = new RFile(cf.filename, cf.colour, vec2f(0.0,0.0), tagid);
 
951
    RFile* file = new RFile(cf.filename, cf.colour, vec2(0.0,0.0), tagid);
986
952
 
987
953
    files[cf.filename] = file;
988
954
    tagfilemap[tagid]  = file;
992
958
    file_key.inc(file);
993
959
 
994
960
    while(root->getParent() != 0) {
995
 
        debugLog("parent changed to %s\n", root->getPath().c_str());
 
961
        debugLog("parent changed to %s", root->getPath().c_str());
996
962
        root = root->getParent();
997
963
    }
998
964
 
1001
967
 
1002
968
RUser* Gource::addUser(const std::string& username) {
1003
969
 
1004
 
    vec2f pos;
 
970
    vec2 pos;
1005
971
 
1006
972
    if(dir_bounds.area() > 0) {
1007
973
        pos = dir_bounds.centre();
1008
974
    } else {
1009
 
        pos = vec2f(0,0);
 
975
        pos = vec2(0,0);
1010
976
    }
1011
977
 
1012
978
    int tagid = tag_seq++;
1063
1029
 
1064
1030
    //debugLog("readLog()\n");
1065
1031
 
1066
 
    while(!commitlog->isFinished() && commitqueue.size() < 1) {
 
1032
    // read commits until either we are ahead of currtime
 
1033
    while(!commitlog->isFinished() && (commitqueue.empty() || commitqueue.back().timestamp <= currtime && commitqueue.size() < commitqueue_max_size)) {
1067
1034
 
1068
1035
        RCommit commit;
1069
1036
 
1074
1041
            continue;
1075
1042
        }
1076
1043
 
1077
 
        //ignore blank commits
1078
 
        if(commit.files.size() > 0) {
1079
 
            commitqueue.push_back(commit);
1080
 
        }
 
1044
         commitqueue.push_back(commit);
1081
1045
    }
1082
1046
 
1083
 
    if(first_read && commitqueue.size()==0) {
 
1047
    if(first_read && commitqueue.empty()) {
 
1048
        fprintf(stderr, "no files on first read\n");
1084
1049
        throw SDLAppException("no commits found");
1085
1050
    }
1086
1051
 
1104
1069
 
1105
1070
void Gource::processCommit(RCommit& commit, float t) {
1106
1071
 
1107
 
    //check user against filters, if found, discard commit
1108
 
    if(!gGourceSettings.user_filters.empty()) {
1109
 
        for(std::vector<Regex*>::iterator ri = gGourceSettings.user_filters.begin(); ri != gGourceSettings.user_filters.end(); ri++) {
1110
 
            Regex* r = *ri;
1111
 
 
1112
 
            if(r->match(commit.username)) {
1113
 
                return;
1114
 
            }
1115
 
        }
1116
 
    }
1117
 
 
1118
1072
    //find files of this commit or create it
1119
1073
    for(std::list<RCommitFile>::iterator it = commit.files.begin(); it != commit.files.end(); it++) {
1120
1074
 
1121
1075
        RCommitFile& cf = *it;
1122
1076
        RFile* file = 0;
1123
1077
 
1124
 
        //check filename against filters
1125
 
        if(!gGourceSettings.file_filters.empty()) {
1126
 
 
1127
 
            bool filtered_filename = false;
1128
 
 
1129
 
            for(std::vector<Regex*>::iterator ri = gGourceSettings.file_filters.begin(); ri != gGourceSettings.file_filters.end(); ri++) {
1130
 
                Regex* r = *ri;
1131
 
 
1132
 
                if(r->match(cf.filename)) {
1133
 
                    filtered_filename = true;
1134
 
                    break;
1135
 
                }
1136
 
            }
1137
 
 
1138
 
            if(filtered_filename) continue;
1139
 
        }
1140
 
 
1141
1078
        //is this a directory (ends in slash)
1142
1079
        //deleting a directory - find directory: then for each file, remove each file
1143
1080
 
1155
1092
            for(std::list<RDirNode*>::iterator it = dirs.begin(); it != dirs.end(); it++) {
1156
1093
 
1157
1094
                RDirNode* dir = (*it);
1158
 
                
 
1095
 
1159
1096
                //fprintf(stderr, "deleting everything under %s because of %s\n", dir->getPath().c_str(), cf.filename.c_str());
1160
1097
 
1161
1098
                //foreach dir files
1169
1106
                    addFileAction(commit.username, cf.action, file, t);
1170
1107
                }
1171
1108
            }
1172
 
                
 
1109
 
1173
1110
            return;
1174
1111
        }
1175
1112
 
1178
1115
 
1179
1116
        if(file == 0) {
1180
1117
 
1181
 
            //if we already have max files in circulation
1182
 
            //we cant add any more
1183
 
            if(gGourceSettings.max_files > 0 && files.size() >= gGourceSettings.max_files)
1184
 
                continue;
1185
 
 
1186
1118
            file = addFile(cf);
 
1119
 
 
1120
            if(!file) continue;
1187
1121
        }
1188
1122
 
1189
1123
        addFileAction(commit.username, cf.action, file, t);
1204
1138
    if(user == 0) {
1205
1139
        user = addUser(username);
1206
1140
 
1207
 
        // set the highlighted flag if name matches a highlighted user
1208
 
        for(std::vector<std::string>::iterator hi = gGourceSettings.highlight_users.begin(); hi != gGourceSettings.highlight_users.end(); hi++) {
1209
 
            std::string highlight = *hi;
 
1141
        if(gGourceSettings.highlight_all_users) user->setHighlighted(true);
 
1142
        else {
 
1143
        
 
1144
            // set the highlighted flag if name matches a highlighted user
 
1145
            for(std::vector<std::string>::iterator hi = gGourceSettings.highlight_users.begin(); hi != gGourceSettings.highlight_users.end(); hi++) {
 
1146
                std::string highlight = *hi;
1210
1147
 
1211
 
            if(highlight.size() && user->getName() == highlight) {
1212
 
                user->setHighlighted(true);
1213
 
                break;
 
1148
                if(!highlight.empty() && user->getName() == highlight) {
 
1149
                    user->setHighlighted(true);
 
1150
                    break;
 
1151
                }
1214
1152
            }
1215
1153
        }
1216
1154
    }
1240
1178
    // update quad tree
1241
1179
    Bounds2D quadtreebounds = user_bounds;
1242
1180
 
1243
 
    quadtreebounds.min -= vec2f(1.0f, 1.0f);
1244
 
    quadtreebounds.max += vec2f(1.0f, 1.0f);
 
1181
    quadtreebounds.min -= vec2(1.0f, 1.0f);
 
1182
    quadtreebounds.max += vec2(1.0f, 1.0f);
1245
1183
 
1246
1184
    update_user_tree_time = SDL_GetTicks();
1247
1185
 
1365
1303
    // update quad tree
1366
1304
    Bounds2D quadtreebounds = dir_bounds;
1367
1305
 
1368
 
    quadtreebounds.min -= vec2f(1.0f, 1.0f);
1369
 
    quadtreebounds.max += vec2f(1.0f, 1.0f);
 
1306
    quadtreebounds.min -= vec2(1.0f, 1.0f);
 
1307
    quadtreebounds.max += vec2(1.0f, 1.0f);
1370
1308
 
1371
1309
    update_dir_tree_time = SDL_GetTicks();
1372
1310
 
1427
1365
 
1428
1366
    if(manual_camera) {
1429
1367
 
1430
 
        if(cursor_move.length2() > 0.0f) {
 
1368
        if(glm::length2(cursor_move) > 0.0f) {
1431
1369
 
1432
1370
            float cam_rate = ( -camera.getPos().z ) / ( 5000.0f );
1433
1371
 
1434
 
            vec3f cam_pos = camera.getPos();
 
1372
            vec3 cam_pos = camera.getPos();
1435
1373
 
1436
 
            vec2f cursor_delta = cursor_move * cam_rate * 400.0f * dt;
 
1374
            vec2 cursor_delta = cursor_move * cam_rate * 400.0f * dt;
1437
1375
 
1438
1376
            cam_pos.x += cursor_delta.x;
1439
1377
            cam_pos.y += cursor_delta.y;
1443
1381
 
1444
1382
            auto_rotate = false;
1445
1383
 
1446
 
            cursor_move = vec2f(0.0f, 0.0f);
 
1384
            cursor_move = vec2(0.0f, 0.0f);
1447
1385
        }
1448
1386
 
1449
1387
    } else {
1453
1391
        if(track_users && (selectedFile !=0 || selectedUser !=0)) {
1454
1392
            Bounds2D focusbounds;
1455
1393
 
1456
 
            vec3f camerapos = camera.getPos();
 
1394
            vec3 camerapos = camera.getPos();
1457
1395
 
1458
1396
            if(selectedUser !=0) focusbounds.update(selectedUser->getPos());
1459
1397
            if(selectedFile !=0) focusbounds.update(selectedFile->getAbsolutePos());
1484
1422
 
1485
1423
        } else if(!cursor.rightButtonPressed() && dir_bounds.area() > 10000.0f) {
1486
1424
 
1487
 
            float ratio = dir_bounds.width() / dir_bounds.height();
1488
 
 
1489
 
            if(ratio < 0.67f) {
 
1425
            float aspect_ratio = display.width / (float) display.height;
 
1426
 
 
1427
            float bounds_ratio = (aspect_ratio > 1.0f) ? dir_bounds.width() / dir_bounds.height() : dir_bounds.height() / dir_bounds.width();
 
1428
 
 
1429
            if(bounds_ratio < 0.67f) {
1490
1430
                rotation_remaining_angle = 90.0f;
1491
1431
            }
1492
1432
        }
1513
1453
 
1514
1454
void Gource::logic(float t, float dt) {
1515
1455
 
1516
 
    if(draw_loading) return;
1517
 
 
 
1456
    if(shutdown && logmill->isFinished()) {
 
1457
        appFinished=true;
 
1458
        return;
 
1459
    }
 
1460
    
1518
1461
    if(message_timer>0.0f) message_timer -= dt;
1519
1462
    if(splash>0.0f)        splash -= dt;
1520
1463
 
1521
1464
    //init log file
1522
1465
    if(commitlog == 0) {
1523
1466
 
1524
 
        try {
1525
 
 
1526
 
            commitlog = determineFormat(logfile);
1527
 
 
1528
 
        } catch(SeekLogException& exception) {
1529
 
            throw SDLAppException("unable to read log file");
1530
 
        }
1531
 
 
1532
 
        if(commitlog == 0) {
1533
 
            //if not in a git dir and no log file, show help
1534
 
            if(logfile.size() == 0 || logfile == ".") {
 
1467
        if(!logmill->isFinished()) return;
 
1468
        
 
1469
        commitlog = logmill->getLog();
 
1470
 
 
1471
        std::string error = logmill->getError();
 
1472
 
 
1473
        if(!commitlog) {
 
1474
 
 
1475
            if(!error.empty()) {
 
1476
                throw SDLAppException(error);
 
1477
            } else {
 
1478
 
 
1479
                if(frameExporter!=0) frameExporter->stop();
 
1480
 
1535
1481
                SDL_Quit();
1536
1482
 
1537
1483
                SDLAppException exception("");
1538
1484
                exception.setShowHelp(true);
 
1485
 
1539
1486
                throw exception;
1540
 
            } else if(SDLAppDirExists(logfile)) {
1541
 
                throw SDLAppException("directory not supported");
1542
 
            } else {
1543
 
                throw SDLAppException("unsupported log format (you may need to regenerate your log file)");
1544
1487
            }
1545
1488
        }
1546
1489
 
1553
1496
 
1554
1497
    slider.logic(dt);
1555
1498
 
 
1499
    bool right = false;
 
1500
    bool left  = false;
 
1501
    bool up    = false;
 
1502
    bool down  = false;
 
1503
 
 
1504
#if SDL_VERSION_ATLEAST(1,3,0)
 
1505
    Uint8 *keystate = SDL_GetKeyboardState(0);
 
1506
 
 
1507
    right = keystate[SDL_SCANCODE_RIGHT];
 
1508
    left  = keystate[SDL_SCANCODE_LEFT];
 
1509
    up    = keystate[SDL_SCANCODE_UP];
 
1510
    down  = keystate[SDL_SCANCODE_DOWN];
 
1511
#else
1556
1512
    Uint8 *keystate = SDL_GetKeyState(0);
1557
1513
 
1558
 
    if(keystate[SDLK_RIGHT]) {
 
1514
    right = keystate[SDLK_RIGHT];
 
1515
    left  = keystate[SDLK_LEFT];
 
1516
    up    = keystate[SDLK_UP];
 
1517
    down  = keystate[SDLK_DOWN];
 
1518
#endif
 
1519
 
 
1520
    if(right) {
1559
1521
        cursor_move.x = 10.0;
1560
1522
        manual_camera = true;
1561
1523
    }
1562
1524
 
1563
 
    if(keystate[SDLK_LEFT]) {
 
1525
    if(left) {
1564
1526
        cursor_move.x = -10.0;
1565
1527
        manual_camera = true;
1566
1528
    }
1567
1529
 
1568
 
    if(keystate[SDLK_UP]) {
 
1530
    if(up) {
1569
1531
        cursor_move.y = -10.0;
1570
1532
        manual_camera = true;
1571
1533
    }
1572
1534
 
1573
 
    if(keystate[SDLK_DOWN]) {
 
1535
    if(down) {
1574
1536
        cursor_move.y = 10.0;
1575
1537
        manual_camera = true;
1576
1538
    }
1586
1548
        for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
1587
1549
            RUser* user = it->second;
1588
1550
 
1589
 
            vec2f userpos = user->getPos();
 
1551
            vec2 userpos = user->getPos();
1590
1552
 
1591
 
            user->setPos(userpos.rotate(s, c));
 
1553
            user->setPos(rotate_vec2(userpos, s, c));
1592
1554
        }
1593
1555
 
1594
1556
        rotate_angle = 0.0f;
1616
1578
    }
1617
1579
 
1618
1580
    // get more entries
1619
 
    if(commitqueue.size() == 0) {
 
1581
    if(commitqueue.empty()) {
1620
1582
        readLog();
1621
1583
    }
1622
1584
 
1623
1585
    //loop in attempt to find commits
1624
 
    if(commitqueue.size()==0 && commitlog->isSeekable() && gGourceSettings.loop) {
 
1586
    if(commitqueue.empty() && commitlog->isSeekable() && gGourceSettings.loop) {
1625
1587
        first_read=true;
1626
1588
        seekTo(0.0);
1627
1589
        readLog();
1628
1590
    }
1629
1591
 
1630
 
    if(currtime==0 && commitqueue.size()) {
 
1592
    if(currtime==0 && !commitqueue.empty()) {
1631
1593
        currtime   = lasttime = commitqueue[0].timestamp;
1632
1594
        subseconds = 0.0;
1633
1595
    }
1654
1616
 
1655
1617
 
1656
1618
    //add commits up until the current time
1657
 
    while(commitqueue.size() > 0) {
 
1619
    while(!commitqueue.empty()) {
1658
1620
 
1659
 
        RCommit commit = commitqueue[0];
 
1621
        RCommit commit = commitqueue.front();
1660
1622
 
1661
1623
        //auto skip ahead, unless stop_position_reached
1662
1624
        if(gGourceSettings.auto_skip_seconds>=0.0 && idle_time >= gGourceSettings.auto_skip_seconds && !stop_position_reached) {
1689
1651
 
1690
1652
    updateCamera(dt);
1691
1653
 
1692
 
    updateTime(commitqueue.size() > 0 ? currtime : lasttime);
 
1654
    updateTime(!commitqueue.empty() ? currtime : lasttime);
1693
1655
}
1694
1656
 
1695
1657
void Gource::mousetrace(float dt) {
1696
1658
 
1697
 
    vec3f cam_pos = camera.getPos();
 
1659
    vec3 cam_pos = camera.getPos();
1698
1660
 
1699
 
    vec2f projected_mouse = vec2f( -(mousepos.x * 2.0f - ((float)display.width)) / ((float)display.height),
 
1661
    vec2 projected_mouse = vec2( -(mousepos.x * 2.0f - ((float)display.width)) / ((float)display.height),
1700
1662
                                   (1.0f - (2.0f * mousepos.y) / ((float)display.height)))
1701
1663
                                   * cam_pos.z;
1702
1664
    projected_mouse.x += cam_pos.x;
1813
1775
 
1814
1776
    glColor4f(1.0, 1.0, 1.0, 1.0);
1815
1777
 
1816
 
    std::string loading_message("Reading Log...");
1817
 
    int width = font.getWidth(loading_message);
1818
 
 
1819
 
    font.print(display.width/2 - width/2, display.height/2 - 10, "%s", loading_message.c_str());
 
1778
    const char* progress;
 
1779
 
 
1780
    switch(int(runtime*3.0f)%4) {
 
1781
        case 0:
 
1782
            progress = "";
 
1783
            break;
 
1784
        case 1:
 
1785
            progress = ".";
 
1786
            break;
 
1787
        case 2:
 
1788
            progress = "..";
 
1789
            break;
 
1790
        case 3:
 
1791
            progress = "...";
 
1792
            break;
 
1793
    }
 
1794
 
 
1795
    const char* action = !shutdown ? "Reading Log" : "Aborting";
 
1796
    
 
1797
    int width = font.getWidth(action);
 
1798
    font.setColour(vec4(1.0f));
 
1799
    font.print(display.width/2 - width/2, display.height/2 - 10, "%s%s", action, progress);
1820
1800
}
1821
1801
 
1822
1802
void Gource::drawBackground(float dt) {
1823
1803
    if(!gGourceDrawBackground) return;
1824
1804
 
1825
 
    display.setClearColour(vec4f(gGourceSettings.background_colour, gGourceSettings.transparent ? 0.0f : 1.0f));
 
1805
    display.setClearColour(vec4(gGourceSettings.background_colour, gGourceSettings.transparent ? 0.0f : 1.0f));
1826
1806
    display.clear();
1827
1807
 
1828
1808
    if(backgroundtex!=0) {
1866
1846
 
1867
1847
    draw_edges_time = SDL_GetTicks() - draw_edges_time;
1868
1848
 
1869
 
    //draw shadows
 
1849
    //draw file shadows
1870
1850
 
1871
1851
    draw_shadows_time = SDL_GetTicks();
1872
1852
 
1873
 
    drawUserShadows(dt);
1874
 
 
1875
1853
    drawFileShadows(dt);
1876
1854
 
1877
1855
    draw_shadows_time = SDL_GetTicks() - draw_shadows_time;
1896
1874
 
1897
1875
    draw_users_time = SDL_GetTicks();
1898
1876
 
 
1877
    drawUserShadows(dt);
 
1878
 
1899
1879
    drawUsers(dt);
1900
1880
 
1901
1881
    draw_users_time = SDL_GetTicks() - draw_users_time;
1942
1922
        shadow_shader->use();
1943
1923
        shadow_shader->setFloat("shadow_strength", 0.5);
1944
1924
 
1945
 
        vec2f shadow_offset = vec2f(2.0, 2.0);
 
1925
        vec2 shadow_offset = vec2(2.0, 2.0);
1946
1926
 
1947
1927
        glPushMatrix();
1948
1928
            glTranslatef(shadow_offset.x, shadow_offset.y, 0.0f);
2085
2065
            RUser* user = it->second;
2086
2066
 
2087
2067
            float alpha = user->getAlpha();
2088
 
            vec3f col   = user->getColour();
 
2068
            vec3 col   = user->getColour();
2089
2069
 
2090
 
            user_vbo.add(user->graphic->textureid, user->getPos() - user->dims*0.5f, user->dims, vec4f(col.x, col.y, col.z, alpha));
 
2070
            user_vbo.add(user->graphic->textureid, user->getPos() - user->dims*0.5f, user->dims, vec4(col.x, col.y, col.z, alpha));
2091
2071
 
2092
2072
            //draw actions
2093
2073
            user->updateActionsVBO(action_vbo);
2147
2127
        shadow_shader->use();
2148
2128
        shadow_shader->setFloat("shadow_strength", 0.5);
2149
2129
 
2150
 
        vec2f shadow_offset = vec2f(2.0, 2.0) * gGourceSettings.user_scale;
 
2130
        vec2 shadow_offset = vec2(2.0, 2.0) * gGourceSettings.user_scale;
2151
2131
 
2152
2132
        glPushMatrix();
2153
2133
            glTranslatef(shadow_offset.x, shadow_offset.y, 0.0f);
2217
2197
 
2218
2198
    drawBackground(dt);
2219
2199
 
2220
 
    if(draw_loading) {
 
2200
    if(!commitlog) {
2221
2201
        loadingScreen();
2222
 
        draw_loading = false;
2223
2202
        return;
2224
2203
    }
2225
2204
 
2226
 
    Frustum frustum(camera);
 
2205
    Frustum frustum(camera.getPos(), camera.getTarget(), camera.getUp(), camera.getFOV(), camera.getZNear(), camera.getZFar());
2227
2206
 
2228
2207
    trace_time = SDL_GetTicks();
2229
2208
 
2305
2284
        fontmanager.startBuffer();
2306
2285
    }
2307
2286
 
2308
 
    font.roundCoordinates(false);
 
2287
    font.roundCoordinates(false);    
 
2288
    font.setColour(vec4(gGourceSettings.dir_colour, 1.0f));
2309
2289
 
2310
2290
    root->drawNames(font);
2311
2291
 
2390
2370
    glEnable(GL_BLEND);
2391
2371
    glEnable(GL_TEXTURE_2D);
2392
2372
 
2393
 
    vec3f campos = camera.getPos();
 
2373
    vec3 campos = camera.getPos();
2394
2374
 
2395
2375
    if(logotex!=0) {
2396
2376
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2401
2381
 
2402
2382
        glBindTexture(GL_TEXTURE_2D, logotex->textureid);
2403
2383
 
2404
 
        vec2f logopos = vec2f(display.width, display.height) - vec2f(logotex->w, logotex->h) - gGourceSettings.logo_offset;
 
2384
        vec2 logopos = vec2(display.width, display.height) - vec2(logotex->w, logotex->h) - gGourceSettings.logo_offset;
2405
2385
 
2406
2386
        glPushMatrix();
2407
2387
 
2432
2412
        int cwidth    = font.getWidth("Software Version Control Visualization");
2433
2413
        int awidth    = font.getWidth("(C) 2009 Andrew Caudwell");
2434
2414
 
2435
 
        vec2f corner(display.width/2 - logowidth/2 - 30.0f, display.height/2 - 40);
 
2415
        vec2 corner(display.width/2 - logowidth/2 - 30.0f, display.height/2 - 40);
2436
2416
 
2437
2417
        glDisable(GL_TEXTURE_2D);
2438
2418
        glColor4f(0.0f, 0.5f, 1.0f, splash * 0.015f);
2445
2425
 
2446
2426
        glEnable(GL_TEXTURE_2D);
2447
2427
 
2448
 
        glColor4f(1.0,1.0,1.0,1.0);
 
2428
        fontlarge.setColour(vec4(1.0f));
2449
2429
        fontlarge.draw(display.width/2 - logowidth/2,display.height/2 - 30, "Gource");
 
2430
 
 
2431
        font.setColour(vec4(1.0f));
2450
2432
        font.draw(display.width/2 - cwidth/2,display.height/2 + 10, "Software Version Control Visualization");
2451
2433
        font.draw(display.width/2 - awidth/2,display.height/2 + 30, "(C) 2009 Andrew Caudwell");
2452
2434
    }
2453
2435
 
2454
2436
    // text using the specified font goes here
2455
2437
 
2456
 
    fontmedium.setColour(vec4f(gGourceSettings.font_colour, 1.0f));
2457
 
    
 
2438
    fontmedium.setColour(vec4(gGourceSettings.font_colour, 1.0f));
 
2439
 
2458
2440
    if(!gGourceSettings.hide_date) {
2459
2441
        fontmedium.draw(display.width/2 - date_x_offset, 20, displaydate);
2460
2442
    }
2502
2484
    //debug info
2503
2485
 
2504
2486
    if(debug) {
2505
 
        font.setAlpha(1.0f);
 
2487
        font.setColour(vec4(1.0f));
2506
2488
 
2507
2489
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2508
2490
        glEnable(GL_BLEND);
2509
2491
        glEnable(GL_TEXTURE_2D);
2510
2492
 
2511
 
 
2512
2493
        font.print(1,20, "FPS: %.2f", fps);
2513
2494
        font.print(1,40,"Days Per Second: %.2f",
2514
2495
            gGourceSettings.days_per_second);
2515
 
        font.print(1,60,"Time Scale: %.2f", gGourceSettings.time_scale);
 
2496
        font.print(1,60,"Commit Queue: %d", commitqueue.size());
2516
2497
        font.print(1,80,"Users: %d", users.size());
2517
2498
        font.print(1,100,"Files: %d", files.size());
2518
2499
        font.print(1,120,"Dirs: %d",  gGourceDirMap.size());