Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove 50% frames in diablo death and standby animations
Browse files Browse the repository at this point in the history
- remove all death animations for knights (blackd.clx) except for the
south-facing one (because they all look similar) and turn knight
monsters south after they die and before the animation is loaded
azihassan committed Dec 1, 2024
1 parent a01d52c commit 459f50e
Showing 11 changed files with 170 additions and 13 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/dreamcast.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Sega Dreamcast

on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
push:
branches:
- master
@@ -84,6 +84,15 @@ jobs:
run: |
source /opt/toolchains/dc/kos/environ.sh && cd build && kos-make
- name: Patch RAM-heavy assets
run: |
[ -e build/data/diabdat ] && \
cp build/data/diabdat/monsters/snake/snakbl.trn build/data/diabdat/monsters/snake/snakb.trn && \
cp blackd.clx build/data/diabdat/monsters/black/blackd.clx && \
cp diablod.clx build/data/diabdat/monsters/diablo/diablod.clx && \
cp diablon.clx build/data/diabdat/monsters/diablo/diablon.clx && \
patch build/data/txt/monsters/monstdat.tsv -l -p0 < monstdat.patch
- name: Generate .cdi
run: |
source /opt/toolchains/dc/kos/environ.sh && \
33 changes: 21 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ RUN git clone https://github.com/diasurgical/devilutionx-mpq-tools/ && \

RUN echo "Cloning project..."
WORKDIR /opt/toolchains/dc/kos/
RUN git clone -b dreamcast https://github.com/azihassan/devilutionX.git
RUN git clone -b fix/ISSUE-7-ram-limitations https://github.com/azihassan/devilutionX.git

