Example #1
0
int		main(int argc, char **argv)
{
	t_env	e;
	t_cam	cam;
	t_set	settings;

	if (!argv[1] || argc != 2)
	{
		ft_putendl_fd("\033[1;33;40mWrong number of argument\033[0m", 2);
		ft_putstr_fd("Wolf3d : \n\t./wolf3d \033[1;32;40myour_map\033[0m", 2);
		ft_putendl_fd(" -> will start an arcade game with your map", 2);
		ft_putendl_fd("\t./wolf3d story -> will start the story mode", 2);
		return (0);
	}
	e.cam = &cam;
	e.set = &settings;
	e.file = ft_strdup(argv[1]);
	w_init(&e);
	w_check_out(&e);
	mlx_expose_hook(e.win, expose_hook, &e);
	mlx_hook(e.win, KeyPress, KeyPressMask, key_p, &e);
	mlx_hook(e.win, KeyRelease, KeyReleaseMask, key_r, &e);
	mlx_mouse_hook(e.win, mouse_hook, &e);
	mlx_loop_hook(e.mlx, &move, &e);
	mlx_loop(e.mlx);
	return (0);
}
Example #2
0
File: ansari.c Project: kmillar/rho
static void
qansari(int len, double *P, double *Q, int m, int n)
{
    int i, l, u;
    double c, p, xi;
    double ***w;

    w = w_init(m, n);
    l = (m + 1) * (m + 1) / 4;
    u = l + m * n / 2;
    c = choose(m + n, m);
    for (i = 0; i < len; i++) {
        xi = P[i];
        if(xi < 0 || xi > 1)
            error(_("probabilities outside [0,1] in qansari()"));
        if(xi == 0)
            Q[i] = l;
        else if(xi == 1)
            Q[i] = u;
        else {
            p = 0.;
            int q = 0;
            for(;;) {
                p += cansari(q, m, n, w) / c;
                if (p >= xi) break;
                q++;
            }
            Q[i] = q;
        }
    }
}
Example #3
0
int camera_on(){
    if(!w_init())error("bcm2835 missing");
    sphere_init(stepper_init(RHO_SLEEP,RHO_STEP,RHO_DIR,RHO_M0,RHO_M1,RHO_MODE,RHO_STEPS,"ρ"),
                stepper_init(THETA_SLEEP,THETA_STEP,THETA_DIR,THETA_M0,THETA_M1,THETA_MODE,THETA_STEPS,"θ"),
                stepper_init(PHI_SLEEP,PHI_STEP,PHI_DIR,PHI_M0,PHI_M1,PHI_MODE,PHI_STEPS,"φ"),
                "ο");
    trigger_init("μ");
    camera_init("δ");
}
Example #4
0
int slave_read(){
    int i;
    verbose(L_SLVE,"%s:",slv_name);
    while((i=get_long(in))>=0){
        switch(i){
            case    ACT_NOP:break;
            case     ACT_ON:w_init();break;
            case    ACT_OFF:w_close();break;
            case  ACT_SLEEP:w_delayMicroseconds(get_long(in));break;
            case  ACT_WRITE:w_gpio_write(get_long(in),get_long(in));break;
            case   ACT_FSEL:w_gpio_fsel(get_long(in),get_long(in));break;
            case ACT_SETPUD:w_gpio_set_pud(get_long(in),get_long(in));break;
        }
    }
}
Example #5
0
File: ansari.c Project: kmillar/rho
static void
pansari(int len, double *Q, double *P, int m, int n)
{
    int i, j, l, u;
    double c, p, q;
    double ***w;

    w = w_init(m, n);
    l = (m + 1) * (m + 1) / 4;
    u = l + m * n / 2;
    c = choose(m + n, m);
    for (i = 0; i < len; i++) {
        q = floor(Q[i] + 1e-7);
        if (q < l)
            P[i] = 0;
        else if (q > u)
            P[i] = 1;
        else {
            p = 0;
            for (j = l; j <= q; j++) p += cansari(j, m, n, w);
            P[i] = p / c;
        }
    }
}
Example #6
0
int
InitDisplayW(int argc, char **argv)
{
	rgb_t color;
	struct timeval time;

	if (magstep < 1) {
		magstep = 1;
	}
	if (magstep > maxsize) {
		fprintf(stderr, "Warning: Enlargement factor %d is too large!\n",
		        magstep);
		magstep = maxsize;
	}
	if (!(serverW = w_init())) {
		fprintf(stderr, "%s: W initialization failed\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	bpp = serverW->planes;
	if (verbose)
		fprintf(stderr,
		        "W: %dbpp [%s, %s] %d shared colors, %s blocks\n",
		        bpp,
		        (serverW->type == BM_PACKEDCOLORMONO) ? "bitplanes, monochrome"
		        : (serverW->type == BM_PACKEDMONO) ? "1 bitplane, monochrome"
		        : (serverW->type == BM_DIRECT8) ? "8-bit chunky (direct) colors"
		        : (serverW->type == BM_PACKEDCOLOR) ? "bitplanes, colors settable"
		        : (serverW->type == BM_DIRECT24) ? "24-bit (rgb) image"
		        : "unknown scheme",
		        (indexedcolor && (bpp > 1)) ? "dynamic" : "static",
		        serverW->sharedcolors,
		        (serverW->flags & WSERVER_SHM) ? "shared" : "normal");
	if (renderer_config.inroot) {
		width = serverW->width;
		height = serverW->height;
		x0 = 0;
		y0 = 0;
		winW = WROOT;
	} else {
		WFONT *fontW;

		width = UNDEF;
		height = UNDEF;
		x0 = UNDEF;
		y0 = UNDEF;
		if (renderer_config.geometry) {
			char *s;
			int c;

			/* this little hack converts "NxM" geometry specs into "N,M" */
			for (s = renderer_config.geometry; (c = *s); s++)
				if ((c == 'x') || (c == ',')) {
					*s = ',';
					break;
				}
			scan_geometry(renderer_config.geometry,
			              &width, &height,
			              &x0, &y0);
		}
		if ((width == UNDEF) || !width)
			width = 256 * magstep;
		if ((height == UNDEF) || !height)
			height = 240 * magstep;
		if (!(fontW = w_loadfont("lucidat", 13, F_BOLD)))
			if (!(fontW = w_loadfont(0, 0, 0))) {
				w_exit();
				fprintf(stderr, "%s: failed to acquire font\n", argv[0]);
				exit(EXIT_FAILURE);
			}
		if ((iconW = w_create(w_strlen(fontW, PACKAGE) + 4,
		                      fontW->height + 2,
		                      W_MOVE | EV_MOUSE
		                      | EV_KEYS | EV_MODIFIERS))) {
			w_setfont(iconW, fontW);
			w_printstring(iconW, 2, 1, PACKAGE);
		}
		w_unloadfont(fontW);
		if (!(winW = w_create(width, height,
		                      W_MOVE | W_TITLE | W_CLOSE
		                      | (iconW ? W_ICON : 0)
		                      | W_RESIZE
		                      | EV_KEYS | EV_MODIFIERS))) {
			if (iconW) w_delete(iconW);
			w_exit();
			fprintf(stderr, "%s: failed to create window\n", argv[0]);
			exit(EXIT_FAILURE);
		}
		w_settitle(winW, PACKAGE_NAME);
		limit2screen(winW, &x0, &y0);
	}
	/* Allocate rendering bitmap */
	if (!(bitmapW = w_allocbm(256 * magstep, 240 * magstep,
	                          serverW->type,
	                          ((serverW->type == BM_DIRECT8) ||
	                           (serverW->type == BM_PACKEDCOLOR))
	                          ? 1 << serverW->planes
	                          : 0))) {
		w_delete(winW);
		if (iconW)
			w_delete(iconW);
		w_exit();
		fprintf(stderr, "%s: failed to allocate bitmap\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	/* Allocate black and white pixels */
	for (blackpixel = 0; blackpixel < serverW->sharedcolors; blackpixel++)
		if (!w_getColor(winW, blackpixel,
		                &(color.red), &(color.green), &(color.blue))) {
			if ((color.red <= 0x0FU)
			 && (color.green <= 0x0FU)
			 && (color.blue <= 0x0FU))
				break;
		}
	if (blackpixel == serverW->sharedcolors)
		blackpixel = w_allocColor(winW, 0x00U, 0x00U, 0x00U);
	if (blackpixel < 0) {
		if (bpp > 1)
			fprintf(stderr,
			        "W: can't allocate black pixel -- using index 1\n");
		blackpixel = 1;
	}
	color.red = color.green = color.blue = 0x00U;
	if (bitmapW->palette)
		bitmapW->palette[blackpixel] = color;
	for (whitepixel = 0; whitepixel < serverW->sharedcolors; whitepixel++)
		if (!w_getColor(winW, whitepixel,
		                &(color.red), &(color.green), &(color.blue))) {
			if ((color.red >= 0xF0U)
			 && (color.green >= 0xF0U)
			 && (color.blue >= 0xF0U))
				break;
		}
	if (whitepixel == serverW->sharedcolors)
		whitepixel = w_allocColor(winW, 0xFFU, 0xFFU, 0xFFU);
	if (whitepixel < 0) {
		if (bpp > 1)
			fprintf(stderr,
			        "W: can't allocate white pixel -- using index 0\n");
		whitepixel = 0;
	}
	color.red = color.green = color.blue = 0xFFU;
	if (bitmapW->palette)
		bitmapW->palette[whitepixel] = color;
	for (int x=0; x < 24; x++) {
		palette[x] = palette2[x] = whitepixel;
	}
	if (indexedcolor && (bpp > 1)) {
		/* Pre-initialize the colormap to known values */
		oldbgcolor = currentbgcolor = NES_palette[0];
		color.red = ((NES_palette[0] & 0xFF0000) >> 16);
		color.green = ((NES_palette[0] & 0xFF00) >> 8);
		color.blue = (NES_palette[0] & 0xFF);
		for (int x = 0; x <= 24; x++) {
			palette[x] =
			  w_allocColor(winW, color.red, color.green, color.blue);
			palette2[x] = blackpixel;
			if (palette[x] < 0) {
				if (winW != WROOT)
					w_delete(winW);
				if (iconW)
					w_delete(iconW);
				w_exit();
				fprintf(stderr, "Can't allocate colors!\n");
				exit(EXIT_FAILURE);
			} else if (bitmapW->palette)
				bitmapW->palette[palette[x]] = color;
		}
		if (scanlines && (scanlines != 100)) {
			fprintf(stderr, "Warning: Scanline intensity is ignored in indexed-color modes!\n");
			scanlines = 0;
		}
	} else /* truecolor */ {
Example #7
0
/*
 * Receive a file.
 */
static void recvtftp(struct testcase *test, struct formats *pf)
{
  ssize_t n, size;
  recvblock = 0;
#if defined(HAVE_ALARM) && defined(SIGALRM)
  mysignal(SIGALRM, timer);
#endif
  rdp = w_init();
  rap = (struct tftphdr *)ackbuf;
  do {
    timeout = 0;
    rap->th_opcode = htons((u_short)opcode_ACK);
    rap->th_block = htons((u_short)recvblock);
    recvblock++;
#ifdef HAVE_SIGSETJMP
    (void) sigsetjmp(timeoutbuf, 1);
#endif
send_ack:
    if (swrite(peer, ackbuf, 4) != 4) {
      logmsg("write: fail\n");
      goto abort;
    }
    write_behind(test, pf->f_convert);
    for ( ; ; ) {
#ifdef HAVE_ALARM
      alarm(rexmtval);
#endif
      n = sread(peer, rdp, PKTSIZE);
#ifdef HAVE_ALARM
      alarm(0);
#endif
      if (n < 0) {                       /* really? */
        logmsg("read: fail\n");
        goto abort;
      }
      rdp->th_opcode = ntohs((u_short)rdp->th_opcode);
      rdp->th_block = ntohs((u_short)rdp->th_block);
      if (rdp->th_opcode == opcode_ERROR)
        goto abort;
      if (rdp->th_opcode == opcode_DATA) {
        if (rdp->th_block == recvblock) {
          break;                         /* normal */
        }
        /* Re-synchronize with the other side */
        (void) synchnet(peer);
        if (rdp->th_block == (recvblock-1))
          goto send_ack;                 /* rexmit */
      }
    }

    size = writeit(test, &rdp, (int)(n - 4), pf->f_convert);
    if (size != (n-4)) {                 /* ahem */
      if (size < 0)
        nak(ERRNO + 100);
      else
        nak(ENOSPACE);
      goto abort;
    }
  } while (size == SEGSIZE);
  write_behind(test, pf->f_convert);

  rap->th_opcode = htons((u_short)opcode_ACK);  /* send the "final" ack */
  rap->th_block = htons((u_short)recvblock);
  (void) swrite(peer, ackbuf, 4);
#if defined(HAVE_ALARM) && defined(SIGALRM)
  mysignal(SIGALRM, justtimeout);        /* just abort read on timeout */
  alarm(rexmtval);
#endif
  n = sread(peer, buf, sizeof(buf));     /* normally times out and quits */
#ifdef HAVE_ALARM
  alarm(0);
#endif
  if (n >= 4 &&                          /* if read some data */
      rdp->th_opcode == opcode_DATA &&   /* and got a data block */
      recvblock == rdp->th_block) {      /* then my last ack was lost */
    (void) swrite(peer, ackbuf, 4);      /* resend final ack */
  }
abort:
  return;
}
Example #8
0
/*
 * Receive a file.
 */
static void recvtftp(struct testcase *test, struct formats *pf)
{
  struct tftphdr *dp;
  struct tftphdr *ap;    /* ack buffer */
  unsigned short block = 0;
  int n, size;
#if defined(HAVE_ALARM) && defined(SIGALRM)
  mysignal(SIGALRM, timer);
#endif
  dp = w_init();
  ap = (struct tftphdr *)ackbuf;
  do {
    timeout = 0;
    ap->th_opcode = htons((u_short)ACK);
    ap->th_block = htons((u_short)block);
    block++;
#ifdef HAVE_SIGSETJMP
    (void) sigsetjmp(timeoutbuf, 1);
#endif
send_ack:
    if (send(peer, ackbuf, 4, 0) != 4) {
      logmsg("write: fail\n");
      goto abort;
    }
    write_behind(test, pf->f_convert);
    for ( ; ; ) {
#ifdef HAVE_ALARM
      alarm(rexmtval);
#endif
      n = recv(peer, dp, PKTSIZE, 0);
#ifdef HAVE_ALARM
      alarm(0);
#endif
      if (n < 0) {                       /* really? */
        logmsg("read: fail\n");
        goto abort;
      }
      dp->th_opcode = ntohs((u_short)dp->th_opcode);
      dp->th_block = ntohs((u_short)dp->th_block);
      if (dp->th_opcode == ERROR)
        goto abort;
      if (dp->th_opcode == DATA) {
        if (dp->th_block == block) {
          break;                         /* normal */
        }
        /* Re-synchronize with the other side */
        (void) synchnet(peer);
        if (dp->th_block == (block-1))
          goto send_ack;                 /* rexmit */
      }
    }

    size = writeit(test, &dp, n - 4, pf->f_convert);
    if (size != (n-4)) {                 /* ahem */
      if (size < 0)
        nak(errno + 100);
      else
        nak(ENOSPACE);
      goto abort;
    }
  } while (size == SEGSIZE);
  write_behind(test, pf->f_convert);

  ap->th_opcode = htons((u_short)ACK);   /* send the "final" ack */
  ap->th_block = htons((u_short)(block));
  (void) send(peer, ackbuf, 4, 0);
#if defined(HAVE_ALARM) && defined(SIGALRM)
  mysignal(SIGALRM, justquit);           /* just quit on timeout */
  alarm(rexmtval);
#endif
  n = recv(peer, buf, sizeof (buf), 0);  /* normally times out and quits */
#ifdef HAVE_ALARM
  alarm(0);
#endif
  if (n >= 4 &&                          /* if read some data */
      dp->th_opcode == DATA &&           /* and got a data block */
      block == dp->th_block) {           /* then my last ack was lost */
    (void) send(peer, ackbuf, 4, 0);     /* resend final ack */
  }
abort:
  return;
}
Example #9
0
/*
 * Receive a file.
 */
int tftp_recvfile(int f, union sock_addr *peeraddr,
		   int fd, const char *name, const char *mode)
{
    struct tftphdr *ap;
    struct tftphdr *dp;
    int n;
    volatile u_short block;
    volatile int size, firsttrip;
    volatile unsigned long amount;
    union sock_addr from;
    socklen_t fromlen;
    FILE *file;
    volatile int convert;       /* true if converting crlf -> lf */
    u_short dp_opcode, dp_block;

    startclock();
    dp = w_init();
    ap = (struct tftphdr *)ackbuf;
    convert = !strcmp(mode, "netascii");
    file = fdopen(fd, convert ? "wt" : "wb");
    block = 1;
    firsttrip = 1;
    amount = 0;

    bsd_signal(SIGALRM, timer);
    do {
        if (firsttrip) {
            size = makerequest(RRQ, name, ap, mode);
            firsttrip = 0;
        } else {
            ap->th_opcode = htons((u_short) ACK);
            ap->th_block = htons((u_short) block);
            size = 4;
            block++;
        }
        timeout = 0;
        (void)sigsetjmp(timeoutbuf, 1);
      send_ack:
        if (trace)
            tpacket("sent", ap, size);
        if (sendto(f, ackbuf, size, 0, &(peeraddr->sa),
                   SOCKLEN(peeraddr)) != size) {
            alarm(0);
            perror("tftp: sendto");
            goto abort;
        }
        write_behind(file, convert);
        for (;;) {
            alarm(rexmtval);
            do {
                fromlen = sizeof(from);
                n = recvfrom(f, dp, PKTSIZE, 0,
                             &from.sa, &fromlen);
            } while (n <= 0);
            alarm(0);
            if (n < 0) {
                perror("tftp: recvfrom");
                goto abort;
            }
            sa_set_port(peeraddr, SOCKPORT(&from));  /* added */
            if (trace)
                tpacket("received", dp, n);
            /* should verify client address */
            dp_opcode = ntohs((u_short) dp->th_opcode);
            dp_block = ntohs((u_short) dp->th_block);
            if (dp_opcode == ERROR) {
                printf("Error code %d: %s\n", dp_block, dp->th_msg);
                goto abort;
            }
            if (dp_opcode == DATA) {
                int j;

                if (dp_block == block) {
                    break;      /* have next packet */
                }
                /* On an error, try to synchronize
                 * both sides.
                 */
                j = synchnet(f);
                if (j && trace) {
                    printf("discarded %d packets\n", j);
                }
                if (dp_block == (block - 1)) {
                    goto send_ack;      /* resend ack */
                }
            }
        }
        /*      size = write(fd, dp->th_data, n - 4); */
        size = writeit(file, &dp, n - 4, convert);
        if (size < 0) {
            nak(f, peeraddr, errno + 100, NULL);
            break;
        }
        amount += size;
    } while (size == SEGSIZE);
  abort:                       /* ok to ack, since user */
    ap->th_opcode = htons((u_short) ACK);       /* has seen err msg */
    ap->th_block = htons((u_short) block);
    (void)sendto(f, ackbuf, 4, 0, (struct sockaddr *)peeraddr,
                 SOCKLEN(peeraddr));
    write_behind(file, convert);        /* flush last buffer */
    fclose(file);
    stopclock();
    //if (amount > 0)
    //    printstats("Received", amount);
    return amount;
}
Example #10
0
/*
 * Receive a file.
 */
void
recvfile(struct formats *pf)
{
	struct tftphdr *dp;
	struct tftphdr *ap;    /* ack buffer */
	int n, size;
	volatile unsigned short block;

	signal(SIGALRM, timer);
	dp = w_init();
	ap = (struct tftphdr *)ackbuf;
	block = 0;
	do {
		timeouts = 0;
		ap->th_opcode = htons((u_short)ACK);
		ap->th_block = htons((u_short)block);
		block++;
		(void) setjmp(timeoutbuf);
send_ack:
		if (send(peer, ackbuf, 4, 0) != 4) {
			syslog(LOG_ERR, "write: %m");
			goto abort;
		}
		write_behind(file, pf->f_convert);
		for ( ; ; ) {
			alarm(rexmtval);
			n = recv(peer, dp, PKTSIZE, 0);
			alarm(0);
			if (n < 0) {            /* really? */
				syslog(LOG_ERR, "read: %m");
				goto abort;
			}
			dp->th_opcode = ntohs((u_short)dp->th_opcode);
			dp->th_block = ntohs((u_short)dp->th_block);
			if (dp->th_opcode == ERROR)
				goto abort;
			if (dp->th_opcode == DATA) {
				if (dp->th_block == block) {
					break;   /* normal */
				}
				/* Re-synchronize with the other side */
				(void) synchnet(peer);
				if (dp->th_block == (block-1))
					goto send_ack;          /* rexmit */
			}
		}
		/*  size = write(file, dp->th_data, n - 4); */
		size = writeit(file, &dp, n - 4, pf->f_convert);
		if (size != (n-4)) {                    /* ahem */
			if (size < 0) nak(errno + 100);
			else nak(ENOSPACE);
			goto abort;
		}
	} while (size == SEGSIZE);
	write_behind(file, pf->f_convert);
	(void) fclose(file);            /* close data file */

	ap->th_opcode = htons((u_short)ACK);    /* send the "final" ack */
	ap->th_block = htons((u_short)(block));
	(void) send(peer, ackbuf, 4, 0);

	signal(SIGALRM, justquit);      /* just quit on timeout */
	alarm(rexmtval);
	n = recv(peer, buf, sizeof (buf), 0); /* normally times out and quits */
	alarm(0);
	if (n >= 4 &&                   /* if read some data */
	    dp->th_opcode == DATA &&    /* and got a data block */
	    block == dp->th_block) {	/* then my last ack was lost */
		(void) send(peer, ackbuf, 4, 0);     /* resend final ack */
	}
abort:
	return;
}
Example #11
0
void le_soa_step_x(le_task *t)
{
	assert(t->stype == ST_SOA);
	int i, j;
	
	const real k1 = t->dt * t->mat.c1 / t->h.x;
	const real k2 = t->dt * t->mat.c2 / t->h.x;
	
#define soa_omega_x(i, j, k) \
	{ \
	const real nv = soa_vx(i, j); \
	const real N00T = soa_sxx(i, j) * t->mat.irhoc1; \
	const real n1v = soa_vy(i, j); \
	const real N01T = soa_sxy(i, j) * t->mat.irhoc2; \
	\
	w1[k + 2] = nv  - N00T; \
	w2[k + 2] = nv  + N00T; \
	w3[k + 2] = n1v - N01T; \
	w4[k + 2] = n1v + N01T; \
	}

	for (j = 0; j < t->n.y; j++) {
		real w1[5], w2[5], w3[5], w4[5];
		soa_omega_x(0, j, 0);
		soa_omega_x(1, j, 1);
		soa_omega_x(2, j, 2);
		
#define w_init(w) w[0] = w[1] = w[2];
		w_init(w1);
		w_init(w2);
		w_init(w3);
		w_init(w4);
#undef w_init
		for (i = 0; i < t->n.x; i++) {
			real d1 = tvd2(k1, w1[0], w1[1], w1[2], w1[3]) - w1[2];
			real d2 = tvd2(k1, w2[4], w2[3], w2[2], w2[1]) - w2[2];
			real d3 = tvd2(k2, w3[0], w3[1], w3[2], w3[3]) - w3[2];
			real d4 = tvd2(k2, w4[4], w4[3], w4[2], w4[1]) - w4[2];
			d1 *= 0.5;
			d2 *= 0.5;
			d3 *= 0.5;
			d4 *= 0.5;
			
			soa_vx(i, j) += d1 + d2;
			soa_vy(i, j) += d3 + d4;
			soa_sxx(i, j) += (d2 - d1) * t->mat.rhoc1;
			soa_syy(i, j) += (d2 - d1) * t->mat.rhoc3;
			soa_sxy(i, j) += t->mat.rhoc2 * (d4 - d3);

			
			//reconstruct(w_2, w_1, w, w1, w2, k1, k2, &d);
			//inc_x(&t->mat, &gind(i, j), &d);
			
#define w_copy(w) \
			w[0] = w[1];\
			w[1] = w[2];\
			w[2] = w[3];\
			w[3] = w[4];
			w_copy(w1);
			w_copy(w2);
			w_copy(w3);
			w_copy(w4);
#undef w_copy
			if (i < t->n.x - 3) soa_omega_x(i + 3, j, 2);
		}
	}
}
Example #12
0
void le_soa_step_y(le_task *t)
{
	assert(t->stype == ST_SOA);
	
	int i, j;
	const real k1 = t->dt * t->mat.c1 / t->h.y;
	const real k2 = t->dt * t->mat.c2 / t->h.y;
	
	real *w1[5], *w2[5], *w3[5], *w4[5];
#define w_malloc(w)\
	w[0] = (real*)malloc(sizeof(real) * t->n.x);\
	w[1] = (real*)malloc(sizeof(real) * t->n.x);\
	w[2] = (real*)malloc(sizeof(real) * t->n.x);\
	w[3] = (real*)malloc(sizeof(real) * t->n.x);\
	w[4] = (real*)malloc(sizeof(real) * t->n.x);
	
	w_malloc(w1);
	w_malloc(w2);
	w_malloc(w3);
	w_malloc(w4);
#undef w_malloc

#define soa_omega_y(i, j, k) \
	{ \
	const real nv = soa_vy(i, j); \
	const real N00T = soa_syy(i, j) * t->mat.irhoc1; \
	const real n1v = soa_vx(i, j); \
	const real N01T = soa_sxy(i, j) * t->mat.irhoc2; \
	\
	w1[k + 2][i] = nv  - N00T; \
	w2[k + 2][i] = nv  + N00T; \
	w3[k + 2][i] = n1v - N01T; \
	w4[k + 2][i] = n1v + N01T; \
	}

	for (i = 0; i < t->n.x; i++) {
		soa_omega_y(i, 0, 0);
		soa_omega_y(i, 1, 1);
		soa_omega_y(i, 2, 2);
	}
#define w_init(w)\
	for (i = 0; i < t->n.x; i++) {\
		w[0][i] = w[1][i] = w[2][i];\
	}
	
	w_init(w1);
	w_init(w2);
	w_init(w3);
	w_init(w4);
#undef w_init

	for (j = 0; j < t->n.y; j++) {
		for (i = 0; i < t->n.x; i++) {
			real d1 = tvd2(k1, w1[0][i], w1[1][i], w1[2][i], w1[3][i]) - w1[2][i];
			real d2 = tvd2(k1, w2[4][i], w2[3][i], w2[2][i], w2[1][i]) - w2[2][i];
			real d3 = tvd2(k2, w3[0][i], w3[1][i], w3[2][i], w3[3][i]) - w3[2][i];
			real d4 = tvd2(k2, w4[4][i], w4[3][i], w4[2][i], w4[1][i]) - w4[2][i];
			d1 *= 0.5;
			d2 *= 0.5;
			d3 *= 0.5;
			d4 *= 0.5;

			soa_vy(i, j) += d1 + d2;
			soa_vx(i, j) += d3 + d4;

			soa_syy(i, j) += (d2 - d1) * t->mat.rhoc1;
			soa_sxx(i, j) += (d2 - d1) * t->mat.rhoc3;
			soa_sxy(i, j) += t->mat.rhoc2 * (d4 - d3);
		}
		
#define w_copy(w)\
		{\
		real *t = w[0];\
		w[0] = w[1];\
		w[1] = w[2];\
		w[2] = w[3];\
		w[3] = w[4];\
		w[4] = t;\
		}
		
		w_copy(w1);
		w_copy(w2);
		w_copy(w3);
		w_copy(w4);
#undef w_copy
		
		if (j < t->n.y - 3) {
			for (i = 0; i < t->n.x; i++) {
				soa_omega_y(i, j + 3, 2);
			}
		}
	}

#define w_free(w)\
	free(w[0]);\
	free(w[1]);\
	free(w[2]);\
	free(w[3]);\
	free(w[4]);
	
	w_free(w1);
	w_free(w2);
	w_free(w3);
	w_free(w4);
#undef w_free
}