Kill’n time

Found an interesting time paser, GNU Robots. Quite interesting really you write program in scheme and it uses GNU Guile to run the robot off the scheme program you supply.

It’s also a good excuse to learn more about Scheme hehe. I also found an interesting program called gnubg, I want to take a look at it’s windows port to see how well behaved it is. I might know some one that might have use for it 😉

I also need to start writing my todo list for what to do next with NPM and to get NPM_PortConfig operational.

Tired, Angry, and Generally P.T.F.O.

At the wits end and bored as watching shit roll down a snow drift in winter.

The only remaining possibility for the GF8400GS’s amazingly crappy performance with RvS and TSS… Drivers or worse the games are just rubbish with that card because of the age difference. I did first run RvS on a GF4200 and SWAT4 on a high end Radeon 9800 after all lol

To top it all off, I could’ve either gotten a 8600GT online for less after rebates or same care for much less if I could’ve “just ordered online” but no… who the fook listens to me lol.

I can’t roll back drivers to the ones that I know did work smoothly with RvS & TSS on my 6200 though because they are so damn old that those drivers don’t support the 8400 even through the unified arch. Grrrrr…. I’m not getting a fucking deskjob out of this and retirement is not an option !!!

How the rat fucking hell you can kick at a games settings until you’ve gotten average frame rates from every thing between 30 FPS and a 150FPS and still get the lag step feeling of “doing the robot” when moving is ridicules ! FFS I may as well have blown it all on a paper weight instead of an “upgrade” of a replacement.. Sheesh if they had the right port type I’d get the same cheap-ass card I had to replace… Wasn’t much but at least it fucking worked right !!!

It can run BF2 all out without even moving a muscle but RvS and TSS kill it. Today we had a rough & tumble assault plan by Rct Hawke, slow down was so bad I practically got hng up on the door. When I got to the stairs it was so damn slow it felt like I was wearing lead army boots. By the time I did get up top of the stairs in what felt like minutes later, I was shot, limping, still in high FPS rates all through it, and hadn’t seen a flib’n tango along the way that could’ve hit me. piece of crap…. I guess I should move Americas Army up on the test list since it’s the only other Unreal Engine game I own, who knows maybe it could effect all Unreal 2.x games : I don’t own any of the UT games to test either.

Now that would suck… if every Unreal Engine game was utter crap on this piece of crap card.

*sigh* why do I even fscking bother…

Oh wait, I forgot I’m in this mess because the card I didn’t want in the first place but got stuck with went bad. And the card I had to get to replace it because I couldn’t get any other (thank you very much for no online shopping option!!!) doesn’t work well with the damn games I play.. I swear, if I ever get the cash for a Personal Computer again.. I’m building it my self and ain’t listening to no whining ass family when it comes to how to spend the money !!

Hell, I’ve been accustomed to a weekly income of $0 my entire life and having to make the absolute most of what I do spend. And I know more about computers then any one in this burg I’ve met that ain’t paid to know more then I do. Let along being capable of assembling my own workstation and buying the parts wisely enough. My desktop has been $1600 + $80 and now + $100 worth of hell and countless headaches over the past two years. And I could build a better system for $1200 ffs !!! Thi sis what happens when you compromise on your freedom.

You become the (en)slave(d).

days recap

It’s been a bit of a busy night, took a little time to work on the NPM_PortConfig class but I’m still not really happy with it. The main thing that concerns me at the moment is dealing with saved config’s. Namely how to handle a situation where the Makefile has more options in it then the saved options from last time the system was built. Because other then that, it is really just as simple as check for a saved config,parse it if found and the makefile if not then and move on..

Also been playing around with the ol’C++ tonight. So farI’ve been reminded of why I hate C++ and why I love Qt and the GNU Compiler Collection at the same time lol. It does feel kind of weird to be working on some thing in C++ again, it was my first language but I have not used it in ages.. used C yeah sure but not C++ :

Lead some Planning & Leading training on TG#1 today. I was a little disapointed that Chester was the only one that showed up… But I think it whent quite good. Chester continues to show he’s worth our time in training. And the best part, we got to sneak past a ton of tango’s right under their noses hehe xD

Still early here, 0320R (local) but it’s hard to keep my mind on the code…

*sighs* women… lol.

Proof of Concept: Randomize a list

