Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Dualnames

#281
AGS Games in Production / Re: Future Flashback
Thu 14/02/2019 03:42:00
Somewhere between blurry one and bottom right
#282
Yeah, I'm sorry this is kinda new information and I'm bruteforcing it like a chimp :D
#283
Actually I figured out the slowdown on the modularized version, so i don't need to do this through a plugin!!
#284
I've tried this as a means of clearing the virtual screen, but nope.
Code: ags

else if (event == AGSE_POSTSCREENDRAW)
  {
	  BITMAP* P = engine->GetVirtualScreen();
	  unsigned int32 **spriteMemRef = (unsigned int32 **)engine->GetRawBitmapSurface (P);
	  int x,y;
	  for (y = 0; y < screen_height; y++)
	  {
		  for (x = 0; x < screen_width; x++)
		  {
			  spriteMemRef[y][x]=0;
		  }
	 }
	 engine->ReleaseBitmapSurface(P);
	 engine->SetVirtualScreen(P);
  }
#285
Where it's supposed to draw nothing aka draw fully transparent sprites, instead it's drawing static (non-moving) wind sprites.
Which makes me thing it's not pulling from an empty screen, but rather the version of the screen, one loop before.

I am using D3d9
#286
Mhh, i seemed to be unable to draw on a clean slate, like I want, I'm gonna try some stuff.
#287
Yes, it's 3.4.1!
#288
The plugin is drawing particles on the screen. It's a wind effect.

What it does is it draws sprites on the screen, altering their size, their position and their transparency.
In the equivalent of the AGS script, every x loops a sprite is created, then parsing through all the existing particles (flagged with ACTIVE) it moves them based on a force (X and Y) and adjusts their size and transparency.
Then clears the screen and on the next loop it repeats the same processt.

#289
I'm also looking for a command that clears the virtual screen, so that i can use that before accessing it.
#290
You are correct now it's properly hooked, it needed SetVirtualScreen at the end as well. So question

Code: ags

BITMAP* ParticleGraph = engine->GetSpriteGraphic(pgraph+particles[h].frame);
engine->BlitSpriteTranslucent(px, py, ParticleGraph,tp);
//drawt.DrawImage(px, py, pgraph+particles[h].frame, tp, pwidth, pheight);


This part i want it to scale the sprite to width PWIDTH and height PHEIGHT, before blitspriting it onto the screen, what commands are there for that?

Edit:
Code: ags

BITMAP* ParticleGraph = engine->GetSpriteGraphic(pgraph+particles[h].frame);
int32 w, h, d;
engine->GetBitmapDimensions(Particle_B, &w, &h, &d);
w=pwidth;
 h=pheight;
engine->ReleaseBitmapSurface(Particle_B);
engine->BlitSpriteTranslucent(px, py, ParticleGraph,tp);


Is that the right way?
#291
Code: ags

//WIND ENGINE

struct Particle{
int x;
int y;
int transp;
int life;
bool active;
int dx;
int dy;
int mlay;
int timlay;
int movedport;
int translay;
int translayHold;
int width;
int height;
int fx;
int fy;
bool doingcircle;
float angle;
float radius;
int doingCircleChance;
int angleLay;
int frame;
float anglespeed;
};

Particle particles[110];
Particle particlesF[10];
int WForceX[110];
int WForceY[110];

int raysizeF=4; 
int dsizeF=0;
int raysize=100; 
int dsize=0;
int creationdelay=0;
int creationdelayf=0;
bool found_Activeparticle=false;

int32 Random(int value)
{
	return (rand() % value);
}

void CreateParticle(int xx, int yy, int ForceX, int ForceY)
{
  int h=0;
  bool foundparticle=false;
  int fid=-1;
  while (h <= dsize && !foundparticle)
  {
    if (particles[h].active==false)
    {
      foundparticle=true;
      fid=h;
    }
    h++;
  }
  
  if (foundparticle)
  {
    int d=fid;
    particles[d].x=xx;
    particles[d].y=yy;
    particles[d].dx=0;
    particles[d].dy=0;
    particles[d].life=20000;
    particles[d].transp=55+Random(10);
    particles[d].active=true;
    particles[d].mlay=4+Random(2);
    particles[d].timlay=0;
    particles[d].translay=0;
    particles[d].translayHold=19+Random(15);
    particles[d].width=2+Random(2);
    particles[d].height=particles[d].width;
    particles[d].fx=0;
    particles[d].fy=0;
    particles[d].doingcircle=false;
    particles[d].angle=0.0;
    particles[d].radius=4.0+float(Random(6));
    particles[d].doingCircleChance=Random(200);
    particles[d].angleLay=0;
    particles[d].frame=0;
    particles[d].anglespeed=float(Random(20))/100.0;
    WForceX[d]=ForceX;
    WForceY[d]=ForceY;
    if (dsize<(raysize-1)) dsize++;
  }
}



void CreateParticleF(int xx, int yy, int ForceX, int ForceY)
{
  int h=0;
  bool foundparticle=false;
  int fid=-1;
  while (h <= dsizeF && !foundparticle)
  {
    if (particlesF[h].active==false)
    {
      foundparticle=true;
      fid=h;
    }
    h++;
  }
  
  if (foundparticle)
  {
    int d=fid;
    particlesF[d].x=xx;
    particlesF[d].y=yy;
    particlesF[d].dx=(-1)+Random(1);
    particlesF[d].dy=(-1)+Random(1);
    particlesF[d].life=20000;
    particlesF[d].transp=45+Random(10);
    particlesF[d].active=true;
    particlesF[d].mlay=4+Random(2);
    particlesF[d].timlay=0;
    particlesF[d].translay=0;
    particlesF[d].translayHold=19+Random(15);
    particlesF[d].width=8+Random(2);
    particlesF[d].height=particlesF[d].width;
    particlesF[d].fx=0;
    particlesF[d].fy=0;
    particlesF[d].doingcircle=false;
    particlesF[d].angle=0.0;
    particlesF[d].radius=4.0+float(Random(6));
    particlesF[d].doingCircleChance=Random(200);
    particlesF[d].angleLay=0;
    WForceX[d+100]=ForceX;
    WForceY[d+100]=ForceY;
    particlesF[d].frame=0;
    
    
    if (dsizeF<(raysizeF-1)) dsizeF++;
  }
}

//WIND ENGINE

