Talk:The 7th Guest: Difference between revisions

From XentaxWiki
Jump to navigation Jump to search
imported>DenizOezmen
No edit summary
imported>DenizOezmen
Line 23: Line 23:
* I'd agree that real code snippets are usually better readable than pseudo code (as long as the snippets are not comprised of "compressed C style" that seasoned C programmers are often prone to produce). On the other hand, this special algorithm looks much more frightening in a fully implemented variant (due to the buffer management overhead). For example, a fully-fledged Object Pascal implementation of said algorithm might take around 50 lines (not counting comments, declarations and empty lines), which is a bit too much to show the idea behind it.<br>C or Java code would of course be a bit shorter, but nonetheless ...<br>Maybe there's something "in between"?  
* I'd agree that real code snippets are usually better readable than pseudo code (as long as the snippets are not comprised of "compressed C style" that seasoned C programmers are often prone to produce). On the other hand, this special algorithm looks much more frightening in a fully implemented variant (due to the buffer management overhead). For example, a fully-fledged Object Pascal implementation of said algorithm might take around 50 lines (not counting comments, declarations and empty lines), which is a bit too much to show the idea behind it.<br>C or Java code would of course be a bit shorter, but nonetheless ...<br>Maybe there's something "in between"?  
* Creating a single page sounds good. Where should it belong?
* Creating a single page sounds good. Where should it belong?
<br>
Just as a thought ... what about something along these lines:<br>
<br>
<tt>
<b>while</b> InputPos < InputSize <b>do</b><br>
<b>begin</b><br>
: FlagByte := Input[InputPos++]<br>
: <b>for</b> i := 1 <b>to</b> 8 <b>do</b><br>
: <b>begin</b><br>
::  <b>if</b> FlagByte <b>and</b> 1 <b>then</b><br>
::  <b>begin</b><br>
:::  OfsLen := Input[InputPos] + Input[InputPos + 1] <b>shl</b> 8<br>
:::  InputPos += 2<br>
:::  <b>if</b> OfsLen = 0 <b>then</b><br>
::::    Exit;<br>
:::  Length := OfsLen <b>and</b> LengthMask + Threshold<br>
:::  Offset := (BufPos - (OfsLen <b>shr</b> LengthBits)) <b>and</b> (N - 1)<br>
:::  ''copy Length bytes from Buffer[Offset] onwards''<br>
:::  ''while increasing BufPos''
::  <b>end</b><br>
::  <b>else</b><br>
::  <b>begin</b><br>
:::  ''copy 1 byte from Input[InputPos]''<br>
:::  InputPos += 1<br>
::  <b>end</b><br>
::  FlagByte := FlagByte <b>shr</b> 1<br>
: <b>end</b><br>
<b>end</b><br>
</tt>


--[[User:DenizOezmen|Deniz Oezmen]] 08:56, 31 May 2005 (EDT)
--[[User:DenizOezmen|Deniz Oezmen]] 08:56, 31 May 2005 (EDT)

Revision as of 13:18, 31 May 2005

Algorithm and such ...

OK, I have added some information about the VDX format, but I'm not sure whether the pseudo code is appropriate here: LZSS is a fairly well known compression routine which has been used quite in bit especially in older games, but unfortunately it has been implemented in many different variantions. You need at least the parameters N, F, Threshold, Start Position and Void Byte as well as the information on how the offset is calculated (relative or absolute) to properly decompress LZSS-compressed data.

So ... should we instead write something about this algorithm in a centralized place and just point there with the right parameters or keep it to each game entry?

Someone might want to take a look at the code -- I think it's not very readable yet ...
--Deniz Oezmen 07:57, 31 May 2005 (EDT)

Good question

Let me try to understand. If I'm reading this correctly, your question has two parts:

  • How to improve readability of the pseudo code?
    I've looked at it and I agree the pseudo code isn't very readable at this point. I think the kind of visitor we get is pretty capable of reading proper, 'real' code, like for instance java or C snippets. I would like the other guys imput on this though.
  • If there are more games using a similar technique, should a separate page be created?
    The team has pretty much agreed that in such cases, a separate page should be created, that the game pages can link to. This prevents certain maintenance problems down the road.

-Captain 08:30, 31 May 2005 (EDT)

Yes ... =

... you got that correct so far. ;-)

  • I'd agree that real code snippets are usually better readable than pseudo code (as long as the snippets are not comprised of "compressed C style" that seasoned C programmers are often prone to produce). On the other hand, this special algorithm looks much more frightening in a fully implemented variant (due to the buffer management overhead). For example, a fully-fledged Object Pascal implementation of said algorithm might take around 50 lines (not counting comments, declarations and empty lines), which is a bit too much to show the idea behind it.
    C or Java code would of course be a bit shorter, but nonetheless ...
    Maybe there's something "in between"?
  • Creating a single page sounds good. Where should it belong?


Just as a thought ... what about something along these lines:

while InputPos < InputSize do
begin

FlagByte := Input[InputPos++]
for i := 1 to 8 do
begin
if FlagByte and 1 then
begin
OfsLen := Input[InputPos] + Input[InputPos + 1] shl 8
InputPos += 2
if OfsLen = 0 then
Exit;
Length := OfsLen and LengthMask + Threshold
Offset := (BufPos - (OfsLen shr LengthBits)) and (N - 1)
copy Length bytes from Buffer[Offset] onwards
while increasing BufPos
end
else
begin
copy 1 byte from Input[InputPos]
InputPos += 1
end
FlagByte := FlagByte shr 1
end

end

--Deniz Oezmen 08:56, 31 May 2005 (EDT)