Author Topic: [SRC] monoPong - 1k  (Read 16613 times)

0 Members and 1 Guest are viewing this topic.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [SRC] monoPong - 1k
« Reply #20 on: January 29, 2008 »
@taj:

And of course -> Karma boost !!!  :kewl:
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: [SRC] monoPong - 1k
« Reply #21 on: January 29, 2008 »
...
// this version is 928 bytes with crinkler 1.0a (haven't tried 1.1 yet).
...

The exe crunched with Crinkler1.1 is 4 bytes bigger (-932bytes).

:-) haha. I would check flags though, that sounds like its checking dll safety or something automatically now. Maybe you need to switch that *off*.

Taj
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: [SRC] monoPong - 1k
« Reply #22 on: January 29, 2008 »
Ooops, I used abs, not fabs. That caused the code to be buggy!
The new one is 899 bytes. I also optimised your game logic a bit better for crinkler (about 10 bytes saved).
Oh yes also was able to remove glLoadIdentity. You might actually be able to add "bloop", "blop" sounds.

Code: [Select]
// New crinkler optimised OpenGL 1k framework.
// /CRINKLER /COMPMODE:SLOW /HASHSIZE:200 /HASHTRIES:50 /ORDERTRIES:6000
// this version is 899 bytes

#include <windows.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>

#define NULLNULL 0.0000000000f
#define NULLNULLONETRHEE 0.0130000000f
#define NULLNINE 0.8984375000f
#define NULLTWO 0.2001953125f
#define NULLNULLFIVE 0.0500488281f
#define NULLEIGHTSIX 0.8593750000f
#define NULLNULLEIGHT 0.0800781250f
#define NULLFIVE 0.5000000000f

static GLfloat batY, ballX, ballY;

static PIXELFORMATDESCRIPTOR pfd={
0, // Size Of This Pixel Format Descriptor... BAD coding, nothing new, saves 6 bytes
1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 32, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0
};

static void drawRect(float x, float y, float s) {glRectf(x, y, x+NULLNULLFIVE, y+s);}

void WINAPI WinMainCRTStartup()
{
DWORD cur;
GLfloat veloX, veloY, check;

   veloX=veloY=NULLNULLONETRHEE;
     
   HDC hDC = GetDC( CreateWindow("edit", 0, WS_POPUP|WS_VISIBLE|WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0) );
   SetPixelFormat ( hDC, ChoosePixelFormat ( hDC, &pfd) , &pfd );
   wglMakeCurrent ( hDC, wglCreateContext(hDC) );
   ShowCursor(FALSE);
   
    DWORD start = GetTickCount();
   

    for (;;)
    {
cur = GetTickCount();
if ( (cur - start ) < 10 ) continue;

start = cur;

ballX+=veloX;
ballY+=veloY;

if ( ballY > NULLNINE || ballY < -NULLNINE ) veloY = -veloY;

check  = fabs(batY - ballY);
if ( ballX > NULLEIGHTSIX) if (check<NULLTWO) veloX = -(0.005f + (check/5)); else break;
check  = abs(-batY - ballY);
if ( ballX < -NULLEIGHTSIX) if (check<NULLTWO) veloX = 0.005f + (check/5); else break;

if ( GetAsyncKeyState(VK_RIGHT) && batY < NULLNINE ) batY += NULLNULLFIVE;
if ( GetAsyncKeyState(VK_LEFT) && batY > -NULLNINE) batY -= NULLNULLFIVE;

glClear( GL_COLOR_BUFFER_BIT );
    drawRect( NULLNINE, -NULLNULLEIGHT + batY, NULLTWO );
    drawRect( -NULLNINE, -NULLNULLEIGHT - batY, NULLTWO );
    drawRect( ballX, ballY, NULLNULLFIVE );

SwapBuffers(hDC);
    }
ExitProcess(0);
}
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [SRC] monoPong - 1k
« Reply #23 on: January 29, 2008 »
Wow ... amazing. That means that I have tons of
bytes left for more. Good idea about sound. Will think
about.
Kewl!!!

[EDIT]
2nd check calculation should be fabs(), too - eh ?
[/EDIT]
« Last Edit: January 29, 2008 by benny! »
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: [SRC] monoPong - 1k
« Reply #24 on: January 29, 2008 »
Yes indeed - if you're lucky that will save another 10 bytes.

BTW I tried converting everything to ints except the glRectf function (in which I multiplied the scaled ints by a float to scale them down again). It saved about 20 bytes but I screwed it up somewhere and I cant be bothered to find out where. Still if you are desperate, it can be done. The trick is to use numbers between 0..255 as much as possible (as you are already using 2 byte floats). This ensures there are lots of zeroes in the higher order bytes and the compressor can work better. Also then you can get rid of abs and use & instead- but I didnt try that. It seems to me this can go down as far as about 875 bytes which given that your base (crinkler + open window + loop with swapbuffers + exitprocess) is 617 bytes is really astonishing. Thats about 260 bytes: in C! Next stop : games compendium in 4k.

« Last Edit: January 30, 2008 by taj »
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: [SRC] monoPong - 1k
« Reply #25 on: January 30, 2008 »
Benny,

try crinkler 1.1 with these flags:
/CRINKLER /COMPMODE:SLOW /HASHSIZE:200 /HASHTRIES:50 /ORDERTRIES:6000 /UNSAFEIMPORT /TRUNCATEFLOATS:12
(you dont need safe importing dialgue boxes with OGL)

Its now 870 bytes...

Taj
« Last Edit: January 30, 2008 by taj »
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [SRC] monoPong - 1k
« Reply #26 on: January 30, 2008 »
Yeah, taj. Thanks a lot again. Always tried to
avoid /UNSAFEIMPORT option. BUt guess you
are right.

I hope to add some boing sounds this weekend
and see how much space it needs.

Your optimized code really gives me hundreds of
ideas of new concepts to work on !!!  :inspired:

Very cool ... that deserves some more K  ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: