added run loop for simulation
This commit is contained in:
parent
9fa3e924a4
commit
438f019e28
@ -12,7 +12,7 @@ out vec3 normal;
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
texCoord = inTexCoord.xy;
|
texCoord = vec2(inTexCoord.x/2,inTexCoord.y);
|
||||||
normal = inNormal.xyz;
|
normal = inNormal.xyz;
|
||||||
gl_Position = mvp * vec4(inPosition*camera.z, 1.0);
|
gl_Position = mvp * vec4(inPosition*camera.z, 1.0);
|
||||||
}
|
}
|
||||||
|
10
src/dude.cpp
10
src/dude.cpp
@ -10,3 +10,13 @@ Dude::Dude(Coord _pos, Info _info):m_pos(_pos),m_info(_info),m_dead(false)
|
|||||||
{
|
{
|
||||||
memset(&m_memory,0,DUDE_MEMORY_SIZE*sizeof(char));
|
memset(&m_memory,0,DUDE_MEMORY_SIZE*sizeof(char));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* Dude::getMemory()
|
||||||
|
{
|
||||||
|
return m_memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info* Dude::getInfo()
|
||||||
|
{
|
||||||
|
return &m_info;
|
||||||
|
}
|
||||||
|
@ -13,6 +13,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
Dude();
|
Dude();
|
||||||
Dude(Coord,Info);
|
Dude(Coord,Info);
|
||||||
|
char* getMemory();
|
||||||
|
Info* getInfo();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DUDE_H
|
#endif // DUDE_H
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
|
|
||||||
|
#include "map.h"
|
||||||
|
|
||||||
Simulation::Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors):
|
Simulation::Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors):
|
||||||
p_map(_map)
|
p_map(_map)
|
||||||
{
|
{
|
||||||
@ -7,18 +9,17 @@ Simulation::Simulation(Map *_map,std::vector<BehaviorFunction> _behaviors):
|
|||||||
for(auto behavior : _behaviors){
|
for(auto behavior : _behaviors){
|
||||||
glm::vec3 color;
|
glm::vec3 color;
|
||||||
color[i%3]=i*50;
|
color[i%3]=i*50;
|
||||||
Coord spawn;
|
m_teams[i] = Team(color,behavior);
|
||||||
m_teams[i] = Team(color,spawn,behavior);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::run()
|
void Simulation::run()
|
||||||
{
|
{
|
||||||
for(auto team : m_teams){
|
for(auto t : m_teams){
|
||||||
// team.second.updateSpawn();
|
if (t.second.updateSpawn())
|
||||||
|
t.second.spawn(p_map->team(t.first));
|
||||||
|
t.second.updateDudes();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
20
src/team.cpp
20
src/team.cpp
@ -5,12 +5,26 @@ Team::Team()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Team::Team(glm::vec3 _color,Coord _spawn,BehaviorFunction _behavior):
|
Team::Team(glm::vec3 _color,BehaviorFunction _behavior):
|
||||||
m_color(_color),m_spawn(_spawn),m_spawnCooldown(SPAWN_COOLDOWN),
|
m_color(_color),m_spawnCooldown(SPAWN_COOLDOWN),
|
||||||
m_foodQuantity(NB_STARTING_FOOD), m_behavior(_behavior)
|
m_foodQuantity(NB_STARTING_FOOD), m_behavior(_behavior)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Team::updateSpawn(){
|
bool Team::updateSpawn()
|
||||||
|
{
|
||||||
return !(--m_spawnCooldown);
|
return !(--m_spawnCooldown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Team::spawn(Coord &d)
|
||||||
|
{
|
||||||
|
m_dudes.push_back(Dude(d,Info()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Team::updateDudes()
|
||||||
|
{
|
||||||
|
for (auto dude : m_dudes){
|
||||||
|
Action* action;
|
||||||
|
m_behavior(action,dude.getMemory(),dude.getInfo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,15 +15,16 @@
|
|||||||
class Team
|
class Team
|
||||||
{
|
{
|
||||||
glm::vec3 m_color;
|
glm::vec3 m_color;
|
||||||
Coord m_spawn;
|
|
||||||
int m_spawnCooldown;
|
int m_spawnCooldown;
|
||||||
int m_foodQuantity;
|
int m_foodQuantity;
|
||||||
std::vector<Dude> m_dudes;
|
std::vector<Dude> m_dudes;
|
||||||
BehaviorFunction m_behavior;
|
BehaviorFunction m_behavior;
|
||||||
public:
|
public:
|
||||||
Team();
|
Team();
|
||||||
Team(glm::vec3 _color,Coord _spawn,BehaviorFunction _behavior);
|
Team(glm::vec3 _color,BehaviorFunction _behavior);
|
||||||
bool updateSpawn();
|
bool updateSpawn();
|
||||||
|
void spawn(Coord &d);
|
||||||
|
void updateDudes();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEAM_H
|
#endif // TEAM_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user