Lastly I've been posting links, status and thoughts on twitter, buzz and linkedin. It's an experiment, to try keep posting more often.
If you wish, you can follow me in twitter
http://twitter.com/gyakoo
google buzz
google profile
or linkedin
http://es.linkedin.com/in/gyakoo/

Tags: comments 0 comments
There are a lot of literature and articles about using script languages in games (lua, python, unrealscript, lisp, javascript, c# ...) or applications like 3dStudio Max, Maya, even FXComposer. In some projects I've bound the C++ code with Python or Lua (the most popular languages AFAIK), by using the language SDK or wrapping it around with boost::python or Luabind for advanced object oriented features.
Vector3 =
{
x = 0.0,
y = 0.0,
z = 0.0,
_init( _x, _y, _z )
{
this.x=_x;
this.y=_y;
this.z=_z;
}
add( o )
{
this.x = this.x + o.x;
this.y = this.y + o.y;
this.z = this.z + o.z;
}
};
suma(a,b)
{
return Vector3( a.x+b.x,a.y+b.y,a.z+b.z );
}
// -- Main code
v0 = Vector3(1,2,3);
v1 = Vector3(3,3,3);
c = suma(v0,v1);
v0.add( v1 );
if ( c.x == v0.x && c.y == v0.y && c.z == v0.z )
{
print( "Equals" );
}else
{
print( "Differents" );
}
As you can see, my approach is to use tables (dicts) like objects. This is used in Lua too, and other languages, but the difference here is I'm trying to do it in an easier way. The syntax is almost minimal, and you can invoke a table with the () operator, and when exists a constructor (I called it '_init') it is called to create a new object. 'print' is an external c++ function and you have others like 'std.execfile' or 'std.execstring', grouped.
meta( func, param )
{
func( param );
}
doit( m )
{
m(print, 3);
}
doit( meta );
About the final stack based machine code, below you have the extensive code corresponding to the first snippet. Explaination in next posts:
[CODE]
[Func] $00001
load _x
push this
push x
dotlv
store
load _y
push this
push y
dotlv
store
load _z
push this
push z
dotlv
store
[Func] $00002
push this
push x
dot
push o
push x
dot
add
push this
push x
dotlv
store
push this
push y
dot
push o
push y
dot
add
push this
push y
dotlv
store
push this
push z
dot
push o
push z
dot
add
push this
push z
dotlv
store
[Func] suma
push a
push x
dot
push b
push x
dot
add
push a
push y
dot
push b
push y
dot
add
push a
push z
dot
push b
push z
dot
add
lst 3
call Vector3
ret
pushtable
load $00001
store _init
del $00001
load $00002
store add
del $00002
push 0.000000
store x
push 0.000000
store y
push 0.000000
store z
poptable
store Vector3
push 1
push 2
push 3
lst 3
call Vector3
store v0
push 3
push 3
push 3
lst 3
call Vector3
store v1
load v0
load v1
lst 2
call suma
store c
push v0
push add
dot
load v1
lst 1
call
push c
push x
dot
push v0
push x
dot
eq
push c
push y
dot
push v0
push y
dot
eq
and
push c
push z
dot
push v0
push z
dot
eq
and
jz 66
push Equals
lst 1
call print
jmp 69
push Differents
lst 1
call print
Tags: c++, code, projects 4 comments
Hi, I'm back, after about 1 year since I wrote the last post. A lot of things has happened in my life, personal and professional.
I left the company and moved to another city where I'm currently working on a massively multiplayer online game, mainly focused to learn the Spanish language, but it's almost a traditional MMORPG eventually. It's a big project with a considerable budget, to develop in several years. I'm really excited with it.
...and I got married last July, after ten years sharing my life with a great person, who understands all my freak passions :)
From now I will try post in this blog more regularly.
Tags: comments 5 comments
Exploiting of systems is a subject of which I'd like to know more about. I think it's good to understand how avoid future hacking, but really you neither find much information on web nor books related. I've found a book which maybe could help us to improve these skills. Topics in book include:
- Program computers using C, assembly language, and shell scripts
- Corrupt system memory to run arbitrary code using buffer overflows and format strings
- Inspect processor registers and system memory with a debugger to gain a real understanding of what is happening
- Outsmart common security measures like nonexecutable stacks and intrusion detection systems
- Gain access to a remote server using port-binding or connect-back shellcode, and alter a server's logging behavior to hide your presence
- Redirect network traffic, conceal open ports, and hijack TCP connections
- Crack encrypted wireless traffic using the FMS attack, and speed up brute-force attacks using a password probability matrix
And related to that, in the video below, speakers Michael Stail and Felix Domke talk about The XBox 360 Security System and its Weaknesses. They first talk about all weaknesses in old Xbox I, and one by one they're going giving technical information about how they fixed them.
Tags: books, media, security 2 comments
I'm really thinking that C vs C++ discussion will never end. I just read a Peter Seibel post about interviews he has written in his book Coders at Work, asking to fifteen top programmers and computer scientist around the world about what are their opinions in using C++ language.
Tags: c++, comments 9 comments
A post from The Endeavour blog about a Linus Torval's response in a forum, makes me remember the ethernal dilemma about OO and Procedural methodologies flamewar, C++ vs C, STL vs C, Java vs C, well whatever vs C...
Linus:
C++ is a horrible language. It's made more horrible by the fact that a lotJohn:
of substandard programmers use it, to the point where it's much much
easier to generate total and utter crap with it. Quite frankly, even if
the choice of C were to do *nothing* but keep the C++ programmers out,
that in itself would be a huge reason to use C.
...
...
Well, I’m nowhere near as talented a programmer as Linus Torvalds, but I totally disagree with him. If it’s easy to generate crap in a relatively high-level and type-safe language like C++, then it must be child’s play to generate crap in C. It’s not fair to compare world-class C programmers like Torvalds and his peers to average C++ programmers. Either compare the best with the best or compare the average with the average.
...
John's impressions are clever and looks like more polite, against Linus's outspoken attitude but completely honest, but anyway after read a lot of controversial comments and what Stroustup said about his C++, finally I think that why do we have to chose one of them? Are always things black or white? I neither agree nor disagree with extreme positions ... people like discussions!
Tags: c++, comments 2 comments
What do you think about agile software development? Is it suitable for all kind of software? Maybe it isn't, but, are you sure that you can't apply principles of agile programming to some parts of your non-agile development process? Well, like almost everything in the life, it isn't a black or white response, but a gray one.


