Author Topic: Let's talk about bmpman  (Read 14009 times)

0 Members and 1 Guest are viewing this topic.

Offline Bryan See

  • Has anyone really been far as decided to use even go want to do look more like?
  • 210
  • Trying to redeem, but under Tiger Parents
    • Skype
    • Steam
    • Twitter
Re: Let's talk about bmpman
Now, given modern coding practices, it could be made better. That's what we're trying to do here, but remaking something just because it's old is stupid when you do not know exactly why you're doing it, which in this case means knowing what the subtle issues are that cause problems.

Quote
The maximum number of bitmaps and repetitive items are the problems we're running into.

No, it's not. That's the surface level issue, and if it was the actual issue, we could just increase the number of bitmap slots and be done with it. Just like your attempts at raising the number of asteroids or changing path lengths, if it was just an issue of adjusting the value of one constant, we'd have done it long ago.
The actual problem goes deeper. And you, quite frankly, do NOT have the experience with the engine or C/C++ required to fix it. [/quote]

I get it, as I intend to do some code refactoring on it. As for my attempts at raising the number of asteroids (to my intended 1024, though it's raised from 256 to 512, short of that) or changing path lengths, I will re-visit these at some point in the future.

Two tasks.
One. Explain what the keyword "static" in C/C++ does, and what behaviour your specific usage here will result in.
Two. Explain what a "Template" in C++ is, and what it does in this code snippet of yours.

The static keyword is used to declare variables and functions at global scope, namespace scope, class scope and local scope. Static objects or variables are allocated when the program starts and is deallocated when the program ends. In this case here, an ID is initialized upon starting FSO, and it deallocated when FSO closes.

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. Here in my code snippet, type is a placeholder name for a data type used by the function. This name can be used within the function definition - in this case, get an ID for a bitmap entry.

I know C/C++ a decade ago, bolstered thanks to my college studies, which is starting to pay off.
Bryan See - My FreeSpace Wiki User Page (Talk, Contributions)

Full Projects:
Shattered Stars

Campaigns:
Lost in the Mist - Cyrene vs. Psamtik
FreeSpace: Reunited

Ships:
GTS Hygeia, GTT Argo, SC Raguel

Tools:
FSO TC/Game template

I've been under attack by Tiger Parents like Jennifer Pan...

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Let's talk about bmpman
The static keyword is used to declare variables and functions at global scope, namespace scope, class scope and local scope. Static objects or variables are allocated when the program starts and is deallocated when the program ends. In this case here, an ID is initialized upon starting FSO, and it deallocated when FSO closes.

See, I can kinda see why you did this the way you did, but it doesn't look like a well thought-out design to me. You are using a design pattern that is used nowhere else in FSO, and one that is deeply unintuitive to boot (If only because of naming issues; "get_id" does not sound like the kind of function that should have global side effects the way it does in your snippet there).
Secondly, I think you're mistaking the high-level intent ("Bitmap ids should be unique and valid throughout the lifetime of the program") for a low-level implementation detail.

Quote
Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. Here in my code snippet, type is a placeholder name for a data type used by the function. This name can be used within the function definition - in this case, get an ID for a bitmap entry.

Why do you believe that templates are useful here? There is nothing in the bm_entry struct that needs to have templating applied to it.

Again, your understanding of C/C++, the engine, and now apparently software design principles, is not at the level required to do this sort of work. If you want to help out, you should pick an easier project first, because right now, we'd have to hold your hand through the entire process. We have neither the time nor the inclination to do so.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Bryan See

  • Has anyone really been far as decided to use even go want to do look more like?
  • 210
  • Trying to redeem, but under Tiger Parents
    • Skype
    • Steam
    • Twitter
Re: Let's talk about bmpman
What kind of easy project within SCP I can pick, The E? I wanted to help out the SCP, after all of these false starts happened back in 2009 prior to my college days... I think it's simply due to my current programming level, which is below the level needed to do this sort of work. I'm making my Shattered Stars campaign/mod. This thread is nothing but a discussion about what to do with BMPMAN, which you said is almost hitting its limits.
Bryan See - My FreeSpace Wiki User Page (Talk, Contributions)

Full Projects:
Shattered Stars

Campaigns:
Lost in the Mist - Cyrene vs. Psamtik
FreeSpace: Reunited

Ships:
GTS Hygeia, GTT Argo, SC Raguel

Tools:
FSO TC/Game template

I've been under attack by Tiger Parents like Jennifer Pan...

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: Let's talk about bmpman
A great way to learn the code (albeit with a steep learning curve) is by tracing through it to track down bugs.  There are plenty of bugs in Mantis, and some are simple enough that a person with little code expertise could squash them in a couple hours.

Here is one with a pretty straightforward fix.  There are others as well.

 

Offline Bryan See

  • Has anyone really been far as decided to use even go want to do look more like?
  • 210
  • Trying to redeem, but under Tiger Parents
    • Skype
    • Steam
    • Twitter
Re: Let's talk about bmpman
Thanks. I'll look into it.

Now then, back to the discussion on how BMPMAN should be changed according to the times where highly modern computers are in use.
Bryan See - My FreeSpace Wiki User Page (Talk, Contributions)

Full Projects:
Shattered Stars

Campaigns:
Lost in the Mist - Cyrene vs. Psamtik
FreeSpace: Reunited

Ships:
GTS Hygeia, GTT Argo, SC Raguel

Tools:
FSO TC/Game template

I've been under attack by Tiger Parents like Jennifer Pan...

 

Offline z64555

  • 210
  • Self-proclaimed controls expert
    • Minecraft
    • Steam
Re: Let's talk about bmpman
 :blah: um. ok.

Anyway. Just a heads up, I should be "useful" starting near the end of this month or maybe by mid-January. Finally got some life stuffs out of the way.

Something that would really help BMPMAN in terms of maintainability is the usage of some standard containers such as the dense_hash_map by boost (I think). If someone can get a logic flow chart of BMPMAN in action as well as some use cases in graphic form, that should help the rest of the team get a general idea of what's going on.

AFAIK, the actual image data for each texture/map is stored on the heap, while the management structure is stored on a proprietary container.

I also read somewhere that the old MacOS memory system used a lookup table and handle system, which sounds awfully like BMPMAN. Could be worth investigation.
Secure the Source, Contain the Code, Protect the Project
chief1983

------------
funtapaz: Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Juche.
z64555: s/J/Do
BotenAlfred: <funtapaz> Hunchon University biologists prove mankind is evolving to new, higher form of life, known as Homopithecus Douche.

 

Offline niffiwan

  • 211
  • Eluder Class
Re: Let's talk about bmpman
well, since I've been spelunking in bmpman for adding apngs, have my brain dump on the use cases for animations. Please post any corrections or additions required!

General
The "management structure" is an array of bitmap_entry structs
The following functions are in loose order of how a bitmap slot travels through its lifecycle
  bm_load: creates & populates a new slot; does not load image data
  bm_load_animation: like bm_load except for animations
  bm_create: creates & populates a new slot; slot is created as a USER slot which means data *is* loaded when this function runs and bmpman won't allocate/load it
  bm_lock: load image data for a slot (heap allocated); knows how to handle every type of image file supported by FSO; can also convert image data between different bit depths
  bm_unlock: reduces the reference count on a slot (nothing else!)
  bm_unload: free's the image data but leaves the rest of the slot alone; a slot must be unlocked to be unloaded
  bm_release: free's the image data & resets the slot so it can be reused; ignores slots that are locked or loaded

Streaming animations
ani's (and apngs when done) use a single bmpman slot created by bm_create (i.e. type USER so allocate that data yourself); each frame has its data loaded into the same slot when the frame is displayed
eff's use two slots created by bm_load; 1st slot gets the 1st frames data (I think?), 2nd slot gets all the other frames data loaded in as required

Non-streaming animations
All frames are loaded into sequential/contiguous slots; the slots are allocated by bm_load_animation; much of the code that accesses animations assumes that frame X is at the slot of frame 0 + X
bm_lock/bm_unload/bm_release affect all frames in an animation (bm_unlock doesn't though?)
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...