Skip to main content
gamedev.net
🔒 Locked

c++ -> Object Pascal

Started by Pexi 9 replies 800+ views
Original Post
Pexi
Pexi
I''m having problems with two pices of c++ code which I understand but don''t know how to translate them to Delphi. In the second pice I have problems spacially with the last line. 1. What does that do? (1< 0); }
Pekka Heikurapekka.heikura@mbnet.fi
Null and Void
Null and Void
His first one got killed by HTML, here it is again: (1<<VARIANCE_DEPTH)

That means "1 shifted left by the value of the macro (I assume it''s a macro/constant/whatever) VARIENCE_DEPTH", and is probably done at compile time. I don''t know Pascal, so I can''t help you out.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
dwarfsoft
dwarfsoft
For the first one. The difficult way of doing it is (forgive me, but my pascal is old and my brain is soggy).

Assume the C code reads like

X = (1<<VARIANCE_DEPTH);

INTEGER i,x;
...
i:=0;
x:=1;
REPEAT / LOOP (Gee... I haven''t done this for a while )
x := x*2;
i := i+1;
UNTIL i >= VARIANCE_DEPTH


Ugly eh? But a bit shift is a multiple of 2. It all makes sense in the end

-Chris Bennett of Dwarfsoft - The future of RPGs
Thanks to all the goblins over in our little Game Design Corner niche
kvh
kvh
or you could just use the 'shl' and 'shr' operators for bitshifting

X := (1 shl VARIANCE_DEPTH);

return (d < 0) ? (-1) : (d > 0); is just an if-statement like previous posts mention, here's the object pascal code:

        
if D < 0 then
Result := -1
else if D > 0 then
Result := 1 //in C/C++, true = 1 and

else
Result := 0; //false = 0




BTW: as far as i know, there's no such thing as inlining in object pascal, if there is i'd like to here about it...

Edited by - kvh on April 23, 2001 2:01:41 PM
LoreKeeper
LoreKeeper
Okay... *grinZ*

the

x := 1 shl VARIANCE_DEPTH

is cool.

The second one can be improved slightly:

  
if d<1 then
Result := -1
else
Result := d>0;


This works coZ Delphi also assigns 1 for true and 0 for false.


Edited by - LoreKeeper on April 24, 2001 4:44:08 AM
Pexi
Pexi
THX for everybody for helphing me out.
Pekka Heikurapekka.heikura@mbnet.fi
dwarfsoft
dwarfsoft
Just came back to append what I said and mention SHL.. but looks like I was beaten to the punch... So what was it to do the loop? My Pascal skills are sooooo old and rusty

-Chris Bennett of Dwarfsoft - The future of RPGs Thanks to all the goblins in the GDCorner niche
Sly
Sly
quote:
Original post by dwarfsoft

For the first one. The difficult way of doing it is (forgive me, but my pascal is old and my brain is soggy).

Assume the C code reads like

X = (1<
INTEGER i,x;
...
i:=0;
x:=1;
REPEAT / LOOP (Gee... I haven''t done this for a while )
x := x*2;
i := i+1;
UNTIL i >= VARIANCE_DEPTH


The loop would have been this:

var
i, x: Integer;
begin
i := 0;
x := 1;
while (i < VARIANCE_DEPTH) do
begin
x := x * 2;
i := i + 1;
end;
...
end;

Using a do..while loop would always execute the loop once, resulting in a minimum shift of one, ie. a minimum x value of 2. But what if the shift was to be zero, ie. x = 1? That is why I chose a while loop.
quote:

Ugly eh? But a bit shift is a multiple of 2. It all makes sense in the end




Ugly, yes.

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.