Commit 50ff0273 authored by Benjamin 'Albsi' Albsmeier's avatar Benjamin 'Albsi' Albsmeier
Browse files

mapgen now supports donut shaped maps

parent 12789100
......@@ -77,6 +77,8 @@ private:
glm::vec4 cannon_offset_;
bool is_level_build_;
void loadMap();
};
} //Namespace gdw
......
......@@ -8,6 +8,8 @@
#include <vector>
#include <memory>
#include <random>
#include <glm/glm.hpp>
#include <glm/gtx/norm.hpp>
namespace gdw{
/**
......@@ -55,22 +57,28 @@ namespace gdw{
maxAstroidRadius: maximal astroid radius
astroidDistance: distance between astroids
astroids: std::vector filled with astroids
donutShapedMap: donut shaped map flag
donutCenterX: center of the donut
donutCenterY: center of the donut
donutCenterZ: center of the donut
donutMinRadius: minimal radius of the donut
donutMaxRadius: maximal radius of the donut
*/
struct map{
int width = 0;
int height = 0;
int deep = 0;
int startX = 0;
int startY = 0;
int startZ = 0;
int minBoundX = 0;
int minBoundY = 0;
int minBoundZ = 0;
int maxBoundX = 0;
int maxBoundY = 0;
int maxBoundZ = 0;
float width = 0.0f;
float height = 0.0f;
float deep = 0.0f;
float startX = 0.0f;
float startY = 0.0f;
float startZ = 0.0f;
float minBoundX = 0.0f;
float minBoundY = 0.0f;
float minBoundZ = 0.0f;
float maxBoundX = 0.0f;
float maxBoundY = 0.0f;
float maxBoundZ = 0.0f;
int seed = 0;
int scatter = 0;
float scatter = 0.0f;
int astroidTypes = 0;
float astroidDistance = 0.0f;
float realAstroidDistance = 0.0f;
......@@ -79,6 +87,12 @@ namespace gdw{
float maxAstroidRotationSpeed = 0.2f;
float maxAstroidMotionSpeed = 0.2f;
std::vector<astroid> astroids;
bool donutShapedMap = false;
float donutCenterX = 0.0f;
float donutCenterY = 0.0f;
float donutCenterZ = 0.0f;
float donutMinRadius = 0.0f;
float donutMaxRadius = 1.0f;
};
/**
......@@ -94,17 +108,23 @@ namespace gdw{
minAstroidRadius: minimal astroid radius (<= maxAstroidRadius)
maxAstroidRadius: maximal astroid radius (> 0)
astroidDistance: factor for distance between astroids (>= 1) 1 = maxAstroidRadius, 2 = maxAstroidRadius*2 ...
donutShapedMap: donut shaped map flag - set it if you like a donut shaped map
donutCenterX: center of the donut
donutCenterY: center of the donut
donutCenterZ: center of the donut
donutMinRadius: minimal radius of the donut
donutMaxRadius: maximal radius of the donut
debug: debug flag
*/
struct constructMapGen{
int mapWidth = 0;
int mapHeight = 0;
int mapDeep = 0;
int startX = 0;
int startY = 0;
int startZ = 0;
float mapWidth = 0.0f;
float mapHeight = 0.0f;
float mapDeep = 0.0f;
float startX = 0.0f;
float startY = 0.0f;
float startZ = 0.0f;
int seed = 27389;
int scatter = 20;
float scatter = 20.0f;
int astroidTypesCount = 1;
float minAstroidRadius = 1.0f;
float maxAstroidRadius = 1.0f;
......@@ -112,6 +132,12 @@ namespace gdw{
float maxAstroidRotationSpeed = 0.2f;
float maxAstroidMotionSpeed = 0.2f;
bool debug = false;
bool donutShapedMap = false;
float donutCenterX = 0.0f;
float donutCenterY = 0.0f;
float donutCenterZ = 0.0f;
float donutMinRadius = 0.0f;
float donutMaxRadius = 1.0f;
};
class mapgen{
......
......@@ -67,7 +67,10 @@ namespace gdw {
const int& mapWidth,const int& mapHeight,const int& mapDeep,
const int& startX,const int& startY,const int& startZ,
const int& seed = 27389,const int& scatter= 17,
const float& minAstroidRadius = 1,const float& maxAstroidRadius = 1, bool debug = false);
const float& minAstroidRadius = 1,const float& maxAstroidRadius = 1,
bool donutShapedMap = false, const float& donutMinRadius = 0, const float& donutMaxRadius = 0,
const float &donutCenterX = 0, const float &donutCenterY = 0, const float &donutCenterZ = 0,
bool debug = false);
int add_agent(const float *p, unsigned long long int entityID);
void set_move_target(const float *p, bool adjust);
......
......@@ -140,9 +140,7 @@ namespace gdw {
cannon_ = cannon.id();
}
maploader_.load({"mesh/asteroid.msh", "mesh/asteroid2.msh", "mesh/asteroid3.msh"}, 1.f, 50, 1, 40, -25, plane_offset_y_, -2,
static_cast<int>(time(0)), 30, 1.0f, 2.0f,
engine_.getConfig().get("navDebug", false)); //old seed: 27389
loadMap();
float tpos[]{20 + 15, plane_offset_y_, 15};
maploader_.set_move_target(tpos, false);
......@@ -221,9 +219,7 @@ namespace gdw {
if (map_load_timer_ > 0.6f) {
if (load_timer >= map_load_timer_) {
maploader_.load({"mesh/asteroid.msh", "mesh/asteroid2.msh", "mesh/asteroid3.msh"}, 1.f, 50, 1, 40, -25,
3, -2, static_cast<int>(time(0)), 30, 1.0f, 2.0f,
engine_.getConfig().get("navDebug", false)); //old seed: 27389
loadMap();
float tpos[]{20 + 15, 3, 15};
maploader_.set_move_target(tpos, false);
load_timer = 0.f;
......@@ -421,4 +417,26 @@ namespace gdw {
}
}
void level_manager::loadMap(){
maploader_.load({"mesh/asteroid.msh", "mesh/asteroid2.msh", "mesh/asteroid3.msh"},
1.0f,//model skale
50.0f,//mapWidth
1.0f,//mapHeiht
40.0f,//mapDeep
-25.0f,//startX
plane_offset_y_,//startY
0.0f,//startZ
static_cast<int>(time(0)),//seed: 27389
30.0f,//scatter
1.0f,//minAstroidRadius
2.0f,//maxAstroidRadius
true,//false,//donutShapedMap
100.0f,//donutMinRadius
400.0f,//donutMaxRadius
0.0f,//donutCenterX
plane_offset_y_,//donutCenterY
20.0f,//donutCenterZ
engine_.getConfig().get("navDebug", false));//nav mesh debug
}
} //Namespace gdw
......@@ -43,6 +43,12 @@ namespace gdw{
m->maxBoundY = m->height + m->realAstroidDistance;
m->maxBoundZ = m->deep + m->realAstroidDistance;
m->donutShapedMap = c.donutShapedMap;
m->donutCenterX = c.donutCenterX;
m->donutCenterY = c.donutCenterY;
m->donutCenterZ = c.donutCenterZ;
m->donutMinRadius = c.donutMinRadius;
m->donutMaxRadius = c.donutMaxRadius;
std::mt19937_64 generator(m->seed);
std::uniform_int_distribution<> scatterAstroids(0, 99);
......@@ -65,7 +71,10 @@ namespace gdw{
<< "map: min: x:" << m->startX << " y:" << m->startY << " z:" << m->startZ << std::endl
<< " max: x:" << m->width << " y:" << m->height << " z:" << m->deep << std::endl
<< "bounds: min: x:" << m->minBoundX << " y:" << m->minBoundY << " z:" << m->minBoundZ << std::endl
<< " max: x:" << m->maxBoundX << " y:" << m->maxBoundY << " z:" << m->maxBoundZ << std::endl;
<< " max: x:" << m->maxBoundX << " y:" << m->maxBoundY << " z:" << m->maxBoundZ << std::endl
<< "donutShapedMap: " << m->donutShapedMap << std::endl
<< "donutCenter: x:" << m->donutCenterX << " y:" << m->donutCenterY << " z:" << m->donutCenterZ << std::endl
<< "donutRadius: min:" << m->donutMinRadius << " max:" << m->donutMaxRadius << std::endl;
for(float y=m->startY; y <= m->height; y += m->realAstroidDistance){
if(debug)log << "(y) " << y <<" ======================================================" << std::endl;
......@@ -74,18 +83,25 @@ namespace gdw{
for(float x=m->startX; x <= m->width; x += m->realAstroidDistance){
if(scatterAstroids(generator) < m->scatter){
astroid a;
a.type = astroidTypes(generator);
a.radius = astroidRadius(generator);
a.centerX = x +astroidPosShift(generator);
a.centerY = y +astroidPosShift(generator);
a.centerZ = z +astroidPosShift(generator);
a.rotationX = astroidRotation(generator);
a.rotationY = astroidRotation(generator);
a.rotationZ = astroidRotation(generator);
a.motionSpeed = astroidMotionSpeed(generator);
a.rotationSpeed = astroidRotationSpeed(generator);
m->astroids.push_back(a);
if(debug)log << "o";
float distance = glm::distance2(glm::vec3(a.centerX, a.centerY, a.centerZ), glm::vec3(m->donutCenterX, m->donutCenterY, m->donutCenterZ));
if(!m->donutShapedMap || (distance >= m->donutMinRadius && distance <= m->donutMaxRadius)){
a.type = astroidTypes(generator);
a.radius = astroidRadius(generator);
a.rotationX = astroidRotation(generator);
a.rotationY = astroidRotation(generator);
a.rotationZ = astroidRotation(generator);
a.motionSpeed = astroidMotionSpeed(generator);
a.rotationSpeed = astroidRotationSpeed(generator);
m->astroids.push_back(a);
if(debug)log << "o";
}else{
if(debug)log << " ";
}
}else{
if(debug)log << " ";
}
......@@ -98,12 +114,14 @@ namespace gdw{
char i='a';
log << "|";
for(float x=m->startX; x <= m->width; x += m->realAstroidDistance){
if(i == 'z'+1)i='A';
log << i;
++i;
}
log << "| (x)| ";
i='a';
for(float x=m->startX; x <= m->width; x += m->realAstroidDistance){
if(i == 'z'+1)i='A';
log << i << ":" << x << " | ";
++i;
}
......
......@@ -159,7 +159,10 @@ namespace gdw {
const int &mapWidth, const int &mapHeight,const int& mapDeep,
const int& startX,const int& startY,const int& startZ,
const int &seed, const int &scatter,
const float &minAstroidRadius,const float &maxAstroidRadius, bool debug) {
const float &minAstroidRadius,const float &maxAstroidRadius,
bool donutShapedMap, const float &donutMinRadius, const float &donutMaxRadius,
const float &donutCenterX, const float &donutCenterY, const float &donutCenterZ,
bool debug) {
cleanup();
......@@ -178,7 +181,15 @@ namespace gdw {
cm.astroidTypesCount = int(meshnames.size());
cm.minAstroidRadius = minAstroidRadius;
cm.maxAstroidRadius = maxAstroidRadius;
cm.debug = debug || engine_.getConfig().get("mapGenDebug",false);
cm.debug = engine_.getConfig().get("mapGenDebug",false);
cm.donutShapedMap = donutShapedMap;
cm.donutCenterX = donutCenterX;
cm.donutCenterY = donutCenterY;
cm.donutCenterZ = donutCenterZ;
cm.donutMinRadius = donutMinRadius;
cm.donutMaxRadius = donutMaxRadius;
auto m = mapgen::makeMap(cm);
std::vector<float> verts;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment