Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions data/gource.1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ Time in seconds files remain idle before they are removed or 0 for no limit.
\fB\-\-file\-idle\-time\-at\-end SECONDS\fR
Time in seconds files remain idle at the end before they are removed.
.TP
\fB\-S, \-\-scale-by-file-size\fR
Scale file nodes by file size.
.TP
\fB\-\-file-scale FACTOR\fR
Scale factor for file nodes (default: 1.0).
.TP
\fB\-\-dir-spacing FACTOR\fR
Spacing for directory nodes (default: 1.0).
.TP
\fB\-\-file-gravity FACTOR\fR
Gravity for file nodes (default: 0.000001).
.TP
\fB\-\-file-repulsion FACTOR\fR
Repulsion for file nodes (default: 1000.0).
.TP
\fB\-\-show-file-size-on-hover\fR
Show file size on hover.
.TP
\fB\-e, \-\-elasticity FLOAT\fR
Elasticity of nodes.
.TP
Expand Down Expand Up @@ -378,6 +396,8 @@ type - Single character for the update type - (A)dded, (M)odified or (D)ele
file - Path of the file updated.
.ti 10
colour - A colour for the file in hex (FFFFFF) format. Optional.
.ti 10
file_size - The size of the file in bytes. Optional.

.SS Caption Log Format

Expand Down
86 changes: 76 additions & 10 deletions src/dirnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/

#include "dirnode.h"
#include "gource_settings.h"

float gGourceMinDirSize = 15.0;

float gGourceForceGravity = 10.0;
float gGourceDirPadding = 1.5;

