Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fpscheck #14

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
TC25 and 26 passed finally. The FPS is not going down too much and th…
…e game is playable even with all the islands conquered. Big push forward ./test -test 25 Still remains an enhancement on the container structure but it is very risky in terms of memory stability.
  • Loading branch information
faturita committed Jun 1, 2020
commit 0e8f12b1f626c8d1cc1179e169cd7c726ed95416
3,501 changes: 3,501 additions & 0 deletions data/fps_newcallback.dat

Large diffs are not rendered by default.

6,001 changes: 6,001 additions & 0 deletions data/fpsmultispace.dat

Large diffs are not rendered by default.

6,001 changes: 6,001 additions & 0 deletions data/fpsnearcallback.dat

Large diffs are not rendered by default.

6,000 changes: 6,000 additions & 0 deletions data/fpsnoenhancement.dat

Large diffs are not rendered by default.

6,001 changes: 6,001 additions & 0 deletions data/fpsnoodemodel.dat

Large diffs are not rendered by default.

6,001 changes: 6,001 additions & 0 deletions data/fpswithmodelnodrawing.dat

Large diffs are not rendered by default.

6,001 changes: 6,001 additions & 0 deletions data/fpswithnearcallback.dat

Large diffs are not rendered by default.

6,001 changes: 6,001 additions & 0 deletions data/fpswithoutdrawing.dat

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ bool groundcollisions(Vehicle *vehicle)
{
if (vehicle)
{
if (vehicle->getSpeed()>70 and vehicle->getType() == MANTA)
if (vehicle->getSpeed()>10 and vehicle->getType() == MANTA)
{
//explosion();
SimplifiedDynamicManta *s = (SimplifiedDynamicManta*)vehicle;
Expand Down
54 changes: 47 additions & 7 deletions keplerivworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ std::vector<std::string> messages;
* Collision detection function.
*
* This is one of the most important pieces of code of this program. It handles too many things.
* vTC26: Islands now contain their own ODE Space, which depends on the world space.
* The heightmap associated with each island is constructed on that space. All the structures are associated with each
* space from each island.
*
* All the units are generated in the world space. Hence this function first check both geoms and calls dSpaceCollid2 which
* verifies if some moving object may be colliding with some space (i.e. island). If there is a collition this callback is called
* again and those collisions are handled.
*
* This is much faster. I verified that by doing this procedure (check TEST 26) the fps of 175 entities improves from 25 to 60 almost
* the highest possible in this platform.
*
*
* @brief nearCallback
Expand All @@ -85,6 +95,20 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)

dBodyID b1,b2;

assert(o1);
assert(o2);

if (dGeomIsSpace(o1) || dGeomIsSpace(o2))
{
//fprintf(stderr,"testing space %p %p\n", (void*)o1, (void*)o2);
// colliding a space with something
dSpaceCollide2(o1,o2,data,&nearCallback);
// Note we do not want to test intersections within a space,
// only between spaces.
// @NOTE: If you ever want to test collisions within each space, call dSpaceCollide2((dSpaceID)o1) and the same for o2.
return;
}

// only collide things with the ground
int g1 = (o1 == ground );
int g2 = (o2 == ground );
Expand Down Expand Up @@ -127,7 +151,7 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
// Water buyoncy reaction
contact[i].surface.mode = dContactSlip1 | dContactSlip2 |
dContactSoftERP | dContactSoftCFM | dContactApprox1;

//printf("1\n");
contact[i].surface.mu = 0.0f;
contact[i].surface.slip1 = 1.0f;
contact[i].surface.slip2 = 1.0f;
Expand All @@ -141,7 +165,7 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
contact[i].surface.mu = 0;
contact[i].surface.slip1 = 0.1f;
contact[i].surface.slip2 = 0.1f;

//printf("2\n");
if (isAction(v1) && isCarrier(v2) && hit(v2,(Gunshot*)v1)) {}
if (isAction(v2) && isCarrier(v1) && hit(v1,(Gunshot*)v2)) {}
if (isAction(v1) && isManta(v2) && hit(v2,(Gunshot*)v1)) {}
Expand All @@ -157,7 +181,7 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
// Manta landing on Carrier
contact[i].surface.mode = dContactBounce |
dContactApprox1;

//printf("3\n");
contact[i].surface.mu = dInfinity;
contact[i].surface.slip1 = 0.0f;
contact[i].surface.slip2 = 0.0f;
Expand All @@ -168,7 +192,7 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
// Manta landing on Runways.
contact[i].surface.mode = dContactBounce |
dContactApprox1;

//printf("4\n");

contact[i].surface.mu = 0.99f;
contact[i].surface.slip1 = 0.9f;
Expand All @@ -179,12 +203,27 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
if ( isRunway(s2) && isManta(v1) && landed(v1, s2->island)) {}

} else
if ((v1 && isManta(v1) && s2) || (v2 && isManta(v2) && s1))
{
// Island reaction
contact[i].surface.mode = dContactBounce |
dContactApprox1;
printf("Hit structure\n");

contact[i].surface.mu = 0;
contact[i].surface.bounce = 0.2f;
contact[i].surface.slip1 = 0.1f;
contact[i].surface.slip2 = 0.1f;

contact[i].surface.soft_erp = 0; // 0 in both will force the surface to be tight.
contact[i].surface.soft_cfm = 0;
}
if (isIsland(contact[i].geom.g1) || isIsland(contact[i].geom.g2))
{
// Island reaction
contact[i].surface.mode = dContactBounce |
dContactApprox1;

//printf("5\n");
contact[i].surface.mu = 0;
contact[i].surface.bounce = 0.2f;
contact[i].surface.slip1 = 0.1f;
Expand All @@ -194,6 +233,9 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
contact[i].surface.soft_cfm = 0;


//if (v1 && isManta(v1) && groundcollisions(v1)) {printf("Hit manta against structure.\n");}
//if (v2 && isManta(v2) && groundcollisions(v2)) {printf("Hit manta against structure.\n");}

// Carrier stranded and Walrus arrived on island.
if (isIsland(contact[i].geom.g1) && isCarrier(v2) && stranded(v2,getIsland(contact[i].geom.g1))) {}
if (isIsland(contact[i].geom.g2) && isCarrier(v1) && stranded(v1,getIsland(contact[i].geom.g2))) {}
Expand Down Expand Up @@ -229,7 +271,6 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)

if (v1 && isManta(v1) && groundcollisions(v1)) {}
if (v2 && isManta(v2) && groundcollisions(v2)) {}

}

