Jump to content

  • Log In with Google      Sign In   
  • Create Account

Conoktra

Member Since 31 Aug 2010
Offline Last Active Aug 18 2014 03:48 PM

#4949423 C++ - do you use STL in your game?

Posted by Conoktra on 14 June 2012 - 10:18 PM

I don't ever use the STL, period. Not even when time is tight and I just "need to get it done". But then again I am a die-hard Lisper, so... take it for a grain of salt.


#4836628 Torrent API for Web-based game installer.

Posted by Conoktra on 17 July 2011 - 09:51 PM

Out of sheer curiosity, why don't you like Boost? It's basically a waiting-room for the next C++ standard library Posted Image

Well, I don't want to start a debate or anything, but I am a die-hard Scheme/C fan (that should say it all :D). IMHO C++ (and especially Boost), implement very bad programming techniques. Yes, programming in a low-level language is hard and meticulous for those used to high-level programming, but it uses a completely different coding mindset/technique that once mastered is far easier than the high-level programming. It allows for cross-platform, screaming-fast, and minimalistic/non-bloated programs to be written with elegant simplism.

On the other hand, C++ often leads to code like this:
#include <stdio.h>

enum { SCALElog=15, SCALE=1<<SCALElog, mSCALE=SCALE-1, hSCALE=SCALE/2 };

template< int DECODE >
struct Rangecoder {
  enum { NUM=4, sTOP=0x01000000U, Thres=0xFF000000U };

  typedef unsigned long long int qword;
  unsigned range, code, FFNum, Cache; qword lowc; FILE* f;

  void Init( FILE* _f ) {
	f = _f; range = 0xFFFFFFFF; lowc = 0; FFNum = 0; Cache = 0;
	if( DECODE==1 ) for( unsigned _=0; _<NUM+1; _++ ) (code<<=8)+=getc(f); 
  }

  void Quit( void ) { if( DECODE==0 ) for( unsigned _=0; _<NUM+1; _++ ) ShiftLow();  }

  unsigned Process( unsigned freq, unsigned bit ) { 
	unsigned rnew = (qword(range)*(freq<<(32-SCALElog)))>>32;
	if( DECODE ) bit = (code>=rnew);
	bit ? range-=rnew, (DECODE ? code-=rnew : lowc+=rnew) : range=rnew;
	while( range<sTOP ) range<<=8, (DECODE ? (code<<=8)+=getc(f) : ShiftLow());
	return bit;
  }

  unsigned ShiftLow( void ) {
	unsigned Carry = unsigned(lowc>>32), low = unsigned(lowc);
	if( low<Thres || Carry ) {
  	putc( Cache+Carry, f );
  	for (;FFNum != 0;FFNum--) putc( Carry-1, f );
  	Cache = low>>24;
	} else FFNum++;
	return lowc = (low<<8);
  }
};

struct Predictor {
  short cxt; 
  short p[256-1]; 

  Predictor() { for( unsigned i=0; i<sizeof(p)/sizeof(p[0]); i++ ) p[i]=hSCALE; byte(); }
  int P() const { return p[cxt-1]; }
  unsigned byte( void ) { unsigned c=cxt; cxt=1; return c; }

  void update( unsigned y ) {
	if( y ) p[cxt-1] -= ( 		p[cxt-1]  >> 5), cxt+=cxt+1;
	else	p[cxt-1] += ((SCALE - p[cxt-1]) >> 5), cxt+=cxt+0;
  }
};

template< class Predictor, class Rangecoder > 
void proc( Predictor& p, Rangecoder& rc, unsigned y=0 ) { p.update( rc.Process( p.P(), y ) ); }

unsigned flen( FILE* f ) {
  fseek( f, 0, SEEK_END );
  unsigned len = ftell(f);
  fseek( f, 0, SEEK_SET );
  return len;
}

int main( int argc, char** argv ) {
  unsigned i,c,f_len = 0;
  if( argc<4 ) return 1;
  FILE* f = fopen( argv[2], "rb" ); if( f==0 ) return 2;
  FILE* g = fopen( argv[3], "wb" ); if( g==0 ) return 3;
  Predictor p;
  if( argv[1][0]=='c' ) {
	f_len = flen( f );
	fwrite( &f_len, 1,4, g );
	Rangecoder<0> rc; rc.Init(g);
	for( i=0; i<f_len; i++ ) {
  	c = getc(f); p.byte();
  	proc(p,rc,c&0x80); proc(p,rc,c&0x40); proc(p,rc,c&0x20); proc(p,rc,c&0x10);
  	proc(p,rc,c&0x08); proc(p,rc,c&0x04); proc(p,rc,c&0x02); proc(p,rc,c&0x01);
	} rc.Quit();
  } else {
	fread( &f_len, 1,4, f );
	Rangecoder<1> rc; rc.Init(f);
	for( i=0; i<f_len; i++ ) {
  	proc(p,rc); proc(p,rc); proc(p,rc); proc(p,rc); proc(p,rc); proc(p,rc); proc(p,rc); proc(p,rc);
  	putc( p.byte(), g );
	}
  }
  fclose( f );
  fclose( g );
  return 0;
}

Yes, that's a range coder. Yes, It's horribly slow. And yes, I think I just went blind xD.


Back to the original topic:
Does anyone know of an alternative to libtorrent, one that doesn't boost?


PARTNERS