azihassan / devilutionX

Diablo build for modern operating systems
Other
4 stars 1 forks source link

RAM limitations #7

Open azihassan opened 1 month ago

azihassan commented 1 month ago

According to this reply and this one, the game requires 32 MB of RAM. The Dreamcast has 16 MB and 8 MB of VRAM, so I'm not sure if it's enough to meet the requirements.

So far, the game crashed with an out of memory error once when I was storing save files in RAM. It didn't crash when I retried, probably because it generated a less ambitious level, but I estimate that the save files were using about 1 MB of RAM at that point.

I tested the first hell level on emulator (in multiplayer mode) and it didn't crash in the loading screen, but more tests need to be conducted to make sure that the game is playable in its entirety.

AJenbo commented 1 month ago

Multiplayer uses more run time memory where singeplayer use larger save games (they are sued as swap files for level info). Of cause if you don't have much space for saving that isn't really any help :)

azihassan commented 1 week ago

Update: I played through the hell levels on Flycast but it eventually OOMed on the 16th level. I'll try again without sound

https://github.com/user-attachments/assets/4071074c-7d4f-43b9-9982-1dcba1315c1f

AJenbo commented 1 week ago

sooo close

azihassan commented 4 days ago

I changed trigs.cpp to get the hell entry to throw me right into level 16 to make testing easier. After narrowing down the crash to InitAllMonsterGFX, I sprinkled some RAM logging statements thanks to ian micheal's logging module from Discord. malloc_stats only reports 10 MBs (in max system bytes below) during the crash which made it unreliable. Never mind the PVR part in the logs, I disabled it because I didn't want to accidentally mess with SDL:

INFO: Loading monster graphics: golem\golem     x1

---------
RAM stats (MB):
Total: 16.00, Free: 3.17, Used: 12.83, PVR: 0.00
---------
max system bytes =   10199744
system bytes     =   10199744
in use bytes     =    9763312
INFO: 

INFO: Loaded monster graphics: golem\golem      297 KiB   x1

---------
RAM stats (MB):
Total: 16.00, Free: 2.88, Used: 13.12, PVR: 0.00
---------
max system bytes =   10506944
system bytes     =   10506944
in use bytes     =   10067672
INFO: 

INFO: Loading monster graphics: diablo\diablo   x1

---------
RAM stats (MB):
Total: 16.00, Free: 2.88, Used: 13.12, PVR: 0.00
---------
max system bytes =   10506944
system bytes     =   10506944
in use bytes     =   10067672
INFO: 

Out of memory. Requested sbrk_base 0x8d06a000, was 0x8cd1f000, diff 3452928
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
arch: aborting the system

It reaches the limit when it attempts to load the diablo*.clx files, which occupy 3.3ish megs:

# https://www.baeldung.com/linux/sum-the-size-of-files#1-using-awk-to-sum-file-sizes
$ ls -l build/data/diabdat/monsters/diablo/*.clx | awk '{ sum += $5 } END{ print sum/1024/1024 }'
3.29322

The diablo walking animation (diablow.clx) is the smallest one at 236 kB. I replaced all the other animations with it (1.6 megs total) and the level loaded, but for some reason I got instakilled by a large horde of monsters. I think it's because I messed with the triggers, I suspect it's loading monsters from levels 15 and 14 as well because this issue didn't happen when I restored the trigger and loaded the game with the 32 MB extension enabled on Flycast.

The next thing I'm gonna try is to look for a way to downgrade the animations to make them smaller in size. Another option is to try and skip the death/win initially (diablod.clx, 817 kB and diablon.clx I think, 648 kB), and load them when the time is right (after freeing the regular walk/attack/spell animations ones). This way we gain 1.4 megs without degrading the quality, but I think that change might be too invasive.

azihassan commented 4 days ago

@AJenbo I looked into the animations with https://github.com/diasurgical/d1-graphics-tool. I was initially thinking of keeping half the sprites in each animation (keep 1/x, skip 2/x, keep 3/x), would this have an effect on game logic? I'm worried about it affecting things like hitboxes

AJenbo commented 4 days ago

The game originally didn't use the graphics for hitbox at all and instead used tiles and a set number for each monster type. It's only something we are adding in the next release for mouse select and dropping frames won't have a negative on it.

The engine does support playing animations at different speeds.

Dropping half the frames is also on of the cuts the PlayStation did.