Categories
Uncategorized

Sourcegear Vault does not support fixing merge conflicts.

I found a problem with Vault which is that, when a merge conflict arises, I can’t edit the code generated by the resultant conflict. My only choice is to accept or reject parts of the code.
Forum post

This simple case illustrates the problem:.

Lets say I have a released function as follows:
void func1(int numbre);

I fixed the spelling in a branch:
void func1(int number);

I add a parameter to that function in the released version:
void func1(int numbre, bool b);

Obviously no tool can figure this out automatically so a merge conflict arises. The proper solution for the branched version is to have both the “bool b” parameter and the correctly spelled variable.
void func1(int number, bool b);

However, the only option I’m given is to use the released version.
void func1(int numbre, bool b);

I have no way to edit text in the merge resolve tool. Even something as limited as saying “CONFLICT HERE” and saving out the file would help. But there’s no support for that. My only option is to save the incorrect file, fix the conflicts myself, and then merge later, which takes 10X longer than simply changing a variable name. This is doable but pretty unacceptable considering that Perforce does let you edit code and that conflict resolution is a fundamental feature of a source control application. I could use it by myself, but for a large company?

Categories
Uncategorized

Artist of the year

At work an artist wanted to improve the framerate by disabling lights. So he made the light color black. His logic was that if he couldn’t see the light, the light didn’t exist. He then bothered us (the graphics programmers) complaining that the framerate was still too low.

This is similar to the story of the woman who used the smallest font in all her Word documents in order to minimize the filesize.

Categories
Uncategorized

Anti-spam solution against bots

There’s an easy solution to bot spam that as far as I know nobody has implemented yet.

1. All spam contains hyperlinks
2. All spam is sent repeatedly in a short timeframe from the same computer.
3. There is rarely a legitimate case where a single computer will send greater than some threshold (say 20) emails in a short timeframe which contains hyperlinks.

Therefore, just have email servers check outgoing emails. If emails per second is greater than X, and greater than Y emails have been sent by that system already in the last M minutes, and all those emails contain hyperlinks, that computer is potentially sending spam. It would be more accurate to add the condition “Identical or similar hyperlinks” but that would be easily circumvented.

Legitimate marketers will have their own email servers so can still send legitimate spam (such as mailling lists). Bot computers behind AOL accounts would be throttled.

The way to implement this is through a table which tracks the last N email senders. Every time an email with a hyperlink is sent, lookup that sender in the table. If that sender is not in the table, add it. Add to that sender’s spam score the number of recipients. If this would cause the score to exceed some threshold T, reject the send entirely and flag this sender in some kind of log as a potential spammer. This score will diminish by 1 point every M seconds. If the score reaches 0, remove this sender from the table.

With the correct settings, this won’t bother 99% of the users, spam bots would be throttled, and perhaps most importantly they would be flagged as suspect systems. An admin can then check if that user is indeed spamming and ban as appropriate.

Categories
Uncategorized

Minor annoyance of the day: vector

When I was in college I would occasionally overhear a classmate refer to a vector when talking about a homework project. For years I was mildly puzzled by this. My programming classes didn’t have anything to do with linear algebra. It made no sense, but as I only heard it rarely I didn’t follow up.

Later on I found out that stl calls a dynamic length array a vector. What the heck? Other than trying to sound pretentious, I can’t think of any grounds for or reason to relate the two. A vector is a “quantity completely specified by a magnitude and a direction.” A dynamic array is an set which can grow in size.

The best term to use is a List (which is what I use in RakNet).

Categories
Uncategorized

Telecommuting for programmers

I’ve worked as a telecommuter for 7 years and as an on-site employee for 3. I’ve spoken to those who are both strongly for telecommuting and strongly against it. The conclusions I’ve come to are:

Telecommuting programmers work more and are more productive in the hours they spend
Because there’s no physical going to work, one is always at work. As a telecommuter I tended to work 10-12 hour days as opposed to the strict 8 hour schedule at my on-site work. Furthermore, I tended to work at times when I was feeling most productive, with fewer interruptions, noise, and on better equipment. Last month a lead programmer at the Collective spent one day working at home and remarked to me “I’m surprised how much I got done at home.” This is no surprise to anyone that has telecommuted.

Telecommuting programmers have better communication
A common argument against telecommuting is that communication is worse. The quality of written vs. verbal communication depends on the communication skills of the indvidual. While some producers and artists need improvement on this, programmers tend to excel at textually describing information, using accurate terminology with complete descriptions and all necessary and relevant information In practice, be it instant messenger or email, programmers are more likely to accurately describe what they mean in text than verbally. Furthermore, it is much faster to read and write than to speak, without the repetition and noise you get with verbal descriptions. Should verbal communication be necessary, there is an invention called the phone that does a pretty good job. It’s never been necessary for me in 7 years.

