Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

An outrageous question. OUTRAGE!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Bagne
ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA




Joined: 19 Feb 2003
Posts: 518
Location: Halifax

PostPosted: Thu Dec 17, 2009 9:37 pm    Post subject: An outrageous question. OUTRAGE! Reply with quote

Okay - I'm really gonna go out on a limb here.

Is there any way - any way at all - to control the colour value for each pixel on the screen?
Like - is it possible to have a 1x1 pixel slice, and I have 320X200 of them ... aaand I can control the colour of each?

The best way I could think of was to make a walkabout sprite with a single pixel in the upper left corner, and then spam 320x200 of these pixels on the screen.
Then - by tweaking the colour palette of each, I could change their colour.

Or is that possible? If I changed the palette of one, would they all change?

Awesomely related:
What's the precision of hspeak variables? Are they doubles or something?

Oh no! You're only allowed 4000 or so globals, aren't you?
Hm. I need a way to calculate and store 320x200 pixels.
I hear that you can make fake arrays with slices?
_________________
Working on rain and cloud formation
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Thu Dec 17, 2009 10:02 pm    Post subject: Reply with quote

Yes you can do that. It makes more sense to use box borders instead of walkabouts, they're smaller. Yes, each sprite slice can load an independent palette. However it would probably be significantly faster to use 1x1 rects instead of sprites. Probably - there's a lot of overhead each way.

The memory usage will probably be about, guessing, 15MB (from the slices, not from loading sprites. You would only be loading 0 or 1 sprites)

And the speed - I don't know, 0 frames per second? I'd like to see you try. Then I can use it as a benchmark for the interpreter and slice system. Include scripts please :)


HS variables are 32 bit signed integers. Floating point types will be added in the future. Theere are 4096 gloal variables, but slices are unlimited.

Also, I should mention that direct pixel-level access will be added to slices, either next release or instead whenever arrays are added.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Bagne
ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA




Joined: 19 Feb 2003
Posts: 518
Location: Halifax

PostPosted: Fri Dec 18, 2009 1:01 am    Post subject: Reply with quote

Only signed ints?
Blast. Plans down the tubes.

I wanted to build a Mandelbrot fractal.
I've done it in MATLAB - I thought it would be super fun to do it in the OHR.
It would be cool. You use the mouse and click a certain area. Then the clicked area becomes the new domain, the computer does some computation, and the new fractal will be calculated.
Even better - once all the interface jazz is figured out, all I gotta do is change the formula, and you can see the julian or the burning ship fractal - whatever you like.

I would have to set up a home-made complex-number system in hamsterspeak, but that shouldn't be too hard ... and it would be fun.

I like this direct-access to pixels idea. That way, if you know what you're doing, you could script in special effects. Like ... I donno, if you write a script to print out some concentric circles following a colour gradient, you could make an explosive shockwave.
If you're really clever, you could make mist or rain!
If people shared their scripts, we could build a library of special effects!
I'm way to tired to curb my enthusiasm!
Goodnight!
_________________
Working on rain and cloud formation
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Dec 18, 2009 5:06 am    Post subject: Reply with quote

For fun, I will be optimising the new script interpreter specifically for pumping out pixels. I might even try vectorising JIT compilation - I am doing this for fun after all. It's great to hear I won't be the only one making use of it. The very first thing I'll write will be a polygon rasteriser :). On my 9 year old 1GHz P3, I think I'll manage a fill rate hopefully near 20M pixels/s.

Of course, we should just add builtin (3D) transformed sprite (quad) rendering, it would be useful for 2D games too.

However, I warn you that until then, the current HS interpreter is pretty slow. I've managed to speed it up something like 10 times over what it was years ago (provided you don't use any commands), but it's reached the limit without a rewrite.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Fri Dec 18, 2009 10:26 am    Post subject: Reply with quote

I was actually playing with pixel-sized slices the other day (trying to draw a mandelbrot set using plotscripting)

