merge end stuff
This commit is contained in:
commit
6e6a28c9ff
5 changed files with 82 additions and 64 deletions
|
@ -49,8 +49,8 @@ namespace developer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout<<"[developer console] adding developer "
|
//std::cout<<"[developer console] adding developer "
|
||||||
"callback for token '" << token << "'" << std::endl;
|
// "callback for token '" << token << "'" << std::endl;
|
||||||
|
|
||||||
m_callbacks[token] = cb;
|
m_callbacks[token] = cb;
|
||||||
|
|
||||||
|
|
|
@ -78,11 +78,11 @@ namespace endofthejedi {
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
if (color_type == PNG_COLOR_TYPE_RGB) {
|
//if (color_type == PNG_COLOR_TYPE_RGB) {
|
||||||
puts("PNG_COLOR_TYPE_RGB");
|
// puts("PNG_COLOR_TYPE_RGB");
|
||||||
} else if (color_type == PNG_COLOR_TYPE_RGBA) {
|
//} else if (color_type == PNG_COLOR_TYPE_RGBA) {
|
||||||
puts("PNG_COLOR_TYPE_RGBA");
|
// puts("PNG_COLOR_TYPE_RGBA");
|
||||||
}
|
//}
|
||||||
|
|
||||||
//update width and height based on png info
|
//update width and height based on png info
|
||||||
|
|
||||||
|
@ -95,11 +95,11 @@ namespace endofthejedi {
|
||||||
|
|
||||||
m_size = glm::vec2();
|
m_size = glm::vec2();
|
||||||
|
|
||||||
puts("#########################################");
|
//puts("#########################################");
|
||||||
printf("# PNG: width=%d, height=%d\n", twidth, theight);
|
//printf("# PNG: width=%d, height=%d\n", twidth, theight);
|
||||||
printf("# powers of two: w=%d, h=%d\n", pot_width, pot_height);
|
//printf("# powers of two: w=%d, h=%d\n", pot_width, pot_height);
|
||||||
printf("# uv scale two: x=%f, y=%f\n", m_uvScale.x, m_uvScale.y);
|
//printf("# uv scale two: x=%f, y=%f\n", m_uvScale.x, m_uvScale.y);
|
||||||
puts("#########################################");
|
//puts("#########################################");
|
||||||
|
|
||||||
// Update the png info struct.
|
// Update the png info struct.
|
||||||
png_read_update_info(png_ptr, info_ptr);
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
#include "developer_console.hpp"
|
#include "developer_console.hpp"
|
||||||
|
|
||||||
namespace endofthejedi {
|
namespace endofthejedi {
|
||||||
void RendererPolygon3d::setup()
|
void RendererPolygon3d::setup() {
|
||||||
{
|
|
||||||
m_lastTime = -1.0;
|
m_lastTime = -1.0;
|
||||||
|
|
||||||
//std::cout << "setup polygon 3d" << std::endl;
|
//std::cout << "setup polygon 3d" << std::endl;
|
||||||
|
@ -39,7 +38,7 @@ namespace endofthejedi {
|
||||||
addModel("../data/mesh/ship_ufo.stl", &m_shipModel);
|
addModel("../data/mesh/ship_ufo.stl", &m_shipModel);
|
||||||
|
|
||||||
m_texture = nullptr;
|
m_texture = nullptr;
|
||||||
m_backgroundTexturePath = "../data/img/background_3.png";
|
m_backgroundTexturePath = "../data/img/stars_nebular.png";
|
||||||
loadBackgroundTexture();
|
loadBackgroundTexture();
|
||||||
|
|
||||||
m_postprocess_shader.init();
|
m_postprocess_shader.init();
|
||||||
|
@ -88,15 +87,15 @@ namespace endofthejedi {
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
m_texture->loadPng();
|
m_texture->loadPng();
|
||||||
|
|
||||||
std::cout<<"texture loading: " << m_texture->valid() << std::endl;
|
//std::cout<<"texture loading: " << m_texture->valid() << std::endl;
|
||||||
if (!m_texture->valid()) {
|
if (!m_texture->valid()) {
|
||||||
std::cout<<"loading failed!";
|
std::cout<<"loading failed!";
|
||||||
return;
|
return;
|
||||||
//exit(-1);
|
//exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 s = m_texture->size();
|
//glm::vec2 s = m_texture->size();
|
||||||
std::cout<<"texture size is " << s.x << " X " << s.y << std::endl;
|
//std::cout<<"texture size is " << s.x << " X " << s.y << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderBackgroundImage()
|
void RendererPolygon3d::renderBackgroundImage()
|
||||||
|
@ -574,7 +573,7 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
glm::mat4 model = computeModelMatrix(ship);
|
glm::mat4 model = computeModelMatrix(ship);
|
||||||
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
|
||||||
glm::vec3 c = ship->color;
|
glm::vec3 c = glm::vec3(0.1, 1.0, 0.2);
|
||||||
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
|
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
|
||||||
|
|
||||||
m_shipModel->render();
|
m_shipModel->render();
|
||||||
|
@ -681,6 +680,7 @@ void RendererPolygon3d::renderMissiles() {
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
glLineWidth(1.0f);
|
||||||
glPolygonMode(GL_FRONT, GL_FILL);
|
glPolygonMode(GL_FRONT, GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ namespace endofthejedi {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void renderPlanets();
|
void renderPlanets();
|
||||||
void renderSun();
|
|
||||||
void renderMissiles();
|
void renderMissiles();
|
||||||
void renderShips();
|
void renderShips();
|
||||||
void renderParticles();
|
void renderParticles();
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace game {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ship *ship = new Ship(generateId(), spawnPos, player->color, m_shipRadius);
|
Ship *ship = new Ship(generateId(), spawnPos, m_shipRadius);
|
||||||
player->ship = ship;
|
player->ship = ship;
|
||||||
ships.push_back(ship);
|
ships.push_back(ship);
|
||||||
|
|
||||||
|
@ -159,21 +159,29 @@ namespace game {
|
||||||
|
|
||||||
void State::quitPlayer(size_t playerId)
|
void State::quitPlayer(size_t playerId)
|
||||||
{
|
{
|
||||||
std::cout << playerId << " quit" << std::endl;
|
std::cout << playerId << " quit" << std::endl;
|
||||||
|
|
||||||
Player *player = playerForId(playerId);
|
Player *player = playerForId(playerId);
|
||||||
if (player != nullptr) {
|
if (player != nullptr) {
|
||||||
for (Missile *missile : player->missiles) {
|
for (Missile *missile : player->missiles) {
|
||||||
missile->player = nullptr;
|
player->missiles.remove(missile);
|
||||||
}
|
missile->player = nullptr;
|
||||||
|
m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile));
|
||||||
|
}
|
||||||
|
|
||||||
players.remove(player);
|
if (player->ship != nullptr) {
|
||||||
}
|
ships.remove(player->ship);
|
||||||
|
m_nextEvents.push_back(new ShipEvent(LifeCycle::Destroy, player->ship));
|
||||||
|
}
|
||||||
|
|
||||||
|
players.remove(player);
|
||||||
|
delete(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::clear(size_t playerId)
|
void State::clear(size_t playerId)
|
||||||
{
|
{
|
||||||
std::cout << playerId << " clear" << std::endl;
|
std::cout << playerId << " clear" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::setName(size_t playerId, std::string name)
|
void State::setName(size_t playerId, std::string name)
|
||||||
|
@ -226,8 +234,9 @@ namespace game {
|
||||||
(void) dt;
|
(void) dt;
|
||||||
for (Player *player : players) {
|
for (Player *player : players) {
|
||||||
if (player->alive) {
|
if (player->alive) {
|
||||||
player->energy += dt * ENERGY_PER_DT;
|
player->energy += dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to execute as much queued commands as possible.
|
// try to execute as much queued commands as possible.
|
||||||
while (player->hasCommandInQueue()) {
|
while (player->hasCommandInQueue()) {
|
||||||
Command *command = player->peekCommand();
|
Command *command = player->peekCommand();
|
||||||
|
@ -252,7 +261,7 @@ namespace game {
|
||||||
std::cout<<"player " << killer->id << " killed " << victim->id << std::endl;
|
std::cout<<"player " << killer->id << " killed " << victim->id << std::endl;
|
||||||
|
|
||||||
// destroy ship
|
// destroy ship
|
||||||
ships.remove(victim->ship);
|
ships.remove(victim->ship);
|
||||||
|
|
||||||
delete(victim->ship);
|
delete(victim->ship);
|
||||||
victim->ship = nullptr;
|
victim->ship = nullptr;
|
||||||
|
@ -273,7 +282,7 @@ namespace game {
|
||||||
for (Player *player : players) {
|
for (Player *player : players) {
|
||||||
|
|
||||||
std::vector<Missile*> rm;
|
std::vector<Missile*> rm;
|
||||||
for (Missile *missile : player->missiles) {
|
for (Missile *missile : player->missiles) {
|
||||||
const Missile::Event evt = missile->advance(this, dt);
|
const Missile::Event evt = missile->advance(this, dt);
|
||||||
const bool isHit = (evt.hit != Hit::Nothing);
|
const bool isHit = (evt.hit != Hit::Nothing);
|
||||||
|
|
||||||
|
@ -281,73 +290,73 @@ namespace game {
|
||||||
missile->trace->addPointFromMissile(isHit); // force point if missile gets destroyed a
|
missile->trace->addPointFromMissile(isHit); // force point if missile gets destroyed a
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isHit) {
|
if (!isHit) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool spawnExplosion = true;
|
bool spawnExplosion = true;
|
||||||
|
|
||||||
switch(evt.hit) {
|
switch(evt.hit) {
|
||||||
case Hit::Planet:
|
case Hit::Planet:
|
||||||
// TODO: add black spot on the planet.
|
// TODO: add black spot on the planet.
|
||||||
// TODO: if water planet, add waves
|
// TODO: if water planet, add waves
|
||||||
// TODO: if gas planet, add nice gas explosion effect
|
// TODO: if gas planet, add nice gas explosion effect
|
||||||
// and start burning on this spot for some time.
|
// and start burning on this spot for some time.
|
||||||
|
|
||||||
//std::cout<<"hit Planet" << std::endl;
|
//std::cout<<"hit Planet" << std::endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Hit::Ship:
|
case Hit::Ship:
|
||||||
//std::cout<<"hit Player" << std::endl;
|
//std::cout<<"hit Player" << std::endl;
|
||||||
playerKillsPlayer(playerForId(evt.playerIdKiller), playerForId(evt.playerIdVictim));
|
playerKillsPlayer(playerForId(evt.playerIdKiller), playerForId(evt.playerIdVictim));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Hit::BorderOfUniverse:
|
case Hit::BorderOfUniverse:
|
||||||
//std::cout<<"missile left the universe." << std::endl;
|
//std::cout<<"missile left the universe." << std::endl;
|
||||||
spawnExplosion = false;
|
spawnExplosion = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawnExplosion) {
|
if (spawnExplosion) {
|
||||||
addExplosionFromHit(&evt);
|
addExplosionFromHit(&evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missile->trace != nullptr) {
|
if (missile->trace != nullptr) {
|
||||||
missile->trace->finish();
|
missile->trace->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
rm.push_back(missile);
|
rm.push_back(missile);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Missile *missile : rm) {
|
for (Missile *missile : rm) {
|
||||||
player->missiles.remove(missile);
|
player->missiles.remove(missile);
|
||||||
|
|
||||||
m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile));
|
m_nextEvents.push_back(new MissileEvent(LifeCycle::Destroy, missile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::advanceExplosions(float dt)
|
void State::advanceExplosions(float dt)
|
||||||
{
|
{
|
||||||
std::vector<Explosion*> rm;
|
std::vector<Explosion*> rm;
|
||||||
|
|
||||||
for (Explosion *explosion : explosions) {
|
for (Explosion *explosion : explosions) {
|
||||||
explosion->age += dt;
|
explosion->age += dt;
|
||||||
if (explosion->age >= explosion->maxAge) {
|
if (explosion->age >= explosion->maxAge) {
|
||||||
rm.push_back(explosion);
|
rm.push_back(explosion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Explosion *explosion : rm) {
|
for (Explosion *explosion : rm) {
|
||||||
explosions.remove(explosion);
|
explosions.remove(explosion);
|
||||||
|
|
||||||
m_nextEvents.push_back(new ExplosionEvent(LifeCycle::Destroy, explosion));
|
m_nextEvents.push_back(new ExplosionEvent(LifeCycle::Destroy, explosion));
|
||||||
|
|
||||||
//delete(explosion);
|
//delete(explosion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void State::advance(float dt)
|
void State::advance(float dt)
|
||||||
|
@ -533,6 +542,16 @@ namespace game {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EventType::Ship:
|
||||||
|
{
|
||||||
|
auto *se = static_cast<ShipEvent*>(evt);
|
||||||
|
//std::cout<<"got missile delete event, finally deleting missile #"
|
||||||
|
// << me->object()->id << std::endl;
|
||||||
|
|
||||||
|
delete(se->object());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case EventType::Missile:
|
case EventType::Missile:
|
||||||
{
|
{
|
||||||
auto *me = static_cast<MissileEvent*>(evt);
|
auto *me = static_cast<MissileEvent*>(evt);
|
||||||
|
|
Loading…
Reference in a new issue