To adopt an agile software development process should be a natural process. It is good all the documentation and theory about agile methodologies out there, but if you force the team to adopt that cool methodology you read a month ago in a magazine, without taking in mind that it's almost a way of react before a changing environment, maybe it will cost more than you expected. Tags: agile, postmortem, projects 0 comments
Since I read an article from EntBlog about this book, I pushed it in my pending books queue. And ... finally a good colleague at Optenet give it to me like a present. I'm really excited. Thank you dude.

Tags: books, c++ 0 comments
Today a person asked me for books to learn to "program videogames". Well, despite that this question is more difficult to answer than you initially can think, I knew what he actually meant and I asked him (intentionally):
Nooo, graphics again! There is no problem, but, how many times I've heard this wrong association?
I said him: Why don't you begin with other things different from graphics? And his response was: Bah, that another stuff (non-graphics) is easy, at least I can understand it without problems, but I've never done graphics programming.
Wow!, Overall engine architecture, entities system, networking or even AI? Gameplay and entities behavior is really exciting. Sound system or script binding. And a parallel engine architecture, with tasks scheduling is also cool. Another good stuff is the filters pipeline, more related with graphics if you want. These are complicated ones, but are videogames too. And there are a lot of more things I can't talk you about. Also, XNA or Ogre3D are good start points. Even you can download my simple c++ space invaders game and modify it.
He: Yes, yes, but, what about graphics? Draw models. Textures!
Ok then, definitely he wants draw primitives :)

Tags: comments 2 comments
Complexity Order I mean. Algorithmic is an useful tool which every programmer needs to know. As you already know, you could find/do a very very fast routine to compare two strings, by using new SIMD instructions built in the SS4, as the PCMPEQQ for example, and reordering instructions to minimize cache fails and take advantage of out of order micro execution. But if you're applying a direct algorithm to traverse words or a direct structure to store them, there is nothing you can do when you get an asynthotic input. It is the beauty about algorithmic, an university's subject that all the software engineers should know, and apply it in their daily technology decisions (whenever they can), because the system's behavior with large input matters and can makes the difference.
I remember, when I was studying at UCA, we did practices about algorithmic and complexity order theory by measuring different algorithms times to the same problem. We sampled the time that an algorithm takes for different input sizes, so you're sampling the complexity order curve/function and then by comparing all the algorithms-times, you can see how they behave asynthotically, in a graphic manner.
I've been using this technique since then, when I need to test different approaches to same problem, or when I need to empirically demonstrate a data structure, for example. In another post in this blog I talked about a special radix tree to store IP numbers, demonstrating you'll get a constant complexity order O(k) when search for an IP, independently you store all internet IPs (another thing is the complexity order in space). This means that you'll perform same number of instructions to search any number.
So you have, O(1) < O(logn) < O(n) < O(n·logn) < O(n^2) < O(n^a) < O(a^n) < O(n!), being O(1) the best you can get in time and space. Related with this you have the NP complete problems.
Sometimes when trying to get a best time complexity, probably you'll get worse the spatial one, and vice versa. Another important note about measuring times is the time precision. Although you use a high performance counter, you cannot measure how much time takes two std vector's inserts, because current microprocessors are very fast. You should use a big N input, repeated M times, because memory never is enough (you can't insert 1·10^12 words in a vector, at least you shouldn't), and then divide the time to compute the average time. Selection of N and M is important. Also, you need to know that another daemons or processes are continuously interrupting the algorithm, maybe the compiler can generate an optimize version of your algorithm (only improving the multiplicative constant). All these variables can corrupt the times you get, so the conclusion is do not use the times as it, but the graphical comparisons between algorithms' times, or in other words, you need to extract all the multiplicative constants and think only in terms of sampled curves' behavior.
In the code below you see a snippet to measure a std list insert varying N.
unsigned long step = (MAX-MIN)/N_POINTS;
// Varying our input N
for ( unsigned long N = MIN; N < MAX; N+=step )
{
double time = 0.0;
// Repeating M times
for ( unsigned long m = 0; m < M; ++m )
{
Clock cl;
cl.Start();
// Algorithm test comes here.
// Trying to insert N numbers in a stl list
std::list<int> lis;
for ( unsigned long i = 0; i < N; ++i )
{
lis.push_back( i );
}
time += cl.Stop();
}
printf ( "%lu\t%0.10lf\n", N, time/(N*M) );
}
This code will print an output like follow:
99999 0.0000001016
6759999 0.0000001023
13419999 0.0000001042
20079999 0.0000001021
26739999 0.0000001028
33399999 0.0000001037
40059999 0.0000001016
46719999 0.0000001051
53379999 0.0000001017
60039999 0.0000001020
66699999 0.0000001012
73359999 0.0000001021
80019999 0.0000001005
86679999 0.0000001011
93339999 0.000000101
This data can be obtained for several algorithms. All those data then can be graphically represented using a plot program, like gnuplot for example.
Follow are curves for insert algorithms in <vector>, <list> and <map> Before you look through the image below, it would be interesting you know what are the complexity order for insertions in these containers. In this page you can see all O for stl containers. O(1) for vector and list. And * for map. Well, the time complexity requirements imposed by the standard for each map operation suggest a balanced binary search tree mostly. Let's see the results:

Wow!, it is interesting that the vector (red line) and the list (blue line) are constant ( O(1) ). In other words, doesn't matter how N increase, always you'll get a constant time. And the map (green line) follows a logarithmic curve ( O(logn) ). Obviously a linear interpolation between measuring points are used.
As you can view, vector has O(1) in push_back operations. Wait a minute! When a vector increases beyond its capacity, a memory resize is needed, and a copy for all elements is performed. So, why is it O(1)? It's a O(n) just because asynthotically you'll need to make N copies... Well, there exists a thing called amortized analysis to deal with it. In fact, in the wikipage about amortized analysis, the example used to describe it, is the array push back operation.
Also you can get from graphic that vector is faster than list when inserting elements, due to multiplicative constant, being smaller in vector structure. But remember, with this implementation and in the CPU I used. This is can be because in list you need to make pointers operations when a new node is added, in vector you only need access to last available memory slot to put the element. Also in list you need to create every new node (memory alloc operation).
Another comparison graphic below, measuring find operations in the three same containers.

