add clang-format config and format everything

This commit is contained in:
Stefan Bühler 2021-09-15 19:20:06 +02:00
parent 187ec1a68e
commit 56458af5fc
20 changed files with 2193 additions and 2183 deletions

29
.clang-format Normal file
View File

@ -0,0 +1,29 @@
---
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 160
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 0
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PointerAlignment: Left
SpaceAfterCStyleCast: true
Standard: Cpp11
UseTab: Always
...

View File

@ -2,12 +2,12 @@
#include "announce.h"
#include "network.h"
#include <time.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <avahi-client/client.h>
#include <avahi-client/lookup.h>
@ -50,8 +50,7 @@ static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
case AVAHI_ENTRY_GROUP_ESTABLISHED:
break;
case AVAHI_ENTRY_GROUP_COLLISION :
{
case AVAHI_ENTRY_GROUP_COLLISION: {
char* n = avahi_alternative_service_name(name);
avahi_free(name);
name = n;
@ -90,8 +89,7 @@ again:
snprintf(buf_version, sizeof(buf_version), "version=%X", (unsigned int) version);
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, SERVICE_TYPE, NULL, NULL, port, buf_version, NULL)) < 0) {
if (ret == AVAHI_ERR_COLLISION)
goto collision;
if (ret == AVAHI_ERR_COLLISION) goto collision;
fprintf(stderr, "Failed to add " SERVICE_TYPE ": %s\n", avahi_strerror(ret));
goto fail;
@ -105,8 +103,7 @@ again:
return;
collision:
{
collision : {
char* n = avahi_alternative_service_name(name);
avahi_free(name);
name = n;
@ -132,9 +129,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void * userd
break;
case AVAHI_CLIENT_S_COLLISION:
case AVAHI_CLIENT_S_REGISTERING:
if (group) {
avahi_entry_group_reset(group);
}
if (group) { avahi_entry_group_reset(group); }
break;
case AVAHI_CLIENT_CONNECTING:
break;
@ -180,9 +175,20 @@ static void remove_game_with_name(const char *name) {
}
}
static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event,
const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address,
uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void* userdata) {
static void resolve_callback(
AvahiServiceResolver* r,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiResolverEvent event,
const char* name,
const char* type,
const char* domain,
const char* host_name,
const AvahiAddress* address,
uint16_t port,
AvahiStringList* txt,
AvahiLookupResultFlags flags,
void* userdata) {
int i;
uint32_t want_version;
(void) interface;
@ -201,7 +207,13 @@ static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, Av
switch (event) {
case AVAHI_RESOLVER_FAILURE:
fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
fprintf(
stderr,
"(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n",
name,
type,
domain,
avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))));
break;
case AVAHI_RESOLVER_FOUND: {
@ -233,8 +245,16 @@ done:
avahi_service_resolver_free(r);
}
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event,
const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) {
static void browse_callback(
AvahiServiceBrowser* b,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiBrowserEvent event,
const char* name,
const char* type,
const char* domain,
AvahiLookupResultFlags flags,
void* userdata) {
(void) flags;
assert(b);

View File

@ -1,24 +1,24 @@
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <signal.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include "bomber.h"
#include "gfx.h"
#include "announce.h"
#include "sound.h"
#include "menu.h"
#include "utils.h"
#include "network.h"
#include "game.h"
#include "bomber.h"
#include "draw.h"
#include "game.h"
#include "gfx.h"
#include "menu.h"
#include "network.h"
#include "sound.h"
#include "utils.h"
int main(void) {
char* p;

View File

@ -1,7 +1,8 @@
#ifndef BOMBER_H
#define BOMBER_H
#include "SDL.h"
#include "list.h"
#include <SDL.h>
typedef unsigned char uchar;
extern int xcolors[256];
@ -54,11 +55,6 @@ typedef struct solid {
uchar* graphics;
} solid;
typedef struct listhead listhead;
struct listhead {
listhead *prev, *next;
};
typedef struct player {
listhead list, list_all_players;
int xpos, ypos;
@ -200,7 +196,6 @@ enum tile_types {
#define CODE_ALLDEAD 2
#define MAXTHINGS 500
#define MAXSETS 8
#define MAXSPRITES 256

View File

@ -1,15 +1,15 @@
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <signal.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include "bomber.h"
#include "draw.h"
@ -103,13 +103,24 @@ static int dopcxreal(char *name,gfxset *gs) {
char tname2[260];
snprintf(tname2, sizeof(tname2), "%s.pcx", tname);
ihand = open(tname2, O_RDONLY);
if(ihand<0)
return 1;
if (ihand < 0) return 1;
}
if(myci()!=10) {close(ihand);return 2;} // 10=zsoft .pcx
if(myci()!=5) {close(ihand);return 3;} // version 3.0
if(myci()!=1) {close(ihand);return 4;} //encoding method
if(myci()!=8) {close(ihand);return 5;} //bpp
if (myci() != 10) {
close(ihand);
return 2;
} // 10=zsoft .pcx
if (myci() != 5) {
close(ihand);
return 3;
} // version 3.0
if (myci() != 1) {
close(ihand);
return 4;
} // encoding method
if (myci() != 8) {
close(ihand);
return 5;
} // bpp
xs = myci();
xs |= myci() << 8;
ys = myci();
@ -122,7 +133,10 @@ static int dopcxreal(char *name,gfxset *gs) {
height = height + 1 - ys;
for (i = 0; i < 48 + 4; ++i) myci();
myci();
if(myci()!=1) {close(ihand);return 6;} // # of planes
if (myci() != 1) {
close(ihand);
return 6;
} // # of planes
byteswide = myci();
byteswide |= myci() << 8;
i = myci();
@ -131,7 +145,10 @@ static int dopcxreal(char *name,gfxset *gs) {
for (i = 0; i < 58; ++i) myci();
totalsize = height * byteswide;
bm = malloc(totalsize + 1);
if(!bm) {close(ihand);return 8;} // no memory
if (!bm) {
close(ihand);
return 8;
} // no memory
gs->gs_pic = bm;
gs->gs_xsize = width;
gs->gs_ysize = height;
@ -164,8 +181,7 @@ static int dopcx(char *name,gfxset *gs) {
int err;
err = dopcxreal(name, gs);
if(err)
printf("Error loading \"%s\":code %d\n",name,err);
if (err) printf("Error loading \"%s\":code %d\n", name, err);
return err;
}
@ -179,8 +195,7 @@ static void getgroup(char *name,gfxset *colorgs,figure *fig,int count) {
createinout(&gs);
for (i = 0; i < MAXSETS; ++i, fig += count, ++colorgs) {
if (!colorgs->gs_pic) continue;
memmove(gs.gs_colormap,colorgs->gs_colormap,
sizeof(gs.gs_colormap));
memmove(gs.gs_colormap, colorgs->gs_colormap, sizeof(gs.gs_colormap));
createinout(&gs);
gfxfetch(&gs, fig, count);
}
@ -309,9 +324,7 @@ void erasesprites(void) {
for (i = 0; i < spritesused; ++i) {
fig = sp->fig;
solidcopy(&background,
sp->xpos+fig->xdelta,sp->ypos+fig->ydelta,
fig->xsize,fig->ysize);
solidcopy(&background, sp->xpos + fig->xdelta, sp->ypos + fig->ydelta, fig->xsize, fig->ysize);
++sp;
}
}
@ -325,8 +338,7 @@ void clearsprites(void) {
for (i = 0; i < spritesused; ++i) {
fig = sp->fig;
clearrect(sp->xpos+fig->xdelta,sp->ypos+fig->ydelta,
fig->xsize,fig->ysize);
clearrect(sp->xpos + fig->xdelta, sp->ypos + fig->ydelta, fig->xsize, fig->ysize);
++sp;
}
}
@ -373,12 +385,12 @@ static void loadfonts(void) {
bigfontysize = 24;
bigfontyspace = 32;
p = remapstring;
j=0;while(*p && *p!=' ') ++p,++j;
j = 0;
while (*p && *p != ' ') ++p, ++j;
memset(asciiremap, j, sizeof(asciiremap));
p = remapstring;
i = 0;
while(*p && i<NUMCHARACTERS)
asciiremap[(int)*p++]=i++;
while (*p && i < NUMCHARACTERS) asciiremap[(int) *p++] = i++;
}
void loadgfx() {
@ -402,8 +414,7 @@ void loadgfx() {
strcpy(bigfontname, "bigfont");
gs = malloc((MAXSETS + 1) * sizeof(gfxset));
if(!gs)
nomem("loadgfx");
if (!gs) nomem("loadgfx");
colorgs = gs + 1;
for (i = 0; i < MAXSETS; ++i) {
@ -441,8 +452,7 @@ void loadgfx() {
bigscrprintf("Loading death sequence\n");
getsingle(deathname, death, NUMDEATHFRAMES);
for(i=0;i<MAXSETS;++i)
freegfxset(colorgs+i);
for (i = 0; i < MAXSETS; ++i) freegfxset(colorgs + i);
free(gs);
bigscrprintf("Done loading graphics\n");
}

View File

@ -37,6 +37,7 @@ extern int arraynumx, arraynumy, arraystartx, arraystarty, arrayspacex, arrayspa
#define NUMDEATHFRAMES 41
extern figure blocks[3], blocksx[9], bombs1[MAXSETS][NUMBOMBFRAMES], bombs2[MAXSETS][NUMBOMBFRAMES], flamefigs[MAXSETS][NUMFLAMEFRAMES], tiles[15], death[NUMDEATHFRAMES];
extern figure blocks[3], blocksx[9], bombs1[MAXSETS][NUMBOMBFRAMES], bombs2[MAXSETS][NUMBOMBFRAMES], flamefigs[MAXSETS][NUMFLAMEFRAMES], tiles[15],
death[NUMDEATHFRAMES];
#endif

View File

@ -1,13 +1,13 @@
#include "bomber.h"
#include "game.h"
#include "gfx.h"
#include "network.h"
#include "bomber.h"
#include "draw.h"
#include "utils.h"
#include "sound.h"
#include "menu.h"
#include "gfx.h"
#include "list.h"
#include "menu.h"
#include "network.h"
#include "sound.h"
#include "utils.h"
static int gameframe;
@ -35,27 +35,13 @@ char playername[16];
static int mycount;
static int bonustotal;
static const int bonuschances[]= {
TILE_BOMB,20,
TILE_FLAME,20,
TILE_TRIGGER,2,
TILE_GOLDFLAME,2,
TILE_SKATES,20,
TILE_TURTLE,5,
TILE_NONE,160
};
static const int bonuschances[] = {TILE_BOMB, 20, TILE_FLAME, 20, TILE_TRIGGER, 2, TILE_GOLDFLAME, 2, TILE_SKATES, 20, TILE_TURTLE, 5, TILE_NONE, 160};
static GameOptions gameoptions;
static const unsigned char playerpositions[MAXNETNODES*3] = { /* color, x, y */
2,0,0,
3,14,10,
4,14,0,
5,0,10,
1,6,0,
6,8,10,
7,0,6,
8,14,4,
static const unsigned char playerpositions[MAXNETNODES * 3] = {
/* color, x, y */
2, 0, 0, 3, 14, 10, 4, 14, 0, 5, 0, 10, 1, 6, 0, 6, 8, 10, 7, 0, 6, 8, 14, 4,
};
static void resetplayer(player* pl, int color, int x, int y) {
@ -82,8 +68,7 @@ static void initplayer(int color,int x,int y,int controller) {
player* pl;
pl = allocentry(player);
if(!pl)
nomem("Couldn't get player structure (allocentry())");
if (!pl) nomem("Couldn't get player structure (allocentry())");
list_add_tail(&allplayers, &pl->list_all_players);
@ -153,8 +138,7 @@ static void initgame() {
const int* p;
int comp;
if (network != NETWORK_SLAVE)
set_game_options(&configopts);
if (network != NETWORK_SLAVE) set_game_options(&configopts);
gameframe = 0;
things_list_clear(&activebombs);
@ -180,8 +164,7 @@ static void initgame() {
/* if((i&j)&1) {
field[j][i]=FIELD_BORDER;
} else*/
field[j][i]=
(myrand()&3)>=comp ? FIELD_BRICK : FIELD_EMPTY;
field[j][i] = (myrand() & 3) >= comp ? FIELD_BRICK : FIELD_EMPTY;
}
solidcopyany(&backgroundoriginal, &background, 0, 0, IXSIZE, IYSIZE);
@ -193,9 +176,12 @@ static void initgame() {
for (i = 0; i < arraynumx; ++i) {
x = arraystartx + i * arrayspacex;
bl = field[j][i];
if(bl==FIELD_BORDER) bl=2;
else if(bl==FIELD_BRICK) bl=1;
else continue;
if (bl == FIELD_BORDER)
bl = 2;
else if (bl == FIELD_BRICK)
bl = 1;
else
continue;
drawfigureany(x, y, blocks + bl, &background);
}
}
@ -273,8 +259,7 @@ static void adddecay(int px,int py) {
addtail(&activedecays, bd);
xpos = tovideox(bd->xpos);
ypos = tovideoy(bd->ypos);
solidcopyany(&backgroundoriginal,&background,xpos,ypos,
arrayspacex,arrayspacey);
solidcopyany(&backgroundoriginal, &background, xpos, ypos, arrayspacex, arrayspacey);
solidcopy(&background, xpos, ypos, arrayspacex, arrayspacey);
}
@ -338,8 +323,7 @@ static void processbombs() {
++bmb->timer;
switch (bmb->type) {
case BOMB_NORMAL:
if (bmb->timer == BOMBLIFE)
adddetonate(bmb);
if (bmb->timer == BOMBLIFE) adddetonate(bmb);
break;
case BOMB_CONTROLLED:
if (bmb->timer == BOMB_CONTROLLED_LIFE) {
@ -487,8 +471,7 @@ static void drawdecays() {
brickdecay* bd;
list_for_each_entry(bd, &activedecays, list) {
addsprite(tovideox(bd->xpos),tovideoy(bd->ypos),
blocksx+(bd->timer*9)/DECAYLIFE);
addsprite(tovideox(bd->xpos), tovideoy(bd->ypos), blocksx + (bd->timer * 9) / DECAYLIFE);
}
}
@ -496,8 +479,7 @@ static void drawbonus() {
bonustile* bonus;
list_for_each_entry(bonus, &activebonus, list) {
addsprite(tovideox(bonus->xpos),tovideoy(bonus->ypos),
tiles+bonus->type);
addsprite(tovideox(bonus->xpos), tovideoy(bonus->ypos), tiles + bonus->type);
}
}
@ -507,8 +489,7 @@ static void drawplayers() {
list_for_each_entry(pl, &activeplayers, list) {
if (!(pl->flags & FLG_DEAD)) {
if(!pl->figure)
pl->figure=walking[pl->color]+30;
if (!pl->figure) pl->figure = walking[pl->color] + 30;
xpos = tovideox(pl->xpos) + pl->fixx;
ypos = tovideoy(pl->ypos) + pl->fixy;
addsprite(xpos, ypos, pl->figure);
@ -520,8 +501,7 @@ static void detonatecontrolled(player *pl) {
bomb *bmb, *next;
list_for_each_entry_safe(bmb, next, &activebombs, list) {
if(bmb->owner==pl && bmb->type==BOMB_CONTROLLED)
adddetonate(bmb);
if (bmb->owner == pl && bmb->type == BOMB_CONTROLLED) adddetonate(bmb);
}
}
@ -642,14 +622,12 @@ static int centerychange(player *pl) {
val = pl->ypos + (max << 2);
val %= max;
line = max >> 1;
if(val<line)
{
if (val < line) {
if (val - speed < 0)
return -val;
else
return -speed;
} else if(val>=line)
{
} else if (val >= line) {
if (val + speed > max)
return max - val;
else
@ -686,18 +664,14 @@ static void trymove(player *pl,int dx,int dy) {
return;
}
there = field[wy][wx];
if((px!=wx || py!=wy) &&
(there==FIELD_BRICK||there==FIELD_BOMB||there==FIELD_BORDER))
{
if ((px != wx || py != wy) && (there == FIELD_BRICK || there == FIELD_BOMB || there == FIELD_BORDER)) {
if (dx && !dy) {
ty = centerychange(pl);
if(ty && depth==1)
trymove(pl,0,-SGN(ty));
if (ty && depth == 1) trymove(pl, 0, -SGN(ty));
} else if (dy && !dx) {
tx = centerxchange(pl);
if(tx && depth==1)
trymove(pl,-SGN(tx),0);
if (tx && depth == 1) trymove(pl, -SGN(tx), 0);
}
} else {
@ -719,12 +693,10 @@ static void applybonus(player *pl,bonustile *bonus) {
deletebonus(bonus);
switch (type) {
case TILE_BOMB:
if (pl->bombsavailable < 9)
++(pl->bombsavailable);
if (pl->bombsavailable < 9) ++(pl->bombsavailable);
break;
case TILE_FLAME:
if(pl->flamelength<maxflame)
++(pl->flamelength);
if (pl->flamelength < maxflame) ++(pl->flamelength);
break;
case TILE_GOLDFLAME:
pl->flamelength = maxflame;
@ -793,12 +765,9 @@ static void doplayer(player *pl) {
// if(what&ACT_TURBO) speed<<=2;
if (what & ACT_PRIMARY) {
if(there==FIELD_EMPTY && pl->bombsavailable)
dropbomb(pl,px,py,
(flags&FLG_CONTROL) ? BOMB_CONTROLLED :BOMB_NORMAL);
if (there == FIELD_EMPTY && pl->bombsavailable) dropbomb(pl, px, py, (flags & FLG_CONTROL) ? BOMB_CONTROLLED : BOMB_NORMAL);
}
if(what&ACT_SECONDARY && (flags&FLG_CONTROL))
detonatecontrolled(pl);
if (what & ACT_SECONDARY && (flags & FLG_CONTROL)) detonatecontrolled(pl);
switch (what & ACT_MASK) {
case ACT_UP:
@ -846,8 +815,7 @@ static void processquits(void) {
if (network != NETWORK_SLAVE) return;
for (i = 0; i < MAXNETNODES; ++i) {
if (netnodes[i].used && actions[i]==ACT_QUIT)
netnodes[i].used=0;
if (netnodes[i].used && actions[i] == ACT_QUIT) netnodes[i].used = 0;
}
}
@ -855,17 +823,21 @@ static int getaction(void) {
int what;
what = ACT_NONE;
if(checkpressed(MYLEFT)) what=ACT_LEFT;
else if(checkpressed(MYRIGHT)) what=ACT_RIGHT;
else if(checkpressed(MYDOWN)) what=ACT_DOWN;
else if(checkpressed(MYUP)) what=ACT_UP;
else if(checkdown(13)) what=ACT_ENTER;
else if(checkdown(0x1b)) what=ACT_QUIT;
if (checkpressed(MYLEFT))
what = ACT_LEFT;
else if (checkpressed(MYRIGHT))
what = ACT_RIGHT;
else if (checkpressed(MYDOWN))
what = ACT_DOWN;
else if (checkpressed(MYUP))
what = ACT_UP;
else if (checkdown(13))
what = ACT_ENTER;
else if (checkdown(0x1b))
what = ACT_QUIT;
if(checkdown(' '))
what|=ACT_PRIMARY;
if(checkdown('b'))
what|=ACT_SECONDARY;
if (checkdown(' ')) what |= ACT_PRIMARY;
if (checkdown('b')) what |= ACT_SECONDARY;
return what;
}
@ -939,8 +911,7 @@ static int iterate(void) {
}
if (deadplayers > 0 && (!i || (NETWORK_NONE != network && i == 1))) {
++deathcount;
if(deathcount==25)
return CODE_ALLDEAD;
if (deathcount == 25) return CODE_ALLDEAD;
} else
deathcount = 0;
}

View File

@ -1,6 +1,8 @@
#ifndef GAME_H
#define GAME_H
#include "bomber.h"
#define FRACTION 9
#define SPEEDDELTA (1 << (FRACTION - 1))
#define SPEEDMAX (10 << FRACTION)

755
src/gfx.c

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
#include "bomber.h"
#include "list.h"
#include "bomber.h"
#include "utils.h"
typedef union genericlistitem genericlistitem;
@ -31,9 +31,7 @@ void alloc_things(void) {
}
if (!things) nomem("Trying to allocate thing memory");
for (i=0; i < MAXTHINGS - 1; ++i) {
things[i].next = &things[i + 1];
}
for (i = 0; i < MAXTHINGS - 1; ++i) { things[i].next = &things[i + 1]; }
things[i].next = 0;
free_things = things;
count_used = 0;

View File

@ -1,10 +1,16 @@
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
/* from linux kernel (with some changes for "iso" c) */
#define container_of(ptr, type, member) \
((type *)( (char *)(__typeof__( ((type *)0)->member ) *)(ptr) - offsetof(type,member)))
typedef struct listhead listhead;
struct listhead {
listhead *prev, *next;
};
#define container_of(ptr, type, member) ((type*) ((char*) (__typeof__(((type*) 0)->member)*) (ptr) -offsetof(type, member)))
/**
* list_entry - get the struct for this entry
@ -37,8 +43,7 @@ void things_list_clear(listhead *head); /* listhead member must be the first mem
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, __typeof__(*pos), member); \
/* prefetch(pos->member.next), */ \
for (pos = list_entry((head)->next, __typeof__(*pos), member); /* prefetch(pos->member.next), */ \
&pos->member != (head); \
pos = list_entry(pos->member.next, __typeof__(*pos), member))
@ -50,9 +55,7 @@ void things_list_clear(listhead *head); /* listhead member must be the first mem
* @member:>the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, __typeof__(*pos), member), \
n = list_entry(pos->member.next, __typeof__(*pos), member); \
&pos->member != (head); \
for (pos = list_entry((head)->next, __typeof__(*pos), member), n = list_entry(pos->member.next, __typeof__(*pos), member); &pos->member != (head); \
pos = n, n = list_entry(n->member.next, __typeof__(*n), member))
#define list_empty(head) ((head) == (head)->next)

View File

@ -1,17 +1,17 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/timeb.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <time.h>
#include <signal.h>
#include <fcntl.h>
#define MAXMSG 256
@ -35,8 +35,7 @@ char masterhostname[256];
#define MAXMATCHES 16
struct registration
{
struct registration {
uchar id;
uchar unique[4];
uchar password[4];
@ -44,15 +43,13 @@ struct registration
uchar name[16];
uchar status;
};
struct query
{
struct query {
uchar id;
uchar password[4];
uchar version[4];
};
struct gamehost
{
struct gamehost {
struct gamehost *next, *prev;
uchar machine[4];
uchar port[2];
@ -64,21 +61,18 @@ struct gamehost
struct gamehost *freehosts = 0, *activehosts = 0;
int udpsocket, myport;
struct sockaddr_in myname = {0}, mastername = {0};
socklen_t senderlength;
struct sockaddr_in sender = {0};
long longtime(void)
{
long longtime(void) {
struct timeb tb;
ftime(&tb);
return tb.time;
}
char *timestr()
{
char* timestr() {
static char timestring[80];
time_t t;
@ -91,16 +85,13 @@ int l;
}
int putmsg(struct sockaddr_in *toname,unsigned char *msg,int len)
{
int putmsg(struct sockaddr_in* toname, unsigned char* msg, int len) {
int status;
status=sendto(udpsocket,msg,len,0,
(struct sockaddr *)toname,sizeof(struct sockaddr_in));
status = sendto(udpsocket, msg, len, 0, (struct sockaddr*) toname, sizeof(struct sockaddr_in));
return status;
}
void ack()
{
void ack() {
uchar copy[256];
*copy = PKT_ACK;
@ -108,15 +99,13 @@ uchar copy[256];
putmsg(&sender, copy, lastsize + 1);
}
int getmsg(int seconds)
{
int getmsg(int seconds) {
int size;
lastsize = -1;
memset(&sender, 0, sizeof(sender));
senderlength = sizeof(sender);
if(seconds)
{
if (seconds) {
struct timeval timeout;
fd_set readfds;
int res;
@ -128,29 +117,24 @@ int size;
res = select(udpsocket + 1, &readfds, 0, 0, &timeout);
if (res <= 0) return -1;
}
lastsize=size=recvfrom(udpsocket,mesg,MAXMSG,0,
(struct sockaddr *)&sender,&senderlength);
lastsize = size = recvfrom(udpsocket, mesg, MAXMSG, 0, (struct sockaddr*) &sender, &senderlength);
return size;
}
long longind(unsigned char *p)
{
long longind(unsigned char* p) {
return (p[0] << 24L) | (p[1] << 16L) | (p[2] << 8) | p[3];
}
short shortind(unsigned char *p)
{
short shortind(unsigned char* p) {
return (p[0] << 8L) | p[1];
}
void openport(int portwant)
{
void openport(int portwant) {
int status;
myport = portwant;
udpsocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(udpsocket==-1)
{
if (udpsocket == -1) {
perror("socket()");
exit(1);
}
@ -160,8 +144,7 @@ int status;
myname.sin_port = htons(myport);
status = bind(udpsocket, (struct sockaddr*) &myname, sizeof(myname));
if(status==-1)
{
if (status == -1) {
perror("bind()");
exit(1);
}
@ -169,19 +152,16 @@ int status;
#define PERBLOCK 512
struct gamehost *newhost()
{
struct gamehost* newhost() {
struct gamehost *h, *block;
int i;
if(!freehosts)
{
if (!freehosts) {
block = malloc(sizeof(struct gamehost) * PERBLOCK);
if (!block) return 0;
freehosts = block;
i = PERBLOCK - 1;
while(i--)
{
while (i--) {
block->next = block + 1;
++block;
}
@ -193,72 +173,73 @@ int i;
return h;
}
void freehost(struct gamehost *h)
{
void freehost(struct gamehost* h) {
h->next = freehosts;
freehosts = h;
}
struct gamehost *findmatch(struct registration *key)
{
struct gamehost* findmatch(struct registration* key) {
struct gamehost* h;
h = activehosts;
while(h)
{
if(!memcmp(&h->reg,key,sizeof(struct registration)-1))
return h;
while (h) {
if (!memcmp(&h->reg, key, sizeof(struct registration) - 1)) return h;
h = h->next;
}
return 0;
}
void insert(struct gamehost *h)
{
if(activehosts)
{
void insert(struct gamehost* h) {
if (activehosts) {
h->next = activehosts;
h->prev = activehosts->prev;
activehosts->prev = h;
activehosts = h;
} else
{
} else {
h->next = h->prev = 0;
activehosts = h;
}
}
void delete(struct gamehost *h)
{
void delete (struct gamehost* h) {
if (h->prev)
h->prev->next = h->next;
else
activehosts = h->next;
if(h->next)
h->next->prev=h->prev;
if (h->next) h->next->prev = h->prev;
freehost(h);
}
void doreg()
{
void doreg() {
struct registration* new;
struct gamehost* match;
long now;
new = (struct registration*) mesg;
match = findmatch(new);
if(logging)
{
if (logging) {
unsigned addr = ntohl(sender.sin_addr.s_addr);
unsigned short port = ntohs(sender.sin_port);
printf("reg :%s:%d.%d.%d.%d:%d %c%lx '%s'\n",timestr(),
(addr>>24)&255,(addr>>16)&255,(addr>>8)&255,addr&255,port,
new->status ? '+' : '-',(long)match,new->name);
printf(
"reg :%s:%d.%d.%d.%d:%d %c%lx '%s'\n",
timestr(),
(addr >> 24) & 255,
(addr >> 16) & 255,
(addr >> 8) & 255,
addr & 255,
port,
new->status ? '+' : '-',
(long) match,
new->name);
fflush(stdout);
}
if(!match && !new->status) {ack();return;}
if(match && new->status) {ack();return;}
if(!match && new->status)
{
if (!match && !new->status) {
ack();
return;
}
if (match && new->status) {
ack();
return;
}
if (!match && new->status) {
match = newhost();
if (!match) return; // No memory, what can we do?
memmove(match->machine, &sender.sin_addr.s_addr, 4);
@ -277,20 +258,17 @@ long now;
}
}
void doquery()
{
void doquery() {
uchar* password;
uchar* version;
struct gamehost* h;
uchar response[2048], *rput, *countersave;
int counter;
if(logging)
{
if (logging) {
unsigned addr = ntohl(sender.sin_addr.s_addr);
unsigned short port = ntohs(sender.sin_port);
printf("query:%s:%d.%d.%d.%d:%d\n",timestr(),
(addr>>24)&255,(addr>>16)&255,(addr>>8)&255,addr&255,port);
printf("query:%s:%d.%d.%d.%d:%d\n", timestr(), (addr >> 24) & 255, (addr >> 16) & 255, (addr >> 8) & 255, addr & 255, port);
fflush(stdout);
}
password = mesg + 1;
@ -307,11 +285,8 @@ int counter;
*rput++ = 0;
counter = 0;
while(h)
{
if(!memcmp(password,h->reg.password,4) &&
!memcmp(version,h->reg.version,4) && counter<MAXMATCHES)
{
while (h) {
if (!memcmp(password, h->reg.password, 4) && !memcmp(version, h->reg.version, 4) && counter < MAXMATCHES) {
++counter;
memmove(rput, h->reg.unique, 4);
rput += 4;
@ -327,27 +302,20 @@ int counter;
*countersave++ = counter >> 8;
*countersave++ = counter;
putmsg(&sender, response, rput - response);
}
void purge(long cutoff)
{
void purge(long cutoff) {
struct gamehost *h, *h2;
h = activehosts;
while(h)
{
while (h) {
h2 = h;
h = h->next;
if(cutoff-h2->timeout>0)
{
delete(h2);
}
if (cutoff - h2->timeout > 0) { delete (h2); }
}
}
int main(int argc,char **argv)
{
int main(int argc, char** argv) {
int i;
int want;
int size;
@ -355,24 +323,21 @@ long purgetime;
long now;
want = PORT;
if(argc>1)
{
if (argc > 1) {
for (i = 1; i < argc; ++i)
if(!strncmp(argv[i],"-p",2))
{
if(strlen(argv[i])>2) want=atoi(argv[i]+2);
else if(i+1<argc) want=atoi(argv[i+1]);
if (!strncmp(argv[i], "-p", 2)) {
if (strlen(argv[i]) > 2)
want = atoi(argv[i] + 2);
else if (i + 1 < argc)
want = atoi(argv[i + 1]);
}
}
freehosts = 0;
openport(want);
purgetime = longtime() + TIMETOLIVE;
for(;;)
{
for (;;) {
size = getmsg(10);
if(size>=1)
switch(*mesg)
{
if (size >= 1) switch (*mesg) {
case PKT_REGISTER:
if (size < sizeof(struct registration)) continue;
doreg();

View File

@ -1,24 +1,19 @@
#include "bomber.h"
#include "menu.h"
#include "draw.h"
#include "gfx.h"
#include "utils.h"
#include "sound.h"
#include "network.h"
#include "announce.h"
#include "bomber.h"
#include "draw.h"
#include "game.h"
#include "gfx.h"
#include "network.h"
#include "sound.h"
#include "utils.h"
GameOptions configopts = {2, 1, 0, 2};
/* Generic menu */
typedef enum {
MENU_ANY = -1,
MENU_MAIN = 0,
MENU_CONFIG = 2,
MENU_JOIN = 3
} menuname;
typedef enum { MENU_ANY = -1, MENU_MAIN = 0, MENU_CONFIG = 2, MENU_JOIN = 3 } menuname;
#define MENU_SELECT(x) ((menuname)(-x - 1))
@ -36,12 +31,10 @@ static void drawmenu(int selected) {
j = strlen(menutitle) * bigfontxsize;
drawbigstring((IXSIZE - j) >> 1, 20, menutitle);
ty = ((IYSIZE - (bigfontysize * menunum)) >> 1) - (IYSIZE >> 3);
for(i=0;i<menunum;++i)
{
for (i = 0; i < menunum; ++i) {
j = strlen(menuitems[i]) * bigfontxsize;
tx = (IXSIZE - j) >> 1;
if(i==selected)
{
if (i == selected) {
greyrect(0, ty - 1, tx - 5, bigfontysize);
greyrect(tx + j + 3, ty - 1, IXSIZE - (tx + j + 3), bigfontysize);
}
@ -93,18 +86,18 @@ static int domenu(menuname whichmenu, int (*pause)(void)) {
return selected;
case 'k':
case MYUP:
if (selected) --selected;
else selected=menunum-1;
if (whichmenu>=0)
menuhistory[whichmenu]=selected;
if (selected)
--selected;
else
selected = menunum - 1;
if (whichmenu >= 0) menuhistory[whichmenu] = selected;
redraw = 1;
break;
case 'j':
case MYDOWN:
++selected;
if (selected == menunum) selected = 0;
if (whichmenu>=0)
menuhistory[whichmenu]=selected;
if (whichmenu >= 0) menuhistory[whichmenu] = selected;
redraw = 1;
break;
case 0x1b:
@ -296,9 +289,7 @@ static void drawjoinscreen(void) {
static int tryjoin(int which) {
int res;
if (0 == (res = send_join(&gamelistentries[which].netname, playername))) {
return 0;
}
if (0 == (res = send_join(&gamelistentries[which].netname, playername))) { return 0; }
while (!exitflag) {
switch (res) {
@ -309,8 +300,10 @@ static int tryjoin(int which) {
drawjoinscreen();
copyup();
break;
case 3: return 1;
default: break;
case 3:
return 1;
default:
break;
}
scaninput();
while (anydown()) {
@ -335,9 +328,7 @@ static void join_game(void) {
int i;
int sel = -1;
if (!searchgames()) {
return;
}
if (!searchgames()) { return; }
menuhistory[MENU_JOIN] = 0;
@ -348,9 +339,7 @@ static void join_game(void) {
addexit("EXIT");
} else {
additem("JOIN NETWORK GAME");
for (i = 0; i < gamelistsize; i++) {
additem(gamelistentries[i].name);
}
for (i = 0; i < gamelistsize; i++) { additem(gamelistentries[i].name); }
addexit("EXIT");
}
sel = domenu(MENU_JOIN, join_game_pause);
@ -358,12 +347,8 @@ static void join_game(void) {
}
stop_search();
if(menuexit == sel || !gamelistsize) {
return;
}
if(!tryjoin(sel)) {
return;
}
if (menuexit == sel || !gamelistsize) { return; }
if (!tryjoin(sel)) { return; }
run_network_game();
}

View File

@ -1,11 +1,11 @@
#include "bomber.h"
#include "network.h"
#include "announce.h"
#include "bomber.h"
#include "draw.h"
#include "game.h"
#include "menu.h"
#include "network.h"
#include "utils.h"
#include "draw.h"
#define MAXMSG 4096
@ -65,10 +65,7 @@ enum reject_reason {
#define _REJECT_LAST REJECT_VERSION
const char *reject_reason_str[] = {
"Server full",
"Version mismatch"
};
const char* reject_reason_str[] = {"Server full", "Version mismatch"};
/* all bytes stored MSB first */
@ -143,8 +140,7 @@ outmsgs() {
if (message[i].time) {
--message[i].time;
if (message[i].time) continue;
sendto(udpsocket,message[i].msg,message[i].len,0,
message[i].to,sizeof(struct sockaddr_in));
sendto(udpsocket, message[i].msg, message[i].len, 0, message[i].to, sizeof(struct sockaddr_in));
}
}
}
@ -167,11 +163,9 @@ static int putmsg(struct sockaddr_in *toname,unsigned char *msg,int len) {
}
return 0;
#else
status=sendto(udpsocket,msg,len,0,
(struct sockaddr *)toname,sizeof(struct sockaddr_in));
status = sendto(udpsocket, msg, len, 0, (struct sockaddr*) toname, sizeof(struct sockaddr_in));
return status;
#endif
}
static int getmsg(int msec) {
@ -192,8 +186,7 @@ static int getmsg(int msec) {
res = select(udpsocket + 1, &readfds, 0, 0, &timeout);
if (res <= 0) return -1;
}
size=recvfrom(udpsocket,mesg,MAXMSG,0,
(struct sockaddr *)&sender,&senderlength);
size = recvfrom(udpsocket, mesg, MAXMSG, 0, (struct sockaddr*) &sender, &senderlength);
return size;
}
@ -236,17 +229,12 @@ static int isvalidmsg_from_slave() {
host = &sender.sin_addr.s_addr;
port = &sender.sin_port;
for (i = 1; i < MAXNETNODES; ++i)
if(netnodes[i].used &&
!memcmp(&netnodes[i].netname.sin_addr.s_addr,host,4) &&
!memcmp(&netnodes[i].netname.sin_port,port,2))
return i;
if (netnodes[i].used && !memcmp(&netnodes[i].netname.sin_addr.s_addr, host, 4) && !memcmp(&netnodes[i].netname.sin_port, port, 2)) return i;
return -1;
}
static int isvalidmsg_from_master() {
if (sender.sin_family != mastername.sin_family
|| sender.sin_addr.s_addr != mastername.sin_addr.s_addr
|| sender.sin_port != mastername.sin_port) return 0;
if (sender.sin_family != mastername.sin_family || sender.sin_addr.s_addr != mastername.sin_addr.s_addr || sender.sin_port != mastername.sin_port) return 0;
return 1;
}
@ -293,13 +281,11 @@ int networktraffic(void) {
actions[0] = myaction;
if (myaction == ACT_QUIT) {
for (i = 1; i < MAXNETNODES; ++i) {
if (netnodes[i].used)
actions[i] = ACT_QUIT;
if (netnodes[i].used) actions[i] = ACT_QUIT;
}
} else {
for (i = 1; i < MAXNETNODES; ++i) {
if (netnodes[i].used)
actions[i] &= ACT_MASK; /* only keep direction */
if (netnodes[i].used) actions[i] &= ACT_MASK; /* only keep direction */
}
now = gtime();
for (;;) {
@ -326,8 +312,7 @@ int networktraffic(void) {
for (i = 1; i < MAXNETNODES; ++i) {
if (netnodes[i].used) {
sendactions(i); /* send actions to every active node */
if (actions[i] == ACT_QUIT)
netnodes[i].used = 0; /* remove disconnected clients */
if (actions[i] == ACT_QUIT) netnodes[i].used = 0; /* remove disconnected clients */
}
}
return actioncount;
@ -464,8 +449,7 @@ void send_config() {
int i;
build_config();
for (i = 1; i < MAXNETNODES; ++i)
if (netnodes[i].used)
send_config1(i);
if (netnodes[i].used) send_config1(i);
}
static void send_reject(struct sockaddr_in* toname, Uint32 network_join_unique, unsigned char reason) {
@ -516,9 +500,7 @@ void cancel_network_game() {
mesg[5] = 0xff;
for (i = 1; i < MAXNETNODES; ++i) {
if(netnodes[i].used) {
putmsg(&netnodes[i].netname,mesg,6);
}
if (netnodes[i].used) { putmsg(&netnodes[i].netname, mesg, 6); }
}
}
@ -556,10 +538,8 @@ int handle_joins() {
if (-1 == j) j = i;
continue; /* don't compare with unused host */
}
if(memcmp(&netnodes[i].netname.sin_addr.s_addr,
&sender.sin_addr.s_addr,4)) continue;
if(memcmp(&netnodes[i].netname.sin_port,
&sender.sin_port,2)) continue;
if (memcmp(&netnodes[i].netname.sin_addr.s_addr, &sender.sin_addr.s_addr, 4)) continue;
if (memcmp(&netnodes[i].netname.sin_port, &sender.sin_port, 2)) continue;
/* found host */
break;
}
@ -580,10 +560,8 @@ int handle_joins() {
}
if (i == MAXNETNODES) i = j;
memmove(&netnodes[i].netname.sin_addr.s_addr,
&sender.sin_addr.s_addr,4);
memmove(&netnodes[i].netname.sin_port,
&sender.sin_port,2);
memmove(&netnodes[i].netname.sin_addr.s_addr, &sender.sin_addr.s_addr, 4);
memmove(&netnodes[i].netname.sin_port, &sender.sin_port, 2);
netnodes[i].netname.sin_family = AF_INET;
netnodes[i].used = 1;
memcpy(netnodes[i].name, mesg + 9, 16);
@ -603,12 +581,14 @@ static int read_inform(unsigned char** pbuf, int *psize) {
int i;
if (size < 1) return 0;
myslot = *buf++; size--;
myslot = *buf++;
size--;
if (0xff == myslot) return 1;
if (size < 1) return 0;
while (0xff != *buf) {
i = *buf++; size--;
i = *buf++;
size--;
if (size < 17 || i >= MAXNETNODES) return 0;
netnodes[i].used = 1;
memcpy(netnodes[i].name, buf, 16);
@ -723,7 +703,6 @@ void send_quit() {
size = getmsg(1000);
if (size < 6) continue;
if (mesg[0] != PKT_ACK || mesg[1] != PKT_QUIT) continue;
if (isvalidunique(mesg+2))
break;
if (isvalidunique(mesg + 2)) break;
}
}

View File

@ -1,13 +1,11 @@
#ifndef NETWORK_H
#define NETWORK_H
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
enum {
MAXNETNODES = 8
};
enum { MAXNETNODES = 8 };
struct netnode {
struct sockaddr_in netname;

View File

@ -1,9 +1,9 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <SDL_audio.h>
#include <SDL_error.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "sound.h"
@ -31,8 +31,7 @@ static const char *soundnames[] = {
"power2.raw",
};
typedef struct sample
{
typedef struct sample {
char* data;
int len;
} sample;
@ -53,23 +52,22 @@ static char soundcommands[MAXSOUNDCOMMANDS];
static int soundtake, soundput;
static int sndplaying[MIXMAX], sndposition[MIXMAX];
static void fillaudio(void *udata,Uint8 *buffer,int len)
{
static void fillaudio(void* udata, Uint8* buffer, int len) {
char com, *p;
int i, j, *ip;
int which;
(void) udata;
while(soundtake!=soundput)
{
while (soundtake != soundput) {
com = soundcommands[soundtake];
soundtake = (soundtake + 1) & (MAXSOUNDCOMMANDS - 1);
if(com==SOUND_QUIET) {memset(sndposition,0,sizeof(sndposition));continue;}
if(com<NUMSOUNDS)
{
if (com == SOUND_QUIET) {
memset(sndposition, 0, sizeof(sndposition));
continue;
}
if (com < NUMSOUNDS) {
for (i = 0; i < MIXMAX; ++i)
if(!sndposition[i])
{
if (!sndposition[i]) {
sndposition[i] = 1;
sndplaying[i] = com;
break;
@ -77,12 +75,10 @@ int which;
}
}
memset(soundbuffer, 0, soundbufferlen);
for(i=0;i<MIXMAX;++i)
{
for (i = 0; i < MIXMAX; ++i) {
if (!sndposition[i]) continue;
which = sndplaying[i];
if(sndposition[i]==samples[which].len)
{
if (sndposition[i] == samples[which].len) {
sndposition[i] = 0;
continue;
}
@ -94,9 +90,9 @@ int which;
while (j--) *ip++ += *p++;
}
j = len;
ip=soundbuffer;;
ip = soundbuffer;
;
while (j--) *buffer++ = sndclip[4096 + *ip++];
}
@ -120,28 +116,24 @@ int i,j;
wanted.callback = fillaudio;
wanted.userdata = 0;
if(SDL_OpenAudio(&wanted,0)<0)
{
if (SDL_OpenAudio(&wanted, 0) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
return -1;
}
soundworking = 1;
for(i=0;i<8192;i++)
{
for (i = 0; i < 8192; i++) {
j = i - 4096;
sndclip[i] = j > 127 ? 255 : (j < -128 ? 0 : j + 128);
}
for(i=0;i<NUMSOUNDS;++i)
readsound(i);
for (i = 0; i < NUMSOUNDS; ++i) readsound(i);
SDL_PauseAudio(0);
return 0;
}
void soundclose(void) {
if(soundworking)
{
if (soundworking) {
SDL_CloseAudio();
soundworking = 0;
}
@ -152,17 +144,14 @@ int readsound(int num) {
char name[256], *p1, *p2, ch;
int file, size, len;
p1 = dirlist;
for(;;)
{
for (;;) {
p2 = name;
while(*p1 && (ch=*p1++)!=',')
*p2++=ch;
while (*p1 && (ch = *p1++) != ',') *p2++ = ch;
if (p2 > name && p2[-1] != '/') *p2++ = '/';
strcpy(p2, soundnames[num]);
file = open(name, O_RDONLY);
if (file >= 0) break;
if(!*p1)
{
if (!*p1) {
samples[num].len = -1;
return 0;
}
@ -172,8 +161,7 @@ int file,size,len;
len = samples[num].len = (size + fragment - 1) / fragment;
len *= fragment;
p1 = samples[num].data = malloc(len);
if(p1)
{
if (p1) {
read(file, p1, size);
if (len - size) memset(p1 + size, 0, len - size);
while (size--) *p1++ ^= 0x80;

View File

@ -1,13 +1,13 @@
#include "bomber.h"
#include "utils.h"
#include "bomber.h"
#include "gfx.h"
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int volatile hc = 0;
@ -35,9 +35,18 @@ static void surf(Uint32 out[8], const Uint32 in[12], const Uint32 seed[32]) {
for (loop = 0; loop < 2; ++loop) {
for (r = 0; r < 16; ++r) {
sum += 0x9e3779b9;
MUSH(0, 5); MUSH(1, 7); MUSH(2, 9); MUSH(3, 13);
MUSH(4, 5); MUSH(5, 7); MUSH(6, 9); MUSH(7, 13);
MUSH(8, 5); MUSH(9, 7); MUSH(10, 9); MUSH(11, 13);
MUSH(0, 5);
MUSH(1, 7);
MUSH(2, 9);
MUSH(3, 13);
MUSH(4, 5);
MUSH(5, 7);
MUSH(6, 9);
MUSH(7, 13);
MUSH(8, 5);
MUSH(9, 7);
MUSH(10, 9);
MUSH(11, 13);
}
for (i = 0; i < 8; ++i) out[i] ^= t[i + 4];
}
@ -62,10 +71,14 @@ static Uint32 surf_init(void) {
if (-1 == fd) {
Uint32 genseed[4][8];
surf_seed[0] = surf_seed[1] = gtime();
surf_in[0]++; surf(genseed[0], surf_in, surf_seed);
surf_in[0]++; surf(genseed[1], surf_in, surf_seed);
surf_in[0]++; surf(genseed[2], surf_in, surf_seed);
surf_in[0]++; surf(genseed[3], surf_in, surf_seed);
surf_in[0]++;
surf(genseed[0], surf_in, surf_seed);
surf_in[0]++;
surf(genseed[1], surf_in, surf_seed);
surf_in[0]++;
surf(genseed[2], surf_in, surf_seed);
surf_in[0]++;
surf(genseed[3], surf_in, surf_seed);
memcpy(surf_seed, genseed[0], 32);
memcpy(surf_seed, genseed[1], 32);
memcpy(surf_seed, genseed[2], 32);
@ -86,7 +99,8 @@ static Uint32 surf_init(void) {
static Uint32 surf_random(void) {
if (surf_left == 0) {
int i;
for (i = 0; (i < 12) && !(++surf_in[i]); i++) ;
for (i = 0; (i < 12) && !(++surf_in[i]); i++)
;
surf_left = 8;
surf(surf_out, surf_in, surf_seed);
}
@ -235,6 +249,5 @@ void hexdump(unsigned char *p, int len) {
else
fprintf(stderr, "0x%X ", p[i]);
}
if (i % 16)
fprintf(stderr, "\n");
if (i % 16) fprintf(stderr, "\n");
}

View File

@ -1,6 +1,8 @@
#ifndef UTILS_H
#define UTILS_H
#include <SDL.h>
Uint32 gtime(void);
Uint32 longtime(void);