diasurgical / devilutionX

Diablo build for modern operating systems
Other
8.12k stars 796 forks source link

Adding birds to town #3545

Open AJenbo opened 3 years ago

AJenbo commented 3 years ago

The PlayStation version had birds in town. It would be nice to also have this as an option.

sw

Rendered all angles: raven-8bit.zip (you can use pngs2cel to convert it to cl2)

You will need to split up the different animation cycles before converting as they are just done as one continuous animation in a single folder.

Birds should be lightly spread over town and fly away when players get close. Probably implemented as a towner similar to cows.

https://youtu.be/7nKwF-nSNgs?t=159

Model and animation: https://sketchfab.com/3d-models/crow-d5a9b0df4da3493688b63ce42c8a83e2

matheusgomes28 commented 3 years ago

This looks fun, I'll look at it if no one has started. I need to learn how animations are rendered in the engine first πŸ˜‹ , I also have no idea where to find the town.pal file needed for the converter haha

qndel commented 3 years ago

This looks fun, I'll look at it if no one has started. I need to learn how animations are rendered in the engine first πŸ˜‹ , I also have no idea where to find the town.pal file needed for the converter haha

probably in diabdat.mpq

ThomasChr commented 3 years ago

@matheusgomes28 Great! Tell me if you need any help. I also havenβ€˜t got any experience in diablo animations though :-)

matheusgomes28 commented 3 years ago

So: I've been looking into CEL and CL2 files, and tried to replicate how the cow animation gets created. These are the steps I've gone through:

  1. Created a CL2 file with the data under the n directory. I was intending to use this for every direction to start with then split all animations later.
  2. Created a new Towner for the birds and an Init function for it.
  3. In the InitTowners function, loaded the cl2 file with LoadFileInMem to a buffer BirdCels.
  4. In the BirdInit function, I set the animation to all directions to CelGetFrame(BirdCels.get(), 0), I assume the 0 (frame) is refers to the frame data you want returned.

After placing a bird near the fountain in town, the game... crashed! It crashes in LoadLE16(...) called by CelGetFrameClipped(...). So I assumed there's was something wrong with my data setup. Then I realised that the function CelGetFrame was probably meant for CEL files, not CL2.

I later made a CEL file with the same pictures, in the same directory, but still... crashed on the same call.

I'm now digging into CL2 files a little bit more, found this useful repo that explains the format. But still, I guess I just understand how the animations are loaded in D1, hence it will probably take me a few more days to go through it all.

Btw, there's a subtle bug in LoadFileInMem. Absolute paths to disk locations only work for unix-like paths. If you try and load a disk file on Windows (such as D:/something/hello.cel), it will fail as it will attempt to load that path from the MPQ. I had to modify the function and SFile to make this work temporarily.

Just an update, will take a little longer for me to grasp this stuff.

AJenbo commented 3 years ago

players and monsters are CL2, the cow is a bit of a special case being CL2 with CEL headers i belive. Towners are CEL

matheusgomes28 commented 2 years ago

@ThomasChr Is the help offer still there? I've spent some time on this a couple of weeks ago, converted some of the animations to "cel" and "cel2" formats. I've attempted to add bird towners with the animations but I keep getting some memory access errors when the animation is read in.

I'll get a trace of this tonight whenever I get back to my laptop and I'll post it here.

It would be very nice if someone knew how to properly load "cel" files in, because I am clearly struggling πŸ˜† I've even started writing a "cel" reader to understand the format a little better....

ThomasChr commented 2 years ago

Hi @matheusgomes28! Of course! Do you have the branch pushed? Then I could take a look on the crash. As I understand AJenbo there should be already working CEL Formats in devX, so I would try to go from there. No promises though :-)

qndel commented 2 years ago

Hi @matheusgomes28! Of course! Do you have the branch pushed? Then I could take a look on the crash. As I understand AJenbo there should be already working CEL Formats in devX, so I would try to go from there. No promises though :-)

Original d1 graphics are in CEL / CL2 formats so they always worked - how else would we load the graphics at all? lol

matheusgomes28 commented 2 years ago

@ThomasChr The draft PR is here, notice that I'm loading a cel file from disk so you might wanna replace the hardcoded path! The cel file in question was obtained by using the pngs2cel tool @AJenbo has recommended, I simply converted one of the direction png directories into a cel, with the town.pal colours.

I'm going to keep digging into this tonight since work isn't so busy at the moment, I'll update this thread if I manage to figure out how to load any given cel file properly πŸ˜†

AJenbo commented 2 years ago

I would suggest using cl2 instead of cel, it's a lot more sensible for something that has more then 1 angle.

The cow is actually a mix between cel and cl2 so i suggest not looking at it for reference as it will probably just confuse you. Instead look at a monster.

matheusgomes28 commented 2 years ago

I would suggest using cl2 instead of cel, it's a lot more sensible for something that has more then 1 angle.

The cow is actually a mix between cel and cl2 so i suggest not looking at it for reference as it will probably just confuse you. Instead look at a monster.

I tried CL2 first, also crashes as I'm probably not putting the correct params in the towner animations. My thought process was: maybe if I get cel working, I'll be able to get CL2 after that... But yes, I'll look at monsters instead of Cows now. Cheers for the advice dude!

AJenbo commented 2 years ago

But where does it crash :)

This is where towner an monster rendering diverges. https://github.com/diasurgical/devilutionX/blob/master/Source/scrollrt.cpp#L759

ThomasChr commented 2 years ago

@matheusgomes28 grafik I think those files are not in your branch, could you upload them here?

matheusgomes28 commented 2 years ago

@ThomasChr Sorry for the delay. That file was generated with the pngs2cel tool, I used one of the direction folders to create the cel/cl2 files. I've pushed the file "bird.cl2" in the root folder of the repo. At the current state, just put that file somewhere and change the path in "towners.cpp".

I'm making some changes to load the file from the "assets" directory as @AJenbo pointed out.

matheusgomes28 commented 2 years ago

@ThomasChr Sorry for the delay. That file was generated with the pngs2cel tool, I used one of the direction folders to create the cel/cl2 files. I've pushed the file "bird.cl2" in the root folder of the repo. At the current state, just put that file somewhere and change the path in "towners.cpp".

I'm making some changes to load the file from the "assets" directory as @AJenbo pointed out.

Ignore that ^

The new state of the branch adds the "bird.cl2" file as an asset and sets up a towner with that as the animation. You can see the crash if you start the game and go into town, top left of the fountain! I'll be doing some more digging into how to properly setup the animations.

AJenbo commented 2 years ago

Towners are hardcoded to be rendered with cel so it will definatly crash if you load a cl2 with no modefications to the render logic

matheusgomes28 commented 2 years ago

Towners are hardcoded to be rendered with cel so it will definatly crash if you load a cl2 with no modefications to the render logic

@AJenbo I tried generating both "cel" and "cl2" formats with the towner renderers. I'll add the "cel" logic today and I'll try again. As far as I remember, rendering "cel" files was also crashing for me, implying I'm messing something up !