Made PhysicsWorld to inherit Terrain instead of having it as an attribute.
--- a/src/proto2/Graphics.cc Mon Dec 01 17:46:52 2008 +0000
+++ b/src/proto2/Graphics.cc Mon Dec 01 21:49:35 2008 +0000
@@ -70,7 +70,7 @@
const float factorY = GRAPHICS_RESOLUTION_HEIGHT / MAP_HEIGHT;
// draw terrain
- state.drawTerrain(gc);
+ state.draw(gc);
//terrain.draw(gc);
/*
// Demonstrates digging, but is very slow
--- a/src/proto2/Physics.cc Mon Dec 01 17:46:52 2008 +0000
+++ b/src/proto2/Physics.cc Mon Dec 01 21:49:35 2008 +0000
@@ -10,9 +10,8 @@
#include <assert.h>
PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions)
- : tick_timer(PHYSICS_TICK_MS), tick_counter(0), dimensions(dimensions),
+ : Terrain(1337), tick_timer(PHYSICS_TICK_MS), tick_counter(0), dimensions(dimensions),
gravity(gravity) {
- terrain = Terrain(1337);
slots.connect(tick_timer.sig_timer(), this, &PhysicsWorld::tick);
tick_timer.enable();
}
@@ -251,41 +250,6 @@
}
/**
- * Gets the index of the given coordinate direction
- * referring to the DIRECTIONS table in Physics.hh
- *
- * moved to Terrain.cc
- *//*
-int getDirectionIndex (Vector dir) {
- if(dir.x == 0 && dir.y == -1) {
- return 0;
- } else if(dir.x == 1 && dir.y == -1) {
- return 1;
- } else if(dir.x == 1 && dir.y == 0) {
- return 2;
- } else if(dir.x == 1 && dir.y == 1) {
- return 3;
- } else if(dir.x == 0 && dir.y == 1) {
- return 4;
- } else if(dir.x == -1 && dir.y == 1) {
- return 5;
- } else if(dir.x == -1 && dir.y == 0) {
- return 6;
- } else if(dir.x == -1 && dir.y == -1) {
- return 7;
- }
- Engine::log(DEBUG, "physics.getDirectionIndex ") << "invalid direction: " << dir;
- return 0;
-}*/
-
-/**
- * Computes hitten wall's normal. Calculated from 3*3 grid
- */
-Vector PhysicsWorld::getNormal (Vector hitPoint, Vector prevPoint) {
- return terrain.getNormal(hitPoint, prevPoint);
-}
-
-/**
* Bounces from straight wall in any direction.
* Direction given as normal of that wall
*/
@@ -415,29 +379,3 @@
}
}
-/**
- * Returns terrainType in given tile. ROCK if tile is out of area
- * @param pos - coordinate of tile
- */
-TerrainType PhysicsWorld::getType(int x, int y) const {
- return terrain.getType((int32_t)x,(int32_t)y);
-}
-TerrainType PhysicsWorld::getType(Vector pos) const {
- return terrain.getType(pos.x, pos.y);
-}
-
-/**
- * Removes ground from given circle. ROCK is not removed.
- * @param (x, y) or pos - center of circle.
- * @param r - radius of circle
- */
-void PhysicsWorld::removeGround(int x, int y, float r) {
- terrain.removeGround(Vector(x,y), r);
-}
-void PhysicsWorld::removeGround(Vector pos, float r) {
- terrain.removeGround(pos, r);
-}
-
-void PhysicsWorld::drawTerrain(CL_GraphicContext *gc) {
- terrain.draw(gc);
-}
--- a/src/proto2/Physics.hh Mon Dec 01 17:46:52 2008 +0000
+++ b/src/proto2/Physics.hh Mon Dec 01 21:49:35 2008 +0000
@@ -26,14 +26,14 @@
* PhysicsWorld class. PhysicsWorld contains PhysicsObjects that are
* simulated in the PhysicsWorld.
*/
-class PhysicsWorld {
+class PhysicsWorld : public Terrain {
friend class PhysicsObject;
private:
CL_Timer tick_timer;
uint32_t tick_counter;
- Terrain terrain;
+ // Terrain terrain;
protected:
//std::vector<PlayerObject*> players;
@@ -75,51 +75,6 @@
*/
uint32_t getTick();
- // ?!!?!?!?!?!?!
- // TODO: If there were a terrain class, these could it's members.
- /**
- * Generate random terrain.
- *
- * @param seed Random generator seed.
- */
- void generateTerrain(int seed);
- /**
- * Remove ground from the terrain. Removes a circle.
- *
- * @param x Circle x-coordinate
- * @param y Circle y-coordinate
- * @param r Circle radius
- */
- void removeGround(int x, int y, float r);
- /**
- * Remove ground from the terrain. Removes a circle.
- *
- * @param pos Circle location
- * @param r Circle radius
- */
- void removeGround(Vector pos, float r);
- /**
- * Return normal for the wall that has been hit.
- *
- * @param hitPoint The point of the wall that has been hit.
- * @param prevPoint The point from where we were coming.
- */
- Vector getNormal(Vector hitPoint, Vector prevPoint);
- /**
- * Return terrain type in given position.
- *
- * @param x X-coordinate
- * @param y Y-coordinate
- */
- TerrainType getType(int x, int y) const;
- /**
- * Return terrain type in given position.
- *
- * @param pos Coordinate vector
- */
- TerrainType getType(Vector pos) const;
-
- void drawTerrain(CL_GraphicContext *gc);
};
/**