Constructing the field of 320x200 pixel slices was VERY slow.

Just displaying them on the screen was not as bad as expected. I was averaging about 14 frames per second.... but that was without trying to DO anything with them.

I ended up switching to a 80x50 field of 4-pixel-square rects. That was something I could work with at a reasonable speed (although I gave up on my mandelbrot because of the lack of floating point variables. An integer-only mandelbrot is pretty dang boring.)

Teeemcee: The way I envision direct pixel access working would be something like this: a command like "put pixel" which would operate on a sprite slice. It would "fork" the sprite in the cache so you could write on a copy of a normal sprite without messing up other copies of it. (I guess I am thinking of "copy-on-write"). There could be other pixel-level drawing commands too, like line drawing and flood filling. I think SDL could optimize some of that stuff for us for free too, if we are willing to push it into the backend... Is that similar to what you have in mind?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Fri Dec 18, 2009 10:31 am    Post subject: Reply with quote

Code:

include plotscr.hsd

global variable(100, xsize)
global variable(101, ysize)
global variable(102, pixsize)

plotscript, init, begin
  xsize := 160
  ysize := 100
  pixsize := 2
  create pixel field
end

script, create pixel field, begin
  variable(x, y, row, pixel)
  for(y, 0, ysize--1) do(
    row := create container(320, pixsize)
    set slice y(row, y * pixsize)
    for(x, 0, xsize--1) do(
      pixel := create rect(pixsize, pixsize, -1)
      set parent(pixel, row)
      set slice x(pixel, x * pixsize)
      set rect border(pixel, border:none)
      set rect bg col(pixel, random(0,255))
    )
  )
end
Back to top
View user's profile Send private message Send e-mail Visit poster's website
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Dec 18, 2009 5:20 pm    Post subject: Reply with quote

Hmm, with 1x1 rects, it takes me 133 seconds to create the slices, and it runs at full speed, consuming 90% CPU (of one core of this 2.7Ghz 7750). But I've got slice debug enabled.

That'll be a nice script to try when I complete script profiling to clock time spent processing commands.

Modified sprites wouldn't be placed in the cache at all, but otherwise I agree.

Since slice commands can be fairly slow (and with the new interpreter I can usually expect nearly all time to be spent on commands) I would bypass a putpixel command entirely - when I say 'direct pixel access', I really mean direct. We can still have a putpixel, but I'd add a 'get pixel array' which creates a HS native array 'view' on the pixel data, which can be read and written to without leaving the interpreter's inner loop.

SDL doesn't have drawing functions like that; they're provided by SDL_gfx. But I've been thinking about it, and I think it might be best to leave 8 bit graphics rendering in allmodex/blit.c if that guarentees no locking required (speed increases are unlikely to be very significant unless hardware accelerated) but any 32 bit graphics or transparency or whatever would have to go in the backend, because it's too much work to write.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
ShakeyAir




Joined: 27 Apr 2004
Posts: 93

PostPosted: Fri Dec 18, 2009 6:43 pm    Post subject: Reply with quote

tetris loads instantly. and the title screen is 2 layers of 32X20 10x10 pixel slices that take up the whole screen. i wonder at what point the slowdown occurs, and how many slices the engine can reasonably handle onscreen (no problems with 1280, and no delay checking conditions and cycling through frames for each of them.)

..haha. I guess thinking about it now, that is a lot less slices than you guys are talking about using.
Back to top
View user's profile Send private message
Bagne
ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA




Joined: 19 Feb 2003
Posts: 518
Location: Halifax

PostPosted: Sat Dec 19, 2009 12:18 am    Post subject: Reply with quote

Wow!
You copied my idea even before I came up with it!
How did you do that?
_________________
Working on rain and cloud formation
Back to top
View user's profile Send private message
Bob the Hamster
OHRRPGCE Developer




Joined: 22 Feb 2003
Posts: 2526
Location: Hamster Republic (Southern California Enclave)

