Author Topic: 4k Intro Coding...  (Read 11506 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
4k Intro Coding...
« on: April 02, 2007 »
hi folk...
i am trying to code / working on my first 4k intro... Whats the best way to structure / build the sourcecode for such a thing? I just ask, because atm the test version is not coded in C/CPP nor ASM... but i will try to convert the finished source to C/CPP to get small exesize and this project should be my first step into C/CPP coding... (i will move over to this language for future)

Afaik, in C/CPP you need something like Functions/Procedures like Main() as entrypoint? So what the best way, just having 3 procedures like Main() for opening screen and init needed stuff, Intro() for the mainloop (all stuff, routines are just packed into this one procedure) and something like Free() for freeing all the stuff when end the intro?

Or does it make more sence to have for each routine like CreateFont, DrawFont, FreeFont... an own procedure? I think the way, where all stuff / routines are packed into one procedure may be the best solution for 4k coding, isnt it?

Thanks for sharing your opinions...




- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 4k Intro Coding...
« Reply #1 on: April 02, 2007 »
Two great links to get you started
http://dbfinteractive.com/index.php?topic=703.msg8733#msg8733
http://dbfinteractive.com/index.php?topic=864.0

There's also krunchy, but I'm not sure how useful that is down at sizes as tiny as 4Kb
http://www.farbrausch.de/~fg/kkrunchy/

Jim
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: 4k Intro Coding...
« Reply #2 on: April 02, 2007 »
...
Afaik, in C/CPP you need something like Functions/Procedures like Main() as entrypoint?
So what the best way, just having 3 procedures like Main() for opening screen and init
needed stuff, Intro() for the mainloop (all stuff, routines are just packed into this one
procedure) and something like Free() for freeing all the stuff when end the intro?

Hey va!n,

yes. The entrypoint would be the WinMain function. Actually you do not need any
more procedures at all. Have a look at rbraz small 4k framework.

There you only have the one WinMain function. You do all initialisation before the MainLoop
and you care about freeing resources right after the mainloop. However, the more complex
your 4kb intro gets - I think there wouldnt be any problem using some seperat functions. At
least those who are called within the mainloop.

Don't know how much overload a seperate function produces but I don't think that it is a lot ...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2759
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: 4k Intro Coding...
« Reply #3 on: April 03, 2007 »
You will find some good information about coding 4ks in C here:
http://in4k.untergrund.net/index.php?title=User:auld

Some advices from me:
- Just use functions/procedure when needed, try to reuse it as much as possible.
- Same for variables
- Try to make your algorithms tiny as possible
- There's no need to free memory , who cares about it :P , just ExitProcess(0); in the end of your prog.
- Use procedural graphics, there's no way to use gfx resources in 4ks
- Use a tiny softsynth to play your music (that's the hard part of 4ks)
- To compress your demo/intro you will need to use crinkler, so to use it, you will need to code your demo/intro in C/C++.

good luck  :)




« Last Edit: April 03, 2007 by rbraz »
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: 4k Intro Coding...
« Reply #4 on: April 03, 2007 »
...
- To compress your demo/intro you will need to use crinkler, so to use it, you will need to code your demo/intro in C/C++.
...

Speaking of crinkler ... what are the best option settings to compress a C/C++ exe built with
Visual Stuidio 2oo5 ??? I just use it in cooperation with apack - and I use crinkler without
any options - but I guess there could be some options to squeeze my exe more ?

Any hints appreciated ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: 4k Intro Coding...
« Reply #5 on: April 03, 2007 »
i dont have experience with crinker yet... but i think using first apack and then crinker isnt a good choise... just use only one packer and i am sure the result will be better instead using two packers..
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: 4k Intro Coding...
« Reply #6 on: April 03, 2007 »
I am doing it the other way around - first crinkler to get a com file. Then
apack to squeeze it ...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: 4k Intro Coding...
« Reply #7 on: April 03, 2007 »
I told b*ll**** ... I use dropper and then apack. Not crinkler yet.

Anyway ... any cruncher settings for Visual Studio C/C++ codes to make the exe
as tiny as possible still welcome ( no matter if it is crinkler or not )...
« Last Edit: April 03, 2007 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: 4k Intro Coding...
« Reply #8 on: April 03, 2007 »
Heres some hard worn experience:

1. Use C and drop to asm when you need. Far too many people in the scene worship asm without ever trying to optimise their C algorithms first. That said, asm is useful for some key things. First time though, C will suffice.

2. Exclude stdlib fom your build (there is an option in VC++ for it). Optimise for size (-Os) but also try -O2 because it might compress better.

3. Use crinkler. Its the best at 4k. Dont be fooled...if you use crinkler at around 1k it will be worse in performance than dropper and apack but by 4k its kicking arse.

4. Dont use libraries like math.lib - write your own functions. Many source code 4ks include some cool substitutes for math functions. Most memory fiunctions and file functions (should you need them) have win32 equivalents, meaning you dont need to import any libraries except OGL or DX. Importing a lib could be 40 bytes. Each function is 12-16 bytes. Just dont do it.
(exception, dont write vector and matrix libs yourself, read the d3dx documents with the microsoft directx sdk)

5. Extract *everything* to a function and think fourty times how to reuse. For example...a random point in a sphere routine. Could be used for camera path around an object, for drawing lines, for creating a starfield, for the location to draw your next cube, for an explosion of points...etc.

6. Aim for 3k of code and leave 1k for your synth and music *at least*.

7. At 4k dont import by ordinal.

8. Use iteration and recursion to the max to achieve your goals.

9. The great 4ks of last year had just one technique (eg raytracing, ambient occlusion) and so had one core routine and exploited it to the max. Dont try to write a demo in 4k...just adding black borders, a fade and some design will see you at 400 bytes less. Forget it, focus, do one thing wll and you are more likely to succeed (well at least to get thumbs on Pouet- depends what you call succeeding I guess).

10. For your synth, steal samples from inside gm.dls : its the same under Vista so its future proof too. The code to read them and do simple playback is about 300 bytes. Then add a tracker (300 again). Then consider effects.

11. Watch for converting floats to ints - its huge code because of IEEE. lrintf can be used in GCC but better is to use something like fist in asm.

12. Remember one x86 asm instruction can get both sin and cos of a number - that can be a huge byte saving.

13. Rbrazs VC++ opengl framework (based on my old GCC one) is the best around. In C, I doubt it can be beaten (famous last words).

14. Ignore any crap you hear from people who have never written a 4k once you finish. People who dont size code have no clue what is easy and what is hard (extra bytes). Try to laugh at the ridiculously ignorant saying things like "absolutely no design" - they have no clue. Do what you believe in.

15. Textures. 90% of the time they are hand coded. A good general texture technique in 4k is hard. Dont forget rand() can look great when stretched, layered etc. Checks are too easy, Xor similarly. Avoid them. Chladni is great. Cellular is ok. You'll be looking at around 250-300 bytes for decent textures.

16. Shaders are the way to go. They are smaller than equivalent normal code and doing bump mapping, noise, phong, displacement mapping is all possible in 450 bytes or less.

17. Lastly the best advice I can give dont download and use code from the internet. Write your own, then write it again, then write it again. It will get smaller, and smaller.

Writing a 4k is easy but ten times more _work_ to produce a good one than writing an intro. The synth alone could take you months. My prediction: breakpoint last year was an easy target for 4ks, they were well below what was expected in terms of quality. This year I know some of the participants and they are *good*. Its going to be a good competition.

No, I wont be there- I'm retired. I shall be in Disney with my family considering how small a space I can get Mickey Mouse into ;-)

Chris
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: 4k Intro Coding...
« Reply #9 on: April 03, 2007 »
thanks for all the infos... nice to read... i am not sure if i get managed some parts of my "simple" 4k intro until BP... i still hope so but the time is running to fast away... would be nice, to have the 4k finished for the BP 4k compo... if so, i will ofcourse post the d/l here :)
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: 4k Intro Coding...
« Reply #10 on: April 03, 2007 »
@Chris:

Nice that you stepped by and visit us again.

Your post shows again how much knowledge you have about 4kb development.
Thumb up and karma boost (even if you propably dont care about it anymore).

Have fun in disney land and enjoy your life!!! And happy easter btw.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: 4k Intro Coding...
« Reply #11 on: April 03, 2007 »
...
3. Use crinkler. Its the best at 4k. Dont be fooled...if you use crinkler at around 1k
it will be worse in performance than dropper and apack but by 4k its kicking arse.
...

Just have configured crinkler with my Visual C++ project. Chris is absolutely right. It
really rocks ...

Btw, you find crinkler here : http://www.crinkler.net
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: