All Blog Entries

All blog entries, ordered from most recent. Entry count: 1198.

Warning! Some information on this page is older than 6 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: > 1 ... 56 57 58 59 60 ... 150 >

# Overtime Concern in Game Industry

Sat
16
Jan 2010

For those who are not up-to-date with news from the industry: There is lots of stuff posted and commented recently about the the concern of overtime work at Rockstar San Diego. I won't comment it as I don't like controversies, I'll just show interesting links:

Comments | #game industry Share

# Processing File Paths in C++

Tue
12
Jan 2010

Paths to files and directories are special kind of strings. Sometimes they have to be processed, e.g. merged or splitted into some parts like drive letter, directory, file name and extension. Standard C library provides two function for this: makepath and splitpath. They use char* strings and operate always on all possible parts (drive, dir, fname, ext). In my opinion they are not very convenient. On the other hand, modern programming languages have more functionality in this field. For example, .NET has System.IO.Path static class with methods like GetExtension, GetFileName, GetDirectoryName.

To make operations on file paths convenient in C++, I've developed some time ago my own functions for that which operate on std::string strings. I've included them in my CommonLib library. They are similar a bit to these from Delphi :) Here is how I approach this topic: First, a common task is to extract part of a path (e.g. "C:\Windows\notepad.exe"). My functions for this are:

I also have some functions for processing paths:

Path can be absolute or relative. In Windows, absolute paths start with drive letter like "C:\" (which we can recognized by looking for colon) or network share (paths that begin with "\\"). Relative paths (where most basic example is a single file name) make sense only in some context. When we use relative paths to open real files, we address them relative to the "Current Directory" (which is a separate topic, I will write about it another time). To deal with absolute and relative paths, I've coded functions such as:

NormalizePath function preprocessess all the . and .. drectories in the path. A single dot used as directory name means "my own directory" (just does nothing) and two dots mean going up one level to the parent directory. So the path we consider here is logically equal to "C:\Windows\.\system32\..\notepad.exe". Paths like this still work, but they can look a bit unclear, so you can use NormalizePath function to clean them.

Paths in Linux are quite different. My functions also support them, although I didn't test this case in real situations yet. First of all, there are no drive letters in Linux, so absolute paths just start with '/', like "/etc/passwd". Second, a slash sign is used as a separator instead of backslash (it's interesting that slash also works in Windows). It's also more common in Linux than in Windows to meet files that don't have extension or have double extension (like "MyFile.tar.gz"). A question arises here whether what we call "extension" starts from the first or from the second dot :)

Comments | #algorithms #c++ #commonlib Share

# A Reminder About My Links

Sun
10
Jan 2010

For those who don't know yet, on my website there is more than my blog, photos and screenshots gallery and portfolio. I also maintain quite long list of links to other people's blogs, especially programmers dealing with game programming and graphics programming. So if you are interested in this subject, I encourage you to take a look. I try to keep it up to date by removing not working or inactive sites while adding new ones I find interesting. I also have my parsonal links collection called Links - gamedev.txt which I update sometiemes by addign URL-s to interesting articles and websites related to gamedev.

It may sound funny by I currently find blogs and Twitter as my most valuable source of interesting news and links. With careful choice of places you visit and people you follow it has much bigger "Signal/Noise Ratio" than any Internet forum :)

Comments | #web #homepage Share

# RegScript - Bidirectional Type Inference

Sun
03
Jan 2010

Coding my RegScript programming language is no longer easy as code grows bigger, but it's still much fun. In the last days I've added support for numeric types of different size. Here is the full list: float, double, uint8, uint16, uint32 (uint), uint64, int8, int16, int32 (int), int64.

I try to keep the syntax as close to C/C++ as possible, but at the same time I introduce some interesting details like:

I've also implemented function overloading and many compiler errors and warnings similar to these from C++ compiler. But most interesting feature so far is what I call "Bidirectional Type Inference" :) I first introduced auto keyword to allow skipping type name and next I've made literal constants like 123 typeless so their type is deduced from the context (because I hate typing this f, u or ll postfixes everywhere in C++ code). For example:

// Left to right - these numbers are int16
int16 myShort = -32000 + 10;
// Right to left - newVar is int16
auto newVar = myShort;

Comments | #c++ #compilers #regscript Share

# WTS Keyboard

Sat
02
Jan 2010

It definitely wasn't a good buy. I was dreaming about new keyboard with multimedia keys to control mp3 player instead of binding strange global hotkeys like Ctrl+Alt+Home, so I was more than happy when I chose nice looking A4-Tech X-SLIM KL-7MU model with USB, headphones and microphone extension cable. It was part of my hardware upgrade together with new processor, motherboard, monitor and more. I've also installed Windows 7 then.

It took place 1.5 months ago and I've experienced many things since then. Most things work fine but I couldn't get rid of strange feeling that coding on my new computer is less comfortable than before. I blamed it on Windows 7 and I was partially right as there is a scandalous flaw in this new Microsoft product - GUI is no longer hardware accelerated! So it's no suprise that I can often see windows and controls being drawn as I move them, scroll them or type my code, even after turning off all the animations, transparencies and even all this beautiful Aero. As a proof, look at this YouTube video: Windows 7 GUI slowness. I just feel like working under Linux before installing graphics drivers. What a shame, a big step backward...