Regardless, I really don’t see any difference between speaking to someone on the phone and speaking to them standing there. Need diagrams? Want to show a bug? I’ve never had a case where a bug could not be accurately described to me without being there in-person.

Another benefit of electronic communication is that one can quickly send short messages “Where is the code that renders the GUI?” on instant messenger and get a fast response “See GUI.h”. This results in vastly improved productivity for the person asking the question without disrupting the attention or workflow of the person answering the question. With verbal communication you invariably disrupt the person you are asking and it takes them 15 minutes to get back into the zone.

Part of the reason why one person (me) was able to implement loading and saving of multiplayer games, with 4 game modes, in Deadly Dozen 2 was because of the efficiency of electronic communication. Anytime I had a question I could ask and get a fast answer. There is a massive time savings between being able to ask a question and continue working as opposed to having to guess and check foreign code, and redoing work because a previous assumption was incorrect.

Everyone I’ve spoken to that has tried telecommuting has had positive feedback regarding communication. One producer indicated to me that he wouldn’t allow it because of the poor communication. When I asked him if he actually tried it before his answer was “No but…”

Telecommuting programmers are cheaper

No office, no power usage, no free lunches, the programmer provides his own equipment. Programmers at home tend to continue working while eating while programmers at the office tend to go out to lunch with coworkers. Furthermore, telecommuting positions are in higher demand and there is a shortage of available positions. Due to supply and demand, this means telecommuting employees will often work for less and there is a greater pool to choose from. I’ve turned down work at Blizzard because they have no incentive to offer me to work there other than more money. But if they were to let me telecommute my quality of life would be so much higher that would supplant any monetary incentives they could offer.

But I don’t know who is working!

One argument against telecommuting is you can’t control people. You don’t know what they are working on or if they are working at all. However, just because you force a programmer to be at his desk doesn’t mean he is working. As long as the employer practices due diligence, keeping track of what people are working on whether they be at the office or not, you can easily detect the bad apples.

In my opinion a company that lets its programmers telecommute would enjoy increased productivity, lowered costs, and better communication.

Categories
Uncategorized

Decals against arbitrary surfaces which also shoot through objects

This is one (big) bullet shot which went through the triangle out to the other side. It supports clipping against static geometry and fades at an angle.

Front side:

Front Side

Back Side:

Back Side

Categories
Uncategorized

CEGUI update / mini review

I’ve been using CEGUI for a couple of weeks now. I’ve been trying to get a string to show up, with word wrap, for 5 days. Not actively, but on and off I’ve been pursuing this topic for that long.

My difficulty lies in that I don’t need to use their window system, with selectable text, etc. And I don’t want to define my text in an xml file, the preferred way to setup your interface. I simply want to do the equivalent of printing “Hello World” purely from code, including word wrap.

My first approach was to use the Font class. It seemed pretty good – there is a function to tell you how long a string was and how many lines it would span. I didn’t see a function to tell you where exactly the string was split but it’s a good start. The problem was that it didn’t work. So I asked about this on the forum. A day later I was essentially told not to use that class directly. It didn’t bother me too much, because I had a hunch of the technical reasons why this might be, but user classes should have clearly been delineated from internal classes and marked as such. As an aside, in RakNet all classes are independently functional and are documented as to their use, not just with Doxygen.

Anyway, to display text, you have to create a window and set the text for that window. How do you do this? There’s a Window class, a StaticText class, a DefaultWindow type, and a GUISheet class. GUISheet is the one to use although StaticText is the one you would think to use, with functions to set the text color, formatting, and other things. However, StaticText contains abstract functions, meaning you can’t use it directly, as I found out after I went to the trouble of trying to use it and then compiling. It turns out this is a class for internal use only. Arguably this was my fault for not looking closely enough to see that there were pure virtual functions. This is the same problem as before though – it should have been marked which classes were for the user and which not.

It’s definitely not obvious that GUISheet is the class you would use to display text. This is doubly the case because GUISheet does not contain functions related to text. It turns out the way it supports text operation is through a setProperty function which takes a string for the action to be performed and a string for the parameter. For example. “HorizFormatting” followed by “LeftAligned” (or something similar). I’m not sure how you are supposed to know this. In order to determine what properties were supported I had to search the source code for “: public Property”

Using strings as the native interface to set properties is a design mistake because it adds an unnecessary layer of abstraction between the user and the intended functionality. Rather than simply passing native types around (such as numbers) I have to convert them to strings. When I want to get the native type back from the string I have to do a reverse conversion, which I’m not sure is even supported. The reason they did this was to more easily support scripting. However, the proper way to architect this would have been to provide a translation layer from script strings to native types, such as numbers, with the reverse operation supported as well, rather than taking strings directly and hiding the native types.