dJointID c = dJointCreateContact (world,contactgroup,&contact[i]);
Expand All @@ -238,7 +279,6 @@ void nearCallback (void *data, dGeomID o1, dGeomID o2)
dGeomGetBody(contact[i].geom.g2));
}
}

}

void inline initIslands()
Expand Down
61 changes: 61 additions & 0 deletions scripts/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import matplotlib.pyplot as plt
import csv
import numpy as np


import sys


def is_number(s):
try:
float(s)
return True
except ValueError:
pass

try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass

return False

if (len(sys.argv)<2):
print ("Log File parameter should be provided.")
quit()

file = sys.argv[1]

data1 = []
data2 = []
data3 = []
with open(file) as inputfile:
for row in csv.reader(inputfile):
print ( row )
if (len(row) > 2 and is_number(row[0])):
data1.append(float(row[0]))
data2.append(float(row[1]))
data3.append(float(row[2]))

print("File length:" + str(len(data1)))

data1 = np.asarray(data1)
data2 = np.asarray(data2)
data3 = np.asarray(data3)

fig = plt.figure()
ax1 = fig.add_subplot(111)

ax1.plot(data1,'r', label='entities')
ax1.plot(data2,'g', label='fps')
ax1.plot(data3,'b', label='elapsedtime')
plt.legend(loc='upper left')

plt.savefig('output.png')

plt.show()



92 changes: 66 additions & 26 deletions testbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ std::vector<std::string> messages;
extern float fps;
extern clock_t elapsedtime;

void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
int i,n;

Expand All @@ -102,7 +102,7 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)

