FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Arc: The Road to version 0.10
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic     Forum Index -> ArcLib
View previous topic :: View next topic  
Author Message
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Wed May 17, 2006 7:18 pm    Post subject: Reply with quote

Quote:
processCollision()


I was worried this might confuse the programmer, because no collisions are being computed or processed... it only computes values for later 'collide' function calls...

moveToValue[XY] functions returns the value needed to move coordinates in the given direction, for example:

x_position += moveToValueX(45);
y_position += moveToValueY(45);

will move the position in a 45 degree angle -- you can multiply the moveToValue return value to increase/decrease speeds.

angleDistance gives the angle distance between two angles. For example, 360 and 0 have a 0 degree distance, 270 and 180 have a 90 degree difference etc. This function will never return a distance greater than 180 degrees.
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Wed May 17, 2006 11:21 pm    Post subject: Reply with quote

oh ok. and i renamed 'processCollision' to 'processPosition'
Back to top
View user's profile Send private message AIM Address
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Thu May 18, 2006 12:31 am    Post subject: Reply with quote

I just added a new functionality to sprite in case anyone ever wants to set things such as, weapon spawn points. It will allow you to add a point to the sprite that is kept in the same rotation as the sprite, you just give it length and angle to face, it uses the same angle system as Sprite does with 0 at the top.

it works like...

s.addRotationPoint(length, angle);

s.rotate(anything);

// get first rotation point will give x and y values of it after it has been rotated
Point p = s.getRotationPoint(0);
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Thu May 18, 2006 8:39 am    Post subject: Reply with quote

Quote:
oh ok. and i renamed 'processCollision' to 'processPosition'


Hrm... that can also be confusing: you can display sprites, move their positions around without calling processPosition()... I think the name should imply something with collisions

other choices:

processPrepareCollisions()
processCollisionInfo()
processCollisionPositions()
processColissionPos()

I think I like 'processCollisionPos()' -- not as long as proccessCollisionPosition() and gets the message across.

Quote:
weapon spawn points


That sounds pretty cool -- I *might* use them... but I have this feature where any user can import graphics into the game simply by putting PNGs into a directory, so I won't be able to automagically create weapon spawn points off of PNGs Sad
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Thu May 18, 2006 9:54 am    Post subject: Reply with quote

Renamed to 'processCollisionPos'

I'm sure there are ways to get around your situation, such as designating a certain pixel color to be a 'weapon spawn point,' so users can place these spawn points anywhere on the sprite. Should I add this feature?
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Thu May 18, 2006 10:35 am    Post subject: Reply with quote

Quote:
Should I add this feature?


That actually sounds pretty cool -- have a [user specified] specific color that will fill up the RotationPoint list

e.g. sprite.parseRotationPoints(short r, short g, short b);

function returns number of points added to rotation point list Smile

I'm working on other things in FreeUniverse now, so if I do use it, it won't be for awhile. BUT, I can see it being useful, but it doesn't have to be a priority.
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Thu May 18, 2006 11:35 am    Post subject: Reply with quote

Sure, but the user will have to specify the pixel color before they load up the sprite. I think i'll try adding it, as it would make things easier for what I'm currently doing as well.
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Fri May 19, 2006 8:32 pm    Post subject: Reply with quote

I'm having a hell of a time with Access Violations, they just won't go away, and I'm not sure what exactly is causing it -- but it is definetly in your Font.draw method, this is the code:

Code:
   /// print freetype to the screen
   void draw(char[] text, float x, float y, short r, short g, short b, short a) 
   {
      debug writefln("Starting text drawing...");
      
      glColor4ub(r,g,b,a);
      
      // We want a coordinate system where things coresponding to window pixels.
      //pushScreenCoordinateMatrix();         
      glPushAttrib(GL_TRANSFORM_BIT);
      //GLint[4] viewport;
      //glGetIntegerv(GL_VIEWPORT, viewport);
      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      //glLoadIdentity();
      //gluOrtho2D(viewport[0],viewport[2],viewport[1],viewport[3]);
      glPopAttrib();      
   
      GLuint font=list_base;
      float mh=h/.63f;   //We make the height about 1.5* that of
   
      glPushAttrib(GL_LIST_BIT | GL_CURRENT_BIT  | GL_ENABLE_BIT | GL_TRANSFORM_BIT);   
      glMatrixMode(GL_MODELVIEW);
      glDisable(GL_LIGHTING);
      glEnable(GL_TEXTURE_2D);
      glDisable(GL_DEPTH_TEST);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);   

      glListBase(font);

      float modelview_matrix[16];   
      glGetFloatv(GL_MODELVIEW_MATRIX, modelview_matrix);

      debug writefln("Entering foreach loop");
      debug writefln("Text: ?s",text);
      debug fflush(stdout);
      
      char[][] lines = splitlines(text);

      //This is where the text display actually happens.
      //For each line of text we reset the modelview matrix
      //so that the line's text will start in the correct position.
      //Notice that we need to reset the matrix, rather than just translating
      //down by h. This is because when each character is
      //draw it modifies the current matrix so that the next character
      //will be drawn immediatly after it. 

      debug writefln("really now, first line: ?s", lines[0]);
      debug writefln("length: ?s", lines.length);
      debug fflush(stdout);
      
      foreach (int i, char[] line; lines)
      {

         debug writefln("Foreach loop: ?s",i);
         debug fflush(stdout);
         
         glPushMatrix();
         glLoadIdentity();
         glTranslatef(x,y+((i+1)*h),0);
         glMultMatrixf(modelview_matrix);

         //  The commented out raster position stuff can be useful if you need to
         //  know the length of the text that you are creating.
         //  If you decide to use it make sure to also uncomment the glBitmap command
         //  in make_dlist().

         debug writefln("Middle of loop1");         
         debug fflush(stdout);
         glRasterPos2f(0,0);
         debug writefln("Middle of loop2");
         debug fflush(stdout);
         char *newCString = toStringz(line);
         assert(newCString != null);
         glCallLists(line.length, GL_UNSIGNED_BYTE, newCString);
         debug writefln("Middle of loop3");
         debug fflush(stdout);
         float rpos[4];
         debug writefln("Middle of loop4");
         debug fflush(stdout);
         glGetFloatv(GL_CURRENT_RASTER_POSITION ,rpos);
         debug writefln("Middle of loop5");
         debug fflush(stdout);
         w=x-rpos[0];
         debug writefln("Middle of loop6");
         debug fflush(stdout);
         glPopMatrix();
      }

      debug writefln("Done drawing text.");
      debug fflush(stdout);

      glPopAttrib();      

      glPushAttrib(GL_TRANSFORM_BIT);
      glMatrixMode(GL_PROJECTION);
      glPopMatrix();
      glPopAttrib();
      //pop_projection_matrix();
   }