PostPosted: Sat Dec 19, 2009 8:17 am    Post subject: Reply with quote

Bagne wrote:
Wow!
You copied my idea even before I came up with it!
How did you do that?


Great minds think alike? ;)

After fractals in the conversation in the God thread, I started playing with various fractal programs, and that made me want to write one for the OHR.

I think it could be done now with some reasonable level of quality by multiplying and dividing the numbers by large powers of 10 to fake fixed-point decals, but when I tried it I severely confused myself and gave up.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Bagne
ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA




Joined: 19 Feb 2003
Posts: 518
Location: Halifax

PostPosted: Sat Dec 19, 2009 11:05 am    Post subject: Reply with quote

Know what? Maybe I should just make up my own float formatting. That way I can maximize my precision.

This is what I'm thinking. I have 32 to bits to do whatever I want.
The Mandelbrot set never has any values larger than 2, and the algorithm I'm using decides that the orbit of a point will not converge if an iteration starts getting values larger than 4.
So this calculation probably will never need a value larger than 8 ... I think.

Therefore, I can store my numbers like this:
Code:
sign, 4 bits, (implicit decimal place), 27 bits

I was thinking that every time the user zooms in, a pixel would be zoomed up to the size of a tile, so each zoom is ~20x.
This would be super sweet, because the computer can calculate the fractal to a precision of 1/2^27 and since Log_20(2^27) > 6, the user could could make six 20x zooms in a row before reaching the numeric limit. That's pretty good!

Ok, so I would need scripts that read and write my values. I can use AND operators to extract any bit I choose.

Addition and subtraction would function normally ... you just use AND to extract the right bits, add normally, and write them using AND.
I don't have a coherent plan for multiplication though ...
What would I do for that?
_________________
Working on rain and cloud formation
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sat Dec 19, 2009 7:57 pm    Post subject: Reply with quote

Pah, von Neumann didn't need floating point arithmetic to design the plutonium nuclear bomb explosive lenses.

Quote:
So this calculation probably will never need a value larger than 8 ... I think.

Larger than 6, actually.

Curse you Bagne, I saw this and immediately started thinking about software floating point, even though using software floating point for this is ludicrous and not what you were suggesting:

Multiplying two 31/32 bit significands needs to be split into 3 parts, multiplying 15 bit pieces together (assuming you throw away the 4th insignificant part which would only contribute 1 bit):
Code:

  (a1 * 2^15 + a2) * (b1 * 2^15 + b2)
= a1*b1 * 2^30 + (a1*b2 + a2*b1) * 2 ^ 15 + a2*b2
~ a1*b1 * 2^30 + (a1*b2 + a2*b1) * 2 ^ 15

Maybe you can probably save an extra bit by multiplying a 15 bit piece with a 16 bit one.

For an example, see the sine script at 'Scripts:3rd Party HSI', which does 32 bit multiplication using 16 bit integers. However looking at it now, it looks kind of garbage. It would have made a lot more sense with an explicit floating exponent.

