Skip to content

Commit

Permalink
copy and paste tools work, although leaky
Browse files Browse the repository at this point in the history
  • Loading branch information
superjer committed Feb 27, 2011
1 parent 2bc4bbb commit c88d23e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions mcdiddy/obj_.h
Expand Up @@ -39,6 +39,9 @@ typedef struct{
int model;
int client;
int avatar;
int clipboard_x;
int clipboard_y;
CB *clipboard_data;
} GHOST_t;

void obj_ghost_draw( int objid, OBJ_t *o );
Expand Down
25 changes: 18 additions & 7 deletions mcdiddy/obj_ghost.c
Expand Up @@ -55,45 +55,56 @@ void obj_ghost_adv( int objid, Uint32 a, Uint32 b, OBJ_t *oa, OBJ_t *ob )

if( dnx<0 || dny<0 || upx>=co->x || upy>=co->y ) { SJC_Write("Edit command out of bounds!"); break; }

if( value == 0x4F ) { //COPY tool texture
gh->clipboard_x = upx - dnx + 1;
gh->clipboard_y = upy - dny + 1;
gh->clipboard_data = malloc( gh->clipboard_x*gh->clipboard_y*(sizeof *gh->clipboard_data) ); //FIXME: mem leak
}

if( value == 0x5F && !gh->clipboard_data ) { SJC_Write("Clipboard is empty"); break; }

for( j=dny; j<=upy; j++ )
for( i=dnx; i<=upx; i++ ) {
int pos = 0*co->y*co->x + j*co->x + i;

// FIXME: WARNING: ALERT: LAME HACK for tool textures
switch( value ) {
case 15: //NUL
case 0x0F: //NUL
co->dmap[pos].flags |= CBF_NULL;
break;

case 31: //SOL
case 0x1F: //SOL
if( co->dmap[pos].flags & CBF_NULL ) co->dmap[pos].data[0] = co->map[pos].data[0];
co->dmap[pos].flags &= ~(CBF_NULL|CBF_PLAT);
co->dmap[pos].flags |= CBF_SOLID;
break;

case 47: //PLAT
case 0x2F: //PLAT
if( co->dmap[pos].flags & CBF_NULL ) co->dmap[pos].data[0] = co->map[pos].data[0];
co->dmap[pos].flags &= ~(CBF_NULL|CBF_SOLID);
co->dmap[pos].flags |= CBF_PLAT;
break;

case 63: //OPN
case 0x3F: //OPN
if( co->dmap[pos].flags & CBF_NULL ) co->dmap[pos].data[0] = co->map[pos].data[0];
co->dmap[pos].flags &= ~(CBF_NULL|CBF_SOLID|CBF_PLAT);
break;

case 79: //COPY
case 0x4F: //COPY
gh->clipboard_data[(j-dny)*gh->clipboard_x + (i-dnx)] = (co->dmap[pos].flags & CBF_NULL) ? co->map[pos] : co->dmap[pos];
break;

case 95: //PSTE
case 0x5F: //PSTE
co->dmap[pos] = gh->clipboard_data[ ((j-dny)%gh->clipboard_y)*gh->clipboard_x + ((i-dnx)%gh->clipboard_x) ];
break;

case 111: //OBJ
case 0x6F: //OBJ
pl->pos.x = i*co->blocksize;
pl->pos.y = j*co->blocksize;
break;

default:
if( co->dmap[pos].flags & CBF_NULL ) co->dmap[pos].flags = co->map[pos].flags;
co->dmap[pos].flags &= ~CBF_NULL;
co->dmap[pos].data[0] = (char)value;
}
Expand Down
3 changes: 3 additions & 0 deletions mcdiddy/obj_mother.c
Expand Up @@ -39,6 +39,9 @@ void obj_mother_adv( int objid, Uint32 a, Uint32 b, OBJ_t *oa, OBJ_t *ob )
gh->model = 0;
gh->client = i;
gh->avatar = slot0;
gh->clipboard_x = 0;
gh->clipboard_y = 0;
gh->clipboard_data = NULL;

pl->pos = (V){(i+1)*64,-50.0f,0.0f};
pl->vel = (V){0.0f,0.0f,0.0f};
Expand Down

0 comments on commit c88d23e

Please sign in to comment.