pouët.net

Go to bottom

Random line of code thread

category: code [glöplog]
Code:template <class T> inline T remap(T value, T a, T b, T c, T d) { return c + (d - c) * (value - a) / (b - a); }
added on the 2009-12-22 22:07:07 by neoneye neoneye
Code: push {r4-r5,lr} lsr r2, r2, #3 mov r3, #77 mov r4, #151 mov r5, #28 vdup.8 d3, r3 vdup.8 d4, r4 vdup.8 d5, r5 .loop: vld3.8 {d0-d2}, [r1]! vmull.u8 q3, d0, d3 vmlal.u8 q3, d1, d4 vmlal.u8 q3, d2, d5 vshrn.u16 d6, q3, #8 vst1.8 {d6}, [r0]! subs r2, r2, #1 bne .loop pop { r4-r5, pc }
added on the 2009-12-22 22:57:50 by torus torus
entity foo is
generic( d : integer );
port( ck, rs_n : in std_logic; x, y, z : in integer; v : out integer );
end entity;
architecture bar of foo is
type z_t is array(0 to d) of std_logic_vector(r-1 downto 0);
type y_t is array(0 to d) of z_t;
type x_t is array(0 to d) of y_y;
signal box : x_t ;
begin
process(ck, rs)
begin
if rs='1' then
for _z in 0 to d-1 loop
for _y in 0 to d-1 loop
for _x in 0 to d-1 loop
box(z)(y)(x) <= x*y*z;
end loop;
end loop;
end loop;
elsif rising_edge(ck) then
v <= box(z)(y)(x);
end if;
end process;
added on the 2009-12-22 23:19:45 by rmeht rmeht
Code: for (int x = 0; x < 4; x++) //worst cubegen code evar {pointList[x] = new VertexPositionColor(new Vector3(100 * (x & 1)-50, 50 * (x & 2)-50, -50), Color.White); pointList[x+4] = new VertexPositionColor(new Vector3(100 * (x & 1)-50, 50 * (x & 2)-50,50), Color.White);}
added on the 2010-01-02 23:06:18 by QUINTIX QUINTIX
@torus: http://hilbert-space.de/?p=22 looks familiar :T

SIMD kicks ass for image filters. I wish the HTC Hero had a Neon-enabled ARM.. doing scalar processing of RGB565 data is bullshit :P
added on the 2010-01-03 00:44:38 by mic mic
Code: void __attribute__((section(".iwram"),long_call)) rotozoomer() { int x,y; int dx=(-(vid_screen.w>>2)); int dy; int sdy,cdy; int _x,_y; int presin; int precos; int color; u16 *p,*b; while(1) { p=((u16*)(vid_screen.pixel)); b=p+SCREEN_WIDTH*SCREEN_HEIGHT; presin=*(sin_lut+(angle&511)); precos=*(sin_lut+((angle+128)&511)); vid_vsync(); for(y^=y,dy=80;y<SCREEN_HEIGHT/2;y++,dy--) { sdy=dy*presin; cdy=dy*precos; for(x^=x,dx=-120;x<SCREEN_WIDTH;x++,dx++) { _y=((cdy+dx*presin)>>14)&63; _x=((dx*precos-sdy)>>14)&63; color=*(((u16*)(textureBitmap))+_x+(_y<<6)); *p++=color; *b--=color; } } angle++; } }
added on the 2010-01-03 05:02:54 by OnSoL OnSoL
Code: #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Terrible things are about to happen # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def meet_monster( _Player, _dung_monsters ):


From "pytarl" a text adventure/rougelike dungeon crawler game I currently develop. If anyone cares, the dev site is over here. You can download a win32 version from here. :)
added on the 2010-01-03 10:40:47 by tomaes tomaes
shmup-basics :)

private function gameLoop(e:Event):void
{
updateEnemies();
updatePlayerShip();
updatePlayerShots();
updateGameDisplay();
}
added on the 2010-01-03 11:09:11 by maw maw
@mic - well. That hilbert-space thing is my blog :-)
added on the 2010-01-03 14:50:53 by torus torus
OnSoL: Notice that the result of dx*presin increase by presin for every x-iteration; forward differencing it would be faster. The same goes for dx*precos. Basically, everything before ">>14)&63" can be turned into one add per pixel (or, two. one for _x and one for _y). Then notice how you can get rid of the dx-tracking - in fact, all you have left is the x-counter, x/y, x/y-deltas, and screen pointers. Next, turn your x-counter to count downwards, as that allows the compiler to have the sub-instruction update the zero-flag, giving the compare for free. Then you should start unrolling the inner loop :)

If you really want to be hard-core, you can combine the x and y counters (and deltas) into the same register, by using 16 bit per each. But beware of precision. Doing something like tracking high-precision x and y for each 16th pixel, and using low-precision between usually pays off.