bool gGourceNodeDebug = false;
bool gGourceGravity = true;
Expand Down Expand Up @@ -108,7 +108,8 @@ void RDirNode::nodeUpdated(bool userInitiated) {
if(userInitiated) since_last_node_change = 0.0;

calcRadius();
updateFilePositions();
if (!gGourceSettings.scale_by_file_size)
updateFilePositions();
if(visible && noDirs() && noFiles()) visible = false;
if(parent !=0) parent->nodeUpdated(true);
}
Expand Down Expand Up @@ -408,6 +409,11 @@ bool RDirNode::addFile(RFile* f) {
//debugLog("addFile %s to %s\n", f->fullpath.c_str(), abspath.c_str());

files.push_back(f);
if (parent == 0) {
float rx = (rand() % 200 - 100) / 100.0f;
float ry = (rand() % 200 - 100) / 100.0f;
f->setPos(f->getPos() + vec2(rx, ry));
}
if(!f->isHidden()) visible_count++;
f->setDir(this);

Expand Down Expand Up @@ -573,7 +579,17 @@ float RDirNode::getArea() const{

void RDirNode::calcRadius() {

float total_file_area = file_area * visible_count;
float total_file_area = 0;
if (gGourceSettings.scale_by_file_size) {
for (RFile* f : files) {
if (!f->isHidden()) {
float r = f->getSize() / 2.0f;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this sets the radius to file size. It means the actual dot size will be proportional to file size squared. The area of the dots will not be proportional to file size.

total_file_area += r * r * PI;
}
}
} else {
total_file_area = file_area * visible_count;
}

dir_area = total_file_area;

Expand All @@ -586,11 +602,11 @@ void RDirNode::calcRadius() {
// parent_circ += node->getRadiusSqrt();
}

this->dir_radius = std::max(1.0f, (float)sqrt(dir_area)) * gGourceDirPadding;
this->dir_radius = std::max(1.0f, (float)sqrt(dir_area)) * gGourceSettings.dir_spacing;
//this->dir_radius_sqrt = sqrt(dir_radius); //dir_radius_sqrt is not used

// this->parent_radius = std::max(1.0, parent_circ / PI);
this->parent_radius = std::max(1.0f, (float) sqrt(total_file_area) * gGourceDirPadding);
this->parent_radius = std::max(1.0f, (float) sqrt(total_file_area)) * gGourceSettings.dir_spacing;
}

float RDirNode::distanceToParent() const{
Expand Down Expand Up @@ -892,6 +908,53 @@ void RDirNode::calcEdges() {
}
}

void RDirNode::applyFilePhysics(float dt) {
if (files.empty() || !gGourceSettings.scale_by_file_size) return;

const int iterations = 2;
for (int i = 0; i < iterations; ++i) {
// Apply forces
for (auto it1 = files.begin(); it1 != files.end(); ++it1) {
RFile* f1 = *it1;
if (f1->isHidden()) continue;

// Gravity
vec2 dir_to_center = pos - f1->getPos();
float dist_to_center = glm::length(dir_to_center);
f1->accel += normalise(dir_to_center) * dist_to_center * gGourceSettings.file_gravity;

// Repulsion from other files
for (auto it2 = std::next(it1); it2 != files.end(); ++it2) {
RFile* f2 = *it2;
if (f2->isHidden()) continue;

vec2 dir = f2->getPos() - f1->getPos();
float dist2 = glm::length2(dir);
float r1 = f1->getSize() / 2.0f;
float r2 = f2->getSize() / 2.0f;
float r_sum = r1 + r2;

if (dist2 < r_sum * r_sum) {
float dist = sqrt(dist2);
float overlap = r_sum - dist;
vec2 force = normalise(dir) * overlap * gGourceSettings.file_repulsion;
f1->accel -= force;
f2->accel += force;
}
}
}

// Update positions
for (RFile* f : files) {
if (f->isHidden()) continue;
f->vel += f->accel * dt;
f->setPos(f->getPos() + f->vel * dt);
f->vel *= 0.9f; // Damping
f->accel = vec2(0.0f, 0.0f);
}
}
}

void RDirNode::logic(float dt) {

//move
Expand All @@ -904,11 +967,14 @@ void RDirNode::logic(float dt) {
}

//update files
for(std::list<RFile*>::iterator it = files.begin(); it!=files.end(); it++) {
RFile* f = *it;

f->logic(dt);
}
if (gGourceSettings.scale_by_file_size) {
applyFilePhysics(dt);
}
for(std::list<RFile*>::iterator it = files.begin(); it!=files.end(); it++) {
RFile* f = *it;

f->logic(dt);
}

//update child nodes
for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) {
Expand Down
3 changes: 2 additions & 1 deletion src/dirnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ class RDirNode : public QuadItem {
void updateSplinePoint(float dt);
void move(float dt);

vec2 calcFileDest(int layer_no, int file_no);
vec2 calcFileDest(int max_files, int file_no);
void updateFilePositions();
void applyFilePhysics(float dt);

void adjustDepth();
void adjustPath();
Expand Down
28 changes: 26 additions & 2 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

#include "file.h"
#include "gource_settings.h"
#include <cmath>
#include <string>

float gGourceFileDiameter = 8.0;

Expand All @@ -28,6 +31,7 @@ RFile::RFile(const std::string & name, const vec3 & colour, const vec2 & pos, in
hidden = true;
size = gGourceFileDiameter * 1.05;
radius = size * 0.5;
file_size = 0;

setGraphic(gGourceSettings.file_graphic);

Expand Down Expand Up @@ -73,6 +77,24 @@ RFile::RFile(const std::string & name, const vec3 & colour, const vec2 & pos, in
RFile::~RFile() {
}

void RFile::setFileSize(unsigned int new_file_size) {
file_size = new_file_size;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to animate the file size changing, so it interpolates between the old file size and the new file size, maybe over the same period as the action laser beam. So it would keep the old size but also store the new size, and then it could use another variable like file_size_change_time_elapsed to work out the current size.


if (gGourceSettings.scale_by_file_size) {
if (file_size > 0) {
radius = gGourceSettings.file_scale * log((float)file_size + 1.0f);
} else {
radius = gGourceSettings.file_scale;
}
size = radius * 2.0f;
setGraphic(gGourceSettings.file_graphic);
}
}

unsigned int RFile::getFileSize() const {
return file_size;
}

void RFile::remove(time_t removed_timestamp) {
last_action = elapsed;
fade_start = elapsed;
Expand Down Expand Up @@ -283,11 +305,13 @@ void RFile::drawNameText(float alpha) {

float name_alpha = selected ? 1.0 : alpha;

std::string label = gGourceSettings.file_extensions ? ext : name;

if(selected) {
file_selected_font.draw(screenpos.x, screenpos.y, name);
file_selected_font.draw(screenpos.x, screenpos.y, label.c_str());
} else {
file_font.setAlpha(name_alpha);
file_font.draw(screenpos.x, screenpos.y, gGourceSettings.file_extensions ? ext : name);
file_font.draw(screenpos.x, screenpos.y, label.c_str());
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RFile : public Pawn {
float last_action;

float radius;
unsigned int file_size;

vec2 dest;
float distance;
Expand Down Expand Up @@ -75,6 +76,8 @@ class RFile : public Pawn {

void setDest(const vec2 & dest){ this->dest = dest; }
void setDistance(float distance){ this->distance = distance; }
void setFileSize(unsigned int file_size);
unsigned int getFileSize() const;

void calcScreenPos(GLint* viewport, GLdouble* modelview, GLdouble* projection);

Expand Down
11 changes: 6 additions & 5 deletions src/formats/commitlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool RCommitLog::createTempFile(std::string& temp_file) {

// RCommitFile

RCommitFile::RCommitFile(const std::string& filename, const std::string& action, vec3 colour) {
RCommitFile::RCommitFile(const std::string& filename, const std::string& action, vec3 colour, unsigned int file_size) {

this->filename = RCommitLog::filter_utf8(filename);

Expand All @@ -298,6 +298,7 @@ RCommitFile::RCommitFile(const std::string& filename, const std::string& action,

this->action = action;
this->colour = colour;
this->file_size = file_size;
}

RCommit::RCommit() {
Expand All @@ -318,11 +319,11 @@ vec3 RCommit::fileColour(const std::string& filename) {
}
}

void RCommit::addFile(const std::string& filename, const std::string& action) {
addFile(filename, action, fileColour(filename));
void RCommit::addFile(const std::string& filename, const std::string& action, unsigned int file_size) {
addFile(filename, action, fileColour(filename), file_size);
}

void RCommit::addFile(const std::string& filename, const std::string& action, const vec3& colour) {
void RCommit::addFile(const std::string& filename, const std::string& action, const vec3& colour, unsigned int file_size) {
//check filename against filters
if(!gGourceSettings.file_filters.empty()) {

Expand All @@ -347,7 +348,7 @@ void RCommit::addFile(const std::string& filename, const std::string& action, c
}
}

files.push_back(RCommitFile(filename, action, colour));
files.push_back(RCommitFile(filename, action, colour, file_size));
}

void RCommit::postprocess() {
Expand Down
8 changes: 5 additions & 3 deletions src/formats/commitlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ class RCommitFile {
std::string filename;
std::string action;
vec3 colour;
unsigned int file_size;

RCommitFile(const std::string& filename, const std::string& action, vec3 colour);
RCommitFile(const std::string& filename, const std::string& action, vec3 colour, unsigned int file_size);
};

class RCommit {
vec3 fileColour(const std::string& filename);
public:
time_t timestamp;
std::string username;
std::string commit_hash;

std::list<RCommitFile> files;

void postprocess();
bool isValid();

void addFile(const std::string& filename, const std::string& action);
void addFile(const std::string& filename, const std::string& action, const vec3& colour);
void addFile(const std::string& filename, const std::string& action, unsigned int file_size = 0);
void addFile(const std::string& filename, const std::string& action, const vec3& colour, unsigned int file_size = 0);

RCommit();
void debug();
Expand Down
Loading