swars icon indicating copy to clipboard operation
swars copied to clipboard

refactoring: Separate Bullfrog Library from the rest of the code

Open mefistotelis opened this issue 2 years ago • 13 comments

The Bullfrog Library could be changed into a static library, and kept in separate folder. This way it would be much easier to share patches with other Bullfrog games, ie. keeperfx or genewars.

Example of a project where bflibrary is already a separate static lib: https://github.com/mefistotelis/genewars

mefistotelis avatar Apr 22 '22 09:04 mefistotelis

would you eventually move the bflib to 1 repo shared between the games? or just make sure it's similar enough to easily use the other ones as reference? if seperate repo I guess for keeperFx it would be ideal to first wait till there's no more dll dependency but that one would also be the best one to use as a base, as it's the only fully rewritten one then

PieterVdc avatar Jun 01 '22 07:06 PieterVdc

separate repo - I am considering this, but it's probably not the best idea - it means any changes would have to be coordinated between multiple projects, and there isn't enough community to make this work.

best base - keeperfx diverged from the original bullfrog library in some aspects; it's the most complete code base, but not the best source for re-creating original API. I want bflibrary to stay backward compatible for any more games (creations, hi-octane, magic carpet). But I will expand the API to some of KeeperFX changes, ie. defining new video modes to allow custom resolutions.

wait for full rewrite - there is no real need for that. But moving to this library will probably not be a priority - KeeperFX works well enough as is. On the other hand, the API might drift away even further over time. But first, KeeperFX would have to be switched to autotools.

The library will have some benefits for KeeperFX though:

  • ability to choose between SDL1 and SDL2 (not done yet)
  • windows/linux/mac support (already done)

I was also thinking about a switch between hardware/software renderer. That's not easy to achieve while keeping backward compatibility, but still, seem possible. Maybe the HUD could be rendered in a separate layer, and then composited with main screen buffer - like cellphones do.

mefistotelis avatar Jun 01 '22 08:06 mefistotelis

for magic carpet specifically I see a couple of branches of remc2, this one seems like the most active, https://github.com/thobbsinteractive/magic-carpet-2-hd guess a ticket could be made there as well to see if he's interested in aligning as well

PieterVdc avatar Jun 01 '22 15:06 PieterVdc

Yeah, that wouldn't hurt.

mefistotelis avatar Jun 10 '22 19:06 mefistotelis

Progress: Most of the original bflibrary API is now remade and used; missing: Fading - gpalette.c: LbPaletteFade,LbPaletteStopOpenFade (exists in KeeperFX, though modified; we probably want original) Sprite font: gtext.c: LbTextStringWidth, LbTextStringHeight, LbTextDraw (exists in KeeperFX; modified, but those are good modifications) Polygon rendering: poly.c (whole) Other: rom.c:int prop_text, make_fade_table, qaz

Other needed stuff: Support of custom resolutions - to be copied from KeeperFX Support of SDL2 - not started Unified parsing of INI files - to be developed base on KeeperFX Support of scaled fonts - to be copied from KeeperFX

mefistotelis avatar Jun 15 '22 15:06 mefistotelis

Progress: Fading is now remade Sprite fonts are remade, though not well tested Polygon rendering - there are 3 functions: trig(), poly_line() and draw_gpoly() -- trig() is remade, and the C version works exactly as original. It is also compatible with KeeperFX - tested that today -- poly_line() is not remade -- draw_gpoly() - I see considerable differences in this function between Dungeon Keeper and Syndicate Wars. I didn't decided yet how to approach this (whether I should rewrite DK version or SW version). Other: rom.c:int prop_text, make_fade_table - remade, qaz - removed, as it is unnecessary in C implementation.

mefistotelis avatar Aug 09 '22 13:08 mefistotelis

ah nice, keeperFx is getting close getting rid of dll, good to know some of the asm can be taken from here

PieterVdc avatar Aug 09 '22 13:08 PieterVdc

@mefistotelis I can provide the source code to gpoly.asm if you like. It has a set of macros which controls the assembled output - so that might be why the implementations are different.

IntelOrca avatar Nov 11 '22 02:11 IntelOrca

keeperfx started on rewriting some of the asm here, atm still draft https://github.com/dkfans/keeperfx/pull/3129

PieterVdc avatar Apr 07 '24 11:04 PieterVdc

That's great. Though it's unlikely to help with Syndicate Wars. I stopped working on draw_gpoly rewrite mostly because I was unable to consolidate DK and SW versions - they are too different.

Maybe like @IntelOrca suggested, it is driver by macros too much.

mefistotelis avatar Apr 07 '24 11:04 mefistotelis