///WING ENGINE UPDATE
void ParticleUpdate(int ForceX, int ForceY, int Transparency,int RoomWidth,int RoomHeight)
{
  
  int ww=RoomWidth;
  int hh=RoomHeight;
  BITMAP* screen = engine->GetVirtualScreen();

  found_Activeparticle=false;
  creationdelay+=int(2.0);
  if (creationdelay > 0)
  {   
    
    int by=0;
    while (by <2)
    {
    int dnx=Random(ww+250)-250;
    int dny=Random(hh);    
    CreateParticle(dnx, dny, ForceX, ForceY);
    by++;
    }
    
    int dnx=-(20+Random(50));
    if (dnx<-160) dnx=-160;
    if (dnx > ww+160) dnx=ww+160;
    
    int dny=Random(hh);    
    CreateParticleF(dnx, dny, ForceX, ForceY);
    
    found_Activeparticle=true;
    
    creationdelay=0;
  }
  
  int h=dsize-1;
  
  if (h < dsizeF-1)
  {
    h=dsizeF-1;
  }
  while (h>0)
  {
    if (particles[h].life>0)
    {
      found_Activeparticle=true;
      particles[h].life-=int(2.0);
      particles[h].doingCircleChance-=1;
      int df=100-particles[h].transp;
      df=10-(df/4);
      int pwidth=particles[h].width+df;
      int pheight=particles[h].height+df;
      
      int px=particles[h].x-(pwidth/2);
      int py=particles[h].y-(pheight/2);
      int tp=particles[h].transp+Transparency;
      
      if (tp>100) tp=100;
      
      int pgraph=0;
      int SplitBetweenTwo=Random(100);
      if (SplitBetweenTwo<=50) pgraph=813;
      else pgraph=4466;
      
      if (tp!=100)
	  {
		  BITMAP* ParticleGraph = engine->GetSpriteGraphic(pgraph+particles[h].frame);
		  engine->BlitSpriteTranslucent(px, py, ParticleGraph,tp);
		  //drawt.DrawImage(px, py, pgraph+particles[h].frame, tp, pwidth, pheight);
	  }
      particles[h].timlay+=int(4.0);
      if (particles[h].timlay> particles[h].mlay)
      {
        particles[h].frame++;
        if (particles[h].frame>6) particles[h].frame=0;
        particles[h].timlay=0;
        particles[h].x += particles[h].dx+particles[h].fx; 
        particles[h].y += particles[h].dy+particles[h].fy;      
      }
      particles[h].translay+=1;
      if (particles[h].translay>=particles[h].translayHold)
      {
        if (particles[h].transp<=99) particles[h].transp++;
        else 
        {
          particles[h].life=0;
          found_Activeparticle=false;
        }
      }
      if (particles[h].x>=ww-90 || particles[h].x<90)
      {
        if (particles[h].transp<=99)particles[h].transp++;
        else 
        {
          found_Activeparticle=false;
          particles[h].life=0;       
        }
      }
      
      if (!particles[h].doingcircle && particles[h].angle==0.0
      && particles[h].doingCircleChance<=0)
      {
        particles[h].doingcircle=true;
      }
      if (particles[h].doingcircle)
      {
        particles[h].angleLay+=(1+WForceX[h]);
        if (particles[h].angleLay> 12)
        {
          particles[h].angleLay=0;
          particles[h].angle+=particles[h].anglespeed;
          int Y=particles[h].y + int((sin(particles[h].angle)* particles[h].radius));
          int X=particles[h].x + int((cos(particles[h].angle)* particles[h].radius));
          particles[h].x=X;
          particles[h].y=Y;  
        }
      }
      particles[h].fx=ForceX;
      particles[h].fy=ForceY;
      
    }
    else 
    {
      particles[h].active=false;
    }
    
    
    
    if (h<=9 && particlesF[h].life>0)
    {
      found_Activeparticle=true;
      int pwidth=particlesF[h].width;
      int pheight=particlesF[h].height;
      int px=particlesF[h].x-(pwidth/2);
      int py=particlesF[h].y-(pheight/2);
      int pgraph=0;
      int SplitBetweenTwo=Random(100);
      if (SplitBetweenTwo<=50) pgraph=806;
      else pgraph=4459;
      
      int tp=particlesF[h].transp+Transparency;      
      if (tp>100) tp=100;
      
      
      if (tp!=100)
	  {
		  BITMAP* Particle_B = engine->GetSpriteGraphic(pgraph+particlesF[h].frame);
		  engine->BlitSpriteTranslucent(px, py, Particle_B,tp);
		  //drawt2.DrawImage(px, py, pgraph+particlesF[h].frame, tp, pwidth, pheight);
	  }
      particlesF[h].timlay+=int(4.0);
      if (particlesF[h].timlay> particlesF[h].mlay)
      {
        particlesF[h].frame++;
        if (particlesF[h].frame>6)  particlesF[h].frame=0;
        particlesF[h].timlay=0;
        particlesF[h].x += particlesF[h].dx + ForceX;
        particlesF[h].y += particlesF[h].dy + ForceY;  
      }
      
      
      if (particlesF[h].x>=ww-90 || particlesF[h].x<90)
      {
        particlesF[h].translay+=1; 
        if (particlesF[h].translay>=particlesF[h].translayHold)
        {          
          if (particlesF[h].transp<=99) particlesF[h].transp++;
          else 
          {
            found_Activeparticle=false;
            particlesF[h].life=0;
          }
        }
      }      
    }
    else 
    {
      if (h<=9)  particlesF[h].active=false;
    }
    
    
    h--;
  }
  engine->ReleaseBitmapSurface(screen);
  
}

