PoP Unity - A remake in the Unity Engine

Threads about other remakes and ports.
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

PoP Unity - A remake in the Unity Engine

Post by ikazrima »

Hello guys,

This is my 2nd post so I guess it's appropriate for me to reveal my hand! :D

Introducing my attempt to recreate the original PoP using the Unity3d engine (which I'm going to call it PoP Unity)
Image

What it does - EDITED (as I think it caused some confusion)

- Place all tiles accordingly by reading any external LEVEL.DAT file. [edit]

I'm giving the current build a v0.1
(I've only worked for this for about a full week, so go easy on me ;) )

What I'm aiming for it to be

- Port the whole game into a new modern engine while retaining the exact same feel of the old game! (which is hard, I know :( )
- Mods! (I'm designing it to be mod friendly; from custom levels, sprites, tiles modifiers, events, etc. Level files from custom mods [such as Prince 4d] can be used)
- Ability to use HD sprites!

I've worked on a separate Levels.dat reader to extract all the necessary bytes as according to Format Specification documentation from this site.

Image

Unfortunately, roadblock(s) :cry:

I've managed to read and extract the relevant information inside the levels.dat file, and slowly working on the tile drawing algorithm.
Which I've come to a stump right now, and would appreciate if anyone could help me figure it out.

Referring to the image below:-
Image

As you can see, the tiles position is incorrect. Reading the documentation, it mentioned that there is a seed that stores the offset of these tiles.
Reading it again and again still hasn't made a sense to me. If anyone can explain as to where I can get the offsets, I really appreciate it as I can move on working on different parts of the game.

I know, just seeing a few image isn't that exciting. But hey, I'll be working on this for a while (because PoP is one of those games that I've been playing since 5 like the rest of us) so expect future updates soon. ;)
Last edited by ikazrima on March 10th, 2014, 10:28 am, edited 1 time in total.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: PoP Unity - A remake in the Unity Engine

Post by Norbert »

Hello ikazrima, I see that nobody replied to your first post yet, so I hereby welcome you to the forum (better late than never). :)

So, roughly speaking there are two paths you could follow.
The first is using the original DAT files (those made sense in 1989/1990, given various restrictions at the time), the second is using files and formats that are easier to understand and would make sense if PoP1 for DOS was created in 2014.
There are good arguments for both. I understand how thrilling it can be to visit the past and to figure out how things worked and can be manipulated, for instance.

As far as using the original DAT files goes. In your first post you wrote you "have experience in programming in the .NET environment". Check out Prince Of Persia Dot Net. The 4th post there, "Room wall algorithm", is something polipo was looking into. I pointed him to FreePrince, which uses the DAT files and has tile drawing code. And to David's room-drawing code. Its data/ files are (PNG versions of) what PR can extract. PR is one of the most impressive tools of the PoP modding community; it can read and write DAT files.

The second option would be converting the DAT files to modern equivalents and working with those. If I had to choose - I've been thinking about (re)creating PoP1 for DOS with SDL2 - I would take this route. This would be easier for you and also more interesting for modders. Instead of working with LEVELS.DAT, you could work with the (plain text) XML files that apoplexy can export (with: apoplexy -x) of whatever mod you feed it. Instead of working with the DIGISND*/MIDISND*/IBM_SND* files, you could work with WAV and OGG (or MP3) files. Instead of using VDUNGEON.DAT, VPALACE.DAT, and so on for images, you could use various transparent PNG images. For the tiles, you would need a total of 72 x 4 images of - if I'm not mistaken - 118x152 pixels. Reason: you would need foreground and background layers for all 72 tile variants, both for the dungeon and palace levels. (Foregrounds and backgrounds to allow the prince to walk behind, for example, pillars.) Yes, this would mean that the custom graphics of mods would not be immediately usable, but there are 22 custom palace graphics and 36 custom dungeon graphics, and the work to convert those would be doable. Another huge advantage of this path would be that future mods for your PoP Unity would be incredibly customizable, because there would be virtually no palette limits. The original DAT files limit palettes to (mostly) 16 colors and palettes are used for groups of images, which further complicates things. (See this document for more information.) In theory, a standalone program could even convert the tile fragments that PR exports to those 72 x 4 images, although some images might need some manual tweaking because of the move to two layers.

Anyways, I hope some of this was useful to you.
Good luck!
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

Re: PoP Unity - A remake in the Unity Engine

Post by ikazrima »

Hello Norbert, thanks for replying! :D

What I'm doing right now, is read the levels.dat file and store them in my own way (or as a modern equivalent, as you put it). The levels are map using code by reading said levels.dat file.

I'm only focusing on the graphics part right now, and other things such as sound and guard behaviour will come much later ;)
Though currently I'm using the original .bmp images, I will later use .png images as it is easier to use alpha channels that blitting images together using code.
I've contacted polipo on his blog, I'm hoping he will reply soon :)

Now, further elaboration on the problem I'm facing.
Below is the sample values that I'm using to draw each tiles.

Image

Looking at the Raise Button part, right now I'm manually adjusting the offsets for it to appear right on top of a wall. In the Format Specification pdf, in section 3.4.3, quoted below is the part I couldn't really put my head around.
When the base wall is drawn, the modifiers should be blitted over it. There
are 53 different types of walls using the same base image. We will call the seed
array to the one having the modifier information of those 53 panels. This array
has indexes from 1 to 53 included.

...

Another modifiers are saved in the seed too. Those modifiers are not boolean
values, they are offsets and sizes. As each stone has a different size the stone
separation offset is saved in the seed.
For the first row, the stones are all the same size and the seed is not needed.
For the second row we have got the first 20 values, ordered from 1 to 20.
From what I understand (correct me if I'm wrong), before a tile is drawn it will refer to this offset value for it to appear correctly. OR I could've misinterpreted it, as it maybe ONLY referring to stone modifiers. If the latter, then how does the original game knows at what location/pixel does the tile have to be drawn, as each tiles is made of different image sizes? Is it hardcoded, and the information is not contained in the DAT files?

Thank you. :)
polipo
Vizier
Vizier
Posts: 89
Joined: September 6th, 2012, 8:34 am

Re: PoP Unity - A remake in the Unity Engine

Post by polipo »

Dear,
I have the same Norbert's opinion, it's a waste of time studing the old DAT's file format.
Norbert has implemented an XML output file, this is the right path, i think the Apoplexy xml output file is not perfect: there are some duplicates tags but can permit to have an editor and all level in your hand.
You have a long and dangerous path ahead you, seek to implement the game logic and animation.
I don't know the dat file format, i don't like it!
I have study all game only with play and look at runtime and read some techical files.
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

Re: PoP Unity - A remake in the Unity Engine

Post by ikazrima »

Dear Polipo,

I may not have been clear before, so I'll say it again to clean things up. :)

The only reason that I've created a DAT reader (emphasize on the reader part) is because I need to know the level structure, as of right now I don't want to manually place each and every tiles and rooms. It is a tedious process to create everything from scratch, so what I did is create a program that extract all the relevant information I need to build a level layout. This has already been done, so I guess we can just leave it just be.

My PoP Unity can already place all tiles as according to the original level files. The problem that I'm facing now is that the images themselves are in the incorrect position, however they are in the correct tile/grid. This is because every image is drawn at the centre of the tile/grid.

Take for example; I define that each grid that holds a tile should be the size of 32*60 (size of a wall image). Each of my image has its pivot in the middle. So if I spawn a wall onto a grid, it will appear correctly because the size just fits. Now if I spawn a skeleton/button/etc. onto the tile, the skeleton will appear to be hanging in the middle of the air as can be seen the image below.

Image

I can manually key in the offsets of the skeleton image so that it appears at the bottom of the grid, but to me that doesn't seem practical as it might not be the most accurate guess. Not to mention that we have several other objects such as tapestry that appears on the top of a grid. I wanted to know if there's anyway that I can get the offsets of each individual tiles, either from the DAT files, or the source code. But as you have pointed out Polipo, it might be better for me to study others implementation such as Norbert's XML approach. I will study them when I got home tonight. Thanks for the tips. ;)

I hope that you catch what I'm saying, and thanks :)
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: PoP Unity - A remake in the Unity Engine

Post by Norbert »

ikazrima wrote:image is drawn at the centre of the tile/grid [...] each grid that holds a tile should be the size of 32*60
The easiest approach will have rectangle images, partially projected on top of each other, each the same size regardless of its contents. This means "32*60" will not be enough. You will need approximately 59x76 pixels for each tile, or (as I wrote in my first post in this thread) double that. The reason to double size everything is that it will allow for higher resolution custom graphics in the future.

Now, where in that 59x76 (or double: 118x152) area to display the tiles? This is something you can figure out manually. Attached to this post are two sample images. (Also mirrored here: 1/1, 2/2.) What you see there is: I pick a tile (first two images in the collage), then I check the foreground and modifier codes (3rd and 4th images), then I make a screenshot of the room from inside the game (top right) and start dissecting the rectangle that I need into two layers.

This may seem like a lot of work, but it's doable. For apoplexy I did this not only for PoP1 but also for PoP2 which has a lot more tile types (environments). To reach/view the third screen in the collage, you press the gear icon in the lower right of the apoplexy program. The second sample (sample 2) has one of the spikes. As you can see, the XML export, level1.xml, has <tile element="2" modifier="2" /> (see A) as the 12th tile/line in <room number="1" />. This matches what apoplexy displays on its main screen and custom tiles screen. If you count tiles from the upper left, the 12th tile (the 2nd tile after the 10 tiles in the top row) has the spikes. Also, the custom tiles screen has foreground code 2 and modifier code 2. The three spikes in the foreground (B) will be in the foreground rectangle, the three spikes in the back (C) plus the platform in the background rectangle. Again, both of these rectangles will be the same size, regardless of how much content they contain. Also, the background (D) will need to be transparent.

Even though this is precision work, it can be done relatively quickly. The bright green in the image on the top right is not just the rectangle. There are also four squares in all the corners. This means that a selection by the green color makes it possible to easily copy-paste the green rectangle on top of screenshots with other tiles. Then all you'd need to do is copy the content from inside the rectangle, double size that, and split those into foreground and background layers with transparent backgrounds. Once the 72 x 4 images are done, everyone could use those for their modern PoP1 programs.

On top of those 72 x 4 images, the XML files will sometimes contain element/modifier combinations that are unknown to you. This is, as can be seen on the custom tiles screen, because it's possible to set a modifier ("mod"). All that does is add 32 to the foreground code. In other words, if the XML file has an element that's 32 or higher, just subtract 32. Example: <tile element="34" modifier="2" /> is the same spike I wrote about earlier, so simply display that spike.
Attachments
sample 2
sample 2
sample 1
sample 1
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

Re: PoP Unity - A remake in the Unity Engine

Post by ikazrima »

Thank you Norbert for your explanation and example! :D

I've made some progress on the tile placement, and will keep you guys updated once I've something new to show you. ;)
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

Re: PoP Unity - A remake in the Unity Engine

Post by ikazrima »

UPDATE

Level 1 example
Image

What you can do with it now :
- Load any POP1 LEVEL.DAT file for level mapping.
- Room and tiles are now placed in the correct position.
- Half of tiles layering are now done and appears correctly.
- You can select a room and move it around (no room snapping yet)
- Various code changes to make it mod friendly for future use.

*I bet some of you thought I've abandoned it, huh? :D

Working on this has been an awesome, fun experience. Once I've get all the tiles to appear correctly I'll upload my first build for you guys to mess around. :cool:
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: PoP Unity - A remake in the Unity Engine

Post by Norbert »

ikazrima wrote:Working on this has been an awesome, fun experience.
Yeah, programming is fun. :)
I'm currently working on an IRC bot, something completely different but also fun to work on.
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

Re: PoP Unity - A remake in the Unity Engine

Post by ikazrima »

Oh, for what purpose? Kicking spammers? :D

Anyways, is there a proper/not so proper guide on the platforming parts of PoP?
I think it is only appropriate for me to work on that next since tiles drawing is almost finished.

Edit :

Also, how far is the progress for FreePrince? I know it's abandoned but I feel like trying it. Is there anywhere I can get a precompiled version?
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: PoP Unity - A remake in the Unity Engine

Post by Norbert »

ikazrima wrote:Oh, for what purpose? Kicking spammers? :D
Mostly to retrieve information from other websites (like Twitter, Wikipedia, Steam).
ikazrima wrote:Anyways, is there a proper/not so proper guide on the platforming parts of PoP?
The disassembly should have pointers, and possibly this PDF file. Then there is PR which can extract all the frames. Finally, there is DOSBox, which can be used to create screenshots of the prince moving around; if I'm not mistaken you can press ESC in-game to skip forward frame by frame. Anyways, that's just some random stuff from the top of my head.
ikazrima wrote:Also, how far is the progress for FreePrince?
To be honest, I wouldn't waste your time looking at its code.
ikazrima wrote:I know it's abandoned but I feel like trying it. Is there anywhere I can get a precompiled version?
A download for Windows can be found here.
polipo
Vizier
Vizier
Posts: 89
Joined: September 6th, 2012, 8:34 am

Re: PoP Unity - A remake in the Unity Engine

Post by polipo »

Dear,
i'm very happy about your progress on PoP Unity.
can PoP Unity editor downloaded for test it?
can Pop Unity editor export an XML file output can be usefull for PoP.net.

Thanks
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: PoP Unity - A remake in the Unity Engine

Post by Norbert »

polipo wrote:can Pop Unity editor export an XML file output can be usefull for PoP.net.
PoP Unity is not a level editor, so it may not be very suitable for XML exporting.
However, ikazrima, if you add this feature, please use the XML format described here.
User avatar
yaqxsw
Wizard Scribe
Wizard Scribe
Posts: 727
Joined: June 18th, 2012, 3:35 pm
Location: Germany

Re: PoP Unity - A remake in the Unity Engine

Post by yaqxsw »

For knowlege ;)
1. Tile fragments.
Foreground: 0/N/31

2. Weird tapest/ttop variants. (Palace only!)
Foreground: 0/N/7 and 0/N/12
Modifier: 64, 128, 160, 192 and 224

3. Weird spikes.
Foreground: 0/N/2
Modifier: 32, 64 and 96

4. Bloody chompers.
Foreground: 0/N/18
Modifier: 128, 129, 130, 131, 132 and 133 (Modifier 130, for example, is a stuck bloody chomper.)

5. Exit doors.
Foreground: 16
Modifier: 32, 64, 253 and 255 (32 is the default)
ikazrima
Efendi
Efendi
Posts: 12
Joined: February 21st, 2014, 6:01 am

Re: PoP Unity - A remake in the Unity Engine

Post by ikazrima »

Ack! Totally forgotten about the existence of this topic :oops: (weird that I didn't get any emails on new replies)

Anyways, if anyone is still interested :
It is still in development, I've switched engine from Unity 4 to Unity 5 recently. (in Unity 4 some critical features are locked behind the pro version, in Unity 5 every features are open up for the personal (read : free) version).

Other than that progress is quite slow, working as a full time game dev has taken over most of my time for the past 8 months.

However, since I've recently switched to full indie I've got some time to revisit this project.

What I plan on doing with PoP Unity :
- A game engine WITH level editor IN GAME. (the placement of the tiles are there, just need to figure how to properly store the tiles structure)*
- Try to replicate the physics of the original game as close as possible (haven't even started on this yet :oops: )
- DAT and XML compatibility for level files**

* I'm in a dilemma whether I should strictly follow the old way of storing the level data. Room by room, or put every tiles as one big room.
** I don't really have the knowledge on parsing XML using C#, I'm considering switching to JSON since I've found a plugin for it. Problem is if I use said plugin, then I might not be able to make the game source public since it is a commercial plugin. I want others to have the ability on modifying the source freely.

I'll find a time to upload a working exe / web player whenever possible.
Post Reply