AdamsLair / duality

a 2D Game Development Framework
https://adamslair.github.io/duality
MIT License
1.4k stars 289 forks source link

Component Overhaul #781

Closed Shadowblitz16 closed 4 years ago

Shadowblitz16 commented 4 years ago

Summary

ok so I had an idea on how to make components a bit better. basically there would be a Util class for math, drawing, sound, physics, etc this class would be then used to implement logic into components without having to actully use components.

here is a example of what I can think of (note I am shorting the names for convenience )..


public class Util
{
  //Math (everything i can think of)
  float MthLrp(float value1, float value2, float time); //Lerp
  float MthRng(float value); //Random
  float MthFlr(float value); // Floor
  float MthRnd(float value); //Round
  float MthCel(float value); //Ceiling
  float MthSgn(float value); //Sign
  float MthAbs(float value); //Abs
  float MthCos(float value); // Cos (value in turns)
  float MthSin(float value); //Sin (value in turns)
  float MthLen(float x1, float y1, float x2, float y2);
  float MthDir(float x1, float y1, float x2, float y2);
  float MthMax(params float[] values); //Max
  float MthMed(params float[] values); //Med
  float MthMin(params float[] values); //Min

  //Physics (more needs to be added i'm sure I don't know much about physics)
  Vector2 PhyGetBnce(Vector2 vec1,  Vector2 norm); Point Direction //bounce
  Vector2 PhyGetNorm(Vector2 vec1, Normal vec2); Point Direction //normal
  Vector2 PhyGetBuoy(Vector2 vec1, float amount); Point Direction  //buoyancy 

  //Collision (Collison would be a type that hold a bool and a normal) 
  Collision ColGetPoly(Vec2[] polyA, Vec2[] polyB, float rotation); //returns a collision (poly of 1 point is dot poly of 2 is line) 

  //Drawing (poly of 1 point is dot poly of 2 is line) (also textures can be drawn using DrawGetPoly and GfxSetCanv)
  void    GfxSetCanv(Image=Application.Canvas); //sets the canvas or image we are using
  void    GfxSetShdr(Shader=Application.Shader); //sets the shader we are using
  Color[] GfxSetPoly(DrawMode drawmode, Vector2[] pos, float rotation, int border, Color blend,  Color[] colors); //drawmode is either line or fill
  Color[] GfxSetPoly(DrawMode drawmode, Vector2[] pos, float rotation, int border, Color blend,  Color colors); //drawmode is either line or fill
  Color[] GfxGetPoly(DrawMode drawmode, Vector2[] pos, float rotation, int border, Color blend); //drawmode is either line or fill

  //Sound (Sound can be any format) (also the sub and at methods can be used to generate 8 bit sound)
  void SfxSetPit(Sound sound, float pitch); //sets sound pitch
  void SfxSetPan(Sound sound,   float pan); //sets sound pan
  void SfxSetVol(Sound sound, float volume); //sets sound volumn
  void SfxSetAt (Sound sound, float pos, float value); //sets a part of the sound
  void SfxGetAt(Sound sound, float pos, float value); //gets a part of the sound
  void SfxSetSub(Sound sound, float pos, Sound sample); //sets a part of the sound
  void SfxGetSub(Sound sound, float pos, Sound sample); //gets a part of the sound
  void SfxPlay(Sound sound, float start, float end, bool loop); //Plays a sound

}

It would also be nice to have PixMaps, Textures and RenderTextures be combined into just Textures. this allows for easy pixel manipulation

Analysis

This would then allow us to get rid of the default components and package them as plugins

Pros

Cons

Barsonax commented 4 years ago

A utility class is quite different from a component. Besides there already are utility classes for stuff like math. So its unclear what benefits this issue would provide us.

Shadowblitz16 commented 4 years ago

@Barsonax the point is it would be alot easier to make new components

Barsonax commented 4 years ago

I don't see the benefit of this. Your example is something completely different compared to a component. I think you want a static utility class (which we already use where appropriate).

Closing this.