//WIND ENGINE UPDATE



Nothing seems to be drawing on the screen, on my AGS script side i just run ParticleUpdate(int ForceX, int ForceY, int Transparency,int RoomWidth,int RoomHeight).
This is 'replacement' code moved from AGS to the plugin, so the code itself works fine. Any thoughts on why it doesn't? I'm not sure I'm using the 'virtual screen' part correctly, but there's little to no examples, I could find for it. Apologies for the sequence of new posts every day.
#292
Alright, replaced all longs with int32, i've never coded much in c++ beyond like few lines, can you explain how to use int32_t, if that's not too much to ask.
Does it automatically convert the data types within stdint script? So i just do an include and keep using int and it will choose the appropriate one, unless explicitly defined by me?
#293
That reduces the effect into a line at the top of the screen. A single pixel 1 pixel height starting from 0 to halfway only one pixel height.


edit: Posting working code, thanks to qptain_nemo
Code: ags

 int x, y;
  
  BITMAP* src_a = engine->GetSpriteGraphic(sprite_a);

  BITMAP* src_b = engine->GetSpriteGraphic(sprite_b);

  
  unsigned long** pixel_a = (unsigned long**)engine->GetRawBitmapSurface(src_a);
  unsigned long** pixel_b = (unsigned long**)engine->GetRawBitmapSurface(src_b);

  for (y = 0; y < screen_height; y++)
  {
    for (x = 0; x < screen_width; x++)
    {
	  unsigned long colorfromB = pixel_b[y][x];
	  pixel_a[y][(x-(rand() % 2)-2)]=colorfromB;	  
     // pixel_a++;//=2;
	 // pixel_b++;//=2;
    }
  }
  engine->ReleaseBitmapSurface(src_a);
  engine->ReleaseBitmapSurface(src_b);
 // }
}
#294
I'm trying to code a PLUGIN function that grabs two sprites (sprite_a and sprite_b) parses the entirety of sprite_a and replaces the color of each pixel in sprite_b (with coordinates y = y from sprite a and x= x-Random(2) -2 from sprite_a), but that's not working, and i can't figure out why, I think I'm parsing the 2d array wrongfully.


Code: ags


int x, y;  
  BITMAP* src_a = engine->GetSpriteGraphic(sprite_a);
  BITMAP* src_b = engine->GetSpriteGraphic(sprite_b);
  unsigned short* pixel_a = *(unsigned short**)engine->GetRawBitmapSurface(src_a);
  unsigned short* pixel_b = *(unsigned short**)engine->GetRawBitmapSurface(src_b);

  for (y = 0; y < screen_height; y++)
  {
    for (x = 0; x < screen_width; x++)
    {
	  unsigned short colorfromB = pixel_b[y,x];
	  pixel_a[y,(x-(rand() % 2)-2)]=colorfromB;
      pixel_a++;
	  pixel_b++;
    }
  }
  engine->ReleaseBitmapSurface(src_a);
  engine->ReleaseBitmapSurface(src_b);  


Clarifying it's only doing half the screen, and it shouldn't, and i think the colors it picks are a bit wrong as well.


https://imgur.com/dMLLhUA
#295
Code: ags


int i=0;
while (i <20)
{
while (d < x && CircleSize>0)
{
 f=y2;
        f1=0;
        while (f < y)
        {         
          f++;
          f1++;
        }
        d1++;
        d++;
      }    
i++;
}



My main thing, is that the issues within AGS's inability to perform complex drawing stuff in real-time, isn't on the drawing functions. A big while like the one above, seems to be the problem in most cases. Like for example doing

Code: ags


int x=0;
while (x < width)//Width being 640 or 320 or whatever
{
int y=0;
while (y < height)//same as above
{
y++;
}
x++;
}