But after comparing my experiences from work with these from home I've noticed that it has to do something with the keyboard. I've always been opposing to "flat", laptop-style keyboards and my new A4tech one is just like this. So I returned to my old-school, white keyboard. Now the GUI of Windows 7 still annoys me a bit, but coding is much better. You may tell it's the matter of taste but as for me, I'm sure now that I prefer to code on a keyboard with high "step", where I can clearly see, hear and feel whether I've pressed particular key or not. I just type faster and make less mistakes on such keyboard. I'm also sure it's not the matter of getting used to it as I tried to use laptop-style keyboard now for more than a month as well as for three months when I've been in USA and in both cases I couldn't start to like it. So now I want to sell my new great keyboard (see the auction). Anyone interested? :)


Comments | #hardware #shopping Share

# RegScript - my Scripting Language

Wed
30
Dec 2009

RegScript is my scripting language I've started coding yesterday. I'm not a guru in formal languages theory, but I'm quite fascinated with programming languages, parsers and interpreters. I don't know why but I felt I'd love to write my own programming language so I just started coding it, even if it doesn't make any sense. Maybe that's just because it's like being the creator of something that we, as developers, are usually only users. The language syntax is similar to C++. Here are features I've coded untill now:

The implementation is not optimal yet as I don't generate any bytecode. I just execute statements and evaluate expressions from a tree made of polymorphic nodes dynamically allocated by parser. Sample program:

print("Hello World!\n");
for (auto i = 0; i < 10; i++)
  print("i = " + i + '\n');

Comments | #scripts #compilers #regscript Share

# Generating and Compressing AVI Video Files

Mon
28
Dec 2009

Yesterday I've decided to share all my home code using Project Hosting on Google Code, so now everyone can browse my code online by entering project called blueway. I'll be very glad to hear your opinions and suggestions about it.

Today I've researched subject of generating video data as AVI file, compressed on the fly with codecs installed in Windows. After succeeding with that I've created simple class to support this task, called VideoCompressor. You can find it in Video.hpp and Video.cpp. Test code is in ProgramMain.cpp, line 2318. It generates a 5 second video with a white horizonal line moving from bottom to top.

Here are some technical details. Functionality needed to handle video files is already inside Windows API, described in MSDN Library. The AVIFile library contains functions like AVIFileOpen, AVIFileCreateStream, AVIStreamWrite. It supports reading and writing AVI files. You need to include <Vfw.h> header and link with Vfw32.lib file. AVI is actually a container file format made of RIFF data chunks identified by 4-byte FOURCC codes (if you ever loaded 3DS models, you know what I mean). It can contain multiple streams like video and audio, which can be coded in many different formats, compressed and decompressed by codecs.

Compressing and decompressing frames of video with installed codecs can be done with Video Compression Manager library. You can display standard, system dialog window to let the user choose and configure codec with ICCompressorChoose function. Then you can just pass subsequent video frames as uncompressed RGB images to a function like ICSeqCompressFrame and you get a piece of compressed data that you can save to your AVI file.

Comments | #video #winapi Share

# Writing Parsers is Easy

Sun
27
Dec 2009

Using binary file formats is easier as data can be read and written almost directly as they are in memory, but sometimes we have to use some text formats. Whenever it is neither a standard format like XML or YAML, nor it is so simple we can load it with std::cin or scanf, we have to write a parser to read it. Writing a parser - code that reads and interprets some text format (e.g. file format or network protocol) looks like very complex task, but here I want to convince you that's not true - it is actually quite easy.

Why do I think so? It may look like it is a very long way from reading characters from a file till interpreting them as data records containing numbers, strings and other meaningful information. My answer for that is to split this problem into three layers.

The lowest layer is called CharReader. All it can do is reading single characters. It provides a layer of abstraction over reading data from a real source so you can forget whether you read from a file (hopefully with some buffering - never do file reads byte-after-byte!) or just iterate over a string fully loaded into memory. You can also forger about encoding so you see you data as characters, not bytes. It's a good idea to keep last read character somewhere so it can be "peeked" (read without losing it) many times before going to next one. The interface of a simple CharReader may look like this:

class CharReader {
public:
  CharReader(const std::string &filePath);
  // Returns last read character as out.
  // If cursor at end, returns false.
  bool Peek(char &out);
  // Moves cursor one character forward.
  void Next();
};

Next layer is called Tokenizer. We need it because it's still complicated to interpret characters directly as some structured information. Data in almost every text format is made of multiple-character pieces of information like numbers, strings etc. so it's convenient to provide another layer of abstraction to see data as a sequence of tokens, not single characters. Here are some typical kinds of tokens that can be found also in programming languages:

Tokenizer uses CharReader to read chars and interprets these chars as tokens. Just like CharReader, it buffers and provides access to single token that was parsed recently so you can read it many times before anvancing to next one. It's also Tokenizer's responsibility to skip comments and whitespaces between tokens. Example interface may look like this:

class Tokenizer {
public:
  Tokenizer(CharReader &cr);
  
  enum TOKEN_TYPE {
    TOKEN_END,
    TOKEN_IDENTIFIER,
    TOKEN_STRING,
    TOKEN_SYMBOL,
  };
  // Returns type of the last read token.
  TOKEN_TYPE GetType();
  // Returns content of the last read token.
  const std::string & GetContent();
  // Moves cursor one token forward.
  void Next();
};

And finally, when being able to see file as made of tokens, it's easy to code the third layer - Parser - on top of that. Parser reads subsequent tokens and interprets them as some meaningful data. For example, you can parse a Key="Value" pair by expecting token of type identifier and saving its content as Key, then expecting the (=) symbol and finally expecting a string token and saving its content as Value. Of course you also have to find a way to report errors on all these stages, including information about current row and column.

Comments | #algorithms Share

Pages: > 1 ... 56 57 58 59 60 ... 150 >

[Download] [Dropbox] [pub] [Mirror] [Privacy policy]
Copyright © 2004-2026