Dark Bit Factory & Gravity

GENERAL => Projects => Topic started by: va!n on December 09, 2008

Title: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 09, 2008
hi guys..
as some of you know this month is the german demoparty TUM... since some time i am working on a "very simple" 1k intro for this event and most things are done and working more or less good... (using VC2005 and DX9 for the 1k intro)

With some help and tips i managed to shrink the actually version to 1061 bytes (unenjoyable slow version) and to 1069 bytes (faster version)... I am out of ideas how and where are possibilities to save more bytes to get it fit in just 1024 bytes!

Here you DBF members can exclusive see my 1k intro as captured video version which runs a lot smoother as the original 1061 bytes exe version :
(Klick here to watch the video! Please do not copy nor spread the video nor idea around before the 1k has been released, thx) (http://www.secretly.de/dbf/please_do_not_copy_nor_spread.avi) 


And here is my actually problem list:
- Optimize size to fit into 1024 bytes (still using /UNSAFEIMPORT by crinkler)
- Speed up the particle system drawing ( using DX9->DrawText() which is extreme slow, using no sprite yet *damn* )
- Add GetTickCount (Kernel32.dll) for timing things to run in same speed on all PCs instead using things like   x = x + 1   on good old amiga ^^
- Maybe some design reworking (like background colors but this is easy and not so important yet... i like it myself colorfull)
- Sometimes (not often but still happens from time to time), the intro resets my computer while running O.O  (possible a HW prob with my PC?)

So if someone of you having good 1k coding/size-optimizing skills and is interested to help me it would be really nice...  feedback if you like or dislike the intro and its idea would be nice too... Btw, due fact i need help from other ppl to realise this 1k, the intro will be released with complete C/CPP source (with the party release!) - so any other ppl can try to see how it was done and can hopefully learn a bit from!!!

Due fact this prod is planed to be released in the "4k intro competition", i think its would be a problem with the compo-rulez to show here the source, before the intro has been released!? Thanks a lot for any feedback!
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: benny! on December 09, 2008
- How did you store the moving scenery ? In which format ?
Maybe there is space to optimize?

- How you print the text out ?
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 09, 2008
@benny:
Quote
How did you store the moving scenery ? In which format ?
Mhhh.. sorry, i am not really sure what you mean... the scenery graphic is just drawn by using the webdings font. So the full scenery is stored in stringdatas (sky + airplane + sun == only 7 bytes of data without the shown text messages)

Quote
- How you print the text out ?
Due fact the intro is DX9 based, i use   DX->DrawText()   to draw the text and a bit tricky, the particles too :P
Thats the reason, the particles are so extreme slow in the 1061 bytes version... DX->DrawText is very very slow for my need!
Afaik it could be speed up by using sprites... but this would cost more bytes/space in the exe...



Btw, here is the part where and how i draw things:
Code: [Select]
// ---- Draw our Scene with Text ----

rect.left = 680+(ScrollX<<1);
rect.top  = -50;
g_pFont[0]->DrawText(NULL, "j", -1, &rect, DT_LEFT , 0x88000000); // D3DCOLOR_XRGB(85,49,23) Airplane
// g_pFont[0]->DrawText(NULL, "j", -1, &rect, DT_LEFT , 0xff523317); // D3DCOLOR_XRGB(85,49,23) Airplane

rect.left  = 910+(ScrollX>>1);
rect.top = -30;
g_pFont[0]->DrawText(NULL, "Ö", -1, &rect, DT_LEFT , 0xff000000); // D3DCOLOR_XRGB(0,0,0) ) Sun 

rect.left  = ScrollX;
rect.top = 150;
g_pFont[0]->DrawText(NULL, "CKMSQ", -1, &rect, DT_LEFT , 0xff000000); // D3DCOLOR_XRGB(0,0,0) Landschaft

rect.left  = 20;
rect.top = 20;
g_pFont[2]->DrawText(NULL, TextParts[TextObj], -1, &rect, DT_LEFT , 0xffFFFFFF); // D3DCOLOR_XRGB(255,255,255) MessageText

// -----------------------------------------------

if (ScrollX > -1212) // Check how to get it work using GetTickCount() to run in same speed on all PCs
{
--ScrollX;
}

if ((change > 310) && (TextObj < 3))
{
++TextObj;
change = 0;
}
else
{
++change;
}

// ---- End the scene ----
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: hellfire on December 09, 2008
Instead of calling DrawText multiple times with different parameters, you can try something like this:
Code: [Select]
static int posx[3]={680, 910, 0};
static int posy[3]={-50, -30, 150};
static int speed[3]={4, 1, 2};
static char *text[3]={"j", "Ö", "CKMSQ" };
static unsigned int color[3]={0x88000000, 0xff000000, 0xff000000};

for (int i=0;i<3;i++)
{
  rect.left = posx[i] + (ScrollX*speed[i]>>1);
  rect.top  = pos[y];
  g_pFont[0]->DrawText(NULL, text[i], -1, &rect, DT_LEFT , color[i]);
}
(untested)

timing should be something like this:
Code: [Select]
int startTime= GetTickCount();

while (...)
{
  int scrollX= (startTime - GetTickCount)>>4; // scrollX is negative
  ...
};
this assumes that you're now running at ~60 frames per 1000 miliseconds => 1000/60=~16
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Clyde on December 10, 2008
Looking pretty cool so far dude; one thing I noticed that you might want to address is with the plane, and that it could do with being made more rounded on the nose of it.
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: AnimalMother on December 10, 2008
Looks really cool. I like it!

But one funny thing: Airplane, Sun, Landschaft  ;D
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 11, 2008
thanks for your feedback and comments!

@hellfire:
thanks for your help... i have tried to add your code which works fine with fixing a small typemistake ^^ The packed file was a lot bigger using this way as the original. But no problem, it was a try worth. However i tried something similar myself before and had no luck with...

@all:
I know that its not really possible to help/optimize things when not having the full source/project to play a bit around with it... So i finally determined myself to attache the complete source/project here "for DBF forum members only"... but please do not copy nor spread the source/project/exe nor idea of this unfinished version! (The final 1k version will be released as exe with the complete and final source/project files for everybody!) For more infos, please read the info in the source. Thanks a lot!



Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 11, 2008
CPP source/project added...
btw... is it true, when writing a intro in pure C that the generated output (exe) may be some bytes smaller as writing in CPP? O.O

Here i will list some things i have tried myself to optimize the size (possible some older source versions here)

Code: [Select]
struct MyTextData
{
int x;
int y;
int font;
char* string;
int color;
};

static MyTextData td[4] = {
910+(ScrollX>>1),  -30, 0,     "Ö", 0xff000000,
580+(ScrollX<<1),  -50, 0,     "j", 0xff523317,
ScrollX ,  150, 0, "CKMSQ", 0xff000000,
20 ,   20, 1, TextParts[TextObj], 0xffFFFFFF,
};

for (int i=0; i<=3; i++)
{
SetRect( &rect, td[i].x, td[i].y, 1024, 1024);
g_pFont[ td[i].font ]->DrawText(NULL, td[i].string, -1, &rect, DT_LEFT , td[i].color); // D3DCOLOR_XRGB(0,0,0) ) Sun 
};

// ************************************************************
//   i n s t e a d   o f   t h i s :
// ************************************************************

rect.left = 680+(ScrollX<<1);
rect.top  = -50;
g_pFont[0]->DrawText(NULL, "j", -1, &rect, DT_LEFT , 0x88000000); // D3DCOLOR_XRGB(85,49,23) airplane (saves some bytes!)
// g_pFont[0]->DrawText(NULL, "j", -1, &rect, DT_LEFT , 0xff523317); // D3DCOLOR_XRGB(85,49,23) airplane

rect.left  = 910+(ScrollX>>1);
rect.top = -30;
g_pFont[0]->DrawText(NULL, "Ö", -1, &rect, DT_LEFT , 0xff000000); // D3DCOLOR_XRGB(0,0,0) sun 

rect.left  = ScrollX;
rect.top = 150;
g_pFont[0]->DrawText(NULL, "CKMSQ", -1, &rect, DT_LEFT , 0xff000000); // D3DCOLOR_XRGB(0,0,0) landscape


Code: [Select]
static void MyDrawText(int x, int y, int font, char* string, int color)
{
SetRect( &rect, x, y, 1024, 1024);
g_pFont[font]->DrawText(NULL, string, -1, &rect, DT_LEFT , color);
};

MyDrawText( 0, 910+(ScrollX>>1), -30, "Ö", 0xff000000);
MyDrawText( 0, 680+(ScrollX<<1), -50, "j", 0xff523317);
MyDrawText( 0, ScrollX, 150, "CKMSQ", 0xff000000);
MyDrawText( 1,               20,  20, TextParts[TextObj], 0xffFFFFFF);



Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 12, 2008
from yesterday until now (03:10am here) i have spend over 4 hours in trying a lot of things to optimize the filesize without any success yet :diablo:
does someone of the tiny size coders here have any idea/tip for me?

Would be nice to see in what filesize the exe ends up when it would be packed with a custom "no public" 1k packer like by mentor or hitchicker...  8)
Okay.. now i have to go to bed..  4,5 hours to sleep before going to work :P
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: hellfire on December 12, 2008
I believe you don't require 3 individual timers.
this:
Code: [Select]
if ((change > 310) && (TextObj < 3))
{
++TextObj;
change = 0;
}
else
{
++change;
}
is essentially the same as this:
Code: [Select]
TextObj= time / 311You just have to handle the case "TextObj==4" properly.
For example you could declare "mirand" (which is 0 at the time of calling DrawText) right behind "TextParts", making TextParts[4] a null-pointer (which is valid input to DrawText).