But, what happened to green line (map's find operation)? This is a common issue you'll get when comparing very different measuring scales. Map's searches are so fast, comparing with the vector or list ones. So, you cannot see the green line because is very near to X axis, in other words, with low times. You need to change scale, but anyway you can see here that vector and list find operations are linear ( O(n) ), with different constants (again vector has lower constant). To view if map searching operation behaves like a logarithmic one, we represent independently the third curve.

And finally, it behaves like a logarithmic curve!.
Tags: algorithmic, c++, code, optimization 0 comments
Do you think you're a Duct Tape Programmer? It's more difficult than people think. Another Spolsky's great article.
And the duct-tape programmer is not afraid to say, “multiple inheritance sucks. Stop it. Just stop.”
...you’re not here to write code; you’re here to ship products.
One principle duct tape programmers understand well is that any kind of coding technique that’s even slightly complicated is going to doom your project. Duct tape programmers tend to avoid C++, templates, multiple inheritance, multithreading, COM, CORBA, and a host of other technologies that are all totally reasonable, when you think long and hard about them, but are, honestly, just a little bit too hard for the human brain.
Tags: comments 2 comments
Following last Windows focused post, I come to talk you about hooks. Well, I'm not an expert about hooks, but basically, a Windows' hook is a procedure that you can register in the operating system to intercept events before they reach an application. More information in msdn.
Well, in our try to automatize systems, we need to create a mechanism to intercept all mouse and keyboard messages generated by user in desktop. So, we can record something similar to macros in Windows, and later playback them. For example, we need to automate the Skype user interaction, or the Outlook application, and then play the macro.
It's a very interesting thing because, WM_MOUSEMOVE is a message too ;), and we could save it for example to perform some QA automated tests in a game, moving the avatar around scenario, capturing mouse moving and keyboard strokes. There are a lot of applications about hooks, and there are more hooks than only Journaling which is only a kind of hook.
Here you have a very simple application that creates this hook and records all messages. Just a note: Be careful when you're executing from Visual Studio IDE, because if you set a breakpoint in code, the hook cannot be established correctly. Maybe it could be generated by VS thread (attached to process) which avoid messages to hook, I don't know, but it is a very rare bug, difficult to find, and can drives a team's member crazy. In fact, done it.
The idea behind, you intercept all messages and serializes them (lparam, wparam, time, message number, even the hwnd but have no sense) and when you want play them you've to feed to journal playback hook with those messages. In the code below, (all) the messages are stored in a plain txt file, but its performance can be pretty bad due to the big number of messages intercepted. You can buffer and then flush them. Also you can change this, for example, sending them by network or something. Let your imagination flies.
Finally, it is not a new thing, you can google for "winmacro" and you'll find an open software (with source code) which does this journaling stuff, but with an own interface and more control. Anyway, in my code below you only have a record feature. Playback in another post...
CPP file here.
#include <windows.h>
#include <stdio.h>// -- wow, two global objects!
static HHOOK gHookHandle = 0;
static FILE* gFile = NULL;
LRESULT CALLBACK JournalRecordProc(int code ,WPARAM wparam,LPARAM lparam)
{
if ( code == HC_ACTION )
{
EVENTMSG* mesg = (EVENTMSG *)lparam;
// -- Serializes entire message
fprintf_s( gFile, "%d %d %d %d %d\n", mesg->message, mesg->paramL, mesg->paramH, mesg->time, (UINT)mesg->hwnd );
// -- Exiting when PAUSE key is pressed
if ( mesg->message == WM_KEYDOWN && GetAsyncKeyState(VK_PAUSE) )
{
const LRESULT result = CallNextHookEx( gHookHandle, code, wparam, lparam);
UnhookWindowsHookEx( gHookHandle );
gHookHandle = 0;
PostQuitMessage(0);
return result;
}
}
return CallNextHookEx( gHookHandle, code, wparam, lparam );
}
// WinMain
// --------
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
// -- Record hook and file to store messages
if ( (gHookHandle = SetWindowsHookEx(WH_JOURNALRECORD, JournalRecordProc, hInstance, 0) ) == NULL )
return 1;
if ( (gFile = fopen( "msgs.txt", "wt" ) ) == NULL )
return 1;
fprintf_s( gFile, "# Message ParamL ParamH Time HWND\n" );
// -- Main message dispatching
MSG msg = {0};
GetMessage(&msg, 0, NULL, NULL );
while ( msg.message != WM_QUIT )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
GetMessage(&msg, 0, NULL, NULL );
}
// -- Closing
fclose( gFile );
return 0;
}
Tags: c++, code, sqa 0 comments
My company just bought it. A must-to-have book.
Tags: books, comments, media 3 comments
This so addictive game really impressed me by its playability. The graphics aren't bad, and you have a lot of gaming modes, vehicles and tracks. When you're playing for a while, you get an inmersive experience, and is cool how you're running at 160km/h, listening to your co-driver giving you track information, while the car is skidding near to the trees.
Tags: comments, game, media 0 comments
Yesterday, a coworker passed me a pdf extracted form the {cuv} magazine, Sep09, where Bjarne Stroustup talks briefly about the incoming c++ standard revision, c++0x. Last revision was c++98.
At the beginning of article, he says:
‘What will C++ be once we have the facilities offered by the upcoming
standard?’ This is not an innocent ‘just philosophical’ question. Consider
how many programmers have been harmed by believing that ‘C++ is an
object-oriented language’ and ‘religiously’ built all code into huge class
hierarchies, missing out on simpler, more modular approaches and on
generic programming. Of course C++ also supports OOP, but a simple
label – especially if supported by doctrinaire teaching – can do harm by
overly narrowing a programmer’s view of what can be considered
reasonable code.
Is interesting what the main creator of c++ thinks about using it in complex Object Oriented systems.
You can download the pdf here.
Tags: c++, comments 1 comments