Addition and subtraction can not be done normally, you have to take into account the exponents amking it even harder than multiplication. This is simple if you normalise the significands, however doing so may be prohibitively time consuming (and I don't believe adds very much to accuracy anway). Unfortunately, if you don't normalise, and take the naive approach, you're going to end up losing a hell of a lot of accuracy, retaining as little as 1 correct bit! To see what I mean:

Code:

a = a_sig * 2 ^ a_exp
b = b_sig * 2 ^ b_exp
# naive approach on unnormalised significands:
new_exp = max(a_exp, b_exp)
if (a_exp < b_exp) then:
  a + b = a_sig * 2 ^ a_exp + b_sig * 2 ^ b_exp
        = a_sig * 2 ^ (a_exp - b_exp) * 2 ^ b_exp + b_sig * 2 ^ b_exp
        = (a_sig / 2 ^ (b_exp - a_exp) + b_sig) * 2 ^ b_exp
#the problem:
a = 1023 * 2 ^ 0 = 1023
b = 1 * 2 ^ 10  = 1024
a + b = (1023 / 2 ^ (10 - 0) + 1) * 2 ^ 10
      = (1023 /  1024 + 1) * 2 ^ 10
      ~ 1 * 2 ^ 10
      = 1024

Of course, I should have rounded, but that will only give you one more bit (repeat with a = 511).

(EDIT: therefore, probably best to bite the bullet and normalise, it wouldn't be all that slow considering all the other slow things you're doing. Ie. a should be represented as a = 2145386496 * 2 ^ -21 = 1023 )



I retried the 64,000 slice script without script debugging, and it took 20 seconds to start up. Also! I totally forgot - a couple days ago I tested the engine, gfx_fb/music_silence, on a 300MHz Pentium MMX laptop from circa 1999 and it ran '1 Day in #Castleparadox' at full speed, with about 1200 slices (16x16 box borders) on screen. Unfortunately, when I tried a build with music enabled (music_sdl), the frame rate plummetted, even when displaying just a title screen with no music playing :( gfx_sdl was slightly slower than gfx_fb and couldn't quite manage 18fps. Oh, so close to lowering the minimum requirements to a machine as old as the OHR itself!


EDIT 10: OK, given up yet? If not, you better hurry, because I think I'll try this after the Ypsilifrom release candidate is done.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Bagne
ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA




Joined: 19 Feb 2003
Posts: 518
Location: Halifax

PostPosted: Sun Dec 20, 2009 1:24 am    Post subject: Reply with quote

I need to read over your post again when it's not 3 in the morning. I didn't understand 200% of it.

Aren't I suggesting software floating point?
I was thinking of taking the 32 bit variable and using AND operators to read and write bits using scripts according to a home-made format. Any read or write to my floats would be scripted.
Is this somehow different to "software floating point"? (which I have never before heard of (and I'm just guessing at the term's meaning (Triple parentheses!)))

I'm thinking of tossing out the exponent altogether btw. Use only the significand.
Am I being ludicrous? Would that slow everything down cubic light-year?

Haven't given up yet. I'm only planning, there's little to give up.

I need to get to bed so that tomorrow I can make some captions for cross-section photos of Eocene walnut fossils (from the north pole).
Sounds like I'm joking?
Well, I'm not joking.
_________________
Working on rain and cloud formation
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sun Dec 20, 2009 5:42 am    Post subject: Reply with quote

You appeared to be talking about (software) fixed point (it is probably implemented on some hardware but it most common in software), with 4 bits integer part, and 27 bits fractional, not an exponent and significand. (I'd guess that you'd only need 3 bits for the integer part - have to check the equations more closely). Software floating point is just floating point, done in software. I was talking about a scheme of storing a 32 bit exponent and 31 or 30 bit (not including sign bit) significand, in separate variables.

Quote:
I'm thinking of tossing out the exponent altogether btw. Use only the significand.
Am I being ludicrous? Would that slow everything down cubic light-year?


So what, you were talking about floating point? I'm confused, instead I'll just say that fixed point is much much faster than software floating point.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Bagne
ALL YOUR NUDIBRANCH ARE BELONG TO GASTROPODA




Joined: 19 Feb 2003
Posts: 518
Location: Halifax

PostPosted: Sun Dec 20, 2009 7:15 pm    Post subject: Reply with quote

I don't know what I'm talking about, that's my problem!

Oh okay, software fixed point. I'm guessing that's the right term for what I'm thinking (I've never heard the term before). I think we're on the same page now.

I'm trying to understand that first example you gave me. That was for software floating point, yes? Are a1 and b1 significands, and a2,b2 exponents?
What's the 2^15 do?

I need to multiply in fixed point. How do I do that? Do I just use your first example and set the exponents to ... I donno, 1? (improving precision by storing only values smaller than ... 10?)
Adding in software fixed point should be normal, right?
_________________
Working on rain and cloud formation
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group