Just a thought...
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Clyde on December 12, 2008
Cant wait to see your progress dude, btw, Karma for supplying a video capture, as on my system I can't run the smaller Special K intros.
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 12, 2008
@hellfire:
thanks for the help... i have tried something simular but i had to add a if condition to check if TextObj>3 so no crap will be displayed... your way saves me about 5 bytes but after last msg has been shown, memory-trash (some random bytes) will be shown :P i will take a closer look to this methode next minutes...

btw i have tried wihout success (get it working and more tiny), to combine "time" and "SpeedX" into just one variable... should be possible.. i will play with this again... hopefully it saves some bytes too ^^



@all:
wanna just tell you great news...  actually i have a running version == 1022 bytes!!! :updance:  :mince:
i will tell you more about this very soon... so please be patienced...
btw if you have still any ideas, dont hestitate and let me know :)

Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Rbz on December 12, 2008
If the effect produced by removing mirand = 0; is acceptable for you I got it down to 1022 bytes too with proper timer added.

Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 13, 2008
@rbz:
Wow, 1022 bytes with an added timer to run in same speed on all PCs?  8) (this would be really cool!) The effect produced without using mirand = 0; does not looks so great but i could life with it if necessary ;) Btw, is there any way to get your reworked and optimized source version, so i can compare your version with my latest version and probaly shrink some more bytes?

Attached: my actually source version (1022 bytes). Many many thanks to Auld for his great help !!! :cheers:



Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Rbz on December 13, 2008
1020 now, I forgot to add data_seg and code_seg like Auld did :)

The trick here was to remove your sfrand function and use rand() function from msvcrt.dll instead.

In the .zip file you will find a library called "msvcrts.lib" which msvc and crinkler will use, just keep it in the same intro folder, any problems let me know.

Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 13, 2008
@rbz:
thanks for the source. i am just wondering whats going wrong here... i can compile your source without problems... but the crinkled exe is always 1312 bytes for me, using VC++2005, Crinkler v1.1, DX SDK Nov2008... Any idea why i cant compile your version to 1020/1022 bytes too? O.O Thanks!
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Rbz on December 13, 2008
You need to add this command line for crinkler ->   /ENTRY:WinMain
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 14, 2008
@rbz:
thanks for the source and the info with the settings! Yes, now it compiles to 1020 bytes...*thumbs up*

i have spend the full last night to compare the code differences between your and aulds source and tried to create a new version which uses tricks/optimiations from both sources... until now without real success... so i have still a queston i dont really check atm.

you changed following which i dont really understand why you canged nor where/whats the diffent between both versions:

Code: [Select]
void WinMainCRTStartup()
{

Code: [Select]
int WINAPI WinMain(HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                         LPSTR lpszArgument,
                           int nFunsterStil)

{

Ok, both are the Entrypoint, i have to change in the linker settings... but when adding your WinMain version to aulds version, the compiled exe is over 1300 bytes! So i am not sure about this point/changes and would be nice to know some more about it. thanks!

i will try to make a new tiny version (  <=1024 bytes including optimisations from you both with real timer and possible faster particle drawings).
Many thanks for your help, rbz!

 
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Rbz on December 15, 2008
This happens because msvcrt lib already have this symbol -> WinMainCRTStartup() / header
What we do is only use it's function, bypassing crt header using our own entry point.
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 23, 2008
ok guys.. just only a few days and the TUM begins... so i have really try to hurry up and come up with something that works hopefully faster (i mean the extreme slow particle drawing system) and to put all in just max 1024 bytes!

Since having two jobs and beeing very busy i will continue this project in a few minutes and try to compare both optimized version you guys posted/helped me... maybe it may be possible to save some more bytes and optimize the extrem slow DrawText()-Particle system, i.e. its possible to use the particles as texture/sprites, which should be faster!? So if someone of you great size-coders here have tips or may help, it would be really cool!

Would be very interested to see the packed exe size when it would be packed with a custom packer like the one by mentor or hitchhiker ;)
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 26, 2008
okay guys... with some help of a very great person i have now a version with full timer, which compiles to 1023 bytes here. Their are still some things where i could need your help to finish the final version.

- Fixing: Drawing more particles without lack of speed. something i thought about but does not fit into 1024 bytes, is to draw the particles on two positions each time... and adding the -400 @ rect.left and rect.top, so the particles looks much better (my opinion):
Code: [Select]
for (int i=0; i<511; i++)
{
rect.left= ((sfrand() + (sfrand()&3) * time) & 1023)-400; // Very cool optimizing tip by mentor! Thanks! <3
rect.top = ((sfrand() + (sfrand()&3) * time) & 1023)-400;          // No more need of array and struct! :D
g_pFont[1]->DrawText(NULL, "n   n n   n  n    n", -1, &rect, DT_LEFT , 0x08ffffff);

rect.left= rect.left - 200
rect.top= rect.top - 200
g_pFont[1]->DrawText(NULL, "n   n n   n  n    n", -1, &rect, DT_LEFT , 0x08ffffff);
}

- Fixing: Speed of showing/changing the MessageText does not really fit (like in the old original version) and it repeats instead stoped at the last messsage.

Else i would say, its nearly done... Thanks to all ppl helped me until now, like mentor, auld, rbz and all the others...! Source is attached... If you think the source must be reformated then let me know and show me whats the best way, since i am still learning.

@Rbz:
maybe their is a way to use again the msvcrts.lib functions for random, but on a way, that the particle fx looks like atm (moving particles instead randomed diplayed particles? ^^)
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Jim on December 27, 2008
Have you tried using D3DXCreateFontIndirect to create your fonts instead of D3DCreateFont?  That might save a little space as the parameters are almost all the same.

Have you tried adding
DT_NOCLIP (ie DT_LEFT|DT_NOCLIP)
to the drawing flags?  From the docs
Quote
ID3DXFont::DrawText is somewhat faster when DT_NOCLIP is used

Jim
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 27, 2008
@Jim:
Thanks for your feedback ;)
Yes, today i have tried to change the D3DXCreateFont() stuff to this here:

Code: [Select]
D3DXFONT_DESC Font1 = { -400, 0, 0, 0, 0, 1, 0, 0, 0, "webdings" };
D3DXFONT_DESC Font2 = {  -26, 0, 0, 0, 0, 0, 0, 0, 0, "impact" };

D3DXCreateFontIndirect( g_pDevice, &Font1, &g_pFont[0] );

Font1.Height  = -45;
D3DXCreateFontIndirect( g_pDevice, &Font1, &g_pFont[1] );
D3DXCreateFontIndirect( g_pDevice, &Font3, &g_pFont[2] );

But the exe was > 1024 bytes... so i have tried something to use/fill just only one D3DXFONT_DESC for Font1 and chaning the datas at runtime by overwriting/changing them so save possible some bytes... whatever i tried, i was not able to overwrite "webdings" to "impact". So i am not sure if there is any potential to save some bytes or not.

Code: [Select]
D3DXFONT_DESC Font1 = { -400, 0, 0, 0, 0, 1, 0, 0, 0, "webdings" };

D3DXCreateFontIndirect( g_pDevice, &Font1, &g_pFont[0] );

Font1.Height  = -45;
D3DXCreateFontIndirect( g_pDevice, &Font1, &g_pFont[1] );

Font1.Height  = -26;
Font1.FaceName = "impact";                                     
D3DXCreateFontIndirect( g_pDevice, &Font1, &g_pFont[2] );

I have read the DT_NOCLIP on the SDK docs but i think its only ok to use, when dont drawing outside of the screenarea (clipping)... so i have tried this yesterday for this, but exe got bigger and i dont noticed any speed different:

Code: [Select]
rect.left  = rect.top = 20;
g_pFont[2]->DrawText(NULL, TextParts[TextObj], -1, &rect, DT_LEFT|DT_NOCLIP, 0xffFFFFFF);

Two really nice and good modifications would be this for the particle drawings:

Code: [Select]
Original:

for (int i=0; i<1023; i++)
{
rect.left= ((sfrand() + (sfrand()&3) * time) & 1023);        //;-400; // Very cool optimizing tip by mentor! Thanks! <3
rect.top = ((sfrand() + (sfrand()&3) * time) & 1023);        //;-400;       // No more need of array and struct! :D
g_pFont[1]->DrawText(NULL, "n   n n   n  n    n", -1, &rect, DT_LEFT , 0x08ffffff);
}

Step1 - Change to:

for (int i=0; i<511; i++)
{
rect.left= ((sfrand() + (sfrand()&3) * time) & 1023)-400; // Very cool optimizing tip by mentor! Thanks! <3
rect.top = ((sfrand() + (sfrand()&3) * time) & 1023)-400;       // No more need of array and struct! :D
g_pFont[1]->DrawText(NULL, "n   n n   n  n    n", -1, &rect, DT_LEFT , 0x08ffffff);
}


Step2 - Change to:

for (int i=0; i<511; i++)
{
rect.left= ((sfrand() + (sfrand()&3) * time) & 1023)-400; // Very cool optimizing tip by mentor! Thanks! <3
rect.top = ((sfrand() + (sfrand()&3) * time) & 1023)-400;       // No more need of array and struct! :D
g_pFont[1]->DrawText(NULL, "n   n n   n  n    n", -1, &rect, DT_LEFT , 0x08ffffff);

rect.left=rect.left - 200;    // i.e. +200 instead -200
rect.top=rect.top - 200;    // i.e. +200 instead -200
g_pFont[1]->DrawText(NULL, "n   n n   n  n    n", -1, &rect, DT_LEFT , 0x08ffffff);

}

Sadly even when trying Step1 only, the exe is >1024 bytes...  Step2 would result in a much better looking and faster particle drawing, but i have no space to add this, sadly :(

Maybe i could save some bytes when using rand() of msvcrt but not sure how to add and get it work (rbz did it on his version). But the particle drawings should not be displayed randomized... they should move smooth (scroll)... mhhh...

However i thought about splitting the Main() function into three function parts...  Creating the three fonts, The DrawText() block, and the rest of mainloop... maybe this would pack better but just had some small wired problems
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 27, 2008
I got the version down to 1022 bytes... sadly without the modifications/wishes i posted before... here is actually version:
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: benny! on December 27, 2008
Cool. Good luck at TUM with it, va!n.
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 27, 2008
@benny:
thanks... would be cool if someone has one or more tips/trick to add the last two wishes, so its really perfect ;)
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 28, 2008
mhhhh... nobody? its really very quiet on this forum atm...
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Jim on December 28, 2008
The bits you want to add must come to 100s of bytes.  There's possibly no way to do it without totally changing how you draw those things.

Jim

Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 29, 2008
@all:
Vista problem:
Someone tested it on Vista? A friend told me that he gets always IMAs (illegal memory access) when running on Vista and so it dont work for him O.O (the needed DLLS are available on his vista system)

Size optimizing:
I have checked all my versions and i come up with the result that only following two changes are needed:

a) Adding -400 for x and y position of particles (looks much better)

b) MessageText should work like the first source i posted (and should not repeat)... or dou guys think, its better when it repeats ever and ever? If so, the text should changed not so fast as atm...

The idea to draw the particles two times is just stupid... so this idea was yesterday and is no longer up 2 date...

Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Jim on December 29, 2008
The exe in the zip from a few posts back works for me on Vista (after I grabbed the latest DirectX update), of course you've changed it since then.:)

Jim
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Rbz on December 29, 2008
Now I can only wish you good luck on the compo
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: va!n on December 29, 2008
1k Intro "Start the journey" has been released at TUM  8)
It will come with full VS2005 source! Thanks to everybody who helped me to finish this 1k intro! Thanks!  :cheers:
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: Shockwave on December 30, 2008
Best of luck :)
Title: Re: preview - possible an 1k intro for TUM2008 (exclusiv captured video)
Post by: bikerboy on December 30, 2008
g/luck man ;D