Well, the idea was essentially that RvS allows up to 30~32 maps or so all stored as a pair of assicated arrays loaded from the servers configuration file. One array that holds the game types (e.g. tango hunt, hostage rescue, misson et. al.) and the other the actual maps to load, i.e. GameType[0]=first maps gametype and Maps[0]=first map to load.

I took a moment the other day (before my gfx card went fuzzy) to write a small program that would generate a new configuration file with a maplist specified from another file, the prototype works fine but I didn’t know how I could archive my real goal: randomly populate the maplist from that file.

Here is a proof-of-concept algorithm that takes a list of items and returns a new list containing the same values but sorted into a ‘random’ order.


#!/usr/bin/env python

import random

def unsort(list, index):
    "return a copy of list reordered randomly"

    new_list = []
    table = []

    while len(new_list) != index:
        r = random.randint(0, index)
        try:
            if r not in table:
                table.append(r)
                new_list.append(list[r])
            else:
                continue
        except IndexError:
            pass
    return new_list

if __name__ == "__main__":
    li = [1,2,3,4,5]
    print unsort(li, len(li))

This took me about 10 minutes of thinking at work today and about 12 or 14 hours later I’ve made a test script in Python since that is the language I’ve been using for stuff latly. Basically the problem is the only way to randomly map items from one list into another is if you access elements in the list at random. But if you access a list at a random index and push it into a new list you can get duplicates. So a table (list) is used to store random numbers we have already generated. If the current number is not referenced in the table we can assume that we have not copied the element at that index in the list into the new list, if it does exist we need to try again. One bad thing is the algorithm is designed to run until completion, which can take an arbitrary amount of time to ‘unsort’ any given set. In theory, it could loop forever! However it would be trivial to modify it to abort the randomization process after a given time frame (such as >N iterations or seconds, which ever comes first) and just append remaining elements onto the end of the new list.

Here is a few test runs:

Terry@Dixie$ ./unsort.py
[3, 5, 4, 1, 2]
Terry@Dixie$ ./unsort.py
[3, 5, 2, 1, 4]
Terry@Dixie$ ./unsort.py
[4, 1, 2, 3, 5]
Terry@Dixie$ ./unsort.py
[5, 4, 1, 2, 3]
Terry@Dixie$ ./unsort.py
[5, 2, 4, 1, 3]
Terry@Dixie$ ./unsort.py
[3, 2, 1, 4, 5]
Terry@Dixie$ ./unsort.py
[4, 5, 3, 2, 1]
Terry@Dixie$

Odds are the PRNG is being seeded with the system time by default or making use of /dev/random on my FreeBSD laptop and that is good enough for me. And these results are random enough for me because I dunno how to write first class pseudo random number generators hehe.

RIP nVidia GeForce 6200, PoS@256mb

Well, to make a long story shorter..

Whent to join TG#1 to kill some stress but it was full, supper was soon so I switched to TG#3 instead and went to join Duke for a round.

Before the round started I had to getup and do some thing and ma moved my chair out so she could get to the printer so I had to wait. By the time I got to sit back down my computer had already had the monitor blip and the PC restart — from running SWAT4:TSS to showing the BIOS start screen… if there was any error message before that I didn’t get a chance to see it.

On each restart that followed the monitor was all funky and kept blipping on and off as if the signal wasn’t working.

Instantly my brains thinking monitor, monitor cable, graphics card, fans, and motherboard for possible problems. Hooked up the monitor I got from the Library for a few bucks, same effect. Opened the case, blew the crap out of it with a can of air. Yanked all of the PCI family cards out, Audigy 4, TV Tuner, GeForce 6200 e.t.c and gave them a go. Cut my finger trying to get the graphics card out of it’s PCI-Ex16 slot, freaking plastic lever was to buried to see which way it angled.

Unscrewed the main (looked 90mm) fan from the case but the power connector was to short to pull it clean for cleaning… Couldn’t get that unplugged so I pulled out the (E)IDE cable connecting the DVD-ROM’s and one of the 512MB RAM DIMMs and still couldn’t get the flib’n thing out.. So I ended up cleaning it with a paper towel half over the PSU, half over the mother board : Needless to say I didn’t even want to mess with the issue of getting to the CPU.

Managed to get that screwed back in and then I had to pull the main power off the motherboard to get the RAM slot back in (the slots are right under the worst tangle of power cabling!). The inside of the PC was dusty but not that bad, most of it was just on the fan blades and the front side vents (veeerrrryyyy bad) but still cleaner then Ma’s Dell and that things been running forever without a cleaning, like once in 7+ years.

Booted her back up and still no luck although the main fan was running a heck of a lot better the temp was still normalD. I noticed though that my motherboard had a port for a monitor on it with a cover. I remember there was a note taped on it when I first set up the computer < 2 years ago.
Interestingly while the monitor was displaying screwy when plugged intot he Geforce 6200, maybe even some kind of pixel array during the computers startup. It was perfectly fine when in the BIOS setup, maybe because it would have to be used at a really low level dunno. Set the BIOS Video configuration from AUTO to Integrated, restarted and changed ports.

Using the onboard 128MB Intel GMA it works… RVS works fine to but RvS will work with just about any thing made after the stone age if it supports the right features.. With how over-optimized RvS is you could probably run it on a Cuisinart without trouble : SWAT4:TSS on the other hand is quite sensitive to ATI/nVidia drivers and essentially resulted in an impossible to kill application.

All of the other computers here use AGP so Ic an’t even test the card or a different card in the slot, so I hope it’s the GeForce 6200 and not part of the Motherboard..

So it looks like I have to either give up on S4 or buy a new Gfx card.. I know I’ve often thought about upgrading if finances allowed but this does not make me happy. Data failure is cheap, use backups but when the hardware goes nuts what do you do?

Upgrade to GeForce 8400GS and it’s fixed… Guess it was the GeForce 6200 going bad :

randomly sorting lists

Was hashing out a very quick program to take a list of maps from a file and to replace the ones in the config file with those but sorted into a fairly random pattern.

Then I realized that I have no bloody idea how to randomly sort, ehh unsort a list of strings.

My notes scribbled in file:

##################################################
# Randomize the contents of a list -- algorithmic ideas
#
# input; list of N items to be randomized
# storage: table T to hold previously generated random numbers
#
# loop until done where each item in list is sorted into new list
# generate random number R between 0 and N
# store N in a table T if not already done so then
# if N is not in table T
# new list[R] = current item in loop
# else if N is in table continue to next iteration
#
# List will probably have to be a temporary to be generated from input list
#
# result expected: loop once per each item in the input list creating
#

That is the best I can think of when you consider the number of distractions:

birds screeching
mother shouting (at me, dog, and bird)
dozen pans falling
going AFK every X minutes
walking out in the cold to check the car cover
sorting pans back onto shelf
et alii

Is it a wonder I *usually* don’t touch an ounce of code until I am THE ONLY MORON AWAKE in this house ? I think not !

rf.c revisited

Got bored, so I revisited an old program I wrote like last year. One of the very first ones I set out to write in C in fact. I admit there is no practical need for this program haha. The only reason I wrote it is that I found it some one annoying that the cat program was made to concatenate files and print them to stdout. But is all so often just used to print out a lone file when less -F does the same thing. For the fun of it I basically added the ability to mimic the head and tail commands with an implicit number of lines to print (e.g. like head -n / tail -n ) while still keeping to the basic function of outputing a lone file, later I made it handle multiple files just for fun.

I was remembering today the sfalloc() macro I had defined early on. Some thing like

#define sfalloc( _type, _ptr ) 
(_type *)malloc( sizeof(_ptr) )

The main point of it was to ensure I wrote sizeof(foo) instead of sizeof(int) or some thing. And to get it to compile with a C++ compiler. I was thinking about making a new version of it for one of my header files that would use the cast only if __cplusplus was defined or better yet the new operator instead for use in code I would want to be compatible with both C and C++ but why bother for such a small program? Althouhg it would be a good spot to test it out in if I did hehe. Besides MSVC++ is a pain in the ass any way for compiling C99 code (imho).

My favorite non standard extensions to the C standard library on BSD and GNU systems is deffo err(), errx(), warn(), warnx(), and related routines in err.h namely because they are major time savers imho. Since a unix like system is assumed unistd is included and getopt(3) used for parsing argv rather then doing it manually.

I didn’t use the various linked list macros provided by BSD boxes because I wanted to avoid them, in case I ever decided to build the app on Windows or DOS. It also was the first time I ever used a linked list in a C program so I wanted to give it a go hehe. I’m really glad I did to because it was a really good excuse to learn how to use the GNU Debugger at the time 😉

