Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Made a Function to scroll multiple sections of a background.
#2
Hi!

I'm glad you're doing progress, and thanks for contributing your code.

It's always good to have reusable code, that's the point of having functions and modules!. However, your function should be placed in a layer above Tilengine, but not inside the engine itself. Why? Because the engine is designed to be a general purpose virtual VDP. The engine provides tools and mechanisms to implement other things, but these new things are outside of the scope. Using raster effects to alter layer start offset can be used to create region scrolling, like your function does. But it can also be used to implement linescroll (pseudo-3D floor), heat/water wavy distortion, barrel distortion, fake vertical scaling, aiding fake rotation combined with column offset... many different applications! It wouldn't be feasible to "cook" each imaginable effect inside the engine itself. The more prebuilt functions you put inside a tool, the less flexible it becomes.

That's why this kind of utility functions are placed above the engine, to be reused at your will. For example rendering text using tile-based fonts, do reflections, create a virtual camera for mode-7 like games... there are countless things that can be automated and reused and would make a great "toolkit" library. In fact Microsoft used this approach with Direct3D9: D3D9 contained the core, low-level graphics API, and D3DX9 ("x" for eXtension) provided additional functionality on top of it.

Regarding your function, I understand what it does, but let me point some issues:
  • "direction" parameter should be called "factor", because it acts a scaling factor for the base array, not just a binary choice
  • "num_sections" should be of integer type (int), not floating point (float)
  • "num_sections" can't be calculated as you do. In C, size of arrays passed as pointers must always be specified separately, because the C runtime doesn't hold this information. In your code, num_sections will always compute to 4 because &bg[1] - &bg[0] is 4 bytes.
Keep going!
Reply


Messages In This Thread
RE: Made a Function to scroll multiple sections of a background. - by megamarc - 09-19-2020, 10:26 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)