CEGUI is very powerful if you stick to the mechanisms they give you. With almost no effort you can add tables, scroll bars, buttons, input windows, and other widgets. However, these widgets do not provide everything you might need. For example, my current difficulty comes from the fact that I’m trying to fade out and then delete text over time, a function not natively provided. It seems like cracks in the armor start to show through in those instances.

For API usability I’d give CEGUI a C-. It’s well documented at the level of Doxygen. They use Doxygen much better than RakNet does. Depreciated and non-user classes are not documented as such that I was able to see. The newer features seem to have worse architecture than the older features. However, the availability of the source code is a huge plus: it makes what would be otherwise insurmountable problems minor inconveniences.

For functionality I’d give it a B+. It does a lot and covers most of the common features. My favorite feature is input parsing, so it will natively understand double clicks. It also supports copy/paste, text highlighting, tables, and scroll bars. The GUI editor is a major benefit.

Categories
Uncategorized

Test your C++ architecture skills

Here’s the problem:
Often in games when text shows up on the screen it doesn’t just pop in and pop out. Instead, it will fade in, display for some time, and fade out.
CEGUI (my GUI library) doesn’t support this. So I have to write something myself.

Solution:
Obviously the solution is to modify the alpha of the string.

My question for you:
“What is the best way to architect this?” Composition? Inheritance? Modify the string class? Write a string manager? Something else? This is non-trivial.

Think about your answer, then scroll down

.

.

.

.

.

If you’ve read my previous posts, the best architecture has small units of functionality that do the minimum possible while accomplishing the task at hand.

Classes which are well designed
A. Have loose coupling, which means that they have generic inputs and outputs.
B. Have tight cohesion, which mean they don’t rely on other systems to do the work they are responsible for.

Think again what you would do, then scroll down for what I did:

.

.

.

.

.

Header file:

#ifndef __FADE_CONTROLLER_H
#define __FADE_CONTROLLER_H

// Assumes the object being faded has an alpha.
// This handles the math of fading in and out.
// Just have an instance of this class composited with whatever you want faded. Then multiply GetAlpha by the alpha of the object.
// Call Update with the elapsed time since the last call to Update
// You can freely change the member variables of the class
struct FadeController
{
FadeController();
~FadeController();
float GetAlpha(void) const;
bool IsExpired(void) const;
void Update(unsigned elapsedTime);

// If fadeInTime < elapsedTime, the percentile elapsed will be used as alpha unsigned int fadeInTimeMS; // If lifeTime!=0 && lifeTime < elapsedTime then this string will be removed from AlphaTextList unsigned int lifeTimeMS; // Total MS elapsed unsigned int elapsedTimeMS; // Will calculate alpha as the remaining time unsigned int fadeOutTimeMS; }; #endif

Source file:

#include "FadeController.h"

FadeController::FadeController()
{
}
FadeController::~FadeController()
{
}
float FadeController::GetAlpha(void) const
{
if (elapsedTimeMS < fadeInTimeMS) return (float) elapsedTimeMS / (float) fadeInTimeMS; else if (lifeTimeMS!=0) { if (elapsedTimeMS < fadeOutTimeMS) return 1.0f; else if (elapsedTimeMS < lifeTimeMS) return (float) (lifeTimeMS-fadeOutTimeMS) /(float) (lifeTimeMS-elapsedTimeMS); return 0.0f; } else return 1.0f; } void FadeController::Update(unsigned elapsedTime) { elapsedTimeMS+=elapsedTime; } bool FadeController::IsExpired(void) const { return lifeTimeMS!=0 && elapsedTimeMS > lifeTimeMS;
}

Seems very simple right? But consider that there are NO external dependencies. This will link fast, can work with any game, and in fact overengineers the problem beecause it can work with things other than strings. For example, shrapnel could fade out too.

Just composite this class with whatever you want faded and hook it in with two lines of code.

If you have come up with a better solution, post it in the comments.

Categories
Uncategorized

There’s something wrong with Visual Studio 2005

I noticed that Visual Studio 2005 will frivolously ask you if you want to build out of date projects. For example, if I change a file in one project, build that project and its dependencies, and then try to run it will tell me that unrelated projects are out of date. Eventually I disabled that warning. Now I get a problem where, after building a project, it won’t take my changes or will tell me the source file is wrong.

So it seems like the warning was right and the real problem is even though you build your project sometimes you need to build it twice for no reason.

Categories
Uncategorized

CEGUI is very nice!

As in my last post I’m working on the GUI system for my engine. I’m using CEGUI and positively suprised me. I went to their forums and gave my requirements, which are non-trivial:

Scrolling chat window that splits text, with a per-line prefix
Line, bar graphs
Tables
Console input window.

While they couldn’t do everything I wanted (graphs were for a later version) everything else they claimed they could do directly and it was in their sample already.

I’m investigating now. If this is the case then it’ll save me a lot of time.