This is what is usually printing when the error happens:

Starting text drawing...
Entering foreach loop
Text: ENGINE
really now, first line: ENGINE
length: 1
Foreach loop: 0
Middle of loop1
Middle of loop2
Error: Access Violation

Sometimes the access violation happens in other places, but it is always a result of calling font.draw. The problem ONLY occurs after some garbage collection happens (e.g. I do many many new's of other unrelated objects to reproduce this access violation). Other notes are: I use the same font file twice, like this:

Font smallFont = new Font("font.ttf",Cool;
Font normalFont = new Font("font.ttf",12);

Not sure if this is a problem. Anyway, my FreeUniverse development has been at a standstill because I'm stuck on this, which is making my game crash after a minute or two of play.

[ edit ] If I use different font files, same problem exists. I'm still stuck on this, very frustrating Crying or Very sad

[ edit ] still stuck with this... definetly something funky going on with this font.draw method... is there any way you can rewrite it to be more reliable/faster? What code are other people using the print text?
Back to top
View user's profile Send private message
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun May 21, 2006 7:39 pm    Post subject: Reply with quote

I would normally never use such things like OMFG... but...

OMFG!

The problem was in my class destructors... I'm not sure exactly why they were crashing, but changing my destructors to ~this() { } fixed the problem. For some reason, the Access Violation always happend somewhere in font.draw, but after getting some windbg working, I realized that it was in _delclass where a jump to a bad address was happening. I hope the GC will take care of my now pathetic destructors Smile
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon May 22, 2006 10:27 am    Post subject: Reply with quote

Sorry I wasn't able to reply, see the 'Summer Hours' thread. So, you've fixed your problem then?
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Mon May 22, 2006 11:18 am    Post subject: Reply with quote

Yeah, I finally did. The biggest problem was getting a debugger to work

e.g. "-g" doesn't work, executables are not compatible with objdump/gdb with MinGW...

But, with windbg and FreeUniverse.map, I figured it out painfully Smile
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon May 22, 2006 4:41 pm    Post subject: Reply with quote

I just fixed a bug where the slow rotation would not reach its target angle, but it now does.

Also fixed a bug so now font width and height work with newlines.

The 'png pixel weapon spawn point' feature will be the next one i'll work on, but I just wanted to squash some bugs first Smile

----- edit -------------------

In order to implement this, I think I will give sprite an overloaded 'addFrame' function that will take all normal parameters along with a red, green, and blue pixel color which it will create a point for.

Also, I really do not like the redundant 'addFrame' functions which just use default parameters if not specified, so I'm thinking about removing those.

------ edit 2 ------------------

Here's how the weapon spawn point feature will work. I'm going to make a function that takes a texture and color and finds all those pixels of a certain color and return the points length and angle. It will

// load texture
Texture tex = texture("image.png");

// get points
Point[] points = getPixelPoints(tex, 255,0,0);

// add all points into sprite
foreach(Point p; points)
s.addPoint(p);

the names are not exactly this, but this is just a proof of concept.
Back to top
View user's profile Send private message AIM Address
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Fri May 26, 2006 9:05 pm    Post subject: Reply with quote

hrm... I've decided to scrap that feature. It would be really simple, but I've been getting weird results with getpixel and SDL_MapRGB, the color results just don't seem to add up.

Back to programming my asteroids game again, if anyone else can match the values of SDL_MapRGB and getpixel on an alpha transparent image, tell me what's up.

~ Clay
Back to top
View user's profile Send private message AIM Address
Phr00t



Joined: 03 Mar 2006
Posts: 203

PostPosted: Sun May 28, 2006 8:10 pm    Post subject: Reply with quote

I'm making good progress on FreeUniverse -- I just checked out some updated Arc files. I see you scrapped the pixelPoints feature, so what was changed in this last update?

Thanks!
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon May 29, 2006 5:10 am    Post subject: Reply with quote

Code comments and commented out code.

-- edit ----------

Just gave input modifiers the 'hit' ability

-- edit ----------

Just made a big API change, instead of using .x you will have to use .getX etc. Good for the long run as it will allow my API to not change drastically anytime soon again, and it is now more consistent. Docs were re-generated to reflect this.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> ArcLib All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 6 of 7

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group