if (dGeomIsSpace(o1) || dGeomIsSpace(o2))
{
fprintf(stderr,"testing space %p %p\n", (void*)o1, (void*)o2);
//fprintf(stderr,"testing space %p %p\n", (void*)o1, (void*)o2);
// colliding a space with something
dSpaceCollide2(o1,o2,data,&nearCallback);
// Note we do not want to test intersections within a space,
Expand Down Expand Up @@ -152,7 +152,7 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
// Water buyoncy reaction
contact[i].surface.mode = dContactSlip1 | dContactSlip2 |
dContactSoftERP | dContactSoftCFM | dContactApprox1;

//printf("1\n");
contact[i].surface.mu = 0.0f;
contact[i].surface.slip1 = 1.0f;
contact[i].surface.slip2 = 1.0f;
Expand All @@ -166,7 +166,7 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
contact[i].surface.mu = 0;
contact[i].surface.slip1 = 0.1f;
contact[i].surface.slip2 = 0.1f;

//printf("2\n");
if (isAction(v1) && isCarrier(v2) && hit(v2,(Gunshot*)v1)) {}
if (isAction(v2) && isCarrier(v1) && hit(v1,(Gunshot*)v2)) {}
if (isAction(v1) && isManta(v2) && hit(v2,(Gunshot*)v1)) {}
Expand All @@ -182,7 +182,7 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
// Manta landing on Carrier
contact[i].surface.mode = dContactBounce |
dContactApprox1;

//printf("3\n");
contact[i].surface.mu = dInfinity;
contact[i].surface.slip1 = 0.0f;
contact[i].surface.slip2 = 0.0f;
Expand All @@ -193,7 +193,7 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
// Manta landing on Runways.
contact[i].surface.mode = dContactBounce |
dContactApprox1;

//printf("4\n");

contact[i].surface.mu = 0.99f;
contact[i].surface.slip1 = 0.9f;
Expand All @@ -204,12 +204,27 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
if ( isRunway(s2) && isManta(v1) && landed(v1, s2->island)) {}

} else
if ((v1 && isManta(v1) && s2) || (v2 && isManta(v2) && s1))
{
// Island reaction
contact[i].surface.mode = dContactBounce |
dContactApprox1;
printf("Hit structure\n");

contact[i].surface.mu = 0;
contact[i].surface.bounce = 0.2f;
contact[i].surface.slip1 = 0.1f;
contact[i].surface.slip2 = 0.1f;

contact[i].surface.soft_erp = 0; // 0 in both will force the surface to be tight.
contact[i].surface.soft_cfm = 0;
}
if (isIsland(contact[i].geom.g1) || isIsland(contact[i].geom.g2))
{
// Island reaction
contact[i].surface.mode = dContactBounce |
dContactApprox1;

//printf("5\n");
contact[i].surface.mu = 0;
contact[i].surface.bounce = 0.2f;
contact[i].surface.slip1 = 0.1f;
Expand All @@ -219,6 +234,9 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
contact[i].surface.soft_cfm = 0;


//if (v1 && isManta(v1) && groundcollisions(v1)) {printf("Hit manta against structure.\n");}
//if (v2 && isManta(v2) && groundcollisions(v2)) {printf("Hit manta against structure.\n");}

// Carrier stranded and Walrus arrived on island.
if (isIsland(contact[i].geom.g1) && isCarrier(v2) && stranded(v2,getIsland(contact[i].geom.g1))) {}
if (isIsland(contact[i].geom.g2) && isCarrier(v1) && stranded(v1,getIsland(contact[i].geom.g2))) {}
Expand Down Expand Up @@ -250,17 +268,8 @@ void hierarchicalnearCallback (void *data, dGeomID o1, dGeomID o2)
if (v2 && isWalrus(v2)) { v2->inert = false;}

} else {
/**
// Water buyoncy reaction
contact[i].surface.mode = dContactSlip1 | dContactSlip2 |
dContactSoftERP | dContactSoftCFM | dContactApprox1;
// Object against object collision.

contact[i].surface.mu = 0.0f;
contact[i].surface.slip1 = 0.1f;
contact[i].surface.slip2 = 0.1f;
contact[i].surface.soft_erp = .5f; // 0 in both will force the surface to be tight.
contact[i].surface.soft_cfm = .3f;
**/
if (v1 && isManta(v1) && groundcollisions(v1)) {}
if (v2 && isManta(v2) && groundcollisions(v2)) {}
}
Expand Down Expand Up @@ -376,6 +385,21 @@ void _nearCallback (void *data, dGeomID o1, dGeomID o2)
if ( isRunway(s2) && isManta(v1) && landed(v1, s2->island)) {}

} else
if ((v1 && isManta(v1) && s2) || (v2 && isManta(v2) && s1))
{
// Island reaction
contact[i].surface.mode = dContactBounce |
dContactApprox1;
printf("Hit structure\n");

contact[i].surface.mu = 0;
contact[i].surface.bounce = 0.2f;
contact[i].surface.slip1 = 0.1f;
contact[i].surface.slip2 = 0.1f;

contact[i].surface.soft_erp = 0; // 0 in both will force the surface to be tight.
contact[i].surface.soft_cfm = 0;
}
if (isIsland(contact[i].geom.g1) || isIsland(contact[i].geom.g2))
{
// Island reaction
Expand Down Expand Up @@ -445,7 +469,7 @@ void _nearCallback (void *data, dGeomID o1, dGeomID o2)
}
}

void nearCallback (void *data, dGeomID o1, dGeomID o2)
void __nearCallback (void *data, dGeomID o1, dGeomID o2)
{
int i,n;

Expand Down Expand Up @@ -2252,11 +2276,19 @@ void checktest25(unsigned long timer)
Walrus* w = spawnWalrus(space,world,b);
}

if (timer > 200 && fps<20.0)
if (timer > 200 && entities.size()>30)
{
printf("Test passed OK!\n");
endWorldModelling();
exit(1);
if (fps>20.0)
{
printf("Test passed OK!\n");
endWorldModelling();
exit(1);
} else
{
printf("Test failed: FPS is too slow. \n");
endWorldModelling();
exit(0);
}
}

}
Expand Down Expand Up @@ -2430,10 +2462,18 @@ void checktest26(unsigned long timer)

if (timer > 3500)
{
fpsfile.close();
printf("Test passed OK!\n");
endWorldModelling();
exit(1);
if (fps > 40)
{
fpsfile.close();
printf("Test passed OK!\n");
endWorldModelling();
exit(1);
} else {
fpsfile.close();
printf("Test failed: FPS is too slow. \n");
endWorldModelling();
exit(0);
}
}
}

Expand Down
Loading