From 965c4d926949f1b1ed60d7cc10474309396b09af Mon Sep 17 00:00:00 2001 From: "Martin Felis (lola)" Date: Sun, 2 Jan 2011 18:25:20 +0100 Subject: [PATCH] quick and dirty editor works for now --- asteroids/AsteroidsEnums.h | 1 + asteroids/Controller.cc | 8 ++ asteroids/Controller.h | 1 + asteroids/Model.cc | 1 + asteroids/Model.h | 10 ++ asteroids/View.cc | 268 ++++++++++++++++++++++++++++++++++-- asteroids/View.h | 16 +++ engine/ControllerBase.cc | 4 + engine/ControllerBase.h | 6 + engine/DrawingsGL.cc | 2 +- engine/EntityBase.h | 10 +- engine/IMGUIControls.cc | 7 +- engine/IMGUIControls.h | 2 + engine/ModelBase.cc | 28 +++- engine/ModelBase.h | 11 ++ engine/ModelBaseGlobal.h | 5 + engine/PhysicsEntityBase.cc | 16 --- engine/ViewBase.cc | 4 +- engine/ViewBase.h | 2 +- 19 files changed, 360 insertions(+), 42 deletions(-) diff --git a/asteroids/AsteroidsEnums.h b/asteroids/AsteroidsEnums.h index dd54f2e..0481f09 100644 --- a/asteroids/AsteroidsEnums.h +++ b/asteroids/AsteroidsEnums.h @@ -29,6 +29,7 @@ BEGIN_ENUM(ViewState) DECL_ENUM_ELEMENT(ViewStateLevelComplete), DECL_ENUM_ELEMENT(ViewStateShowHighscore), DECL_ENUM_ELEMENT(ViewStateEnterPlayername), + DECL_ENUM_ELEMENT(ViewStateEditor), DECL_ENUM_ELEMENT(ViewStateOptions), DECL_ENUM_ELEMENT(ViewStateGameOver), DECL_ENUM_LAST(ViewState) diff --git a/asteroids/Controller.cc b/asteroids/Controller.cc index 96429b0..c817768 100644 --- a/asteroids/Controller.cc +++ b/asteroids/Controller.cc @@ -49,4 +49,12 @@ void Controller::ResetPlayerEntity () { GetModel()->SetPlayerEntityId(Engine::NullEntityId); } +void Controller::ResetLevel() { + Engine::LogMessage ("Resetting level"); + + GetModel()->ClearEntities(); + GetModel()->mAsteroids.clear(); + ResetPlayerEntity(); +} + } diff --git a/asteroids/Controller.h b/asteroids/Controller.h index 018bbb2..8929145 100644 --- a/asteroids/Controller.h +++ b/asteroids/Controller.h @@ -23,6 +23,7 @@ class Controller : public Engine::ControllerBase { Controller () {}; void ResetPlayerEntity (); + void ResetLevel(); protected: /** \brief Set up basic keybindings */ virtual int OnInit (int argc, char* argv[]); diff --git a/asteroids/Model.cc b/asteroids/Model.cc index 24f65b5..19f78b4 100644 --- a/asteroids/Model.cc +++ b/asteroids/Model.cc @@ -32,6 +32,7 @@ int Model::OnInit (int argc, char* argv[]) { /// \TODO use or similar for initialization of mCurrentLevelIndex mCurrentLevelIndex = 99999; + mLevelName = ""; if (InitLevelList() == 0) Engine::LogError ("No levels found!"); diff --git a/asteroids/Model.h b/asteroids/Model.h index 54ce104..6c6de62 100644 --- a/asteroids/Model.h +++ b/asteroids/Model.h @@ -23,6 +23,7 @@ class Model : public Engine::ModelBase { /* Level loading etc. */ int DoLoadLevel (const char* filename); int DoSaveLevel (const char* filename); + void ResetLevel (); void ReloadLevel(); void ProceedToNextLevel (); @@ -34,6 +35,12 @@ class Model : public Engine::ModelBase { mPlayerName = name; }; + std::string GetLevelName() { return mLevelName; }; + void SetLevelName(const std::string &name) { + Engine::LogMessage("new level name: %s", name.c_str()); + mLevelName = name; + } + /* Highscore */ struct HighscoreEntry { HighscoreEntry(): name ("unknown"), points (0) { }; @@ -74,12 +81,15 @@ class Model : public Engine::ModelBase { int mPlayerLives; unsigned int mPoints; unsigned int mCurrentLevelIndex; + std::string mPlayerName; std::vector mLevelList; + std::string mLevelName; virtual bool OnReceiveEvent (const Engine::EventBasePtr &event); friend class View; + friend class Controller; }; } diff --git a/asteroids/View.cc b/asteroids/View.cc index c6a21ed..1d70e9c 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -2,6 +2,8 @@ #include "CameraBase.h" #include "SimpleConsoleOverlay.h" #include "IMGUIControls.h" +#include "keytable.h" +#include "DrawingsGL.h" #include "Engine.h" #include "Physics.h" @@ -56,6 +58,10 @@ int View::OnInit (int argc, char* argv[]) { mBackgroundStars.push_back (star); } + // Editor default variables + mEditorEntityId = 0; + mEditorState = EditorStateUnknown; + mGUIShipSprite.LoadFromPNG(Engine::GetResourceFullPath("/data/textures/ship.png")); mGUIShipSprite.SetScale (0.1); @@ -240,7 +246,15 @@ void View::Draw() { DrawAxis (); */ - DrawWorld (); + std::map::iterator entity_iterator; + Model *game_model = static_cast (mModel); + unsigned int game_state = game_model->GetGameState(); + + DrawStars (); + + if ( game_state == GameStateRunning || GetViewState() == ViewStateEditor) { + DrawWorld (); + } DrawUi (); @@ -250,15 +264,8 @@ void View::Draw() { void View::DrawWorld() { std::map::iterator entity_iterator; - Model *game_model = static_cast (mModel); - DrawStars (); - - if ( game_model->GetGameState() != GameStateRunning) { - return; - } - ViewBase::DrawWorld(); for (entity_iterator = game_model->mEntities.begin (); @@ -271,6 +278,15 @@ void View::DrawWorld() { float world_width = game_physics->GetWorldWidth(); float world_height = game_physics->GetWorldHeight(); + // if we are in Edit mode and are currently editing the velocity we must + // make sure that we display it + if (GetViewState() == ViewStateEditor) { + if (mEditorState == EditorStateEntityVelocity) { + DrawVector (entity->mPhysicState->GetPosition(), + entity->mPhysicState->GetPosition() + entity->mPhysicState->GetVelocity()); + } + } + // Drawing at the original position: glPushMatrix (); glTranslatef (entity->mPhysicState->mPosition[0], @@ -289,7 +305,6 @@ void View::DrawWorld() { // If we move out the right side if (entity->mPhysicState->mPosition[0] + entity->mPhysicState->mRadius * 2 >= world_width * 0.5) { - glPushMatrix (); glTranslatef (entity->mPhysicState->mPosition[0] - world_width, entity->mPhysicState->mPosition[1], @@ -395,8 +410,8 @@ void View::DrawUi () { ViewState current_view_state = GetViewState(); -// SelectFont ("console.ttf size=12"); -// Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16); + SelectFont ("console.ttf size=12"); + Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16); switch (current_view_state) { case ViewStateMainMenu: @@ -426,6 +441,9 @@ void View::DrawUi () { case ViewStateGameOver: DrawUiGameOver(); break; + case ViewStateEditor: + DrawUiEditor(); + break; default: Engine::LogWarning ("Trying to draw unknown ViewState: %s (%d)", GetStringViewState (game_state), game_state); @@ -469,6 +487,10 @@ void View::DrawUiMainMenu() { PushViewState(ViewStateShowHighscore); } + if (Engine::GUI::Button (6, "E", screen_right - 48, 20, 32, button_height)) { + PushViewState(ViewStateEditor); + } + if (Engine::GUI::Button (4, "Quit", screen_right * 0.5 - 100, 380, button_width, button_height)) { Engine::RunCommand("quit"); } @@ -542,7 +564,19 @@ void View::DrawUiLevelComplete() { if(Engine::GUI::Button (1, "Next level ...", (screen_right - button_width) * 0.5, screen_bottom * 0.5 + 60, button_width, button_height)) { PopViewState(); - GetModel()->ProceedToNextLevel(); + + // we have to take care when we are testing the level to not proceed to + // the next level... + if (GetViewState() == ViewStateEditor) { + GetModel()->SetGameState(GameStatePaused); + + if (mEditorState == EditorStateTest) { + GetModel()->DoLoadLevel("level_edit_temp.txt"); + mEditorState = EditorStateUnknown; + } + } else { + GetModel()->ProceedToNextLevel(); + } } } @@ -580,8 +614,20 @@ void View::DrawUiPlayerDied() { if (Engine::GUI::Button (1, "Continue", screen_right * 0.5 - 100, 380, button_width, button_height)) { PopViewState(); - GetModel()->ReloadLevel(); - GetModel()->SetGameState(GameStateRunning); + + // we have to take care when we are testing the level to not proceed to + // the next level... + if (GetViewState() == ViewStateEditor) { + GetModel()->SetGameState(GameStatePaused); + + if (mEditorState == EditorStateTest) { + GetModel()->DoLoadLevel("level_edit_temp.txt"); + mEditorState = EditorStateUnknown; + } + } else { + GetModel()->ReloadLevel(); + GetModel()->SetGameState(GameStateRunning); + } } } @@ -718,6 +764,199 @@ void View::DrawUiEnterPlayername() { } } +void View::DrawUiEditor() { +// DrawPageTitle ("Editor"); + SelectFont ("console.ttf size=23"); + + // Special case: if we get here and are currently in the editor state + // EditorStateTest, then we returned from our test. In this case we have to + // reset the editor state + if (mEditorState == EditorStateTest) { +// mEditorState = EditorStateUnknown; +// Engine::LogMessage ("Returned from testing"); + } + + // The close button + if (Engine::GUI::Button (1, "X", screen_right - 48, 20, 32, button_height) + || Engine::GUI::CheckKeyPress(SDLK_ESCAPE)) { + if (mEditorState == EditorStateTest) { + mEditorState = EditorStateUnknown; + + GetModel()->DoLoadLevel("level_edit_temp.txt"); + GetModel()->SetGameState(GameStatePaused); + } else { + PopViewState(); + } + } + + if (mEditorState != EditorStateTest) { + if (Engine::GUI::Button (2, "+", 30, 20, 32, button_height)) { + mEditorState = EditorStateAddEntity; + } + + if (Engine::GUI::Button (3, "M", 70, 20, 32, button_height)) { + mEditorState = EditorStateMoveEntity; + } + + if (Engine::GUI::Button (4, "V", 110, 20, 32, button_height)) { + mEditorState = EditorStateEntityVelocity; + } + + if (Engine::GUI::Button (5, "S", 150, 20, 32, button_height)) { + mEditorState = EditorStateSave; + } + + if (Engine::GUI::Button (6, "L", 190, 20, 32, button_height)) { + mEditorState = EditorStateLoad; + } + + if (Engine::GUI::Button (7, "T", 230, 20, 32, button_height)) { + mEditorState = EditorStateTest; + + GetModel()->DoSaveLevel("level_edit_temp.txt"); + GetModel()->SetGameState(GameStateRunning); + } + } + + std::ostringstream mouse_pos_str; + vector3d mouse_world_pos; + Controller* controller = GetController(); + + controller->GetMouseWorldPosition(mouse_world_pos); + mouse_pos_str << mouse_world_pos[0] << "," << mouse_world_pos[2]; + + if (mEditorState == EditorStateAddEntity) { + SelectFont ("console.ttf size=12"); + Engine::GUI::Label (9999, "Adding", 128, 16); + + if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) { + // if there is no entity so far we create a player, otherwise we create + // an asteroid + + Engine::EntityBase* entity = NULL; + GameEntityType entity_type = GameEntityTypeShip; + if (GetModel()->GetPlayerEntityId() != 0) { + entity = Engine::CreateEntity(GameEntityTypeAsteroid); + entity->mPhysicState->SetVelocity (vector3d (0., 0., -1.)); + } else { + entity = Engine::CreateEntity(GameEntityTypeShip); + GetModel()->SetPlayerEntityId(entity->mId); + + entity->mPhysicState->SetOrientation (vector3d (0., 90., 0.)); + } + + // Now we want to insert an Asteroid at the given position + entity->mPhysicState->SetPosition (vector3d (mouse_world_pos[0], 0., mouse_world_pos[2])); + + mEditorState = EditorStateUnknown; + } + } + + if (mEditorState == EditorStateMoveEntity) { + SelectFont ("console.ttf size=12"); + Engine::GUI::Label (9999, "Moving", 128, 16); + + if (controller->GetButtonState(MouseButtonLeft)) { + // Check if there is an entity near the given position + Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos); + if (asteroid) { + mEditorEntityId = asteroid->mId; + } + } + + if (mEditorEntityId != 0) { + Engine::EntityBase* asteroid = Engine::GetEntity (mEditorEntityId); + asteroid->mPhysicState->SetPosition (mouse_world_pos); + } + + if (!controller->GetButtonState(MouseButtonLeft)) { + if (mEditorEntityId != 0) { + mEditorEntityId = 0; + } + } + } + + if (mEditorState == EditorStateEntityVelocity) { + SelectFont ("console.ttf size=12"); + Engine::GUI::Label (9999, "Velocity", 128, 16); + + if (mEditorEntityId == 0) { + if (controller->GetButtonState(MouseButtonLeft)) { + // Check if there is an entity near the given position + Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos); + if (asteroid) { + mEditorEntityId = asteroid->mId; + } + } + } + + if (mEditorEntityId != 0) { + Engine::EntityBase* asteroid = Engine::GetEntity (mEditorEntityId); + + vector3d new_velocity = mouse_world_pos - asteroid->mPhysicState->GetPosition(); + new_velocity[1] = 0.; + asteroid->mPhysicState->SetVelocity (new_velocity); + + if (!controller->GetButtonState(MouseButtonLeft)) { + if (mEditorEntityId != 0) { + mEditorEntityId = 0; + } + } + } + } + + if (mEditorState == EditorStateSave) { + glColor3f (0.2, 0.2, 0.2); + Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200); + Engine::GUI::Label (9999, "Saving", 128, 16); + SelectFont ("console.ttf size=23"); + + Engine::GUI::Label(51, "Filename: ", 145, 180); + std::string level_name = GetModel()->GetLevelName(); + + glColor3f (1., 1., 1.); + if (Engine::GUI::LineEdit(52, 145, 210, level_name, 32)) + GetModel()->SetLevelName(level_name); + + if (Engine::GUI::Button (54, "Save", 145, 300, button_width, button_height)) { + GetModel()->DoSaveLevel((level_name + std::string(".txt")).c_str()); + Engine::LogMessage ("Save"); + mEditorState = EditorStateUnknown; + } + + if (Engine::GUI::Button (55, "Cancel", screen_right - 140 - 5 - button_width, 300, button_width, button_height)) + mEditorState = EditorStateUnknown; + } + + if (mEditorState == EditorStateLoad) { + glColor3f (0.2, 0.2, 0.2); + Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200); + Engine::GUI::Label (9999, "Loading", 128, 16); + SelectFont ("console.ttf size=23"); + + Engine::GUI::Label(51, "Filename: ", 145, 180); + std::string level_name = GetModel()->GetLevelName(); + + glColor3f (1., 1., 1.); + if (Engine::GUI::LineEdit(52, 145, 210, level_name, 32)) + GetModel()->SetLevelName(level_name); + + if (Engine::GUI::Button (54, "Load", 145, 300, button_width, button_height)) { + GetModel()->DoLoadLevel((level_name + std::string(".txt")).c_str()); + Engine::LogMessage ("Load"); + mEditorState = EditorStateUnknown; + } + + if (Engine::GUI::Button (55, "Cancel", screen_right - 140 - 5 - button_width, 300, button_width, button_height)) + mEditorState = EditorStateUnknown; + } + + if (controller->GetButtonState(MouseButtonRight) + || controller->GetButtonState(SDLK_ESCAPE) ) { + mEditorState = EditorStateUnknown; + } +} + /* * Entities */ @@ -733,6 +972,7 @@ void View::DrawEntity (Engine::EntityBase *entity) { else { Engine::LogError ("Cannot draw entity: unknown type '%d'", entity->mType); } + } /// \todo: Update of the animation ?? diff --git a/asteroids/View.h b/asteroids/View.h index fb78600..da76599 100644 --- a/asteroids/View.h +++ b/asteroids/View.h @@ -55,8 +55,11 @@ class View : public Engine::ViewBase { void DrawUiOptions(); void DrawUiEnterPlayername(); + void DrawUiEditor(); + virtual void Draw (); virtual void DrawWorld (); + void DrawEntities(); void DrawStars (); void DrawEntity (Engine::EntityBase *entity); @@ -130,6 +133,19 @@ class View : public Engine::ViewBase { int button_width; int button_height; + enum EditorState { + EditorStateUnknown = 0, + EditorStateAddEntity, + EditorStateMoveEntity, + EditorStateSave, + EditorStateEntityVelocity, + EditorStateLoad, + EditorStateTest + }; + + EditorState mEditorState; + unsigned int mEditorEntityId; + /// \brief can be used to perform some fading, etc. float mFadeTimerSecValue; diff --git a/engine/ControllerBase.cc b/engine/ControllerBase.cc index 54cb273..40784c4 100644 --- a/engine/ControllerBase.cc +++ b/engine/ControllerBase.cc @@ -60,6 +60,7 @@ int ControllerBase::OnInit (int argc, char* argv[]) { uistate.kbditem = 0; uistate.last_keysym = SDLK_CLEAR; uistate.last_unicode = 0; + uistate.last_key = SDLK_CLEAR; uistate.lastwidget = 0; @@ -162,12 +163,14 @@ void ControllerBase::IMGUIFinish () { // also reset the last keysym such that old values will not be reported uistate.last_keysym = SDLK_FIRST; + uistate.last_key = SDLK_FIRST; } /** \brief Keyboard processing */ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) { mButtonStates.set(keysym.sym, true); uistate.last_keysym = keysym.sym; + uistate.last_key = keysym.sym; // Only when Unicode processing is activated store the unicode value if (SDL_EnableUNICODE(-1)) { @@ -208,6 +211,7 @@ bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) { bool ControllerBase::OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos) { MouseButton mouse_button = convert_sdl_button (button); mButtonStates.set(mouse_button, true); + uistate.last_key = mouse_button; if (mView->mOverlayManager.SendMouseButtonDown (button, xpos, ypos)) return true; diff --git a/engine/ControllerBase.h b/engine/ControllerBase.h index 97bef9d..9fb7fed 100644 --- a/engine/ControllerBase.h +++ b/engine/ControllerBase.h @@ -20,6 +20,7 @@ struct IMGUIState { int kbditem; SDLKey last_keysym; Uint16 last_unicode; + int last_key; int lastwidget; }; @@ -59,6 +60,11 @@ class ControllerBase : public Module { pos_out[1] = mMouseWorldPosition[1]; pos_out[2] = mMouseWorldPosition[2]; } + void GetMouseWorldPosition (vector3d &pos_out) { + pos_out[0] = mMouseWorldPosition[0]; + pos_out[1] = mMouseWorldPosition[1]; + pos_out[2] = mMouseWorldPosition[2]; + } bool GetButtonState (unsigned int key) { assert (key < BINDING_KEYS_LAST); return mButtonStates.test(key); diff --git a/engine/DrawingsGL.cc b/engine/DrawingsGL.cc index dbd51b6..102c111 100644 --- a/engine/DrawingsGL.cc +++ b/engine/DrawingsGL.cc @@ -224,7 +224,7 @@ void DrawVector(vector3d start, vector3d end) { float rad_delta = 2. * M_PI / (float) segments; double s,c; - glColor3f(0.2, 0.2, 0.5); + glColor3f(0.2, 0.8, 0.2); glPointSize (10.); glBegin (GL_TRIANGLE_FAN); glVertex3f (end[0], end[1], end[2]); diff --git a/engine/EntityBase.h b/engine/EntityBase.h index e911ef5..17ae4a5 100644 --- a/engine/EntityBase.h +++ b/engine/EntityBase.h @@ -70,10 +70,10 @@ struct EntityPhysicState { vector3d &GetOrientation (); float &GetAngleVelocity (); - void SetPosition (const vector3d &position); - void SetVelocity (const vector3d &velocity); - void SetOrientation (const vector3d &orientation); - void SetAngleVelocity (const float &angle_velocity); + void SetPosition (const vector3d &position) { mPosition = position; } + void SetVelocity (const vector3d &velocity) { mVelocity = velocity; } + void SetOrientation (const vector3d &orientation) { mOrientation = orientation; } + void SetAngleVelocity (const float &angle_velocity) { mAngleVelocity = angle_velocity; } /** \brief Transforms the given vector in local space to world coordinates */ void Globalize (vector3d &vec); @@ -149,6 +149,8 @@ struct EntityBase { } }; +typedef std::map::iterator EntityBaseIter; + } #endif // _ENTITYBASE_H diff --git a/engine/IMGUIControls.cc b/engine/IMGUIControls.cc index e643ea0..f583816 100644 --- a/engine/IMGUIControls.cc +++ b/engine/IMGUIControls.cc @@ -69,7 +69,7 @@ void DrawRoundedBlock (int x, int y, int w, int h) { assert (w > d); glBegin(GL_QUADS); - // lower part + // lower part glVertex3f (x, y, 0.); glVertex3f (x, y + d, 0.); glVertex3f (x + w, y + d, 0.); @@ -127,7 +127,6 @@ void Label (int id, const char* caption, int x, int y) { view = EngineGetView (); assert (view); - glColor3f (1., 1., 1.); view->DrawGLStringMeasure(caption, &width, &height); view->DrawGLString(x , y + height * 0.5, caption); } @@ -148,6 +147,7 @@ void LabelCentered (int id, const char* caption, int x, int y) { view = EngineGetView (); assert (view); + SelectFont("console.ttf size=23"); view->DrawGLStringMeasure(caption, &width, &height); view->DrawGLString(x - 0.5 * width, y + height * 0.5, caption); } @@ -334,6 +334,7 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng if (controller->uistate.kbditem == id && SDL_GetTicks() >> 9 & 1) text_output += "_"; + SelectFont("console.ttf size=23"); view->DrawGLStringMeasure(text_value.c_str(), &width, &height); view->DrawGLString(textpos_x, textpos_y, text_output.c_str()); @@ -507,7 +508,7 @@ float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float } bool CheckKeyPress (int keycode) { - if (controller->uistate.last_keysym == keycode) + if (controller->uistate.last_key == keycode) return true; return false; diff --git a/engine/IMGUIControls.h b/engine/IMGUIControls.h index 029edcb..ad7d4a5 100644 --- a/engine/IMGUIControls.h +++ b/engine/IMGUIControls.h @@ -17,6 +17,8 @@ namespace GUI { /** \brief Checks whether the mouse is in the given rectangle */ bool regionhit (int x, int y, int w, int h); +void DrawRoundedBlock (int x, int y, int w, int h); + /** \brief Draws a label at the given position with vertical center at y */ void Label (int id, const char* caption, int x, int y); /** \brief Draws a label centered at the given position with vertical center at y */ diff --git a/engine/ModelBase.cc b/engine/ModelBase.cc index d3f3f0b..6f89f8b 100644 --- a/engine/ModelBase.cc +++ b/engine/ModelBase.cc @@ -175,6 +175,24 @@ EntityBase* ModelBase::GetEntity (const unsigned int id) { return NULL; } +EntityBase* ModelBase::GetEntityAt (const vector3d &pos) { + std::map::iterator iter = mEntities.begin(); + + while (iter != mEntities.end ()) { + EntityPhysicState* entity = iter->second->mPhysicState; + /// \todo fix const casting! + vector3d temp_pos (pos); + + if ( (temp_pos - entity->GetPosition()).length() < entity->mRadius) + return iter->second; + + iter++; + } + + return NULL; +} + + unsigned int ModelBase::CreateEntityId () { if (mEntityIdCounter == NullEntityId - 1) LogError ("Could not create valid entity id, reached maximum value of %u", mEntityIdCounter); @@ -307,7 +325,7 @@ void KillEntity (unsigned int id) { ModelInstance->KillEntity (id); } -EntityBase * GetEntity (unsigned int id) { +EntityBase* GetEntity (unsigned int id) { if (!ModelInstance) { LogError ("Couldn't execute GetEntity(): Model not initialized!"); } @@ -315,6 +333,14 @@ EntityBase * GetEntity (unsigned int id) { return ModelInstance->GetEntity (id); } +EntityBase* GetEntityAt(const vector3d &pos) { + if (!ModelInstance) { + LogError ("Couldn't execute GetEntityAt(): Model not initialized!"); + } + + return ModelInstance->GetEntityAt (pos); +} + EntityPhysicState * GetEntityPhysicState (unsigned int id) { EntityBase *entity = GetEntity (id); diff --git a/engine/ModelBase.h b/engine/ModelBase.h index 7427ac6..4e3a864 100644 --- a/engine/ModelBase.h +++ b/engine/ModelBase.h @@ -68,6 +68,17 @@ class ModelBase : public Module { EntityBase* CreateEntity (int type); /** Returns the Entity with the given id */ EntityBase* GetEntity (const unsigned int id); + + /** Returns the Entity at the given world coordinates */ + EntityBase* GetEntityAt (const vector3d &pos); + + EntityBaseIter GetEntityIterBegin () { + return mEntities.begin(); + } + EntityBaseIter GetEntityIterEnd() { + return mEntities.end(); + } + /** Returns a unused id for an Entity */ unsigned int CreateEntityId (); /** Removes all Entities */ diff --git a/engine/ModelBaseGlobal.h b/engine/ModelBaseGlobal.h index ae62cbc..af0e6e6 100644 --- a/engine/ModelBaseGlobal.h +++ b/engine/ModelBaseGlobal.h @@ -2,9 +2,14 @@ #define _MODELGLOBAL_H namespace Engine { +class EntityBase; /** \brief Adds the function callback as command for the given name*/ unsigned int GetPlayerEntityId (); + +/** \brief Returns the entity at the given world coordinates or NULL */ +EntityBase* GetEntityAt(const vector3d &pos); + /** \brief Assigns the player to an Entity. All controls will be redirected to that player * * This can be used to disable the controls of of the player by assinging diff --git a/engine/PhysicsEntityBase.cc b/engine/PhysicsEntityBase.cc index 043f836..fab771b 100644 --- a/engine/PhysicsEntityBase.cc +++ b/engine/PhysicsEntityBase.cc @@ -53,22 +53,6 @@ float& EntityPhysicState::GetAngleVelocity () { return mAngleVelocity; } -void EntityPhysicState::SetPosition (const vector3d &position) { - mPosition = position; -} - -void EntityPhysicState::SetVelocity (const vector3d &velocity) { - mVelocity = velocity; -} - -void EntityPhysicState::SetOrientation (const vector3d &orientation) { - mOrientation = orientation; -} - -void EntityPhysicState::SetAngleVelocity (const float &angle_velocity) { - mAngleVelocity = angle_velocity; -} - void EntityPhysicState::Globalize (vector3d &vec) { // make a copy of the local coordinates vector3d local (vec); diff --git a/engine/ViewBase.cc b/engine/ViewBase.cc index 4065554..dedf2be 100644 --- a/engine/ViewBase.cc +++ b/engine/ViewBase.cc @@ -362,7 +362,8 @@ void ViewBase::DrawGrid () { xstep = 1.; zstep = 1.; - glColor3f (1., 1., 1.); + glColor3f (0.8, 0.8, 0.8); + glLineWidth(1.); glBegin (GL_LINES); for (i = 0; i <= count_x; i++) { glVertex3f (i * xstep + xmin, 0., zmin); @@ -373,7 +374,6 @@ void ViewBase::DrawGrid () { glVertex3f (xmax, 0, i * zstep + zmin); } glEnd (); - } void ViewBase::DrawWorld () { diff --git a/engine/ViewBase.h b/engine/ViewBase.h index 7b7a919..36c21f5 100644 --- a/engine/ViewBase.h +++ b/engine/ViewBase.h @@ -81,7 +81,7 @@ class ViewBase : public Module{ bool SendMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos); bool SendMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos); */ - + private: protected: /** \brief Initializes the system */