Creating mods for OpenArena

March 26, 2009

Using the Quake 3 source, we can also create mods for OpenArena, albeit with some modifications. Just compiling the source and installing a mod will give you a ‘Client/Server mismatch’ error. So, follow the steps below to get your mod up and running :

  • Install OpenArena first (You can get it from the package manager on most linux distributions)
  • Download the Quake 3 source from http://ioquake3.org/
  • Change BASENAME in ioquake3/code/qcommon/q_shared.h from “baseq3″ to “baseoa”
  • Make other changes to code if you want
  • Make sure you have libsdl and libopenal
  • Compile using make
  • Navigate to the directory baseoa/ under ~/.openarena/ and create a directory vm/ under it
  • Copy ioquake3/build/release-linux-i386/baseq3/vm/qagame.qvm to baseoa/vm/
  • Run the game

C++ Cheat Codes

December 2, 2008

1. Finding out if a sequence is palindromic

bool isPalindrome(string s)
{
return equal( s.begin(), s.end(), s.rbegin() );
}

2. Eliminating consecutive duplicates in a sequence

void eliminate(string& s)
{
s.resize( unique(s.begin(), s.end()) - s.begin() );
}

3. Counting the number of bits in an integer

int bitCount(int x)
{
return __builtin_popcount(x);
}

4. Finding the GCD of two integers

int gcd(int x, int y)
{
return __gcd(x, y);
}

5. Summing up all elements in a sequence

int sum(vector<int> v)
{
return accumulate(v.begin(), v.end(), 0);
}

Dont reinvent the wheel. Use STL.

May 10, 2008

The STL (Standard Template Library) provides numerous classes and functions to simplify everyday programming tasks in C++. It is written into the C++ specification, so you needn’t worry that you may be using non-standard headers in case you do use it.

If you find yourself constantly needing stacks, queues, expandable arrays et al, the STL is just for you.

In this article, i will demonstrate the basics of the vector, which is a great replacement for an array. A vector is, simplistically speaking, an expandable array. It grows and shrinks according to your requirements.

Lets assume you need to accept N integers from the user and need to display the list at the end (a very naive example, just for demonstration).

Since N is known only at runtime, you have a problem.

  • How many locations on an array do you allocate?
  • Do you opt for the messier linked list implementation instead?

One approach is to declare an array with a large number of elements.

This approach has two disadvantages:

  • It wastes space.
  • It places an upper bound (which although may never be reached, is still a constraint) on the number of elements you can have in the array.

Without the STL, your code may look like this :

#include <iostream>
using namespace std;

int main()
{
   //Declare large array
   int arr[100];
   int size=0;

   //Get input from the user
   char reply = 'y';
   do
   {
      cout<<"Enter number : ";
      cin>>arr[size++];

      cout<<"Any more (y/n)? ";
      cin>>reply;
   } while(reply != 'n');

   //Display the list
   for(int i=0 ; i<size ; i++)
      cout<<arr[i]<<" ";

   cout<<endl;
   return 0;
}

With the STL :

#include <iostream>
#include <vector>
using namespace std;

int main()
{
   //Vector
   vector<int> V;

   //Get input from the user
   char reply = 'y';
   int num;
   do
   {
      cout<<"Enter number : ";
      cin>>num;

      //Add the number to the back of the vector
      V.push_back(num);   

      cout<<"Any more (y/n)? ";
      cin>>reply;
   } while(reply != 'n');

   //Display the list
   //Notice that the vector knows its own size
   for(int i=0 ; i<V.size() ; i++)
      cout<<V[i]<<" ";

   cout<<endl;
   return 0;
}

Line 8 creates the vector. The datatype is specified within <>. So in case you want to create a vector that holds chars, then you would type

vector<char> V;

The number of elements in the vector can be found using the size() function. This simplifies things a lot. You no longer have to maintain and update separate variable that indicates the size.

Accessing an element in a vector can be done similar to the way in which you would access an element in an array.

There is a more efficient way to iterate through the vector, but for all practical purposes this will do.

Good reference :
http://www.cplusplus.com/reference/stl/vector/


Getting over Turbo C++ 3.0 and moving on

May 8, 2008

I can’t understand this craze for an antiquated compiler which, although, was a great product during its time, is not really a great platform to work on now.

So, if you still use Turbo C++, here are a few reasons to move on.

1. It follows an older C++ standard

Ever wondered why the following program (the ubiquitous ‘Hello World’ in C++) does not compile on Turbo C++?

#include <iostream>
using namespace std;

int main()
{
   cout<<"Hello World";
   return 0;
}

The reason is that Turbo C++ requires you to use the older
#include <iostream.h> declaration.

This is just a trivial menace. You cannot use template functions, there is no exception handling, no STL…… must i go on?

2. It forces you to use non-standard headers and functions

The first thing that people say when they move onto another compiler is, “Hey, where did conio.h go?”. Thats because you’re forced to use getch() at the end of any console program written in Turbo C++ (you wont see the output if you dont).

So, the moment you step outside the Turbo C++ world, you feel lost without your friends getch(), gotoxy() and clrscr().

3. The DOS mode editor just doesn’t cut it anymore

Agreed, the syntax highlighting is tidy. But thats all there is to compliment.

You cant change the font. The scrollbars are not convenient to use either.

Some alternatives:

1. Dev C++ : This is a great IDE thats free to download and use.
http://www.bloodshed.net/devcpp.html

2. Code::Blocks : My personal favorite. Has a great code completion feature, and you can configure it to work with any compiler.
http://www.codeblocks.org/

3. Visual C++ 2008 express : Free to download and use again, but a little heavyweight.
http://www.microsoft.com/express/vc/

4. Dump all the IDEs. Just switch to linux, use vim and g++ from the commandline :
You will end up doing this someday. Its the purest way to code, and gives you total control.