minor improvements for gl error checcking/printing and shot defaults.

This commit is contained in:
Andreas Ortmann 2016-09-29 18:11:00 +02:00
parent c06e138b3e
commit b6f99e6498
5 changed files with 60 additions and 30 deletions

View file

@ -44,12 +44,12 @@ bool Game::cycle(float dt)
acc += dt; acc += dt;
total += dt; total += dt;
float spawnInterval = 0.1; float spawnInterval = 0.5;
while (acc > spawnInterval) { while (acc > spawnInterval) {
acc -= spawnInterval; acc -= spawnInterval;
float angle = 360.0 * util::randf_0_1(); float angle = 360.0 * util::randf_0_1();
float speed = 0.01; float speed = 1.;
m_state->players.back()->addCommand(new game::SetSpeedCommand(speed)); m_state->players.back()->addCommand(new game::SetSpeedCommand(speed));
m_state->players.back()->addCommand(new game::ShootCommand(angle)); m_state->players.back()->addCommand(new game::ShootCommand(angle));

View file

@ -126,3 +126,41 @@ namespace endofthejedi {
return glGetUniformLocation(m_program, name.c_str()); return glGetUniformLocation(m_program, name.c_str());
} }
} }
void printGlError(GLenum err)
{
if (err != GL_NO_ERROR) {
std::cout << "opengl error is: " << stringFromGlError(err) << std::endl;
}
}
void discardLastGlError(bool print)
{
GLenum err = glGetError();
if (print) {
printGlError(err);
}
}
// return false if there's an error
bool checkAndPrintGlError()
{
GLenum err = glGetError();
printGlError(err);
return true;
}
const char *stringFromGlError(GLenum err)
{
switch(err) {
case GL_INVALID_ENUM: return "GL_INVALID_ENUM"; break;
case GL_INVALID_VALUE: return "GL_INVALID_VALUE"; break;
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION"; break;
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY"; break;
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION"; break;
default: return "<unknown>"; break;
}
}

View file

@ -93,3 +93,13 @@ TBufferObject(void, map)(GLenum access) {
TBufferObject(void, unmap)() { TBufferObject(void, unmap)() {
// todo // todo
} }
void discardLastGlError(bool print=false);
// return false if there's an error
bool checkAndPrintGlError();
void printGlError(GLenum err);
const char *stringFromGlError(GLenum err);

View file

@ -2,29 +2,6 @@
#include <iostream> #include <iostream>
void discardLastGlError()
{
glGetError();
}
void checkAndPrintGlError()
{
GLenum err = glGetError();
const char *errString;
switch(err) {
case GL_INVALID_ENUM: errString = "GL_INVALID_ENUM"; break;
case GL_INVALID_VALUE: errString = "GL_INVALID_VALUE"; break;
case GL_INVALID_OPERATION: errString = "GL_INVALID_OPERATION"; break;
case GL_OUT_OF_MEMORY: errString = "GL_OUT_OF_MEMORY"; break;
case GL_INVALID_FRAMEBUFFER_OPERATION: errString = "GL_INVALID_FRAMEBUFFER_OPERATION"; break;
default: errString = "<unknown>"; break;
}
if (err != GL_NO_ERROR) {
std::cout<<"glGetAttribLocation() returned error: " << errString << std::endl;
}
}
namespace endofthejedi { namespace endofthejedi {
PolygonModel::PolygonModel(const std::string &filename) PolygonModel::PolygonModel(const std::string &filename)
: m_filename(filename) : m_filename(filename)

View file

@ -8,14 +8,16 @@
namespace game { namespace game {
void ShootCommand::apply(Player *player, State *state) const void ShootCommand::apply(Player *player, State *state) const
{ {
//std::cout<<"apply command " << name() << std::endl;
// TODO: idea // TODO: idea
// shoot multiple rockets at once or from different positions after // shoot multiple rockets at once or from different positions after
// level up / upgrade ... // level up / upgrade ...
// angles are supplied in degrees and are CCW // angles are supplied in degrees and are CCW
Missile *missile = new Missile(player, player->ship->position, -util::deg2rad(m_angle), player->speed); Missile *missile = new Missile(
player,
player->ship->position,
-util::deg2rad(m_angle),
0.005*player->speed);
Trace *trace = new Trace(missile); Trace *trace = new Trace(missile);
missile->trace = trace; missile->trace = trace;
@ -30,9 +32,7 @@ namespace game {
{ {
(void) state; (void) state;
// TODO
return player->alive && player->energy >= player->speed; return player->alive && player->energy >= player->speed;
//return player->alive;
} }
void ChangeNameCommand::apply(Player *player, State *state) const void ChangeNameCommand::apply(Player *player, State *state) const
@ -51,6 +51,11 @@ namespace game {
void SetSpeedCommand::apply(Player *player, State *state) const void SetSpeedCommand::apply(Player *player, State *state) const
{ {
(void) state; (void) state;
if (m_speed < 0.0) {
return;
}
player->speed = m_speed; player->speed = m_speed;
} }