One of the changes I made today was ensuring it would compile fine without assuming a C99 environment, I also ran it by gcc42 with -std=c89 -ansi and -pedantic-errors in the hopes of catching any thing I might’ve visually missed.

the ‘final’ version of the old program

/*-
* Copyright (C) 2007
* [my name ]. All rights reserved.
*
* permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


#if __STDC_VERSION__ >= 199901L
/* inline functions were added in C99 */
#else
#define inline /* protect me */
#endif

#define MALLOC_FAILED "Unable to initialize memory at __LINE__ n"

/* magic number for debugging read_bottom() and clean_up() */
#define NOMEM ((struct lnpos *)0xDEADBEEF)

#include <err.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/* For storing end of line characters */
typedef struct lnpos {
long eol;
struct lnpos *next;
struct lnpos *prev;
} LNPOS;


static inline FILE *open_file( char * );
static inline void read_all( FILE *, int );
static void read_top( FILE *, int );
static void read_bottom( FILE *, int );
static inline void clean_up( LNPOS * );
static inline void be_verbose( char * );
static inline void usage( void );


static const char *this_progname;


/*
* rf - read file to standard out v2.0 -- see changes.log for details
*/
int
main( int argc, char *argv[] ) {

char *errp;
int b_flag = 0, s_flag = 0, t_flag = 0, v_flag = 0;
int ch, f, lncnt = 0;
FILE *fp;


setlocale( LC_ALL, "" );
this_progname = argv[0];

while ( (ch = getopt( argc, argv, "b:st:v" )) != -1 ) {
switch ( ch ) {
case 'b':
/* Mimic tail(1) -n */
b_flag++;
lncnt = strtol( optarg, &errp, 10 );
if ( *errp || lncnt <= 0 ) {
errx( EXIT_FAILURE,
"Improper line count -- %sn", optarg );
}
break;
case 's':
/* Suppress -v when given multiple files. */
s_flag++;
v_flag = 0;
break;
case 't':
/* Mimic head(1) -n */
t_flag++;
lncnt = strtol( optarg, &errp, 10 );
if ( *errp || lncnt <= 0 ) {
errx( EXIT_FAILURE,
"Improper line count -- %sn", optarg );
}
break;
case 'v':
/* Append file names -- be_verbose() */
v_flag++;
break;
case '?':
default:
usage();
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;

if ( argc < 1 ) {
usage();
}

/* Handle multiple files */
for ( f = 0; f < argc; f++ ) {
fp = open_file( argv[f] );

if ( (!t_flag) && (!b_flag) ) {
read_all( fp, lncnt );
} else if ( t_flag ) {
read_top( fp, lncnt );
} else if ( b_flag ) {
read_bottom( fp, lncnt );
} else {
usage();
/* NOTREACHED */
}

if ( (v_flag != 0) || (argc > 1) ) {
/* Don't suppress if not set */
if ( s_flag == 0 ) {
be_verbose( argv[f] );
v_flag++;
} else {
v_flag = 0;
}
}

fclose( fp );
}

return EXIT_SUCCESS;
}


/* Simple fopen wrapper to keep the if...else if...else blockage from getting
* ugly. Since doing other wise would defeat the purpose of it in this program.
* open_file() halts the program if fopen failed.
*/
static inline FILE *
open_file( char *arg ) {

FILE *fto;

fto = fopen( arg, "r" );
if ( fto == NULL ) {
errx( EXIT_FAILURE, "File can not be opened or"
" does not exist -- %sn", arg );
}

return fto;
}


/*
* print out an open file to standard output
*/
static inline void
read_all( FILE *fp, int lncnt ) {

while ( (lncnt = fgetc( fp )) != EOF ) {
printf( "%c", lncnt );
}
}

/*
* Read n lines from the top of the file.
*/
static void
read_top( FILE *fp, int lncnt ) {

int c = 0;
int f = 0;

while ( (c < lncnt) && (f != EOF ) ) {
f = fgetc( fp );
printf( "%c", f );
if ( f == 'n') {
c++;
}
}
}


/*
* Read n lines from the bottom of the file
*/
static void
read_bottom( FILE *fp, int lncnt ) {

int fin = 0, i;
long int eolnum = 0;
long int where;
struct lnpos *cur = NULL;
struct lnpos *root = NULL;
struct lnpos *last = NULL;

/* initiate the linked list */

root = malloc( sizeof(root) );
root->eol=0;
if ( root == NULL ) {
err( EXIT_FAILURE, MALLOC_FAILED );
}
root->next = NOMEM;
root->prev = NOMEM;
cur = root;

cur->next = malloc( sizeof(cur->next) );
cur->next->eol = 0;
if ( cur->next == NULL ) {
err( EXIT_FAILURE, MALLOC_FAILED );
}
cur->next->prev = cur;
cur->next->next = NOMEM;
cur = cur->next;


/*
* read the file, count every end of line and store them in a new
* member of our linked list.
*/
while ( (fin = fgetc( fp )) != EOF ) {
if ( fin == 'n' ) {
eolnum++;
cur->eol = ftell( fp );
cur->next = malloc( sizeof(cur->next) );
cur->next->eol = 0;
if ( cur->next == NULL ) {
err( EXIT_FAILURE, MALLOC_FAILED );
}
cur->next->prev = cur;
cur->next->next = NOMEM;
cur = cur->next;
}
}

/* double check last nodes prev is up to date before marking the end */

cur->next = malloc( sizeof(cur->next) );
cur->next->eol = 0;
if ( cur->next == NULL ) {
err( EXIT_FAILURE, MALLOC_FAILED );
}
cur->next->prev = cur;
cur->next->next = NOMEM;
cur = cur->next;
last = cur;

/* print out the rest of file from the given offset. */
for ( i = 0; i < lncnt; ) {
if ( cur->prev != NOMEM ) {
if ( cur->eol ) {
i++;
}
cur = cur->prev;
}
}


where = fseek( fp, cur->eol, SEEK_SET );
if ( where != 0 ) {
err( EXIT_FAILURE, "Could not seek through the filen" );
}
read_all( fp, lncnt );
clean_up( root );

}

static inline void
clean_up( LNPOS *root ) {

/* Free linked lists memory */
struct lnpos *cur = root;
while ( cur->next != NOMEM ) {
cur = cur->next;
if ( cur->prev != NOMEM ) {
free( cur->prev );
cur->prev = NOMEM;
}
}
free( cur ); /* free the end node */
}

static inline void
be_verbose( char *fname ) {

printf( "n==> %s <==n", fname );
}

static inline void
usage( void ) {

fprintf( stderr, "usage: %s [-t count | -b count] "
"[-v] [file ...]n", this_progname );
exit( EXIT_FAILURE );
}

The simple makefile compiles it:

gcc -Wall -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion
-Waggregate-return -Wstrict-prototypes -Wmissing-prototypes
-Wmissing-declarations -Wredundant-decls -Winline -Wnested-externs
-std=c99 -march=i686

and Makefile.optimize adds the -fforce-mem -fforce-addr -finline-functions -fstrength-reduce -floop-optimize -O3 options for when testing is done, program works fine. FreeBSD’s lint implementation also doesn’t spew any serious messages.

GCC42

I was installing a program last night on my laptop that needed several GNUStep stuff, so I found out the hardway that it needed GCC v4.2.x’s Objective C compiler…

It took maybe 3 1/2 to 4++ hours to build lang/gcc42 but I suppose it’s a good thing. I always wanted to give it a test drive and it seems to have included the Fortran and Java (gcj) compilers with it.

The only good things I can say is one of my C programs built fine with the C Compiler (/usr/local/bin/gcc42) and I got to thumb through the source code in /usr/ports/lang/work/gcc-*/ while I waited. The parts I saw were quite well documented to and a pleasure to read.

One nice thing I suppose, a successful build of a compiler collection is probably a good stress-test for my laptops hardware :

Never trust the cable guy

I can understand wanting to get done in a hurry especially in the morning as much as the next worker but come on man.

Finally found reason to fire up the ol’VCR tonight after we had the cable set up in here like last week.

The mook only unplugged my cable from the VCR<->TV connection and put in the one from the setup box. Without even being so kind as to route the cabling properly so all systems would work.

Geeze, I ain’t no Telecom Engineer or nothing but I know how to hook up a bloody TV system with cable and video systems !!!