This loop without anything inside the while conditions, just as is, will cause framerate drop. I'm not sure if that's ameniable/fixable in any way, but I think it would solve a lot of issues. I wanted to use LUA for AGS but it's very risky given the state of that plugin. Regardless, I appreciate your work and I love you super hardcore <3.
#296
This is what it's supposed to be doing https://www.youtube.com/watch?v=HUxcmeT3LKs

I altered the code to make it run to 40 fps or so and made the effect a bit more subtle.

https://www.youtube.com/watch?v=vXQCf3zYez4&feature=youtu.be

Ignore the 2 characters, there are still WIP parts of this.
But you can see the frame drop is non existent.
#297
I've noticed i was drawing a smaller circle than a rectangle, so now frames are at 29. 11 fps droprate.
#298
It takes about 3 seconds to finish executing the code, around 120-150 loops. I did your adjustments, but same problem, I'm afraid.
#299
The issue doesn't stand on the calculations, albeit those can be improved, the issue lies on the two nested while loops

Code: ags

while (d < x && CircleSize>0)
{
 f=y2;
        f1=0;
        while (f < y)
        {         
          f++;
          f1++;
        }
        d1++;
        d++;
      }    


Even like this, no drawing whatsoever, the frame rate drops to 10 for a solid 2 seconds.
#300
This basically creates a circle and saves each frame on a Dynamic Sprite array (size of 20).
I've noticed that this takes 2-4 seconds to execute, and the whole issue stands (i've commented parts of the code etc) inside the two while loops, is there a way I can make this faster/better?



Code: ags


//CODE IS EXECUTED TILL 20 Dynamic Sprite FRAMES ARE CREATED.

  waveFrames[waveFrameC]=DynamicSprite.CreateFromExistingSprite(waveFrames[0].Graphic, true);//waveFrameC
  DrawingSurface*area = waveFrames[waveFrameC].GetDrawingSurface();
  DrawingSurface*refarea = waveFrames[0].GetDrawingSurface();//waveFrameC-1
  
      float Size=6.0;//2.0;
      float IncX=2.6;
      int CircleSize=((wvc+1)-waveFrameC);
      int incBy=waveFrameC*FloatToInt(Size, eRoundNearest);//*6;
      
      int incByx=FloatToInt(IntToFloat(incBy)*IncX, eRoundNearest);
      
      
      int CentralX=cEgo.x;
      int CentralY=cEgo.y-150;
      
      int x=CentralX+(incByx);
      int x2=CentralX-(incByx);
      
      int y=CentralY+(incBy);
      int y2=CentralY-(incBy);//180-(incBy);
      
      int d=x2;
      int d1=0;
      int f=y2;
      int f1=0;
      
      
      float difX;
      float difY;
      float sum;
      float distance;        
      int checkDist;
      
      float gx=IntToFloat(waveFrameC)*Size*IncX;
      int getXv=FloatToInt(gx, eRoundNearest);
      int getX=CentralX-getXv;
      int getY=CentralY-(waveFrameC*6);
      
      while (d < x && CircleSize>0)//while
      {
        f=y2;
        f1=0;
        while (f < y)
        {
          //CALCULATE DISTANCE BETWEEN TWO POINTS
          
          difX = IntToFloat(CentralX) - IntToFloat(d);
          difY = IntToFloat(CentralY) - IntToFloat(f);
          difX = Maths.RaiseToPower(difX, 2.0);
          difY = Maths.RaiseToPower(difY, 2.0);
          sum = difX+difY;
          distance = Maths.Sqrt(sum);        
          checkDist = FloatToInt(distance, eRoundNearest);
          
          if (checkDist<= incBy && checkDist>incBy-CircleSize)
          {            
            area.DrawingColor=refarea.GetPixel(getX+d1, getY + (f1-1));            
            area.DrawPixel(d, f);
          }
          
          f++;
          f1++;
        }
        d1++;
        d++;
      }    
  
  
  area.Release();
  refarea.Release();
  waveFrameC++;
  
  
}
SMF spam blocked by CleanTalk