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