And, as a final tweak you could use mode 4 instead, giving you double buffering. In that case, you need to write two horizontal pixels at the time, due to the lack of 8-bit writes to VRAM. This fits nicely with the unrolling, though :)

Congrats, now you have one of the fastest braindead rotozoomers for the GBA -- just using the BG transformation matrix is just soooo much faster :)

As a final nit-pick: your use of leading underscores for the _x and _y variables is not entirely kosher C++. Symbols starting with underscore is reserved for the C++ implementation.
added on the 2010-01-03 15:34:26 by kusma kusma
@tomaes: when de monster asks you to guess his trow, it's really vage.
i don't know how to format my reply. " 1 2 3" "123" "1,2,3" is all possible, but a wrongly formatted guess just counts as a wrong reply. (even entering "?" made me loose a guess.)

also, let some space between the messages, it's hard to know where you need to start reading for the last new message.

but i can see a cool game comming up :)
whynot2000: You just enter them one by one. F.e., an easy example: If the throw is 4, you know it can only be 1+1+2. So you enter your first guess "1" <enter> etc. Depending on the answers (f.e. a guess you were not sure of, because multiple options would be possible), you can change your strategy.

I'll upload a win32 version of the latest 0.6.2b to sourceforge later today. Bitbucket always has the latest version. :)
added on the 2010-01-03 18:14:39 by tomaes tomaes
(on second thought, that routine was kinda broken anyway. I am at 0.6.5b now and with the help of a really anal playtester, his thing is approaching actual playability/extended-coffee-break-fun rather quickly... ;)
added on the 2010-01-04 21:46:11 by tomaes tomaes
Quote:
static void unHAM( MOVIE *mov, unsigned char *src, unsigned char *dst )
Quote:
shmup-basics :)

private function gameLoop(e:Event):void
{
updateEnemies();
updatePlayerShip();
updatePlayerShots();
updateGameDisplay();
}


or just consider enemies, playership, playshots and so as entities and just do this : (with actor being of course a class and playership a sub-class of actor)

Code:foreach(actor a in actors) { a.update(); }
added on the 2010-01-09 19:57:27 by Tigrou Tigrou
if worlddestroyedbylargehadroncollider = 1 then print "The world has been destroyed by the large hadron collider" else print "The world has not been destroyed by the large hadron collider" endif
artrotate#[threeDs[i]] = ATan2(ourY#,ourX#)
added on the 2010-01-11 11:47:58 by 4mat 4mat
slightly OT yet code-related:

emacs ibuffer mode is the best thing since sliced bread! :)

here's my .emacs ini file , compatible with emacs 23.1 / win32 (place in c:/.emacs)

random-LOC:
Code: define int CTL_SLIDE = 27; // Note slide (0=off, 1..255)

added on the 2010-01-17 06:28:56 by xyz xyz
wurstkäse
added on the 2010-01-17 13:14:52 by rac rac
Code:if (!(pIns->VolEnv.dwFlags & ENV_CARRY)) resetEnvelopes(pChn, ENV_RESET_VOL);


bra andpantsoff

andpantsoff ret

added on the 2010-01-17 19:53:53 by Gmitts Gmitts
Code:drawcopy @demo %plane02.x %plane02.y %plane02.w $calc(%plane02.h + 8) @demo %plane02.x $calc(%plane02.y + 1) %plane02.w $calc(%plane02.h + 8)
added on the 2010-01-17 22:11:42 by ___ ___
Code: while [ 0 -eq 0 ] do echo "this topic is useless" wait 1 done
added on the 2010-01-17 22:49:26 by bull bull
Code:if(!isset($re[$tmp[$i]['prd_id']])) $re[$tmp[$i]['prd_id']] = array();

...can't wait to fire up the ASM again this weekend
added on the 2010-01-22 15:50:05 by d0DgE d0DgE
Code: #define INTERPOLATE_CASE1(p,n,c,r,g,b) \ { \ (b) = (c); \ (r) = _dotpu4 (_packl4 ((p),(n)), 0x40404040); \ (g) = _dotpu4 (_packh4 ((c)<<8, _pack2((p),(n))),0x40404040); \ } #define INTERPOLATE_CASE2(p,n,c,r,g,b) \ { \ (b) = _dotpu4 ((c)>>8, 0x00800080); \ (g) = (c)>>8; \ (r) = _avgu4 ((p),(n))>>8; \ } #define INTERPOLATE_CASE3(p,n,c,r,g,b) \ { \ (b) = _avgu4 ((p),(n)); \ (r) = _dotpu4 ((c), 0x00800080); \ (g) = (c); \ } #define INTERPOLATE_CASE4(p,n,c,r,g,b) \ { \ (b) = _dotpu4(_packh4((p),(n)), 0x40404040); \ (g) = _dotpu4(_packl4((c>>8), _packh2((p),(n))), 0x40404040); \ (r) = (c)>>8; \ }

added on the 2010-01-22 16:22:45 by torus torus

login

Go to top