RUN echo "Uninstall kos-ports SDL 1.2..."
RUN source /opt/toolchains/dc/kos/environ.sh && \
@@ -25,20 +25,21 @@ RUN git clone -b SDL-dreamhal--GLDC https://github.com/GPF/SDL-1.2 && \
cp include/* /usr/include/SDL/

WORKDIR /opt/toolchains/dc/kos/devilutionX
RUN echo "Downloading and unpacking spawn.mpq..."
RUN curl -LO https://raw.githubusercontent.com/d07RiV/diabloweb/3a5a51e84d5dab3cfd4fef661c46977b091aaa9c/spawn.mpq && \
unpack_and_minify_mpq spawn.mpq && \
rm spawn.mpq

RUN echo "Downloading and unpacking fonts.mpq..."
RUN curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/fonts.mpq && \
unpack_and_minify_mpq fonts.mpq && \
rm fonts.mpq

#WORKDIR /opt/toolchains/dc/kos/devilutionX
#RUN echo "Copying and unpacking diabdat.mpq..."
#COPY DIABDAT.MPQ .
#RUN unpack_and_minify_mpq DIABDAT.MPQ
#spawn version
#RUN echo "Downloading and unpacking spawn.mpq..."
#RUN curl -LO https://raw.githubusercontent.com/d07RiV/diabloweb/3a5a51e84d5dab3cfd4fef661c46977b091aaa9c/spawn.mpq && \
# unpack_and_minify_mpq spawn.mpq && \
# rm spawn.mpq

#full version
RUN echo "Copying and unpacking diabdat.mpq..."
COPY DIABDAT.MPQ .
RUN unpack_and_minify_mpq DIABDAT.MPQ

RUN echo "Configuring CMake..."
RUN source /opt/toolchains/dc/kos/environ.sh && \
@@ -50,11 +51,19 @@ RUN source /opt/toolchains/dc/kos/environ.sh && \
RUN echo "Compiling..."
RUN source /opt/toolchains/dc/kos/environ.sh && cd build && kos-make

RUN echo "Patching RAM-heavy assets..."
RUN [ -e build/data/diabdat ] && \
cp build/data/diabdat/monsters/snake/snakbl.trn build/data/diabdat/monsters/snake/snakb.trn && \
cp blackd.clx build/data/diabdat/monsters/black/blackd.clx && \
cp diablod.clx build/data/diabdat/monsters/diablo/diablod.clx && \
cp diablon.clx build/data/diabdat/monsters/diablo/diablon.clx && \
patch build/data/txt/monsters/monstdat.tsv -l -p0 < monstdat.patch

RUN echo "Generating CDI"
RUN source /opt/toolchains/dc/kos/environ.sh && \
mv spawn build/data/spawn && \
#mv spawn build/data/spawn && \
mv fonts/fonts/ build/data/fonts/ && \
#mv diabdat build/data/diabdat && \
mv diabdat build/data/diabdat && \
mkdcdisc -e build/devilutionx.elf -o build/devilutionx.cdi --name 'Diablo 1' -d build/data/

ENTRYPOINT ["sh", "-c", "source /opt/toolchains/dc/kos/environ.sh && \"$@\"", "-s"]
1 change: 1 addition & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ include(functions/devilutionx_library)
include(functions/genex)

set(libdevilutionx_SRCS
memory_stats.cpp
appfat.cpp
automap.cpp
capture.cpp
63 changes: 63 additions & 0 deletions Source/memory_stats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// DREAMCAST memory stats related code

#include "memory_stats.h"

#include <dc/pvr.h>

#include <malloc.h>
#include <stdio.h>

static unsigned long systemRam = 0x00000000;
static unsigned long elfOffset = 0x00000000;
static unsigned long stackSize = 0x00000000;

extern unsigned long end;
extern unsigned long start;

#define _end end
#define _start start
void print_VRAM_stats()
{
pvr_mem_available();
}

void set_system_ram()
{
systemRam = 0x8d000000 - 0x8c000000;
elfOffset = 0x8c000000;

stackSize = (int)&_end - (int)&_start + ((int)&_start - elfOffset);
}

unsigned long get_system_ram()
{
return systemRam;
}

unsigned long get_free_ram()
{
struct mallinfo mi = mallinfo();
return systemRam - (mi.usmblks + stackSize);
}

void print_ram_stats()
{
float sys_ram, free_ram, used_ram, pvr_ram;
sys_ram = (float)get_system_ram() / (float)(1024 * 1024);
free_ram = (float)get_free_ram() / (float)(1024 * 1024);
used_ram = (sys_ram - free_ram);
// pvr_ram = (float)pvr_mem_available() / (float)(1024*1024);

printf("\n---------\nRAM stats (MB):\nTotal: %.2f, Free: %.2f, Used: %.2f, PVR: %.2f\n---------\n", sys_ram, free_ram, used_ram, pvr_ram);
// printf("\n---------\nRAM stats (MB):\nTotal: %.2f, Free: %.2f, Used: %.2f\n---------\n", sys_ram, free_ram, used_ram);
}

void get_ram_stats(float *sys_ram, float *free_ram, float *used_ram, float *pvr_ram)
{
*sys_ram = (float)get_system_ram() / (float)(1024 * 1024);
*free_ram = (float)get_free_ram() / (float)(1024 * 1024);
*used_ram = (*sys_ram - *free_ram);
if (pvr_ram) {
//*pvr_ram = (float)pvr_mem_available() / (float)(1024*1024);
}
}
11 changes: 11 additions & 0 deletions Source/memory_stats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __MEMORY_STATS_H__
#define __MEMORY_STATS_H__ 1

void set_system_ram();
void print_VRAM_stats();
unsigned long get_system_ram();
unsigned long get_free_ram();
void print_ram_stats();
void get_ram_stats(float *sys_ram, float *free_ram, float *used_ram, float *pvr_ram);

#endif
36 changes: 36 additions & 0 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
@@ -54,6 +54,9 @@
#ifdef _DEBUG
#include "debug.h"
#endif
#ifdef __DREAMCAST__
#include "memory_stats.h"
#endif

namespace devilution {

@@ -1441,6 +1444,14 @@ void ShrinkLeaderPacksize(const Monster &monster)

void MonsterDeath(Monster &monster)
{
#ifdef __DREAMCAST__
// knights only have south death animation in the dreamcast port
// the death animations are similar because they show the knight rotate into the ground
// so I removed the other ones for less RAM usage (1018 kB down to 171 kB)
if (monster.type().type == MT_NBLACK || monster.type().type == MT_RTBLACK || monster.type().type == MT_BTBLACK || monster.type().type == MT_RBLACK) {
monster.direction = Direction::South;
}
#endif
monster.var1++;
if (monster.type().type == MT_DIABLO) {
if (monster.position.tile.x < ViewPosition.x) {
@@ -3449,6 +3460,15 @@ void InitMonsterGFX(CMonster &monsterType, MonsterSpritesData &&spritesData)
GetMissileSpriteData(MissileGraphicID::DiabloApocalypseBoom).LoadGFX();
}

#ifdef __DREAMCAST__
void print_memory_usage()
{
set_system_ram();
print_ram_stats();
Log("\n\n\n");
}
#endif

void InitAllMonsterGFX()
{
if (HeadlessMode)
@@ -3467,6 +3487,10 @@ void InitAllMonsterGFX()
CMonster &firstMonster = LevelMonsterTypes[monsterTypes[0]];
if (firstMonster.animData != nullptr)
continue;
#ifdef __DREAMCAST__
LogVerbose("Loading monster graphics: {:15s} x{:d}", firstMonster.data().spritePath(), monsterTypes.size());
print_memory_usage();
#endif
MonsterSpritesData spritesData = LoadMonsterSpritesData(firstMonster.data());
const size_t spritesDataSize = spritesData.offsets[GetNumAnimsWithGraphics(firstMonster.data())];
for (size_t i = 1; i < monsterTypes.size(); ++i) {
@@ -3475,6 +3499,9 @@ void InitAllMonsterGFX()
InitMonsterGFX(LevelMonsterTypes[monsterTypes[i]], std::move(spritesDataCopy));
}
LogVerbose("Loaded monster graphics: {:15s} {:>4d} KiB x{:d}", firstMonster.data().spritePath(), spritesDataSize / 1024, monsterTypes.size());
#ifdef __DREAMCAST__
print_memory_usage();
#endif
totalUniqueBytes += spritesDataSize;
totalBytes += spritesDataSize * monsterTypes.size();
InitMonsterGFX(firstMonster, std::move(spritesData));
@@ -3795,6 +3822,15 @@ void MonsterDeath(Monster &monster, Direction md, bool sendmsg)
if (monster.mode != MonsterMode::Petrified) {
if (monster.type().type == MT_GOLEM)
md = Direction::South;
#ifdef __DREAMCAST__
// knights only have south death animation in the dreamcast port
// the death animations are similar because they show the knight rotate into the ground
// so I removed the other ones for less RAM usage (1018 kB down to 171 kB)
if (monster.type().type == MT_NBLACK || monster.type().type == MT_RTBLACK || monster.type().type == MT_BTBLACK || monster.type().type == MT_RBLACK) {
md = Direction::South;
monster.direction = Direction::South;
}
#endif
NewMonsterAnim(monster, MonsterGraphic::Death, md, gGameLogicStep < GameLogicStep::ProcessMonsters ? AnimationDistributionFlags::ProcessAnimationPending : AnimationDistributionFlags::None);
monster.mode = MonsterMode::Death;
} else if (monster.isUnique()) {
17 changes: 17 additions & 0 deletions Source/to_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i DiabloUI/mainmenu.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i appfat.h &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i controls/devices/joystick.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i diablo.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i init.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i interfac.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i loadsave.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i main.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i msg.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i pfile.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i pfile.h &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i platform/locale.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i utils/display.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i utils/file_util.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i utils/paths.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i utils/sdl2_to_1_2_backports.cpp &&
docker run --rm -it -v $(pwd):/app -w /app devilutionx-sdl2 clang-format -style=file -i utils/sdl_compat.h
Binary file added blackd.clx
Binary file not shown.
Binary file added diablod.clx
Binary file not shown.
Binary file added diablon.clx
Binary file not shown.
11 changes: 11 additions & 0 deletions monstdat.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- assets/txtdata/monsters/monstdat.tsv 2024-10-07 01:53:20.352087707 +0100
+++ monstdat.tsv 2024-12-01 00:14:59.000000000 +0100
@@ -109,7 +109,7 @@
MT_CABALIST Cabalist mage\mage mage\cnselgd Retail 128 2000 true false 12,1,20,8,28,20 1,1,1,1,1,1 15 16 29 120 120 Counselor CAN_OPEN_DOOR 2 110 8 14 30 0 0 0 0 0 Demon RESIST_MAGIC,RESIST_FIRE,IMMUNE_LIGHTNING IMMUNE_MAGIC,RESIST_FIRE,IMMUNE_LIGHTNING Bottom,Middle,Top 4929
MT_ADVOCATE Advocate mage\mage mage\cnselbk Retail 128 2000 true false 12,1,20,8,28,20 1,1,1,1,1,1 16 16 30 145 145 Counselor CAN_OPEN_DOOR 3 120 8 15 25 0 0 0 0 0 Demon IMMUNE_MAGIC,RESIST_FIRE,IMMUNE_LIGHTNING IMMUNE_MAGIC,IMMUNE_FIRE,IMMUNE_LIGHTNING Bottom,Middle,Top 4968
MT_GOLEM Golem golem\golem golem\golm Never 96 386 true false 0,16,12,0,12,20 1,1,1,1,1,1 1 1 12 1 1 Golem CAN_OPEN_DOOR 0 0 7 1 1 0 0 0 0 1 Demon 0
-MT_DIABLO The Dark Lord diablo\diablo Never 160 2000 true true 16,6,16,6,16,16 1,1,1,1,1,1 26 26 45 3333 3333 Diablo KNOCKBACK,SEARCH,CAN_OPEN_DOOR 3 220 4 30 60 0 11 0 0 90 Demon IMMUNE_MAGIC,RESIST_FIRE,RESIST_LIGHTNING IMMUNE_MAGIC,RESIST_FIRE,RESIST_LIGHTNING Bottom,Middle,Top 31666
+MT_DIABLO The Dark Lord diablo\diablo Never 160 2000 true true 8,6,16,6,8,16 1,1,1,1,2,1 26 26 45 3333 3333 Diablo KNOCKBACK,SEARCH,CAN_OPEN_DOOR 3 220 4 30 60 0 11 0 0 90 Demon IMMUNE_MAGIC,RESIST_FIRE,RESIST_LIGHTNING IMMUNE_MAGIC,RESIST_FIRE,RESIST_LIGHTNING Bottom,Middle,Top 31666
MT_DARKMAGE The Arch-Litch Malignus darkmage\dmage darkmage\dmag Never 128 1060 true false 6,1,21,6,23,18 1,1,1,1,1,1 21 21 30 160 160 Counselor CAN_OPEN_DOOR 3 120 8 20 40 0 0 0 0 70 Demon RESIST_MAGIC,RESIST_FIRE,RESIST_LIGHTNING IMMUNE_MAGIC,IMMUNE_FIRE,IMMUNE_LIGHTNING Bottom,Middle,Top 4968
MT_HELLBOAR Hellboar fork\fork newsfx\hboar Retail 188 800 false false 10,10,15,6,16,0 2,1,1,1,1,1 17 18 23 80 100 SkeletonMelee KNOCKBACK,SEARCH 2 70 7 16 24 0 0 0 0 60 Demon RESIST_FIRE,RESIST_LIGHTNING Bottom,Middle 750
MT_STINGER Stinger scorp\scorp newsfx\stingr Retail 64 305 false false 10,10,12,6,15,0 2,1,1,1,1,1 17 18 22 30 40 SkeletonMelee 3 85 8 1 20 0 0 0 0 50 Animal RESIST_LIGHTNING Bottom 500

0 comments on commit 459f50e

Please sign in to comment.