Permalink
Browse files

Able to add new blocks, but there's a segfault I need to diagnose

  • Loading branch information...
1 parent 5e940f1 commit b72998e13decbdcd5deb46428565e0173444c8bb @RachelJMorris committed Mar 20, 2013
Showing with 41 additions and 1 deletion.
  1. +40 −1 Input.cpp
  2. +1 −0 Input.h
View
@@ -12,6 +12,25 @@ Input::Input() : m_timeoutMax( 5.0 )
m_cursorTimeout = 0.0;
}
+void Input::CreateNewBox( std::vector<Geometry>& lstBoxes )
+{
+ // Create a new one!
+ // Position, Dimensions, Index
+ lstBoxes.push_back( Geometry(
+ sf::Vector3f(
+ m_cursorPosition.x,
+ m_cursorPosition.y,
+ m_cursorPosition.z
+ ),
+ sf::Vector3f( 10, 10, 10 ),
+ sf::Vector3i(
+ m_cursorPosition.x / 10,
+ m_cursorPosition.y / 10,
+ m_cursorPosition.z / 10
+ )
+ ) );
+}
+
void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBoxes, GLuint lstTextures[5], float mapWidth, float mapDepth )
{
if ( m_cursorTimeout > 0 )
@@ -29,7 +48,7 @@ void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>
HandleMouseControls( input, app, lstBoxes );
// Find active box
- int activeBox = 0;
+ int activeBox = -1;
for ( int i = 0; i < lstBoxes.size(); i++ )
{
if ( lstBoxes[i].CheckCursor( CursorPosition() ) )
@@ -40,22 +59,42 @@ void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>
if ( input.IsKeyDown( sf::Key::Num0 ) )
{
+ if ( activeBox == -1 )
+ {
+ CreateNewBox( lstBoxes );
+ }
lstBoxes[activeBox].SetTexture( lstTextures[0] );
}
else if ( input.IsKeyDown( sf::Key::Num1 ) )
{
+ if ( activeBox == -1 )
+ {
+ CreateNewBox( lstBoxes );
+ }
lstBoxes[activeBox].SetTexture( lstTextures[1] );
}
else if ( input.IsKeyDown( sf::Key::Num2 ) )
{
+ if ( activeBox == -1 )
+ {
+ CreateNewBox( lstBoxes );
+ }
lstBoxes[activeBox].SetTexture( lstTextures[2] );
}
else if ( input.IsKeyDown( sf::Key::Num3 ) )
{
+ if ( activeBox == -1 )
+ {
+ CreateNewBox( lstBoxes );
+ }
lstBoxes[activeBox].SetTexture( lstTextures[3] );
}
else if ( input.IsKeyDown( sf::Key::Num4 ) )
{
+ if ( activeBox == -1 )
+ {
+ CreateNewBox( lstBoxes );
+ }
lstBoxes[activeBox].SetTexture( lstTextures[4] );
}
View
@@ -21,6 +21,7 @@ class Input
GLuint lstTextures[5], float mapWidth, float mapDepth );
void DrawCursor();
+ void CreateNewBox( std::vector<Geometry>& lstBlocks );
sf::Vector3f CursorPosition() { return m_cursorPosition; }

0 comments on commit b72998e

Please sign in to comment.