From 2d0681266c920492a80a62f050f8d2c035b15c11 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Tue, 1 Nov 2011 23:20:15 +0000 Subject: [PATCH] [Fix] -- Mem leak due to allocating memory for the player each frame. -- This is not functioning fully yet, the push is just to check out the new twitter feed. --- Unuk-QT/Unuk-QT.pro.user | 37 +++++++++++++-------------- src/Unuk/Game.cpp | 55 +++++++++++++++++++++++++++++++++++----- src/Unuk/Game.h | 4 +++ src/Unuk/Player.cpp | 27 ++++++++++++-------- src/Unuk/Player.h | 6 ++--- src/Unuk/main.cpp | 16 ++++++------ 6 files changed, 98 insertions(+), 47 deletions(-) diff --git a/Unuk-QT/Unuk-QT.pro.user b/Unuk-QT/Unuk-QT.pro.user index 7b8b512..4fbe52a 100644 --- a/Unuk-QT/Unuk-QT.pro.user +++ b/Unuk-QT/Unuk-QT.pro.user @@ -76,26 +76,26 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-4UYrGe6jeO,guid=40a924bb0ee270060bcf5bef0012a938 + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KIZOCtJ0Qj,guid=2d6e4614e1a8d0c60ff1566700000052 DISPLAY=:0 HOME=/home/allanis HUSHLOGIN=FALSE LD_LIBRARY_PATH=/usr/lib/qtcreator LOGNAME=allanis - LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: + LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: MAIL=/var/mail/allanis PATH=/usr/bin:/home/allanis/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin:/sbin PWD=/home/allanis QTDIR=/usr/share/qt4 SHELL=/bin/bash SHLVL=1 - SSH_AGENT_PID=23095 - SSH_AUTH_SOCK=/tmp/ssh-cvzHtqq23070/agent.23070 + SSH_AGENT_PID=3289 + SSH_AUTH_SOCK=/tmp/ssh-bmvArYgf3264/agent.3264 TERM=linux USER=allanis - WINDOWPATH=8 + WINDOWPATH=7 XAUTHORITY=/home/allanis/.Xauthority - XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319391241.38441-1429138967 + XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319816808.532592-2012073557 _=/usr/bin/startx @@ -115,26 +115,26 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-4UYrGe6jeO,guid=40a924bb0ee270060bcf5bef0012a938 + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KIZOCtJ0Qj,guid=2d6e4614e1a8d0c60ff1566700000052 DISPLAY=:0 HOME=/home/allanis HUSHLOGIN=FALSE LD_LIBRARY_PATH=/usr/lib/qtcreator LOGNAME=allanis - LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: + LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: MAIL=/var/mail/allanis PATH=/usr/bin:/home/allanis/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin:/sbin PWD=/home/allanis QTDIR=/usr/share/qt4 SHELL=/bin/bash SHLVL=1 - SSH_AGENT_PID=23095 - SSH_AUTH_SOCK=/tmp/ssh-cvzHtqq23070/agent.23070 + SSH_AGENT_PID=3289 + SSH_AUTH_SOCK=/tmp/ssh-bmvArYgf3264/agent.3264 TERM=linux USER=allanis - WINDOWPATH=8 + WINDOWPATH=7 XAUTHORITY=/home/allanis/.Xauthority - XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319391241.38441-1429138967 + XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319816808.532592-2012073557 _=/usr/bin/startx false @@ -151,27 +151,26 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-jZvtFgh4Q8,guid=64951d68d90161d18293293f00000185 + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KIZOCtJ0Qj,guid=2d6e4614e1a8d0c60ff1566700000052 DISPLAY=:0 HOME=/home/allanis HUSHLOGIN=FALSE - LANGUAGE= LD_LIBRARY_PATH=/usr/lib/qtcreator LOGNAME=allanis - LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: + LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: MAIL=/var/mail/allanis PATH=/usr/bin:/home/allanis/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/sbin:/sbin PWD=/home/allanis QTDIR=/usr/share/qt4 SHELL=/bin/bash SHLVL=1 - SSH_AGENT_PID=4618 - SSH_AUTH_SOCK=/tmp/ssh-GLBfmvFD4589/agent.4589 + SSH_AGENT_PID=3289 + SSH_AUTH_SOCK=/tmp/ssh-bmvArYgf3264/agent.3264 TERM=linux USER=allanis WINDOWPATH=7 XAUTHORITY=/home/allanis/.Xauthority - XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1318168661.569853-1852884431 + XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319816808.532592-2012073557 _=/usr/bin/startx true @@ -181,7 +180,7 @@ /usr/bin/make true - /drv/storage/Projects/Portfolio/saracraft/trunk/Unuk/Unuk-QT + /home/allanis/Unuk/Unuk-QT true clean diff --git a/src/Unuk/Game.cpp b/src/Unuk/Game.cpp index 40015d5..8905b81 100644 --- a/src/Unuk/Game.cpp +++ b/src/Unuk/Game.cpp @@ -16,17 +16,23 @@ #include "../libUnuk/Debug.h" Game::Game(void) { + m_assets = false; + //m_player = new Player(); + //m_player->SetSprite(); m_rotationAngle = 0.0f; } Game::~Game(void) { - + DeleteAssets(); } bool Game::Init(void) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); + LoadAssets(); + m_assets = true; + return true; } @@ -46,7 +52,6 @@ void Game::Prepare(float dt) { if(m_rotationAngle > 360.0f) { m_rotationAngle -= 360.0f; } - } void Game::Render(void) { @@ -57,10 +62,12 @@ void Game::Render(void) { glRasterPos2i(0, 0); // Draw the test image. - m_player->Render(); + if(m_assets) { + m_player->Render(); + } glFlush(); - //glutSwapBuffers(); + glDisable(GL_TEXTURE_2D); // Get frames per second. @@ -80,19 +87,46 @@ void Game::Render(void) { void Game::Shutdown(void) { Debug::logger->message("\n\n-----Cleaning Up-----"); m_player->CleanUp(); + delete m_player; Debug::logger->message("\nPlayer Deleted."); Debug::closeLog(); } void Game::UpdateProjection(void) { + GLint iViewport[4]; + + // Get a copy of the viewport. + glGetIntegerv(GL_VIEWPORT, iViewport); + glPushMatrix(); + glLoadIdentity(); + + // Save a copy of the projection matrix so that we can restore + // it when it's time to do 3D rendering again. glMatrixMode(GL_PROJECTION); + glPushMatrix(); glLoadIdentity(); // Set up the orthographic projection. - glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, 1000.0); - + glOrtho( iViewport[0], iViewport[0] + iViewport[2], + iViewport[1] + iViewport[3], iViewport[1], -1, 1); glMatrixMode(GL_MODELVIEW); + glPushMatrix(); glLoadIdentity(); + + // Make sure depth testing and lighting are disabled for 2D rendering + //until we are finished rendering in 2D. + glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + +// glMatrixMode(GL_PROJECTION); +// glLoadIdentity(); +// +// // Set up the orthographic projection. +// glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, 1000.0); +// +// glMatrixMode(GL_MODELVIEW); +// glLoadIdentity(); } void Game::OnResize(int width, int height) { @@ -105,3 +139,12 @@ void Game::OnResize(int width, int height) { // Set the projection. UpdateProjection(); } + +void Game::LoadAssets(void) { + m_player = new Player(); + m_player->SetSprite(); +} + +void Game::DeleteAssets(void) { + delete m_player; +} diff --git a/src/Unuk/Game.h b/src/Unuk/Game.h index e11171a..ff7d2a1 100644 --- a/src/Unuk/Game.h +++ b/src/Unuk/Game.h @@ -17,8 +17,12 @@ public: void OnResize(int width, int height); private: + void LoadAssets(void); + void DeleteAssets(void); float m_rotationAngle; Player *m_player; + + bool m_assets; }; #endif diff --git a/src/Unuk/Player.cpp b/src/Unuk/Player.cpp index 6eb6cc8..cb518d5 100644 --- a/src/Unuk/Player.cpp +++ b/src/Unuk/Player.cpp @@ -5,30 +5,31 @@ #include "../libUnuk/Input.h" #include "Player.h" -Player::Player(void) : - m_posx(0), - m_posy(0) {} +Player::Player(void) : m_posx(0), m_posy(0) { + //m_player = new Sprite("../Data/Media/test.bmp"); +} Player::~Player(void) { CleanUp(); } void Player::Prepare(void) { - m_player = new Sprite("../Data/Media/test.bmp"); // I borked up the image loader, so for now we will // rotate the image 180 degrees. m_player->Rotate(180); m_player->SetScale(0.5f, 0.5f); - // Set our pivot to the top right. + //Set our pivot to the top right. m_player->SetPivot(1.0f, 1.0f); + CreateInput(); // Move the player. - if(KeyStillDown(SDLK_w) || KeyStillDown(SDLK_UP)) { SetVelocity(0, -5); } - if(KeyStillDown(SDLK_a) || KeyStillDown(SDLK_LEFT)) { SetVelocity(-5, 0); } - if(KeyStillDown(SDLK_s) || KeyStillDown(SDLK_DOWN)) { SetVelocity( 0, 5); } - if(KeyStillDown(SDLK_d) || KeyStillDown(SDLK_RIGHT)) { SetVelocity( 5, 0); } + if(KeyStillDown(SDLK_w) || KeyStillDown(SDLK_UP)) { SetVelocity(0, -5); } + if(KeyStillDown(SDLK_a) || KeyStillDown(SDLK_LEFT)) { SetVelocity(-5, 0); } + if(KeyStillDown(SDLK_s) || KeyStillDown(SDLK_DOWN)) { SetVelocity( 0, 5); } + if(KeyStillDown(SDLK_d) || KeyStillDown(SDLK_RIGHT)) { SetVelocity( 5, 0); } + UpdateInput(); - SetPosition(m_posx, m_posy); + SetPosition(m_posx, m_posy); } void Player::Render(void) { @@ -36,8 +37,12 @@ void Player::Render(void) { m_player->Render(); } +void Player::SetSprite(void) { + m_player = new Sprite("../Data/Media/test.bmp"); +} + void Player::SetPosition(GLdouble posx, GLdouble posy) { - // -- Set the position of the player sprite. + // Set the position of the player sprite. m_posx = posx; m_posy = posy; diff --git a/src/Unuk/Player.h b/src/Unuk/Player.h index eca7d9b..3672047 100644 --- a/src/Unuk/Player.h +++ b/src/Unuk/Player.h @@ -11,17 +11,17 @@ public: void Prepare(void); void Render(void); + void SetSprite(void); + void SetPosition(GLdouble posx, GLdouble posy); void SetVelocity(GLdouble velx, GLdouble vely); void CleanUp(void); private: - Sprite *m_player; + Sprite* m_player; // Position variables. - GLdouble m_tempx; - GLdouble m_tempy; GLdouble m_posx; GLdouble m_posy; diff --git a/src/Unuk/main.cpp b/src/Unuk/main.cpp index d2e338d..43a3cb8 100644 --- a/src/Unuk/main.cpp +++ b/src/Unuk/main.cpp @@ -34,11 +34,11 @@ int ResizeWindow(int width, int height) { // Height and width ration. GLfloat ratio; - // Prevent devide by zero. + // Prevent divide by zero. if(height == 0) height = 1; - ratio = (GLfloat )width / (GLfloat)height; + ratio = (GLfloat)width / (GLfloat)height; // Setup our viewport. glViewport(0, 0, (GLsizei)width, (GLsizei)height); @@ -170,13 +170,13 @@ int main() { // Initialize OpenGL. InitGL(); - // Resize the initial window. - ResizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT); + game.Init(); + Debug::logger->message("Game Initialize!"); + Debug::logger->message("\n\n-----Engine Initialization Complete-----"); Debug::logger->message("\n\n-----Logic-----"); while(!done) { - CreateInput(); // Time to poll events. while(SDL_PollEvent(&event)) { switch(event.type) { @@ -184,7 +184,7 @@ int main() { // Handle resize events. surface = SDL_SetVideoMode(event.resize.w, event.resize.h, 16, videoFlags); if(!surface) { - fprintf(stderr, "Could not get a surface after resize: %s\n", SDL_GetError()); + Debug::logger->message("Could not get a surface after resize\n"); Quit(1); } ResizeWindow(event.resize.w, event.resize.h); @@ -200,7 +200,8 @@ int main() { default: break; } - UpdateInput(); + //CreateInput(); + //UpdateInput(); } // Render the scene. float elapsedTime = GetElapsedSeconds(); @@ -216,4 +217,3 @@ int main() { // We should never get here. return(0); } -