Just so you guys know, but Android has a per-process limit of 16-24 megabytes of RAM usage. Try not to get over that limit. If you are going to call JNI functions often and allocate/free memory on each call, you'd need to keep JNI initialized as malloc-ing and free-ing is expensive, I found that out the hard way.
And if you need to update Java from the JNI side, you'd need to free the local reference.
- Viewing Profile: Reputation: farmdve
Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics
Community Stats
- Group Members
- Active Posts 15
- Profile Views 587
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
#5011306 Question about use of JNI
Posted by farmdve
on 16 December 2012 - 11:13 AM
#5009989 2D collision resolution code not behaving properly.
Posted by farmdve
on 12 December 2012 - 04:25 PM
Long story short, I followed the SDL tutorial on LazyFoo here http://lazyfoo.net/S...son29/index.php and wrote the game from scratch in C(since the examples were C++), but borrowed some of the functions.
What is happening is that the collision code is working, but not entirely. If I were to hit a wall, and continue to walk towards it(and being unable to pass through it obviously) and at the same time try to move in a different direction(but not the opposite to the wall) I can't move.
This is my if/else statement
player.box.x and player.box.y are the current positions of the player on the X and Y axis respectively. player.prev_x and player.prev_y are the previous positions.
GetVelocity pretty much returns some static hardcoded values of the velocity for each axis(depending on the second argument being 0 or 1).
My previous collision handling code was this huge one http://pastebin.com/mrFkLTLH but while it worked the way I wanted it allowed under some conditions the object to pass through the wall near the corners.
Here's a picture of a more detailed explanation; http://i.imgur.com/Rn7MY.png
Where the arrows are, I basically make the object go left, let it collide and then either go up or down, while still going left, but it will stay still and won't move either way.
With my previous large code that I just pasted on pastebin, where the small blue lines are on the screenshot, that's where the object passed through the wall on some conditions.
So I basically need a solution on how to fix this. I've been working on that since last night, to the point where I wrote the same code over and over again, expecting a different result.
EDIT:It is fairly obvious to me, that since my collision code is inside a single if-statement, and I am indeed colliding with a wall, while trying to move up or down, either of the sub-statements always execute thus preventing me to move. No idea how to fix it though,
What is happening is that the collision code is working, but not entirely. If I were to hit a wall, and continue to walk towards it(and being unable to pass through it obviously) and at the same time try to move in a different direction(but not the opposite to the wall) I can't move.
This is my if/else statement
if(touches_wall(player.box))
{
if(player.box.x < player.prev_x)
{
player.box.x += GetVelocity(player, 0);
}
else if(player.box.x > player.prev_x)
{
player.box.x -= GetVelocity(player, 0);
}
if(player.box.y > player.prev_y)
{
player.box.y -= GetVelocity(player, 1);
}
else if(player.box.y < player.prev_y)
{
player.box.y += GetVelocity(player, 1);
}
}
player.box.x and player.box.y are the current positions of the player on the X and Y axis respectively. player.prev_x and player.prev_y are the previous positions.
GetVelocity pretty much returns some static hardcoded values of the velocity for each axis(depending on the second argument being 0 or 1).
My previous collision handling code was this huge one http://pastebin.com/mrFkLTLH but while it worked the way I wanted it allowed under some conditions the object to pass through the wall near the corners.
Here's a picture of a more detailed explanation; http://i.imgur.com/Rn7MY.png
Where the arrows are, I basically make the object go left, let it collide and then either go up or down, while still going left, but it will stay still and won't move either way.
With my previous large code that I just pasted on pastebin, where the small blue lines are on the screenshot, that's where the object passed through the wall on some conditions.
So I basically need a solution on how to fix this. I've been working on that since last night, to the point where I wrote the same code over and over again, expecting a different result.
EDIT:It is fairly obvious to me, that since my collision code is inside a single if-statement, and I am indeed colliding with a wall, while trying to move up or down, either of the sub-statements always execute thus preventing me to move. No idea how to fix it though,
#4927233 Newbie here, I wish to start.
Posted by farmdve
on 01 April 2012 - 12:05 PM
Well, it's obvious I am a newbie. I only know a bit of C, I am a newbie at C, but this hasn't stopped me from writing an application I want.
I was able to write myself a GPU temp monitor using AMD's ADL library. It's multithreaded so each thread is checking the corresponding sensor for overheats.
I am in the process of writing an HTML parser of sorts(not a library, but one that uses it) using cURL then piping to htmlTidy to fix up the document then piping the fixed document to libxml2 for the actual HTML parsing and finally through PCRE for regular expressions.
Well, I pretty much pointed out that I wish to write a game in pure C. I already have SDL. Now the problem I am facing is that, I don't know anything about game programming. Neither terminology(shading,voxel,polygons and the list goes on), neither about geometry involved, nor the concepts and maths of "Depth,Gravity,Collision". And for instance how walking on some texture, you don't fall off of it.
So if possible, can you point me to some resources on how all these stuff work. And perhaps how to start.
I was able to write myself a GPU temp monitor using AMD's ADL library. It's multithreaded so each thread is checking the corresponding sensor for overheats.
I am in the process of writing an HTML parser of sorts(not a library, but one that uses it) using cURL then piping to htmlTidy to fix up the document then piping the fixed document to libxml2 for the actual HTML parsing and finally through PCRE for regular expressions.
Well, I pretty much pointed out that I wish to write a game in pure C. I already have SDL. Now the problem I am facing is that, I don't know anything about game programming. Neither terminology(shading,voxel,polygons and the list goes on), neither about geometry involved, nor the concepts and maths of "Depth,Gravity,Collision". And for instance how walking on some texture, you don't fall off of it.
So if possible, can you point me to some resources on how all these stuff work. And perhaps how to start.
- Home
- » Viewing Profile: Reputation: farmdve

Find content